📄 tidy.php
字号:
<?php /** This PHP file is intended for use with XMLHTTPRequest from an HTMLArea * it requrns javascript to set the htmlarea html with tidied html that is * submitted in a $_POST parameter called 'content' */ if(get_magic_quotes_gpc()) { // trigger_error('Magic Quotes GPC is on, cleaning GPC.', E_USER_NOTICE); $to_clean = array(&$_GET, &$_POST, &$_REQUEST, &$_COOKIE); while(count($to_clean)) { $cleaning =& $to_clean[array_pop(array_keys($to_clean))]; unset($to_clean[array_pop(array_keys($to_clean))]); foreach(array_keys($cleaning) as $k) { if(is_array($cleaning[$k])) { $to_clean[] =& $cleaning[$k]; } else { $cleaning[$k] = stripslashes($cleaning[$k]); } } } } /** Function to POST some data to a URL */ function PostIt($DataStream, $URL) {// Strip http:// from the URL if present $URL = ereg_replace("^http://", "", $URL);// Separate into Host and URI $Host = substr($URL, 0, strpos($URL, "/")); $URI = strstr($URL, "/");// Form up the request body $ReqBody = ""; while (list($key, $val) = each($DataStream)) { if ($ReqBody) $ReqBody.= "&"; $ReqBody.= $key."=".urlencode($val); } $ContentLength = strlen($ReqBody);// Generate the request header $ReqHeader = "POST $URI HTTP/1.0\n". "Host: $Host\n". "User-Agent: PostIt\n". "Content-Type: application/x-www-form-urlencoded\n". "Content-Length: $ContentLength\n\n". "$ReqBody\n";// echo $ReqHeader;// Open the connection to the host $socket = fsockopen($Host, 80, &$errno, &$errstr); if (!$socket) { $result = "($errno) $errstr"; return $Result; } fputs($socket, $ReqHeader); $result = ''; while(!feof($socket)) { $result .= fgets($socket); } return $result; } function js_encode($string) { static $strings = "\\,\",',%,&,<,>,{,},@,\n,\r"; if(!is_array($strings)) { $tr = array(); foreach(explode(',', $strings) as $chr) { $tr[$chr] = sprintf('\x%02X', ord($chr)); } $strings = $tr; } return strtr($string, $strings); } // Any errors would screq up our javascript error_reporting(E_NONE); ini_set('display_errors', false); if(trim(@$_REQUEST['content'])) { ob_start(); passthru("echo " . escapeshellarg($_REQUEST['content']) . " | tidy -q -i -wrap 9999 2>/dev/null", $result); $content = ob_get_contents(); ob_end_clean(); if(!strlen($content)) { // Tidy on the local machine failed, try a post $res_1 = PostIt( array ( '_function' => 'tidy', '_html' => $_REQUEST['content'], 'char-encoding' => 'utf8', '_output' => 'warn', 'indent' => 'auto', 'wrap' => 9999, 'break-before-br' => 'y', 'bare' => 'n', 'word-2000' => 'n', 'drop-empty-paras' => 'y', 'drop-font-tags' => 'n', ), 'http://infohound.net/tidy/tidy.pl'); if(preg_match('/<a href="([^"]+)" title="Save the tidied HTML/', $res_1, $m)) { $tgt = strtr($m[1], array_flip(get_html_translation_table(HTML_ENTITIES))); $content = implode('', file('http://infohound.net/tidy/' . $tgt)); } } if(strlen($content) && ! preg_match('/<\/body>/i', $_REQUEST['content'])) { if( preg_match('/<body[^>]*>(.*)<\/body>/is', $content, $matches) ) { $content = $matches[1]; } } elseif(!strlen($content)) { $content = $_REQUEST['content']; } if($content) { ?> editor.setHTML('<?php echo js_encode($content) ?>'); <?php } else { ?> alert(SuperClean.I18N.failed); <?php } } else { ?> alert(SuperClean.I18N.nothingtodo); <?php }?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -