Subversion Repositories cheapmusic

Rev

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