[Astrospaces-commits] SF.net SVN: astrospaces: [100] trunk
Brought to you by:
p3net
From: <cal...@us...> - 2007-08-18 21:31:57
|
Revision: 100 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=100&view=rev Author: caleb870 Date: 2007-08-18 14:31:59 -0700 (Sat, 18 Aug 2007) Log Message: ----------- Finally completed the entire template system with caching and many other features. The template system is now ready for use and now we can get on with designing AstroSPACES. Modified Paths: -------------- trunk/config.php trunk/develop/template-example/tester.php trunk/functions/template.php trunk/globals.php Added Paths: ----------- trunk/cache/ Modified: trunk/config.php =================================================================== --- trunk/config.php 2007-08-07 17:22:04 UTC (rev 99) +++ trunk/config.php 2007-08-18 21:31:59 UTC (rev 100) @@ -1,45 +1,45 @@ -<?php -/* These settings are autogenerated by AstroSPACES - do not change them unless you know what you are - doing! -*/ -define('AS_DB_TYPE', 'mysql'); -define('AS_DB_PREFIX', 'as_'); -define('AS_DB_HOST', 'localhost'); -define('AS_DB_SCHEMA', 'schema'); -define('AS_DB_USER', 'user'); -define('AS_DB_PASS', 'pass'); - -define('AS_EXT', '.php'); -define('AS_LANG', 'en-us'); - -define('AS_LOC_URL', 'http://localhost/'); -define('AS_LOC_DIRECT', 'C:/path/to/astrospaces/'); - -/* These settings are constants and must NOT - be altered. Doing so will prevent AstroSPACES - from functioning. -*/ -define('AS_TBL_USERS', AS_DB_PREFIX.'users'); -define('AS_TBL_SETTINGS', AS_DB_PREFIX.'settings'); -define('AS_TBL_STATPROF', AS_DB_PREFIX.'static_profile_fields'); -define('AS_TBL_BLOG', AS_DB_PREFIX.'blog'); -define('AS_TBL_BLOG_CMT', AS_DB_PREFIX.'blog_comment'); -define('AS_TBL_COMMENTS', AS_DB_PREFIX.'comments'); -define('AS_TBL_FRIEND', AS_DB_PREFIX.'friends'); -define('AS_TBL_IMG', AS_DB_PREFIX.'images'); -define('AS_TBL_IMG_CMT', AS_DB_PREFIX.'image_comments'); -define('AS_TBL_ACTION', AS_DB_PREFIX.'actions'); -define('AS_TBL_CMT', AS_DB_PREFIX.'comments'); -define('AS_TBL_SESSION', AS_DB_PREFIX.'sessions'); -define('AS_TBL_PM', AS_DB_PREFIX.'private_messages'); -define('AS_TBL_GRPRES', AS_DB_PREFIX.'group_resolver'); -define('AS_TBL_GRPS', AS_DB_PREFIX.'groups'); -define('AS_TBL_SPROFLDS', AS_DB_PREFIX.'static_profile_fields'); -define('AS_TBL_DPROFLDS', AS_DB_PREFIX.'dynamic_profile_fields'); -define('AS_TBL_DPROVAL', AS_DB_PREFIX.'dynamic_profile_values'); - -define('AS_DIR_TPL', 'template/'); -define('AS_TPL', AS_LOC_URL.AS_DIR_TPL.'default/'); -?> - +<?php +/* These settings are autogenerated by AstroSPACES + do not change them unless you know what you are + doing! +*/ +define('AS_DB_TYPE', 'mysql'); +define('AS_DB_PREFIX', 'as_'); +define('AS_DB_HOST', 'localhost'); +define('AS_DB_SCHEMA', 'schema'); +define('AS_DB_USER', 'user'); +define('AS_DB_PASS', 'pass'); + +define('AS_EXT', '.php'); +define('AS_LANG', 'en-us'); + +define('AS_LOC_URL', 'http://localhost/'); +define('AS_LOC_DIRECT', 'C:/path/to/astrospaces/'); +define('AS_LOC_CACHE', AS_LOC_DIRECT.'cache/'); + +/* These settings are constants and must NOT + be altered. Doing so will prevent AstroSPACES + from functioning. +*/ +define('AS_TBL_USERS', AS_DB_PREFIX.'users'); +define('AS_TBL_SETTINGS', AS_DB_PREFIX.'settings'); +define('AS_TBL_STATPROF', AS_DB_PREFIX.'static_profile_fields'); +define('AS_TBL_BLOG', AS_DB_PREFIX.'blog'); +define('AS_TBL_BLOG_CMT', AS_DB_PREFIX.'blog_comment'); +define('AS_TBL_COMMENTS', AS_DB_PREFIX.'comments'); +define('AS_TBL_FRIEND', AS_DB_PREFIX.'friends'); +define('AS_TBL_IMG', AS_DB_PREFIX.'images'); +define('AS_TBL_IMG_CMT', AS_DB_PREFIX.'image_comments'); +define('AS_TBL_ACTION', AS_DB_PREFIX.'actions'); +define('AS_TBL_CMT', AS_DB_PREFIX.'comments'); +define('AS_TBL_SESSION', AS_DB_PREFIX.'sessions'); +define('AS_TBL_PM', AS_DB_PREFIX.'private_messages'); +define('AS_TBL_GRPRES', AS_DB_PREFIX.'group_resolver'); +define('AS_TBL_GRPS', AS_DB_PREFIX.'groups'); +define('AS_TBL_SPROFLDS', AS_DB_PREFIX.'static_profile_fields'); +define('AS_TBL_DPROFLDS', AS_DB_PREFIX.'dynamic_profile_fields'); +define('AS_TBL_DPROVAL', AS_DB_PREFIX.'dynamic_profile_values'); + +define('AS_DIR_TPL', 'template/'); +define('AS_TPL', AS_LOC_URL.AS_DIR_TPL.'default/'); +?> \ No newline at end of file Modified: trunk/develop/template-example/tester.php =================================================================== --- trunk/develop/template-example/tester.php 2007-08-07 17:22:04 UTC (rev 99) +++ trunk/develop/template-example/tester.php 2007-08-18 21:31:59 UTC (rev 100) @@ -1,19 +1,20 @@ <?php +define('AS_LOC_CACHE', 'C:/Program Files/xampp/htdocs/as/cache/'); $time = microtime(); include '../../functions/template.php'; -$tpl = new template('test.tpl','test.cache',5); +$tpl = new tpl_base('test.tpl','tester.cache',5); $tpl->load_lang_file('../../lang/en/lang_main.php'); $tpl->compile_slices(); -//print_r($tpl); $tpl->set(array('address' => '123 Sample Street NW')); $tpl->set_multi(array(array('two.bold' => 'Just', 'two.morez' => ' script <br />'),array('two.bold' => 'Im', 'two.morez' => ' pie.', 'color' => ' red')),'two'); //echo "<a href=\"http://www.deltalabs.net/othercrap/musicsample.zip\">CLICK ME</a>"; -$tpl->set_lang_var('var','GALLERY_COMMENTS','one','5'); +//$tpl-> $tpl->parse_slice_to_parent('one'); //print_r($tpl->slices); $tpl->pparse(); $tpl->finish(); //print_r($tpl->slices); echo microtime() - $time; + ?> \ No newline at end of file Modified: trunk/functions/template.php =================================================================== --- trunk/functions/template.php 2007-08-07 17:22:04 UTC (rev 99) +++ trunk/functions/template.php 2007-08-18 21:31:59 UTC (rev 100) @@ -18,23 +18,23 @@ @id: $Id$ *********************************************************/ -class template { +define('TPL_LANG_PRE', 'LANG:'); +define('TPL_LANG_PRE_REG', 'LANG:'); +define('TPL_SLICE_PRE', 'SLICE:'); +define('TPL_SLICE_PRE_REG', 'SLICE:'); +define('TPL_VAR', '[%s]'); +define('TPL_VAR_REG', '\[%s\]'); +define('TPL_VAR_FINDER', '[a-zA-Z0-9_.-:]+'); +define('TPL_SLICE_FINDER', '[a-zA-Z0-9_.-]+'); +define('TPL_INCLUDE', '\<\!--\s*INCLUDE\s*\'%s\'\s*--\>'); +define('TPL_SLICE_START', '\<\!--\s*START\s+%s\s*--\>'); +define('TPL_SLICE_END', '\<\!--\s*END\s+%s\s*--\>'); +class tpl_base { + var $slices; var $lang; - var $lang_prefix = 'LANG:'; - var $lang_prefix_reg = 'LANG:'; - var $slice_prefix_reg = 'SLICE:'; - var $slice_prefix = 'SLICE:'; - var $start_symbol_reg = '\['; - var $end_symbol_reg = '\]'; - var $start_symbol = '['; - var $end_symbol = ']'; - - var $include_reg = '\<\!--\s*INCLUDE\s*\'%s\'\s*--\>'; - var $slice_start = '\<\!--\s*START %s\s*--\>'; - var $slice_end = '\<\!--\s*END %s\s*--\>'; var $slice_array; // System-only variable var $tpl_folder; @@ -42,76 +42,10 @@ var $cache_file; var $cache_life; var $cache_age; - var $recache = true; var $cache_exists = false; - /* - [FUNCTIONS] - - [ LOADING ] - load_from_file - Load template from a file's contents - $file - The file. - load - Load template from a variable in PHP - $template - Variable with template - - [ VARIABLES ] - define_var - Defines a variable - $var_name - Name of variable, overwrites previous - $value - Value of variable - $parent (optional) - Parent of variable. Meant for situations when using slices. - add_to_var - Add to the existing value of a variable - $var_name - Name of variable - $add_what - Add what to the variable - $parent (optional) - Parent of variable. Meant for situations when using slices. - set - Sets an array or variables. - $var_array - Array of variables to set. Valid input would be like: - array('var_one' => 'value', 'var_two' => 'another value') - $slice_name - Name of slice to set the variables of. Is set to the root template by default. - set_multi - Sets an array of variables to a slice and then parses it. Then sets the next - set of variables, and parses until the array is fully iterated. - Svar_array - Array of variables to set. Valid input would be like: - array(array('var1' => 'value', 'var2' => 'value again'), - array('var1' => 'new value', 'var2' => 'another new value')) - $slice_name - Name of slice to set the variables of. Is set to the root template by default. - - [ SLICES & SLICE PARSING ] - parse_slice_to_parent - Parses a slices result to it location in it's parent. - $slice_name - Name of slice to parse. - parse_slice_to_var - Parse the result of a slice to a variable - $slice_name - Name of slice to be parsed - $root_var_name - Name of variable to parse the slice to. - $parent (optional) - Parent of variable. Meant for situations when using slices. - parse_slice - Parse a slice. Returns the result to the caller. - $slice_name - Name of slice to be parsed. - - [ ROOT PARSING ] - parse - Parses the root with echoing the result, yet returning the result to the caller. - (No parameters needed) - pparse - Parses the root and echoes the result. - - [ MISCELLANEOUS ] - flush_template - Drops the current data of template - flush_slice - Drops the current data of the slice - $slice_name - Name of slice to drop - reset_template - Resets the entire template and drops all information. - - [ TERMINOLOGY ] - Slice - A Removable or a part of a template that can be repetitively parsed. - - Root - The core template. Slices must be parsed to a variable in the root - in order to be seen, otherwise they are never printed. - - [ HOW IT WORKS ] - When you load a file, it loads all the slices in the file and removes them - from the root template. When you define a variable, it is only added to - a list of variables to be parsed. They can still be added to before it - is parsed. Once it is parsed it echoes the result and resets it so that - it may be parsed again. - - */ - - function template($file, $cache_to, $cache_life = 600) + function tpl_base($file, $cache_to, $cache_life = 600) { $this->tpl_folder = dirname($file).'/'; $this->tpl_file = $file; @@ -122,7 +56,6 @@ { $cache_age = @filemtime($cache_to); $this->cache_age = $cache_age; - // ($cache_age != false AND time() - $cache_life < $cache_age) or ($cache_age != false and $cache_life === 0) if ($cache_age === false) { $this->cache_exists = false; @@ -137,20 +70,9 @@ } $this->cache_exists = true; $cache = unserialize(implode(null,$content)); - $this->slices = $cache->slices; - $this->lang = $cache->lang; - $this->lang_prefix = $cache->lang_prefix; - $this->lang_prefix_reg = $cache->lang_prefix_reg; - $this->slice_prefix_reg = $cache->slice_prefix_reg; - $this->slice_prefix = $cache->slice_prefix; - - $this->start_symbol_reg = $cache->start_symbol_reg; - $this->end_symbol_reg = $cache->end_symbol_reg; - $this->start_symbol = $cache->start_symbol; - $this->end_symbol = $cache->end_symbol; - - $this->slice_start = $cache->slice_start; - $this->slice_end = $cache->slice_end; + $this->slices = $cache->slices; + $this->lang = $cache->lang; + echo "cache exists<br />"; return true; } elseif ($cache_age != false) @@ -178,19 +100,17 @@ function load( $template ) { - $this->slices['root']['template'] = $template; - $this->slices['root']['result'] = $template; - $this->slices['root']['name'] = 'root'; - $this->include_files(); - $regex = '/'.$this->slice_start('(.*)').'/smiU'; + $template = $this->include_files($template); + $this->slices['root'] = new tpl_slice( $template ); + $regex = '/'.sprintf(TPL_SLICE_START,'('.TPL_SLICE_FINDER.')').'/smiU'; preg_match_all($regex, $template, $slice_array); $this->slice_array = $slice_array[1]; } - function include_files() + function include_files($template) { - preg_match_all('/'.sprintf($this->include_reg, '(.*)').'/smU', - $this->slices['root']['template'], + preg_match_all('/'.sprintf(TPL_INCLUDE, '(.*)').'/smU', + $template, $files); if (count($files) === 0) return; @@ -204,14 +124,15 @@ $content = implode(null,$content); } - $regex = '/'.sprintf($this->include_reg, str_replace('/','\/',preg_quote($file))).'/sm'; - $this->slices['root']['template'] = preg_replace($regex, $content, $this->slices['root']['template']); + $regex = '/'.sprintf(TPL_INCLUDE, str_replace('/','\/',preg_quote($file))).'/sm'; + $template = preg_replace($regex, $content, $template); } - if (preg_match('/'.sprintf($this->include_reg, '(.*)').'/sm', $this->slices['root']['template'], $files)) + if (preg_match('/'.sprintf(TPL_INCLUDE, '(.*)').'/sm', $template, $files)) { - $this->include_files(); + $template = $this->include_files($template); } + return $template; } function load_lang_file ( $filename ) @@ -228,29 +149,6 @@ } } - function parse_lang_vars() - { - if (empty($this->lang)) return false; - - foreach ($this->lang as $name => $value) - { - if (strstr($value, '%s') === false) - { - $this->slices['root']['template'] = str_replace($this->start_symbol.$this->lang_prefix.$name.$this->end_symbol, $value, $this->slices['root']['template']); - } - } - return true; - } - - function set_lang_var ( $var_name, $lang_name, $parent, $value, $value2 = null, $value3 = null, $value4 = null ) - { - $this->define_var($var_name, sprintf($this->lang[$lang_name], $value, $value2, $value3, $value4),$parent); - } - - function slice_start ( $name ) { return sprintf( $this->slice_start, $name); } // System-only function - - function slice_end ( $name ) { return sprintf( $this->slice_end, $name); } // System-only function - function determine_parent( $name ) // System-only function. No longer usable after compile_slices(). { $name_reg = preg_quote( $name ); @@ -259,8 +157,8 @@ foreach ($this->slice_array as $slice) { $slice_reg = preg_quote($slice); - $regex = '/'.$this->slice_start($slice_reg).'(?:.*)'.$this->slice_start($name_reg).'(?:.*)'.$this->slice_end($slice_reg).'/sm'; - if (preg_match($regex, $this->slices['root']['template'], $results)) + $regex = '/'.sprintf(TPL_SLICE_START,$slice_reg).'(?:.*)'.sprintf(TPL_SLICE_START,$name_reg).'(?:.*)'.sprintf(TPL_SLICE_END,$slice_reg).'/sm'; + if (preg_match($regex, $this->slices['root']->template, $results)) $array[$slice] = strlen($results[0]); } @@ -283,47 +181,42 @@ return $biggest_slice; } - function compile_slices () // System-only function + function compile_slices () { - $this->parse_lang_vars(); - $regex = '/'.$this->slice_end('(.*)').'/smiU'; - preg_match_all( $regex, $this->slices['root']['template'], $sub_slices); - foreach ($sub_slices[1] as $slice) + // Parse every language variable. + if (!empty($this->lang)) { - $this->assemble_slice($slice); + foreach ($this->lang as $name => $value) + { + $this->slices['root']->template = str_replace(sprintf(TPL_VAR,TPL_LANG_PRE.$name), $value, $this->slices['root']->template); + } } - } - - function assemble_slice ( $slice_name ) // System-only function - { - $regex = '/'.$this->slice_start($slice_name).'(.*)\r\n\s*'.$this->slice_end($slice_name).'\s*\r?\n?/si'; - preg_match($regex, $this->slices['root']['template'], $resultset); - if (count($resultset) > 0) + // Find all the slices in the template and make them into tpl_slice objects. + $regex = '/'.sprintf(TPL_SLICE_END,'(.*)').'/smiU'; + preg_match_all( $regex, $this->slices['root']->template, $sub_slices); + $slices = $sub_slices[1]; + foreach ($slices as $slice) { - $this->slices[$slice_name]['template'] = $resultset[1]; - $this->slices[$slice_name]['result'] = $resultset[1]; - $this->slices[$slice_name]['name'] = $slice_name; - $this->slices[$slice_name]['parent'] = $this->determine_parent(preg_quote($slice_name)); - $newTemplate = preg_replace($regex, $this->start_symbol.$this->slice_prefix.$slice_name.$this->end_symbol."\r\n", $this->slices['root']['template']); - $this->slices['root']['template'] = $newTemplate; - $this->slices['root']['result'] = $newTemplate; + // Assemble the slice object + $regex = '/'.sprintf(TPL_SLICE_START,$slice).'(.*)\r\n\s*'.sprintf(TPL_SLICE_END,$slice).'\s*\r?\n?/si'; + preg_match($regex, $this->slices['root']->template, $resultset); + + if (count($resultset) > 0) + { + + $this->slices[$slice] = new tpl_slice($resultset[1]); + $this->slices[$slice]->parent = $this->determine_parent(preg_quote($slice)); + $this->slices['root']->template = preg_replace($regex, sprintf(TPL_VAR,TPL_SLICE_PRE_REG.$slice)."\r\n", $this->slices['root']->template); + } } } - function count_slices ( $parent ) - { - $regex = '/'.$this->slice_start($parent).'(?:.*)('.$this->slice_start('(.*)').')(?:.*)'.$this->slice_end($parent).'/smi'; - preg_match( $regex, $this->slices['root']['template'], $sub_slices ); - $count = count($sub_slices); - return $count; - } - function set($var_array, $slice_name = 'root') { foreach ($var_array as $name => $value) { - $this->define_var($name, $value, $slice_name); + $this->slices[$slice_name]->vars[$name] = $value; } } @@ -333,134 +226,51 @@ { foreach ($var_array as $id => $vars) { - foreach ($vars as $var_name => $var_value) + foreach ($vars as $name => $value) { - $this->define_var($var_name, $var_value, $slice_name); + $this->slices[$slice_name]->vars[$name] = $value; } $this->pparse(false); } } else { foreach ($var_array as $id => $vars) { - foreach ($vars as $var_name => $var_value) + foreach ($vars as $name => $value) { - $this->define_var($var_name, $var_value, $slice_name); + $this->slices[$slice_name]->vars[$name] = $value; } - $this->parse_slice_to_var($slice_name, $this->slice_prefix.$slice_name, $this->slices[$parent]['parent'], false); + $this->slices[$this->slices[$slice_name]->parent]->define(TPL_SLICE_PRE.$slice_name, $this->slices[$slice_name]->parse()); } } } - - function define_var ( $var_name, $value, $parent = 'root') - { - $this->slices[$parent]['vars'][$var_name] = $value; - } - function add_to_var ( $var_name, $add_what, $parent = 'root' ) - { - $this->slices[$parent]['vars'][$var_name] .= $add_what; - } - - function parse_slice_to_var ( $slice_name, $root_var_name, $parent = 'root', $overwrite = true ) // Use parse_slice_to_parent instead - { - $content = $this->parse_slice( $slice_name ); - if ($overwrite) - { - $this->define_var($root_var_name, $content, $parent); - } else { - $this->add_to_var($root_var_name, $content, $this->slices[$slice_name]['parent']); - } - return $parsed_result; - } - function parse_slice_to_parent ( $slice_name ) { - $parent = $this->slices[$slice_name]['parent']; - $root_var_name = $this->slice_prefix.$slice_name; - $content = $this->parse_slice( $slice_name ); - $this->add_to_var($root_var_name, $content, $parent); + $parent = $this->slices[$slice_name]->parent; + $root_var_name = TPL_SLICE_PRE.$slice_name; + $content = $this->slices[$slice_name]->parse(); + $this->slices[$parent]->define($root_var_name, $content); return $parsed_result; } - - function parse_slice ( $slice_name ) - { - if ($this->slices[$slice_name]['vars'] != Null) - { - foreach($this->slices[$slice_name]['vars'] as $name => $value) - { - $replacement_regex = '/\r?\n?\s*' . $this->start_symbol_reg . preg_quote($name).$this->end_symbol_reg.'\r?\n?/si'; - $result = preg_replace( $replacement_regex, $value, $this->slices[$slice_name]['result'] ); - $this->slices[$slice_name]['result'] = $result; - } - } - - $replacement_regex = '/\r?\n?'.$this->start_symbol_reg.'(.*)'.$this->end_symbol_reg.'\r?\n?/sU'; - $this->slices[$slice_name]['result'] = preg_replace( $replacement_regex, '', $this->slices[$slice_name]['result'] ); - - $parsed_result = $this->slices[$slice_name]['result']; - - $this->flush_slice( $slice_name ); - /*$parsed_result = str_replace("\n", "\nLF", $parsed_result); - $parsed_result = str_replace("\r", "CR", $parsed_result);*/ - return $parsed_result; - } function parse () { - if ($this->slices['root']['vars'] != null) - { - foreach($this->slices['root']['vars'] as $name => $value) - { - $replacement_regex = '/\r?\n?'.$this->start_symbol_reg.preg_quote($name).$this->end_symbol_reg.'\r?\n?/si'; - $result = preg_replace($replacement_regex,$value,$this->slices['root']['result']); - $this->slices['root']['result'] = $result; - } - } - - $replacement_regex = '/\r?\n?'.$this->start_symbol_reg.'(.*)'.$this->end_symbol_reg.'\r?\n?/siU'; - $this->slices['root']['result'] = preg_replace( $replacement_regex, '', $this->slices['root']['result'] ); - - $parsed_result = $this->slices['root']['result']; - - $this->flush_template(); - - return $parsed_result; + return $this->slices['root']->parse(); } - function pparse ($die_on_finish = false) + function pparse () { - echo $this->parse(); - - if ($die_on_finish == true) - { - die(); - } + $result = $this->slices['root']->parse(); + echo $result; + return $result; } - - function flush_template () - { - $this->slices['root']['result'] = $this->slices['root']['template']; - unset($this->slices['root']['vars']); - } - function flush_slice ( $slice_name ) + function dir($location, $dir) { - $this->slices[$slice_name]['result'] = $this->slices[$slice_name]['template']; - $this->slices[$slice_name]['vars'] = null; - } - - function reset_template () - { - $this->slices['root']['template'] = null; - $this->slices['root']['result'] = null; - $this->slices = null; - } - - function dir($location, $dir) // done and tested - { $array = explode('/',$dir); if ($array === '.') return true; $count = count($array); + print_r($array); for ($i = 0; $i < $count; $i++) { @@ -476,6 +286,7 @@ if (!file_exists($location.$path)) { $missing = $i; + //echo $i; break 1; } } @@ -504,7 +315,12 @@ { if ($this->cache_exists === false) { - $resource = fopen($this->cache_file, 'w'); + if (!file_exists(dirname(AS_LOC_CACHE.$this->cache_file))) + { + + $this->dir(AS_LOC_CACHE, dirname($this->cache_file)); + } + $resource = fopen(AS_LOC_CACHE.$this->cache_file, 'w'); $this->cache_exists = true; return fwrite($resource, serialize($this)); } @@ -516,4 +332,52 @@ unlink($this->cache_file); } } + +class tpl_slice +{ + var $parent; + var $vars; + var $template; + + function tpl_slice($content) + { + $this->template = $content; + } + + function define($name, $value) + { + $this->vars[$name] .= $value; + } + + function burn_var($name) + { + if (!empty($name)) + { + $this->template = str_replace(sprintf(TPL_VAR,$name),$this->vars[$name],$this->template); + } + } + + function parse() + { + $result = $this->template; + if ($this->vars != null) + { + foreach($this->vars as $name => $value) + { + $regex = '/\r?\n?\s*'.sprintf(TPL_VAR_REG, preg_quote($name)).'\r?\n?/si'; + $result = preg_replace( $regex, $value, $result ); + } + } + + $regex = '/\r?\n?'.sprintf(TPL_VAR_REG, TPL_VAR_FINDER).'\r?\n?/sU'; + $result = preg_replace( $regex, '', $result ); + $this->flush(); + return $result; + } + + function flush() + { + $this->vars = null; + } +} ?> \ No newline at end of file Modified: trunk/globals.php =================================================================== --- trunk/globals.php 2007-08-07 17:22:04 UTC (rev 99) +++ trunk/globals.php 2007-08-18 21:31:59 UTC (rev 100) @@ -21,7 +21,6 @@ /* Include our larger functions */ require('config.php'); require(AS_LOC_DIRECT.'functions/template.php'); -$template =& new template(); require(AS_LOC_DIRECT.'functions/user.php'); $user =& new user(); require(AS_LOC_DIRECT.'functions/adodb/adodb.inc.php'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |