if (!isset($fileCache) || !$fileCache) { // #Date range $gs_dateFrom = date('Y-m', strtotime('3 months ago')); $gs_dateTo = date('Y-m', strtotime('1 month ago')); // #"API" uri $gs_Uri = 'http://gs.statcounter.com/chart.php?bar=1&statType_hidden=browser_version_partially_combined®ion_hidden=ww&granularity=monthly&statType=Browser%20Version%20(Partially%20Combined)®ion=Worldwide&fromMonthYear=' . $gs_dateFrom . '&toMonthYear=' . $gs_dateTo; $result = array('graph' => array('title' => 'Browser Versions', 'type' => 'bar', 'yAxis' => array('units' => array('suffix' => '%')))); // #Data limit $limit = 5; if (isset($_GET['limit'])) { $limit = intval($_GET['limit']); } $current = 1; // #Parse data $gs_xml = @simplexml_load_file($gs_Uri); if ($gs_xml) { foreach ($gs_xml->set as $set) { $result['graph']['datasequences'][] = array('title' => (string) $set['label'], 'refreshEveryNSeconds' => 64800, 'datapoints' => array(array('title' => '', 'value' => floatval($set['value'])))); if ($current++ == $limit) { break; } } } else { $result['graph']['error'] = array('message' => 'Oops, an error has occured.', 'detail' => 'The stats load does not work, something is wrong with the url.'); } echo json_encode($result); // #If cache set -> saveCache if (isset($oCache)) { $oCache->saveCache(); } }