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

📄 it.php

📁 FP2 CRM code+Mysql DB
💻 PHP
📖 第 1 页 / 共 3 页
字号:
        $this->touchedBlocks[$block] = true;        return true;    } // end func touchBlock    /**     * Clears all datafields of the object and rebuild the internal blocklist     *     * LoadTemplatefile() and setTemplate() automatically call this function     * when a new template is given. Don't use this function     * unless you know what you're doing.     *     * @access   public     * @see      free()     */    function init() {        $this->free();        $this->findBlocks($this->template);        // we don't need it any more        $this->template = '';        $this->buildBlockvariablelist();    } // end func init    /**     * Clears all datafields of the object.     *     * Don't use this function unless you know what you're doing.     *     * @access   public     * @see      init()     */    function free() {        $this->err = array();        $this->currentBlock = "__global__";        $this->variableCache    = array();        $this->blocklookup      = array();        $this->touchedBlocks    = array();        $this->flagBlocktrouble = false;        $this->flagGlobalParsed = false;    } // end func free    /**     * Sets the template.     *     * You can eighter load a template file from disk with     * LoadTemplatefile() or set the template manually using this function.     *     * @param        string      template content     * @param        boolean     remove unknown/unused variables?     * @param        boolean     remove empty blocks?     * @see          LoadTemplatefile(), $template     * @access       public     */    function setTemplate( $template, $removeUnknownVariables = true,                          $removeEmptyBlocks = true    ) {        $this->removeUnknownVariables = $removeUnknownVariables;        $this->removeEmptyBlocks = $removeEmptyBlocks;        if ("" == $template && $this->flagCacheTemplatefile) {            $this->variableCache = array();            $this->blockdata = array();            $this->touchedBlocks = array();            $this->currentBlock = "__global__";        } else {            $this->template = '<!-- BEGIN __global__ -->' . $template .                              '<!-- END __global__ -->';            $this->init();        }        if ($this->flagBlocktrouble)            return false;        return true;    } // end func setTemplate    /**     * Reads a template file from the disk.     *     * @param    string      name of the template file     * @param    bool        how to handle unknown variables.     * @param    bool        how to handle empty blocks.     * @access   public     * @return   boolean    false on failure, otherwise true     * @see      $template, setTemplate(), $removeUnknownVariables,     *           $removeEmptyBlocks     */    function loadTemplatefile( $filename,                               $removeUnknownVariables = true,                               $removeEmptyBlocks = true ) {        $template = "";        if (!$this->flagCacheTemplatefile ||            $this->lastTemplatefile != $filename        ){            $template = $this->getfile($filename);        }        $this->lastTemplatefile = $filename;        return $template!=""?                $this->setTemplate(                        $template,$removeUnknownVariables, $removeEmptyBlocks                    ):false;    } // end func LoadTemplatefile    /**     * Sets the file root. The file root gets prefixed to all filenames passed     * to the object.     *     * Make sure that you override this function when using the class     * on windows.     *     * @param    string     * @see      IntegratedTemplate()     * @access   public     */    function setRoot($root) {        if ("" != $root && "/" != substr($root, -1))            $root .= "/";        $this->fileRoot = $root;    } // end func setRoot    /**     * Build a list of all variables within of a block     */    function buildBlockvariablelist() {        foreach ($this->blocklist as $name => $content) {            preg_match_all( $this->variablesRegExp, $content, $regs );            if (0 != count($regs[1])) {                foreach ($regs[1] as $k => $var)                    $this->blockvariables[$name][$var] = true;            } else {                $this->blockvariables[$name] = array();            }        }    } // end func buildBlockvariablelist    /**     * Returns a list of all global variables     */    function getGlobalvariables() {        $regs   = array();        $values = array();        foreach ($this->blockvariables["__global__"] as $allowedvar => $v) {            if (isset($this->variableCache[$allowedvar])) {                $regs[]   = "@" . $this->openingDelimiter .                            $allowedvar . $this->closingDelimiter."@";                $values[] = $this->variableCache[$allowedvar];                unset($this->variableCache[$allowedvar]);            }        }        return array($regs, $values);    } // end func getGlobalvariables    /**     * Recusively builds a list of all blocks within the template.     *     * @param    string    string that gets scanned     * @see      $blocklist     */    function findBlocks($string) {        $blocklist = array();        if (            preg_match_all($this->blockRegExp, $string, $regs, PREG_SET_ORDER)        ) {            foreach ($regs as $k => $match) {                $blockname         = $match[1];                $blockcontent = $match[2];                if (isset($this->blocklist[$blockname])) {                    $this->err[] = PEAR::raiseError(                                            $this->errorMessage(                                            IT_BLOCK_DUPLICATE ) . '"' .                                            $blockname . "'",                                            IT_BLOCK_DUPLICATE                                    );                    $this->flagBlocktrouble = true;                }                $this->blocklist[$blockname] = $blockcontent;                $this->blockdata[$blockname] = "";                $blocklist[] = $blockname;                $inner = $this->findBlocks($blockcontent);                foreach ($inner as $k => $name) {                    $pattern = sprintf(                        '@<!--\s+BEGIN\s+%s\s+-->(.*)<!--\s+END\s+%s\s+-->@sm',                        $name,                        $name                    );                    $this->blocklist[$blockname] = preg_replace(                                        $pattern,                                        $this->openingDelimiter .                                        "__" . $name . "__" .                                        $this->closingDelimiter,                                        $this->blocklist[$blockname]                               );                    $this->blockinner[$blockname][] = $name;                    $this->blockparents[$name] = $blockname;                }            }        }        return $blocklist;    } // end func findBlocks    /**     * Reads a file from disk and returns its content.     * @param    string    Filename     * @return   string    Filecontent     */    function getFile($filename) {        if ("/" == $filename{0} && "/" == substr($this->fileRoot, -1))            $filename = substr($filename, 1);        $filename = $this->fileRoot . $filename;        if (!($fh = @fopen($filename, "r"))) {            $this->err[] = PEAR::raiseError(                        $this->errorMessage(IT_TPL_NOT_FOUND) .                        ': "' .$filename .'"',                        IT_TPL_NOT_FOUND                    );            return "";        }        $content = fread($fh, filesize($filename));        fclose($fh);        return preg_replace(            "#<!-- INCLUDE (.*) -->#ime", "\$this->getFile('\\1')", $content        );    } // end func getFile    /**     * Adds delimiters to a string, so it can be used as a pattern     * in preg_* functions     *     * @param string     * @return string     */    function _addPregDelimiters($str)    {        return '@' . $str . '@';    }   /**    * Replaces an opening delimiter by a special string    *    * @param string    * @return string    */    function _preserveOpeningDelimiter($str)    {        return (false === strpos($str, $this->openingDelimiter))?                $str:                str_replace(                    $this->openingDelimiter,                    $this->openingDelimiter .                    '%preserved%' . $this->closingDelimiter,                    $str                );    }    /**     * Return a textual error message for a IT error code     *     * @param integer $value error code     *     * @return string error message, or false if the error code was     * not recognized     */    function errorMessage($value)    {        static $errorMessages;        if (!isset($errorMessages)) {            $errorMessages = array(                IT_OK                       => '',                IT_ERROR                    => 'unknown error',                IT_TPL_NOT_FOUND            => 'Cannot read the template file',                IT_BLOCK_NOT_FOUND          => 'Cannot find this block',                IT_BLOCK_DUPLICATE          => 'The name of a block must be'.                                               ' uniquewithin a template.'.                                               ' Found "$blockname" twice.'.                                               'Unpredictable results '.                                               'may appear.',                IT_UNKNOWN_OPTION           => 'Unknown option'            );        }        if (PEAR::isError($value)) {            $value = $value->getCode();        }        return isset($errorMessages[$value]) ?                $errorMessages[$value] : $errorMessages[IT_ERROR];    }} // end class IntegratedTemplate?>

⌨️ 快捷键说明

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