class_editor.php
来自「sabreipb 2.1.6 utf-8中文版本!」· PHP 代码 · 共 404 行
PHP
404 行
<?php/*+--------------------------------------------------------------------------| Invision Power Board v2.1.5| =============================================| by Matthew Mecham| (c) 2001 - 2005 Invision Power Services, Inc.| | =============================================| Web: | Time: Wed, 01 Mar 2006 19:11:28 GMT| Release: | Licence Info: +---------------------------------------------------------------------------| > $Date: 2005-10-24 22:17:00 +0100 (Mon, 24 Oct 2005) $| > $Revision: 64 $| > $Author: bfarber $+---------------------------------------------------------------------------|| > Posting Editor| > Module written by Matt Mecham| > Date started: Thursday 10th March 2005 11:08|+--------------------------------------------------------------------------*//*** Text Editor Main Class** This class contains all the main class functions* EXAMPLE USAGE* <code>* $han_editor = new han_editor();* $han_editor->ipsclass =& $this->ipsclass;* $han_editor->init();* * # To generate the HTML for the editor:* $editor_html = $han_editor->show_editor( $raw_post, 'Post' );* * # $raw_post is either raw HTML for the rich text editor or raw BBCode tagged text when* # using the standard editor. (See the document on the BBCode parser for more information)* # 'Post' is the name of the form field you wish use. In this case it'll return $_POST['Post'].* * #To process the editor's text into tagged BBCode text:* $post = $han_editor->process_raw_post( 'Post' );* * #'Post' is the name of the form field you used when displaying the editor. As in $_POST['Post']* * # To use the HTML generated by editor class for displaying the actual editor (in our example; $editor_html)* # you'll need to use it like this:* * <form id='postingform' onsubmit='return ValidateForm()' action="$url" method="post" name="REPLIER">* {$editor_html}* <br /><input type="submit" value="Post" /></div>* </form>* * The form tag MUST have: id='postingform' onsubmit='return ValidateForm()' otherwise the editor will fail.* </code>** @package InvisionPowerBoard* @subpackage TextEditor* @author Matt Mecham* @copyright Invision Power Services, Inc.* @version 2.1*//****//*** Text Editor Main Class** Main object class** @package InvisionPowerBoard* @subpackage TextEditor* @author Matt Mecham* @version 2.1* @since 2.1.0*/class class_editor{ /** * Main IPS class object * * @var object */ var $ipsclass; /** * Allow unicode setting * * @var integer */ var $allow_unicode; /** * Get magic quotes * * @var integer */ var $get_magic_quotes; /** * Reverse font sizes * * @var array */ var $rev_font_sizes = array(); /** * Main font sizes * * @var array */ var $font_sizes = array( 1 => 8, 2 => 10, 3 => 12, 4 => 14, 5 => 18, 6 => 24, 7 => 36 ); /*-------------------------------------------------------------------------*/ // Main init /*-------------------------------------------------------------------------*/ /** * Main init: Prep font sizes * * @return void */ function main_init( ) { //------------------------------- // Remap font sizes //------------------------------- foreach( $this->font_sizes as $bbcode => $real ) { $this->rev_font_sizes[ $real ] = $bbcode; } } /*-------------------------------------------------------------------------*/ // Get real font size /*-------------------------------------------------------------------------*/ /** * Get BBCode font size from real PX size * * @param integer PX Size * @return integer BBCode size */ function convert_realsize_to_bbsize( $real ) { $real = intval( $real ); if ( $this->rev_font_sizes[ $real ] ) { return $this->rev_font_sizes[ $real ]; } else { return 3; } } /*-------------------------------------------------------------------------*/ // unhtml smilie emoid: Replaces < and > to ascii as < is < upon smilie // save from ACP, so we don't want to use that. /*-------------------------------------------------------------------------*/ /** * unhtml smilie emoid: Replaces < and > to ascii as < is < upon smilie * save from ACP, so we don't want to use that. * * @param string Raw text * @return string Converted text */ function unhtml_emoid( $emoid ) { $emoid = stripslashes( $emoid ); $emoid = str_replace( '<', '<', $emoid ); $emoid = str_replace( '>', '>', $emoid ); return $emoid; } /*-------------------------------------------------------------------------*/ // html smilie emoid: Opposite of unhtml_emoid /*-------------------------------------------------------------------------*/ /** * html smilie emoid: Opposite of unhtml_emoid * * @param string Raw text * @return string Converted text */ function html_emoid( $emoid ) { $emoid = stripslashes( $emoid ); $emoid = str_replace( '<', '<', $emoid ); $emoid = str_replace( '>', '>', $emoid ); $emoid = str_replace( '"', '-', $emoid ); return $emoid; } /*-------------------------------------------------------------------------*/ // unhtml url: Removes < and > /*-------------------------------------------------------------------------*/ /** * unhtml url: Removes < and > * * @param string Type (IMG / A HREF) * @param string URL * @return string Converted text */ function unhtml_url( $type='a href', $url='' ) { $url = stripslashes( $url ); $type = stripslashes( $type ); $url = str_replace( '<', '<', $url ); $url = str_replace( '>', '>', $url ); $url = str_replace( ' ', '%20' , $url ); return $type.'="'.$url.'"'; } /*-------------------------------------------------------------------------*/ // make_rtf_safe: Formats HTML to make safe for preloading RTE /*-------------------------------------------------------------------------*/ /** * Converts color:rgb(x,x,x) to color:#xxxxxx * * @param string rgb contents: x,x,x * @param string regex end * @return string Converted text */ function _rgb_to_hex($t, $t2) { $tmp = array_map( "trim", explode( ",", $t ) ); //print sprintf("#%02X%02X%02X".$t2, intval($tmp[0]), intval($tmp[1]), intval($tmp[2]) ); return sprintf("#%02X%02X%02X".$t2, intval($tmp[0]), intval($tmp[1]), intval($tmp[2]) ); } /*-------------------------------------------------------------------------*/ // make_rtf_safe: Formats HTML to make safe for preloading RTE /*-------------------------------------------------------------------------*/ /** * make_rtf_safe: Formats HTML to make safe for preloading RTE * * @param string Raw text * @return string Converted text */ function _make_rtf_safe($t) { $t = trim($t); //------------------------------- // Convert all types of single quotes //------------------------------- if ( strtolower($this->ipsclass->vars['gb_char_set']) != 'utf-8' ) { $t = str_replace(chr(145), chr(39), $t); $t = str_replace(chr(146), chr(39), $t); } $t = str_replace("'" , "'", $t); //------------------------------- // Convert all types of double quotes //------------------------------- if ( strtolower($this->ipsclass->vars['gb_char_set']) != 'utf-8' ) { $t = str_replace(chr(147), chr(34), $t); $t = str_replace(chr(148), chr(34), $t); } //------------------------------- // Replace carriage returns & line feeds //------------------------------- $t = str_replace(chr(10), " ", $t); $t = str_replace(chr(13), " ", $t); return $t; } /*-------------------------------------------------------------------------*/ // Clean up IPB html /*-------------------------------------------------------------------------*/ /** * Clean up IPB html * * @param string Raw text * @return string Converted text */ function _clean_ipb_html( $t="" ) { //----------------------------------------- // Remove all comments //----------------------------------------- $t = preg_replace( "#\<\!\-\-(.+?)\-\-\>#is", "", $t ); $t = str_replace( ''' , "'", $t ); $t = str_replace( ''' , "'", $t ); $t = str_replace( '!' , "!", $t ); //----------------------------------------- // left, right, center //----------------------------------------- $t = preg_replace( "#\[(left|right|center)\](.+?)\[/\\1\]#is" , "<div align=\"\\1\">\\2</div>", $t ); //----------------------------------------- // Indent => Block quote //----------------------------------------- while( preg_match( "#\[indent\](.+?)\[/indent\]#is" , $t ) ) { $t = preg_replace( "#\[indent\](.+?)\[/indent\]#is" , "<blockquote>\\1</blockquote>", $t ); } return $t; } /*-------------------------------------------------------------------------*/ // Clean up and make the post safe for the DB /*-------------------------------------------------------------------------*/ /** * Clean up and make the post safe for the DB * * @param string Raw text * @return string Converted text */ function _clean_post( $t ) { if ( $t == "" ) { return ""; } //----------------------------------------- // Make it safe //----------------------------------------- $t = str_replace( "&" , "&" , $t ); $t = str_replace( "<!--" , "<!--" , $t ); $t = str_replace( "-->" , "-->" , $t ); $t = preg_replace( "/<script/i" , "<script" , $t ); $t = str_replace( ">" , ">" , $t ); $t = str_replace( "<" , "<" , $t ); $t = str_replace( '"' , """ , $t ); $t = preg_replace( "/\n/" , "<br />" , $t ); $t = preg_replace( "/\\\$/" , "$" , $t ); $t = preg_replace( "/\r/" , "" , $t ); $t = str_replace( "!" , "!" , $t ); $t = str_replace( "'" , "'" , $t ); //----------------------------------------- // Ensure unicode chars are OK //----------------------------------------- if ( $this->allow_unicode ) { $t = preg_replace("/&#([0-9]+);/s", "&#\\1;", $t ); } //----------------------------------------- // Strip slashes if not already done so. //----------------------------------------- if ( $this->get_magic_quotes ) { $t = stripslashes($t); } //----------------------------------------- // Swap user inputted backslashes //----------------------------------------- $t = preg_replace( "/\\\(?!&#|\?#)/", "\", $t ); return $t; } }?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?