cvs: bugtracker /htdocs/index index.php /includes functions.php template.php /template/generic debug.php footer.html header.html
/template/generic/bug index.php /template/php home.html
| From: | Barry Carlyon | Date: | Fri, 01 Aug 2008 10:51:12 +0000 |
| Subject: | cvs: bugtracker /htdocs/index index.php /includes functions.php template.php /template/generic debug.php footer.html header.html /template/generic/bug index.php /template/php home.html |
||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-2273@lists.php.net to get a copy of this message | ||
bcarlyon Fri Aug 1 10:51:12 2008 UTC
Added files:
/bugtracker/includes template.php
/bugtracker/template/generic debug.php
Modified files:
/bugtracker/htdocs/index index.php
/bugtracker/includes functions.php
/bugtracker/template/generic footer.html header.html
/bugtracker/template/generic/bug index.php
/bugtracker/template/php home.html
Log:
completed the bulk of the template engine
http://cvs.php.net/viewvc.cgi/bugtracker/htdocs/index/index.php?r1=1.13&r2=1.14&diff_format=u Index: bugtracker/htdocs/index/index.php diff -u bugtracker/htdocs/index/index.php:1.13 bugtracker/htdocs/index/index.php:1.14 --- bugtracker/htdocs/index/index.php:1.13 Thu Jul 31 12:34:20 2008 +++ bugtracker/htdocs/index/index.php Fri Aug 1 10:51:11 2008 @@ -8,7 +8,7 @@ ***********************************************************/ //backtrace has something to talk too -$template_data = array('backtrace' => ''); +$backtrace = ''; $trace = ''; //before we start lets see if the database engine is online include($_SERVER['DOCUMENT_ROOT'] . '/config.php'); @@ -28,79 +28,40 @@ } //if that is ok lets boot the class in the ass! +//V3 template engine +include($_SERVER['DOCUMENT_ROOT'] . '../includes/template.php'); include($_SERVER['DOCUMENT_ROOT'] . '../includes/user.php'); include($_SERVER['DOCUMENT_ROOT'] . '../includes/email.php'); include($_SERVER['DOCUMENT_ROOT'] . '../includes/bug.php'); include($_SERVER['DOCUMENT_ROOT'] . '../includes/comment.php'); include($_SERVER['DOCUMENT_ROOT'] . '../includes/cache.php'); + +$template = new template(); $user = new user(); $email = new email(); $bug = new bug(); $comment = new comment(); $cache = new cache(); -//cahce! +//cache! $cache->load_cache(); +$template->initialize(); -//email set up -$email_data = array(); -$email_data['send'] = FALSE; - -//we need to determine what bug tracker templates to use -$bugtracker = array_shift(explode(".",$_SERVER['HTTP_HOST'])); -//lets check to see if those templates exist -$template = is_dir($_SERVER['DOCUMENT_ROOT'] . '../template/' . $bugtracker) ? $bugtracker : 'php'; - -/* -//lets generate some useful template varibles -//however first lets include the caches -include($_SERVER['DOCUMENT_ROOT'] . '../includes/cachelist.php'); -//open cache dir -if ($handle = opendir($_SERVER['DOCUMENT_ROOT'] . '../includes/cache/')) -{ - while (FALSE !== ($file = readdir($handle))) - { - if ($file != "." && $file != "..") - { - $ref = explode(".",$file); - if ($ref[1] == 'php') - { - include($_SERVER['DOCUMENT_ROOT'] . '../includes/cache/' . $file); - //lets compile the element into the $cache - } - } - } - closedir($handle); -} -//hack in a version of php -$php_version[0] = 'Irrelevant'; -*/ - -$form_data = array();//array for holding the data in forms -$display_data = array();// array for holding all the display data that users could of entered -$template_data = array_merge($template_data, array( - 'page_title' => 'PHP Bugs', - 'content_title' => '', - 'year' => date('Y',time()), - 'url' => ($_REQUEST['page']) ? $_REQUEST['page'] : 'home', - 'alternative_stylesheet' => '', - 'login' => '<li><a href="/account-request.php">Register</a></li>' . "\n" . '<li><a href="/login.php?redirect=">Login</a></li>', - 'login' => "\n" . '<li><a href="/login/">Login</a></li>', - 'favicon' => '', - 'system_error' => '', - ) -); -//$template_data['cvs_version'] = substr( $php_version[sizeof($php_version)] ,0,4); -//$template_data['cvs_version'] = substr( $php_version[sizeof($php_version)-1] ,0,4); -$cache->add_to_cache('php_version', 'Irrelevant', '0'); -$template_data['cvs_version'] = substr( $cache->obtain('php_version',-1), 0, 4 ); +//this is where we do stuff +//its related to the page we are requesting from the server +$template->determine_template(); -if ($template != 'php') -{ - $template_data['page_title'] .= ' ' . titleit($bugtracker); - $template_data['favicon'] = 'http://' . $bugtracker . '.php.net'; - $template_data['alternative_stylesheet'] = '<link rel="stylesheet" type="text/css" href="/elements/' . strtolower($bugtracker) . '.css" media="screen" />'; -} +$template->load_template(); + +//now we have stopped doing stuff + +$template->compile_and_echo(); + +//last tasks +$db->close(); +unset($db); + +exit; //now then is the user logged in? $user->check_auth(); @@ -111,158 +72,3 @@ $template_data['else logged_in'] = '-->'; $template_data['endif logged_in'] = ''; -$jsscripts = array(); -$meta_refresh = array(); - -$content = ''; - -//next job is to determine which file we need to load template/content wise -$page = ($_REQUEST['page']) ? $_REQUEST['page'] : 'home'; -if (substr($page,-1,1) == '/') -{ - $page = substr($page,0,-1); - //lop off the / at the end -} - -//switched to ALWAYS tpl_process - -if (is_file($_SERVER['DOCUMENT_ROOT'] . '../template/' . $template . '/' . $page . '.html')) -{ -// $content .= tpl_process($template . '/' . $page . '.html'); - $content .= $template . '/' . $page . '.html'; -} -else if (is_file($_SERVER['DOCUMENT_ROOT'] . '../template/' . $template . '/' . $page . '.php')) -{ - include($_SERVER['DOCUMENT_ROOT'] . '../template/' . $template . '/' . $page . '.php'); -} - -else if (is_file($_SERVER['DOCUMENT_ROOT'] . '../template/' . $template . '/' . $page . '/index.html')) -{ -// $content .= tpl_process($template . '/' . $page . '/index.html'); - $content .= $template . '/' . $page . '/index.html'; -} -else if (is_file($_SERVER['DOCUMENT_ROOT'] . '../template/' . $template . '/' . $page . '/index.php')) -{ - include($_SERVER['DOCUMENT_ROOT'] . '../template/' . $template . '/' . $page . '/index.php'); -} - -else if (is_file($_SERVER['DOCUMENT_ROOT'] . '../template/generic/' . $page . '.html')) -{ -// $content .= tpl_process('generic/' . $page . '.html'); - $content .= 'generic/' . $page . '.html'; -} -else if (is_file($_SERVER['DOCUMENT_ROOT'] . '../template/generic/' . $page . '.php')) -{ - include($_SERVER['DOCUMENT_ROOT'] . '../template/generic/' . $page . '.php'); -} - -else if (is_file($_SERVER['DOCUMENT_ROOT'] . '../template/generic/' . $page . '/index.html.')) -{ -// $content .= tpl_process('generic/' . $page . '/index.html'); - $content .= 'generic/' . $page . '/index.html'; -} -else if (is_file($_SERVER['DOCUMENT_ROOT'] . '../template/generic/' . $page . '/index.php')) -{ - include($_SERVER['DOCUMENT_ROOT'] . '../template/generic/' . $page . '/index.php'); -} - -else -{ - header("HTTP/1.0 404 Not Found"); - $page = '404'; -// $template_data['page_title'] .= ' | 404 File Not Found'; - $content .= '<h2>404 File Not Found</h2>'; -// $content .= tpl_process('/generic/404.html'); -// $content .= '/generic/404.html'; - $template_data['system_error'] = 'I am sorry the file (<strong>{URL}</strong>) you have requested could not be found'; -} - -$template_data['queries'] = $db->query_count; - -$content = tpl_process($content); -$content = create_title($content); - -$content = tpl_process('generic/header.html', $jsscripts, $meta_refresh) . $content . '<br />' . tpl_process('generic/footer.html'); -//lets cheat in the world of table fixing for display -$content = str_replace('<table','<table cellspacing="0" cellpadding="0"',$content); - -echo $content; - -//penultimate task -/* -if ($email_data['send']) -{ - $email->send(); -} -*/ - -//last task -$db->close(); -unset($db); - -// COMMENCE TRACE -echo '<textarea style="width: 95%; height: 200px; border: 1px solid #000;" rows="10" cols="50">debug: ' . "\n"; - -echo ' -trace: -'; -echo $trace; - -echo ' - -cookie -'; -print_r($_COOKIE); - -echo ' -display -'; -//print_r($template_data); -foreach ($display_data as $ref => $data) -{ -echo $ref . ' - ' . htmlentities($data) . "\n"; -} - -echo ' -tpl -'; -//print_r($template_data); -foreach ($template_data as $ref => $data) -{ -echo $ref . ' - ' . htmlentities($data) . "\n"; -} - -echo ' -form_data -'; -//print_r($template_data); -foreach ($form_data as $ref => $data) -{ - if (is_array($data)) - { - foreach ($data as $aref => $adata) - echo $aref . ' - ' . htmlentities($adata) . "\n"; - } - else - { - echo $ref . ' - ' . htmlentities($data) . "\n"; - } -} - - -echo ' -server -'; -//print_r($template_data); -foreach ($_SERVER as $ref => $data) -{ -echo $ref . ' - ' . htmlentities($data) . "\n"; -} - -echo '</textarea>'; - -echo ' -</body> -</html> -'; - http://cvs.php.net/viewvc.cgi/bugtracker/includes/functions.php?r1=1.15&r2=1.16&diff_format=u Index: bugtracker/includes/functions.php diff -u bugtracker/includes/functions.php:1.15 bugtracker/includes/functions.php:1.16 --- bugtracker/includes/functions.php:1.15 Thu Jul 31 13:27:30 2008 +++ bugtracker/includes/functions.php Fri Aug 1 10:51:11 2008 @@ -128,6 +128,7 @@ $html = str_replace('{' . strtoupper($ref) . '}',$replace,$html); } } +/* if ($jsscripts) { foreach ($jsscripts as $jsscript) @@ -140,6 +141,7 @@ $meta = '<meta http-equiv="refresh" content="' . $meta_refresh['time'] . ';' . $meta_refresh['url'] .'" />'; $html = str_replace('</head>',$meta . "\n" . '</head>',$html); } +*/ return $html; } @@ -167,7 +169,7 @@ function theerrorhandler($errno, $errstr, $errfile, $errline) { - global $template_data; + global $backtrace; $fail = ''; switch ($errno) { case E_USER_ERROR: @@ -188,9 +190,9 @@ break; } - $template_data['backtrace'] .= '<strong>' . $fail . '</strong>'; + $backtrace .= '<strong>' . $fail . '</strong>'; errorarray(debug_backtrace()); - $template_data['backtrace'] = '<div id="error" style="font-size: 8px;">' . $template_data['backtrace'] . '</div>'; + $backtrace = '<div id="error" style="font-size: 8px;">' . $backtrace . '</div>'; $first_flag = FALSE; @@ -199,7 +201,7 @@ function errorarray($array) { - global $template_data,$first_flag; + global $backtrace,$first_flag; foreach ($array as $ref => $data) { if (!$first_flag) @@ -208,14 +210,14 @@ } else { - $template_data['backtrace'] .= '<br />'; + $backtrace .= '<br />'; if (!is_numeric($ref)) { - $template_data['backtrace'] .= $ref. ': '; + $backtrace .= $ref. ': '; } if (get_class($data)) { - $template_data['backtrace'] .= get_class($data); + $backtrace .= get_class($data); } else if (is_array($data)) { @@ -223,7 +225,7 @@ } else { - $template_data['backtrace'] .= $data; + $backtrace .= $data; } } } http://cvs.php.net/viewvc.cgi/bugtracker/template/generic/footer.html?r1=1.1&r2=1.2&diff_format=u Index: bugtracker/template/generic/footer.html diff -u bugtracker/template/generic/footer.html:1.1 bugtracker/template/generic/footer.html:1.2 --- bugtracker/template/generic/footer.html:1.1 Wed Jul 9 13:07:22 2008 +++ bugtracker/template/generic/footer.html Fri Aug 1 10:51:11 2008 @@ -1,9 +1,8 @@ <div id="footer_top"> - <a href="/source.php?url={URL}">show source</a> </div> <div id="footer_base"> <a href="/" id="sm_logo">Home</a> - <p id="updated">Last updated: <br />Queries used: {QUERIES}</p> + <p id="updated">Last updated: {LAST}<br />Queries used: {QUERIES}</p> <p id="copyright"><a href="copyright.php">Copyright © 2001-{YEAR} The PHP Group</a></p> <p>All rights reserved.</p> </div> http://cvs.php.net/viewvc.cgi/bugtracker/template/generic/header.html?r1=1.5&r2=1.6&diff_format=u Index: bugtracker/template/generic/header.html diff -u bugtracker/template/generic/header.html:1.5 bugtracker/template/generic/header.html:1.6 --- bugtracker/template/generic/header.html:1.5 Thu Jul 31 02:38:33 2008 +++ bugtracker/template/generic/header.html Fri Aug 1 10:51:11 2008 @@ -18,15 +18,13 @@ <link rel="stylesheet" type="text/css" href="/elements/reset.css" media="screen" /> <link rel="stylesheet" type="text/css" href="/style.css" media="screen" /> <link rel="stylesheet" type="text/css" href="/elements/screen.php" media="screen" /> -{ALTERNATIVE_STYLESHEET} -<!-- -css files go here -javascript files go here -xml files go here ---> +{ALTERNATIVE_CSS} + <script type="text/javascript" src="/elements/js/wrapper.js" ></script> <title>{PAGE_TITLE}</title> +{META} +{JAVASCRIPT} </head> <body> <a name="top" id="top"></a> http://cvs.php.net/viewvc.cgi/bugtracker/template/generic/bug/index.php?r1=1.15&r2=1.16&diff_format=u Index: bugtracker/template/generic/bug/index.php diff -u bugtracker/template/generic/bug/index.php:1.15 bugtracker/template/generic/bug/index.php:1.16 --- bugtracker/template/generic/bug/index.php:1.15 Thu Jul 31 12:34:21 2008 +++ bugtracker/template/generic/bug/index.php Fri Aug 1 10:51:11 2008 @@ -188,6 +188,9 @@ //how are we going to calculate the queue length? $query = 'SELECT *,UNIX_TIMESTAMP(updated),UNIX_TIMESTAMP(reported_on) FROM bug ORDER BY bug_id ASC'; + + //filters.... + $db->get_data($query); $content .= '<h2>Bug Summary</h2>'; @@ -200,18 +203,18 @@ while ($row = $db->fetch_row()) { $content .= '<tr>'; - $content .= '<td style="text-align: center;"><a href="' . $row['bug_id'] . '" title="View Bug">#' . $row['bug_id'] . '</a></td><td>' . $row['summary'] . '</td>'; - $content .= '<td>' . $row['reported_by'] . '</td>'; - $content .= '<td>' . $status[$row['status']] . '</td>'; + $content .= '<td style="text-align: center;"><a href="{DSP_BUG_ID}" title="View Bug">#{DSP_BUG_ID}</a></td><td>{DSP_SUMMARY}</td>'; + $content .= '<td>{DSP_SUMMARY}</td>'; + $content .= '<td>{DSP_STATUS}</td>'; if ($row['status']) { - $content .= '<td>' . date('r',$row['UNIX_TIMESTAMP(updated)']) . '</td>'; + $content .= '<td>{DSP_UPDATED}</td>'; } else { - $content .= '<td>' . date('r',$row['UNIX_TIMESTAMP(reported_on)']) . '</td>'; + $content .= '<td>{DSP_REPORTED_ON}</td>'; } - $content .= '<td><a href="' . $row['bug_id'] . '" title="View Bug">View Bug</a></td>'; + $content .= '<td><a href="{DSP_BUG_ID}" title="View Bug">View Bug</a></td>'; $content .= '</tr>'; } $content .= '</table>'; http://cvs.php.net/viewvc.cgi/bugtracker/template/php/home.html?r1=1.3&r2=1.4&diff_format=u Index: bugtracker/template/php/home.html diff -u bugtracker/template/php/home.html:1.3 bugtracker/template/php/home.html:1.4 --- bugtracker/template/php/home.html:1.3 Sat Jul 26 02:33:44 2008 +++ bugtracker/template/php/home.html Fri Aug 1 10:51:11 2008 @@ -8,6 +8,8 @@ <p>You can view the current <a href="/bug/" title="View Bugs">bug listings</a></p> <div id="error"> +Don't be surprised if this site is buggered +<!-- Current Test: <br /><br /> Report a bug @@ -23,6 +25,7 @@ Let me know of pass or fail to <a href="irc://efnet.teleglobe.net/foobared">#foobared on efnet</a> <br /> Also feedback on profile fields +--> </div> <br /><br /><hr /> http://cvs.php.net/viewvc.cgi/bugtracker/includes/template.php?view=markup&rev=1.1 Index: bugtracker/includes/template.php +++ bugtracker/includes/template.php <?php //this is the template engine version 2 /* Release notes this file takes all the elements I usually define in functions add to that all the stuff gsoc has taught me plus all the stuff I have learnt whilst working with classes finally this will actually work properly at lease it will when all the subsequent functions are written and are operational */ class template { public $prehtml = ''; public $html = ''; // set up some nice template varibles public $page_title = 'PHP Bugs | '; public $meta = ''; public $javascript = ''; public $alternative_css = ''; public $favicon = ''; public $content_title = ' '; public $login = '<li> </li>'; public $template_data = array(); public $form_data = array(); public $display_data = array(); public $form_error = ''; public $system_error = ''; //on new //we need to determine what bug tracker templates to use public $bugtracker = ''; //lets check to see if those templates exist public $template_dir = ''; function initialize() { $this->bugtracker = array_shift(explode(".", strtolower($_SERVER['HTTP_HOST']))); $this->template_dir = is_dir($_SERVER['DOCUMENT_ROOT'] . '../template/' . $this->bugtracker) ? $this->bugtracker : ''; $this->alternative_css = (!empty($this->template_dir)) ? '<link rel="stylesheet" type="text/css" href="/elements/' . $this->bugtracker . '.css" media="screen" />' : ''; $this->favicon = (!empty($this->template_dir)) ? 'http://' . $bugtracker . '.php.net' : ''; $this->template_dir = (!empty($this->template_dir)) ? $this->template_dir : 'php'; $this->server = $_SERVER; $this->request = $_REQUEST; $this->get = $_GET; $this->post = $_POST; $this->cookie = $_COOKIE; } // this function will create the head element <title> or at least the content within it function page_title() { $code = explode('</h2>', $this->prehtml); $code = explode('<h2>',$code[0]); $code = $code[1] ? $code[1] : $code[0]; $this->page_title .= $code; $this->content_title = $code; $this->prehtml = str_replace('<h2>' . $code . '</h2>', '', $this->prehtml); return; } function meta_refresh($target, $time = 3) { $this->meta = '<meta tt-equive="refresh" content="' . $target . ';' . $time . '" />' . "\n"; } function load_jscript($jscripts) { if (is_array($jscripts)) { foreach ($jsscript as $script) { $this->javascript .= '<script type="text/javascript" src="' . $script . '"></script>' . "\n"; } } else { $this->javascript .= '<script type="text/javascript" src="' . $jscripts . '"></script>' . "\n"; } } function generate_header() { $this->html = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '../template/generic/header.html'); $this->swap('year', date('Y',time()) ); $this->swap('page_title', $this->page_title ); $this->swap('meta', $this->meta ); $this->swap('javascript', $this->javascript ); $this->swap('content_title', $this->content_title ); $this->swap('favicon', $this->favicon ); $this->swap('alternative_css', $this->alternative_css ); global $backtrace; $this->swap('backtrace', $backtrace ); $this->swap('login', $this->login ); if ($this->system_error) { $this->system_error = '<div id="error">' . $this->system_error . '</div>'; } $this->swap('system_error', $this->system_error ); $this->swap('form_error', $this->form_error ); return; } function generate_footer() { global $db, $trace; $this->html .= file_get_contents($_SERVER['DOCUMENT_ROOT'] . '../template/generic/footer.html'); $this->swap('queries', $db->query_count ); $this->swap('year', date('Y',time()) ); $this->swap('last', date('r',filemtime($this->template_file))); //debug?? $debug = ''; include($_SERVER['DOCUMENT_ROOT'] . '../template/generic/debug.php'); $this->html .= $debug; $this->html .= "\n" . '</body>' . "\n" . '</html>'; return; } function compile_and_echo() { $this->generate_header(); $this->html .= $this->prehtml; $this->generate_footer(); echo $this->html; return; } function swap($target, $victim) { $this->html = str_replace('{' . strtoupper($target) . '}', $victim, $this->html); return; } function loop($loop_data, $loop_html) { $this->loop_html = $loop_html; foreach ($loop_data as $ref => $data) { $this->html .= $this->loop_html; swap($ref, $data); } return; } function sanitize($in) { $out = $in; return $out; } function determine_template() { $base_directory = $_SERVER['DOCUMENT_ROOT'] . '../template/'; $base_this = $base_directory . $this->template_dir . '/'; $this->page = $this->request['page'] ? $this->request['page'] : 'home'; if (substr($this->page,-1,1) == '/') { $this->page = substr($this->page, 0, -1); //lop off te follodwing / if it exists } //its the greate template hunt..... /*..php .html with b_this base page base page index no b_this base generic page base generic page index */ $this->h_or_p($base_this . $this->page); if ($this->template_type == FALSE) { $this->h_or_p($base_this . $this->page . '/index'); } if ($this->template_type == FALSE) { $this->h_or_p($base_directory . 'generic/' . $this->page); } if ($this->template_type == FALSE) { $this->h_or_p($base_directory . 'generic/' . $this->page . '/index'); } if ($this->template_type == FALSE) { //then its a 404! $this->h_or_p($base_directory . 'generic/404'); $this->template_file = $base_directory . 'generic/404.' . $template_type; header("HTTP/1.0 404 Not Found"); $this->system_error = 'I am sorry the file (<strong>' . $this->page . '</strong>) you have requested could not be found'; } else { header("HTTP/1.0 200 OK"); } return; } function h_or_p($file) { if (is_file($file . '.php')) { $this->template_type = 'php'; $this->template_file = $file . '.php'; } else if (is_file($file . '.html')) { $this->template_type = 'html'; $this->template_file = $file . '.html'; } else { $this->template_type = FALSE; $this->template_file = ''; } return; } function load_template() { if ($this->template_type == 'php') { include($this->template_file); } if ($this->template_type == 'html') { $this->prehtml = file_get_contents($this->template_file); //we need to process the html to extract some things $this->page_title(); } return; } } http://cvs.php.net/viewvc.cgi/bugtracker/template/generic/debug.php?view=markup&rev=1.1 Index: bugtracker/template/generic/debug.php +++ bugtracker/template/generic/debug.php <?php $debug = ' <textarea style="width: 95%; height: 200px; border: 1px solid #000;" rows="10" cols="50">debug: trace: ' . $trace . ' cookie: '; foreach ($_COOKIE as $ref => $data) { $debug .= $ref . ' - ' . htmlentities($data) . "\n"; } $debug .= ' server: '; foreach ($_SERVER as $ref => $data) { $debug .= $ref . ' - ' . htmlentities($data) . "\n"; } $debug .= ' </textarea> ';
http://cvs.php.net/viewvc.cgi/bugtracker/htdocs/index/index.php?r1=1.13&r2=1.14&diff_format=u Index: bugtracker/htdocs/index/index.php diff -u bugtracker/htdocs/index/index.php:1.13 bugtracker/htdocs/index/index.php:1.14 --- bugtracker/htdocs/index/index.php:1.13 Thu Jul 31 12:34:20 2008 +++ bugtracker/htdocs/index/index.php Fri Aug 1 10:51:11 2008 @@ -8,7 +8,7 @@ ***********************************************************/ //backtrace has something to talk too -$template_data = array('backtrace' => ''); +$backtrace = ''; $trace = ''; //before we start lets see if the database engine is online include($_SERVER['DOCUMENT_ROOT'] . '/config.php'); @@ -28,79 +28,40 @@ } //if that is ok lets boot the class in the ass! +//V3 template engine +include($_SERVER['DOCUMENT_ROOT'] . '../includes/template.php'); include($_SERVER['DOCUMENT_ROOT'] . '../includes/user.php'); include($_SERVER['DOCUMENT_ROOT'] . '../includes/email.php'); include($_SERVER['DOCUMENT_ROOT'] . '../includes/bug.php'); include($_SERVER['DOCUMENT_ROOT'] . '../includes/comment.php'); include($_SERVER['DOCUMENT_ROOT'] . '../includes/cache.php'); + +$template = new template(); $user = new user(); $email = new email(); $bug = new bug(); $comment = new comment(); $cache = new cache(); -//cahce! +//cache! $cache->load_cache(); +$template->initialize(); -//email set up -$email_data = array(); -$email_data['send'] = FALSE; - -//we need to determine what bug tracker templates to use -$bugtracker = array_shift(explode(".",$_SERVER['HTTP_HOST'])); -//lets check to see if those templates exist -$template = is_dir($_SERVER['DOCUMENT_ROOT'] . '../template/' . $bugtracker) ? $bugtracker : 'php'; - -/* -//lets generate some useful template varibles -//however first lets include the caches -include($_SERVER['DOCUMENT_ROOT'] . '../includes/cachelist.php'); -//open cache dir -if ($handle = opendir($_SERVER['DOCUMENT_ROOT'] . '../includes/cache/')) -{ - while (FALSE !== ($file = readdir($handle))) - { - if ($file != "." && $file != "..") - { - $ref = explode(".",$file); - if ($ref[1] == 'php') - { - include($_SERVER['DOCUMENT_ROOT'] . '../includes/cache/' . $file); - //lets compile the element into the $cache - } - } - } - closedir($handle); -} -//hack in a version of php -$php_version[0] = 'Irrelevant'; -*/ - -$form_data = array();//array for holding the data in forms -$display_data = array();// array for holding all the display data that users could of entered -$template_data = array_merge($template_data, array( - 'page_title' => 'PHP Bugs', - 'content_title' => '', - 'year' => date('Y',time()), - 'url' => ($_REQUEST['page']) ? $_REQUEST['page'] : 'home', - 'alternative_stylesheet' => '', - 'login' => '<li><a href="/account-request.php">Register</a></li>' . "\n" . '<li><a href="/login.php?redirect=">Login</a></li>', - 'login' => "\n" . '<li><a href="/login/">Login</a></li>', - 'favicon' => '', - 'system_error' => '', - ) -); -//$template_data['cvs_version'] = substr( $php_version[sizeof($php_version)] ,0,4); -//$template_data['cvs_version'] = substr( $php_version[sizeof($php_version)-1] ,0,4); -$cache->add_to_cache('php_version', 'Irrelevant', '0'); -$template_data['cvs_version'] = substr( $cache->obtain('php_version',-1), 0, 4 ); +//this is where we do stuff +//its related to the page we are requesting from the server +$template->determine_template(); -if ($template != 'php') -{ - $template_data['page_title'] .= ' ' . titleit($bugtracker); - $template_data['favicon'] = 'http://' . $bugtracker . '.php.net'; - $template_data['alternative_stylesheet'] = '<link rel="stylesheet" type="text/css" href="/elements/' . strtolower($bugtracker) . '.css" media="screen" />'; -} +$template->load_template(); + +//now we have stopped doing stuff + +$template->compile_and_echo(); + +//last tasks +$db->close(); +unset($db); + +exit; //now then is the user logged in? $user->check_auth(); @@ -111,158 +72,3 @@ $template_data['else logged_in'] = '-->'; $template_data['endif logged_in'] = ''; -$jsscripts = array(); -$meta_refresh = array(); - -$content = ''; - -//next job is to determine which file we need to load template/content wise -$page = ($_REQUEST['page']) ? $_REQUEST['page'] : 'home'; -if (substr($page,-1,1) == '/') -{ - $page = substr($page,0,-1); - //lop off the / at the end -} - -//switched to ALWAYS tpl_process - -if (is_file($_SERVER['DOCUMENT_ROOT'] . '../template/' . $template . '/' . $page . '.html')) -{ -// $content .= tpl_process($template . '/' . $page . '.html'); - $content .= $template . '/' . $page . '.html'; -} -else if (is_file($_SERVER['DOCUMENT_ROOT'] . '../template/' . $template . '/' . $page . '.php')) -{ - include($_SERVER['DOCUMENT_ROOT'] . '../template/' . $template . '/' . $page . '.php'); -} - -else if (is_file($_SERVER['DOCUMENT_ROOT'] . '../template/' . $template . '/' . $page . '/index.html')) -{ -// $content .= tpl_process($template . '/' . $page . '/index.html'); - $content .= $template . '/' . $page . '/index.html'; -} -else if (is_file($_SERVER['DOCUMENT_ROOT'] . '../template/' . $template . '/' . $page . '/index.php')) -{ - include($_SERVER['DOCUMENT_ROOT'] . '../template/' . $template . '/' . $page . '/index.php'); -} - -else if (is_file($_SERVER['DOCUMENT_ROOT'] . '../template/generic/' . $page . '.html')) -{ -// $content .= tpl_process('generic/' . $page . '.html'); - $content .= 'generic/' . $page . '.html'; -} -else if (is_file($_SERVER['DOCUMENT_ROOT'] . '../template/generic/' . $page . '.php')) -{ - include($_SERVER['DOCUMENT_ROOT'] . '../template/generic/' . $page . '.php'); -} - -else if (is_file($_SERVER['DOCUMENT_ROOT'] . '../template/generic/' . $page . '/index.html.')) -{ -// $content .= tpl_process('generic/' . $page . '/index.html'); - $content .= 'generic/' . $page . '/index.html'; -} -else if (is_file($_SERVER['DOCUMENT_ROOT'] . '../template/generic/' . $page . '/index.php')) -{ - include($_SERVER['DOCUMENT_ROOT'] . '../template/generic/' . $page . '/index.php'); -} - -else -{ - header("HTTP/1.0 404 Not Found"); - $page = '404'; -// $template_data['page_title'] .= ' | 404 File Not Found'; - $content .= '<h2>404 File Not Found</h2>'; -// $content .= tpl_process('/generic/404.html'); -// $content .= '/generic/404.html'; - $template_data['system_error'] = 'I am sorry the file (<strong>{URL}</strong>) you have requested could not be found'; -} - -$template_data['queries'] = $db->query_count; - -$content = tpl_process($content); -$content = create_title($content); - -$content = tpl_process('generic/header.html', $jsscripts, $meta_refresh) . $content . '<br />' . tpl_process('generic/footer.html'); -//lets cheat in the world of table fixing for display -$content = str_replace('<table','<table cellspacing="0" cellpadding="0"',$content); - -echo $content; - -//penultimate task -/* -if ($email_data['send']) -{ - $email->send(); -} -*/ - -//last task -$db->close(); -unset($db); - -// COMMENCE TRACE -echo '<textarea style="width: 95%; height: 200px; border: 1px solid #000;" rows="10" cols="50">debug: ' . "\n"; - -echo ' -trace: -'; -echo $trace; - -echo ' - -cookie -'; -print_r($_COOKIE); - -echo ' -display -'; -//print_r($template_data); -foreach ($display_data as $ref => $data) -{ -echo $ref . ' - ' . htmlentities($data) . "\n"; -} - -echo ' -tpl -'; -//print_r($template_data); -foreach ($template_data as $ref => $data) -{ -echo $ref . ' - ' . htmlentities($data) . "\n"; -} - -echo ' -form_data -'; -//print_r($template_data); -foreach ($form_data as $ref => $data) -{ - if (is_array($data)) - { - foreach ($data as $aref => $adata) - echo $aref . ' - ' . htmlentities($adata) . "\n"; - } - else - { - echo $ref . ' - ' . htmlentities($data) . "\n"; - } -} - - -echo ' -server -'; -//print_r($template_data); -foreach ($_SERVER as $ref => $data) -{ -echo $ref . ' - ' . htmlentities($data) . "\n"; -} - -echo '</textarea>'; - -echo ' -</body> -</html> -'; - http://cvs.php.net/viewvc.cgi/bugtracker/includes/functions.php?r1=1.15&r2=1.16&diff_format=u Index: bugtracker/includes/functions.php diff -u bugtracker/includes/functions.php:1.15 bugtracker/includes/functions.php:1.16 --- bugtracker/includes/functions.php:1.15 Thu Jul 31 13:27:30 2008 +++ bugtracker/includes/functions.php Fri Aug 1 10:51:11 2008 @@ -128,6 +128,7 @@ $html = str_replace('{' . strtoupper($ref) . '}',$replace,$html); } } +/* if ($jsscripts) { foreach ($jsscripts as $jsscript) @@ -140,6 +141,7 @@ $meta = '<meta http-equiv="refresh" content="' . $meta_refresh['time'] . ';' . $meta_refresh['url'] .'" />'; $html = str_replace('</head>',$meta . "\n" . '</head>',$html); } +*/ return $html; } @@ -167,7 +169,7 @@ function theerrorhandler($errno, $errstr, $errfile, $errline) { - global $template_data; + global $backtrace; $fail = ''; switch ($errno) { case E_USER_ERROR: @@ -188,9 +190,9 @@ break; } - $template_data['backtrace'] .= '<strong>' . $fail . '</strong>'; + $backtrace .= '<strong>' . $fail . '</strong>'; errorarray(debug_backtrace()); - $template_data['backtrace'] = '<div id="error" style="font-size: 8px;">' . $template_data['backtrace'] . '</div>'; + $backtrace = '<div id="error" style="font-size: 8px;">' . $backtrace . '</div>'; $first_flag = FALSE; @@ -199,7 +201,7 @@ function errorarray($array) { - global $template_data,$first_flag; + global $backtrace,$first_flag; foreach ($array as $ref => $data) { if (!$first_flag) @@ -208,14 +210,14 @@ } else { - $template_data['backtrace'] .= '<br />'; + $backtrace .= '<br />'; if (!is_numeric($ref)) { - $template_data['backtrace'] .= $ref. ': '; + $backtrace .= $ref. ': '; } if (get_class($data)) { - $template_data['backtrace'] .= get_class($data); + $backtrace .= get_class($data); } else if (is_array($data)) { @@ -223,7 +225,7 @@ } else { - $template_data['backtrace'] .= $data; + $backtrace .= $data; } } } http://cvs.php.net/viewvc.cgi/bugtracker/template/generic/footer.html?r1=1.1&r2=1.2&diff_format=u Index: bugtracker/template/generic/footer.html diff -u bugtracker/template/generic/footer.html:1.1 bugtracker/template/generic/footer.html:1.2 --- bugtracker/template/generic/footer.html:1.1 Wed Jul 9 13:07:22 2008 +++ bugtracker/template/generic/footer.html Fri Aug 1 10:51:11 2008 @@ -1,9 +1,8 @@ <div id="footer_top"> - <a href="/source.php?url={URL}">show source</a> </div> <div id="footer_base"> <a href="/" id="sm_logo">Home</a> - <p id="updated">Last updated: <br />Queries used: {QUERIES}</p> + <p id="updated">Last updated: {LAST}<br />Queries used: {QUERIES}</p> <p id="copyright"><a href="copyright.php">Copyright © 2001-{YEAR} The PHP Group</a></p> <p>All rights reserved.</p> </div> http://cvs.php.net/viewvc.cgi/bugtracker/template/generic/header.html?r1=1.5&r2=1.6&diff_format=u Index: bugtracker/template/generic/header.html diff -u bugtracker/template/generic/header.html:1.5 bugtracker/template/generic/header.html:1.6 --- bugtracker/template/generic/header.html:1.5 Thu Jul 31 02:38:33 2008 +++ bugtracker/template/generic/header.html Fri Aug 1 10:51:11 2008 @@ -18,15 +18,13 @@ <link rel="stylesheet" type="text/css" href="/elements/reset.css" media="screen" /> <link rel="stylesheet" type="text/css" href="/style.css" media="screen" /> <link rel="stylesheet" type="text/css" href="/elements/screen.php" media="screen" /> -{ALTERNATIVE_STYLESHEET} -<!-- -css files go here -javascript files go here -xml files go here ---> +{ALTERNATIVE_CSS} + <script type="text/javascript" src="/elements/js/wrapper.js" ></script> <title>{PAGE_TITLE}</title> +{META} +{JAVASCRIPT} </head> <body> <a name="top" id="top"></a> http://cvs.php.net/viewvc.cgi/bugtracker/template/generic/bug/index.php?r1=1.15&r2=1.16&diff_format=u Index: bugtracker/template/generic/bug/index.php diff -u bugtracker/template/generic/bug/index.php:1.15 bugtracker/template/generic/bug/index.php:1.16 --- bugtracker/template/generic/bug/index.php:1.15 Thu Jul 31 12:34:21 2008 +++ bugtracker/template/generic/bug/index.php Fri Aug 1 10:51:11 2008 @@ -188,6 +188,9 @@ //how are we going to calculate the queue length? $query = 'SELECT *,UNIX_TIMESTAMP(updated),UNIX_TIMESTAMP(reported_on) FROM bug ORDER BY bug_id ASC'; + + //filters.... + $db->get_data($query); $content .= '<h2>Bug Summary</h2>'; @@ -200,18 +203,18 @@ while ($row = $db->fetch_row()) { $content .= '<tr>'; - $content .= '<td style="text-align: center;"><a href="' . $row['bug_id'] . '" title="View Bug">#' . $row['bug_id'] . '</a></td><td>' . $row['summary'] . '</td>'; - $content .= '<td>' . $row['reported_by'] . '</td>'; - $content .= '<td>' . $status[$row['status']] . '</td>'; + $content .= '<td style="text-align: center;"><a href="{DSP_BUG_ID}" title="View Bug">#{DSP_BUG_ID}</a></td><td>{DSP_SUMMARY}</td>'; + $content .= '<td>{DSP_SUMMARY}</td>'; + $content .= '<td>{DSP_STATUS}</td>'; if ($row['status']) { - $content .= '<td>' . date('r',$row['UNIX_TIMESTAMP(updated)']) . '</td>'; + $content .= '<td>{DSP_UPDATED}</td>'; } else { - $content .= '<td>' . date('r',$row['UNIX_TIMESTAMP(reported_on)']) . '</td>'; + $content .= '<td>{DSP_REPORTED_ON}</td>'; } - $content .= '<td><a href="' . $row['bug_id'] . '" title="View Bug">View Bug</a></td>'; + $content .= '<td><a href="{DSP_BUG_ID}" title="View Bug">View Bug</a></td>'; $content .= '</tr>'; } $content .= '</table>'; http://cvs.php.net/viewvc.cgi/bugtracker/template/php/home.html?r1=1.3&r2=1.4&diff_format=u Index: bugtracker/template/php/home.html diff -u bugtracker/template/php/home.html:1.3 bugtracker/template/php/home.html:1.4 --- bugtracker/template/php/home.html:1.3 Sat Jul 26 02:33:44 2008 +++ bugtracker/template/php/home.html Fri Aug 1 10:51:11 2008 @@ -8,6 +8,8 @@ <p>You can view the current <a href="/bug/" title="View Bugs">bug listings</a></p> <div id="error"> +Don't be surprised if this site is buggered +<!-- Current Test: <br /><br /> Report a bug @@ -23,6 +25,7 @@ Let me know of pass or fail to <a href="irc://efnet.teleglobe.net/foobared">#foobared on efnet</a> <br /> Also feedback on profile fields +--> </div> <br /><br /><hr /> http://cvs.php.net/viewvc.cgi/bugtracker/includes/template.php?view=markup&rev=1.1 Index: bugtracker/includes/template.php +++ bugtracker/includes/template.php <?php //this is the template engine version 2 /* Release notes this file takes all the elements I usually define in functions add to that all the stuff gsoc has taught me plus all the stuff I have learnt whilst working with classes finally this will actually work properly at lease it will when all the subsequent functions are written and are operational */ class template { public $prehtml = ''; public $html = ''; // set up some nice template varibles public $page_title = 'PHP Bugs | '; public $meta = ''; public $javascript = ''; public $alternative_css = ''; public $favicon = ''; public $content_title = ' '; public $login = '<li> </li>'; public $template_data = array(); public $form_data = array(); public $display_data = array(); public $form_error = ''; public $system_error = ''; //on new //we need to determine what bug tracker templates to use public $bugtracker = ''; //lets check to see if those templates exist public $template_dir = ''; function initialize() { $this->bugtracker = array_shift(explode(".", strtolower($_SERVER['HTTP_HOST']))); $this->template_dir = is_dir($_SERVER['DOCUMENT_ROOT'] . '../template/' . $this->bugtracker) ? $this->bugtracker : ''; $this->alternative_css = (!empty($this->template_dir)) ? '<link rel="stylesheet" type="text/css" href="/elements/' . $this->bugtracker . '.css" media="screen" />' : ''; $this->favicon = (!empty($this->template_dir)) ? 'http://' . $bugtracker . '.php.net' : ''; $this->template_dir = (!empty($this->template_dir)) ? $this->template_dir : 'php'; $this->server = $_SERVER; $this->request = $_REQUEST; $this->get = $_GET; $this->post = $_POST; $this->cookie = $_COOKIE; } // this function will create the head element <title> or at least the content within it function page_title() { $code = explode('</h2>', $this->prehtml); $code = explode('<h2>',$code[0]); $code = $code[1] ? $code[1] : $code[0]; $this->page_title .= $code; $this->content_title = $code; $this->prehtml = str_replace('<h2>' . $code . '</h2>', '', $this->prehtml); return; } function meta_refresh($target, $time = 3) { $this->meta = '<meta tt-equive="refresh" content="' . $target . ';' . $time . '" />' . "\n"; } function load_jscript($jscripts) { if (is_array($jscripts)) { foreach ($jsscript as $script) { $this->javascript .= '<script type="text/javascript" src="' . $script . '"></script>' . "\n"; } } else { $this->javascript .= '<script type="text/javascript" src="' . $jscripts . '"></script>' . "\n"; } } function generate_header() { $this->html = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '../template/generic/header.html'); $this->swap('year', date('Y',time()) ); $this->swap('page_title', $this->page_title ); $this->swap('meta', $this->meta ); $this->swap('javascript', $this->javascript ); $this->swap('content_title', $this->content_title ); $this->swap('favicon', $this->favicon ); $this->swap('alternative_css', $this->alternative_css ); global $backtrace; $this->swap('backtrace', $backtrace ); $this->swap('login', $this->login ); if ($this->system_error) { $this->system_error = '<div id="error">' . $this->system_error . '</div>'; } $this->swap('system_error', $this->system_error ); $this->swap('form_error', $this->form_error ); return; } function generate_footer() { global $db, $trace; $this->html .= file_get_contents($_SERVER['DOCUMENT_ROOT'] . '../template/generic/footer.html'); $this->swap('queries', $db->query_count ); $this->swap('year', date('Y',time()) ); $this->swap('last', date('r',filemtime($this->template_file))); //debug?? $debug = ''; include($_SERVER['DOCUMENT_ROOT'] . '../template/generic/debug.php'); $this->html .= $debug; $this->html .= "\n" . '</body>' . "\n" . '</html>'; return; } function compile_and_echo() { $this->generate_header(); $this->html .= $this->prehtml; $this->generate_footer(); echo $this->html; return; } function swap($target, $victim) { $this->html = str_replace('{' . strtoupper($target) . '}', $victim, $this->html); return; } function loop($loop_data, $loop_html) { $this->loop_html = $loop_html; foreach ($loop_data as $ref => $data) { $this->html .= $this->loop_html; swap($ref, $data); } return; } function sanitize($in) { $out = $in; return $out; } function determine_template() { $base_directory = $_SERVER['DOCUMENT_ROOT'] . '../template/'; $base_this = $base_directory . $this->template_dir . '/'; $this->page = $this->request['page'] ? $this->request['page'] : 'home'; if (substr($this->page,-1,1) == '/') { $this->page = substr($this->page, 0, -1); //lop off te follodwing / if it exists } //its the greate template hunt..... /*..php .html with b_this base page base page index no b_this base generic page base generic page index */ $this->h_or_p($base_this . $this->page); if ($this->template_type == FALSE) { $this->h_or_p($base_this . $this->page . '/index'); } if ($this->template_type == FALSE) { $this->h_or_p($base_directory . 'generic/' . $this->page); } if ($this->template_type == FALSE) { $this->h_or_p($base_directory . 'generic/' . $this->page . '/index'); } if ($this->template_type == FALSE) { //then its a 404! $this->h_or_p($base_directory . 'generic/404'); $this->template_file = $base_directory . 'generic/404.' . $template_type; header("HTTP/1.0 404 Not Found"); $this->system_error = 'I am sorry the file (<strong>' . $this->page . '</strong>) you have requested could not be found'; } else { header("HTTP/1.0 200 OK"); } return; } function h_or_p($file) { if (is_file($file . '.php')) { $this->template_type = 'php'; $this->template_file = $file . '.php'; } else if (is_file($file . '.html')) { $this->template_type = 'html'; $this->template_file = $file . '.html'; } else { $this->template_type = FALSE; $this->template_file = ''; } return; } function load_template() { if ($this->template_type == 'php') { include($this->template_file); } if ($this->template_type == 'html') { $this->prehtml = file_get_contents($this->template_file); //we need to process the html to extract some things $this->page_title(); } return; } } http://cvs.php.net/viewvc.cgi/bugtracker/template/generic/debug.php?view=markup&rev=1.1 Index: bugtracker/template/generic/debug.php +++ bugtracker/template/generic/debug.php <?php $debug = ' <textarea style="width: 95%; height: 200px; border: 1px solid #000;" rows="10" cols="50">debug: trace: ' . $trace . ' cookie: '; foreach ($_COOKIE as $ref => $data) { $debug .= $ref . ' - ' . htmlentities($data) . "\n"; } $debug .= ' server: '; foreach ($_SERVER as $ref => $data) { $debug .= $ref . ' - ' . htmlentities($data) . "\n"; } $debug .= ' </textarea> ';