From 853749cbb49f51d70a849e2e12ec97c3acc04645 Mon Sep 17 00:00:00 2001 From: atomaka Date: Sun, 16 Oct 2011 06:33:28 -0400 Subject: [PATCH] Condense config files into one. --- cronjobs/index_data.php | 44 +++++++++++++++++---------------------- public_html/api/links.php | 7 +++---- public_html/index.php | 8 ++----- 3 files changed, 24 insertions(+), 35 deletions(-) diff --git a/cronjobs/index_data.php b/cronjobs/index_data.php index 2c0469e..bb148fb 100644 --- a/cronjobs/index_data.php +++ b/cronjobs/index_data.php @@ -11,20 +11,15 @@ register_shutdown_function('shutdown'); clearstatcache(); if(in_array($_SERVER['SERVER_NAME'],array('localhost','a.io'))) { - $DATABASE_FILE = getcwd() . '/../conf/database.conf'; - $CACHE_FILE = '../data/cache.txt'; - $DATA_FILE = '../data/index.txt'; - $LOCK_FILE = getcwd() . '/../data/whoisandrew.lock'; + $conf = json_decode(file_get_contents(getcwd() . '/../conf/wia.conf')); } else { - chdir('/home/atomaka/data'); - - $DATABASE_FILE = '/home/atomaka/conf/database.conf'; - $CACHE_FILE = 'cache.txt'; - $DATA_FILE = 'index.txt'; - // path changes in the shutdown() function so we need the full path - $LOCK_FILE = '/home/atomaka/data/whoisandrew.lock'; + $conf = json_decode(file_get_contents('/home/atomaka/conf/wia.conf')); } +define('CACHE',$conf->site->path . '/data/cache.txt'); +define('DATA',$conf->site->path . '/data/index.txt'); +define('LOCK',$conf->site->path . '/data/whoisandrew.lock'); + // All the sources we intend on pulling data from with a corresponding // cache lifetime. $dataSources = array( @@ -38,21 +33,21 @@ $dataSources = array( ); // Make sure that the script does not begin execution if it is already. -if(!file_exists($LOCK_FILE)) { - touch($LOCK_FILE); +if(!file_exists(LOCK)) { + touch(LOCK); } else { $interruptedExecution = true; exit(); } // In case our data files are not present -if(file_exists($CACHE_FILE)) { - $cacheData = json_decode(file_get_contents($CACHE_FILE),true); +if(file_exists(CACHE)) { + $cacheData = json_decode(file_get_contents(CACHE),true); } else { $cacheData = array(); } -if(file_exists($DATA_FILE)) { - $sourceData = json_decode(file_get_contents($DATA_FILE),true); +if(file_exists(DATA)) { + $sourceData = json_decode(file_get_contents(DATA),true); } else { $sourceData = array(); } @@ -70,8 +65,8 @@ foreach($dataSources as $dataSource=>$refreshTime) { } } -file_put_contents($CACHE_FILE,json_encode($cacheData)); -file_put_contents($DATA_FILE,json_encode($sourceData)); +file_put_contents(CACHE,json_encode($cacheData)); +file_put_contents(DATA,json_encode($sourceData)); //***************************************************************************// @@ -338,12 +333,11 @@ function progression_sort($a, $b) { function shutdown() { // need to make the variables we need available - global $interruptedExecution, $startTime, $LOCK_FILE, $DATABASE_FILE; - - $db_conf = json_decode(file_get_contents($DATABASE_FILE)); + global $interruptedExecution, $startTime, $conf; + $db = mysqli_init(); - $db->real_connect($db_conf->hostname,$db_conf->username,$db_conf->password, - $db_conf->database); + $db->real_connect($conf->db->hostname,$conf->db->username,$conf->db->password, + $conf->db->database); // $interruptedExecution is true if our lock file still existed when the // script began execution. true also implies that the lock file does not @@ -354,7 +348,7 @@ function shutdown() { 'The script attempted to run while another copy was already processing')"; $db->query($query); } else { - unlink($LOCK_FILE); + unlink(LOCK); } $completionTime = time() - $startTime; diff --git a/public_html/api/links.php b/public_html/api/links.php index c01dd93..3dd15d6 100644 --- a/public_html/api/links.php +++ b/public_html/api/links.php @@ -1,12 +1,11 @@ hostname,$db_config->username,$db_config->password,$db_config->database); +$db = new Database($conf->db->hostname,$conf->db->username,$conf->db->password,$conf->db->database); $key = $_GET['link_key']; -if($key != $api_config->key) die('{"message":"Access Denied."}'); +if($key != $db->site->key) die('{"message":"Access Denied."}'); $url = $_GET['url']; $title = $_GET['title']; diff --git a/public_html/index.php b/public_html/index.php index ad33542..4c7417c 100644 --- a/public_html/index.php +++ b/public_html/index.php @@ -3,9 +3,9 @@ $data = json_decode(file_get_contents('../data/index.txt')); // retrieve links from database -$db_config = json_decode(file_get_contents('../conf/database.conf')); +$conf = json_decode(file_get_contents('../conf/wia.conf')); include('lib/database.php'); -$db = new Database($db_config->hostname,$db_config->username,$db_config->password,$db_config->database); +$db = new Database($conf->db->hostname,$conf->db->username,$conf->db->password,$conf->db->database); $links = $db->query("SELECT id,url,text,status,released_date FROM wia_links WHERE status = 2 OR status = 3 ORDER BY released_date DESC LIMIT 15"); ?> @@ -81,10 +81,6 @@ while($link = $links->fetch_object()) {
-

fitness

-
- Collecting data. -

media