Subversion Repositories cheapmusic

Rev

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