Condense config files into one.

This commit is contained in:
Andrew Tomaka 2011-10-16 06:33:28 -04:00
parent 6a22a3580a
commit 853749cbb4
3 changed files with 24 additions and 35 deletions

View file

@ -11,20 +11,15 @@ register_shutdown_function('shutdown');
clearstatcache(); clearstatcache();
if(in_array($_SERVER['SERVER_NAME'],array('localhost','a.io'))) { if(in_array($_SERVER['SERVER_NAME'],array('localhost','a.io'))) {
$DATABASE_FILE = getcwd() . '/../conf/database.conf'; $conf = json_decode(file_get_contents(getcwd() . '/../conf/wia.conf'));
$CACHE_FILE = '../data/cache.txt';
$DATA_FILE = '../data/index.txt';
$LOCK_FILE = getcwd() . '/../data/whoisandrew.lock';
} else { } else {
chdir('/home/atomaka/data'); $conf = json_decode(file_get_contents('/home/atomaka/conf/wia.conf'));
$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';
} }
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 // All the sources we intend on pulling data from with a corresponding
// cache lifetime. // cache lifetime.
$dataSources = array( $dataSources = array(
@ -38,21 +33,21 @@ $dataSources = array(
); );
// Make sure that the script does not begin execution if it is already. // Make sure that the script does not begin execution if it is already.
if(!file_exists($LOCK_FILE)) { if(!file_exists(LOCK)) {
touch($LOCK_FILE); touch(LOCK);
} else { } else {
$interruptedExecution = true; $interruptedExecution = true;
exit(); exit();
} }
// In case our data files are not present // In case our data files are not present
if(file_exists($CACHE_FILE)) { if(file_exists(CACHE)) {
$cacheData = json_decode(file_get_contents($CACHE_FILE),true); $cacheData = json_decode(file_get_contents(CACHE),true);
} else { } else {
$cacheData = array(); $cacheData = array();
} }
if(file_exists($DATA_FILE)) { if(file_exists(DATA)) {
$sourceData = json_decode(file_get_contents($DATA_FILE),true); $sourceData = json_decode(file_get_contents(DATA),true);
} else { } else {
$sourceData = array(); $sourceData = array();
} }
@ -70,8 +65,8 @@ foreach($dataSources as $dataSource=>$refreshTime) {
} }
} }
file_put_contents($CACHE_FILE,json_encode($cacheData)); file_put_contents(CACHE,json_encode($cacheData));
file_put_contents($DATA_FILE,json_encode($sourceData)); file_put_contents(DATA,json_encode($sourceData));
//***************************************************************************// //***************************************************************************//
@ -338,12 +333,11 @@ function progression_sort($a, $b) {
function shutdown() { function shutdown() {
// need to make the variables we need available // need to make the variables we need available
global $interruptedExecution, $startTime, $LOCK_FILE, $DATABASE_FILE; global $interruptedExecution, $startTime, $conf;
$db_conf = json_decode(file_get_contents($DATABASE_FILE));
$db = mysqli_init(); $db = mysqli_init();
$db->real_connect($db_conf->hostname,$db_conf->username,$db_conf->password, $db->real_connect($conf->db->hostname,$conf->db->username,$conf->db->password,
$db_conf->database); $conf->db->database);
// $interruptedExecution is true if our lock file still existed when the // $interruptedExecution is true if our lock file still existed when the
// script began execution. true also implies that the lock file does not // 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')"; 'The script attempted to run while another copy was already processing')";
$db->query($query); $db->query($query);
} else { } else {
unlink($LOCK_FILE); unlink(LOCK);
} }
$completionTime = time() - $startTime; $completionTime = time() - $startTime;

View file

@ -1,12 +1,11 @@
<?php <?php
$db_config = json_decode(file_get_contents('../../conf/database.conf')); $conf = json_decode(file_get_contents('../../conf/iwa.conf'));
$api_config = json_decode(file_get_contents('../../conf/api.conf'));
include_once('../lib/database.php'); include_once('../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);
$key = $_GET['link_key']; $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']; $url = $_GET['url'];
$title = $_GET['title']; $title = $_GET['title'];

View file

@ -3,9 +3,9 @@
$data = json_decode(file_get_contents('../data/index.txt')); $data = json_decode(file_get_contents('../data/index.txt'));
// retrieve links from database // 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'); 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"); $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");
?><!DOCTYPE HTML> ?><!DOCTYPE HTML>
@ -81,10 +81,6 @@ while($link = $links->fetch_object()) {
</div> </div>
</div> </div>
<div id="column2"> <div id="column2">
<h2>fitness</h2>
<div id="fitness" class="box">
Collecting data.
</div>
<h2>media</h2> <h2>media</h2>
<div id="lastfm" class="box"> <div id="lastfm" class="box">
<table class="formatting"> <table class="formatting">