⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tag.php

📁 FP2 CRM code+Mysql DB
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?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: Tag.php,v 1.50 2004/07/29 04:26:24 alan_k Exp $/* FC/BC compatibility with php5 */if ( (substr(phpversion(),0,1) < 5) && !function_exists('clone')) {    eval('function clone($t) { return $t; }');}/*** Compiler That deals with standard HTML Tag output.* Since it's pretty complex it has it's own class.* I guess this class should deal with the main namespace* and the parent (standard compiler can redirect other namespaces to other classes.** one instance of these exists for each namespace.*** @version    $Id: Tag.php,v 1.50 2004/07/29 04:26:24 alan_k Exp $*/class HTML_Template_Flexy_Compiler_Standard_Tag {            /**    * Parent Compiler for     *    * @var  object  HTML_Template_Flexy_Compiler      *     * @access public    */    var $compiler;    /**    *       * Factory method to create Tag Handlers    *    * $type = namespace eg. <flexy:toJavascript loads Flexy.php    * the default is this... (eg. Tag)    *     *     * @param   string    Namespace handler for element.    * @param   object   HTML_Template_Flexy_Compiler      *     *    * @return    object    tag compiler    * @access   public    */        function &factory($type,&$compiler) {        if (!$type) {            $type = 'Tag';        }        // if we dont have a handler - just use the basic handler.        if (!file_exists(dirname(__FILE__) . '/'. ucfirst(strtolower($type)) . '.php')) {            $type = 'Tag';        }                    include_once 'HTML/Template/Flexy/Compiler/Standard/' . ucfirst(strtolower($type)) . '.php';                $class = 'HTML_Template_Flexy_Compiler_Standard_' . $type;        if (!class_exists($class)) {            return false;        }        $ret = new $class;        $ret->compiler = &$compiler;        return $ret;    }                    /**    * The current element to parse..    *    * @var object    * @access public    */        var $element;        /**    * Flag to indicate has attribute flexy:foreach (so you cant mix it with flexy:if!)    *    * @var boolean    * @access public    */        var $hasForeach = false;                    /**    * toString - display tag, attributes, postfix and any code in attributes.    * Note first thing it does is call any parseTag Method that exists..    *    *     * @see parent::toString()    */    function toString($element)     {                global $_HTML_TEMPLATE_FLEXY_TOKEN;        global $_HTML_TEMPLATE_FLEXY;                 // store the element in a variable        $this->element = $element;       // echo "toString: Line {$this->element->line} &lt;{$this->element->tag}&gt;\n";                 // if the FLEXYSTARTCHILDREN flag was set, only do children        // normally set in BODY tag.        // this will probably be superseeded by the Class compiler.                 if (isset($element->ucAttributes['FLEXY:STARTCHILDREN'])) {                        return $element->compileChildren($this->compiler);        }                $flexyignore = $this->parseAttributeIgnore();                // rewriting should be done with a tag.../flag.                $this->reWriteURL("HREF");        $this->reWriteURL("SRC");                // handle elements        if (($ret =$this->_parseTags()) !== false) {            return $ret;        }        // these add to the close tag..                $ret  = $this->parseAttributeForeach();        $ret .= $this->parseAttributeIf();                // spit ou the tag and attributes.                if ($element->oTag{0} == '?') {            $ret .= '<?php echo "<"; ?>';        } else {             $ret .= "<";        }        $ret .= $element->oTag;              foreach ($element->attributes as $k=>$v) {            // if it's a flexy tag ignore it.                                    if (strtoupper($k) == 'FLEXY:RAW') {                if (!is_array($v) || !isset($v[1]) || !is_object($v[1])) {                    return HTML_Template_Flexy::raiseError(                        'flexy:raw only accepts a variable or method call as an argument, eg.'.                        ' flexy:raw="{somevalue}" you provided something else.' .                        " Error on Line {$this->element->line} &lt;{$this->element->tag}&gt;",                         null,   HTML_TEMPLATE_FLEXY_ERROR_DIE);                }                $add = $v[1]->compile($this->compiler);                if (is_a($add,'PEAR_Error')) {                    return $add;                }                $ret .= ' ' . $add;                continue;                        }                        if (strtoupper(substr($k,0,6)) == 'FLEXY:') {                continue;            }            // true == an attribute without a ="xxx"            if ($v === true) {                $ret .= " $k";                continue;            }                        // if it's a string just dump it.            if (is_string($v)) {                $ret .=  " {$k}={$v}";                continue;            }                        // normally the value is an array of string, however            // if it is an object - then it's a conditional key.            // eg.  if (something) echo ' SELECTED';            // the object is responsible for adding it's space..                        if (is_object($v)) {                $add = $v->compile($this->compiler);                if (is_a($add,'PEAR_Error')) {                    return $add;                }                            $ret .= $add;                continue;            }                        // otherwise its a key="sometext{andsomevars}"                        $ret .=  " {$k}=";                        foreach($v as $item) {                if (is_string($item)) {                    $ret .= $item;                    continue;                }                $add = $item->compile($this->compiler);                if (is_a($add,'PEAR_Error')) {                    return $add;                }                $ret .= $add;            }        }        $ret .= ">";                // post stuff this is probably in the wrong place...                if ($element->postfix) {            foreach ($element->postfix as $e) {                $add = $e->compile($this->compiler);                if (is_a($add,'PEAR_Error')) {                    return $add;                }                $ret .= $add;            }        } else if ($this->element->postfix) { // if postfixed by self..            foreach ($this->element->postfix as $e) {                $add = $e->compile($this->compiler);                if (is_a($add,'PEAR_Error')) {                    return $add;                }                            $ret .= $add;            }        }        // dump contents of script raw - to prevent gettext additions..        //  print_r($element);        if ($element->tag == 'SCRIPT') {            foreach($element->children as $c) {                //print_R($c);                if (!$c) {                    continue;                }                if ($c->token == 'Text') {                    $ret .= $c->value;                    continue;                }                // techically we shouldnt have anything else inside of script tags.                // as the tokeinzer is supposted to ignore it..            }        } else {            $add = $element->compileChildren($this->compiler);            if (is_a($add,'PEAR_Error')) {                return $add;            }            $ret .= $add;        }                                // output the closing tag.                if ($element->close) {            $add = $element->close->compile($this->compiler);            if (is_a($add,'PEAR_Error')) {                return $add;            }            $ret .= $add;        }                // reset flexyignore                $_HTML_TEMPLATE_FLEXY_TOKEN['flexyIgnore'] = $flexyignore;                if (isset($_HTML_TEMPLATE_FLEXY['currentOptions']['output.block']) &&             ($_HTML_TEMPLATE_FLEXY['currentOptions']['output.block'] == $element->getAttribute('ID'))) {                           // echo $_HTML_TEMPLATE_FLEXY['compiledTemplate'];                        $fh = fopen($_HTML_TEMPLATE_FLEXY['compiledTemplate'],'w');            fwrite($fh,$ret);            fclose($fh);                      }                                    return $ret;    }    /**    * Reads an flexy:foreach attribute -     *    *    * @return   string to add to output.    * @access   public    */        function parseAttributeIgnore()     {            global $_HTML_TEMPLATE_FLEXY_TOKEN;                $flexyignore = $_HTML_TEMPLATE_FLEXY_TOKEN['flexyIgnore'];                if ($this->element->getAttribute('FLEXY:IGNORE') !== false) {            $_HTML_TEMPLATE_FLEXY_TOKEN['flexyIgnore'] = true;            $this->element->clearAttribute('FLEXY:IGNORE');        }        return $flexyignore;    }        /**    * Reads an flexy:foreach attribute -     *    *    * @return   string to add to output.    * @access   public    */        function parseAttributeForeach()     {        $foreach = $this->element->getAttribute('FLEXY:FOREACH');        if ($foreach === false) {            return '';        }        //var_dump($foreach);                $this->element->hasForeach = true;        // create a foreach element to wrap this with.                $foreachObj =  $this->element->factory('Foreach',                explode(',',$foreach),                $this->element->line);        // failed = probably not enough variables..                            if ($foreachObj === false) {            return HTML_Template_Flexy::raiseError(                "Missing Arguments: An flexy:foreach attribute was foundon Line {$this->element->line}                 in tag &lt;{$this->element->tag} flexy:foreach=&quot;$foreach&quot; .....&gt;<BR>                the syntax is  &lt;sometag flexy:foreach=&quot;onarray,withvariable[,withanothervar] &gt;<BR>",                 null,  HTML_TEMPLATE_FLEXY_ERROR_DIE);        }                                // does it have a closetag?        if (!$this->element->close) {                    if ($this->element->getAttribute('/') === false) {                                        return HTML_Template_Flexy::raiseError(                    "A flexy:foreach attribute was found in &lt;{$this->element->name} tag without a corresponding &lt;/{$this->element->tag}                        tag on Line {$this->element->line} &lt;{$this->element->tag}&gt;",                     null, HTML_TEMPLATE_FLEXY_ERROR_DIE);            }            // it's an xhtml tag!            $this->element->postfix = array($this->element->factory("End", '', $this->element->line));        } else {            $this->element->close->postfix = array($this->element->factory("End", '', $this->element->line));        }        $this->element->clearAttribute('FLEXY:FOREACH');        return $foreachObj->compile($this->compiler);    }    /**    * Reads an flexy:if attribute -     *    *    * @return   string to add to output.    * @access   public    */        function parseAttributeIf()     {        // dont use the together, if is depreciated..        $if = $this->element->getAttribute('FLEXY:IF');                if ($if === false) {            return '';        }                if (isset($this->element->hasForeach)) {            return HTML_Template_Flexy::raiseError(                "You may not use FOREACH and IF tags in the same tag on Line {$this->element->line} &lt;{$this->element->tag}&gt;",                 null, HTML_TEMPLATE_FLEXY_ERROR_DIE);        }                // allow if="!somevar"        $ifnegative = '';                if ($if{0} == '!') {            $ifnegative = '!';                $if = substr($if,1);        }        // if="xxxxx"        // if="xxxx.xxxx()" - should create a method prefixed with 'if:'        // these checks should really be in the if/method class..!!!                                if (!preg_match('/^[_A-Z][A-Z0-9_]*(\[[0-9]+\])?((\[|%5B)[A-Z0-9_]+(\]|%5D))*'.                '(\.[_A-Z][A-Z0-9_]*((\[|%5B)[A-Z0-9_]+(\]|%5D))*)*(\\([^)]*\))?$/i',$if)) {            return HTML_Template_Flexy::raiseError(                "IF tags only accept simple object.variable or object.method() values on                     Line {$this->element->line} &lt;{$this->element->tag}&gt;                    {$if}",                 null, HTML_TEMPLATE_FLEXY_ERROR_DIE);        }                if (substr($if,-1) == ')') {            // grab args..            $args = substr($if,strpos($if,'(')+1,-1);            // simple explode ...                        $args = strlen(trim($args)) ? explode(',',$args) : array();            //print_R($args);                        // this is nasty... - we need to check for quotes = eg. # at beg. & end..            $args_clean = array();            for ($i=0; $i<count($args); $i++) {                if ($args[$i]{0} != '#') {                    $args_clean[] = $args[$i];                    continue;                }                // single # - so , must be inside..                if ((strlen($args[$i]) > 1) && ($args[$i]{strlen($args[$i])-1}=='#')) {                    $args_clean[] = $args[$i];                    continue;                }                                $args[$i] .=',' . $args[$i+1];                // remove args+1..                array_splice($args,$i+1,1);                $i--;                // reparse..

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -