Subversion Repositories cheapmusic

Rev

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

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