Subversion Repositories cheapmusic

Rev

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