--- nfo/site/htdocs/inc/common/common.php.inc 2004/08/31 02:41:40 1.6 +++ nfo/site/htdocs/inc/common/common.php.inc 2004/09/01 08:58:40 1.7 @@ -4,7 +4,7 @@ --- Setup and common functions include file. -------------------------------------------------------------------------------- --- rabit, 04:31 24.08.2004 ---- $Id: common.php.inc,v 1.6 2004/08/31 02:41:40 rabit Exp $ +--- $Id: common.php.inc,v 1.7 2004/09/01 08:58:40 rabit Exp $ ------------------------------------------------------------------------------*/ //------------------------------------------------------------------------------ @@ -24,7 +24,7 @@ } // The starting entry in the benchmark steps list: -common_benchmark_addstep('COMMON: start'); +common_benchmark_addstep('common: start'); //---------------------------------------------------------- //- Developer host setups: @@ -59,6 +59,8 @@ unset($hostsetups); +common_benchmark_addstep('common: host setup'); + //---------------------------------------------------------- //- Site variable setups: @@ -77,26 +79,25 @@ $common['page']['filename'] = substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], '/') + 1); $common['page']['url'] = $_SERVER['PHP_SELF']; -common_benchmark_addstep('COMMON: setup'); +common_benchmark_addstep('common: site/page setup'); //------------------------------------------------------------------------------ //- Includes: //common_include('cfg/cfg.php.inc'); -//common_benchmark_addstep('COMMON: CFG included'); +//common_benchmark_addstep('common: CFG included'); -common_include('xmlcp/xmlcp.php.inc'); -common_benchmark_addstep('COMMON: XMLCP included'); +include($common['site']['incroot'] . 'xmlcp/xmlcp.php.inc'); +common_benchmark_addstep('common: XMLCP included'); -common_include('cms/cms.php.inc'); -common_benchmark_addstep('COMMON: CMS included'); +include($common['site']['incroot'] . 'cms/cms.php.inc'); +common_benchmark_addstep('common: CMS included'); //------------------------------------------------------------------------------ //- MySQL connection: -$common['dbc']['dbconnected'] = common_dbc_connectdb(); - -common_benchmark_addstep('COMMON: connect database'); +common_dbc_connectdb(); +common_benchmark_addstep('common: connect database'); //------------------------------------------------------------------------------ //- Session setup: @@ -107,13 +108,13 @@ // This is neccessary to make the $_SESSION global available: session_start(); -common_benchmark_addstep('COMMON: session init'); +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_benchmark_addstep('common: New session: start'); $common_sessiondata = array( @@ -132,17 +133,17 @@ ); - common_benchmark_addstep('COMMON: New session: create session'); + 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'); + 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'); + common_benchmark_addstep('common: New session: store session/end'); } else { @@ -156,9 +157,9 @@ $sql = "UPDATE hits SET requestcount=requestcount+1 WHERE id='" . $common_sessiondata['hit_id'] . "';"; - mysql_query($sql); + common_dbc_query($sql); - common_benchmark_addstep('COMMON: session/hit data updated'); + common_benchmark_addstep('common: session/hit data updated'); } @@ -183,7 +184,7 @@ $sql = "SELECT id, rights, logincount, lastlogin FROM users WHERE name='$username' AND password='$password';"; - $res = mysql_query($sql); + $res = common_dbc_query($sql); if(!$res) return false; @@ -214,7 +215,7 @@ $sql = "UPDATE users SET logincount='$logincount', lastlogin=FROM_UNIXTIME('$logintime') WHERE id='$userid';"; - $res = mysql_query($sql); + $res = common_dbc_query($sql); if(!$res) return false; @@ -237,13 +238,7 @@ $sql = "INSERT INTO hits (id, timestamp, address, entryurl, referer, sessionid, useragent, requestcount) VALUES (NULL, FROM_UNIXTIME('$unixtime'), '$address', '$entryurl', '$referer', '$sessionid', '$useragent', '1');"; - $res = mysql_query($sql); - - if ($errstr = mysql_error()) { - - print $errstr . "\n"; - - } + $res = common_dbc_query($sql); if(!$res) return false; @@ -252,7 +247,6 @@ } //---------------------------------------------------------- - //- Database functions: function common_dbc_connect() { @@ -294,359 +288,46 @@ function common_dbc_connectdb() { - return (common_dbc_connect() && common_dbc_selectdb()); - -} - -//---------------------------------------------------------- - -//- File functions: - -function common_include($filename) { - global $common; - return include($common['site']['incroot'] . $filename); - -} - -//---------------------------------------------------------- - -//- XMLCP setup: - -xmlcp_registertagcallbacks('b', 'common_cb_xmlcp_start_bold', 'common_cb_xmlcp_end_bold'); -xmlcp_registertagcallbacks('h', 'common_cb_xmlcp_start_headline', 'common_cb_xmlcp_end_headline'); -xmlcp_registertagcallbacks('p', 'common_cb_xmlcp_start_paragraph', 'common_cb_xmlcp_end_paragraph'); -xmlcp_registertagcallbacks('page', 'common_cb_xmlcp_start_page', 'common_cb_xmlcp_end_page'); - -function common_cb_xmlcp_end_bold($h_parser, $tagname) { - -global $xmlcp_cdata; - - $xmlcp_cdata .= ''; - -} - -function common_cb_xmlcp_start_bold($h_parser, $tagname, $attribs) { + $common['dbc']['dbconnected'] = (common_dbc_connect() && common_dbc_selectdb()); -global $xmlcp_cdata; - - $xmlcp_cdata .= ''; - -} - -function common_cb_xmlcp_end_page($h_parser, $tagname) { - -} - -function common_cb_xmlcp_start_page($h_parser, $tagname, $attribs) { + return $common['dbc']['dbconnected']; } -function common_cb_xmlcp_end_headline($h_parser, $tagname) { - -global $xmlcp_cdata; - - common_headline(trim($xmlcp_cdata)); - - $xmlcp_cdata = ''; - -} - -function common_cb_xmlcp_start_headline($h_parser, $tagname, $attribs) { - -global $xmlcp_cdata; - - $xmlcp_cdata = ''; - -} - -function common_cb_xmlcp_end_paragraph($h_parser, $tagname) { - -global $xmlcp_cdata; - - common_paragraph(trim($xmlcp_cdata)); - - $xmlcp_cdata = ''; - -} - -function common_cb_xmlcp_start_paragraph($h_parser, $tagname, $attribs) { - -global $xmlcp_cdata; - - $xmlcp_cdata = ''; - -} - -//---------------------------------------------------------- - -//- ML functions: - -function common_codeparagraph($contents) { - - echo '

- -' . $contents . ' - -

- -'; - -} - -//---------------------------------------------------------- - -function common_headline($caption) { - - echo '

' . $caption . '

- -'; - -} - -//---------------------------------------------------------- - -function common_page($keyname, $language_id = 0) { +function common_dbc_query($sql) { global $common; - common_benchmark_addstep('COMMON: PAGE: start'); - - $list = cms_getlist('xmlpage', $keyname); + if(!$common['dbc']['dbconnected']) return false; - common_benchmark_addstep('COMMON: PAGE: CMS get list'); - - $contentdata = cms_getcontent('xmlpage', $keyname, $language_id); - - common_benchmark_addstep('COMMON: PAGE: CMS get content'); - - $xml = $contentdata['content']; - - common_pageheader(); - - common_benchmark_addstep('COMMON: PAGE: header'); - - if($xml) { - - $titledata = ''; - - for($i = 0; $i < count($list); $i++) { - - $imgtag = ''; - - $titledata .= ($i ? ' -' : '') . (($language_id == $list[$i][3]) ? $imgtag : '' . $imgtag . ''); - - } - - common_pagetitle($contentdata['description'], $titledata . '
'); - - xmlcp_xmlpage2html($xml); - - common_benchmark_addstep('COMMON: PAGE: xmlpage2html'); - -/* - common_headline('$list array, readable:'); - common_codeparagraph('$list = ' . nl2br(htmlentities(print_r($list, true)))); - - common_headline('$contentdata array, readable:'); - common_codeparagraph('$contentdata = ' . nl2br(htmlentities(print_r($contentdata, true)))); - - common_headline('$common array, readable:'); - common_codeparagraph('$common = ' . nl2br(htmlentities(print_r($common, true)))); - - common_headline('$common_sessiondata array, readable:'); - common_codeparagraph('$common_sessiondata = ' . nl2br(htmlentities(print_r($common_sessiondata, true)))); - - common_headline('Content XML:'); - common_codeparagraph(nl2br(htmlentities($xml))); + $res = mysql_query($sql); -*/ + if($errormsg = mysql_error()) { - // Only show the informations when "devstate" is set: - if($common['hostsetup']['devstate']) { + // >>> MTC <<< - common_paragraph(' -Content informations:
+ echo $errormsg . '

-Description: "' . $contentdata['description'] . '" (Type: "xmlpage")
-Creator: "' . $contentdata['creator_name'] . '"
-Date, Time: "' . date('d.m.Y, H:i:s', $contentdata['unixtime']) . '"
-Language: "' . $contentdata['language_name'] . '"
-XML content size: ' . strlen($xml) . ' bytes -
', 'box2'); - - } - - } else { - - common_pagetitle('Bad content request'); - - common_paragraph('Sorry, but the requested content is unknown.'); - - } - - common_benchmark_addstep('COMMON: PAGE: content'); - - common_pagefooter(); - -} - -//---------------------------------------------------------- - -function common_pageheader() { - -global $common, $common_sessiondata; - - echo ' - - - - -www.netfrag.org - - - - - -
- - - - - -
-www.netfrag.org - -  - - - - - - - - -
User
login
 User: 
 Pass:
-
-
- '; -} - -//---------------------------------------------------------- - -function common_pagefooter() { - -global $common; - - // Only show the benchmark list when "devstate" is set: - if($common['hostsetup']['devstate']) { - - $contents = ''; - - for($i = 0; $i < count($common['benchmark']); $i++) { - - $mtimesegs = explode(' ', $common['benchmark'][$i][1]); - $contents .= '"' . $common['benchmark'][$i][0] . '": '; - - if($i) { - - $timediff = (float)($mtimesegs[1] - $lastmtimesegs[1]); - $timediff += $mtimesegs[0] - $lastmtimesegs[0]; - - $contents .= '+' . round($timediff * 1000000) / 1000 . ' ms
-'; - - } else { - - $contents .= 'Start time: ' . date('H:i:s', $mtimesegs[1]) . substr($mtimesegs[0], 1, 4) . '
-'; - - } - - $lastmtimesegs = $mtimesegs; - - } - - common_paragraph(' -Partial execution times:
-
-' . $contents . '
', 'box2'); - } - common_benchmark_addstep('COMMON: page footer'); - - $endmtimesegs = explode(' ', microtime()); - $startmtimesegs = explode(' ', $common['benchmark'][0][1]); - $timediff = (float)($endmtimesegs[1] - $startmtimesegs[1]); - $timediff += $endmtimesegs[0] - $startmtimesegs[0]; - - $devstate = $common['hostsetup']['devstate']; - - echo ' - - - - -
-Page execution time: ' . round($timediff * 100000) / 100 . ' ms.
-[ ' . ($devstate ? 'devstate off' : 'devstate on') . ' ] -
This page is valid XHTML 1.0 -Valid CSS!
- - - - -'; - -} - -//---------------------------------------------------------- - -function common_pagetitle($title, $additionalcontents = '') { + if(!$res) return false; - echo '

-• ' . $title . '  -' . ($additionalcontents ? $additionalcontents . ' -' : '') . '

- -'; + return $res; } //---------------------------------------------------------- +//- File functions: -function common_paragraph($contents, $class = '') { - - echo '

-' . $contents . ' -

- -'; -} //------------------------------------------------------------------------------ -common_benchmark_addstep('COMMON: end'); +common_benchmark_addstep('common: end'); //------------------------------------------------------------------------------