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

📄 tpl.inc.php

📁 MyDNSConfig-1.1.0 基于LINUX内核系统的DNS解析系统
💻 PHP
📖 第 1 页 / 共 4 页
字号:
         *         * @return float time taken to parse template         * @access public         */        function getParseTime () {            if ($this->OPTIONS['TIME_PARSE'] && $this->_parsed) {                return $this->_totalparsetime;            }            return false;        }        /**         * FUNCTION: fastPrint         *         * Identical to pparse() except that it uses output buffering w/ gz compression thus         * printing the output directly and compressed if poss.         * Will possibly if parsing a huge template.         *         * @access public         * @return boolean true/false         */        function fastPrint () {            $ret = $this->_parse('ob_gzhandler');            print($this->_tmploutput);            return $ret;        }        /**         * FUNCTION: pparse         *         * Calls parse, and then prints out $this->_tmploutput         *         * @access public         * @return boolean true/false         */        function pparse () {            if (!$this->_parsed) $this->_parse();            print($this->_tmploutput);            return true;        }        /**         * FUNCTION: pprint         *         * Alias for pparse()         *         * @access public         */        function pprint () {            return $this->pparse();        }        /**         * FUNCTION: grab         *         * Returns the parsed output, ready for printing, passing to mail() ...etc.         * Invokes $this->_parse() if template has not yet been parsed.         *         * @access public         * @return boolean true/false         */        function grab () {            if (!$this->_parsed) $this->_parse();            return $this->_tmploutput;        }    /*-----------------------------------------------------------------------------\    |                           private functions                                  |    \-----------------------------------------------------------------------------*/        /**         * FUNCTION: vlibTemplate         *         * vlibTemplate constructor.         * if $tmplfile has been passed to it, it will send to $this->newTemplate()         *         * @param string $tmplfile full path to template file         * @param array $options see above         * @return boolean true/false         * @access private         */        function tpl ($tmplfile=null, $options=null) {            if (is_array($tmplfile) && $options == null) {                $options = $tmplfile;                unset($tmplfile);            }            $this->VLIBTEMPLATE_ROOT = dirname(realpath(__FILE__));            if (is_array(vlibIni::vlibTemplate())) {                foreach (vlibIni::vlibTemplate() as $name => $val) {                    $this->OPTIONS[$name] = $val;                }            }            if (is_array($options)) {                foreach($options as $key => $val) {                    $key = strtoupper($key);                    if ($key == 'PATH') {                        $this->setPath($val);                    }                    else {                        $this->_setOption($key, strtolower($val));                    }                }            }            if($tmplfile) $this->newTemplate($tmplfile);            if ($this->OPTIONS['GLOBAL_CONTEXT_VARS']) $this->setContextVars();            return true;        }        /** FUNCTION: _getData         *         * function returns the text from the file, or if we're using cache, the text         * from the cache file. MUST RETURN DATA.         * @param string tmplfile contains path to template file         * @param do_eval used for included files. If set then this function must do the eval()'ing.         * @access private         * @return mixed data/string or boolean         */        function _getData ($tmplfile, $do_eval=false) {            //check the current file depth            if ($this->_includedepth > $this->OPTIONS['MAX_INCLUDES'] || $tmplfile == false) {                return;            }            else {                if ($this->_debug) array_push ($this->_debugIncludedfiles, $tmplfile);                if ($do_eval) {                    array_push($this->_currentincludedir, dirname($tmplfile));                    $this->_includedepth++;                }            }            if($this->_cache && $this->_checkCache($tmplfile)) { // cache exists so lets use it                $data = fread($fp = fopen($this->_cachefile, 'r'), filesize($this->_cachefile));                fclose($fp);            }            else { // no cache lets parse the file                $data = fread($fp = fopen($tmplfile, 'r'), filesize($tmplfile));                fclose($fp);                $regex = '/(<|<\/|{|{\/|<!--|<!--\/){1}\s*';                $regex.= 'tmpl_([\w]+)\s*';                $regex.= '(?:';                $regex.=    '(?:';                $regex.=        '(name|format|escape|op|value|file)';                $regex.=        '\s*=\s*';                $regex.=    ')?';                $regex.=    '(?:[\"\'])?';                $regex.=    '((?<=[\"\'])';                $regex.=    '[^\"\']*|[a-z0-9_\.]*)';                $regex.=    '[\"\']?';                $regex.= ')?\s*';                $regex.= '(?:';                $regex.=    '(?:';                $regex.=        '(name|format|escape|op|value)';                $regex.=        '\s*=\s*';                $regex.=    ')';                $regex.=    '(?:[\"\'])?';                $regex.=    '((?<=[\"\'])';                $regex.=    '[^\"\']*|[a-z0-9_\.]*)';                $regex.=    '[\"\']?';                $regex.= ')?\s*';                $regex.= '(?:';                $regex.=    '(?:';                $regex.=        '(name|format|escape|op|value)';                $regex.=        '\s*=\s*';                $regex.=    ')';                $regex.=    '(?:[\"\'])?';                $regex.=    '((?<=[\"\'])';                $regex.=    '[^\"\']*|[a-z0-9_\.]*)';                $regex.=    '[\"\']?';                $regex.= ')?\s*';                $regex.= '(?:>|\/>|}|-->){1}';                $regex.= '([\r\n|\n|\r])?/ie';                $data = preg_replace($regex,"\$this->_parseTag(array('\\0','\\1','\\2','\\3','\\4','\\5','\\6','\\7','\\8','\\9'));",$data);                if ($this->_cache) { // add cache if need be                    $this->_createCache($data);                }            }            // now we must parse the $data and check for any <tmpl_include>'s            if ($this->_debug) $this->doDebugWarnings(file($tmplfile), $tmplfile);            if ($do_eval) {                $success = @eval('?>'.$data.'<?php return 1;');                $this->_includedepth--;                array_pop($this->_currentincludedir);                return $success;            }            else {                return $data;            }        }        /**         * FUNCTION: _fileSearch         *         * Searches for all possible instances of file { $file }         *         * @param string $file path of file we're looking for         * @access private         * @return mixed fullpath to file or boolean false         */        function _fileSearch ($file) {            $filename = basename($file);            $filepath = dirname($file);            // check fullpath first..            $fullpath = $filepath.'/'.$filename;            if (is_file($fullpath)) return $fullpath;            // ..then check for relative path for current directory..            if (!empty($this->_currentincludedir)) {                $currdir = $this->_currentincludedir[(count($this->_currentincludedir) -1)];                $relativepath = realpath($currdir.'/'.$filepath.'/'.$filename);                if (is_file($relativepath)) {                    array_push ($this->_currentincludedir, dirname($relativepath));                    return $relativepath;                }            }            // ..then check for relative path for all additional given paths..            if (!empty($this->OPTIONS['INCLUDE_PATHS'])) {                foreach ($this->OPTIONS['INCLUDE_PATHS'] as $currdir) {                    $relativepath = realpath($currdir.'/'.$filepath.'/'.$filename);                    if (is_file($relativepath)) {                        return $relativepath;                    }                }            }            // ..then check path from TEMPLATE_DIR..            if (!empty($this->OPTIONS['TEMPLATE_DIR'])) {                $fullpath = realpath($this->OPTIONS['TEMPLATE_DIR'].'/'.$filepath.'/'.$filename);                if (is_file($fullpath)) return $fullpath;            }            // ..then check relative path from executing php script..            $fullpath = realpath($filepath.'/'.$filename);            if (is_file($fullpath)) return $fullpath;            // ..then check path from template file.            if (!empty($this->VLIBTEMPLATE_ROOT)) {                $fullpath = realpath($this->VLIBTEMPLATE_ROOT.'/'.$filepath.'/'.$filename);                if (is_file($fullpath)) return $fullpath;            }            return false; // uh oh, file not found        }        /**         * FUNCTION: _arrayBuild         *         * Modifies the array $arr to add Template variables, __FIRST__, __LAST__ ..etc         * if $this->OPTIONS['LOOP_CONTEXT_VARS'] is true.         * Used by $this->setloop().         *         * @param array $arr         * @return array new look array         * @access private         */        function _arrayBuild ($arr) {            if (is_array($arr) && !empty($arr)) {                $arr = array_values($arr); // to prevent problems w/ non sequential arrays                for ($i = 0; $i < count($arr); $i++) {                    if(!is_array($arr[$i]))  return false;                    foreach ($arr[$i] as $k => $v) {                        unset($arr[$i][$k]);                        if ($this->OPTIONS['CASELESS']) $k = strtolower($k);                        if (preg_match('/^[0-9]+$/', $k)) $k = '_'.$k;                        if (is_array($v)) {                            if (($arr[$i][$k] = $this->_arrayBuild($v)) == false) return false;                        }                        else { // reinsert the var                            $arr[$i][$k] = $v;                        }                    }                    if ($this->OPTIONS['LOOP_CONTEXT_VARS']) {                        if ($i == 0) $arr[$i]['__FIRST__'] = true;                        if (($i + 1) == count($arr)) $arr[$i]['__LAST__'] = true;                        if ($i != 0 && (($i + 1) < count($arr))) $arr[$i]['__INNER__'] = true;                        if (is_int(($i+1) / 2))  $arr[$i]['__EVEN__'] = true;                        if (!is_int(($i+1) / 2))  $arr[$i]['__ODD__'] = true;                        $arr[$i]['__ROWNUM__'] = ($i + 1);                    }                }                return $arr;            }            elseif (empty($arr)) {                return true;            }        }        /**         * FUNCTION: _parseIf         * returns a string used for parsing in tmpl_if statements.         *         * @param string $varname         * @param string $value         * @param string $op         * @param string $namespace current namespace         * @access private         * @return string used for eval'ing         */        function _parseIf ($varname, $value=null, $op=null, $namespace=null) {            if (isset($namespace)) $namespace = substr($namespace, 0, -1);            $comp_str = ''; // used for extended if statements            // work out what to put on the end id value="whatever" is used            if (isset($value)) {                // add the correct operator depending on whether it's been specified or not                if (!empty($op)) {                    if (in_array($op, $this->allowed_if_ops)) {                        $comp_str .= $op;                    }                    else {                        vlibTemplateError::raiseError('VT_WARNING_INVALID_IF_OP', WARNING, $op);                    }                }                else {                    $comp_str .= '==';                }                // now we add the value, if it's numeric, then we leave the quotes off                if (is_numeric($value)) {                    $comp_str .= $value;                }                else {                    $comp_str .= '\''.$value.'\'';                }            }            if (count($this->_namespace) == 0 || $namespace == 'global') return '$this->_vars[\''.$varname.'\']'.$comp_str;            $retstr = '$this->_arrvars';            $numnamespaces = count($this->_namespace);            for ($i=0; $i < $numnamespaces; $i++) {                if ($this->_namespace[$i] == $namespace || (($i + 1) == $numnamespaces && !empty($namespace))) {                    $retstr .= "['".$namespace."'][\$_".$i."]";                    break 1;                }                else {                    $retstr .= "['".$this->_namespace[$i]."'][\$_".$i."]";                }            }            if ($this->OPTIONS['GLOBAL_VARS'] && empty($namespace)) {                return '(('.$retstr.'[\''.$varname.'\'] !== null) ? '.$retstr.'[\''.$varname.'\'] : $this->_vars[\''.$varname.'\'])'.$comp_str;            }            else {                return $retstr."['".$varname."']".$comp_str;            }        }        /**         * FUNCTION: _parseLoop         * returns a string used for parsing in tmpl_loop statements.         *         * @param string $varname         * @access private         * @return string used for eval'ing         */        function _parseLoop ($varname) {            array_push($this->_namespace, $varname);            $tempvar = count($this->_namespace) - 1;            $retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < count(\$this->_arrvars";            for ($i=0; $i < count($this->_namespace); $i++) {

⌨️ 快捷键说明

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