57 |
- |
1 |
<?php
|
|
|
2 |
include_once('php/constants.php');
|
|
|
3 |
|
|
|
4 |
error_reporting(E_ALL);
|
|
|
5 |
|
|
|
6 |
// Get itunes listings
|
|
|
7 |
function get_itunes($query, $searchType) {
|
|
|
8 |
$vendors = Vendors::getInstance();
|
|
|
9 |
$config = $vendors->getVendor(Vendors::ITUNES);
|
|
|
10 |
$safequery = urlencode($query);
|
|
|
11 |
$arrMusic = [];
|
|
|
12 |
$arrEbooks = [];
|
|
|
13 |
$arrAudiobooks = [];
|
|
|
14 |
|
|
|
15 |
// Music (Albums)
|
|
|
16 |
if ($_SESSION["filterMediaType"]["Digital"]) {
|
|
|
17 |
$arrMusic = get_itunesCategory($config, $safequery, $searchType, "music", "album");
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
if ($_SESSION["filterMediaType"]["Book"]) {
|
|
|
21 |
// ebooks
|
|
|
22 |
$arrEbooks = get_itunesCategory($config, $safequery, $searchType, "ebook", "ebook");
|
|
|
23 |
|
|
|
24 |
// audiobooks
|
|
|
25 |
$arrAudiobooks = get_itunesCategory($config, $safequery, $searchType, "audiobook", "audiobook");
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
return(array_merge($arrMusic, $arrEbooks, $arrAudiobooks));
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
// Get linkshare listings by advertiser id
|
|
|
32 |
function get_itunesCategory($config, $safequery, $searchType, $mediaType, $entityType) {
|
|
|
33 |
// API request variables
|
|
|
34 |
$numResults = $config['numResults'];
|
|
|
35 |
|
|
|
36 |
$url = "https://itunes.apple.com/";
|
|
|
37 |
|
|
|
38 |
if (empty($_SESSION["barcode"]['Type'])) {
|
|
|
39 |
$url .= "search";
|
|
|
40 |
$url .= "?term=" . $safequery;
|
|
|
41 |
$url .= "&media=" . $mediaType;
|
|
|
42 |
$url .= "&entity=" . $entityType;
|
|
|
43 |
} else {
|
|
|
44 |
$url .= "lookup";
|
|
|
45 |
$url .= "?upc=" . $safequery;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
$url .= "&limit=" . $numResults;
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
$result = getUrl($url);
|
|
|
52 |
//$result = utf8_encode($result);
|
|
|
53 |
$result = json_decode($result);
|
|
|
54 |
|
|
|
55 |
$arr = [];
|
|
|
56 |
|
|
|
57 |
//echo "$url<pre>";print_r($result);echo "</pre>";
|
|
|
58 |
|
|
|
59 |
// Check to see if the request found any results
|
|
|
60 |
if (isset($result->resultCount)) {
|
|
|
61 |
if ($result->resultCount <= 0) {
|
|
|
62 |
return [];
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
// If the response was loaded, parse it and store in array
|
|
|
66 |
foreach ($result->results as $item) {
|
|
|
67 |
$merchantName = "iTunes";
|
|
|
68 |
$barcode = "";
|
|
|
69 |
$barcodeType = "";
|
|
|
70 |
$price = 0.00;
|
|
|
71 |
|
|
|
72 |
$pic = str_replace('http://', 'https://', (string)$item->artworkUrl100);
|
|
|
73 |
if (empty($pic)) {
|
|
|
74 |
continue;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
$category = "Digital";
|
|
|
78 |
|
|
|
79 |
if (!empty($item->wrapperType)) {
|
|
|
80 |
$title = (string)$item->artistName . " - " . (string)$item->collectionName;
|
|
|
81 |
$url = str_replace('http://', 'https://', (string)$item->collectionViewUrl);
|
|
|
82 |
if (isset($item->collectionPrice)) {
|
|
|
83 |
$price = number_format(floatval($item->collectionPrice), 2, '.', '');
|
|
|
84 |
}
|
|
|
85 |
if ($item->wrapperType == "collection") {
|
|
|
86 |
$category = "Digital";
|
|
|
87 |
} else if ($item->wrapperType == "audiobook") {
|
|
|
88 |
$category = "Book";
|
|
|
89 |
}
|
|
|
90 |
} else if (!empty($item->kind) && $item->kind == "ebook") {
|
|
|
91 |
$category = "Book";
|
|
|
92 |
$title = (string)$item->artistName . " - " . (string)$item->trackName;
|
|
|
93 |
$url = str_replace('http://', 'https://', (string)$item->trackViewUrl);
|
|
|
94 |
if (isset($item->price)) {
|
|
|
95 |
$price = number_format(floatval($item->price), 2, '.', '');
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
if (empty($url)) {
|
|
|
100 |
continue;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
if ($price <= "0.00") {
|
|
|
104 |
continue;
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
$type = 'New';
|
|
|
108 |
$condition = 'Brand New';
|
|
|
109 |
$country = 'US';
|
|
|
110 |
$bestOffer = false;
|
|
|
111 |
|
|
|
112 |
$currency = $item->currency;
|
|
|
113 |
$timeLeft = 0;
|
|
|
114 |
$listingType = 'Fixed';
|
|
|
115 |
$location = 'US';
|
|
|
116 |
$zip = '';
|
|
|
117 |
$feedbackScore = -1;
|
|
|
118 |
$feedbackPercent = -1;
|
|
|
119 |
$sellerName = "";
|
|
|
120 |
$handlingTime = -1;
|
|
|
121 |
$shippingCost = 0.00;
|
|
|
122 |
$shippingCurrency = 'USD';
|
|
|
123 |
$freeShippingCap = 0;
|
|
|
124 |
|
|
|
125 |
$arr[] = array(
|
|
|
126 |
"Merchant" => $merchantName,
|
|
|
127 |
"Type" => "$type",
|
|
|
128 |
"Title" => "$title",
|
|
|
129 |
"Barcode" => "$barcode",
|
|
|
130 |
"BarcodeType" => "$barcodeType",
|
|
|
131 |
"Image" => "$pic",
|
|
|
132 |
"URL" => "$url",
|
|
|
133 |
"Category" => "$category",
|
|
|
134 |
"Condition" => "$condition",
|
|
|
135 |
"Country" => "$country",
|
|
|
136 |
"BestOffer" => "$bestOffer",
|
|
|
137 |
"TimeLeft" => "$timeLeft",
|
|
|
138 |
"Price" => "$price",
|
|
|
139 |
"Currency" => "$currency",
|
|
|
140 |
"ListingType" => "$listingType",
|
|
|
141 |
"Location" => "$location",
|
|
|
142 |
"Zip" => "$zip",
|
|
|
143 |
"FeedbackScore" => "$feedbackScore",
|
|
|
144 |
"FeedbackPercent" => "$feedbackPercent",
|
|
|
145 |
"SellerName" => "$sellerName",
|
|
|
146 |
"HandlingTime" => "$handlingTime",
|
|
|
147 |
"ShippingCost" => "$shippingCost",
|
|
|
148 |
"ShippingCurrency" => "$shippingCurrency",
|
|
|
149 |
"FreeShippingCap" => "$freeShippingCap",
|
|
|
150 |
"Show" => true
|
|
|
151 |
);
|
|
|
152 |
}
|
|
|
153 |
}
|
|
|
154 |
// If the response does not indicate 'Success,' log the error(s)
|
|
|
155 |
else {
|
|
|
156 |
error_log($url);
|
|
|
157 |
error_log($result->errorMessage);
|
|
|
158 |
error_log($result->queryParameters);
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
return $arr;
|
|
|
162 |
}
|