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

📄 itx.php

📁 apache windows下的一款好
💻 PHP
📖 第 1 页 / 共 2 页
字号:
                reset($variables);
                while (list($k, $variable) = each($variables)) 
                    if ($variable == $placeholder) {
                        $found = $blockname;
                        break 2;
                    }

            }
            
        }
        
        return $found;
    } // end func placeholderExists
    
    /**
    * Checks the list of function calls in the template and calls their callback function.
    *
    * @access    public
    */
    function performCallback() {
    
        reset($this->functions);
        while (list($func_id, $function) = each($this->functions)) {
            
            if (isset($this->callback[$function["name"]])) {
            
                if ("" != $this->callback[$function["name"]]["object"])
                    $this->setFunctioncontent($func_id, 
                                              call_user_method( 
                                                                $this->callback[$function["name"]]["function"], 
                                                                $GLOBALS[$this->callback[$function["name"]]["object"]],
                                                                $function["args"]
                                                               )
                                                  );
                else
                    $this->setFunctioncontent(  $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
    * @access   public
    */
    function setFunctioncontent($functionID, $replacement) {
        
        $this->variableCache["__function" . $functionID . "__"] = $replacement;
        
    } // end func setFunctioncontent
    
    /**
    * Sets a callback function.
    * 
    * @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
    
    /**
    * 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 && $arg = $this->getValue($head, ",")) {
                $args[] = trim($arg);
                if ($arg == $head)                                     
                    break;
                $head = substr($head, strlen($arg) + 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();
        }
    } // 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("IntegratedTemplateExtension 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 IntegratedTemplateExtension
?>

⌨️ 快捷键说明

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