Subversion Repositories cheapmusic

Rev

Rev 130 | Rev 134 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 - 1
<?php
20 - 2
error_reporting(E_ALL);
10 - 3
 
4
// BUGBUG {"message": "You are making requests too quickly."}
127 - 5
function findDiscogsMaster($stxt) {
10 - 6
    $vendors = Vendors::getInstance();
7
    $config = $vendors->getVendor(Vendors::DISCOGS);
45 - 8
    $maxMasterCount = $config['maxMasters'];
13 - 9
 
10 - 10
    $_SESSION["discogs"] = "";
11
 
127 - 12
// bugbug $url =  "https://api.discogs.com/artists/" . $stxt . "/releases?";
81 - 13
    $params = [];
14
    $params["token"] = $config['token'];
15
    if (empty($_SESSION["barcode"]["Type"])) {
16
        $params["type"] = "All";
46 - 17
 
18
        if (!empty($_SESSION["discogsTitle"]) || !empty($_SESSION["discogsArtist"])) {
19
            if (!empty($_SESSION["discogsTitle"])) {
81 - 20
                $params["release_title"] = $_SESSION["discogsTitle"];
46 - 21
            }
57 - 22
 
46 - 23
            if (!empty($_SESSION["discogsArtist"])) {
81 - 24
                $params["artist"] = $_SESSION["discogsArtist"];
46 - 25
            }
65 - 26
        }
27
        else {
127 - 28
            $params["query"] = ($stxt == "***RANDOM***" ? mt_rand($config['minRelease'], $config['maxRelease']) : $stxt);
46 - 29
        }
65 - 30
    }
31
    else {
81 - 32
        $params["barcode"] = $_SESSION["barcode"]["Value"];
10 - 33
    }
34
 
81 - 35
    $pairs = array();
36
    foreach ($params as $key => $value) {
37
        array_push($pairs, rawurlencode($key)."=".rawurlencode($value));
38
    }
39
    $canonical_query_string = join("&", $pairs);
40
 
41
    $url = "https://api.discogs.com/database/search?" . $canonical_query_string;
42
 
127 - 43
    $searchResp = ($stxt == "***RANDOM***" ? false : getSearchCache("Discogs", $stxt, ""));
99 - 44
    if ($searchResp === false) {
45
        $searchResp = getUrl($url, $config['userAgent']);
127 - 46
        if ($stxt != "***RANDOM***") {
47
            saveSearchCache("Discogs", $stxt, "", $searchResp);
104 - 48
        }
99 - 49
    }
65 - 50
    $searchResp = utf8_encode($searchResp);
51
    $searchResp = json_decode($searchResp);
10 - 52
 
43 - 53
    if (empty($searchResp)) {
54
        return;
55
    }
56
 
10 - 57
    if (!empty($searchResp->{'message'})) {
58
        if ($searchResp->{'message'} == "You are making requests too quickly.") {
96 - 59
            my_error_log("Discogs: You are making requests too quickly.");
10 - 60
            return;
61
        }
14 - 62
        return;
10 - 63
    }
64
 
65
    if ($searchResp->{'pagination'}->{'items'} < 1) {
127 - 66
        if ($stxt == "***RANDOM***") { // must find something
45 - 67
            findDiscogsMaster("***RANDOM***", !empty($_SESSION['sessData']['userLoggedIn']));
38 - 68
        }
69
 
10 - 70
        return;
71
    }
72
 
127 - 73
    $xh = new Html;
74
    $xh->init($_SESSION["htmlIndent"]);
13 - 75
 
127 - 76
    $xh->add_attribute("class", "container-fluid bg-light");
77
    $xh->tag('div');
78
    $xh->add_attribute("class", "text-center py-2");
79
    $xh->tag('h2', ($stxt == "***RANDOM***" ? "Random" : "Matching") . " Albums");
80
    $xh->add_attribute("method", "post");
81
    $xh->add_attribute("action", "/index.php");
82
    $xh->tag('form');
83
    $xh->insert_code(inputSessionTab());
84
    $xh->insert_code(inputNonce());
85
    $xh->add_attribute("id", "discogsTitle");
86
    $xh->add_attribute("type", "hidden");
87
    $xh->add_attribute("name", "discogsTitle");
88
    $xh->add_attribute("value", "");
89
    $xh->single_tag('input');
90
    $xh->add_attribute("id", "discogsArtist");
91
    $xh->add_attribute("type", "hidden");
92
    $xh->add_attribute("name", "discogsArtist");
93
    $xh->add_attribute("value", "");
94
    $xh->single_tag('input');
95
    $xh->add_attribute("id", "discogsBarcode");
96
    $xh->add_attribute("type", "hidden");
97
    $xh->add_attribute("name", "discogsBarcode");
98
    $xh->add_attribute("value", "");
99
    $xh->single_tag('input');
100
    $xh->add_attribute("id", "discogsDeck");
101
    $xh->add_attribute("class", "card-deck");
102
    $xh->tag('div');
103
 
10 - 104
    $masterCount = 0;
105
    $processedMasters = [];
129 - 106
    $searchUrls = [];
107
    $masterResps_cache = [];
10 - 108
    foreach ($searchResp->{'results'} as $searchey => $searchValue) {
78 - 109
// bugbug foreach ($searchResp->{'releases'} as $searchey => $searchValue) {
65 - 110
        if (!in_array($searchValue->{'type'}, array(
111
            "master",
112
            "release"
113
        )) && empty($_SESSION["barcode"]['Type'])) {
10 - 114
            continue;
115
        }
116
 
50 - 117
        if (empty($_SESSION["barcode"]['Type']) && $searchValue->{'type'} == "release" && $searchValue->{'master_id'} > 0) {
10 - 118
            continue;
119
        }
57 - 120
 
47 - 121
        if ($searchValue->{'master_id'} > 0 && in_array($searchValue->{'master_id'}, $processedMasters)) {
122
            continue;
123
        }
10 - 124
        $processedMasters[] = $searchValue->{'master_id'};
125
 
50 - 126
        if (++$masterCount > $maxMasterCount) {
127
            break;
128
        }
129
 
99 - 130
        $searchUrl = $searchValue->{'master_id'} != 0 ? $searchValue->{'master_url'} : $searchValue->{'resource_url'};
132 - 131
 
129 - 132
        $searchType[$searchUrl] = $searchValue->{'type'};
133
        $searchThumb[$searchUrl] = $searchValue->{'thumb'};
134
        $searchCoverImage[$searchUrl] = $searchValue->{'cover_image'};
132 - 135
 
129 - 136
        $masterResps_cache[$searchUrl] = getSearchCache("Discogs", $searchUrl, "");
137
        if ($masterResps_cache[$searchUrl] === false) {
138
            $searchUrls[] = $searchUrl;
139
            unset($masterResps_cache[$searchUrl]);
99 - 140
        }
129 - 141
    }
10 - 142
 
129 - 143
    $masterResps = [];
144
    if (count($searchUrls) > 0) {
145
        $masterResps = getMultiUrl($searchUrls, $config['userAgent']);
146
    }
17 - 147
 
129 - 148
    foreach($masterResps as $key => $html) {
149
        saveSearchCache("Discogs", $key, "", $html);
150
    }
10 - 151
 
129 - 152
    foreach($masterResps_cache as $key => $html) {
153
        $masterResps[$key] = $html;
154
    }
155
    unset($masterResps_cache);
156
 
157
    $masterCount = 0;
158
    foreach($masterResps as $key => $html) {
159
        $html = utf8_encode($html);
160
        $html = json_decode($html);
161
 
162
        if (!empty($html->{'message'})) {
163
            my_error_log("Discogs: " . $html->{'message'});
164
        } else if (!empty($html)) {
130 - 165
            $xh->insert_code(processMaster($html, $searchType[$key], $searchThumb[$key], $searchCoverImage[$key], ++$masterCount));
17 - 166
        }
10 - 167
    }
132 - 168
 
81 - 169
    if ($masterCount == 0) {
127 - 170
        $xh->clear_buffer();
81 - 171
    } else {
127 - 172
        $xh->close(); // div
173
        $xh->close(); // form
174
        $xh->close(); // div
132 - 175
 
130 - 176
        $xh->insert_code(discogsEvents());
120 - 177
 
127 - 178
        if ($stxt == "***RANDOM***") {
179
            $xh->add_attribute("class", "container-fluid text-center");
180
            $xh->tag('div');
181
              $xh->add_attribute("method", "post");
182
              $xh->add_attribute("action", "/index.php");
183
              $xh->tag('form');
184
                $xh->insert_code(inputSessionTab());
185
                $xh->insert_code(inputSearchTerm());
186
                $xh->insert_code(inputNonce());
187
                $xh->add_attribute("id", "randomBtn");
188
                $xh->add_attribute("type", "submit");
189
                $xh->add_attribute("class", "btn btn-success m-2 rounded");
190
                $xh->add_attribute("name", "submit");
191
                $xh->add_attribute("value", "random");
192
                $xh->tag('button', "More Random Album Suggestions");
193
              $xh->close(); // form
194
            $xh->close(); // div
130 - 195
            $xh->add_attribute("nonce", "xxxNONCExxx");
196
            $xh->tag('script');
197
                $str  = trim('document.addEventListener("DOMContentLoaded", function() {');
198
                $str .= trim('  document.getElementById("randomBtn").addEventListener("click", function(event) {');
199
                $str .= trim('           window.dataLayer.push({ "event" : "trackEvent", "eventCategory" : "Random Album", "eventAction" : "Click", "eventLabel" : "More"});');
200
                $str .= trim('});');
201
            $xh->insert_code($str);
202
            $xh->close(); // script
81 - 203
        }
38 - 204
    }
10 - 205
 
127 - 206
    $_SESSION["discogs"] = $xh->flush();
207
    //error_log(print_r($_SESSION["discogs"], 1));
208
 
10 - 209
    return;
210
}
211
 
130 - 212
function discogsEvents() {
127 - 213
    $xh = new Html;
214
    $xh->init($_SESSION["htmlIndent"]);
130 - 215
 
216
    $xh->add_attribute("nonce", "xxxNONCExxx");
217
    $xh->tag('script');
218
        $str  = trim('document.addEventListener("DOMContentLoaded", function() {');
219
        $str .= trim('  document.getElementById("discogsDeck").addEventListener("click", function(event) {');
220
        $str .= trim('       e = event.target.closest("button");');
221
        $str .= trim('       if (e && e.id.startsWith("discogsSearch")) {');
222
        $str .= trim('           var title = e.getAttribute("data-title");');
223
        $str .= trim('           var artist = e.getAttribute("data-artist");');
224
        $str .= trim('           var barcode = e.getAttribute("data-barcode");');
225
        $str .= trim('           var searchTitle = e.getAttribute("data-search-title");');
226
        $str .= trim('');
227
        $str .= trim('           document.getElementById("discogsTitle").value = title;');
228
        $str .= trim('           document.getElementById("discogsArtist").value = artist;');
229
        $str .= trim('           document.getElementById("discogsBarcode").value = barcode;');
230
        $str .= trim('');
231
        $str .= trim('           window.dataLayer.push({ "event" : "search", "search_term" : title + " by " + (artist.length == 0 ? "Various Artists" : artist)});');
232
        $str .= trim('');
233
        $str .= trim('           progressBar(searchTitle);');
234
        $str .= trim('       } else if (e && e.id.startsWith("wl")) {');
235
        $str .= trim('           var user = e.getAttribute("data-user");');
236
        $str .= trim('           var cnt = e.getAttribute("data-cnt");');
237
        $str .= trim('           var wl = e.getAttribute("data-wl");');
238
        $str .= trim('           window.dataLayer.push({ "event" : "trackEvent", "eventCategory" : "Bookmark", "eventAction" : "Add", "eventLabel" : ""});');
239
        $str .= trim('           addWishlist(user, e, cnt, wl);');
240
        $str .= trim('       } else if (e && e.id.startsWith("discogsInfo")) {');
241
        $str .= trim('           window.dataLayer.push({ "event" : "trackEvent", "eventCategory" : "Album Info", "eventAction" : "Click", "eventLabel" : ""});');
242
        $str .= trim('       } else if (e && e.id.startsWith("discogsVideo")) {');
243
        $str .= trim('           window.dataLayer.push({ "event" : "trackEvent", "eventCategory" : "Video Info", "eventAction" : "Click", "eventLabel" : ""});');
244
        $str .= trim('       }');
245
        $str .= trim('  });');
246
        $str .= trim('});');
247
    $xh->insert_code($str);
248
    $xh->close(); // script
132 - 249
 
130 - 250
    $html = $xh->flush();
251
    //error_log(print_r($html, 1));
252
 
253
    return $html;
254
}
255
 
256
function processMaster($master, $type, $thumbnail, $coverImage, $cnt) {
257
    $xh = new Html;
258
    $xh->init($_SESSION["htmlIndent"]);
127 - 259
    $xhmod = new Html;
260
    $xhmod->init($_SESSION["htmlIndent"]);
261
 
10 - 262
    $artists = [];
263
    foreach ($master->{'artists'} as $key => $value) {
20 - 264
        $artists[] = trim(preg_replace('/\([0-9]+\)$/', "", (string)$value->{'name'}));
10 - 265
    }
266
 
267
    $genres = [];
268
    foreach ($master->{'genres'} as $key => $value) {
65 - 269
        $genres[] = (string)$value;
10 - 270
    }
271
 
20 - 272
    $labels = [];
273
    if (isset($master->{'labels'})) {
274
        foreach ($master->{'labels'} as $key => $value) {
275
            $labels[] = trim(preg_replace('/\([0-9]+\)$/', "", (string)$value->{'name'}));
276
        }
277
    }
278
 
279
    $formats = [];
280
    if (isset($master->{'formats'})) {
281
        foreach ($master->{'formats'} as $key => $value) {
282
            $formats[] = trim(preg_replace('/\([0-9]+\)$/', "", (string)$value->{'name'}));
283
        }
284
    }
38 - 285
 
20 - 286
    $country = '';
287
    if (isset($master->{'country'})) {
288
        $country = (string)$master->{'country'};
289
    }
290
 
127 - 291
    $xh->add_attribute("class", "card mx-auto discogs-card");
292
    $xh->tag('div');
293
 
294
    $xh->add_attribute("class", "card-header bg-secondary d-flex");
295
    $xh->tag('div');
17 - 296
    $searchArtists = "";
20 - 297
    if (count($artists) < 5) {
47 - 298
        $wlArtists = join(", ", $artists);
65 - 299
        if ($artists[0] != 'Various') {
300
            $searchArtists = join(" ", $artists);
301
        }
302
    }
303
    else {
47 - 304
        $wlArtists = "Various Artists";
14 - 305
    }
127 - 306
    $xh->add_attribute("class", "card-title font-weight-bold small flex-grow-1");
307
    $xh->tag('p', htmlentities((string)$master->{'title'}) . " by " . htmlentities($wlArtists));
308
    $xh->close(); // div
132 - 309
 
72 - 310
    if (empty($thumbnail) || preg_match("/spacer.gif$/", $thumbnail)) {
14 - 311
        $thumbnail = "images/no-image-available.jpg";
312
    }
127 - 313
    $xh->add_attribute("class", "card-body d-flex justify-content-center align-items-center p-1 m-0");
314
    $xh->tag('div');
315
    $xh->add_attribute("class", "btn p-0 m-0 lazyload");
316
    $xh->add_attribute("src",PIXEL);
317
    $xh->add_attribute("data-src", $thumbnail);
318
    $xh->add_attribute("data-toggle", "modal");
319
    $xh->add_attribute("data-target", "#masterModal" . $cnt);
320
    $xh->add_attribute("title", "Album Information");
321
    $xh->add_attribute("data-toggle2", "tooltip");
322
    $xh->add_attribute("alt", "Discogs Cover Thumbnail");
323
    $xh->single_tag('img');
324
    $xh->close(); // div
325
    $xh->add_attribute("class", "card-footer bg-secondary p-0 m-0");
326
    $xh->tag('div');
327
    $xh->add_attribute("class", "container clearfix p-0 m-0");
328
    $xh->tag('div');
329
    $xh->add_attribute("class", "float-left btn-group-sm");
330
    $xh->tag('span');
130 - 331
    $xh->add_attribute("id", "discogsInfo" . $cnt);
127 - 332
    $xh->add_attribute("type", "button");
333
    $xh->add_attribute("class", "btn btn-info btn-sm");
334
    $xh->add_attribute("data-toggle", "modal");
335
    $xh->add_attribute("data-target", "#masterModal" . $cnt);
336
    $xh->add_attribute("title", "Album Information");
337
    $xh->add_attribute("aria-label", "Album Information");
338
    $xh->add_attribute("data-toggle2", "tooltip");
339
    $xh->tag('button');
340
    $xh->add_attribute("class", "material-icons");
341
    $xh->tag('i', "info_outline");
342
    $xh->close(); // button
45 - 343
 
344
    if (isset($master->{'videos'})) {
127 - 345
        $xh->tag('span', " ");
130 - 346
        $xh->add_attribute("id", "discogsVideo" . $cnt);
127 - 347
        $xh->add_attribute("type", "button");
348
        $xh->add_attribute("class", "btn btn-info btn-sm");
349
        $xh->add_attribute("data-toggle", "modal");
350
        $xh->add_attribute("data-target", "#videoModal" . $cnt);
351
        $xh->add_attribute("title", "Videos");
352
        $xh->add_attribute("aria-label", "Music videos");
353
        $xh->add_attribute("data-toggle2", "tooltip");
354
        $xh->tag('button');
355
        $xh->add_attribute("class", "material-icons");
356
        $xh->tag('i', "videocam");
357
        $xh->close(); // button
358
 
359
        $xhmod->add_attribute("id", "videoModal" . $cnt);
360
        $xhmod->add_attribute("class", "modal");
361
        $xhmod->tag('div');
362
        $xhmod->add_attribute("class", "modal-dialog");
363
        $xhmod->tag('div');
364
        $xhmod->add_attribute("class", "modal-content");
365
        $xhmod->tag('div');
366
        $xhmod->add_attribute("class", "modal-header bg-secondary");
367
        $xhmod->tag('div');
57 - 368
        if (count($artists) < 5) {
127 - 369
            $str = htmlentities(join(", ", $artists));
65 - 370
        }
371
        else {
127 - 372
            $str = "Various Artists";
57 - 373
        }
127 - 374
        $xhmod->add_attribute("class", "modal-title mx-auto display-6");
375
        $xhmod->tag('p', htmlentities((string)$master->{'title'}) . " by " . $str);
57 - 376
 
127 - 377
        $xhmod->add_attribute("type", "button");
378
        $xhmod->add_attribute("class", "close");
379
        $xhmod->add_attribute("data-dismiss", "modal");
380
        $xhmod->tag('button');
381
        $xhmod->add_attribute("class", "material-icons btn-dismiss");
382
        $xhmod->tag('i', "cancel_presentation");
383
        $xhmod->close(); // button
384
        $xhmod->close(); // div
57 - 385
 
127 - 386
        $xhmod->add_attribute("class", "modal-body mx-auto");
387
        $xhmod->tag('div');
388
        $xhmod->add_attribute("class", "display-6");
389
        $xhmod->tag('p', "Videos");
390
        $xhmod->add_attribute("class", "list-group");
391
        $xhmod->tag('ul');
392
 
45 - 393
        foreach ($master->{'videos'} as $video) {
127 - 394
            $xhmod->add_attribute("class", "list-group-item");
395
            $xhmod->tag('li');
396
            $xhmod->add_attribute("class", "row");
397
            $xhmod->tag('div');
398
            $xhmod->add_attribute("class", "col-1");
399
            $xhmod->tag('div');
400
            $xhmod->add_attribute("class", "svg-yt");
401
            $xhmod->add_attribute("viewBox", "0 0 24 24");
402
            $xhmod->tag('svg');
403
            $xhmod->add_attribute("fill", "currentColor");
404
            $xhmod->add_attribute("d", "M10,15L15.19,12L10,9V15M21.56,7.17C21.69,7.64 21.78,8.27 21.84,9.07C21.91,9.87 21.94,10.56 21.94,11.16L22,12C22,14.19 21.84,15.8 21.56,16.83C21.31,17.73 20.73,18.31 19.83,18.56C19.36,18.69 18.5,18.78 17.18,18.84C15.88,18.91 14.69,18.94 13.59,18.94L12,19C7.81,19 5.2,18.84 4.17,18.56C3.27,18.31 2.69,17.73 2.44,16.83C2.31,16.36 2.22,15.73 2.16,14.93C2.09,14.13 2.06,13.44 2.06,12.84L2,12C2,9.81 2.16,8.2 2.44,7.17C2.69,6.27 3.27,5.69 4.17,5.44C4.64,5.31 5.5,5.22 6.82,5.16C8.12,5.09 9.31,5.06 10.41,5.06L12,5C16.19,5 18.8,5.16 19.83,5.44C20.73,5.69 21.31,6.27 21.56,7.17Z");
405
            $xhmod->single_tag('path');
406
            $xhmod->close(); // svg
407
            $xhmod->close(); // div
408
            $xhmod->add_attribute("class", "col");
409
            $xhmod->tag('div');
410
            $xhmod->add_attribute("href", $video->uri);
411
            $xhmod->add_attribute("target", "_blank");
412
            $xhmod->add_attribute("rel", "noreferrer noopener");
413
            $xhmod->add_attribute("class", "btn btn-light btn-link text-left");
414
            $xhmod->add_attribute("role", "button");
415
            $xhmod->tag('a', htmlentities($video->title) . " [" . gmdate('H:i:s', $video->duration) . "]");
416
            $xhmod->close(); // div
417
            $xhmod->close(); // div
418
            $xhmod->close(); // li
57 - 419
            // bugbug too many videos don't run embedded
420
            // $videoParam = basename($video->uri);
421
            // $videoIdx = strpos($videoParam, "=") + 1;
56 - 422
            // $str .= "<iframe width=\"280\" height=\"158\" src=\"https://www.youtube-nocookie.com/embed/" . substr($videoParam, $videoIdx) . "?rel=0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>";
132 - 423
 
45 - 424
        }
57 - 425
 
127 - 426
        $xhmod->close(); // ul
427
        $xhmod->close(); // div
428
        $xhmod->add_attribute("class", "modal-footer bg-secondary justify-content-between");
429
        $xhmod->tag('div');
430
        $xhmod->add_attribute("class", "font-weight-lighter small");
431
        $xhmod->tag('span');
432
        $xhmod->tag('span', "Data provided by ");
433
 
434
        $xhmod->add_attribute("href", (string)$master->{'uri'});
435
        $xhmod->add_attribute("target", "_blank");
436
        $xhmod->add_attribute("rel", "noreferrer noopener");
437
        $xhmod->tag('a', "Discogs");
438
        $xhmod->close(); // span
439
 
440
        $xhmod->add_attribute("class", "float-right");
441
        $xhmod->tag('span');
442
        $xhmod->add_attribute("type", "button");
443
        $xhmod->add_attribute("class", "btn btn-danger");
444
        $xhmod->add_attribute("data-dismiss", "modal");
445
        $xhmod->tag('button', "Close");
446
        $xhmod->close(); // span
447
        $xhmod->close(); // div
448
        $xhmod->close(); // div
449
        $xhmod->close(); // div
450
        $xhmod->close(); // div
45 - 451
    }
452
 
127 - 453
    $xh->close(); // span
62 - 454
 
127 - 455
    $xh->add_attribute("class", "float-right btn-group-sm");
456
    $xh->tag('span');
45 - 457
 
50 - 458
    $barcode = "";
459
    if (empty($_SESSION["barcode"]['Type']) && !empty($master->{'identifiers'})) {
460
        foreach ($master->{'identifiers'} as $identifier) {
461
            if ($identifier->{'type'} == 'Barcode') {
462
                $tmpBarcode = preg_replace("/[^0-9]/", "", $identifier->{'value'});
463
                $barcodeType = clsLibGTIN::GTINCheck($tmpBarcode, false, 1);
464
                if (!empty($barcodeType)) {
65 - 465
                    $barcode = $tmpBarcode;
50 - 466
                }
467
            }
468
        }
65 - 469
    }
470
    else if (!empty($_SESSION["barcode"]['Type'])) {
50 - 471
        $barcode = $_SESSION["barcode"]['Value'];
472
    }
473
 
46 - 474
    if (isLoggedIn() && !checkWishlist($type, $master->{'id'})) {
65 - 475
        $wlArr = array(
476
            ($type == "master" ? 'mid' : 'rid') => $master->{'id'},
477
            'title' => (string)$master->{'title'},
478
            'artist' => $wlArtists,
479
            'barcode' => $barcode,
480
            'thumbnail' => $thumbnail,
481
            'url' => (string)$master->{'uri'}
482
        );
46 - 483
        $wl = base64_encode(json_encode($wlArr));
127 - 484
 
485
        $xh->add_attribute("id", "wl" . $cnt . "Btn");
486
        $xh->add_attribute("type", "button");
487
        $xh->add_attribute("class", "btn btn-info btn-sm");
488
        $xh->add_attribute("title", "Add to Wishlist");
489
        $xh->add_attribute("aria-label", "Add to Wishlist");
490
        $xh->add_attribute("data-toggle", "tooltip");
130 - 491
        $xh->add_attribute("data-user", $_SESSION['sessData']['userID']);
492
        $xh->add_attribute("data-cnt", $cnt);
493
        $xh->add_attribute("data-wl", $wl);
127 - 494
        $xh->tag('button');
495
        $xh->add_attribute("class", "material-icons");
496
        $xh->tag('i', "bookmark");
497
        $xh->close(); // button
45 - 498
    }
499
 
125 - 500
    $searchTitle = 'Searching for:<br><br><strong>' . htmlentities((string)$master->{'title'}) . ' by ' . (empty($searchArtists) ? 'Various Artists' : htmlentities($searchArtists)) . '</strong>';
50 - 501
    if (!empty($barcode)) {
502
        $searchTitle .= " (" . displayBarcode($barcode) . ")";
503
    }
504
 
127 - 505
    $xh->tag('span', " ");
506
    $xh->add_attribute("id", "discogsSearch" . $cnt . "Btn");
507
    $xh->add_attribute("type", "submit");
508
    $xh->add_attribute("name", "submit");
509
    $xh->add_attribute("value", "discogsSearch");
510
    $xh->add_attribute("class", "btn btn-success btn-sm");
511
    $xh->add_attribute("title", "Search for Store Offers");
512
    $xh->add_attribute("aria-label", "Search for Store Offers");
513
    $xh->add_attribute("data-toggle", "tooltip");
130 - 514
    $xh->add_attribute("data-title", htmlentities((string)$master->{"title"}));
515
    $xh->add_attribute("data-artist", htmlentities($searchArtists));
516
    $xh->add_attribute("data-barcode", $barcode);
517
    $xh->add_attribute("data-search-title", $searchTitle);
127 - 518
    $xh->tag('button');
519
    $xh->add_attribute("class", "material-icons");
520
    $xh->tag('i', "search");
521
    $xh->close(); // button
522
    $xh->close(); // span
523
    $xh->close(); // div
132 - 524
 
127 - 525
    $xh->add_attribute("id", "wishlistAdd" . $cnt);
526
    $xh->tag('span', "");
527
    $xh->close(); // div
14 - 528
 
127 - 529
    $xhmod->add_attribute("id", "masterModal" . $cnt);
530
    $xhmod->add_attribute("class", "modal");
531
    $xhmod->tag('div');
532
    $xhmod->add_attribute("class", "modal-dialog");
533
    $xhmod->tag('div');
534
    $xhmod->add_attribute("class", "modal-content");
535
    $xhmod->tag('div');
536
    $xhmod->add_attribute("class", "modal-header bg-secondary");
537
    $xhmod->tag('div');
20 - 538
    if (count($artists) < 5) {
127 - 539
        $str = htmlentities(join(", ", $artists));
65 - 540
    }
541
    else {
127 - 542
        $str = "Various Artists";
14 - 543
    }
127 - 544
    $xhmod->add_attribute("class", "modal-title mx-auto display-6");
545
    $xhmod->tag('p', htmlentities((string)$master->{'title'}) . " by " . $str);
546
    $xhmod->add_attribute("type", "button");
547
    $xhmod->add_attribute("class", "close");
548
    $xhmod->add_attribute("data-dismiss", "modal");
549
    $xhmod->tag('button');
550
    $xhmod->add_attribute("class", "material-icons btn-dismiss");
551
    $xhmod->tag('i', "cancel_presentation");
552
    $xhmod->close(); // button
553
    $xhmod->close(); // div
14 - 554
 
127 - 555
    $xhmod->add_attribute("class", "modal-body mx-auto");
556
    $xhmod->tag('div');
14 - 557
 
72 - 558
    if (!empty($coverImage) && !preg_match("/spacer.gif$/", $coverImage)) {
127 - 559
        $xhmod->add_attribute("class", "responsive-image mx-auto mb-4 lazyload");
560
        $xhmod->add_attribute("src", $coverImage);
561
        $xhmod->add_attribute("alt", "Discogs Cover");
562
        $xhmod->single_tag('img');
43 - 563
    }
564
 
127 - 565
    $xhmod->add_attribute("class", "table-borderless table-condensed small mx-auto");
566
    $xhmod->tag('table');
14 - 567
 
127 - 568
    $xhmod->tag('tr');
569
    $xhmod->add_attribute("class", "px-1");
570
    $xhmod->tag('td', "Title:");
571
    $xhmod->add_attribute("class", "px-1");
572
    $xhmod->tag('td', htmlentities((string)$master->{'title'}));
573
    $xhmod->close(); // tr
14 - 574
 
127 - 575
    $xhmod->tag('tr');
576
    $xhmod->add_attribute("class", "px-1");
577
    $xhmod->tag('td', "Artist:");
578
    $xhmod->add_attribute("class", "px-1");
579
    $xhmod->tag('td', htmlentities(join(", ", $artists)));
580
    $xhmod->close(); // tr
581
 
50 - 582
    if (!empty($barcode)) {
127 - 583
        $xhmod->tag('tr');
584
        $xhmod->add_attribute("class", "px-1");
585
        $xhmod->tag('td', "Barcode:");
586
        $xhmod->add_attribute("class", "px-1");
587
        $xhmod->tag('td', displayBarcode($barcode));
588
        $xhmod->close(); // tr
50 - 589
    }
590
 
20 - 591
    if (!empty($labels)) {
127 - 592
        $xhmod->tag('tr');
593
        $xhmod->add_attribute("class", "px-1");
594
        $xhmod->tag('td', "Label:");
595
        $xhmod->add_attribute("class", "px-1");
596
        $xhmod->tag('td', htmlentities($labels[0]));
597
        $xhmod->close(); // tr
20 - 598
    }
599
 
600
    if (!empty($formats)) {
127 - 601
        $xhmod->tag('tr');
602
        $xhmod->add_attribute("class", "px-1");
603
        $xhmod->tag('td', "Format:");
604
        $xhmod->add_attribute("class", "px-1");
605
        $xhmod->tag('td', htmlentities(join(", ", $formats)));
606
        $xhmod->close(); // tr
20 - 607
    }
608
 
609
    if (!empty($country)) {
127 - 610
        $xhmod->tag('tr');
611
        $xhmod->add_attribute("class", "px-1");
612
        $xhmod->tag('td', "Country:");
613
        $xhmod->add_attribute("class", "px-1");
614
        $xhmod->tag('td', htmlentities($country));
615
        $xhmod->close(); // tr
20 - 616
    }
617
 
14 - 618
    if ($master->{'year'} > 0) {
127 - 619
        $xhmod->tag('tr');
620
        $xhmod->add_attribute("class", "px-1");
621
        $xhmod->tag('td', "Year:");
622
        $xhmod->add_attribute("class", "px-1");
623
        $xhmod->tag('td', htmlentities((string)$master->{'year'}));
624
        $xhmod->close(); // tr
14 - 625
    }
626
 
127 - 627
    $xhmod->tag('tr');
628
    $xhmod->add_attribute("class", "px-1");
629
    $xhmod->tag('td', "Genre:");
630
    $xhmod->add_attribute("class", "px-1");
631
    $xhmod->tag('td', htmlentities(join(", ", $genres)));
632
    $xhmod->close(); // tr
14 - 633
 
10 - 634
    if (isset($master->{'styles'})) {
635
        $styles = [];
636
        foreach ($master->{'styles'} as $key => $value) {
637
            $styles[] = $value;
638
        }
127 - 639
        $xhmod->tag('tr');
640
        $xhmod->add_attribute("class", "px-1");
641
        $xhmod->tag('td', "Style:");
642
        $xhmod->add_attribute("class", "px-1");
643
        $xhmod->tag('td', htmlentities(join(", ", $styles)));
644
        $xhmod->close(); // tr
10 - 645
    }
14 - 646
 
647
    if (is_array($master->{'tracklist'})) {
127 - 648
        $xhmod->tag('tr');
649
        $xhmod->add_attribute("class", "px-1");
650
        $xhmod->add_attribute("colspan", "2");
651
        $xhmod->tag('td', "Tracks:");
652
        $xhmod->close(); // tr
653
 
654
        $xhmod->tag('tr');
655
        $xhmod->add_attribute("class", "px-1");
656
        $xhmod->add_attribute("colspan", "2");
657
        $xhmod->tag('td');
658
        $xhmod->add_attribute("class", "pl-3 pt-0 small list-unstyled");
659
        $xhmod->tag('ul');
14 - 660
        foreach ($master->{'tracklist'} as $key => $value) {
20 - 661
            if ((string)$value->{'type_'} == "heading") {
127 - 662
                $xhmod->add_attribute("class", "font-weight-bold");
663
                $xhmod->tag('li', htmlentities((string)$value->{'title'}));
65 - 664
            }
665
            else if ((string)$value->{'type_'} == "index") {
127 - 666
                $xhmod->add_attribute("class", "font-italic");
667
                $xhmod->tag('li');
668
                $xhmod->add_attribute("class", "font-italic");
669
                $xhmod->tag('span', htmlentities((string)$value->{'title'}));
14 - 670
                foreach ($value->{'sub_tracks'} as $subkey => $subvalue) {
127 - 671
                    $xhmod->add_attribute("class", "pl-3 pt-0 list-unstyled");
672
                    $xhmod->tag('ul');
673
                    $xhmod->insert_code(processTrack($subvalue, false));
674
                    $xhmod->close(); // ul
17 - 675
                }
127 - 676
                $xhmod->close(); // li
65 - 677
            }
678
            else if ((string)$value->{'type_'} == "track") {
127 - 679
                $xhmod->insert_code(processTrack($value, true));
14 - 680
            }
681
        }
127 - 682
        $xhmod->close(); // ul
683
        $xhmod->close(); // td
684
        $xhmod->close(); // tr
17 - 685
    }
14 - 686
 
127 - 687
    $xhmod->close(); // table
688
    $xhmod->close(); // div
689
    $xhmod->add_attribute("class", "modal-footer bg-secondary justify-content-between");
690
    $xhmod->tag('div');
691
    $xhmod->tag('span');
692
    $xhmod->tag('span', "Data provided by ");
693
    $xhmod->add_attribute("href", (string)$master->{'uri'});
694
    $xhmod->add_attribute("target", "_blank");
695
    $xhmod->add_attribute("rel", "noreferrer noopener");
696
    $xhmod->tag('a', "Discogs");
697
    $xhmod->close(); // span
698
    $xhmod->add_attribute("class", "float-right");
699
    $xhmod->tag('span');
700
    $xhmod->add_attribute("type", "button");
701
    $xhmod->add_attribute("class", "btn btn-danger");
702
    $xhmod->add_attribute("data-dismiss", "modal");
703
    $xhmod->tag('button', "Close");
704
    $xhmod->close(); // span
705
    $xhmod->close(); // div
706
    $xhmod->close(); // div
707
    $xhmod->close(); // div
708
    $xhmod->close(); // div
10 - 709
 
127 - 710
    $html = $xhmod->flush();
711
    //error_log(print_r($html, 1));
712
 
713
    $xh->insert_code($html);
714
    $xh->close(); // div
715
 
716
    $html = $xh->flush();
717
    //error_log(print_r($html, 1));
718
 
719
    return $html;
14 - 720
}
10 - 721
 
14 - 722
function processTrack($value, $posFlag) {
127 - 723
    $xh = new Html;
724
    $xh->init($_SESSION["htmlIndent"]);
725
 
726
    $str = "";
727
 
14 - 728
    if ($posFlag && !empty($value->{'position'})) {
20 - 729
        if (!preg_match("/^[a-zA-Z][0-9]/", (string)$value->{'position'}) && !preg_match("/^[a-zA-Z]$/", (string)$value->{'position'})) {
730
            $str .= (string)$value->{'position'} . '. ';
10 - 731
        }
14 - 732
    }
17 - 733
 
20 - 734
    $str .= (string)$value->{'title'};
10 - 735
 
14 - 736
    $trackArtists = [];
737
    if (isset($value->{'artists'})) {
738
        foreach ($value->{'artists'} as $taKey => $taValue) {
20 - 739
            $trackArtists[] = trim(preg_replace('/\([0-9]+\)$/', "", (string)$taValue->{'name'}));
10 - 740
        }
14 - 741
        if (count($trackArtists)) {
742
            $str .= " - " . join(", ", $trackArtists);
743
        }
744
    }
10 - 745
 
14 - 746
    if (!empty($value->{'duration'})) {
20 - 747
        $str .= " [" . (string)$value->{'duration'} . "]";
10 - 748
    }
13 - 749
 
127 - 750
    $xh->tag('li', $str);
14 - 751
 
127 - 752
    $html = $xh->flush();
753
    //error_log(print_r($html, 1));
754
 
755
    return $html;
14 - 756
}