Subversion Repositories cheapmusic

Rev

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