If we are not on the localhost, detect the files using the full path.

This commit is contained in:
Andrew Tomaka 2011-10-04 05:13:43 -04:00
parent c9b6934be5
commit e8ea5bd681

View file

@ -3,6 +3,15 @@
// index_data.php // index_data.php
// Collect data from various services and store locally for later display. // Collect data from various services and store locally for later display.
//***************************************************************************// //***************************************************************************//
if($_SERVER['SERVER_NAME'] == 'localhost') {
$CACHE_FILE = '../data/cache.txt';
$DATA_FILE = '../data/index.txt';
} else {
chdir('/home/atomaka/data');
$CACHE_FILE = 'cache.txt';
$DATA_FILE = 'index.txt';
}
$dataSources = array( $dataSources = array(
//function, cache_duration //function, cache_duration
@ -14,8 +23,8 @@ $dataSources = array(
'steam' => 3600, 'steam' => 3600,
); );
$cacheData = json_decode(file_get_contents('../data/cache.txt'),true); $cacheData = json_decode(file_get_contents($CACHE_FILE),true);
$sourceData = json_decode(file_get_contents('../data/index.txt'),true); $sourceData = json_decode(file_get_contents($DATA_FILE),true);
foreach($dataSources as $dataSource=>$refreshTime) { foreach($dataSources as $dataSource=>$refreshTime) {
// check last time the data was updated // check last time the data was updated
$lastModified = (array_key_exists($dataSource, $cacheData)) ? $lastModified = (array_key_exists($dataSource, $cacheData)) ?
@ -28,9 +37,9 @@ foreach($dataSources as $dataSource=>$refreshTime) {
$sourceData[$dataSource] = call_user_func($dataSource); $sourceData[$dataSource] = call_user_func($dataSource);
} }
} }
print_r($sourceData);
file_put_contents('../data/cache.txt',json_encode($cacheData)); file_put_contents($CACHE_FILE,json_encode($cacheData));
file_put_contents('../data/index.txt',json_encode($sourceData)); file_put_contents($DATA_FILE,json_encode($sourceData));
//***************************************************************************// //***************************************************************************//