-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax.php
224 lines (186 loc) · 6.55 KB
/
ajax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
$error = FALSE;
if(file_exists('config.php')){
require_once('lib/yelp.php');
$message = '';
if(!isset($CONSUMER_KEY) || empty($CONSUMER_KEY)){
$message .= ' $CONSUMER_KEY is empty.';
$error = TRUE;
}
if(!isset($CONSUMER_SECRET) || empty($CONSUMER_SECRET)){
$message .= ' $CONSUMER_SECRET is empty.';
$error = TRUE;
}
if(!isset($TOKEN) || empty($TOKEN)){
$message .= ' $TOKEN is empty.';
$error = TRUE;
}
if(!isset($TOKEN_SECRET) || empty($TOKEN_SECRET)){
$message .= ' $TOKEN_SECRET is empty.';
$error = TRUE;
}
if($error == TRUE){
$message .= ' Please edit <strong>config.php</strong>, keys can be obtained from <a href="http://www.yelp.com/developers">http://www.yelp.com/developers</a>';
}
} else {
$error = TRUE;
$message = 'Missing <strong>config.php</strong>, Please copy and rename the file <strong>config.php.sample</strong> to <strong>config.php</strong> and provide valid API Keys. API keys can be obtained from'.
' <a href="http://www.yelp.com/developers">http://www.yelp.com/developers</a>';
}
if($error == TRUE){
$data = array();
$results['recordsTotal'] = 0;
$results['recordsFiltered'] = 0;
$results['dataError'] = array('message'=>$message);
$results['draw'] = (int) $draw;
$results['data'] = $data;
echo json_encode($results);
die();
}
/* Magic Begins here! */
extract($_POST);
$data = array();
$results['recordsTotal'] = 0;
$results['recordsFiltered'] = 0;
if(isset($term) && isset($location) && isset($length) && isset($start)){
$response = json_decode(search($term,$location,$length,$start));
$businesses = array();
if($response->businesses){
$businesses = $response->businesses;
}
foreach($businesses as $business){
if(isset($business->name)){
$name = $business->name;
} else {
$name = '';
}
if(isset($business->display_phone)){
$phone_display = $business->display_phone;
} else {
$phone_display = '';
}
if(isset($business->phone)){
$phone = $business->phone;
} else {
$phone = '';
}
if(isset($business->location->display_address)){
$display_address = $business->location->display_address;
} else {
$display_address = '';
}
if(isset($business->location->address)){
$address = $business->location->address;
} else {
$address = '';
}
if(isset($business->location->neighborhoods)){
$neighborhoods = $business->location->neighborhoods;
} else {
$neighborhoods = '';
}
if(isset($business->location->city)){
$city = $business->location->city;
} else {
$city = '';
}
if(isset($business->location->state_code)){
$state = $business->location->state_code;
} else {
$state = '';
}
if(isset($business->location->postal_code)){
$postal_code = $business->location->postal_code;
} else {
$postal_code = '';
}
if(isset($business->url)){
$url = $business->url;
} else {
$url = '';
}
$categories = array();
if(isset($business->categories)){
foreach($business->categories as $bizCategory){
if(isset($bizCategory[0])){
$categories[] = $bizCategory[0];
}
}
}
$category_1 = '';
$category_2 = '';
$category_3 = '';
$category_others = '';
if(isset($business->categories[0][0])){
$category_1 = $business->categories[0][0];
}
if(isset($business->categories[1][0])){
$category_2 = $business->categories[1][0];
}
if(isset($business->categories[2][0])){
$category_3 = $business->categories[2][0];
}
if(isset($business->categories[3])){
$category_others = implode(', ',array_slice($categories,3));
}
$categories = implode(', ', $categories);
// if(isset($neighborhoods[0])){ // removed on request
// $address[] = $neighborhoods[0]; //add first neighbourhood to address for display
// }
if(isset($business->rating)){
$rating = $business->rating;
} else {
$rating = '';
}
if(isset($business->rating_img_url)){
$rating_img_url = $business->rating_img_url;
} else {
$rating_img_url = '';
}
if($rating_img_url != ''){
$rating_img = '<img src="'.$rating_img_url.'">';
} else {
$rating_img = '';
}
$display_url = '';
$display_link = '';
if($url){
if(strlen($url) > 25){
$display_url = substr($url, 0, 25);
$display_link = '<a href="'.$url.'" target="_blank" data-toggle="tooltip" data-placement="bottom" title="'.$url.'">'.$display_url.'...</a>';
} else {
$display_url = $url;
$display_link = '<a href="'.$url.'" target="_blank" data-toggle="tooltip" data-placement="bottom" title="'.$url.'">'.$display_url.'</a>';
}
}
$data[] = array(
'name' => $name,
'phone_display' => $phone_display,
'phone' => $phone,
'address' => implode(', ',$address),
'city' => $city,
'state' => $state,
'zip' => $postal_code,
//'category' => $categories,
'category_1' => $category_1,
'category_2' => $category_2,
'category_3' => $category_3,
'category_others' => $category_others,
'url_link' => $display_link,
'url' => $url,
'rating_img' => $rating_img,
'rating'=> $rating //for csv
);
}
if(is_numeric($response->total)){
$results['recordsTotal'] = $response->total;
$results['recordsFiltered'] = $response->total;
}
} else {
$results['dataError'] = array('message'=>'Missing parameters');
}
//$results['test'] = $business;
$results['draw'] = (int) $draw;
$results['data'] = $data;
echo json_encode($results);
die();