cvs: pear /HTML_TINX TINX.php package.xml

From: Date: Sun, 30 Dec 2001 13:01:59 +0000
Subject: cvs: pear /HTML_TINX TINX.php package.xml
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-1775@lists.php.net to get a copy of this message
sebastian Sun Dec 30 08:01:59 2001 EDT Added files: /pear/HTML_TINX TINX.php package.xml Log: Initial commit for TINX (This Is Not XSLT). This is a 30 minute hack, but it works. Documentation and usage examples follow.

Index: pear/HTML_TINX/TINX.php +++ pear/HTML_TINX/TINX.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: Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // // $Id: TINX.php,v 1.1 2001/12/30 13:01:58 sebastian Exp $ // /** * TINX - This Is Not XSLT * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @version $Revision: 1.1 $ * @access public */ class HTML_TINX { /** * @var string * @access private */ var $_template = ''; /** * @var array * @access private */ var $_keys = array(); /** * @var array * @access private */ var $_values = array(); /** * @var array * @access private */ var $_template_variable_delimiters; /** * @var boolean * @access private */ var $_replace_global_variables; /** * @var boolean * @access private */ var $_execute_processing_instructions; // {{{ function NoNameYet($file = '', $replace_global_variables = false, $execute_processing_instructions = false, $template_variable_delimiters = array('{', '}')) /** * Constructor * * @param string * @param boolean * @param boolean * @param array * @access public */ function HTML_TINX($file = '', $replace_global_variables = false, $execute_processing_instructions = false, $template_variable_delimiters = array('{', '}')) { $this->set_file($file); $this->set_parse_parameters($replace_global_variables, $execute_processing_instructions ); $this->set_template_variable_delimiters($template_variable_delimiters); } // }}} // {{{ function set_file($file) /** * Set/Load template. * * @param string * @access public */ function set_file($file) { if ($file != '' && file_exists($file)) { $this->_template = implode('', @file($file)); } else { $this->_template = ''; } } // }}} // {{{ function set_template_variable_delimiters($start, $end = '') /** * Set template variable delimiters. * * @param mixed * @param mixed * @access public */ function set_template_variable_delimiters($start, $end = '') { if (is_string($start) && is_string($end) && sizeof($end)) { $this->_template_variable_delimiters = array($start, $end); } else if (is_array($start)) { $this->_template_variable_delimiters = $start; } } // }}} // {{{ function set_parse_parameters($replace_global_variables, $execute_processing_instructions) /** * * * @param boolean * @param boolean * @access public */ function set_parse_parameters($replace_global_variables, $execute_processing_instructions) { $this->_replace_global_variables = $replace_global_variables; $this->_execute_processing_instructions = $execute_processing_instructions; } // }}} // {{{ function set_var($keys, $values) /** * Set template variable(s). * * @param mixed * @param mixed * @access public */ function set_var($keys, $values) { if (is_array($keys) && is_array($values) && sizeof($keys) == sizeof($values)) { foreach ($keys as $key) { $this->_keys[] = $this->_template_variable_delimiters[0] . $key . $this->_template_variable_delimiters[1]; } $this->_values = array_merge($this->_values, $values); } else { $this->_keys[] = $this->_template_variable_delimiters[0] . $keys . $this->_template_variable_delimiters[1]; $this->_values[] = $values; } } // }}} // {{{ function parse() /** * Parse template. * * @return string * @access public */ function parse() { if (!empty($this->_template)) { // Execute <php:foo ... /> processing instructions. if ($this->_execute_processing_instructions) { preg_match_all('/\<php:([^>]+)\/\>/im', $this->_template, $processing_instructions ); foreach ($processing_instructions[1] as $processing_instruction) { $this->_keys[] = '<php:' . $processing_instruction . '/>'; $processing_instruction = explode(' ', $processing_instruction); $target = $processing_instruction[0]; $arguments = explode(',', str_replace(array('"', 'parameters='), '', $processing_instruction[1])); if (strstr($target, '::')) { list($class, $method) = explode('::', $target); $result = call_user_method_array($method, $class, $arguments); } elseif (strstr($target, '->')) { list($object, $method) = explode('->', $target); global $$object; $result = call_user_method_array($method, $$object, $arguments); } else { $result = call_user_func_array($target, $arguments); } $this->_values[] = $result; } } // Replace {foo} template variables with values // defined through set_var(). if (sizeof($this->_keys)) { $parsed_template = str_replace($this->_keys, $this->_values, $this->_template ); } else { $parsed_template = $this->_template; } // Replace {foo} template variables, that have not // been taken care of in the previous step, with // global variables of the same name. if ($this->_replace_global_variables) { $parsed_template = preg_replace('/' . preg_quote($this->_template_variable_delimiters[0]) . '([^]]+)' . preg_quote($this->_template_variable_delimiters[1]) . '/ime', 'isset($GLOBALS[\'\\1\']) ? $GLOBALS[\'\\1\'] : \'\'', $parsed_template ); } return $parsed_template; } else { trigger_error('No template loaded or template is empty.', E_USER_WARNING); } } // }}} // {{{ function pparse() /** * Parse and print template. * * @param boolean * @param boolean * @param boolean * @access public */ function pparse() { echo $this->parse(); } // }}} } /* * vim600: et sw=4 ts=4 fdm=marker * vim<600: et sw=4 ts=4 */ ?> Index: pear/HTML_TINX/package.xml +++ pear/HTML_TINX/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <package> <name>HTML_TINX</name> <summary>Template system with tag-triggered function calls.</summary> <description> TINX (This Is Not XSLT) is a template system with tag-triggered PHP function calls. </description> <maintainer> <user>sebastian</user> <name>Sebastian Bergmann</name> <email>sb@sebastian-bergmann.de</email> </maintainer> <release> <version>0.1</version> <date>2001-12-30</date> <notes> This is the initial independent PEAR release. </notes> </release> <filelist> <dir name="/" baseinstalldir="HTML"> <file role="php">TINX.php</file> </dir> </filelist> </package>
« previous php.pear.cvs (#1775) next »