Source Code Index
<?php
/*
	"...we know that the initialization of a program can't be written 
	until the program itself takes shape."
	  -- Donald Knuth
*/
 
/* CONFIG.PHP - This configures the core of the application.
 
This contains all "sitewide" configuration data as an associative array as a 
static variable in the config() function that is initialized on first call. 
All data access is through that function (with a few "helper" functions).
 
The odd things here are how "sections" are read (and we need more documentation 
about that), how 'debug' is handled and how $arg is checked (which should be 
checked in RULES.PHP, but...).
 
*/
 
 
/* config - read/write configuration data */
 
function config($var = NULL, $val = NULL) {
static $config = array();
 
	if ($config == array()) {
 
		if (!is_file($f='config.ini'))
			user_error("'$f' was not found",E_USER_ERROR);
		$config = parse_ini_file($f,TRUE);
		if ($config == FALSE)
			user_error("cannot continue with error in '$f'",E_USER_ERROR);
 
		if (is_file($f='sections.ini')) {
			$sections = parse_ini_file($f,TRUE);
			if ($sections == FALSE)
				user_error("cannot continue with error in '$f'",E_USER_ERROR);
		}
 
		if (!isset($sections)) {
			$sections['name'] = $config['title'];
			$sections['subtitle'] = $config['subtitle'];
			$sections['description'] = 'A Blog';
		}
 
		foreach ($sections as $k => $v)
			if (!is_array($v)) {
				$config['sections']['root'][$k] = $v;
				unset($sections[$k]);
			}
 
		foreach ($sections as $k => $v)
			$config['sections'][$k] = $v;
 
// unlike other GET inputs, 'arg' is checked here as it is needed to set 
// some configuration variables (see also RULES.PHP)...
 
		$arg = getvar('arg');
		if ($arg == '') $arg = 'root';
 
		if (!isset($config['sections'][$arg])) {
			if (isset($config['httperrors']))
				notfound();
			$_GET['arg'] = '';
			$arg = 'root';
		}
 
		$config['arg'] = $arg;
 
// this overrides settings by section (some settings won't make sense in a 
// section; see file SECTIONS); first make a copy of current section
 
		$config['section'] = $config['sections'][$arg];
		$section =& $config['section'];
		foreach ($section as $name => $value) {
			if (!in_array($name,array('name','subtitle','hidden')))
				$config[$name] = $value;
		}
 
// sets 'debug' only if logged in as Admin or running Admin, but with a 
// special value of 100 even if not logged in as Admin (to debug Admin code 
// for example; see file DEBUGGING)
 
		if ($config['debug'] == 100)
			errorlog(100);
		else
		if (userstate() || isset($config['admin'])) {
			if (($t = getvar('debug')) !== "")
				$config['debug'] = $t;
			if ($config['debug'])
				errorlog($config['debug']);
		}
 
		if ($config['debug'])
			error_reporting(E_ALL|E_STRICT);
 
		// make sure directory variables end appropriately
 
		foreach($config as $k => $v)
			if (!is_array($v) && preg_match('/dir$/',$k) && $v)
				$config[$k] = rtrim($v,'/') . '/';
 
		$config['pagedir'] .= $arg.'/';
		$config['importdir'] .= $arg.'/';
 
		$config['ip'] = $_SERVER['REMOTE_ADDR'];
		$config['ua'] = $_SERVER['HTTP_USER_AGENT'];
 
		$config['version'] = $GLOBALS['VERSION'];
		if (stristr($GLOBALS['VERSION'],'admin'))
			$config['admin'] = 1;
		if ($_SERVER['SERVER_NAME'] == 'localhost')
			$config['admin'] = 1;
 
		if (!config('testing') && !defined('DB_NAME'))	// known unknown
			$config['testing'] = 1;			// force testing
 
		debug('cookies: '.cookie_str());
	}
 
	if ($var === NULL)
		return $config;
 
	if ($val !== NULL)
		return $config[$var] = $val;
 
	if (isset($config[$var]))
		return $config[$var];
 
	return '';
}
 
 
// a few "support" functions - these simply reduce some inline string literals 
 
 
/* htmdir - return html directory with possible filename */
 
function htmdir($file = '') {
 
	return config('htmdir').$file;
}
 
/* themedir - return theme directory with possible filename */
 
function themedir($file = '') {
 
	return config('htmdir').config('themedir').$file;
}
 
function imgdir($file = '') {
 
	return config('imgdir').$file;
}
 
/* datestrcmt - return date string formated to comment date format */
 
function datestrcmt($time = "") {
 
	if ($time == "") $time = time();
	return date(config('datestrcmt'),$time);
}
 
 
/* the initialization function */
 
function _config_config() {
	config();
}
 
THIS source compiler