javascript.php
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 562 行 · 第 1/2 页
PHP
562 行
<?php/* vim: set expandtab tabstop=4 shiftwidth=4: */// +----------------------------------------------------------------------+// | PHP Version 4 |// +----------------------------------------------------------------------+// | Copyright (c) 1997-2003 The PHP Group |// +----------------------------------------------------------------------+// | This source file is subject to version 3.0 of the PHP license, |// | that is bundled with this package in the file LICENSE, and is |// | available at through the world-wide-web at |// | http://www.php.net/license/3_0.txt. |// | If you did not receive a copy of the PHP license and are unable to |// | obtain it through the world-wide-web, please send a note to |// | license@php.net so we can mail you a copy immediately. |// +----------------------------------------------------------------------+// | Authors: Tal Peer <tal@php.net> |// | Pierre-Alain Joye <paj@pearfr.org> |// +----------------------------------------------------------------------+// $Id: Javascript.php,v 1.32 2003/05/02 00:28:15 pajoye Exp $/** * A class for performing basic JavaScript operations * * Usage example: * <code> * echo "<html><head><title>JS Test</title></head><body>"; * $js = new HTML_Javascript(); * echo $js->startScript(); * echo $js->writeLine('foo',false); * echo $js->writeLine('bar[0]', true); * echo $js->writeLine('bar[3]', true); * echo $js->endScript(); * echo "</body></html>"; * </code> * TODO: * - Error handler * - Validation mechanism * - Rollovers * - Importation from external files * - Themed popups * * @author Tal Peer <tal@php.net> * @author Pierre-Alain Joye <paj@pearfr.org> * @version 1.1.3 * @package HTML_Javascript * @example examples/javascript.php Usage of HTML_Javascript * @licence http://www.php.net/license/3_0.txt PHP Licence 3.0 * @access public *///Error codes/** * No script started error */define('HTML_JAVASCRIPT_ERROR_NOSTART', 500, true);/** * Unknown error */define('HTML_JAVASCRIPT_ERROR_UNKNOWN', 599, true);/** * Last script was not ended error */define('HTML_JAVASCRIPT_ERROR_NOEND', 501, true);/** * No file was specified for setOutputMode() */define('HTML_JAVASCRIPT_ERROR_NOFILE', 505, true);//Output modes/** * Just return the results (default mode) */define('HTML_JAVASCRIPT_OUTPUT_RETURN', 1);/** * Echo (print) the results directly to browser */define('HTML_JAVASCRIPT_OUTPUT_ECHO', 2);/** * Print the results to a file */define('HTML_JAVASCRIPT_OUTPUT_FILE', 3);if(!defined('HTML_JAVASCRIPT_NL')){ /** Linefeed to use, default set to Unix linefeed. * Define it before the include/require if you want to * override it. */ define('HTML_JAVASCRIPT_NL', "\n");}/** Convertion tools */require_once('HTML/Javascript/Convert.php');/** * Main Javascript class * * Provides the basic function to output Javascript * scripts, like start and end tags or set the output mode. * @package HTML_Javascript */class HTML_Javascript{ /** * Used to determaine if a script has been started * * @var boolean $_started * @access private */ var $_started = false; /** * The output mode specified for the script * * @var integer $_mode * @access private */ var $_mode = HTML_JAVASCRIPT_OUTPUT_RETURN; /** * The file to direct the output to * * @var string $_file * @access private */ var $_file = ''; // {{{ HTML_Javascript /** * Constructor - creates a new HTML_Javascript object * * @access public */ function HTML_Javascript() { } // }}} HTML_Javascript // {{{ setOutputMode /** * Set the output mode for the script * * @param integer $mode the chosen output mode, can be either * {@link HTML_JAVASCRIPT_OUTPUT_RETURN}, * {@link HTML_JAVASCRIPT_OUTPUT_ECHO} or * {@link HTML_JAVASCRIPT_OUTPUT_FILE} * @param string $file the path to the file * (if $mode is {@link HTML_JAVASCRIPT_OUTPUT_FILE}) * @see getOutputMode * @access public * @return mixed PEAR_Error or true */ function setOutputMode($mode = HTML_JAVASCRIPT_OUTPUT_RETURN, $file = NULL) { if($mode == HTML_JAVASCRIPT_OUTPUT_FILE ) { if(isset($file)) { $this->_file = $file; } else { $this->raiseError(HTML_JAVASCRIPT_ERROR_NOFILE); } } $this->_mode = $mode; return true; } // }}} setOutputMode // {{{ setOutputMode /** * Get the output mode for the script * * @see setOutputMode * @access public * @return mixed PEAR_Error or true */ function getOutputMode() { return $this->_mode; } // }}} setOutputMode // {{{ raiseError /** * A custom error handler * * @access private * @param integer $code the error code * @return mixed false if the error code is invalid, * or a PEAR_Error otherwise */ function raiseError($code) { $ret = null; include_once('PEAR.php'); switch ($code) { case HTML_JAVASCRIPT_ERROR_NOSTART: $ret = PEAR::raiseError( 'No script started', HTML_JAVASCRIPT_ERROR_NOSTART ); break; case HTML_JAVASCRIPT_ERROR_NOEND: $ret = PEAR::raiseError( 'Last script was not ended', HTML_JAVASCRIPT_ERROR_NOEND ); break; case HTML_JAVASCRIPT_ERROR_NOFILE: $ret = PEAR::raiseError( 'A filename must be specified for setoutputMode()', HTML_JAVASCRIPT_ERROR_NOFILE ); break; default: return HTML_Javascript_Convert::raiseError( 'Unknown Error', HTML_JAVASCRIPT_ERROR_UNKNOWN ); break; } return $ret; } // }}} raiseError // {{{ startScript /** * Starts a new script * * @param bool $defer whether to wait for the whole page to load * before starting the script or no. Use defer only * with script that does not change the document (i.e. * alert does not change it). * * @access public * @return mixed a PEAR_Error if a script has been already started * or a string (HTML tag <script>) */ function startScript($defer = true) { $this->_started = true; $s = $defer ? 'defer="defer"' : ''; //$s = $defer ? 'defer' : ''; $ret = "<script type=\"text/javascript\" ".$s.">". HTML_JAVASCRIPT_NL; return $ret; } // }}} startScript // {{{ endScript /** * Used to end the script (</script>) * * @return mixed PEAR_Error if no script has been started * or the end tag for the script * @access public */ function endScript() { if ($this->_started) { $this->_started = false; $ret = "</script>".HTML_JAVASCRIPT_NL; } else { $ret = HTML_Javascript::raiseError(HTML_JAVASCRIPT_ERROR_NOSTART); } return $ret; } // }}} endScript //{{{ _out
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?