sigma.php
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 1,759 行 · 第 1/5 页
PHP
1,759 行
<?php//// +----------------------------------------------------------------------+// | PHP Version 4 |// +----------------------------------------------------------------------+// | Copyright (c) 1997-2003 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. |// +----------------------------------------------------------------------+// | Authors: Ulf Wendel <ulf.wendel@phpdoc.de> |// | Alexey Borzov <avb@php.net> |// +----------------------------------------------------------------------+//// $Id: Sigma.php,v 1.13 2005/08/09 14:58:45 avb Exp $//require_once 'PEAR.php';define('SIGMA_OK', 1);define('SIGMA_ERROR', -1);define('SIGMA_TPL_NOT_FOUND', -2);define('SIGMA_BLOCK_NOT_FOUND', -3);define('SIGMA_BLOCK_DUPLICATE', -4);define('SIGMA_CACHE_ERROR', -5);define('SIGMA_UNKNOWN_OPTION', -6);define('SIGMA_PLACEHOLDER_NOT_FOUND', -10);define('SIGMA_PLACEHOLDER_DUPLICATE', -11);define('SIGMA_BLOCK_EXISTS', -12);define('SIGMA_INVALID_CALLBACK', -13);define('SIGMA_CALLBACK_SYNTAX_ERROR', -14);/*** HTML_Template_Sigma: implementation of Integrated Templates API with * template 'compilation' added.** The main new feature in Sigma is the template 'compilation'. Consider the* following: when loading a template file the engine has to parse it using* regular expressions to find all the blocks and variable placeholders. This* is a very "expensive" operation and is definitely an overkill to do on * every page request: templates seldom change on production websites. This is* where the cache kicks in: it saves an internal representation of the * template structure into a file and this file gets loaded instead of the * source one on subsequent requests (unless the source changes, of course).* * While HTML_Template_Sigma inherits PHPLib Template's template syntax, it has* an API which is easier to understand. When using HTML_Template_PHPLIB, you* have to explicitly name a source and a target the block gets parsed into.* This gives maximum flexibility but requires full knowledge of template * structure from the programmer.* * Integrated Template on the other hands manages block nesting and parsing * itself. The engine knows that inner1 is a child of block2, there's* no need to tell it about this:** + __global__ (hidden and automatically added)* + block1* + block2* + inner1* + inner2** To add content to block1 you simply type:* <code>$tpl->setCurrentBlock("block1");</code>* and repeat this as often as needed:* <code>* $tpl->setVariable(...);* $tpl->parseCurrentBlock();* </code>** To add content to block2 you would type something like:* <code>* $tpl->setCurrentBlock("inner1");* $tpl->setVariable(...);* $tpl->parseCurrentBlock();** $tpl->setVariable(...);* $tpl->parseCurrentBlock();** $tpl->parse("block2");* </code>** This will result in one repetition of block2 which contains two repetitions* of inner1. inner2 will be removed if $removeEmptyBlock is set to true (which * is the default).** Usage:* <code>* $tpl = new HTML_Template_Sigma( [string filerootdir], [string cacherootdir] );** // load a template or set it with setTemplate()* $tpl->loadTemplatefile( string filename [, boolean removeUnknownVariables, boolean removeEmptyBlocks] )** // set "global" Variables meaning variables not beeing within a (inner) block* $tpl->setVariable( string variablename, mixed value );** // like with the HTML_Template_PHPLIB there's a second way to use setVariable()* $tpl->setVariable( array ( string varname => mixed value ) );** // Let's use any block, even a deeply nested one* $tpl->setCurrentBlock( string blockname );** // repeat this as often as you need it.* $tpl->setVariable( array ( string varname => mixed value ) );* $tpl->parseCurrentBlock();** // get the parsed template or print it: $tpl->show()* $html = $tpl->get();* </code>** @author Ulf Wendel <ulf.wendel@phpdoc.de>* @author Alexey Borzov <avb@php.net>* @version $Revision: 1.13 $* @access public* @package HTML_Template_Sigma*/class HTML_Template_Sigma extends PEAR{ /** * First character of a variable placeholder ( _{_VARIABLE} ). * @var string * @access public * @see $closingDelimiter, $blocknameRegExp, $variablenameRegExp */ var $openingDelimiter = '{'; /** * Last character of a variable placeholder ( {VARIABLE_}_ ) * @var string * @access public * @see $openingDelimiter, $blocknameRegExp, $variablenameRegExp */ var $closingDelimiter = '}'; /** * RegExp for matching the block names in the template. * Per default "sm" is used as the regexp modifier, "i" is missing. * That means a case sensitive search is done. * @var string * @access public * @see $variablenameRegExp, $openingDelimiter, $closingDelimiter */ var $blocknameRegExp = '[0-9A-Za-z_-]+'; /** * RegExp matching a variable placeholder in the template. * Per default "sm" is used as the regexp modifier, "i" is missing. * That means a case sensitive search is done. * @var string * @access public * @see $blocknameRegExp, $openingDelimiter, $closingDelimiter */ var $variablenameRegExp = '[0-9A-Za-z_-]+'; /** * RegExp used to find variable placeholder, filled by the constructor * @var string Looks somewhat like @(delimiter varname delimiter)@ * @see HTML_Template_Sigma() */ var $variablesRegExp = ''; /** * RegExp used to strip unused variable placeholders * @see $variablesRegExp, HTML_Template_Sigma() */ var $removeVariablesRegExp = ''; /** * RegExp used to find blocks and their content, filled by the constructor * @var string * @see HTML_Template_Sigma() */ var $blockRegExp = ''; /** * Controls the handling of unknown variables, default is remove * @var boolean * @access public */ var $removeUnknownVariables = true; /** * Controls the handling of empty blocks, default is remove * @var boolean * @access public */ var $removeEmptyBlocks = true; /** * Name of the current block * @var string */ var $currentBlock = '__global__'; /** * Template blocks and their content * @var array * @see _buildBlocks() * @access private */ var $_blocks = array(); /** * Content of parsed blocks * @var array * @see get(), parse() * @access private */ var $_parsedBlocks = array(); /** * Variable names that appear in the block * @var array * @see _buildBlockVariables() * @access private */ var $_blockVariables = array(); /** * Inner blocks inside the block * @var array * @see _buildBlocks() * @access private */ var $_children = array(); /** * List of blocks to preserve even if they are "empty" * @var array * @see touchBlock(), $removeEmptyBlocks * @access private */ var $_touchedBlocks = array(); /** * List of blocks which should not be shown even if not "empty" * @var array * @see hideBlock(), $removeEmptyBlocks * @access private */ var $_hiddenBlocks = array(); /** * Variables for substitution. * * Variables are kept in this array before the replacements are done. * This allows automatic removal of empty blocks. * * @var array * @see setVariable() * @access private */ var $_variables = array(); /** * Global variables for substitution * * These are substituted into all blocks, are not cleared on * block parsing and do not trigger "non-empty" logic. I.e. if * only global variables are substituted into the block, it is * still considered "empty". * * @var array * @see setVariable(), setGlobalVariable() * @access private */ var $_globalVariables = array(); /** * Root directory for "source" templates * @var string * @see HTML_Template_Sigma(), setRoot() */ var $fileRoot = ''; /** * Directory to store the "prepared" templates in * @var string * @see HTML_Template_Sigma(), setCacheRoot() * @access private */ var $_cacheRoot = null; /** * Flag indicating that the global block was parsed * @var boolean */ var $flagGlobalParsed = false; /** * Options to control some finer aspects of Sigma's work. * * $_options['preserve_data'] If false, then substitute variables and remove empty * placeholders in data passed through setVariable (see also bugs #20199, #21951) * $_options['trim_on_save'] Whether to trim extra whitespace from template on cache save. * Generally safe to have this on, unless you have <pre></pre> in templates or want to * preserve HTML indentantion */ var $_options = array( 'preserve_data' => false, 'trim_on_save' => true ); /** * Function name prefix used when searching for function calls in the template * @var string */ var $functionPrefix = 'func_'; /** * Function name RegExp * @var string */ var $functionnameRegExp = '[_a-zA-Z]+[A-Za-z_0-9]*'; /** * RegExp used to grep function calls in the template (set by the constructor) * @var string * @see _buildFunctionlist(), HTML_Template_Sigma() */ var $functionRegExp = ''; /** * List of functions found in the template. * @var array * @access private */ var $_functions = array(); /** * List of callback functions specified by the user * @var array * @access private */ var $_callback = array(); /** * RegExp used to find file inclusion calls in the template (should have 'e' modifier) * @var string */ var $includeRegExp = '#<!--\s+INCLUDE\s+(\S+)\s+-->#ime'; /** * Files queued for inclusion * @var array * @access private */ var $_triggers = array();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?