Instantiate template and set template path from seperate method

git-svn-id: file:///svn/phpbb/trunk@2882 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2002-08-22 21:40:51 +00:00
parent eca02e139c
commit 0226e8602a
2 changed files with 28 additions and 32 deletions

View file

@ -143,6 +143,7 @@ require($phpbb_root_path . 'includes/functions.'.$phpEx);
require($phpbb_root_path . 'db/' . $dbms . '.'.$phpEx); require($phpbb_root_path . 'db/' . $dbms . '.'.$phpEx);
$session = new session(); $session = new session();
$template = new Template();
$db = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false); $db = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false);
// //

View file

@ -20,13 +20,13 @@
***************************************************************************/ ***************************************************************************/
/* /*
Template class. Template class.
Nathan Codding - Original version design and implementation Nathan Codding - Original version design and implementation
Crimsonbane - Initial caching proposal and work Crimsonbane - Initial caching proposal and work
psoTFX - Completion of file caching, decompilation routines and implementation of psoTFX - Completion of file caching, decompilation routines and implementation of
conditionals/keywords and associated changes conditionals/keywords and associated changes
The interface was inspired by PHPLib templates, and the template file (formats are The interface was inspired by PHPLib templates, and the template file (formats are
quite similar) quite similar)
@ -62,14 +62,9 @@ class Template {
var $include_counter = 1; var $include_counter = 1;
var $block_nesting_level = 0; var $block_nesting_level = 0;
/** function set_template($template = '')
* Constructor. Simply sets the root dir.
*
*/
function Template($template = '')
{ {
global $phpbb_root_path; global $phpbb_root_path;
$this->root = $phpbb_root_path . 'templates/' . $template; $this->root = $phpbb_root_path . 'templates/' . $template;
$this->cachedir = $phpbb_root_path . 'templates/cache/' . $template . '/'; $this->cachedir = $phpbb_root_path . 'templates/cache/' . $template . '/';
@ -154,7 +149,7 @@ class Template {
return true; return true;
} }
/** /**
* Destroys this template object. Should be called when you're done with it, in order * Destroys this template object. Should be called when you're done with it, in order
* to clear out the template data so you can load/parse a new template set. * to clear out the template data so you can load/parse a new template set.
@ -178,7 +173,7 @@ class Template {
{ {
$_str = ''; $_str = '';
if ( !($this->compile_load($_str, $handle, true)) ) if ( !($this->compile_load($_str, $handle, true)) )
{ {
if ( !$this->loadfile($handle) ) if ( !$this->loadfile($handle) )
{ {
@ -209,7 +204,7 @@ class Template {
{ {
$_str = ''; $_str = '';
if ( !($this->compile_load($_str, $handle, false)) ) if ( !($this->compile_load($_str, $handle, false)) )
{ {
if ( !$this->loadfile($handle) ) if ( !$this->loadfile($handle) )
{ {
@ -237,7 +232,7 @@ class Template {
$this->files[$handle] = $this->make_filename($filename); $this->files[$handle] = $this->make_filename($filename);
$_str = ''; $_str = '';
if ( !($this->compile_load($_str, $handle, false)) ) if ( !($this->compile_load($_str, $handle, false)) )
{ {
if ( !$this->loadfile($handle) ) if ( !$this->loadfile($handle) )
{ {
@ -275,7 +270,7 @@ class Template {
return true; return true;
} }
/** /**
* Block-level variable assignment. Adds a new block iteration with the given * Block-level variable assignment. Adds a new block iteration with the given
* variable assignments. Note that this should only be called once per block * variable assignments. Note that this should only be called once per block
@ -355,7 +350,7 @@ class Template {
$compile_blocks[] = "// BEGINELSE\n}} else {\n"; $compile_blocks[] = "// BEGINELSE\n}} else {\n";
break; break;
case 'END': case 'END':
$compile_blocks[] = ( ( array_pop($this->block_else_level) ) ? "}\n" : "}}\n" ) . '// END ' . array_pop($this->block_names) . "\n"; $compile_blocks[] = ( ( array_pop($this->block_else_level) ) ? "}\n" : "}}\n" ) . '// END ' . array_pop($this->block_names) . "\n";
break; break;
case 'IF': case 'IF':
$compile_blocks[] = '// IF ' . $blocks[2][$curr_tb] . "\n" . $this->compile_tag_if($blocks[2][$curr_tb], false); $compile_blocks[] = '// IF ' . $blocks[2][$curr_tb] . "\n" . $this->compile_tag_if($blocks[2][$curr_tb], false);
@ -378,7 +373,7 @@ class Template {
case 'PHP': case 'PHP':
$temp = ''; $temp = '';
list(, $temp) = each($php_blocks); list(, $temp) = each($php_blocks);
$compile_blocks[] = "// PHP START\n" . $temp . "\n// PHP END\n"; $compile_blocks[] = "// PHP START\n" . $temp . "\n// PHP END\n";
break; break;
default: default:
$this->compile_var_tags($blocks[0][$curr_tb]); $this->compile_var_tags($blocks[0][$curr_tb]);
@ -467,9 +462,9 @@ class Template {
{ {
/* Tokenize args for 'if' tag. */ /* Tokenize args for 'if' tag. */
preg_match_all('/(?: preg_match_all('/(?:
"[^"\\\\]*(?:\\\\.[^"\\\\]*)*" | "[^"\\\\]*(?:\\\\.[^"\\\\]*)*" |
\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\' | \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\' |
[(),] | [(),] |
[^\s(),]+)/x', $tag_args, $match); [^\s(),]+)/x', $tag_args, $match);
$tokens = $match[0]; $tokens = $match[0];
@ -546,7 +541,7 @@ class Template {
break; break;
} }
} }
return ( ( $elseif ) ? '} elseif (' : 'if (' ) . ( implode(' ', $tokens) . ') { ' . "\n" ); return ( ( $elseif ) ? '} elseif (' : 'if (' ) . ( implode(' ', $tokens) . ') { ' . "\n" );
} }
@ -562,7 +557,7 @@ class Template {
// //
// This is from Smarty // This is from Smarty
// //
function _parse_is_expr($is_arg, $tokens) function _parse_is_expr($is_arg, $tokens)
{ {
$expr_end = 0; $expr_end = 0;
@ -755,7 +750,7 @@ class Template {
} }
closedir($dp); closedir($dp);
} }
return; return;
} }
@ -774,7 +769,7 @@ class Template {
} }
} }
closedir($dp); closedir($dp);
return; return;
} }
@ -783,12 +778,12 @@ class Template {
$match_tags = array( $match_tags = array(
"#(<\?php\nif \( .?this\->security\(\) \) \{\n)|(\n\}\n\?".">)#", "#(<\?php\nif \( .?this\->security\(\) \) \{\n)|(\n\}\n\?".">)#",
"#echo '(.*?)';#s", "#echo '(.*?)';#s",
"#\/\/ (INCLUDEPHP .*?)\n.?this\->assign_from_include_php\('.*?'\);\n#s", "#\/\/ (INCLUDEPHP .*?)\n.?this\->assign_from_include_php\('.*?'\);\n#s",
"#\/\/ (INCLUDE .*?)\n.?this\->assign_from_include\('.*?'\);\n#s", "#\/\/ (INCLUDE .*?)\n.?this\->assign_from_include\('.*?'\);\n#s",
"#\/\/ (IF .*?)\nif \(.*?\) \{[ ]?\n#", "#\/\/ (IF .*?)\nif \(.*?\) \{[ ]?\n#",
"#\/\/ (ELSEIF .*?)\n\} elseif \(.*?\) \{[ ]?\n#", "#\/\/ (ELSEIF .*?)\n\} elseif \(.*?\) \{[ ]?\n#",
"#\/\/ (ELSE)\n\} else \{\n#", "#\/\/ (ELSE)\n\} else \{\n#",
"#\/\/ (ENDIF)\n}\n#", "#\/\/ (ENDIF)\n}\n#",
"#\/\/ (BEGIN .*?)\n.?_.*? = \(.*?\) : 0;\nif \(.*?\) \{\nfor \(.*?\)\n\{\n#", "#\/\/ (BEGIN .*?)\n.?_.*? = \(.*?\) : 0;\nif \(.*?\) \{\nfor \(.*?\)\n\{\n#",
"#\}\}?\n\/\/ (END .*?)\n#", "#\}\}?\n\/\/ (END .*?)\n#",
@ -800,9 +795,9 @@ class Template {
); );
$replace_tags = array( $replace_tags = array(
'', '',
"\\1", "\\1",
"\\1", "\\1",
"<!-- \\1 -->", "<!-- \\1 -->",
"<!-- \\1 -->", "<!-- \\1 -->",
"<!-- \\1 -->", "<!-- \\1 -->",
@ -811,7 +806,7 @@ class Template {
"<!-- \\1 -->", "<!-- \\1 -->",
"<!-- \\1 -->", "<!-- \\1 -->",
"<!-- \\1 -->", "<!-- \\1 -->",
"{\\1}", "{\\1}",
"{\\1\\2}", "{\\1\\2}",
"{\\1\\2\\3}", "{\\1\\2\\3}",
"{\\1\\2\\3\\4}" "{\\1\\2\\3\\4}"