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

📄 itx.php

📁 FP2 CRM code+Mysql DB
💻 PHP
📖 第 1 页 / 共 2 页
字号:
                if ('' != $this->callback[$function['name']]['object']) {                    $this->variableCache['__function' . $func_id . '__'] =                        call_user_func(                        array(                        &$GLOBALS[$this->callback[$function['name']]['object']],                        $this->callback[$function['name']]['function']),                        $function['args']                       );                } else {                    $this->variableCache['__function' . $func_id . '__'] =                            call_user_func(                            $this->callback[$function['name']]['function'],                            $function['args']                        );                }            }        }    } // end func performCallback    /**    * Returns a list of all function calls in the current template.    *    * @return   array    * @access   public    */    function getFunctioncalls()    {        return $this->functions;    } // end func getFunctioncalls    /**    * Replaces a function call with the given replacement.    *    * @param    int       Function ID    * @param    string    Replacement    * @deprec    */    function setFunctioncontent($functionID, $replacement)    {        $this->variableCache['__function' . $functionID . '__'] = $replacement;    } // end func setFunctioncontent    /**    * Sets a callback function.    *    * IT[X] templates (note the X) can contain simple function calls.    * "function call" means that the editor of the template can add    * special placeholder to the template like 'func_h1("embedded in h1")'.    * IT[X] will grab this function calls and allow you to define a callback    * function for them.    *    * This is an absolutely evil feature. If your application makes heavy    * use of such callbacks and you're even implementing if-then etc. on    * the level of a template engine you're reiventing the wheel... - that's    * actually how PHP came into life. Anyway, sometimes it's handy.    *    * Consider also using XML/XSLT or native PHP. And please do not push    * IT[X] any further into this direction of adding logics to the template    * engine.    *    * For those of you ready for the X in IT[X]:    *    * <?php    * ...    * function h_one($args) {    *    return sprintf('<h1>%s</h1>', $args[0]);    * }    *    * ...    * $itx = new HTML_Template_ITX( ... );    * ...    * $itx->setCallbackFunction('h1', 'h_one');    * $itx->performCallback();    * ?>    *    * template:    * func_h1('H1 Headline');    *    * @param    string    Function name in the template    * @param    string    Name of the callback function    * @param    string    Name of the callback object    * @return   boolean   False on failure.    * @throws   IT_Error    * @access   public    */    function    setCallbackFunction($tplfunction, $callbackfunction, $callbackobject = '')    {        if ('' == $tplfunction || '' == $callbackfunction) {            return new IT_Error(                "No template function "."('$tplfunction')".                " and/or no callback function ('$callback') given.",                    __FILE__, __LINE__                );        }        $this->callback[$tplfunction] = array(                                          "function"    => $callbackfunction,                                          "object"        => $callbackobject                                        );        return true;    } // end func setCallbackFunction    /**    * Sets the Callback function lookup table    *    * @param    array    function table    *                    array[templatefunction] =    *                       array(    *                               "function" => userfunction,    *                               "object" => userobject    *                       )    * @access    public    */    function setCallbackFuntiontable($functions)    {        $this->callback = $functions;    } // end func setCallbackFunctiontable    /**    * Recursively removes all data assiciated with a block, including all inner blocks    *    * @param    string  block to be removed    */    function removeBlockData($block)    {        if (isset($this->blockinner[$block])) {            foreach ($this->blockinner[$block] as $k => $inner) {                $this->removeBlockData($inner);            }            unset($this->blockinner[$block]);        }        unset($this->blocklist[$block]);        unset($this->blockdata[$block]);        unset($this->blockvariables[$block]);        unset($this->touchedBlocks[$block]);    } // end func removeBlockinner    /**    * Returns a list of blocknames in the template.    *    * @return    array    [blockname => blockname]    * @access    public    * @see        blockExists()    */    function getBlocklist()    {        $blocklist = array();        foreach ($this->blocklist as $block => $content) {            $blocklist[$block] = $block;        }        return $blocklist;    } // end func getBlocklist    /**    * Checks wheter a block exists.    *    * @param    string    * @return    boolean    * @access    public    * @see        getBlocklist()    */    function blockExists($blockname)    {        return isset($this->blocklist[$blockname]);    } // end func blockExists    /**    * Returns a list of variables of a block.    *    * @param    string    Blockname    * @return    array    [varname => varname]    * @access    public    * @see        BlockvariableExists()    */    function getBlockvariables($block)    {        if (!isset($this->blockvariables[$block])) {            return array();        }        $variables = array();        foreach ($this->blockvariables[$block] as $variable => $v) {            $variables[$variable] = $variable;        }        return $variables;    } // end func getBlockvariables    /**    * Checks wheter a block variable exists.    *    * @param    string    Blockname    * @param    string    Variablename    * @return    boolean    * @access    public    * @see    getBlockvariables()    */    function BlockvariableExists($block, $variable)    {        return isset($this->blockvariables[$block][$variable]);    } // end func BlockvariableExists    /**    * Builds a functionlist from the template.    */    function buildFunctionlist()    {        $this->functions = array();        $template = $this->template;        $num = 0;        while (preg_match($this->functionRegExp, $template, $regs)) {            $pos = strpos($template, $regs[0]);            $template = substr($template, $pos + strlen($regs[0]));            $head = $this->getValue($template, ')');            $args = array();            $this->template = str_replace($regs[0] . $head . ')',                                '{__function' . $num . '__}', $this->template                            );            $template = str_replace($regs[0] . $head . ')',                        '{__function' . $num . '__}', $template                        );            while ('' != $head && $args2 = $this->getValue($head, ',')) {                $arg2 = trim($args2);                $args[] = ('"' == $arg2{0} || "'" == $arg2{0}) ?                                    substr($arg2, 1, -1) : $arg2;                if ($arg2 == $head) {                    break;                }                $head = substr($head, strlen($arg2) + 1);            }            $this->functions[$num++] = array(                                                'name'    => $regs[1],                                                'args'    => $args                                            );        }    } // end func buildFunctionlist    function getValue($code, $delimiter) {        if ('' == $code) {            return '';        }        if (!is_array($delimiter)) {            $delimiter = array( $delimiter => true );        }        $len         = strlen($code);        $enclosed    = false;        $enclosed_by = '';        if (isset($delimiter[$code[0]])) {            $i = 1;        } else {            for ($i = 0; $i < $len; ++$i) {                $char = $code[$i];                if (                        ('"' == $char || "'" == $char) &&                        ($char == $enclosed_by || '' == $enclosed_by) &&                        (0 == $i || ($i > 0 && '\\' != $code[$i - 1]))                    ){                    if (!$enclosed) {                        $enclosed_by = $char;                    } else {                        $enclosed_by = "";                    }                    $enclosed = !$enclosed;                }                if (!$enclosed && isset($delimiter[$char])) {                    break;                }            }        }        return substr($code, 0, $i);    } // end func getValue    /**    * Deletes one or many variables from the block variable list.    *    * @param    string    Blockname    * @param    mixed     Name of one variable or array of variables    *                     ( array ( name => true ) ) to be stripped.    */    function deleteFromBlockvariablelist($block, $variables)    {        if (!is_array($variables)) {            $variables = array($variables => true);        }        reset($this->blockvariables[$block]);        while (list($varname, $val) = each($this->blockvariables[$block])) {            if (isset($variables[$varname])) {                unset($this->blockvariables[$block][$varname]);            }        }    } // end deleteFromBlockvariablelist    /**    * Updates the variable list of a block.    *    * @param    string    Blockname    */    function updateBlockvariablelist($block)    {        preg_match_all( $this->variablesRegExp,                        $this->blocklist[$block], $regs                    );        if (0 != count($regs[1])) {            foreach ($regs[1] as $k => $var) {                $this->blockvariables[$block][$var] = true;            }        } else {            $this->blockvariables[$block] = array();        }        // check if any inner blocks were found        if (isset($this->blockinner[$block]) &&            is_array($this->blockinner[$block]) &&            count($this->blockinner[$block]) > 0        ) {            /*             * loop through inner blocks, registering the variable             * placeholders in each             */            foreach($this->blockinner[$block] as $childBlock) {                $this->updateBlockvariablelist($childBlock);            }        }    } // end func updateBlockvariablelist    /**    * Returns an array of blocknames where the given variable    * placeholder is used.    *    * @param    string    Variable placeholder    * @return    array    $parents    parents[0..n] = blockname    */    function findPlaceholderBlocks($variable)    {        $parents = array();        reset($this->blocklist);        while (list($blockname, $content) = each($this->blocklist)) {            reset($this->blockvariables[$blockname]);            while (                list($varname, $val) = each($this->blockvariables[$blockname]))            {                if ($variable == $varname) {                    $parents[] = $blockname;                }            }        }        return $parents;    } // end func findPlaceholderBlocks    /**    * Handles warnings, saves them to $warn and prints them or    * calls die() depending on the flags    *    * @param    string    Warning    * @param    string    File where the warning occured    * @param    int       Linenumber where the warning occured    * @see      $warn, $printWarning, $haltOnWarning    */    function warning($message, $file = '', $line = 0)    {        $message = sprintf(                    'HTML_Template_ITX Warning: %s [File: %s, Line: %d]',                    $message,                    $file,                    $line                );        $this->warn[] = $message;        if ($this->printWarning) {            print $message;        }        if ($this->haltOnError) {            die($message);        }    } // end func warning} // end class HTML_Template_ITX?>

⌨️ 快捷键说明

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