} if ($response) { $xml = array(); $res = simplexml_load_string($response); //echo '<meta charset="utf-8">'; //echo $string_to_sign . '<br/>'; //echo '<pre>'; //print_r($res); //exit; if ($res->Items->Request->IsValid) { $xml['isValid'] = $res->Items->Request->IsValid; $xml['TotalResults'] = $res->Items->TotalResults; $xml['TotalPages'] = (string) $res->Items->TotalPages; $xml['MoreSearchResultsUrl'] = $res->Items->MoreSearchResultsUrl; //$xml['items'] = $res->Items; $objItems = arrify($res->Items); if ((string) $xml['TotalPages'] <= $maxPage) { $maxPage = (string) $xml['TotalPages']; $allRecsShown = 1; } } else { $xml = false; } } else { $maxPage = 0; } $totalCount = isset($res->Items->TotalResults) ? (string) $res->Items->TotalResults : 0; $hash = md5($keyword . $cg['private_key']); $nextPage = 2; $moreUrl = '/list_more.php?index=' . $idx . '&query=' . $keyword . '&node=' . $nodeID . '&hash=' . $hash; include $cg['viewdir'] . '/list_v.php';
function make_file_pickup($keyword, $suffix, $offset = 1, $index, $browseNode, $curlReq = 0) { global $cg; global $lang; $yesterday = strtotime("yesterday") + 60 * 60 * $offset; // yesterday + offset hours $today = strtotime("today") + 60 * 60 * $offset; // today + offset hours $fileY = $yesterday . $suffix; $fileY = $cg['basedir'] . '/cache/' . $fileY . '.php'; $fileT = $today . $suffix; $fileT = $cg['basedir'] . '/cache/' . $fileT . '.php'; $lastWrite = $cg['basedir'] . '/cache/lastwrite.txt'; $canWrite = _check_last_time(3); // interval of 3 mins if (!$canWrite) { // prevent amazon api call for less than 3 minutes // if last file write is less than 3 minutes, return and use current file to display. if (file_exists($fileT)) { return $fileT; } else { return $fileY; } exit; } // if no file exists, means 1 day has elapsed. // need to create a new file based on today. // will also make an API call to amazon to pull new content if (!file_exists($fileT)) { if ($curlReq) { $response = curl_string($curlReq); $res = simplexml_load_string($response); $data = arrify($res->Items); } else { $data = recommended_pickup($keyword, $index, 3, $browseNode); // 3 pages or loops } if (!$data) { return false; } $str = '<ol>'; $i = 0; foreach ($data->Items->Item as $item) { if ($i == 15) { $str .= '</ol>'; break; } if (isset($item->ItemAttributes->ListPrice)) { $price = trim($item->ItemAttributes->ListPrice->FormattedPrice); } else { $price = $lang[119]; } if (isset($item->LargeImage)) { $image = $item->LargeImage->URL; } else { if (isset($item->MediumImage)) { $image = $item->MediumImage->URL; } else { if (isset($item->SmallImage)) { $image = $item->SmallImage->URL; } else { $image = $cg['imageurl'] . '/no-image.png'; } } } if (isset($item->ItemAttributes->ProductGroup)) { $pg = (string) $item->ItemAttributes->ProductGroup[0]; $categ[$pg] = $pg; } if ($i != 0 and $i % 5 == 0) { $str .= '</ol>'; $str .= '<ol>'; } $str .= <<<EOF \t\t\t\t\t<li><a href="{$item->DetailPageURL}" target="_blank"> \t\t\t\t\t<div class="prbox"><span class="hovmask"></span> \t\t\t\t\t\t<img src="{$image}" class="" alt="{$item->ItemAttributes->Title}" title=""> \t\t\t\t\t</div> \t\t\t\t\t<div class="prbottom simptip" data-tooltip="{$item->ItemAttributes->Title}"> \t\t\t\t\t\t<h3 class="title">{$item->ItemAttributes->Title}</h3> \t\t\t\t\t\t<span class="price">{$price}</span> \t\t\t\t\t</div> \t\t\t\t</a></li> EOF; $i++; //<span class="price">{htmlspecialchars($price, ENT_HTML5,'UTF-8', true)}</span> } // foreach unlink($fileY); // delete yesterday's file unlink($lastWrite); file_put_contents($fileT, $str); file_put_contents($lastWrite, time()); // write to file last time(); } // !file_exists return $fileT; }
echo ''; exit; } $searchIndex = $idx; if (!in_array($searchIndex, $categories)) { $keyword .= ' ' . $searchIndex; $searchIndex = 'All'; // reassign All } $operation = 'ItemSearch'; $service = 'AWSECommerceService'; $version = '2011-08-01'; $responseGroup = 'ItemAttributes,Images'; $browseNode = $nodeID; $string_to_sign = build_request($keyword, $searchIndex, $operation, $service, $version, $responseGroup, $page, $browseNode); $signature = get_signature($string_to_sign); $request = $cg['amazonUrl'] . '?' . $string_to_sign; $request .= "&Signature=" . $signature; $maxPage = $searchIndex == 'All' ? 5 : 10; //$response = file_get_contents($request); $response = curl_string($request); if ($response) { $xml = array(); $res = simplexml_load_string($response); //echo json_encode($res); $obj = arrify($res->Items); echo json_encode($obj); } else { echo ''; } exit;