--- nfo/site/htdocs/inc/common/common.php.inc 2004/08/24 03:27:47 1.1 +++ nfo/site/htdocs/inc/common/common.php.inc 2004/09/04 03:06:10 1.10 @@ -4,106 +4,343 @@ --- Setup and common functions include file. -------------------------------------------------------------------------------- --- rabit, 04:31 24.08.2004 ---- $$id$$ +--- $Id: common.php.inc,v 1.10 2004/09/04 03:06:10 rabit Exp $ ------------------------------------------------------------------------------*/ +//------------------------------------------------------------------------------ +//- Benchmarking: + +// Create the benchmark steps array inside "$common": +$common['benchmark'] = array(); + +function common_benchmark_addstep($caption) { + +global $common; + + $step = array($caption, microtime()); + + array_push($common['benchmark'], $step); + +} + +// The starting entry in the benchmark steps list: +common_benchmark_addstep('common: start'); + //---------------------------------------------------------- -//- Developer host setup: +//- Developer host setups: -$cfg['hostsetups'] = array( +$hostsetups = array( 'default' => array( 'urlrel' => '/nfo/', + 'devstate' => false, + 'mysql_host' => 'localhost', + 'mysql_user' => 'nfo', + 'mysql_pass' => 'b2-cV5RF', + 'mysql_db' => 'nfo' ), 'psl.no-ip.com' => array( 'urlrel' => '/work/www.netfrag.org/', + 'devstate' => true, + 'mysql_host' => 'localhost', + 'mysql_user' => 'php', + 'mysql_pass' => 'A289tpQ1', + 'mysql_db' => 'nfo' ), ); -if(isset($cfg['hostsetups'][$_SERVER['SERVER_NAME']])) { +// Set the default host setup: +$common['hostsetup'] = $hostsetups['default']; - $cfg['hostsetup'] = $cfg['hostsetups'][$_SERVER['SERVER_NAME']]; +// Set the host setup if a listed host name is given: +if(isset($hostsetups[$_SERVER['SERVER_NAME']])) $common['hostsetup'] = $hostsetups[$_SERVER['SERVER_NAME']]; -} else { +unset($hostsetups); - $cfg['hostsetup'] = $cfg['hostsetups']['default']; +common_benchmark_addstep('common: host setup'); -} +//---------------------------------------------------------- +//- Site variable setups: -$documentroot = $_SERVER['DOCUMENT_ROOT'] . $cfg['hostsetup']['urlrel']; +// Paths: +$common['site']['docroot'] = $_SERVER['DOCUMENT_ROOT'] . $common['hostsetup']['urlrel']; +$common['site']['incroot'] = $common['site']['docroot'] . 'inc/'; +$common['site']['libroot'] = $common['site']['docroot'] . 'libs/'; + +// URLs: +$common['site']['url'] = 'http://' . $_SERVER['HTTP_HOST'] . $common['hostsetup']['urlrel']; +$common['site']['gfxurl'] = $common['site']['url'] . 'gfx/'; + +//---------------------------------------------------------- +//- Page variable setups: + +$common['page']['filename'] = substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], '/') + 1); +$common['page']['url'] = $_SERVER['PHP_SELF']; + +common_benchmark_addstep('common: site/page setup'); //------------------------------------------------------------------------------ -//- Configuration include file: +//- Includes: + +//common_include('cfg/cfg.php.inc'); +//common_benchmark_addstep('common: CFG included'); + +include($common['site']['incroot'] . 'xmlcp/xmlcp.php.inc'); +common_benchmark_addstep('common: XMLCP included'); + +include($common['site']['incroot'] . 'cms/cms.php.inc'); +common_benchmark_addstep('common: CMS included'); + +//------------------------------------------------------------------------------ +//- MySQL connection: + +common_dbc_connectdb(); +common_benchmark_addstep('common: connect database'); + +//------------------------------------------------------------------------------ +//- Session setup: + +if(!isset($common['client']['session_enabled'])) { + + // Neither proxies, nor the clients are allowed to cache session data: + session_cache_limiter('nocache'); -include($documentroot . 'inc/cfg/cfg.php.inc'); + // This is neccessary to make the $_SESSION global available: + session_start(); + +} + +common_benchmark_addstep('common: session init'); + +if(!isset($_SESSION['common_sessiondata'])) { + + // The session variable isn't set, create it: + + common_benchmark_addstep('common: New session: start'); + + $common_sessiondata = array( + + 'birthtime' => time(), + 'firstrequest' => 1, // Mark the very first page request. + + // User data and authorisation: + 'user_auth' => array( + 'name' => '', + 'password' => '', + 'authorised' => false + ), + + // User preferences and preferred settings: + 'user_prefs' => array( + 'benchlist' => null, + 'debug' => null, + 'language_id' => null, + 'outputtype' => null + ), + + // Content related additional data: + 'additionaldata' => array() + + ); + + common_benchmark_addstep('common: New session: create session'); + + // Protocol the visitors hit and store the columns insertion ID: + $common_sessiondata['hit_id'] = common_protocolhit(); + + common_benchmark_addstep('common: New session: protocol hit'); + + // Store a reference to the session data array: + $_SESSION['common_sessiondata'] = &$common_sessiondata; + + common_benchmark_addstep('common: New session: store session/end'); + +} else { + + // Restore the session data array reference: + $common_sessiondata = &$_SESSION['common_sessiondata']; + + // Reset the first page request flag: + $common_sessiondata['firstrequest'] = null; + + // Update the request count in the "hits" table: + + $sql = "UPDATE hits SET requestcount=requestcount+1 WHERE id='" . $common_sessiondata['hit_id'] . "';"; + + common_dbc_query($sql); + + common_benchmark_addstep('common: session/hit data updated'); + +} //------------------------------------------------------------------------------ //- Functions: -function common_headline($caption) { +function common_authorise($username, $password) { - echo '
-(foot notes) -
+function common_dbc_query($sql) { - +global $common; - + if(!$common['dbc']['dbconnected']) return false; + + $res = mysql_query($sql); + + if($errormsg = mysql_error()) { + + // >>> MTC <<< + + echo $errormsg . '-' . $contents . ' -
+function common_get_baseurl() { -'; +global $common; + + return $common['site']['url']; } //------------------------------------------------------------------------------ -?> \ No newline at end of file +common_benchmark_addstep('common: end'); + +//------------------------------------------------------------------------------ + +?>