📄 token.php
字号:
<?php/* vim: set expandtab tabstop=4 shiftwidth=4: */// +----------------------------------------------------------------------+// | 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. |// +----------------------------------------------------------------------+// | Authors: Alan Knowles <alan@akbkhome> |// +----------------------------------------------------------------------+//// $Id: Token.php,v 1.51 2005/05/14 03:44:26 alan_k Exp $//// This is the master Token file for The New Token driver Engine.// All the Token output, and building routines are in here.//// Note overriden methods are not documented unless they differ majorly from// The parent.//$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['base'] = 0; $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['state'] = 0;$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['statevars'] = array();$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['activeForm'] = '';$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['tokens'] = array();$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['gettextStrings'] = array();$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['activeFormId'] = 0;$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['flexyIgnore'] = false;/*** Base Class for all Tokens.** @abstract Provides the static Create Method, and default toString() methods**/class HTML_Template_Flexy_Token { /** * the token type (Depreciated when we have classes for all tokens * * @var string * @access public */ var $token; /** * the default value (normally a string) * * @var string * @access public */ var $value; /** * the line the token is from * * @var int * @access public */ var $line; /** * the character Position * * @var int * @access public */ var $charPos; /** * factory a Token * * Standard factory method.. - with object vars. * ?? rename me to factory? * @param string Token type * @param mixed Initialization settings for token * @param int line that the token is defined. * * * @return object Created Object * @access public */ function factory($token,$value,$line,$charPos=0) { // try not to reload the same class to often static $loaded = array(); $c = 'HTML_Template_Flexy_Token_'.$token; if (!class_exists($c) && !isset($loaded[$token])) { // make sure parse errors are picked up - no @ here.. if (file_exists(dirname(__FILE__)."/Token/{$token}.php")) { require_once 'HTML/Template/Flexy/Token/'.$token.'.php'; } $loaded[$token] = true; } $t = new HTML_Template_Flexy_Token; if (class_exists($c)) { $t = new $c; } $t->token = $token; $t->charPos = $charPos; if ($t->setValue($value) === false) { // kick back error conditions.. return false; } $t->line = $line; return $t; } /** * Standard Value iterpretor * * @param mixed value recieved from factory method * @return none * @access public */ function setValue($value) { $this->value = $value; } /** * compile to String (vistor method) replaces toString * * @return string HTML * @access public */ function compile(&$compiler) { return $compiler->toString($this); } /** * compile children (visitor approach). * * @return string HTML * @access public */ function compileChildren( &$compiler) { if (!$this->children) { return ''; } if ($this->ignoreChildren) { return; } $ret = ''; //echo "output $this->id"; //new Gtk_VarDump($this); foreach ($this->children as $child) { if (!$child) { continue; } $add = $child->compile($compiler); if (is_a($add,'PEAR_Error')) { return $add; } $ret .= $add; } return $ret; } /* ======================================================= */ /* Token Managmenet = parse and store all the tokens in * an associative array and tree. */ /** * Run a Tokenizer and Store its results * It should build a DOM Tree of the HTML * * @param object Tokenizer to run.. - Theoretically other Tokenizers could be done for email,rtf etc. * * @access public * @return base token (really a dummy token, which contains the tree) * @static */ function buildTokens($tokenizer) { global $_HTML_TEMPLATE_FLEXY_TOKEN; // first record is a filler - to stick all the children on ! // reset my globals.. $_HTML_TEMPLATE_FLEXY_TOKEN['base'] = 0; $_HTML_TEMPLATE_FLEXY_TOKEN['statevars'] = array(); $_HTML_TEMPLATE_FLEXY_TOKEN['state'] = 0; $_HTML_TEMPLATE_FLEXY_TOKEN['flexyIgnore'] = false; if (@$GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['flexyIgnore']) { $_HTML_TEMPLATE_FLEXY_TOKEN['flexyIgnore'] = true; } $_HTML_TEMPLATE_FLEXY_TOKEN['activeFormId'] = 0; $_HTML_TEMPLATE_FLEXY_TOKEN['activeForm'] = ''; $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'] = array(new HTML_Template_Flexy_Token); $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][0]->id =0; $_HTML_TEMPLATE_FLEXY_TOKEN['gettextStrings'] = array(); $i=1; // initialize state - this trys to make sure that // you dont do to many elses etc. //echo "RUNNING TOKENIZER"; // step one just tokenize it. while ($t = $tokenizer->yylex()) { if ($t == HTML_TEMPLATE_FLEXY_TOKEN_ERROR) { //echo "ERROR"; //print_r($tokenizer); $err = "<PRE>" . $tokenizer->error . "\n" . htmlspecialchars(substr($tokenizer->yy_buffer,0,$tokenizer->yy_buffer_end)) . "<font color='red'>". htmlspecialchars(substr($tokenizer->yy_buffer,$tokenizer->yy_buffer_end,100)) . ".......</font></PRE>"; return HTML_Template_Flexy::raiseError('HTML_Template_Flexy::Syntax error in ". "Template line:'. $tokenizer->yyline . $err , HTML_TEMPLATE_FLEXY_ERROR_SYNTAX ,HTML_TEMPLATE_FLEXY_ERROR_RETURN); } if ($t == HTML_TEMPLATE_FLEXY_TOKEN_NONE) { continue; } if ( $tokenizer->value->token == 'Php' ) { if (!$GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['allowPHP']) { return HTML_Template_Flexy::raiseError('PHP code found in script (Token)', HTML_TEMPLATE_FLEXY_ERROR_SYNTAX,HTML_TEMPLATE_FLEXY_ERROR_RETURN ); } if ($GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['allowPHP'] === 'delete') { continue; } } $i++; $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i] = $tokenizer->value; $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->id = $i; // this whole children thing needs rethinking // - I think the body of the page should be wrapped: .. // ?php if (!$this->bodyOnly) { .. <HTML> .... <BODY....> ?php } ? // // old values alias to new ones.. if (isset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->ucAttributes['FLEXYSTART'])) { unset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->ucAttributes['FLEXYSTART']); $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->ucAttributes['FLEXY:START'] = true; } if (isset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->ucAttributes['FLEXYSTARTCHILDREN'])) { unset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->ucAttributes['FLEXYSTARTCHILDREN']); $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->ucAttributes['FLEXY:STARTCHILDREN'] = true; } if (isset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->ucAttributes['FLEXY:START'])) { $_HTML_TEMPLATE_FLEXY_TOKEN['base'] = $i; unset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->ucAttributes['FLEXY:START']); } if (isset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->ucAttributes['FLEXY:STARTCHILDREN'])) { $_HTML_TEMPLATE_FLEXY_TOKEN['base'] = $i; } //print_r($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]); } //echo "BUILT TOKENS"; $res = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens']; // DEBUG DUMPTING : foreach($res as $k) { $k->dump(); } $stack = array(); $total = $i +1; // merge strings and entities - blanking out empty text. for($i=1;$i<$total;$i++) { if (!isset($res[$i]) || !is_a($res[$i],'HTML_Template_Flexy_Token_Text')) { continue; } $first = $i; $i++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -