Subversion Repositories cheapmusic

Rev

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

Rev Author Line No. Line
81 - 1
<?php
2
include_once ('php/constants.php');
3
 
4
error_reporting(E_ALL);
5
 
6
// Get itunes listings
7
function get_amazon($query, $searchCondition) {
8
    $vendors = Vendors::getInstance();
9
    $config = $vendors->getVendor(Vendors::AMAZON);
10
 
11
    $needMatches = empty($_SESSION["discogs"]);
12
    $arrMusic = [];
13
    $arrDigital = [];
82 - 14
    $arrBooks = [];
81 - 15
 
16
    // Music
17
    $arrMusic = get_amazonCategory($config, $query, "Music", $needMatches);
18
 
19
    // Digital Music
20
    if ($_SESSION["filterMediaType"]["Digital"]) {
21
        $arrDigital = get_amazonCategory($config, $query, "MP3Downloads");
22
    }
23
 
24
    if ($_SESSION["filterMediaType"]["Book"]) {
25
        // Books
26
        $arrBooks = get_amazonCategory($config, $query, "Books");
27
    }
28
 
29
    return (array_merge($arrMusic, $arrDigital, $arrBooks));
30
}
31
 
32
// Get Amazon listings
33
function get_amazonCategory($config, $query, $searchIndex, $needMatches = false) {
34
    // API request variables
35
    $access_key_id = $config["access_key_id"];
36
    $secret_key = $config["secret_key"];
37
    $endpoint = $config["endpoint"];
38
    $uri = $config["uri"];
39
    $associate_tag = $config["associate_tag"];
40
 
41
    if ($needMatches) {
42
        $_SESSION["discogs"] = "";
43
    }
44
 
45
    $params = array(
46
        "Service" => "AWSECommerceService",
47
        "Operation" => "ItemSearch",
48
        "AWSAccessKeyId" => $access_key_id,
49
        "AssociateTag" => $associate_tag,
50
        "SearchIndex" => $searchIndex,
51
        "Keywords" => $query,
52
        "ResponseGroup" => "ItemAttributes,Images,Offers,OfferFull,Tracks",
53
        "Condition" => "All", /* New, Used, Collectible, Refurbished */
54
        "Sort" => "price",
55
        "Availability" => "Available",
56
        "Timestamp" => gmdate('Y-m-d\TH:i:s\Z')
57
    );
58
 
59
    // Sort the parameters by key
60
    ksort($params);
61
 
62
    $pairs = array();
63
 
64
    foreach ($params as $key => $value) {
65
        array_push($pairs, rawurlencode($key)."=".rawurlencode($value));
66
    }
67
 
68
    // Generate the canonical query
69
    $canonical_query_string = join("&", $pairs);
70
 
71
    // Generate the string to be signed
72
    $string_to_sign = "GET\n".$endpoint."\n".$uri."\n".$canonical_query_string;
73
 
74
    // Generate the signature required by the Product Advertising API
75
    $signature = base64_encode(hash_hmac("sha256", $string_to_sign, $secret_key, true));
76
 
77
    // Generate the signed URL
78
    $url = 'https://'.$endpoint.$uri.'?'.$canonical_query_string.'&Signature='.rawurlencode($signature);
79
 
80
    $result = getUrl($url);
81
    $parsed_xml = simplexml_load_string($result);
82
 
83
    $arr = [];
84
 
82 - 85
    // echo "<br><br>$url<br><pre>";print_r($parsed_xml);echo "</pre>";
81 - 86
    // Check to see if the request found any results
87
    if (!empty($parsed_xml->Items->Request->IsValid)) {
88
        $valid = (bool)(string)$parsed_xml->Items->Request->IsValid;
89
    }else {
90
        $valid = false;
91
    }
92
 
93
    if ($valid) {
94
        if ($needMatches) {
95
            $cnt = 0;
96
            $_SESSION["discogs"] = startMatches();
97
        }
98
 
99
        // If the response was loaded, parse it and store in array
100
        foreach($parsed_xml->Items->Item as $current){
82 - 101
            // [ProductGroup] => Digital Music Album
102
            if ($searchIndex == "MP3Downloads" && !empty($current->ItemAttributes->TrackSequence)) {
103
                continue; // skip individual songs
104
            }
105
 
81 - 106
            if (isset($current->ItemAttributes->UPC)) {
107
                $barcode = (string)$current->ItemAttributes->UPC;
108
            } else if (isset($current->ItemAttributes->EAN)) {
109
                $barcode = (string)$current->ItemAttributes->EAN;
110
            } else if (isset($current->ItemAttributes->ISBN)) {
111
                $barcode = (string)$current->ItemAttributes->ISBN;
112
            } else if (isset($current->ItemAttributes->EISBN)) {
113
                $barcode = (string)$current->ItemAttributes->EISBN;
114
            } else {
115
                $barcode = "";
116
            }
117
            $barcodeType = clsLibGTIN::GTINCheck($barcode, false, 1);
118
 
119
            $pic = str_replace('http://', 'https://', (string)$current->MediumImage->URL);
120
            if (empty($pic)) {
121
                continue;
122
            }
123
 
124
            if (strpos($current->ItemAttributes->Binding, "CD") !== false) {
125
                $mediaType = "CD";
126
            } else if (strpos($current->ItemAttributes->Binding, "MP3") !== false) {
127
                $mediaType = "Digital";
128
            } else if (strpos($current->ItemAttributes->Binding, "Vinyl") !== false) {
129
                $mediaType = "Record";
82 - 130
            } else if (strpos($current->ItemAttributes->Binding, "Paperback") !== false ||
131
                       strpos($current->ItemAttributes->Binding, "Sheet") !== false ||
132
                       strpos($current->ItemAttributes->Binding, "Hardcover") !== false) {
133
                $mediaType = "Book";
81 - 134
            } else {
82 - 135
                continue;
81 - 136
            }
137
 
138
            if ($needMatches) {
139
                // bugbug: check maxMasterCnt?
140
                $_SESSION["discogs"] .= addMatch($current, ++$cnt, $mediaType);
141
            }
142
 
143
            $title = (string)$current->ItemAttributes->Title;
144
            $artists = getArtists($current);
145
            $creators = getCreators($current);
146
            if (!empty($artists)) {
147
                $title .= " by " . join(", ", $artists);
148
            } else if (!empty($creators)) {
149
                $title .= " by " . join(", ", $creators);
150
            }
151
 
152
            $url = str_replace('http://', 'https://', (string)$current->DetailPageURL);
153
 
154
            if (empty($url)) {
155
                continue;
156
            }
157
 
158
            $country = 'US';
159
            $bestOffer = false;
160
 
161
            foreach($current->ItemLinks->ItemLink as $link) {
162
                if ($link->Description == "All Offers") {
163
                    $url = str_replace('http://', 'https://', (string)$link->URL);
164
                    $url .= "&condition=";
165
                }
166
            }
167
 
168
            if (!empty($current->Offers->Offer)) {
169
                foreach($current->Offers->Offer as $offer){
170
                    $merchantName = "Amazon";
171
                    if (strpos($offer->Merchant->Name, "Amazon") === false) {
172
                        $merchantName .= " Marketplace";
173
                    }
174
 
175
                    $condition = (string)$offer->OfferAttributes->Condition;
176
                    $url .= $condition;
177
                    $detailCondition = $condition;
178
                    if ($condition == "Collectible") { $condition = 'Used'; $detailCondition = "Collectible"; }
179
                    $currency = (string)$offer->OfferListing->Price->CurrencyCode;
180
                    $price = number_format(floatval($offer->OfferListing->Price->Amount) / 100.00, 2, '.', '');
181
 
182
                    if ($price <= "0.00") {
183
                        continue;
184
                    }
185
 
186
                    $timeLeft = 0;
187
                    $listingType = 'Fixed';
188
                    $location = 'US';
189
                    $zip = '';
190
                    $feedbackScore = -1;
191
                    $feedbackPercent = -1;
192
                    $sellerName = "";
193
                    if ($offer->OfferListing->AvailabilityAttributes->MaximumHours == 0) {
194
                        $handlingTime = 1;
195
                    } else {
196
                        $handlingTime = (int)($offer->OfferListing->AvailabilityAttributes->MaximumHours / 24);
197
                    }
198
                    if (!empty($offer->OfferListing->IsEligibleForPrime)) {
199
                        $sellerName = "Prime";
200
                    }
201
                    if ($mediaType == "Digital") {
202
                        $shippingCost = 0.00;
203
                        $shippingEstimated = false;
204
                        $shippingCurrency = 'USD';
205
                    } else {
206
                        $shippingCost = 3.99; // bugbug
207
                        $shippingEstimated = true; // bugbug
208
                        $shippingCurrency = 'USD';
209
                    }
210
                    $freeShippingCap = !empty($offer->OfferListing->IsEligibleForSuperSaverShipping) ? 25 : 0;
211
 
212
                    $arr[] = array(
213
                        "Merchant" => $merchantName,
214
                        "Condition" => $condition,
215
                        "Title" => $title,
216
                        "Barcode" => $barcode,
217
                        "BarcodeType" => $barcodeType,
218
                        "Image" => $pic,
219
                        "URL" => $url,
220
                        "MediaType" => $mediaType,
221
                        "DetailCondition" => $detailCondition,
222
                        "Country" => $country,
223
                        "BestOffer" => $bestOffer,
224
                        "TimeLeft" => $timeLeft,
225
                        "Price" => $price,
226
                        "Currency" => $currency,
227
                        "ListingType" => $listingType,
228
                        "Location" => $location,
229
                        "Zip" => $zip,
230
                        "FeedbackScore" => $feedbackScore,
231
                        "FeedbackPercent" => $feedbackPercent,
232
                        "SellerName" => $sellerName,
233
                        "HandlingTime" => $handlingTime,
234
                        "ShippingCost" => $shippingCost,
235
                        "ShippingEstimated" => $shippingEstimated,
236
                        "ShippingCurrency" => $shippingCurrency,
237
                        "FreeShippingCap" => $freeShippingCap,
238
                        "Show" => true
239
                    );
240
                }
241
            }
242
        }
243
 
244
        if ($needMatches) {
245
            if ($cnt = 0) {
246
                $_SESSION["discogs"] = "";
247
            } else {
248
                $_SESSION["discogs"] .= endMatches();
249
            }
250
        }
251
    }
252
    // If the response does not indicate 'Success,' log the error(s)
253
    else {
254
        error_log($url);
255
        if (!empty($parsed_xml->OperationRequest->Errors)) {
256
            foreach($parsed_xml->OperationRequest->Errors->Error as $error){
257
                error_log($error->Message . " (" . $error->Code . ")");
258
            }
259
        } else if (!empty($parsed_xml->Errors)) {
260
            foreach($parsed_xml->OperationRequest->Errors->Error as $error){
261
                error_log($error->Message . " (" . $error->Code . ")");
262
            }
263
        } else if (!empty($parsed_xml->Error)) {
264
            error_log($parsed_xml->Error->Message . " (" . $parsed_xml->Error->Code . ")");
265
        } else {
266
            error_log(print_r($result, 1));
267
        }
268
    }
269
 
270
    return $arr;
271
}
272
 
273
function startMatches() {
274
    $str = "<div class=\"container-fluid bg-secondary\">";
275
    $str .= "<h4 class=\"text-center py-2\">Matching Albums</h4>";
276
    $str .= "<form method=\"post\" action=\"/index.php\">";
277
    $str .= "<input type=\"hidden\" name=\"sessionTab\" value=\"" . MySessionHandler::getSessionTab() . "\">";
278
    $str .= "<input id=\"discogsTitle\" type=\"hidden\" name=\"discogsTitle\" value=\"\">";
279
    $str .= "<input id=\"discogsArtist\" type=\"hidden\" name=\"discogsArtist\" value=\"\">";
280
    $str .= "<input id=\"discogsBarcode\" type=\"hidden\" name=\"discogsBarcode\" value=\"\">";
281
    $str .= "<div id=\"discogsDeck\" class=\"card-deck\">";
282
 
283
    return $str;
284
}
285
 
286
function endMatches() {
287
    $str = "</div>";
288
    $str .= "</form>";
289
    $str .= "</div>";
290
 
291
 
292
    return $str;
293
}
294
 
295
function addMatch($item, $cnt, $mediaType) {
296
    $artists = getArtists($item);
297
 
298
    $creators = getCreators($item);
299
 
300
    $actors = [];
301
    if (!empty($item->ItemAttributes->Actor)) {
302
        foreach($item->ItemAttributes->Actor as $actor) {
303
            $actors[] = $actor;
304
        }
305
    }
306
 
307
    $authors = [];
308
    if (!empty($item->ItemAttributes->Author)) {
309
        foreach($item->ItemAttributes->Author as $author) {
310
            $authors[] = $author;
311
        }
312
    }
313
 
314
    $directors = [];
315
    if (!empty($item->ItemAttributes->Director)) {
316
        foreach($item->ItemAttributes->Director as $director) {
317
            $directors[] = $director;
318
        }
319
    }
320
 
321
    $genres = [];
322
    if (!empty($item->ItemAttributes->Genre)) {
323
        foreach($item->ItemAttributes->Genre as $genre) {
324
            $genres[] = join(" ", array_map('ucfirst', explode('-', $genre)));
325
        }
326
    }
327
 
328
    $labels = [];
329
    if (!empty($item->ItemAttributes->Label)) {
330
        foreach($item->ItemAttributes->Label as $label) {
331
            $labels[] = $label;
332
        }
333
    }
334
 
335
    $languages = [];
336
    if (!empty($item->ItemAttributes->Languages->Language)) {
337
        foreach($item->ItemAttributes->Languages->Language as $language) {
338
            if ((string)$language->Type != "Unknown") {
339
                $languages[] = $language->Name . " (" . $language->Type . ")";
340
            }
341
        }
342
    }
343
 
344
    $runningTime = "";
345
    if (!empty($item->ItemAttributes->RunningTime)) {
346
        if ($mediaType != 'Digital') {
347
            $runningTime = (string)$item->ItemAttributes->RunningTime . " minutes";
348
        } else {
349
            $runningTime = gmdate("H:i:s", (int)$item->ItemAttributes->RunningTime);
350
        }
351
    }
352
 
353
    $modal = "";
354
    $str = "<div class=\"card mx-auto discogs-card\">";
355
    $str .= "<div class=\"card-header bg-info d-flex h-100\">";
356
    $str .= "<p class=\"card-title font-weight-bold small flex-grow-1\">" . (string)$item->ItemAttributes->Title . " by ";
357
    $searchArtists = "";
358
    if (count($artists) < 5) {
359
        $wlArtists = join(", ", $artists);
360
        if (!empty($artists) && $artists[0] != 'Various') {
361
            $searchArtists = join(" ", $artists);
362
        }
363
    }
364
    else {
365
        $wlArtists = "Various Artists";
366
    }
367
    $str .= $wlArtists;
368
    $str .= "</p>";
369
    $str .= "</div>";
370
 
371
    $thumbnail = !empty($item->MediumImage->URL) ? (string)$item->MediumImage->URL : "images/no-image-available.jpg";
372
 
373
    $str .= "<div class=\"card-body bg-light mx-auto p-0 m-0\">";
374
    $str .= "<img class=\"btn responsive-image p-0 m-0\" src=\"" . $thumbnail . "\" data-toggle=\"modal\" data-target=\"#masterModal" . $cnt . "\" title=\"Album Information\" data-toggle2=\"tooltip\" alt=\"Cover Thumbnail\">";
375
    $str .= "</div>";
376
    $str .= "<div class=\"card-footer bg-dark p-0 m-0\">";
377
    $str .= "<div class=\"container clearfix p-0 m-0\">";
378
    $str .= "<span class=\"float-left\">";
379
    $str .= "<button type=\"button\" class=\"btn btn-primary m-1 btn-sm\" data-toggle=\"modal\" data-target=\"#masterModal" . $cnt . "\" title=\"Album Information\" data-toggle2=\"tooltip\"><i class=\"fas fa-info\"></i></button>";
380
 
381
    $str .= "</span>";
382
 
383
    $str .= "<span class=\"float-right\">";
384
 
385
    $barcode = "";
386
    $tmpBarcode = "";
387
    if (!empty($item->ItemAttributes->UPC)) {
388
        $tmpBarcode = (string)$item->ItemAttributes->UPC;
389
    } else if (!empty($item->ItemAttributes->EAN)) {
390
        $tmpBarcode = (string)$item->ItemAttributes->EAN;
391
    } else if (!empty($item->ItemAttributes->ISBN)) {
392
        $tmpBarcode = (string)$item->ItemAttributes->ISBN;
393
    } else if (!empty($item->ItemAttributes->EISBN)) {
394
        $tmpBarcode = (string)$item->ItemAttributes->EISBN;
395
    }
396
    $barcodeType = clsLibGTIN::GTINCheck($tmpBarcode, false, 1);
397
    if (!empty($barcodeType)) {
398
        $barcode = $tmpBarcode;
399
    }
400
 
401
    if (isLoggedIn() && !checkWishlist('asin', $item->ASIN)) {
402
        $wlArr = array(
403
            'asin' => (string)$item->ASIN,
404
            'title' => (string)$item->ItemAttributes->Title,
405
            'artist' => $wlArtists,
406
            'barcode' => $barcode,
407
            'thumbnail' => $thumbnail,
408
            'url' => (string)$item->DetailPageURL
409
        );
410
        $wl = base64_encode(json_encode($wlArr));
411
        $str .= "  <button type=\"button\" class=\"btn btn-primary m-1 btn-sm\" onclick=\"addWishlist('" . $_SESSION['sessData']['userID'] . "',this," . $cnt . ",'" . $wl . "');\" title=\"Add to Wishlist\" data-toggle=\"tooltip\"><i class=\"fas fa-bookmark\"></i></button>";
412
    }
413
 
414
    $searchTitle = 'Searching for:<br><br><strong>' . (string)$item->ItemAttributes->Title . ' by' . $wlArtists . '</strong>';
415
    if (!empty($barcode)) {
416
        $searchTitle .= " (" . displayBarcode($barcode) . ")";
417
    }
418
 
419
    $str .= "  <button type=\"submit\" name=\"submit\" value=\"discogsSearch\" class=\"btn btn-primary m-1 btn-sm\" onclick=\"document.getElementById('discogsTitle').value = '" . addslashes((string)$item->ItemAttributes->Title) . "';document.getElementById('discogsArtist').value = '" . addslashes($searchArtists) . "';document.getElementById('discogsBarcode').value = '" . $barcode . "';progressBar('" . sanitizeInput2($searchTitle) . "');\" title=\"Search for Sales Offers\" data-toggle=\"tooltip\"><i class=\"fas fa-search\"></i></button>";
420
    $str .= "</span>";
421
    $str .= "</div>";
422
    $str .= "<span id=\"wishlistAdd" . $cnt . "\"></span>";
423
    $str .= "</div>";
424
 
425
    $modal .= "<div id=\"masterModal" . $cnt . "\" class=\"modal\">";
426
    $modal .= "<div class=\"modal-dialog\">";
427
    $modal .= "<div class=\"modal-content\">";
428
    $modal .= "<div class=\"modal-header bg-primary\">";
429
    $modal .= "<h4 class=\"modal-title mx-auto\">" . (string)$item->ItemAttributes->Title . " by " . $wlArtists . "</h4>";
430
    $modal .= "<button type=\"button\" class=\"close\" data-dismiss=\"modal\"><i class=\"fas fa-window-close btn-dismiss\"></i></button>";
431
    $modal .= "</div>";
432
 
433
    $modal .= "<div class=\"modal-body bg-white mx-auto\">";
434
 
435
    if (!empty($item->LargeImage->URL)) {
436
        $modal .= "<img class=\"responsive-image mx-auto mb-4\" src=\"" . (string)$item->LargeImage->URL . "\" alt=\"Cover Image\">";
437
    }
438
 
439
    $modal .= "<table class=\"table-borderless table-condensed small mx-auto\">";
440
    $modal .= "<tr><td class=\"px-1\">Title:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->Title . "</td></tr>";
441
 
442
    $modal .= "<tr><td class=\"px-1\">Artist:</td><td class=\"px-1\">" . join(", ", $artists) . "</td></tr>";
443
    if (!empty($creators)) {
444
        $modal .= "<tr><td class=\"px-1\">Creator:</td><td class=\"px-1\">" . join(", ", $creators) . "</td></tr>";
445
    }
446
 
447
    if (!empty($actors)) {
448
        $modal .= "<tr><td class=\"px-1\">Actor:</td><td class=\"px-1\">" . join(", ", $actors) . "</td></tr>";
449
    }
450
 
451
    if (!empty($directors)) {
452
        $modal .= "<tr><td class=\"px-1\">Director:</td><td class=\"px-1\">" . join(", ", $directors) . "</td></tr>";
453
    }
454
 
455
    if (!empty($authors)) {
456
        $modal .= "<tr><td class=\"px-1\">Author:</td><td class=\"px-1\">" . join(", ", $authors) . "</td></tr>";
457
    }
458
 
459
    if (!empty($item->ItemAttributes->Binding)) {
460
        $modal .= "<tr><td class=\"px-1\">Type:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->Binding . "</td></tr>";
461
    }
462
 
463
    if (!empty($item->ItemAttributes->MediaType)) {
464
        $modal .= "<tr><td class=\"px-1\">Media Type:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->MediaType . "</td></tr>";
465
    }
466
 
467
    if (!empty($barcode)) {
468
        $modal .= "<tr><td class=\"px-1\">Barcode:</td><td class=\"px-1\">" . displayBarcode($barcode) . "</td></tr>";
469
    }
470
 
471
    if (!empty($labels)) {
472
        $modal .= "<tr><td class=\"px-1\">Label:</td><td class=\"px-1\">" . $labels[0] . "</td></tr>";
473
    } else if (!empty($item->ItemAttributes->Publisher)) {
474
        $modal .= "<tr><td class=\"px-1\">Publisher:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->Publisher . "</td></tr>";
475
    } else if (!empty($item->ItemAttributes->Studio)) {
476
        $modal .= "<tr><td class=\"px-1\">Studio:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->Studio . "</td></tr>";
477
    }
478
 
479
    if (!empty($languages)) {
480
        $modal .= "<tr><td class=\"px-1\">Languages:</td><td class=\"px-1\">" . join(", ", $languages) . "</td></tr>";
481
    }
482
 
483
    if (!empty($item->ItemAttributes->PublicationDate)) {
484
        $modal .= "<tr><td class=\"px-1\">Publication Date:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->PublicationDate . "</td></tr>";
485
    }
486
 
487
    if (!empty($item->ItemAttributes->ReleaseDate)) {
488
        $modal .= "<tr><td class=\"px-1\">Release Date:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->ReleaseDate . "</td></tr>";
489
    }
490
 
491
    if (!empty($genres)) {
492
        $modal .= "<tr><td class=\"px-1\">Genre:</td><td class=\"px-1\">" . join(", ", $genres) . "</td></tr>";
493
    }
494
 
495
    if (!empty($item->ItemAttributes->NumberOfDiscs)) {
496
        $modal .= "<tr><td class=\"px-1\">Number of Discs:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->NumberOfDiscs . "</td></tr>";
497
    }
498
 
499
    if (!empty($item->ItemAttributes->NumberOfPages)) {
500
        $modal .= "<tr><td class=\"px-1\">Number of Pages:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->NumberOfPages . "</td></tr>";
501
    }
502
 
503
    if (!empty($item->ItemAttributes->RunningTime)) {
504
        $modal .= "<tr><td class=\"px-1\">Running Time:</td><td class=\"px-1\">" . $runningTime . "</td></tr>";
505
    }
506
 
507
    if (!empty($item->ItemAttributes->Edition)) {
508
        $modal .= "<tr><td class=\"px-1\">Edition:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->Edition . "</td></tr>";
509
    }
510
 
511
    if (!empty($item->ItemAttributes->AudienceRating)) {
512
        $modal .= "<tr><td class=\"px-1\">Rating:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->AudienceRating . "</td></tr>";
513
    }
514
 
515
    if (!empty($item->ItemAttributes->RegionCode)) {
516
        $modal .= "<tr><td class=\"px-1\">Region Code:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->RegionCode . "</td></tr>";
517
    }
518
 
519
    if (!empty($item->Tracks)) {
520
        $modal .= "<tr><td colspan=\"2\" class=\"px-1\">Tracks:</td></tr>";
521
        $modal .= "<tr><td colspan=\"2\">";
522
        $modal .= "<ul class=\"pl-3 pt-0 small list-unstyled\">";
523
        foreach ($item->Tracks->Disc as $disc) {
524
            if ((int)$item->ItemAttributes->NumberOfDiscs > 1) {
525
                $modal .= "<li class=\"font-weight-bold\">Disc " . $disc->attributes() . ":</li>";
526
            }
527
 
528
            foreach($disc->Track as $track) {
529
                $modal .= "<li>" . $track->attributes() . ") " . $track . "</li>";
530
            }
531
        }
532
        $modal .= "</ul>";
533
        $modal .= "</td></tr>";
534
    }
535
 
536
    $modal .= "</table>";
537
    $modal .= "</div>";
538
    $modal .= "<div class=\"modal-footer bg-white justify-content-between\">";
539
    $modal .= "<span class=\"float-right\"><button type=\"button\" class=\"btn btn-danger\" data-dismiss=\"modal\">Close</button></span>";
540
    $modal .= "</div>";
541
    $modal .= "</div>";
542
    $modal .= "</div>";
543
    $modal .= "</div>";
544
    $str .= $modal;
545
    $str .= "</div>";
546
 
547
    return $str;
548
}
549
 
550
function getArtists($item) {
551
    $artists = [];
552
 
553
    if (!empty($item->ItemAttributes->Artist)) {
554
        foreach($item->ItemAttributes->Artist as $artist) {
555
            $artists[] = $artist;
556
        }
557
    }
558
 
559
    return $artists;
560
}
561
 
562
function getCreators($item) {
563
    $creators = [];
564
 
565
    if (!empty($item->ItemAttributes->Creator)) {
566
        foreach($item->ItemAttributes->Creator as $creator) {
567
            if ((string)$creator->attributes() == "Primary Contributor") {
82 - 568
                $creators[] = $creator;
81 - 569
            } else {
570
                $creators[] = $creator . " (" . $creator->attributes() . ")";
571
            }
572
        }
573
    }
574
 
575
    return $creators;
576
}