UseBB Community

The official board for UseBB help and discussion

UseBB Community » 1.0 Discussion » Optimised $template->body();

Optimised $template->body();

Page: 1

Author Post
Member
Registered: Mar 2005
Posts: 92
Location: Rethymno, Crete, Greece
the debug mode could be completely ignored if it is not needed...
In the current cvs-0.4 the $debug_info_* variables are getting initialised and the template part for them is getting parsed anyhow .. in the above function this doesn't happen..
//
// Output the page body
//
function body($enable_debugmessages=true) {

global $db, $functions, $timer, $lang;

//
// Debug features
//
if ( $functions->get_config('debug') && $enable_debugmessages ) {

$debug_info_small = '';
$debug_info_large = '';

//
// Timer for checking parsetime
//
$timer['end'] = explode(' ', microtime());
$timer['end'] = (float)$timer['end'][1] + (float)$timer['end'][0];
$parsetime = round($timer['end'] - $timer['begin'], 2);

$debug_info = array();
$debug_info[] = $lang['ParseTime'].': '.$parsetime.' s';
if ( $serverload = $functions->get_server_load() )
$debug_info[] = $lang['ServerLoad'].': '.$serverload;
$debug_info[] = $lang['TemplateSections'].': '.count($this->loaded_sections);
$debug_info[] = $lang['SQLQueries'].': '.count($db->get_used_queries());

if ( $functions->get_config('debug') === 1 ) {

//
// List parsetime and queries in short
//
$debug_info_small = sprintf($this->get_config('debug_info_small'), join(' '.$this->get_config('item_delimiter').' ', $debug_info));

} elseif ( $functions->get_config('debug') === 2 ) {

//
// Lists parsetime and queries fully
//
$debug_info_large = sprintf($this->get_config('debug_info_large'), '<div><strong>'.$lang['DebugMode'].'</strong> '.$this->get_config('item_delimiter').' '.join(' '.$this->get_config('item_delimiter').' ', $debug_info).':</div><textarea rows="10" cols="50" readonly="readonly">'.htmlspecialchars(join("nn", $db->get_used_queries())).'</textarea>');

}
$this->add_global_vars(array(
'debug_info_small' => $debug_info_small,
'debug_info_large' => $debug_info_large
));
}

//
// Parse all templates
//
foreach ( $this->requests as $request ) {

$current_template = $this->templates[$request['section']][$request['template_name']];
if ( preg_match('#{l_[a-zA-Z]+}#', $current_template) ) {

foreach ( $lang as $key => $val ) {

if ( !is_array($val) )
$current_template = str_replace('{l_'.$key.'}', $val, $current_template);

}

}
$request['variables']['img_dir'] = ROOT_PATH.'templates/'.$functions->get_config('template').'/gfx/';
$request['variables'] = array_merge($this->global_vars, $request['variables']);
foreach ( $request['variables'] as $key => $val )
$current_template = str_replace('{'.$key.'}', $val, $current_template);
$this->body .= $current_template;

}

//
// Compression and output
//
if ( $functions->get_config('output_compression') === 1 || $functions->get_config('output_compression') === 3 )
$this->body = $functions->compress_sourcecode($this->body);

echo $this->body;

}
[*edit*] I apologise for posting in the wrong part of the forum. I meant to post in the General Discussion..
_______________
Yep I know me,.. thats that guy ..
> Lets script :: The PtokaX Lua Board :: The PtokaX Script Database
« Last edit by Herodes on Sat Mar 26, 2005 1:34 pm. »
Developer
Registered: Apr 2004
Posts: 2195
Location: Belgium
There's a reason why empty global template vars are passed (not parsing a template). With your code and debug disabled you get something like this at the footer:

{debug_info_small}
Powered by UseBB 0.4-CVS · Copyright © 2003-2005 UseBB Team
{debug_info_large}
_______________
--Dietrich (developer)
UseBB roadmap, dev mailing list & weblog
Member
Registered: Mar 2005
Posts: 92
Location: Rethymno, Crete, Greece
God, I am feeling bored of getting rejected over here...
... ok, ok...
_______________
Yep I know me,.. thats that guy ..
> Lets script :: The PtokaX Lua Board :: The PtokaX Script Database

Page: 1

UseBB Community » 1.0 Discussion » Optimised $template->body();

UseBB Community is powered by UseBB 1 Forum Software