cvs: pear /HTML_Template_Flexy Flexy.php package.xml /HTML_Template_Flexy/Flexy example.ini /HTML_Template_Flexy/Flexy/Filter BodyOnly.php Mail.php
Math.php Php.php RtfSimpleTags.php SimpleTags.php Tags.php Xml.php
| From: | Alan Knowles | Date: | Fri, 23 Aug 2002 06:55:22 +0000 |
| Subject: | cvs: pear /HTML_Template_Flexy Flexy.php package.xml /HTML_Template_Flexy/Flexy example.ini /HTML_Template_Flexy/Flexy/Filter BodyOnly.php Mail.php Math.php Php.php RtfSimpleTags.php SimpleTags.php Tags.php Xml.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-5889@lists.php.net to get a copy of this message | ||
alan_k Fri Aug 23 02:55:22 2002 EDT
Added files:
/pear/HTML_Template_Flexy Flexy.php package.xml
/pear/HTML_Template_Flexy/Flexy example.ini
/pear/HTML_Template_Flexy/Flexy/Filter BodyOnly.php Mail.php
Math.php Php.php
RtfSimpleTags.php
SimpleTags.php Tags.php
Xml.php
Log:
Adding HTML_Template_Flexy, as discussed quite a few weeks ago
Index: pear/HTML_Template_Flexy/Flexy.php +++ pear/HTML_Template_Flexy/Flexy.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Alan Knowles <alan@akbkhome.com> // | Original Author: Wolfram Kriesing <wolfram@kriesing.de> | // +----------------------------------------------------------------------+ // /** * @package HTML_Template_Flexy */ /** * A Flexible Template engine - based on simpletemplate * * @abstract Long Description * This is a rip of of Wolfram's Simple Template class - heavily simplified, * with a modified filter loading mechanism. * notebly * - no xml config stuff * - simplified filters - so you just tell it which filter (classes) to use, * not individual methods * - a smarty like tag library, * - heavily focused on displaying objects as pages. * (so you can document your tags.) * * @version $Id: Flexy.php,v 1.1 2002/08/23 06:55:21 alan_k Exp $ */ class HTML_Template_Flexy { /* * @var array $options the options for initializing the template class */ var $options = array( 'compileDir' => '', // by default its always the same one as where the template lies in, this might not be desired 'templateDir' => '', 'forceCompile' => false, // only suggested for debugging 'filters' => array(), 'debug' => false ); /** * Constructor * * Initializes the Template engine, for each instance, accepts options or * reads from PEAR::getStaticProperty('HTML_Template_Flexy','options'); * * @access public * @param array $options (Optional) */ function HTML_Template_Flexy( $options=array() ) { $baseoptions = &PEAR::getStaticProperty('HTML_Template_Flexy','options'); foreach( $baseoptions as $key=>$aOption ) { $this->options[$key] = $aOption; } foreach( $options as $key=>$aOption ) { $this->options[$key] = $aOption; } $filters = $this->options['filters']; if (is_string($filters)) { $this->options['filters']= explode(',',$filters); } if(!@is_dir($this->options['compileDir']) ) return new PEAR_Error('The compile-directory doesnt exist yet!'); } /** * Outputs an object as $t * * for example the using simpletags the object's variable $t->test * would map to {t.test} * * maps * $t->o_* maps to {o.*} // used for output * $t->input maps to {i.*} // used for input * $t->modules[xxxx] maps to {m.xxxx} // used for modules * $t->config maps to {c.*} // used for config * PEAR::getStaticProperty('Auth','singleton') maps to {a.*} * {email_boundary} // for email boundaries {email_date} // for email dates * * * @version 01/12/14 * @access public * @author Alan Knowles * @param object object to output as $t * @return none */ function outputObject(&$t) { $options = PEAR::getStaticProperty('HTML_Template_Flexy','options'); if (@$options['debug']) { echo "output $this->compiledTemplate<BR>"; } $m = new StdClass; // compile modules if (@$t->modules) { foreach ($t->modules as $modulename=>$object) { $m->$modulename = &$t->modules[$modulename]; $te = $this; if (@$object->template) { $te->compile($object->template); } } } $c = & $t->config; if (@$t->input) { $i = & $t->input; } $a = &PEAR::getStaticProperty('Auth','singleton'); /* expose o_ as $o */ $o = new stdClass; foreach (get_object_vars($t) as $k=>$v) { if ($k{0} != "o") { continue; } if ($k{1} != "_") { continue; } $kk = substr($k,2); $o->$kk =& $t->$k; } /* usefull stuff for doing emails in Template Flexy */ $email_boundary = md5("FlexyMail".microtime()); $email_date = date("D j M Y G:i:s O"); include($this->compiledTemplate); } /** * Outputs an object as $t, buffers the result and returns it. * * See outputObject($t) for more details. * * @version 01/12/14 * @access public * @author Alan Knowles * @param object object to output as $t * @return string - result */ function &bufferedOutputObject(&$t) { ob_start(); $this->outputObject($t); $data = ob_get_contents(); ob_end_clean(); return $data; } /** * gets the template directory * * @version 01/12/14 * @access public * @author Wolfram Kriesing <wolfram@kriesing.de> * @return string path */ function getTemplateDir() { return $this->options['templateDir']; } /** * here all the replacing, filtering and writing of the compiled file is done * well this is not much work, but still its in here :-) * * @access private * @version 01/12/03 * @author Wolfram Kriesing <wolfram@kriesing.de> * @param * @return */ function parse() { // read the entire file into one variable if ( $input = @file($this->currentTemplate) ) { $fileContent = implode( '' , $input ); } else { $fileContent = ''; // if the file doesnt exist, write a template anyway, an empty one but write one } // apply pre filter $fileContent = $this->applyFilters( $fileContent , "/^pre_/i" ); $fileContent = $this->applyFilters( $fileContent , "/^(pre_|post_)/i",TRUE); $fileContent = $this->applyFilters( $fileContent , "/^post_/i" ); // write the compiled template into the compiledTemplate-File if( ($cfp = fopen( $this->compiledTemplate , 'w' )) ) { fwrite($cfp,$fileContent); fclose($cfp); @chmod($this->compiledTemplate,0775); } return true; } /** * compile the template * * @access public * @version 01/12/03 * @author Wolfram Kriesing <wolfram@kriesing.de> * @param string $file relative to the 'templateDir' which you set when calling the constructor * @return */ function compile( $file ) { if (!$file) { PEAR::RaiseError('HTML_Template_Flexy::compile no file selected',null,PEAR_ERROR_DIE); } if (!@$this->options['locale']) { $this->options['locale']='en'; } // if the compileDir doesnt start with a / then its under the template dir if ( $this->options['compileDir']{0} != '/' ) { $this->options['compileDir'] = $this->options['templateDir'].'/'.$this->options['compileDir']; } // remove the slash if there is one in front, just to be clean if ( $file[0] == '/' ) { $file = substr($file,1); } $compileDest = $this->options['compileDir']; if ( !@is_dir($compileDest) ) { // check if the compile dir has been created PEAR::RaiseError( "'compileDir' could not be accessed<br>". "1. please create the 'compileDir' which is: <b>'$compileDest'</b><br>2. give write-rights to it", null, PEAR_ERROR_DIE); } if( !is_writeable($compileDest)) { PEAR::RaiseError( "can not write to 'compileDir', which is <b>'$compileDest'</b><br>". "1. please give write and enter-rights to it", null, PEAR_ERROR_DIE); } $directory = dirname( $file ); $filename = basename($file); // extract dirname to create directori(es) in compileDir in case they dont exist yet // we just keep the directory structure as the application uses it, so we dont get into conflict with names // i dont see no reason for hashing the directories or the filenames if( $directory!='.' ) { // it is '.' also if no dir is given $path = explode('/',$directory); foreach( $path as $aDir ) { $compileDest = $compileDest."/$aDir"; if( !@is_dir($compileDest) ) { umask(0000); // make that the users of this group (mostly 'nogroup') can erase the compiled templates too if( !@mkdir($compileDest,0770) ) { PEAR::RaiseError( "couldn't make directory: <b>'$aDir'</b> under <b>'".$this->options['compileDir']."'</b><br>". "1. please give write permission to the 'compileDir', so SimpleTemplate can create directories inside", null, PEAR_ERROR_DIE); } } } } $this->currentTemplate = $this->options['templateDir'].'/'.$file; if( !@file_exists($this->currentTemplate )) { // check if the compile dir has been created PEAR::RaiseError( "Template {$this->currentTemplate} does not exist<br>", null, PEAR_ERROR_DIE); } $this->compiledTemplate = $compileDest.'/'.$filename.'.'.$this->options['locale'].'.php'; $recompile = false; if( @$this->option['forceCompile'] ) { $recompile = true; } if( $recompile==false ) { // if recompile is true dont bother to check if template has changed if( !$this->isUpToDate() ) { // check if the template has changed $recompile = true; } } if( $recompile ) { // or any of the config files if( !$this->parse() ) { return false; } } return true; } /** * checks if the compiled template is still up to date * * @access private * @version 01/12/03 * @author Wolfram Kriesing <wolfram@kriesing.de> * @param string $fileToCheckAgainst if given this file is checked if it is newer than the compiled template * this is useful if for example only an xml-config file has changed but not the * template itself * @return boolean true if it is still up to date */ function isUpToDate( $fileToCheckAgainst='' ) { if( $fileToCheckAgainst == '' ) { $checkFile = $this->currentTemplate; } else { $checkFile = $fileToCheckAgainst; } if( !file_exists( $this->compiledTemplate ) || filemtime( $checkFile ) > filemtime( $this->compiledTemplate ) ) { return false; } return true; } /** * actually it will only be used to apply the pre and post filters * * @access public * @version 01/12/10 * @author Alan Knowles <alan@akbkhome.com> * @param string $input the string to filter * @param array $prefix the subset of methods to use. * @return string the filtered string */ function applyFilters( $input , $prefix = "",$negate=FALSE) { $this->debug("APPLY FILTER $prefix<BR>"); $filters = $this->option['filters']; $this->debug(serialize($filters)."<BR>"); foreach($filters as $filtername) { $class = "HTML_Template_Flexy_Filter_{$filtername}"; require_once("HTML/Template/Flexy/Filter/{$filtername}.php"); if (!class_exists($class)) { return $this->raiseError("Failed to load filter $filter",null,PEAR_ERROR_DIE); } if (!@$this->filter_objects[$class]) { $this->filter_objects[$class] = new $class; $this->filter_objects[$class]->_set_engine($this); } $filter = &$this->filter_objects[$class]; $methods = get_class_methods($class); $this->debug("METHODS:"); $this->debug(serialize($methods)."<BR>"); foreach($methods as $method) { if ($method{0} == "_") { continue; // private } if ($method == $class) { continue; // constructor } $this->debug("TEST: $negate $prefix : $method"); if ($negate && preg_match($prefix,$method)) { continue; } if (!$negate && !preg_match($prefix,$method)) { continue; } $this->debug("APPLYING $filtername $method<BR>"); $input = $filter->$method($input); } } return $input; } /** * if debugging is on, print the debug info to the screen * * @access public * @author Alan Knowles <alan@akbkhome.com> * @param string $string output to display * @return none */ function debug($string) { if (!$this->option['debug']) { return; } echo "<PRE><B>FLEXY DEBUG:</B> $string</PRE>"; } } ?> Index: pear/HTML_Template_Flexy/package.xml +++ pear/HTML_Template_Flexy/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "../package.dtd"> <package version="1.0"> <name>HTML_Template_Flexy</name> <summary>A Flexible Caching Template Engine Based on SimpleTemplate</summary> <description>Flexy Template is a Template to php code convertor, based on Simple Template, and similar to Smarty. It should be very fast, and is easy to extend to develop or use any template syntax you like Default filter (SimpleTags) includes variables foreach loops conditionals method calls includes Handles urlencoded tags - so you can edit the template in mozilla etc. Other filters include RtfSimpletags - to make RTF/Word documents BodyOnly - to strip header and footer from a template Php - to strip php code from template Tags - Similar to Simpletemplate. Email - For parsing email templates </description> <license>PHP License</license> <maintainers> <maintainer> <user>alan_k</user> <role>lead</role> <name>Alan Knowles</name> <email>alan@akbkhome.com</email> </maintainer> </maintainers> <release> <version>0.1</version> <date>2002-08-23</date> <notes>First PEAR release, Renamed to HTML_Flexy_Template to conform to PEAR standards Added more phpdoc comments to filters </notes> <state>beta</state> <filelist> <dir name="/" baseinstalldir="HTML/Template" role="php"> <file>Flexy.php</file> <dir name="Flexy" role="php"> <file>example.ini</file> <dir name="Filter" role="php"> <file>BodyOnly.php</file> <file>Php.php</file> <file>RtfSimpleTags.php</file> <file>SimpleTags.php</file> <file>Tags.php</file> <file>Mail.php</file> <file>Xml.php</file> <file>Math.php</file> </dir> </dir> </dir> </filelist> </release> <changelog> <release> <version>0.1</version> <date>2002-08-23</date> <notes>First PEAR release, Renamed to HTML_Flexy_Template to conform to PEAR standards Added more phpdoc comments to filters </notes> <state>beta</state> </release> </changelog> </package> Index: pear/HTML_Template_Flexy/Flexy/example.ini +++ pear/HTML_Template_Flexy/Flexy/example.ini ; ; To use config file with HTML_Template_Flexy ; $config = parse_ini_file('example.ini',TRUE) ; $options = &PEAR::getStaticProperty('HTML_Template_Flexy','options'); ; $options = $config['HTML_Template_Flexy']; ; [HTML_Template_Flexy] compileDir = /home/me/Projects/myapplication/compiled_templates ; where the compiled templates go. templateDir = /home/me/Projects/myapplication/templates ; where the original templates are. forceCompile = 0 ; force compile template every time... filters = Php,SimpleTags,BodyOnly ; Order of Classes to use as filters. Index: pear/HTML_Template_Flexy/Flexy/Filter/BodyOnly.php +++ pear/HTML_Template_Flexy/Flexy/Filter/BodyOnly.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Alan Knowles <alan@akbkhome.com> // +----------------------------------------------------------------------+ // /** * The html Body only filter * * @abstract * a Simple filter to remove the everything thats not in the body! * * @package HTML_Template_Flexy * */ class HTML_Template_Flexy_Filter_BodyOnly { /** * Standard Set Engine * * * @param object HTML_Template_Flexy the main engine * @access private */ function _set_engine(&$engine) { } /** * Strip everything before and including the BODY tag * * @param string The template * @access public */ function strip_body_head ($input) { if (!preg_match("/^(.*)<body/si", $input)) { return $input; } $input = preg_replace("/^(.*)<body/si", "",$input); $input = preg_replace("/^([^>]*)>/si", "",$input); return $input; } /** * Strip everything after and including the end BODY tag * * @param string The template * @access public */ function strip_body_foot ($input) { if (!preg_match("/<\/body>.*/si", $input)) { return $input; } $input = preg_replace("/<\/body>.*/si", "",$input); return $input; } } ?> Index: pear/HTML_Template_Flexy/Flexy/Filter/Mail.php +++ pear/HTML_Template_Flexy/Flexy/Filter/Mail.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Alan Knowles <alan@akbkhome.com> // +----------------------------------------------------------------------+ // /** * The Mail filter template (sorts out cr removal in php) * * * @package HTML_Template_Flexy * * * */ class HTML_Template_Flexy_Filter_Mail { /** * Standard Set Engine * * * @param object HTML_Template_Flexy the main engine * @access private */ function _set_engine(&$engine) { } /* * add an extra cr to the end php tag, so it show correctly in Emails * * @param string The template * @access public */ function post_fix_php_cr ($input) { return str_replace("?>\n","?>\n\n",$input); } } ?> Index: pear/HTML_Template_Flexy/Flexy/Filter/Math.php +++ pear/HTML_Template_Flexy/Flexy/Filter/Math.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Alan Knowles <alan@akbkhome.com> // +----------------------------------------------------------------------+ // /** * A Math Filter * * enable simple maths to be done in the template * * TODO: add an {if:t.xxx%2} type syntax.. * * @package HTML_Template_Flexy * */ class HTML_Template_Flexy_Filter_Math { /* * @var string $start the start tag for the template (escaped for regex) */ var $start = '\{'; /* * @var string $stop the stopt tag for the template (escaped for regex) */ var $stop = '\}'; //ending template tag /** * Standard Set Engine * * * @param object HTML_Template_Flexy the main engine * @access private */ function _set_engine(&$engine) { } /* * allow simple add multiply, divide and subtraction * * eg. * {(12+t.somevar)*2} maps to =(12+$t->somevar)*2 * * @param string The template * @access public */ function variables ($input) { $input = preg_replace( "/".$this->start."([0-9\(\)+*\/-]*)([a-z0-9]+)([0-9\(\)+*\/-]*)".$this->stop."/ie", "'<?=\\1($'.str_replace('.','->','\\2').')\\3?>'", $input); return $input; } } ?> Index: pear/HTML_Template_Flexy/Flexy/Filter/Php.php +++ pear/HTML_Template_Flexy/Flexy/Filter/Php.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Alan Knowles <alan@akbkhome.com> // +----------------------------------------------------------------------+ // /** * Remove PHP tags and replace them with echo '< ? ' * * should be the first filter if you use it * * * * @package HTML_Template_Flexy * */ class HTML_Template_Flexy_Filter_Php { /** * Standard Set Engine * * * @param object HTML_Template_Flexy the main engine * @access private */ function _set_engine(&$engine) { } /* * replace the php tags * * @param string The template * @access public */ function pre_strip_php ($input) { $input = str_replace("<?","__{<__?}__",$input); $input = str_replace("?>","<?php echo '?'.'>'; ?>",$input); return str_replace("__{<__?}__","<?php echo '?'.'>'; ?>",$input); } } ?> Index: pear/HTML_Template_Flexy/Flexy/Filter/RtfSimpleTags.php +++ pear/HTML_Template_Flexy/Flexy/Filter/RtfSimpleTags.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Alan Knowles <alan@akbkhome.com> // +----------------------------------------------------------------------+ // /** * The rtf SimpleTags filter * * really an extension of simple tags with \\\{ and \\\\} as the tag delimiters * can parse an RTF template and generate a file. * * usually best used with callback ouput buffering to reduce memory loads. * * @package HTML_Template_Flexy * */ require_once "HTML/Template/Flexy/Filter/SimpleTags.php"; class HTML_Template_Flexy_Filter_RtfSimpleTags extends HTML_Template_Flexy_Filter_simpletags { /* * @var string $start the start tag for the template (escaped for regex) */ var $start = '\\\{'; /* * @var string $stop the stopt tag for the template (escaped for regex) */ var $stop= '\\\}'; } ?> Index: pear/HTML_Template_Flexy/Flexy/Filter/SimpleTags.php +++ pear/HTML_Template_Flexy/Flexy/Filter/SimpleTags.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Alan Knowles <alan@akbkhome.com> // +----------------------------------------------------------------------+ // /** * The Standard Tag filter * * @abstract * does all the clever stuff... * * @package HTML_Template_Flexy * */ class HTML_Template_Flexy_Filter_SimpleTags { /* * @var object HTML_Template_Flexy the main engine */ var $engine; // the engine (with options) /* * @var string $start the start tag for the template (escaped for regex) */ var $start = '\{'; /* * @var string $stop the stopt tag for the template (escaped for regex) */ var $stop = '\}'; /* * @var string $error show/hide the PHP error messages on/off in templates */ var $error = "@"; // change to blank to debug errors. /** * Standard Set Engine * * * @param object HTML_Template_Flexy the main engine * @access private */ function _set_engine(&$engine) { $this->engine = &$engine; if ($this->engine->options['debug']) { $this->error = ""; } } /** * Standard Variable replacement * * * Maps variables * {i.xyz} maps to <?=htmlspecialchars($i->xyz)?> * {i.xyz:h} maps to <?=$i->xyz?> * {i.xyz:u} maps to <?=urlencode($i->xyz)?> * * {i.xyz:r} maps to <PRE><?=print_r($i->xyz)?></PRE> * {i.xyz:n} maps to <?=nl2br(htmlspecialchars($i->xyz))?> * * * @param string $input the template * @return string the result of the filtering * @access public */ function variables ($input) { $input = preg_replace( "/".$this->start."([a-z0-9_.]+)".$this->stop."/ie", "'<?=htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').')?>'", $input); $input = preg_replace( "/".$this->start."([a-z0-9_.]+):h".$this->stop."/ie", "'<?=".$this->error."$'.str_replace('.','->','\\1').'?>'", $input); $input = preg_replace( "/".$this->start."([a-z0-9_.]+):u".$this->stop."/ie", "'<?=urlencode(".$this->error."$'.str_replace('.','->','\\1').')?>'", $input); $input = preg_replace( "/".$this->start."([a-z0-9_.]+):r".$this->stop."/ie", "'<PRE><?=print_r($'.str_replace('.','->','\\1').')?></PRE>'", $input); $input = preg_replace( "/".$this->start."([a-z0-9_.]+):n".$this->stop."/ie", "'<?=nl2br(htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').'))?>'", $input); return $input; } /** * Urlencoded Variable replacement * * Often when you use a WYSISYG editor, it replaces { in * the href="{somevar}" with the urlencoded version, this bit fixes it. * * Maps variables * %??i.xyz%?? maps to <?=htmlspecialchars($i->xyz)?> * %??i.xyz:h%?? maps to <?=$i->xyz?> * %??i.xyz:u%?? maps to <?=urlencode($i->xyz)?> * THIS IS PROBABLY THE ONE TO USE! * * %??i.xyz:uu%?? maps to <?=urlencode(urlencode($i->xyz))?> * * * @param string $input the template * @return string the result of the filtering * @access public */ function urlencoded_variables ($input) { $input = preg_replace( "/".urlencode(stripslashes($this->start))."([a-z0-9_.]+)".urlencode(stripslashes($this->stop))."/ie", "'<?=htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').')?>'", $input); $input = preg_replace( "/".urlencode(stripslashes($this->start))."([a-z0-9_.]+):h".urlencode(stripslashes($this->stop))."/ie", "'<?=".$this->error."$'.str_replace('.','->','\\1').'?>'", $input); $input = preg_replace( "/".urlencode(stripslashes($this->start))."([a-z0-9_.]+):u".urlencode(stripslashes($this->stop))."/ie", "'<?=urlencode(".$this->error."$'.str_replace('.','->','\\1').')?>'", $input); $input = preg_replace( "/".urlencode(stripslashes($this->start))."([a-z0-9_.]+):uu".urlencode(stripslashes($this->stop))."/ie", "'<?=urlencode(urlencode(".$this->error."$'.str_replace('.','->','\\1').'))?>'", $input); return $input; } /** * Calling Methods * * This allows you to call methods of your application * * Maps Methods * {t.xxxx_xxxx()} maps to <?=htmlspecialchars($t->xxxx_xxxx())?> * {t.xxxx_xxxx():h} maps to <?=$t->xxxx_xxxx()?> * * {t.xxxx_xxxx(sssss.dddd)} maps to <?=htmlspecialchars($t->xxxx_xxxx($ssss->dddd))?> * {t.xxxx_xxxx(sssss.dddd):h} maps to <?=$t->xxxx_xxxx($ssss->dddd)?> * {t.xxxx_xxxx(sssss.dddd):s} maps to <?php highlight_string($t->xxxx_xxxx($ssss->dddd))?> * * {t.xxxx_xxxx(#XXXXX#)} maps to <?=htmlspecialchars($t->xxxx_xxxx('XXXXXX'))?> * {t.xxxx_xxxx(#XXXXX#):h} maps to <?=$t->xxxx_xxxx('XXXXXX')?> * * {t.xxxx_xxxx(sss.ddd,sss.ddd)} maps to <?=htmlspecialchars($t->xxxx_xxxx($sss->ddd,$sss->ddd))?> * {t.xxxx_xxxx(#aaaa#,sss.ddd)} maps to <?=htmlspecialchars($t->xxxx_xxxx("aaaa",$sss->ddd))?> * {t.xxxx_xxxx(sss.ddd,#aaaa#)} maps to <?=htmlspecialchars($t->xxxx_xxxx($sss->ddd,"aaaa"))?> * * * * @param string $input the template * @return string the result of the filtering * @access public */ function methods($input) { /* no vars */ $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(\)".$this->stop."/ie", "'<?=htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').'())?>'", $input); $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(\):h".$this->stop."/ie", "'<?=".$this->error."$'.str_replace('.','->','\\1').'()?>'", $input); /* single vars */ $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(([a-z0-9_.]+)\)".$this->stop."/ie", "'<?=htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . '))?>'", $input); $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(([a-z0-9_.]+)\):h".$this->stop."/ie", "'<?=".$this->error."$'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . ')?>'", $input); $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(([a-z0-9_.]+)\):s".$this->stop."/ie", "'<?php highlight_string($'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . '));?>'", $input); /* double vars */ $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(([a-z0-9_.]+),([a-z0-9_.]+)\)".$this->stop."/ie", "'<?=htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . ',$' . str_replace('.','->','\\3') . '))?>'", $input); /* double vars:: # #'d ,var */ $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(\#([^\#]+)\#,([a-z0-9_.]+)\)".$this->stop."/ie", "'<?=htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').'(\''. str_replace(\"'\",\"\\\'\",'\\2') . '\',$' . str_replace('.','->','\\3') . '))?>'", $input); /* double vars:: var , # #'d */ $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(([a-z0-9_.]+),\#([^\#]+)\#\)".$this->stop."/ie", "'<?=htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . ',\''. str_replace(\"'\",\"\\\'\",'\\3') . '\'))?>'", $input); /*strings or integers */ $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(\#([^\#]+)\#\)".$this->stop."/ie", "'<?=htmlspecialchars(\$'.str_replace('.','->','\\1') . '(\''. str_replace(\"'\",\"\\\'\",'\\2') . '\'))?>'", $input); $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(\#([^\#]+)\#\):h".$this->stop."/ie", "'<?=".$this->error."$'.str_replace('.','->','\\1').'(\"' . str_replace(\"'\",\"\\\'\",'\\2') . '\")?>'", $input); return $input; } /** * Looping * * This allows you to do loops on variables (eg. nested/ repeated blocks!) * * Maps Methods * {foreach:t.xyz,zzz} maps to <?php if ($i->xyz) foreach ($t->xyz as $zzz) { ?> * {foreach:t.xyz,xxx,zzz} maps to <?php if ($i->xyz) foreach ($t->xyz as $xxx=>$zzz) { ?> * {end:} maps to <?php }?> * {else:} maps to <?php }else{?> * * * * @param string $input the template * @return string the result of the filtering * @access public */ function looping($input) { $input = preg_replace( "/".$this->start."foreach:([a-z0-9_.]+),([a-z0-9_.]+)".$this->stop."/ie", "'<?php if (".$this->error."$' . str_replace('.','->','\\1') . ') foreach( $' . str_replace('.','->','\\1') . ' as $' . str_replace('.','->','\\2') . ') { ?>'", $input); $input = preg_replace( "/".$this->start."foreach:([a-z0-9_.]+),([a-z0-9_.]+),([a-z0-9_.]+)".$this->stop."/ie", "'<?php if (".$this->error."$' . str_replace('.','->','\\1') . ') foreach( $' . str_replace('.','->','\\1') . ' as $' . str_replace('.','->','\\2') . '=>$' . str_replace('.','->','\\3') .') { ?>'", $input); $input = str_replace(stripslashes($this->start)."else:".stripslashes($this->stop),'<?php }else{?>', $input); $input = str_replace(stripslashes($this->start)."end:".stripslashes($this->stop),'<?php }?>', $input); return $input; } /** * Conditional inclusion * * This allows you to do conditional inclusion (eg. blocks!) * * Maps conditions * * {if:t.xxxx} => <?php if ($t->xxxx) { ?> * {if:t.x_xxx()} => <?php if ($t->x_xxx()) { ?> * * @param string $input the template * @return string the result of the filtering * @access public */ function conditionals($input) { $input = preg_replace( "/".$this->start."if:([a-z0-9_.]+)".$this->stop."/ie", "'<?php if (".$this->error."$' . str_replace('.','->','\\1') . ') { ?>'", $input); $input = preg_replace( "/".$this->start."if:([a-z0-9_.]+)\(\)".$this->stop."/ie", "'<?php if (".$this->error."$' . str_replace('.','->','\\1') . '()) { ?>'", $input); return $input; } /** * sub template inclusion * * This allows you to do include other files (either flat or generated templates.). * * {include:t.abcdef} maps to <?php * if($t->abcdef && file_exists($compileDir . "/". $t->abcdef . "en.php")) * include($compileDir . "/". $t->abcdef . ".en.php"); * ?> * * * {include:#abcdef#} => <?php * if(file_exists($compileDir . "/abcdef.en.php")) * include($compileDir . "/abcdef.en.php"); * ?> * * * {t_include:#abcdef.html#} => <?php * if(file_exists($templateDir . "/abcdef.html")) * include($compileDir . "/abcdef.html"); * ?> * * * @param string $input the template * @return string the result of the filtering * @access public */ function include_template($input) { $input = preg_replace( "/".$this->start."include:([a-z0-9_.]+)".$this->stop."/ie", "'<?php if ((".$this->error."$' . str_replace('.','->','\\1') . ') && file_exists(\"" . $this->engine->options['compileDir'] . "/\{$' . str_replace('.','->','\\1') . '}.en.php\")) include(\"" . $this->engine->options['compileDir'] . "/\{$' . str_replace('.','->','\\1') . '}.en.php\");?>'", $input); $input = preg_replace( "/".$this->start."include:#([a-z0-9_.]+)#".$this->stop."/ie", "'<?php if (file_exists(\"" . $this->engine->options['compileDir'] . "/\\1.en.php\")) include(\"" . $this->engine->options['compileDir'] . "/\\1.en.php\");?>'", $input); $input = preg_replace( "/".$this->start."t_include:#([a-z0-9_.]+)#".$this->stop."/ie", "'<?php if (file_exists(\"" . $this->engine->option['templateDir'] . "/\\1\")) include(\"" . $this->engine->option['templateDir'] . "/\\1\");?>'", $input); return $input; } } ?> Index: pear/HTML_Template_Flexy/Flexy/Filter/Tags.php +++ pear/HTML_Template_Flexy/Flexy/Filter/Tags.php <? /** * The original SimpleTemplate emulation filter * NOT DOCUMENTED = as it's depreciated. * @package Template_Flexy * */ class Template_Flexy_Filter_Tags { var $engine; // the engine (with options) function Filter_tags (&$engine) { $this->engine = &$engine; } function variables ($input) { /* // variables //mega simple templating engine..... //user sees : <?=$xyz.abc.yx?> //<?=([^\s:]+)?> -> <?=htmlspecialchars(".str_replace(".","->",$1).")?> */ $input = preg_replace( "/<\?=([^\s:]+)\?>/e", "'<?=htmlspecialchars('.str_replace('.','->','\\1').')?>'", $input); /* user sees : <?=$xyz.abc.yx:h?> <?=([^\s:]+):h?> -> <?=".str_replace(".","->",$1)."?> */ $input = preg_replace( "/<\?=([^\s:]+)\:h?>/e", "'<?='.str_replace('.','->','\\1').'?>'", $input); /* user sees : <?=$xyz.abc.yx:u?> <?=([^\s:]+)?> -> <?=urlencode(".str_replace(".","->",$1).")?> */ $input = preg_replace( "/<\?=([^\s:]+):u\?>/e", "'<?=urlencode('.str_replace('.','->','\\1').')?>'", $input); return $input; } function foreach_loop($input) { /* user sees : <?foreach($abc.xxxx,$somevar){?> // foreach loops -> <? if (" . str_replace(".","->",$1). ") foreach( " . str_replace(".","->",$1) . " as " . str_replace(".","->",$2) . ") { ?>" */ $input = preg_replace( "/<\?foreach\(([^,\s]+),([^)\s]+)\){\?>/e", "'<? if (' . str_replace('.','->',\\1) . ') foreach( ' . str_replace('.','->','\\1') . ' as ' . str_replace('.','->','\\2') . ') { ?>'", $input); return $input; } function end_loop($input) { /* // end loops user sees : <?}?> <?> -> <?}?> */ $input = str_replace("<?>",'<?}?>', $input); return $input; } function simple_conditional($input) { /* // conditionals BOOLEAN ONLY user sees: <?if($abc.xyz.zzz){?> <?if\(([^\)\s]+)\){?> -> <?if( " . str_replace(".","->",$1) . ") { ?>" */ $input = preg_replace( "/<\?if\(([^)\s]+)\){\?>/e", "'<? if (' . str_replace('.','->',\\1) . ') { ?>'", $input); return $input; } function method_conditional($input) { /* // conditional method calls BOOLEAN ONLY user sees: <?if($abc.xyz.zzz()){?> <?if\(([^\(\s]+)\(\)\){?> -> <?if( " . str_replace(".","->",$1) . "()) { ?>" */ $input = preg_replace( "/<\?if\(([^(\s]+)\(\)\){\?>/e", "'<? if (' . str_replace('.','->',\\1) . '()) { ?>'", $input); return $input; } function include_template($input) { /* // include blocks user sees <?include(abcdef_ssss)?> <?include([a-z_]+)?> -> <? include('".$compiled_templates_dir . ".... */ $input = preg_replace( "/<\?include\(([a-z0-9]+)\(\)\){\?>/", "'<? include('" . $this->engine->getOption('compileDir') ."\\1');?>'", $input); } } Index: pear/HTML_Template_Flexy/Flexy/Filter/Xml.php +++ pear/HTML_Template_Flexy/Flexy/Filter/Xml.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Alan Knowles <alan@akbkhome.com> // +----------------------------------------------------------------------+ // /** * Replace XML tags with echo '<' .'?xml'; * * @package HTML_Template_Flexy * */ class HTML_Template_Flexy_Filter_Xml { /** * Standard Set Engine * * * @param object HTML_Template_Flexy the main engine * @access private */ function _set_engine(&$engine) { } /* * replace the xml tags * * @param string The template * @access public */ function pre_replace_xml ($input) { $input = str_replace("?>","<?php echo '?'.'>'; ?>",$input); $input = str_replace("<?xml","<?php echo '<'.'?xml'; ?>",$input); return $input; } } ?>
Index: pear/HTML_Template_Flexy/Flexy.php +++ pear/HTML_Template_Flexy/Flexy.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Alan Knowles <alan@akbkhome.com> // | Original Author: Wolfram Kriesing <wolfram@kriesing.de> | // +----------------------------------------------------------------------+ // /** * @package HTML_Template_Flexy */ /** * A Flexible Template engine - based on simpletemplate * * @abstract Long Description * This is a rip of of Wolfram's Simple Template class - heavily simplified, * with a modified filter loading mechanism. * notebly * - no xml config stuff * - simplified filters - so you just tell it which filter (classes) to use, * not individual methods * - a smarty like tag library, * - heavily focused on displaying objects as pages. * (so you can document your tags.) * * @version $Id: Flexy.php,v 1.1 2002/08/23 06:55:21 alan_k Exp $ */ class HTML_Template_Flexy { /* * @var array $options the options for initializing the template class */ var $options = array( 'compileDir' => '', // by default its always the same one as where the template lies in, this might not be desired 'templateDir' => '', 'forceCompile' => false, // only suggested for debugging 'filters' => array(), 'debug' => false ); /** * Constructor * * Initializes the Template engine, for each instance, accepts options or * reads from PEAR::getStaticProperty('HTML_Template_Flexy','options'); * * @access public * @param array $options (Optional) */ function HTML_Template_Flexy( $options=array() ) { $baseoptions = &PEAR::getStaticProperty('HTML_Template_Flexy','options'); foreach( $baseoptions as $key=>$aOption ) { $this->options[$key] = $aOption; } foreach( $options as $key=>$aOption ) { $this->options[$key] = $aOption; } $filters = $this->options['filters']; if (is_string($filters)) { $this->options['filters']= explode(',',$filters); } if(!@is_dir($this->options['compileDir']) ) return new PEAR_Error('The compile-directory doesnt exist yet!'); } /** * Outputs an object as $t * * for example the using simpletags the object's variable $t->test * would map to {t.test} * * maps * $t->o_* maps to {o.*} // used for output * $t->input maps to {i.*} // used for input * $t->modules[xxxx] maps to {m.xxxx} // used for modules * $t->config maps to {c.*} // used for config * PEAR::getStaticProperty('Auth','singleton') maps to {a.*} * {email_boundary} // for email boundaries {email_date} // for email dates * * * @version 01/12/14 * @access public * @author Alan Knowles * @param object object to output as $t * @return none */ function outputObject(&$t) { $options = PEAR::getStaticProperty('HTML_Template_Flexy','options'); if (@$options['debug']) { echo "output $this->compiledTemplate<BR>"; } $m = new StdClass; // compile modules if (@$t->modules) { foreach ($t->modules as $modulename=>$object) { $m->$modulename = &$t->modules[$modulename]; $te = $this; if (@$object->template) { $te->compile($object->template); } } } $c = & $t->config; if (@$t->input) { $i = & $t->input; } $a = &PEAR::getStaticProperty('Auth','singleton'); /* expose o_ as $o */ $o = new stdClass; foreach (get_object_vars($t) as $k=>$v) { if ($k{0} != "o") { continue; } if ($k{1} != "_") { continue; } $kk = substr($k,2); $o->$kk =& $t->$k; } /* usefull stuff for doing emails in Template Flexy */ $email_boundary = md5("FlexyMail".microtime()); $email_date = date("D j M Y G:i:s O"); include($this->compiledTemplate); } /** * Outputs an object as $t, buffers the result and returns it. * * See outputObject($t) for more details. * * @version 01/12/14 * @access public * @author Alan Knowles * @param object object to output as $t * @return string - result */ function &bufferedOutputObject(&$t) { ob_start(); $this->outputObject($t); $data = ob_get_contents(); ob_end_clean(); return $data; } /** * gets the template directory * * @version 01/12/14 * @access public * @author Wolfram Kriesing <wolfram@kriesing.de> * @return string path */ function getTemplateDir() { return $this->options['templateDir']; } /** * here all the replacing, filtering and writing of the compiled file is done * well this is not much work, but still its in here :-) * * @access private * @version 01/12/03 * @author Wolfram Kriesing <wolfram@kriesing.de> * @param * @return */ function parse() { // read the entire file into one variable if ( $input = @file($this->currentTemplate) ) { $fileContent = implode( '' , $input ); } else { $fileContent = ''; // if the file doesnt exist, write a template anyway, an empty one but write one } // apply pre filter $fileContent = $this->applyFilters( $fileContent , "/^pre_/i" ); $fileContent = $this->applyFilters( $fileContent , "/^(pre_|post_)/i",TRUE); $fileContent = $this->applyFilters( $fileContent , "/^post_/i" ); // write the compiled template into the compiledTemplate-File if( ($cfp = fopen( $this->compiledTemplate , 'w' )) ) { fwrite($cfp,$fileContent); fclose($cfp); @chmod($this->compiledTemplate,0775); } return true; } /** * compile the template * * @access public * @version 01/12/03 * @author Wolfram Kriesing <wolfram@kriesing.de> * @param string $file relative to the 'templateDir' which you set when calling the constructor * @return */ function compile( $file ) { if (!$file) { PEAR::RaiseError('HTML_Template_Flexy::compile no file selected',null,PEAR_ERROR_DIE); } if (!@$this->options['locale']) { $this->options['locale']='en'; } // if the compileDir doesnt start with a / then its under the template dir if ( $this->options['compileDir']{0} != '/' ) { $this->options['compileDir'] = $this->options['templateDir'].'/'.$this->options['compileDir']; } // remove the slash if there is one in front, just to be clean if ( $file[0] == '/' ) { $file = substr($file,1); } $compileDest = $this->options['compileDir']; if ( !@is_dir($compileDest) ) { // check if the compile dir has been created PEAR::RaiseError( "'compileDir' could not be accessed<br>". "1. please create the 'compileDir' which is: <b>'$compileDest'</b><br>2. give write-rights to it", null, PEAR_ERROR_DIE); } if( !is_writeable($compileDest)) { PEAR::RaiseError( "can not write to 'compileDir', which is <b>'$compileDest'</b><br>". "1. please give write and enter-rights to it", null, PEAR_ERROR_DIE); } $directory = dirname( $file ); $filename = basename($file); // extract dirname to create directori(es) in compileDir in case they dont exist yet // we just keep the directory structure as the application uses it, so we dont get into conflict with names // i dont see no reason for hashing the directories or the filenames if( $directory!='.' ) { // it is '.' also if no dir is given $path = explode('/',$directory); foreach( $path as $aDir ) { $compileDest = $compileDest."/$aDir"; if( !@is_dir($compileDest) ) { umask(0000); // make that the users of this group (mostly 'nogroup') can erase the compiled templates too if( !@mkdir($compileDest,0770) ) { PEAR::RaiseError( "couldn't make directory: <b>'$aDir'</b> under <b>'".$this->options['compileDir']."'</b><br>". "1. please give write permission to the 'compileDir', so SimpleTemplate can create directories inside", null, PEAR_ERROR_DIE); } } } } $this->currentTemplate = $this->options['templateDir'].'/'.$file; if( !@file_exists($this->currentTemplate )) { // check if the compile dir has been created PEAR::RaiseError( "Template {$this->currentTemplate} does not exist<br>", null, PEAR_ERROR_DIE); } $this->compiledTemplate = $compileDest.'/'.$filename.'.'.$this->options['locale'].'.php'; $recompile = false; if( @$this->option['forceCompile'] ) { $recompile = true; } if( $recompile==false ) { // if recompile is true dont bother to check if template has changed if( !$this->isUpToDate() ) { // check if the template has changed $recompile = true; } } if( $recompile ) { // or any of the config files if( !$this->parse() ) { return false; } } return true; } /** * checks if the compiled template is still up to date * * @access private * @version 01/12/03 * @author Wolfram Kriesing <wolfram@kriesing.de> * @param string $fileToCheckAgainst if given this file is checked if it is newer than the compiled template * this is useful if for example only an xml-config file has changed but not the * template itself * @return boolean true if it is still up to date */ function isUpToDate( $fileToCheckAgainst='' ) { if( $fileToCheckAgainst == '' ) { $checkFile = $this->currentTemplate; } else { $checkFile = $fileToCheckAgainst; } if( !file_exists( $this->compiledTemplate ) || filemtime( $checkFile ) > filemtime( $this->compiledTemplate ) ) { return false; } return true; } /** * actually it will only be used to apply the pre and post filters * * @access public * @version 01/12/10 * @author Alan Knowles <alan@akbkhome.com> * @param string $input the string to filter * @param array $prefix the subset of methods to use. * @return string the filtered string */ function applyFilters( $input , $prefix = "",$negate=FALSE) { $this->debug("APPLY FILTER $prefix<BR>"); $filters = $this->option['filters']; $this->debug(serialize($filters)."<BR>"); foreach($filters as $filtername) { $class = "HTML_Template_Flexy_Filter_{$filtername}"; require_once("HTML/Template/Flexy/Filter/{$filtername}.php"); if (!class_exists($class)) { return $this->raiseError("Failed to load filter $filter",null,PEAR_ERROR_DIE); } if (!@$this->filter_objects[$class]) { $this->filter_objects[$class] = new $class; $this->filter_objects[$class]->_set_engine($this); } $filter = &$this->filter_objects[$class]; $methods = get_class_methods($class); $this->debug("METHODS:"); $this->debug(serialize($methods)."<BR>"); foreach($methods as $method) { if ($method{0} == "_") { continue; // private } if ($method == $class) { continue; // constructor } $this->debug("TEST: $negate $prefix : $method"); if ($negate && preg_match($prefix,$method)) { continue; } if (!$negate && !preg_match($prefix,$method)) { continue; } $this->debug("APPLYING $filtername $method<BR>"); $input = $filter->$method($input); } } return $input; } /** * if debugging is on, print the debug info to the screen * * @access public * @author Alan Knowles <alan@akbkhome.com> * @param string $string output to display * @return none */ function debug($string) { if (!$this->option['debug']) { return; } echo "<PRE><B>FLEXY DEBUG:</B> $string</PRE>"; } } ?> Index: pear/HTML_Template_Flexy/package.xml +++ pear/HTML_Template_Flexy/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "../package.dtd"> <package version="1.0"> <name>HTML_Template_Flexy</name> <summary>A Flexible Caching Template Engine Based on SimpleTemplate</summary> <description>Flexy Template is a Template to php code convertor, based on Simple Template, and similar to Smarty. It should be very fast, and is easy to extend to develop or use any template syntax you like Default filter (SimpleTags) includes variables foreach loops conditionals method calls includes Handles urlencoded tags - so you can edit the template in mozilla etc. Other filters include RtfSimpletags - to make RTF/Word documents BodyOnly - to strip header and footer from a template Php - to strip php code from template Tags - Similar to Simpletemplate. Email - For parsing email templates </description> <license>PHP License</license> <maintainers> <maintainer> <user>alan_k</user> <role>lead</role> <name>Alan Knowles</name> <email>alan@akbkhome.com</email> </maintainer> </maintainers> <release> <version>0.1</version> <date>2002-08-23</date> <notes>First PEAR release, Renamed to HTML_Flexy_Template to conform to PEAR standards Added more phpdoc comments to filters </notes> <state>beta</state> <filelist> <dir name="/" baseinstalldir="HTML/Template" role="php"> <file>Flexy.php</file> <dir name="Flexy" role="php"> <file>example.ini</file> <dir name="Filter" role="php"> <file>BodyOnly.php</file> <file>Php.php</file> <file>RtfSimpleTags.php</file> <file>SimpleTags.php</file> <file>Tags.php</file> <file>Mail.php</file> <file>Xml.php</file> <file>Math.php</file> </dir> </dir> </dir> </filelist> </release> <changelog> <release> <version>0.1</version> <date>2002-08-23</date> <notes>First PEAR release, Renamed to HTML_Flexy_Template to conform to PEAR standards Added more phpdoc comments to filters </notes> <state>beta</state> </release> </changelog> </package> Index: pear/HTML_Template_Flexy/Flexy/example.ini +++ pear/HTML_Template_Flexy/Flexy/example.ini ; ; To use config file with HTML_Template_Flexy ; $config = parse_ini_file('example.ini',TRUE) ; $options = &PEAR::getStaticProperty('HTML_Template_Flexy','options'); ; $options = $config['HTML_Template_Flexy']; ; [HTML_Template_Flexy] compileDir = /home/me/Projects/myapplication/compiled_templates ; where the compiled templates go. templateDir = /home/me/Projects/myapplication/templates ; where the original templates are. forceCompile = 0 ; force compile template every time... filters = Php,SimpleTags,BodyOnly ; Order of Classes to use as filters. Index: pear/HTML_Template_Flexy/Flexy/Filter/BodyOnly.php +++ pear/HTML_Template_Flexy/Flexy/Filter/BodyOnly.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Alan Knowles <alan@akbkhome.com> // +----------------------------------------------------------------------+ // /** * The html Body only filter * * @abstract * a Simple filter to remove the everything thats not in the body! * * @package HTML_Template_Flexy * */ class HTML_Template_Flexy_Filter_BodyOnly { /** * Standard Set Engine * * * @param object HTML_Template_Flexy the main engine * @access private */ function _set_engine(&$engine) { } /** * Strip everything before and including the BODY tag * * @param string The template * @access public */ function strip_body_head ($input) { if (!preg_match("/^(.*)<body/si", $input)) { return $input; } $input = preg_replace("/^(.*)<body/si", "",$input); $input = preg_replace("/^([^>]*)>/si", "",$input); return $input; } /** * Strip everything after and including the end BODY tag * * @param string The template * @access public */ function strip_body_foot ($input) { if (!preg_match("/<\/body>.*/si", $input)) { return $input; } $input = preg_replace("/<\/body>.*/si", "",$input); return $input; } } ?> Index: pear/HTML_Template_Flexy/Flexy/Filter/Mail.php +++ pear/HTML_Template_Flexy/Flexy/Filter/Mail.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Alan Knowles <alan@akbkhome.com> // +----------------------------------------------------------------------+ // /** * The Mail filter template (sorts out cr removal in php) * * * @package HTML_Template_Flexy * * * */ class HTML_Template_Flexy_Filter_Mail { /** * Standard Set Engine * * * @param object HTML_Template_Flexy the main engine * @access private */ function _set_engine(&$engine) { } /* * add an extra cr to the end php tag, so it show correctly in Emails * * @param string The template * @access public */ function post_fix_php_cr ($input) { return str_replace("?>\n","?>\n\n",$input); } } ?> Index: pear/HTML_Template_Flexy/Flexy/Filter/Math.php +++ pear/HTML_Template_Flexy/Flexy/Filter/Math.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Alan Knowles <alan@akbkhome.com> // +----------------------------------------------------------------------+ // /** * A Math Filter * * enable simple maths to be done in the template * * TODO: add an {if:t.xxx%2} type syntax.. * * @package HTML_Template_Flexy * */ class HTML_Template_Flexy_Filter_Math { /* * @var string $start the start tag for the template (escaped for regex) */ var $start = '\{'; /* * @var string $stop the stopt tag for the template (escaped for regex) */ var $stop = '\}'; //ending template tag /** * Standard Set Engine * * * @param object HTML_Template_Flexy the main engine * @access private */ function _set_engine(&$engine) { } /* * allow simple add multiply, divide and subtraction * * eg. * {(12+t.somevar)*2} maps to =(12+$t->somevar)*2 * * @param string The template * @access public */ function variables ($input) { $input = preg_replace( "/".$this->start."([0-9\(\)+*\/-]*)([a-z0-9]+)([0-9\(\)+*\/-]*)".$this->stop."/ie", "'<?=\\1($'.str_replace('.','->','\\2').')\\3?>'", $input); return $input; } } ?> Index: pear/HTML_Template_Flexy/Flexy/Filter/Php.php +++ pear/HTML_Template_Flexy/Flexy/Filter/Php.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Alan Knowles <alan@akbkhome.com> // +----------------------------------------------------------------------+ // /** * Remove PHP tags and replace them with echo '< ? ' * * should be the first filter if you use it * * * * @package HTML_Template_Flexy * */ class HTML_Template_Flexy_Filter_Php { /** * Standard Set Engine * * * @param object HTML_Template_Flexy the main engine * @access private */ function _set_engine(&$engine) { } /* * replace the php tags * * @param string The template * @access public */ function pre_strip_php ($input) { $input = str_replace("<?","__{<__?}__",$input); $input = str_replace("?>","<?php echo '?'.'>'; ?>",$input); return str_replace("__{<__?}__","<?php echo '?'.'>'; ?>",$input); } } ?> Index: pear/HTML_Template_Flexy/Flexy/Filter/RtfSimpleTags.php +++ pear/HTML_Template_Flexy/Flexy/Filter/RtfSimpleTags.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Alan Knowles <alan@akbkhome.com> // +----------------------------------------------------------------------+ // /** * The rtf SimpleTags filter * * really an extension of simple tags with \\\{ and \\\\} as the tag delimiters * can parse an RTF template and generate a file. * * usually best used with callback ouput buffering to reduce memory loads. * * @package HTML_Template_Flexy * */ require_once "HTML/Template/Flexy/Filter/SimpleTags.php"; class HTML_Template_Flexy_Filter_RtfSimpleTags extends HTML_Template_Flexy_Filter_simpletags { /* * @var string $start the start tag for the template (escaped for regex) */ var $start = '\\\{'; /* * @var string $stop the stopt tag for the template (escaped for regex) */ var $stop= '\\\}'; } ?> Index: pear/HTML_Template_Flexy/Flexy/Filter/SimpleTags.php +++ pear/HTML_Template_Flexy/Flexy/Filter/SimpleTags.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Alan Knowles <alan@akbkhome.com> // +----------------------------------------------------------------------+ // /** * The Standard Tag filter * * @abstract * does all the clever stuff... * * @package HTML_Template_Flexy * */ class HTML_Template_Flexy_Filter_SimpleTags { /* * @var object HTML_Template_Flexy the main engine */ var $engine; // the engine (with options) /* * @var string $start the start tag for the template (escaped for regex) */ var $start = '\{'; /* * @var string $stop the stopt tag for the template (escaped for regex) */ var $stop = '\}'; /* * @var string $error show/hide the PHP error messages on/off in templates */ var $error = "@"; // change to blank to debug errors. /** * Standard Set Engine * * * @param object HTML_Template_Flexy the main engine * @access private */ function _set_engine(&$engine) { $this->engine = &$engine; if ($this->engine->options['debug']) { $this->error = ""; } } /** * Standard Variable replacement * * * Maps variables * {i.xyz} maps to <?=htmlspecialchars($i->xyz)?> * {i.xyz:h} maps to <?=$i->xyz?> * {i.xyz:u} maps to <?=urlencode($i->xyz)?> * * {i.xyz:r} maps to <PRE><?=print_r($i->xyz)?></PRE> * {i.xyz:n} maps to <?=nl2br(htmlspecialchars($i->xyz))?> * * * @param string $input the template * @return string the result of the filtering * @access public */ function variables ($input) { $input = preg_replace( "/".$this->start."([a-z0-9_.]+)".$this->stop."/ie", "'<?=htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').')?>'", $input); $input = preg_replace( "/".$this->start."([a-z0-9_.]+):h".$this->stop."/ie", "'<?=".$this->error."$'.str_replace('.','->','\\1').'?>'", $input); $input = preg_replace( "/".$this->start."([a-z0-9_.]+):u".$this->stop."/ie", "'<?=urlencode(".$this->error."$'.str_replace('.','->','\\1').')?>'", $input); $input = preg_replace( "/".$this->start."([a-z0-9_.]+):r".$this->stop."/ie", "'<PRE><?=print_r($'.str_replace('.','->','\\1').')?></PRE>'", $input); $input = preg_replace( "/".$this->start."([a-z0-9_.]+):n".$this->stop."/ie", "'<?=nl2br(htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').'))?>'", $input); return $input; } /** * Urlencoded Variable replacement * * Often when you use a WYSISYG editor, it replaces { in * the href="{somevar}" with the urlencoded version, this bit fixes it. * * Maps variables * %??i.xyz%?? maps to <?=htmlspecialchars($i->xyz)?> * %??i.xyz:h%?? maps to <?=$i->xyz?> * %??i.xyz:u%?? maps to <?=urlencode($i->xyz)?> * THIS IS PROBABLY THE ONE TO USE! * * %??i.xyz:uu%?? maps to <?=urlencode(urlencode($i->xyz))?> * * * @param string $input the template * @return string the result of the filtering * @access public */ function urlencoded_variables ($input) { $input = preg_replace( "/".urlencode(stripslashes($this->start))."([a-z0-9_.]+)".urlencode(stripslashes($this->stop))."/ie", "'<?=htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').')?>'", $input); $input = preg_replace( "/".urlencode(stripslashes($this->start))."([a-z0-9_.]+):h".urlencode(stripslashes($this->stop))."/ie", "'<?=".$this->error."$'.str_replace('.','->','\\1').'?>'", $input); $input = preg_replace( "/".urlencode(stripslashes($this->start))."([a-z0-9_.]+):u".urlencode(stripslashes($this->stop))."/ie", "'<?=urlencode(".$this->error."$'.str_replace('.','->','\\1').')?>'", $input); $input = preg_replace( "/".urlencode(stripslashes($this->start))."([a-z0-9_.]+):uu".urlencode(stripslashes($this->stop))."/ie", "'<?=urlencode(urlencode(".$this->error."$'.str_replace('.','->','\\1').'))?>'", $input); return $input; } /** * Calling Methods * * This allows you to call methods of your application * * Maps Methods * {t.xxxx_xxxx()} maps to <?=htmlspecialchars($t->xxxx_xxxx())?> * {t.xxxx_xxxx():h} maps to <?=$t->xxxx_xxxx()?> * * {t.xxxx_xxxx(sssss.dddd)} maps to <?=htmlspecialchars($t->xxxx_xxxx($ssss->dddd))?> * {t.xxxx_xxxx(sssss.dddd):h} maps to <?=$t->xxxx_xxxx($ssss->dddd)?> * {t.xxxx_xxxx(sssss.dddd):s} maps to <?php highlight_string($t->xxxx_xxxx($ssss->dddd))?> * * {t.xxxx_xxxx(#XXXXX#)} maps to <?=htmlspecialchars($t->xxxx_xxxx('XXXXXX'))?> * {t.xxxx_xxxx(#XXXXX#):h} maps to <?=$t->xxxx_xxxx('XXXXXX')?> * * {t.xxxx_xxxx(sss.ddd,sss.ddd)} maps to <?=htmlspecialchars($t->xxxx_xxxx($sss->ddd,$sss->ddd))?> * {t.xxxx_xxxx(#aaaa#,sss.ddd)} maps to <?=htmlspecialchars($t->xxxx_xxxx("aaaa",$sss->ddd))?> * {t.xxxx_xxxx(sss.ddd,#aaaa#)} maps to <?=htmlspecialchars($t->xxxx_xxxx($sss->ddd,"aaaa"))?> * * * * @param string $input the template * @return string the result of the filtering * @access public */ function methods($input) { /* no vars */ $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(\)".$this->stop."/ie", "'<?=htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').'())?>'", $input); $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(\):h".$this->stop."/ie", "'<?=".$this->error."$'.str_replace('.','->','\\1').'()?>'", $input); /* single vars */ $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(([a-z0-9_.]+)\)".$this->stop."/ie", "'<?=htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . '))?>'", $input); $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(([a-z0-9_.]+)\):h".$this->stop."/ie", "'<?=".$this->error."$'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . ')?>'", $input); $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(([a-z0-9_.]+)\):s".$this->stop."/ie", "'<?php highlight_string($'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . '));?>'", $input); /* double vars */ $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(([a-z0-9_.]+),([a-z0-9_.]+)\)".$this->stop."/ie", "'<?=htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . ',$' . str_replace('.','->','\\3') . '))?>'", $input); /* double vars:: # #'d ,var */ $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(\#([^\#]+)\#,([a-z0-9_.]+)\)".$this->stop."/ie", "'<?=htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').'(\''. str_replace(\"'\",\"\\\'\",'\\2') . '\',$' . str_replace('.','->','\\3') . '))?>'", $input); /* double vars:: var , # #'d */ $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(([a-z0-9_.]+),\#([^\#]+)\#\)".$this->stop."/ie", "'<?=htmlspecialchars(".$this->error."$'.str_replace('.','->','\\1').'($' . str_replace('.','->','\\2') . ',\''. str_replace(\"'\",\"\\\'\",'\\3') . '\'))?>'", $input); /*strings or integers */ $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(\#([^\#]+)\#\)".$this->stop."/ie", "'<?=htmlspecialchars(\$'.str_replace('.','->','\\1') . '(\''. str_replace(\"'\",\"\\\'\",'\\2') . '\'))?>'", $input); $input = preg_replace( "/".$this->start."([a-z0-9_.]+)\(\#([^\#]+)\#\):h".$this->stop."/ie", "'<?=".$this->error."$'.str_replace('.','->','\\1').'(\"' . str_replace(\"'\",\"\\\'\",'\\2') . '\")?>'", $input); return $input; } /** * Looping * * This allows you to do loops on variables (eg. nested/ repeated blocks!) * * Maps Methods * {foreach:t.xyz,zzz} maps to <?php if ($i->xyz) foreach ($t->xyz as $zzz) { ?> * {foreach:t.xyz,xxx,zzz} maps to <?php if ($i->xyz) foreach ($t->xyz as $xxx=>$zzz) { ?> * {end:} maps to <?php }?> * {else:} maps to <?php }else{?> * * * * @param string $input the template * @return string the result of the filtering * @access public */ function looping($input) { $input = preg_replace( "/".$this->start."foreach:([a-z0-9_.]+),([a-z0-9_.]+)".$this->stop."/ie", "'<?php if (".$this->error."$' . str_replace('.','->','\\1') . ') foreach( $' . str_replace('.','->','\\1') . ' as $' . str_replace('.','->','\\2') . ') { ?>'", $input); $input = preg_replace( "/".$this->start."foreach:([a-z0-9_.]+),([a-z0-9_.]+),([a-z0-9_.]+)".$this->stop."/ie", "'<?php if (".$this->error."$' . str_replace('.','->','\\1') . ') foreach( $' . str_replace('.','->','\\1') . ' as $' . str_replace('.','->','\\2') . '=>$' . str_replace('.','->','\\3') .') { ?>'", $input); $input = str_replace(stripslashes($this->start)."else:".stripslashes($this->stop),'<?php }else{?>', $input); $input = str_replace(stripslashes($this->start)."end:".stripslashes($this->stop),'<?php }?>', $input); return $input; } /** * Conditional inclusion * * This allows you to do conditional inclusion (eg. blocks!) * * Maps conditions * * {if:t.xxxx} => <?php if ($t->xxxx) { ?> * {if:t.x_xxx()} => <?php if ($t->x_xxx()) { ?> * * @param string $input the template * @return string the result of the filtering * @access public */ function conditionals($input) { $input = preg_replace( "/".$this->start."if:([a-z0-9_.]+)".$this->stop."/ie", "'<?php if (".$this->error."$' . str_replace('.','->','\\1') . ') { ?>'", $input); $input = preg_replace( "/".$this->start."if:([a-z0-9_.]+)\(\)".$this->stop."/ie", "'<?php if (".$this->error."$' . str_replace('.','->','\\1') . '()) { ?>'", $input); return $input; } /** * sub template inclusion * * This allows you to do include other files (either flat or generated templates.). * * {include:t.abcdef} maps to <?php * if($t->abcdef && file_exists($compileDir . "/". $t->abcdef . "en.php")) * include($compileDir . "/". $t->abcdef . ".en.php"); * ?> * * * {include:#abcdef#} => <?php * if(file_exists($compileDir . "/abcdef.en.php")) * include($compileDir . "/abcdef.en.php"); * ?> * * * {t_include:#abcdef.html#} => <?php * if(file_exists($templateDir . "/abcdef.html")) * include($compileDir . "/abcdef.html"); * ?> * * * @param string $input the template * @return string the result of the filtering * @access public */ function include_template($input) { $input = preg_replace( "/".$this->start."include:([a-z0-9_.]+)".$this->stop."/ie", "'<?php if ((".$this->error."$' . str_replace('.','->','\\1') . ') && file_exists(\"" . $this->engine->options['compileDir'] . "/\{$' . str_replace('.','->','\\1') . '}.en.php\")) include(\"" . $this->engine->options['compileDir'] . "/\{$' . str_replace('.','->','\\1') . '}.en.php\");?>'", $input); $input = preg_replace( "/".$this->start."include:#([a-z0-9_.]+)#".$this->stop."/ie", "'<?php if (file_exists(\"" . $this->engine->options['compileDir'] . "/\\1.en.php\")) include(\"" . $this->engine->options['compileDir'] . "/\\1.en.php\");?>'", $input); $input = preg_replace( "/".$this->start."t_include:#([a-z0-9_.]+)#".$this->stop."/ie", "'<?php if (file_exists(\"" . $this->engine->option['templateDir'] . "/\\1\")) include(\"" . $this->engine->option['templateDir'] . "/\\1\");?>'", $input); return $input; } } ?> Index: pear/HTML_Template_Flexy/Flexy/Filter/Tags.php +++ pear/HTML_Template_Flexy/Flexy/Filter/Tags.php <? /** * The original SimpleTemplate emulation filter * NOT DOCUMENTED = as it's depreciated. * @package Template_Flexy * */ class Template_Flexy_Filter_Tags { var $engine; // the engine (with options) function Filter_tags (&$engine) { $this->engine = &$engine; } function variables ($input) { /* // variables //mega simple templating engine..... //user sees : <?=$xyz.abc.yx?> //<?=([^\s:]+)?> -> <?=htmlspecialchars(".str_replace(".","->",$1).")?> */ $input = preg_replace( "/<\?=([^\s:]+)\?>/e", "'<?=htmlspecialchars('.str_replace('.','->','\\1').')?>'", $input); /* user sees : <?=$xyz.abc.yx:h?> <?=([^\s:]+):h?> -> <?=".str_replace(".","->",$1)."?> */ $input = preg_replace( "/<\?=([^\s:]+)\:h?>/e", "'<?='.str_replace('.','->','\\1').'?>'", $input); /* user sees : <?=$xyz.abc.yx:u?> <?=([^\s:]+)?> -> <?=urlencode(".str_replace(".","->",$1).")?> */ $input = preg_replace( "/<\?=([^\s:]+):u\?>/e", "'<?=urlencode('.str_replace('.','->','\\1').')?>'", $input); return $input; } function foreach_loop($input) { /* user sees : <?foreach($abc.xxxx,$somevar){?> // foreach loops -> <? if (" . str_replace(".","->",$1). ") foreach( " . str_replace(".","->",$1) . " as " . str_replace(".","->",$2) . ") { ?>" */ $input = preg_replace( "/<\?foreach\(([^,\s]+),([^)\s]+)\){\?>/e", "'<? if (' . str_replace('.','->',\\1) . ') foreach( ' . str_replace('.','->','\\1') . ' as ' . str_replace('.','->','\\2') . ') { ?>'", $input); return $input; } function end_loop($input) { /* // end loops user sees : <?}?> <?> -> <?}?> */ $input = str_replace("<?>",'<?}?>', $input); return $input; } function simple_conditional($input) { /* // conditionals BOOLEAN ONLY user sees: <?if($abc.xyz.zzz){?> <?if\(([^\)\s]+)\){?> -> <?if( " . str_replace(".","->",$1) . ") { ?>" */ $input = preg_replace( "/<\?if\(([^)\s]+)\){\?>/e", "'<? if (' . str_replace('.','->',\\1) . ') { ?>'", $input); return $input; } function method_conditional($input) { /* // conditional method calls BOOLEAN ONLY user sees: <?if($abc.xyz.zzz()){?> <?if\(([^\(\s]+)\(\)\){?> -> <?if( " . str_replace(".","->",$1) . "()) { ?>" */ $input = preg_replace( "/<\?if\(([^(\s]+)\(\)\){\?>/e", "'<? if (' . str_replace('.','->',\\1) . '()) { ?>'", $input); return $input; } function include_template($input) { /* // include blocks user sees <?include(abcdef_ssss)?> <?include([a-z_]+)?> -> <? include('".$compiled_templates_dir . ".... */ $input = preg_replace( "/<\?include\(([a-z0-9]+)\(\)\){\?>/", "'<? include('" . $this->engine->getOption('compileDir') ."\\1');?>'", $input); } } Index: pear/HTML_Template_Flexy/Flexy/Filter/Xml.php +++ pear/HTML_Template_Flexy/Flexy/Filter/Xml.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Alan Knowles <alan@akbkhome.com> // +----------------------------------------------------------------------+ // /** * Replace XML tags with echo '<' .'?xml'; * * @package HTML_Template_Flexy * */ class HTML_Template_Flexy_Filter_Xml { /** * Standard Set Engine * * * @param object HTML_Template_Flexy the main engine * @access private */ function _set_engine(&$engine) { } /* * replace the xml tags * * @param string The template * @access public */ function pre_replace_xml ($input) { $input = str_replace("?>","<?php echo '?'.'>'; ?>",$input); $input = str_replace("<?xml","<?php echo '<'.'?xml'; ?>",$input); return $input; } } ?>