javascript.php

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 562 行 · 第 1/2 页

PHP
562
字号
    /**     * Checks the output mode and acts according to it     *     * @param  string   $str the string returned from the calling function     * @return mixed    depends on the output mode,     *                  $str if it's HTML_JAVASCRIPT_OUTPUT_RETURN, true otherwise     * @access private     */    function _out($str)    {        static $fp;        if( isset($this) ){            $mode = $this->_mode;            $file = $this->_file;        } else {            return $str;        }        switch($mode) {            case HTML_JAVASCRIPT_OUTPUT_RETURN: {                return $str;                break;            }            case HTML_JAVASCRIPT_OUTPUT_ECHO: {                echo $str;                return true;                break;            }            case HTML_JAVASCRIPT_OUTPUT_FILE: {                $fp = fopen($file, 'ab');                fwrite($fp, $str);                return true;                break;            }            default: {                HTML_Javascript::raiseError('Invalid output mode');                break;            }        }    }    // }}} _out    // {{{ write    /**     * A wrapper for document.writeln     *     * @access public     * @param  string  $str the string to output     * @param  boolean $var set to true if $str is a variable name     * @return mixed   PEAR_Error if no script was started or the processed string     */    function write($str, $var = false)    {        if ($var) {            $ret = HTML_Javascript::_out(                    'document.writeln('.$str.')'.HTML_JAVASCRIPT_NL                    );        } else {            $ret = HTML_Javascript::_out(                        'document.writeln("'.                        HTML_Javascript_Convert::escapeString($str).'")'.                        HTML_JAVASCRIPT_NL                    );        }        return $ret;    }    // }}} write    // {{{ writeLine    /**     * A wrapper for document.writeln with an addtional <br /> tag     *     * @access public     * @param  string  $str the string to output     * @param  boolean $var set to true if $str is a variable name     * @return mixed   PEAR_Error if no script was started *     *                 or the processed string     */    function writeLine($str, $var = false)    {        if ($var) {            $ret = HTML_Javascript::_out(                    'document.writeln('.$str.'+"<br />")'.HTML_JAVASCRIPT_NL                    );        } else {            $ret = HTML_Javascript::_out(                        'document.writeln("'.                        HTML_Javascript_Convert::escapeString($str).                        '"+"<br />")'.HTML_JAVASCRIPT_NL                    );        }        return $ret;    }    // }}} writeLine    // {{{ alert    /**     * A wrapper for alert     *     * @access public     * @param  string    $str the string to output     * @param  boolean   $var set to true if $str is a variable name     * @return mixed     PEAR_Error if no script was started     *                   or the processed string     */    function alert($str, $var = false)    {        $alert  = 'alert(';        $alert  .= $var?                    $str:                    '"' . HTML_Javascript_Convert::escapeString($str) . '"';        $ret = HTML_Javascript::_out($alert.')'.HTML_JAVASCRIPT_NL);        return $ret;    }    // {{{ alert    // {{{ confirm    /**     * Create a box with yes and no buttons.     * In futur releases, the 1st arg will change, $str will always be the 1st     * argument, $assign the 2nd.     *     * @param  string $assign   the JS variable to assign the confirmation box to     * @param  string $str      the string that will appear in the confirmation box     * @param  bool   $var      whether $str is a JS var or not     * @return string the processed string     */    function confirm($assign, $str, $var = false)    {        if($var) {            $confirm = 'confirm(' . $str . ')' . HTML_JAVASCRIPT_NL;        } else {            $confirm = 'confirm("' .                HTML_Javascript_Convert::escapeString($str) . '")' .                HTML_JAVASCRIPT_NL;        }        $ret = HTML_Javascript::_out($assign . ' = ' . $confirm);        return $ret;    }    // }}} confirm    // {{{ prompt    /**     * Open a propmt (input box)     *     * @param  string $str     the string that will appear in the prompt     * @param  string $assign  the JS var that the input will be assigned to     * @param  string $default the default value     * @param  string $var     wether $str is a JS var or not     * @return mixed  PEAR_Error or the processed string     */    function prompt($str, $assign, $default = '', $var = false)    {        if ($var) {            $prompt = 'prompt('.$str.', "'.$default.')"'.HTML_JAVASCRIPT_NL;        } else {            $prompt = 'prompt("'.                        HTML_Javascript_Convert::escapeString($str).                        '", "'.$default.                        '")'.HTML_JAVASCRIPT_NL;        }        $ret = HTML_Javascript::_out($assign .' = ' . $prompt);        return $ret;    }    // }}} prompt    // {{{ popup    /**     * A method for easy generation of popup windows     *     * @param  string $assign   the JS var to assign the window to     * @param  string $file     the file that will appear in the new window     * @param  string $title    the title of the new window     * @param  int    $width    the width of the window     * @param  int    $height   the height of the window     * @param  mixed  $attr     an array containing the attributes for the new     *                          window, each cell can contain either the ints 1/0     *                          or the strings 'yes'/'no'.     *                          The order of attributes:     *                          resizable, scrollbars, menubar, toolbar,     *                          status, location.     *                          Can be also a boolean, and then all the attributes     *                          are set to yes or no, according to the boolean value.     * @param  int   $top       the distance from the top, in pixels.     * @param  int   $left      the distance from the left, in pixels.     * @return mixed PEAR_Error on error or the processed string.     */    function popup(        $assign, $file, $title, $width, $height, $attr, $top = 300, $left = 300    )    {        if(!is_array($attr)) {            if(!is_bool($attr)) {                PEAR::raiseError('$attr should be either an array or a boolean');            } else {                if($attr) {                    $attr = array('yes', 'yes', 'yes', 'yes', 'yes', 'yes', $top, $left);                } else {                    $attr = array('no', 'no', 'no', 'no', 'no', 'no', $top, $height);                }            }        }        $ret = HTML_Javascript::_out(                    $assign .                    "= window.open(".                    "\"$file\", \"$title\",".                    " \"width=$width, height=$height,".                    "resizable=$attr[0], scrollbars=$attr[1],".                    " menubar=$attr[2], toolbar=$attr[3], status=$attr[4],".                    " location=$attr[5], top=$attr[6], left=$attr[7]\")".                    HTML_JAVASCRIPT_NL);        return $ret;    }    // }}} popup    // {{{ popupWrite    /**     * Creates a new popup window containing a string. Inside the popup windows     * you can access the opener window with the opener var.     *     * @param  string $assign   the JS variable to assign the window to     * @param  string $str      the string that will appear in the new window     *                          (HTML tags would be parsed by the browser, of course)     * @param  string $title    the title of the window     * @param  int    $width    the width of the window     * @param  int    $height   the height of the window     * @param  mixed  $attr     see popup()     * @param  int    $top      distance from the top (in pixels     * @param  int    $left     distance from the left (in pixels)     * @see    popup()     * @return the processed string     */    function popupWrite(        $assign, $str, $title, $width, $height, $attr, $top = 300, $left = 300    )    {        static  $cnt_popup;        $str        = HTML_Javascript_Convert::escapeString($str);        $assign     = strlen($assign)==0?'pearpopup'.$cnt_popup++:$assign;        if($attr) {            $attr = array('yes', 'yes', 'yes', 'yes', 'yes', 'yes', $top, $left);        } else {            $attr = array('no', 'no', 'no', 'no', 'no', 'no', $top, $height);        }        $windows = $assign . "= window.open(\"\",".                                " \"$title\",".                                " \"width=$width, height=$height,".                                " resizable=$attr[0], scrollbars=$attr[1],".                                " menubar=$attr[2], toolbar=$attr[3],".                                " status=$attr[4], location=$attr[5],".                                " top=$attr[6], left=$attr[7]\")".HTML_JAVASCRIPT_NL;        $windows    .= "                        if ($assign){                            $assign.focus();                            $assign.document.open();                            $assign.document.write('$str');                            $assign.document.close();                            if ($assign.opener == null) $assign.opener = self;                        }                      ";        $ret = HTML_Javascript::_out($windows);        return $ret;    }    // }}} popupWrite}?>

⌨️ 快捷键说明

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