[Smarttemplate-cvscommit] smarttemplate class.smarttemplateparser.php, 1.12, 1.13
Brought to you by:
codeworxtech
|
From: EndelWar <end...@us...> - 2006-08-23 19:49:58
|
Update of /cvsroot/smarttemplate/smarttemplate In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv27411 Modified Files: class.smarttemplateparser.php Log Message: Added first attempt to Variable Delimiters Index: class.smarttemplateparser.php =================================================================== RCS file: /cvsroot/smarttemplate/smarttemplate/class.smarttemplateparser.php,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** class.smarttemplateparser.php 1 Aug 2006 00:39:13 -0000 1.12 --- class.smarttemplateparser.php 23 Aug 2006 19:49:55 -0000 1.13 *************** *** 7,10 **** --- 7,12 ---- * @author Philipp v. Criegern ph...@cr... * @author Manuel 'EndelWar' Dalla Lana end...@ar... + * @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License + * @package SmartTemplate * @version 1.2.1 03.07.2006 * *************** *** 21,24 **** --- 23,33 ---- /** + * The template filename + * + * @access private + */ + var $tpl_file; + + /** * The template filename used to extract the dirname for subtemplates * *************** *** 35,38 **** --- 44,61 ---- /** + * Default Left delimiter + * + * @access private + */ + var $left_delimiter; + + /** + * Default Right delimiter + * + * @access private + */ + var $right_delimiter; + + /** * Error messages * *************** *** 44,52 **** * SmartTemplateParser Constructor * - * @param string $template_filename HTML Template Filename */ ! function SmartTemplateParser ( $template_filename ) { // Load Template if ($hd = @fopen($template_filename, "r")) { --- 67,87 ---- * SmartTemplateParser Constructor * */ ! function SmartTemplateParser() ! { ! ! } ! ! /** ! * Main Template Parser ! * ! * @param string $compiled_template_filename Compiled Template Filename ! * @desc Creates Compiled PHP Template ! */ ! function compile( $compiled_template_filename = '' ) { // Load Template + //echo $left_delimiter; + $template_filename = $this->template_dir . $this->tpl_file; if ($hd = @fopen($template_filename, "r")) { *************** *** 54,57 **** --- 89,94 ---- { $this->template = fread($hd, filesize($template_filename)); + $this->left_delimiter = preg_quote($this->left_delimiter); + $this->right_delimiter = preg_quote($this->right_delimiter); } else *************** *** 60,65 **** } fclose($hd); - // Extract the name of the template directory - $this->template_dir = dirname($template_filename); } else --- 97,100 ---- *************** *** 67,80 **** $this->template = "SmartTemplate Parser Error: File not found: '$template_filename'"; } - } - /** - * Main Template Parser - * - * @param string $compiled_template_filename Compiled Template Filename - * @desc Creates Compiled PHP Template - */ - function compile( $compiled_template_filename = '' ) - { if (empty($this->template)) { --- 102,106 ---- *************** *** 82,85 **** --- 108,112 ---- } /* Quick hack to allow subtemplates */ + /* FIXME: resolve problems with cached subtemplates */ if(eregi("<!-- INCLUDE", $this->template)) { *************** *** 102,108 **** } // END, ELSE Blocks ! $page = preg_replace("/<!-- ENDIF.+?-->/", "<?php\n}\n?>", $this->template); ! $page = preg_replace("/<!-- END[ a-zA-Z0-9_.]* -->/", "<?php\n}\n\$_obj=\$_stack[--\$_stack_cnt];}\n?>", $page); ! $page = str_replace("<!-- ELSE -->", "<?php\n} else {\n?>", $page); // 'BEGIN - END' Blocks --- 129,135 ---- } // END, ELSE Blocks ! $page = preg_replace("/<!-- ENDIF.+?-->/", "<?php\n}\n?>", $this->template); ! $page = preg_replace("/<!-- END[ a-zA-Z0-9_.]* -->/", "<?php\n}\n\$_obj=\$_stack[--\$_stack_cnt];}\n?>", $page); ! $page = str_replace("<!-- ELSE -->", "<?php\n} else {\n?>", $page); // 'BEGIN - END' Blocks *************** *** 169,173 **** // Replace Scalars ! if (preg_match_all('/{([a-zA-Z0-9_. >]+)}/', $page, $var)) { foreach ($var[1] as $fulltag) --- 196,200 ---- // Replace Scalars ! if (preg_match_all('/'.$this->left_delimiter.'([a-zA-Z0-9_. >]+)'.$this->right_delimiter.'/', $page, $var)) { foreach ($var[1] as $fulltag) *************** *** 175,187 **** // Determin Command (echo / $obj[n]=) list($cmd, $tag) = $this->cmd_name($fulltag); - list($block, $skalar) = $this->var_name($tag); $code = "<?php\n$cmd \$$block"."['$skalar'];\n?>\n"; ! $page = str_replace('{'.$fulltag.'}', $code, $page); } } ! // ROSI Special: Replace Translations if (preg_match_all('/<"([a-zA-Z0-9_.]+)">/', $page, $var)) { --- 202,213 ---- // Determin Command (echo / $obj[n]=) list($cmd, $tag) = $this->cmd_name($fulltag); list($block, $skalar) = $this->var_name($tag); $code = "<?php\n$cmd \$$block"."['$skalar'];\n?>\n"; ! $page = str_replace(stripslashes($this->left_delimiter).$fulltag.stripslashes($this->right_delimiter), $code, $page); } } ! // Replace Translations if (preg_match_all('/<"([a-zA-Z0-9_.]+)">/', $page, $var)) { *************** *** 197,201 **** // Include Extensions $header = ''; ! if (preg_match_all('/{([a-zA-Z0-9_]+):([^}]*)}/', $page, $var)) { foreach ($var[2] as $cnt => $tag) --- 223,227 ---- // Include Extensions $header = ''; ! if (preg_match_all('/'.$this->left_delimiter.'([a-zA-Z0-9_]+):([^}]*)'.$this->right_delimiter.'/', $page, $var)) { foreach ($var[2] as $cnt => $tag) |