Subversion Repositories cheapmusic

Rev

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