CHART_CACHE_ENABLED, 'expiry' => CHART_CACHE_EXPIRY ); // does the specified config file actually exist if (file_exists($sConfig)) { // grab config file contents if (CHART_CONFIG_SUPPORT_PHP) { // parse any PHP and store lines in array ob_start(); require($sConfig); $aConfig = explode("\n", ob_get_clean()); } else { $aConfig = file($sConfig); } // set up variable to store generated chart URL $sChartUrl = CHART_BASE_URL.'?'; // create URL to request chart foreach ($aConfig as $sParameter) { // pass config format, strip comments if (preg_match("/^\s*([0-9a-z\._-]+)\s*=\s*((\\\\#|[^#])*).*$/iu", $sParameter, $aMatches)) { $aMatches[2] = trim(str_replace('\#', '#', $aMatches[2])); // check for script configuration property (not sent to Google) if (array_key_exists($aMatches[1], $aSettings)) { $aSettings[$aMatches[1]] = $aMatches[2]; } else { $sChartUrl .= $aMatches[1]."={$aMatches[2]}&"; } } } // clean up chart URL and create MD5 equivalent for cache filename $sChartUrl = rtrim($sChartUrl, '&'); $sChartUrlMD5 = CHART_CACHE_PATH.md5($sConfig.filemtime($sConfig)).'.png'; // convert cached property to boolean $aSettings['cache'] = ($aSettings['cache'] == 'yes'); // set image type header('Content-type: image/png'); // check if a valid cache file already exists if (!$aSettings['cache'] || !file_exists($sChartUrlMD5) || filemtime($sChartUrlMD5) < time() - $aSettings['expiry']) { $oCurl = curl_init($sChartUrl); curl_setopt($oCurl, CURLOPT_CONNECTTIMEOUT, CHART_HTTP_TIMEOUT); curl_setopt($oCurl, CURLOPT_TIMEOUT, CHART_HTTP_REQUEST_TIME); curl_setopt($oCurl, CURLOPT_USERAGENT, CHART_HTTP_USERAGENT); curl_setopt($oCurl, CURLOPT_HEADER, false); curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true); // request chart, if curl fails for any reason just redirect directly to Google to retrieve chart if ($oChart = curl_exec($oCurl)) { if ($aSettings['cache']) { file_put_contents($sChartUrlMD5, $oChart); } else { echo $oChart; } } else { header("Location: $sChartUrl"); exit; } } // write cached chart to browser if cache enabled if ($aSettings['cache']) { readfile($sChartUrlMD5); } } else { echo 'Error: Specified configuration file doesn\'t exit'; } } else { echo 'Error: Invalid configuration filename format specified.'; } } else { echo 'Error: CURL isn\'t available on your system. Read more about CURL - http://www.php.net/manual/en/ref.curl.php.'; } ?>