Subversion Repositories cheapmusic

Rev

Rev 82 | Rev 94 | 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"; }
86 - 179
                    if ($condition == "Refurbished") { $condition = 'Used'; $detailCondition = "Refurbished"; }
81 - 180
                    $currency = (string)$offer->OfferListing->Price->CurrencyCode;
181
                    $price = number_format(floatval($offer->OfferListing->Price->Amount) / 100.00, 2, '.', '');
182
 
183
                    if ($price <= "0.00") {
184
                        continue;
185
                    }
186
 
187
                    $timeLeft = 0;
188
                    $listingType = 'Fixed';
189
                    $location = 'US';
190
                    $zip = '';
191
                    $feedbackScore = -1;
192
                    $feedbackPercent = -1;
193
                    $sellerName = "";
194
                    if ($offer->OfferListing->AvailabilityAttributes->MaximumHours == 0) {
195
                        $handlingTime = 1;
196
                    } else {
197
                        $handlingTime = (int)($offer->OfferListing->AvailabilityAttributes->MaximumHours / 24);
198
                    }
199
                    if (!empty($offer->OfferListing->IsEligibleForPrime)) {
200
                        $sellerName = "Prime";
201
                    }
202
                    if ($mediaType == "Digital") {
203
                        $shippingCost = 0.00;
204
                        $shippingEstimated = false;
205
                        $shippingCurrency = 'USD';
206
                    } else {
207
                        $shippingCost = 3.99; // bugbug
208
                        $shippingEstimated = true; // bugbug
209
                        $shippingCurrency = 'USD';
210
                    }
211
                    $freeShippingCap = !empty($offer->OfferListing->IsEligibleForSuperSaverShipping) ? 25 : 0;
212
 
213
                    $arr[] = array(
214
                        "Merchant" => $merchantName,
215
                        "Condition" => $condition,
216
                        "Title" => $title,
217
                        "Barcode" => $barcode,
218
                        "BarcodeType" => $barcodeType,
219
                        "Image" => $pic,
220
                        "URL" => $url,
221
                        "MediaType" => $mediaType,
222
                        "DetailCondition" => $detailCondition,
223
                        "Country" => $country,
224
                        "BestOffer" => $bestOffer,
225
                        "TimeLeft" => $timeLeft,
226
                        "Price" => $price,
227
                        "Currency" => $currency,
228
                        "ListingType" => $listingType,
229
                        "Location" => $location,
230
                        "Zip" => $zip,
231
                        "FeedbackScore" => $feedbackScore,
232
                        "FeedbackPercent" => $feedbackPercent,
233
                        "SellerName" => $sellerName,
234
                        "HandlingTime" => $handlingTime,
235
                        "ShippingCost" => $shippingCost,
236
                        "ShippingEstimated" => $shippingEstimated,
237
                        "ShippingCurrency" => $shippingCurrency,
238
                        "FreeShippingCap" => $freeShippingCap,
239
                        "Show" => true
240
                    );
241
                }
242
            }
243
        }
244
 
245
        if ($needMatches) {
246
            if ($cnt = 0) {
247
                $_SESSION["discogs"] = "";
248
            } else {
249
                $_SESSION["discogs"] .= endMatches();
250
            }
251
        }
252
    }
253
    // If the response does not indicate 'Success,' log the error(s)
254
    else {
255
        error_log($url);
256
        if (!empty($parsed_xml->OperationRequest->Errors)) {
257
            foreach($parsed_xml->OperationRequest->Errors->Error as $error){
258
                error_log($error->Message . " (" . $error->Code . ")");
259
            }
260
        } else if (!empty($parsed_xml->Errors)) {
261
            foreach($parsed_xml->OperationRequest->Errors->Error as $error){
262
                error_log($error->Message . " (" . $error->Code . ")");
263
            }
264
        } else if (!empty($parsed_xml->Error)) {
265
            error_log($parsed_xml->Error->Message . " (" . $parsed_xml->Error->Code . ")");
266
        } else {
267
            error_log(print_r($result, 1));
268
        }
269
    }
270
 
271
    return $arr;
272
}
273
 
274
function startMatches() {
275
    $str = "<div class=\"container-fluid bg-secondary\">";
276
    $str .= "<h4 class=\"text-center py-2\">Matching Albums</h4>";
277
    $str .= "<form method=\"post\" action=\"/index.php\">";
278
    $str .= "<input type=\"hidden\" name=\"sessionTab\" value=\"" . MySessionHandler::getSessionTab() . "\">";
279
    $str .= "<input id=\"discogsTitle\" type=\"hidden\" name=\"discogsTitle\" value=\"\">";
280
    $str .= "<input id=\"discogsArtist\" type=\"hidden\" name=\"discogsArtist\" value=\"\">";
281
    $str .= "<input id=\"discogsBarcode\" type=\"hidden\" name=\"discogsBarcode\" value=\"\">";
282
    $str .= "<div id=\"discogsDeck\" class=\"card-deck\">";
283
 
284
    return $str;
285
}
286
 
287
function endMatches() {
288
    $str = "</div>";
289
    $str .= "</form>";
290
    $str .= "</div>";
291
 
292
 
293
    return $str;
294
}
295
 
296
function addMatch($item, $cnt, $mediaType) {
297
    $artists = getArtists($item);
298
 
299
    $creators = getCreators($item);
300
 
301
    $actors = [];
302
    if (!empty($item->ItemAttributes->Actor)) {
303
        foreach($item->ItemAttributes->Actor as $actor) {
304
            $actors[] = $actor;
305
        }
306
    }
307
 
308
    $authors = [];
309
    if (!empty($item->ItemAttributes->Author)) {
310
        foreach($item->ItemAttributes->Author as $author) {
311
            $authors[] = $author;
312
        }
313
    }
314
 
315
    $directors = [];
316
    if (!empty($item->ItemAttributes->Director)) {
317
        foreach($item->ItemAttributes->Director as $director) {
318
            $directors[] = $director;
319
        }
320
    }
321
 
322
    $genres = [];
323
    if (!empty($item->ItemAttributes->Genre)) {
324
        foreach($item->ItemAttributes->Genre as $genre) {
325
            $genres[] = join(" ", array_map('ucfirst', explode('-', $genre)));
326
        }
327
    }
328
 
329
    $labels = [];
330
    if (!empty($item->ItemAttributes->Label)) {
331
        foreach($item->ItemAttributes->Label as $label) {
332
            $labels[] = $label;
333
        }
334
    }
335
 
336
    $languages = [];
337
    if (!empty($item->ItemAttributes->Languages->Language)) {
338
        foreach($item->ItemAttributes->Languages->Language as $language) {
339
            if ((string)$language->Type != "Unknown") {
340
                $languages[] = $language->Name . " (" . $language->Type . ")";
341
            }
342
        }
343
    }
344
 
345
    $runningTime = "";
346
    if (!empty($item->ItemAttributes->RunningTime)) {
347
        if ($mediaType != 'Digital') {
348
            $runningTime = (string)$item->ItemAttributes->RunningTime . " minutes";
349
        } else {
350
            $runningTime = gmdate("H:i:s", (int)$item->ItemAttributes->RunningTime);
351
        }
352
    }
353
 
354
    $modal = "";
355
    $str = "<div class=\"card mx-auto discogs-card\">";
356
    $str .= "<div class=\"card-header bg-info d-flex h-100\">";
357
    $str .= "<p class=\"card-title font-weight-bold small flex-grow-1\">" . (string)$item->ItemAttributes->Title . " by ";
358
    $searchArtists = "";
359
    if (count($artists) < 5) {
360
        $wlArtists = join(", ", $artists);
361
        if (!empty($artists) && $artists[0] != 'Various') {
362
            $searchArtists = join(" ", $artists);
363
        }
364
    }
365
    else {
366
        $wlArtists = "Various Artists";
367
    }
368
    $str .= $wlArtists;
369
    $str .= "</p>";
370
    $str .= "</div>";
371
 
372
    $thumbnail = !empty($item->MediumImage->URL) ? (string)$item->MediumImage->URL : "images/no-image-available.jpg";
373
 
374
    $str .= "<div class=\"card-body bg-light mx-auto p-0 m-0\">";
375
    $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\">";
376
    $str .= "</div>";
377
    $str .= "<div class=\"card-footer bg-dark p-0 m-0\">";
378
    $str .= "<div class=\"container clearfix p-0 m-0\">";
379
    $str .= "<span class=\"float-left\">";
380
    $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>";
381
 
382
    $str .= "</span>";
383
 
384
    $str .= "<span class=\"float-right\">";
385
 
386
    $barcode = "";
387
    $tmpBarcode = "";
388
    if (!empty($item->ItemAttributes->UPC)) {
389
        $tmpBarcode = (string)$item->ItemAttributes->UPC;
390
    } else if (!empty($item->ItemAttributes->EAN)) {
391
        $tmpBarcode = (string)$item->ItemAttributes->EAN;
392
    } else if (!empty($item->ItemAttributes->ISBN)) {
393
        $tmpBarcode = (string)$item->ItemAttributes->ISBN;
394
    } else if (!empty($item->ItemAttributes->EISBN)) {
395
        $tmpBarcode = (string)$item->ItemAttributes->EISBN;
396
    }
397
    $barcodeType = clsLibGTIN::GTINCheck($tmpBarcode, false, 1);
398
    if (!empty($barcodeType)) {
399
        $barcode = $tmpBarcode;
400
    }
401
 
402
    if (isLoggedIn() && !checkWishlist('asin', $item->ASIN)) {
403
        $wlArr = array(
404
            'asin' => (string)$item->ASIN,
405
            'title' => (string)$item->ItemAttributes->Title,
406
            'artist' => $wlArtists,
407
            'barcode' => $barcode,
408
            'thumbnail' => $thumbnail,
409
            'url' => (string)$item->DetailPageURL
410
        );
411
        $wl = base64_encode(json_encode($wlArr));
412
        $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>";
413
    }
414
 
415
    $searchTitle = 'Searching for:<br><br><strong>' . (string)$item->ItemAttributes->Title . ' by' . $wlArtists . '</strong>';
416
    if (!empty($barcode)) {
417
        $searchTitle .= " (" . displayBarcode($barcode) . ")";
418
    }
419
 
86 - 420
    $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 Store Offers\" data-toggle=\"tooltip\"><i class=\"fas fa-search\"></i></button>";
81 - 421
    $str .= "</span>";
422
    $str .= "</div>";
423
    $str .= "<span id=\"wishlistAdd" . $cnt . "\"></span>";
424
    $str .= "</div>";
425
 
426
    $modal .= "<div id=\"masterModal" . $cnt . "\" class=\"modal\">";
427
    $modal .= "<div class=\"modal-dialog\">";
428
    $modal .= "<div class=\"modal-content\">";
429
    $modal .= "<div class=\"modal-header bg-primary\">";
430
    $modal .= "<h4 class=\"modal-title mx-auto\">" . (string)$item->ItemAttributes->Title . " by " . $wlArtists . "</h4>";
431
    $modal .= "<button type=\"button\" class=\"close\" data-dismiss=\"modal\"><i class=\"fas fa-window-close btn-dismiss\"></i></button>";
432
    $modal .= "</div>";
433
 
434
    $modal .= "<div class=\"modal-body bg-white mx-auto\">";
435
 
436
    if (!empty($item->LargeImage->URL)) {
437
        $modal .= "<img class=\"responsive-image mx-auto mb-4\" src=\"" . (string)$item->LargeImage->URL . "\" alt=\"Cover Image\">";
438
    }
439
 
440
    $modal .= "<table class=\"table-borderless table-condensed small mx-auto\">";
441
    $modal .= "<tr><td class=\"px-1\">Title:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->Title . "</td></tr>";
442
 
443
    $modal .= "<tr><td class=\"px-1\">Artist:</td><td class=\"px-1\">" . join(", ", $artists) . "</td></tr>";
444
    if (!empty($creators)) {
445
        $modal .= "<tr><td class=\"px-1\">Creator:</td><td class=\"px-1\">" . join(", ", $creators) . "</td></tr>";
446
    }
447
 
448
    if (!empty($actors)) {
449
        $modal .= "<tr><td class=\"px-1\">Actor:</td><td class=\"px-1\">" . join(", ", $actors) . "</td></tr>";
450
    }
451
 
452
    if (!empty($directors)) {
453
        $modal .= "<tr><td class=\"px-1\">Director:</td><td class=\"px-1\">" . join(", ", $directors) . "</td></tr>";
454
    }
455
 
456
    if (!empty($authors)) {
457
        $modal .= "<tr><td class=\"px-1\">Author:</td><td class=\"px-1\">" . join(", ", $authors) . "</td></tr>";
458
    }
459
 
460
    if (!empty($item->ItemAttributes->Binding)) {
461
        $modal .= "<tr><td class=\"px-1\">Type:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->Binding . "</td></tr>";
462
    }
463
 
464
    if (!empty($item->ItemAttributes->MediaType)) {
465
        $modal .= "<tr><td class=\"px-1\">Media Type:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->MediaType . "</td></tr>";
466
    }
467
 
468
    if (!empty($barcode)) {
469
        $modal .= "<tr><td class=\"px-1\">Barcode:</td><td class=\"px-1\">" . displayBarcode($barcode) . "</td></tr>";
470
    }
471
 
472
    if (!empty($labels)) {
473
        $modal .= "<tr><td class=\"px-1\">Label:</td><td class=\"px-1\">" . $labels[0] . "</td></tr>";
474
    } else if (!empty($item->ItemAttributes->Publisher)) {
475
        $modal .= "<tr><td class=\"px-1\">Publisher:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->Publisher . "</td></tr>";
476
    } else if (!empty($item->ItemAttributes->Studio)) {
477
        $modal .= "<tr><td class=\"px-1\">Studio:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->Studio . "</td></tr>";
478
    }
479
 
480
    if (!empty($languages)) {
481
        $modal .= "<tr><td class=\"px-1\">Languages:</td><td class=\"px-1\">" . join(", ", $languages) . "</td></tr>";
482
    }
483
 
484
    if (!empty($item->ItemAttributes->PublicationDate)) {
485
        $modal .= "<tr><td class=\"px-1\">Publication Date:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->PublicationDate . "</td></tr>";
486
    }
487
 
488
    if (!empty($item->ItemAttributes->ReleaseDate)) {
489
        $modal .= "<tr><td class=\"px-1\">Release Date:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->ReleaseDate . "</td></tr>";
490
    }
491
 
492
    if (!empty($genres)) {
493
        $modal .= "<tr><td class=\"px-1\">Genre:</td><td class=\"px-1\">" . join(", ", $genres) . "</td></tr>";
494
    }
495
 
496
    if (!empty($item->ItemAttributes->NumberOfDiscs)) {
497
        $modal .= "<tr><td class=\"px-1\">Number of Discs:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->NumberOfDiscs . "</td></tr>";
498
    }
499
 
500
    if (!empty($item->ItemAttributes->NumberOfPages)) {
501
        $modal .= "<tr><td class=\"px-1\">Number of Pages:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->NumberOfPages . "</td></tr>";
502
    }
503
 
504
    if (!empty($item->ItemAttributes->RunningTime)) {
505
        $modal .= "<tr><td class=\"px-1\">Running Time:</td><td class=\"px-1\">" . $runningTime . "</td></tr>";
506
    }
507
 
508
    if (!empty($item->ItemAttributes->Edition)) {
509
        $modal .= "<tr><td class=\"px-1\">Edition:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->Edition . "</td></tr>";
510
    }
511
 
512
    if (!empty($item->ItemAttributes->AudienceRating)) {
513
        $modal .= "<tr><td class=\"px-1\">Rating:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->AudienceRating . "</td></tr>";
514
    }
515
 
516
    if (!empty($item->ItemAttributes->RegionCode)) {
517
        $modal .= "<tr><td class=\"px-1\">Region Code:</td><td class=\"px-1\">" . (string)$item->ItemAttributes->RegionCode . "</td></tr>";
518
    }
519
 
520
    if (!empty($item->Tracks)) {
521
        $modal .= "<tr><td colspan=\"2\" class=\"px-1\">Tracks:</td></tr>";
522
        $modal .= "<tr><td colspan=\"2\">";
523
        $modal .= "<ul class=\"pl-3 pt-0 small list-unstyled\">";
524
        foreach ($item->Tracks->Disc as $disc) {
525
            if ((int)$item->ItemAttributes->NumberOfDiscs > 1) {
526
                $modal .= "<li class=\"font-weight-bold\">Disc " . $disc->attributes() . ":</li>";
527
            }
528
 
529
            foreach($disc->Track as $track) {
530
                $modal .= "<li>" . $track->attributes() . ") " . $track . "</li>";
531
            }
532
        }
533
        $modal .= "</ul>";
534
        $modal .= "</td></tr>";
535
    }
536
 
537
    $modal .= "</table>";
538
    $modal .= "</div>";
539
    $modal .= "<div class=\"modal-footer bg-white justify-content-between\">";
540
    $modal .= "<span class=\"float-right\"><button type=\"button\" class=\"btn btn-danger\" data-dismiss=\"modal\">Close</button></span>";
541
    $modal .= "</div>";
542
    $modal .= "</div>";
543
    $modal .= "</div>";
544
    $modal .= "</div>";
545
    $str .= $modal;
546
    $str .= "</div>";
547
 
548
    return $str;
549
}
550
 
551
function getArtists($item) {
552
    $artists = [];
553
 
554
    if (!empty($item->ItemAttributes->Artist)) {
555
        foreach($item->ItemAttributes->Artist as $artist) {
556
            $artists[] = $artist;
557
        }
558
    }
559
 
560
    return $artists;
561
}
562
 
563
function getCreators($item) {
564
    $creators = [];
565
 
566
    if (!empty($item->ItemAttributes->Creator)) {
567
        foreach($item->ItemAttributes->Creator as $creator) {
568
            if ((string)$creator->attributes() == "Primary Contributor") {
82 - 569
                $creators[] = $creator;
81 - 570
            } else {
571
                $creators[] = $creator . " (" . $creator->attributes() . ")";
572
            }
573
        }
574
    }
575
 
576
    return $creators;
577
}