This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_artists.php
369 lines (306 loc) · 13.8 KB
/
json_artists.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<?php
// Artist list
if (isset($_GET['artists'])) {
$db = Database::getInstance();
$mysqli = $db->getConnection();
$sql_query = "SELECT * FROM v2_users WHERE email = '" . $mysqli->real_escape_string($_GET['artists']) . "'";
$result = $mysqli->query($sql_query);
$num_rows = $result->num_rows;
if (isset($_GET['sortby'])) { $sort = $mysqli->real_escape_string($_GET['sortby']); } else { $sort = ''; }
if ($num_rows == 1) {
$row = mysqli_fetch_array($result);
$current_user_id = $row['user_id'];
// Generate query string for searches...
$query = "";
$bump = 0;
if ($row['album'] == 1) {
$query .= "v2_release_group.type = 'Album'";
$bump++;
}
if ($row['single'] == 1) {
if ($bump > 0) { $query .= " OR ";}
$query .= "v2_release_group.type = 'Single'";
$bump++;
}
if ($row['ep'] == 1) {
if ($bump > 0) { $query .= " OR ";}
$query .= "v2_release_group.type = 'EP'";
$bump++;
}
if ($row['live'] == 1) {
if ($bump > 0) { $query .= " OR ";}
$query .= "v2_release_group.type = 'Live'";
$bump++;
}
if ($row['soundtrack'] == 1) {
if ($bump > 0) { $query .= " OR ";}
$query .= "v2_release_group.type = 'Soundtrack'";
$bump++;
}
if ($row['remix'] == 1) {
if ($bump > 0) { $query .= " OR ";}
$query .= "v2_release_group.type = 'Remix'";
$bump++;
}
if ($row['other'] == 1) {
if ($bump > 0) { $query .= " OR ";}
$query .= "(v2_release_group.type != 'Album' AND v2_release_group.type != 'Single' AND v2_release_group.type != 'EP' AND v2_release_group.type != 'Live' AND v2_release_group.type != 'Soundtrack' AND v2_release_group.type != 'Remix')";
$bump++;
}
$current_query_string = $query;
if ($bump == 0) { $current_query_string = "v2_release_group.type LIKE '%%'"; }
} else {
$current_query_string = "";
$current_user_id = 0;
}
$sql_query = "SELECT v2_artist.name, v2_artist.artist_id, v2_artist.sort_name, v2_artist.art,
(SELECT MAX(v2_release_group.date) FROM v2_release_group WHERE v2_release_group.artist_id = v2_artist.artist_id";
$sql_query .= " AND (".$current_query_string.")";
$sql_query .= ") as recent_date, (SELECT count(release_mbid) FROM `v2_release_group`
LEFT JOIN (SELECT * from v2_user_listen WHERE user_id ='".$current_user_id."') AS x
ON v2_release_group.release_id = x.release_id WHERE (read_status = '0' OR read_status IS NULL) AND v2_release_group.artist_id = v2_artist.artist_id";
$sql_query .= " AND (".$current_query_string.")";
$sql_query .= ") as unread, (SELECT count(release_mbid) FROM `v2_release_group`
LEFT JOIN (SELECT * from v2_user_listen WHERE user_id ='".$current_user_id."') AS x
ON v2_release_group.release_id = x.release_id WHERE v2_release_group.artist_id = v2_artist.artist_id";
$sql_query .= " AND (".$current_query_string.")";
$sql_query .= ") as total_releases,
coalesce((SELECT IF(v2_user_artist.user_id IS NULL,'0','1') FROM `v2_user_artist` WHERE v2_artist.artist_id = v2_user_artist.artist_id AND v2_user_artist.user_id = '".$current_user_id."'),0) as follow_status
FROM `v2_user_artist`
LEFT JOIN `v2_artist` ON v2_user_artist.artist_id = v2_artist.artist_id
LEFT JOIN `v2_users` ON v2_user_artist.user_id = v2_users.user_id WHERE v2_users.email = '". $mysqli->real_escape_string($_GET['artists']) ."' ";
if ($sort == 'date') {
$sql_query .= "ORDER BY recent_date DESC, sort_name";
} else {
$sql_query .= "ORDER BY sort_name";
}
//echo $sql_query."<br/><br/>";
if($mysqli->query($sql_query) === false) {
trigger_error('Wrong SQL: ' . $sql_query . ' Error: ' . $mysqli->error, E_USER_ERROR);
} else {
$result = $mysqli->query($sql_query);
}
$num_rows = $result->num_rows;
$return_array = array();
while ($row = mysqli_fetch_array($result)) {
//$row['art'] = '0';
if ($row['art'] == '0' || $row['art'] == '2') {
$art = array(
"thumb"=>"https://www.numutracker.com/nonly3-1024.png",
"full"=>"https://www.numutracker.com/nonly3-1024.png",
"large"=>"https://www.numutracker.com/nonly3-1024.png",
"xlarge"=>"https://www.numutracker.com/nonly3-1024.png"
);
} else {
$art = array(
"thumb"=>"https://www.numutracker.com/v2/artist/thumb/".$row['art'],
"full"=>"https://www.numutracker.com/v2/artist/".$row['art'],
"large"=>"https://www.numutracker.com/v2/artist/large/".$row['art'],
"xlarge"=>"https://www.numutracker.com/v2/artist/xlarge/".$row['art']
);
}
$recent_date = date("F j, Y", strtotime($row['recent_date']));
if ($recent_date == "January 1, 1970") { $recent_date = "No Releases"; }
array_push($return_array, array("artist_id" => $row['artist_id'],"recent_date" => $recent_date,"artist_art" => $art,"name" => $row['name'], "unread"=>$row['unread'],"total_releases"=>$row['total_releases'],"follow_status"=>$row['follow_status']));
}
$returned = $return_array;
}
if (isset($_GET['artist_search'])) {
$db = Database::getInstance();
$mysqli = $db->getConnection();
$sql_query = "SELECT * FROM v2_users WHERE email = '" . $mysqli->real_escape_string($_GET['artist_search']) . "'";
$result = $mysqli->query($sql_query);
$num_rows = $result->num_rows;
if (isset($_GET['search'])) { $search = $mysqli->real_escape_string($_GET['search']); }
if ($num_rows == 1) {
$row = mysqli_fetch_array($result);
$current_user_id = $row['user_id'];
// Generate query string for searches...
$query = "";
$bump = 0;
if ($row['album'] == 1) {
$query .= "v2_release_group.type = 'Album'";
$bump++;
}
if ($row['single'] == 1) {
if ($bump > 0) { $query .= " OR ";}
$query .= "v2_release_group.type = 'Single'";
$bump++;
}
if ($row['ep'] == 1) {
if ($bump > 0) { $query .= " OR ";}
$query .= "v2_release_group.type = 'EP'";
$bump++;
}
if ($row['live'] == 1) {
if ($bump > 0) { $query .= " OR ";}
$query .= "v2_release_group.type = 'Live'";
$bump++;
}
if ($row['soundtrack'] == 1) {
if ($bump > 0) { $query .= " OR ";}
$query .= "v2_release_group.type = 'Soundtrack'";
$bump++;
}
if ($row['remix'] == 1) {
if ($bump > 0) { $query .= " OR ";}
$query .= "v2_release_group.type = 'Remix'";
$bump++;
}
if ($row['other'] == 1) {
if ($bump > 0) { $query .= " OR ";}
$query .= "(v2_release_group.type != 'Album' AND v2_release_group.type != 'Single' AND v2_release_group.type != 'EP' AND v2_release_group.type != 'Live' AND v2_release_group.type != 'Soundtrack' AND v2_release_group.type != 'Remix')";
$bump++;
}
$current_query_string = $query;
if ($bump == 0) { $current_query_string = "v2_release_group.type LIKE '%%'"; }
} else {
$current_query_string = "(v2_release_group.type = 'Album' OR v2_release_group.type = 'EP')";
$current_user_id = 0;
}
$sql_query = "SELECT v2_artist.name, v2_artist.artist_id, v2_artist.sort_name, v2_artist.art,
(SELECT MAX(v2_release_group.date) FROM v2_release_group WHERE v2_release_group.artist_id = v2_artist.artist_id";
$sql_query .= " AND (".$current_query_string.")";
$sql_query .= ") as recent_date, (SELECT count(release_mbid) FROM `v2_release_group`
LEFT JOIN (SELECT * from v2_user_listen WHERE user_id ='".$current_user_id."') AS x
ON v2_release_group.release_id = x.release_id WHERE (read_status = '0' OR read_status IS NULL) AND v2_release_group.artist_id = v2_artist.artist_id";
$sql_query .= " AND (".$current_query_string.")";
$sql_query .= ") as unread, (SELECT count(release_mbid) FROM `v2_release_group`
LEFT JOIN (SELECT * from v2_user_listen WHERE user_id ='".$current_user_id."') AS x
ON v2_release_group.release_id = x.release_id WHERE v2_release_group.artist_id = v2_artist.artist_id";
$sql_query .= " AND (".$current_query_string.")";
$sql_query .= ") as total_releases,
coalesce((SELECT IF(v2_user_artist.user_id IS NULL,'0','1') FROM `v2_user_artist` WHERE v2_artist.artist_id = v2_user_artist.artist_id AND v2_user_artist.user_id = '".$current_user_id."'),0) as follow_status
FROM `v2_artist`
WHERE v2_artist.name LIKE '%". $search ."%' ";
$sql_query .= "ORDER BY recent_date DESC, sort_name LIMIT 100";
//echo $sql_query."<br/><br/>";
if($mysqli->query($sql_query) === false) {
trigger_error('Wrong SQL: ' . $sql_query . ' Error: ' . $mysqli->error, E_USER_ERROR);
} else {
$result = $mysqli->query($sql_query);
}
$num_rows = $result->num_rows;
$return_array = array();
while ($row = mysqli_fetch_array($result)) {
//$row['art'] = '0';
if ($row['art'] == '0' || $row['art'] == '2') {
$art = array(
"thumb"=>"https://www.numutracker.com/nonly3-1024.png",
"full"=>"https://www.numutracker.com/nonly3-1024.png",
"large"=>"https://www.numutracker.com/nonly3-1024.png",
"xlarge"=>"https://www.numutracker.com/nonly3-1024.png"
);
} else {
$art = array(
"thumb"=>"https://www.numutracker.com/v2/artist/thumb/".$row['art'],
"full"=>"https://www.numutracker.com/v2/artist/".$row['art'],
"large"=>"https://www.numutracker.com/v2/artist/large/".$row['art'],
"xlarge"=>"https://www.numutracker.com/v2/artist/xlarge/".$row['art']
);
}
$recent_date = date("F j, Y", strtotime($row['recent_date']));
if ($recent_date == "January 1, 1970") { $recent_date = "No Releases"; }
array_push($return_array, array("artist_id" => $row['artist_id'],"recent_date" => $recent_date,"artist_art" => $art,"name" => $row['name'], "unread"=>$row['unread'],"total_releases"=>$row['total_releases'],"follow_status"=>$row['follow_status']));
}
$returned = $return_array;
}
if (isset($_GET['single_artist'])) {
$db = Database::getInstance();
$mysqli = $db->getConnection();
$sql_query = "SELECT * FROM v2_users WHERE email = '" . $mysqli->real_escape_string($_GET['single_artist']) . "'";
$result = $mysqli->query($sql_query);
$num_rows = $result->num_rows;
if (isset($_GET['search'])) { $search = $mysqli->real_escape_string($_GET['search']); }
if ($num_rows == 1) {
$row = mysqli_fetch_array($result);
$current_user_id = $row['user_id'];
// Generate query string for searches...
$query = "";
$bump = 0;
if ($row['album'] == 1) {
$query .= "v2_release_group.type = 'Album'";
$bump++;
}
if ($row['single'] == 1) {
if ($bump > 0) { $query .= " OR ";}
$query .= "v2_release_group.type = 'Single'";
$bump++;
}
if ($row['ep'] == 1) {
if ($bump > 0) { $query .= " OR ";}
$query .= "v2_release_group.type = 'EP'";
$bump++;
}
if ($row['live'] == 1) {
if ($bump > 0) { $query .= " OR ";}
$query .= "v2_release_group.type = 'Live'";
$bump++;
}
if ($row['soundtrack'] == 1) {
if ($bump > 0) { $query .= " OR ";}
$query .= "v2_release_group.type = 'Soundtrack'";
$bump++;
}
if ($row['remix'] == 1) {
if ($bump > 0) { $query .= " OR ";}
$query .= "v2_release_group.type = 'Remix'";
$bump++;
}
if ($row['other'] == 1) {
if ($bump > 0) { $query .= " OR ";}
$query .= "(v2_release_group.type != 'Album' AND v2_release_group.type != 'Single' AND v2_release_group.type != 'EP' AND v2_release_group.type != 'Live' AND v2_release_group.type != 'Soundtrack' AND v2_release_group.type != 'Remix')";
$bump++;
}
$current_query_string = $query;
if ($bump == 0) { $current_query_string = "v2_release_group.type LIKE '%%'"; }
} else {
$current_query_string = "";
$current_user_id = 0;
}
$sql_query = "SELECT v2_artist.name, v2_artist.artist_id, v2_artist.sort_name, v2_artist.art,
(SELECT MAX(v2_release_group.date) FROM v2_release_group WHERE v2_release_group.artist_id = v2_artist.artist_id";
$sql_query .= " AND (".$current_query_string.")";
$sql_query .= ") as recent_date, (SELECT count(release_mbid) FROM `v2_release_group`
LEFT JOIN (SELECT * from v2_user_listen WHERE user_id ='".$current_user_id."') AS x
ON v2_release_group.release_id = x.release_id WHERE (read_status = '0' OR read_status IS NULL) AND v2_release_group.artist_id = v2_artist.artist_id";
$sql_query .= " AND (".$current_query_string.")";
$sql_query .= ") as unread, (SELECT count(release_mbid) FROM `v2_release_group`
LEFT JOIN (SELECT * from v2_user_listen WHERE user_id ='".$current_user_id."') AS x
ON v2_release_group.release_id = x.release_id WHERE v2_release_group.artist_id = v2_artist.artist_id";
$sql_query .= " AND (".$current_query_string.")";
$sql_query .= ") as total_releases,
coalesce((SELECT IF(v2_user_artist.user_id IS NULL,'0','1') FROM `v2_user_artist` WHERE v2_artist.artist_id = v2_user_artist.artist_id AND v2_user_artist.user_id = '".$current_user_id."'),0) as follow_status
FROM `v2_artist`
WHERE v2_artist.artist_id = '". $search ."' ";
$sql_query .= "ORDER BY recent_date DESC, sort_name LIMIT 100";
//echo $sql_query."<br/><br/>";
if($mysqli->query($sql_query) === false) {
trigger_error('Wrong SQL: ' . $sql_query . ' Error: ' . $mysqli->error, E_USER_ERROR);
} else {
$result = $mysqli->query($sql_query);
}
$num_rows = $result->num_rows;
$return_array = array();
while ($row = mysqli_fetch_array($result)) {
if ($row['art'] == '0' || $row['art'] == '2') {
$art = array(
"thumb"=>"https://www.numutracker.com/nonly3-1024.png",
"full"=>"https://www.numutracker.com/nonly3-1024.png",
"large"=>"https://www.numutracker.com/nonly3-1024.png",
"xlarge"=>"https://www.numutracker.com/nonly3-1024.png"
);
} else {
$art = array(
"thumb"=>"https://www.numutracker.com/v2/artist/thumb/".$row['art'],
"full"=>"https://www.numutracker.com/v2/artist/".$row['art'],
"large"=>"https://www.numutracker.com/v2/artist/large/".$row['art'],
"xlarge"=>"https://www.numutracker.com/v2/artist/xlarge/".$row['art']
);
}
$recent_date = date("F j, Y", strtotime($row['recent_date']));
if ($recent_date == "January 1, 1970") { $recent_date = "No Releases"; }
array_push($return_array, array("artist_id" => $row['artist_id'],"recent_date" => $recent_date,"artist_art" => $art,"name" => $row['name'], "unread"=>$row['unread'],"total_releases"=>$row['total_releases'],"follow_status"=>$row['follow_status']));
}
$returned = $return_array;
}