<?php$tsId = 'XACCB84E44344C2EEB8714B3210DE2907';
$cacheFileName = $tsId.'.xml';
$cacheTimeOut = 43200; // half a day
$apiUrl = 'http://www.trustedshops.com/api/ratings/v1/'.$tsId.'.xml';
$xmlFound = false;// check if cached version exists
if (!cachecheck($cacheFileName, $cacheTimeOut)) {
// load fresh from API
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_URL, $apiUrl);
$output = curl_exec($ch);
curl_close($ch);
// Write the contents back to the file
// Make sure you can write to file's destination
file_put_contents($cacheFileName, $output);}
if ($xml = simplexml_load_file($cacheFileName)) {
$xPath = "/shop/ratings/result[@name='average']";
$result = (float) $xml -> xpath($xPath)[0];
$max = "5.00";
$count = $xml->ratings["amount"];
$shopName = $xml->name;
$xmlFound = true;}if ($xmlFound) {
?>
<a href="http://www.trustedshops.eu/seller-rating/">Trusted Shops seller rating</a>:<span xmlns:v="http://rdf.data-vocabulary.org/#" typeof="v:Review-aggregate"> <span rel="v:rating"><span property="v:value"><?php echo $result;?> </span> </span> / <span property="v:best"><?php echo $max;?> </span> of <span property="v:count"><?php
echo $count;?> </span> <a href="https://www.trustedshops.de/bewertung/info_<?php echo $tsId?>.html" title="<?php echo $shopName;?> bewertungen">
<?php echo $shopName;?> ratings</a> </span>
<?php
}
function cachecheck($filename_cache, $timeout = 10800) {
if (file_exists($filename_cache) && time() - filemtime($filename_cache) < $timeout) {
return true; }
return false; }
- Output for 5.4.0 - 5.4.34
- Parse error: syntax error, unexpected '$tsId' (T_VARIABLE) in /in/5l30v on line 1
Process exited with code 255. - Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
- Parse error: syntax error, unexpected '}' in /in/5l30v on line 30
Process exited with code 255. - Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
- Parse error: parse error, unexpected '}' in /in/5l30v on line 30
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error in /in/5l30v on line 30
Process exited with code 255.
preferences:
151.67 ms | 956 KiB | 7 Q