Condense config files into one.
This commit is contained in:
parent
6a22a3580a
commit
853749cbb4
3 changed files with 24 additions and 35 deletions
|
@ -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;
|
||||
global $interruptedExecution, $startTime, $conf;
|
||||
|
||||
$db_conf = json_decode(file_get_contents($DATABASE_FILE));
|
||||
$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;
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
<?php
|
||||
$db_config = json_decode(file_get_contents('../../conf/database.conf'));
|
||||
$api_config = json_decode(file_get_contents('../../conf/api.conf'));
|
||||
$conf = json_decode(file_get_contents('../../conf/iwa.conf'));
|
||||
|
||||
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'];
|
||||
if($key != $api_config->key) die('{"message":"Access Denied."}');
|
||||
if($key != $db->site->key) die('{"message":"Access Denied."}');
|
||||
|
||||
$url = $_GET['url'];
|
||||
$title = $_GET['title'];
|
||||
|
|
|
@ -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");
|
||||
?><!DOCTYPE HTML>
|
||||
|
@ -81,10 +81,6 @@ while($link = $links->fetch_object()) {
|
|||
</div>
|
||||
</div>
|
||||
<div id="column2">
|
||||
<h2>fitness</h2>
|
||||
<div id="fitness" class="box">
|
||||
Collecting data.
|
||||
</div>
|
||||
<h2>media</h2>
|
||||
<div id="lastfm" class="box">
|
||||
<table class="formatting">
|
||||
|
|
Loading…
Reference in a new issue