basic.php
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 465 行 · 第 1/2 页
PHP
465 行
<?php//// +----------------------------------------------------------------------+// | PHP Version 4 |// +----------------------------------------------------------------------+// | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group |// +----------------------------------------------------------------------+// | This source file is subject to version 2.02 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/2_02.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: Wolfram Kriesing <wolfram@kriesing.de> |// +----------------------------------------------------------------------+// $Id: Basic.php,v 1.20 2003/04/04 18:16:31 cain Exp $require_once 'HTML/Template/Xipe/Options.php';/*** the default filter(s) i use and Xipe needs** @package HTML_Template_Xipe* @access public* @version 01/12/10* @author Wolfram Kriesing <wolfram@kriesing.de>*/class HTML_Template_Xipe_Filter_Basic extends HTML_Template_Xipe_Options{// i need the method setOption, that's why i extend myPEAR_Common /** * for passing values to the class, i.e. like the delimiters * @access private * @var array $options the options for initializing the filter class */ var $options = array( 'delimiter' => array(), // first value of the array is the begin delimiter, second the end delimiter 'autoBraces' => true ); // we need to check this for some filters, since some depend on it or have to behave differently /** * apply (almost) all filters available in this class * thanks to hint from Alan Knowles * i am only applying those filters which i think are useful in mostly every case * i.e. applyHtmlEntites i am not applying since it would convert every output to html * and that is not desired in every case * * @version 02/05/22 * @author Wolfram Kriesing <wolfram@kriesing.de> * @param string the actual input string, to which the filters will be applied * @param int the filter level * @return string the resulting string */ function allPrefilters( $input , $filterLevel ) { if( $filterLevel > 8 ) // see Main.php for what the filter levels are supposed to do { $input = $this->removeHtmlComments($input); $input = $this->removeCStyleComments($input); } $input = $this->decodeHtmlEntities($input); $input = $this->addIfBeforeForeach($input); $input = $this->escapeShortTags($input); return $input; } /** * see allPrefilters() * * @see allPrefilters() * @version 02/05/22 * @author Wolfram Kriesing <wolfram@kriesing.de> * @param string the actual input string, to which the filters will be applied * @param int the filter level * @return string the resulting string */ function allPostfilters( $input , $filterLevel ) { if( $filterLevel > 9 ) // see Main.php for what the filter levels are supposed to do { $input = $this->removeEmptyLines($input); $input = $this->trimLines($input); $input = $this->optimizeHtmlCode($input); } // this is default since, it enables you to also use 'switch case' blocks // if we wouldnt optimize the php here then there would be spaces printed between switch and case // which php doesnt allow! (only with autoBraces of course) // i.e. {switch($which)} ....those spaces here bother php... // {case 'this':} // // and its better to optimize it always anyway! $input = $this->optimizePhpTags($input); return $input; } /** * remove unnecessary php-tags, looks for ? > only spaces here < ?php and merges them * but watch out might be dangerous, since it also does that on < ?= * better dont use it as it is if u are not 100% sure it will work (u were warned :-) ) * * @version 01/12/07 * @author Wolfram Kriesing <wolfram@kriesing.de> * @param string $input the original template code * @return string the modified template */ function optimizePhpTags($input) { // replace ' } ? > <spaces> < ?php' by '}' AND // replace ' { ? > <spaces> < ?php' by '}' // since the big number of php tags only takes up a lot of parsing by php // NOTE: the space before the $1 is important, since PHP freaks out with '< ?php}' it needs '< ?php }' $input = preg_replace( '/\s*({|})(\s*)\?>(\s*)<\?php/U' , ' $1' , $input ); //" return $input; } /** * removes HTML comments, use as preFilter * * @version 01/12/07 * @author Wolfram Kriesing <wolfram@kriesing.de> * @param string $input the original template code * @return string the modified template */ function removeHtmlComments($input) { return preg_replace('/<!--.*-->/Us','',$input); //worked until now, that i had nested html comments, not cool, but may happen when using {%include ...%}// gotta live with that for now :-( see manual, recursive patterns/* return preg_replace('/<!--((?>[^(<!--)(-->)])|(?R))*-->/Usx','',$input);*/ } /** * removes C-style comments, use as preFilter * but dont remove it if it is inside an html/xml tag <...> * and dont remove it when there is a colon in front, like for a url * * @version 01/12/07 * @author Wolfram Kriesing <wolfram@kriesing.de> * @param string $input the original template code * @return string the modified template */ function removeCStyleComments($input) {/* $input = preg_replace( '/\/\/.+\n/U',"\n",$input); // remove '//' but only on one lineremoves <!DOCTYPE ... //W3C// > too :-( $input = preg_replace( '/(([^<].+)'. // dont remove lines where double slashes are inside a html/xml tag <..> '|([^:]))'. // dont remove if there is a colon in front of the //, this is a url '\/\/.+'. // find the actual // '(.+[^>])'. // that checks for the closing > '\n/U',"\n",$input); // remove '//' but only on one lineremoves the entire line if there is a // also only at the end doesnt work properly on this ...<script> // fuck comment ftp://fuckyou.com http://fuckyou.com</script>http://fuck it<a href="http://www.home.de">home</a>http://dhsfskbut this works:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><a href="http://www.home.de">home</a>*/ // remove // commments when they are at the beginning of the line or if there are only spaces before $input = preg_replace('~^\s*//.*$~Um','',$input); // watch out, that weird strings, like reg-exps dont fuck this up! $input = preg_replace('~/\*.+\*/~Us','',$input); // remove /* */ on multiple lines too return $input; } /** * removes empty lines, leave indention as they are (i need this filter in autoBrace as it is!!!) * * @version 01/12/09 * @author Wolfram Kriesing <wolfram@kriesing.de> * @param string $input the original template code * @return string the modified template */ function removeEmptyLines($input) { return preg_replace('/\n\s*\n/s',"\n",$input); } /** * removes trailing spaces from lines * use only as a POST-filter, if you are using 'autoBrace', since it needs the indention * * @version 01/12/09 * @author Wolfram Kriesing <wolfram@kriesing.de> * @param string $input the original template code * @return string the modified template */ function trimLines($input) { return preg_replace('/\n\s*/s',"\n",$input); } /** * concatenates HTML tags which are spread over many lines * removes spaces inbetween a > and a < * removes new lines before > and /> * use only as a POST-filter, if you are using 'autoBrace', since it needs the indention * * @version 01/12/16 * @author Wolfram Kriesing <wolfram@kriesing.de> * @param string $input the original template code * @return string the modified template */ function optimizeHtmlCode($input) {// all those in here are in use, but not tested all the way, i.e. what happens with compares in JS/PHP using < or >" // make lines at least 100 characters long// dont know hoe yet...// $input = preg_replace('/((.*)\n(.*)){100,}/Us','$2 $3',$input); // removes new lines before > and /> // this only works for tags where there are no PHP tags inside :-( $input = preg_replace('/\n([\/>])/U','$1',$input); // concatenates HTML tags which are spread over many lines, // and replace spaces which are before and after the new line by one space only // this only works for tags where there are no PHP tags inside :-( $input = preg_replace('/<(.*)\n(.*)>/U','<$1 $2>',$input);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?