class_editor_rte.php
来自「sabreipb 2.1.6 utf-8中文版本!」· PHP 代码 · 共 1,216 行 · 第 1/3 页
PHP
1,216 行
<?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: 2006-01-30 18:53:19 +0000 (Mon, 30 Jan 2006) $| > $Revision: 127 $| > $Author: bfarber $+---------------------------------------------------------------------------|| > Posting RTE Editor| > Module written by Matt Mecham| > Date started: Thursday 10th March 2005 13:47|+--------------------------------------------------------------------------*//*** Text Editor: RTE (WYSIWYG) Class** Class for parsing RTE** @package InvisionPowerBoard* @subpackage TextEditor* @author Matt Mecham* @version 2.1* @since 2.1.0*//****//*** Text Editor: RTE (WYSIWYG) Class** Class for parsing RTE** @package InvisionPowerBoard* @subpackage TextEditor* @author Matt Mecham* @version 2.1* @since 2.1.0*/class class_editor_module extends class_editor{ /** * Main IPS class object * * @var object */ var $ipsclass; /** * Clean up HTML on save * * @var integer */ var $clean_on_save = 1; /** * Allow HTML * * @var integer */ var $allow_html = 0; /** * Debug level * * @var integer */ var $debug = 0; /** * Parsing array * * @var array */ var $delimiters = array( "'", '"' ); /** * Parsing array * * @var array */ var $non_delimiters = array( "=", ' ' ); /** * Start tags * * @var string */ var $start_tags; /** * End tags * * @var string */ var $end_tags; /** * Dunno, forgotten * * @var integer */ var $_called = 0; /*-------------------------------------------------------------------------*/ // Process the raw post with BBCode before showing in the form /*-------------------------------------------------------------------------*/ /** * Process the raw post with BBCode before showing in the form * * @param string Raw text * @return string Converted text */ function process_before_form( $t ) { //----------------------------------------- // Opening style attributes //----------------------------------------- $t = preg_replace( "#<!--sizeo:(.+?)-->(.+?)<!--/sizeo-->#" , '<font size="\\1">' , $t ); $t = preg_replace( "#<!--coloro:(.+?)-->(.+?)<!--/coloro-->#" , '<font color="\\1">' , $t ); $t = preg_replace( "#<!--fonto:(.+?)-->(.+?)<!--/fonto-->#" , '<font face="\\1">' , $t ); $t = preg_replace( "#<!--backgroundo:(.+?)-->(.+?)<!--/backgroundo-->#" , '<font background="\\1">' , $t ); //----------------------------------------- // Closing style attributes //----------------------------------------- $t = preg_replace( "#<!--sizec-->(.+?)<!--/sizec-->#" , "</font>" , $t ); $t = preg_replace( "#<!--colorc-->(.+?)<!--/colorc-->#" , "</font>" , $t ); $t = preg_replace( "#<!--fontc-->(.+?)<!--/fontc-->#" , "</font>" , $t ); $t = preg_replace( "#<!--backgroundc-->(.+?)<!--/backgroundc-->#", "</font>" , $t ); //----------------------------------------- // Remove comments //----------------------------------------- $t = preg_replace( "#\<\!\-\-(.+?)\-\-\>#is", "", $t ); //----------------------------------------- // Return //----------------------------------------- $t = $this->_make_rtf_safe( $t ); //----------------------------------------- // Clean up nbsp //----------------------------------------- # Doing so knocks out tabs //$t = str_replace( ' ', "\t", $t ); //$t = str_replace( ' ' , " ", $t ); return $t; } /*-------------------------------------------------------------------------*/ // Process the raw post with BBCode before saving /*-------------------------------------------------------------------------*/ /** * Process the raw post with BBCode before saving * * @param string Raw text * @return string Converted text */ function process_after_form( $form_field ) { return $this->_rte_html_to_bbcode( $this->ipsclass->txt_stripslashes($_POST[ $form_field ]) ); } /*-------------------------------------------------------------------------*/ // Covert RTE-HTML to BBCode /*-------------------------------------------------------------------------*/ /** * Covert RTE-HTML to BBCode * * @param string Raw text * @return string Converted text */ function _rte_html_to_bbcode( $t ) { if ( $this->debug ) { $ot = $t; } //----------------------------------------- // Fix up spaces //----------------------------------------- $t = str_replace( ' ', ' ', $t ); //----------------------------------------- // Gecko engine seems to put \r\n at edge // of iframe when wrapping? If so, add a // space or it'll get weird later //----------------------------------------- if ( $this->ipsclass->browser['browser'] == 'mozilla' OR $this->ipsclass->browser['browser'] == 'gecko' ) { $t = str_replace( "\r\n", " ", $t ); } else { $t = str_replace( "\r\n", "", $t ); } //----------------------------------------- // Clean up already encoded HTML //----------------------------------------- $t = str_replace( '"', '"', $t ); $t = str_replace( ''', "'", $t ); //----------------------------------------- // Fix up incorrectly nested urls / BBcode //----------------------------------------- $t = preg_replace( '#<a\s+?href=[\'"]([^>]+?)\[(.+?)[\'"](.+?)'.'>(.+?)\[\\2</a>#is', '<a href="\\1"\\3>\\4</a>[\\2', $t ); //----------------------------------------- // Make URLs safe (prevent tag stripping) //----------------------------------------- $t = preg_replace( '#<(a href|img src)=([\'"])([^>]+?)(\\3)#ise', "\$this->unhtml_url( '\\1', '\\3' )", $t ); //----------------------------------------- // Make EMOids safe (prevent tag stripping) //----------------------------------------- $t = preg_replace( '#(emoid=\")(.+?)(\")#ise', "'emoid=\"'.\$this->unhtml_emoid('\\2').'\"';", $t ); //----------------------------------------- // Remove tags we're not bothering with // with PHPs wonderful strip tags func //----------------------------------------- if ( ! $this->allow_html ) { $t = strip_tags( $t, '<h1><h2><h3><h4><h5><h6><font><span><div><br><p><img><a><li><ol><ul><b><strong><em><i><u><strike><blockquote>' ); } //----------------------------------------- // WYSI-Weirdness #0: BR tags to \n //----------------------------------------- $t = preg_replace( "#<br.*>#isU", "\n", $t ); //----------------------------------------- // WYSI-Weirdness #1: Named anchors //----------------------------------------- $t = preg_replace( "#<a\s+?name=.+?".">(.+?)</a>#is", "\\1", $t ); //----------------------------------------- // WYSI-Weirdness #1.5: Empty a hrefs //----------------------------------------- $t = preg_replace( "#<a\s+?href([^>]+)></a>#is" , "" , $t ); $t = preg_replace( "#<a\s+?href=(['\"])>\\1(.+?)</a>#is", "\\1", $t ); //----------------------------------------- // WYSI-Weirdness #1.6: Double linked links //----------------------------------------- $t = preg_replace( "#href=[\"']\w+://(%27|'|\"|")(.+?)\\1[\"']#is", "href=\"\\2\"", $t ); //----------------------------------------- // WYSI-Weirdness #2: Headline tags //----------------------------------------- $t = preg_replace( "#<(h[0-9])>(.+?)</\\1>#is", "\n[b]\\2[/b]\n", $t ); //----------------------------------------- // WYSI-Weirdness #2.5: Fix up smilies //----------------------------------------- # Legacy Fix: Old smilies $t = str_replace( 'emoid=":""' , 'emoid="{{:&quot;}}"', $t ); $t = str_replace( 'emoid=":-""', 'emoid="{{:-&quot;}}"', $t ); # Make EMO_DIR safe so the ^> regex works $t = str_replace( "<#EMO_DIR#>", "<#EMO_DIR>", $t ); # Parse... $t = preg_replace( "#[ ]?<([^>]+?)emoid=\"(.+?)\"([^>]+?)?".">[ ]?#ise", "' '.\$this->html_emoid('\\2').' '", $t ); # And convert it back again... $t = str_replace( "<#EMO_DIR>", "<#EMO_DIR#>", $t ); # Convert back $t = str_replace( "{{:&quot;}}" , ':"' , $t ); $t = str_replace( "{{:-&quot;}}", ':-"', $t ); //----------------------------------------- // WYSI-Weirdness #3: Image tags //----------------------------------------- $t = preg_replace( "#<img.+?src=[\"'](.+?)[\"']([^>]+?)?".">#is", "[img]\\1[/img]", $t ); //----------------------------------------- // WYSI-Weirdness #4: Linked URL tags //----------------------------------------- $t = preg_replace( "#\[url=(\"|'|")<a\s+?href=[\"'](.*)/??['\"]\\2/??</a>#is", "[url=\\1\\2", $t ); //----------------------------------------- // Now, recursively parse the other tags // to make sure we get the nested ones //----------------------------------------- $t = $this->_recurse_and_parse( 'b' , $t, "_parse_simple_tag", 'b' ); $t = $this->_recurse_and_parse( 'u' , $t, "_parse_simple_tag", 'u' ); $t = $this->_recurse_and_parse( 'strong' , $t, "_parse_simple_tag", 'b' ); $t = $this->_recurse_and_parse( 'i' , $t, "_parse_simple_tag", 'i' ); $t = $this->_recurse_and_parse( 'em' , $t, "_parse_simple_tag", 'i' ); $t = $this->_recurse_and_parse( 'strike' , $t, "_parse_simple_tag", 's' ); $t = $this->_recurse_and_parse( 'blockquote' , $t, "_parse_simple_tag", 'indent' ); //----------------------------------------- // More complex tags //----------------------------------------- $t = $this->_recurse_and_parse( 'a' , $t, "_parse_anchor_tag" ); $t = $this->_recurse_and_parse( 'font' , $t, "_parse_font_tag" ); $t = $this->_recurse_and_parse( 'div' , $t, "_parse_div_tag" ); $t = $this->_recurse_and_parse( 'span' , $t, "_parse_span_tag" ); $t = $this->_recurse_and_parse( 'p' , $t, "_parse_paragraph_tag" ); //----------------------------------------- // Lists //----------------------------------------- $t = $this->_recurse_and_parse( 'ol' , $t, "_parse_list_tag" ); $t = $this->_recurse_and_parse( 'ul' , $t, "_parse_list_tag" ); //----------------------------------------- // WYSI-Weirdness #6: Fix up para tags //----------------------------------------- $t = preg_replace( "#<p.*>#isU", "\n\n", $t ); //----------------------------------------- // WYSI-Weirdness #7: Random junk //----------------------------------------- $t = preg_replace( "#(<a>|</a>|</li>)#is", "", $t ); //----------------------------------------- // WYSI-Weirdness #8: Fix up list stuff //----------------------------------------- $t = preg_replace( '#<li>(.*)((?=<li>)|</li>)#is', '\\1', $t ); //----------------------------------------- // WYSI-Weirdness #9: Convert rest to HTML //----------------------------------------- $t = str_replace( '<' , '<', $t ); $t = str_replace( '>' , '>', $t ); $t = str_replace( '&', '&', $t ); $t = preg_replace( '#&(quot|lt|gt);#', '&\\1;', $t ); //----------------------------------------- // WYSI-Weirdness #10: Remove useless tags //----------------------------------------- while( preg_match( "#\[(url|img|b|u|i|s|email|list|indent|right|left|center)\]\[/\\1\]#is", $t ) ) { $t = preg_replace( "#\[(url|img|b|u|i|s|email|list|indent|right|left|center)\]\[/\\1\]#is", "", $t ); } //----------------------------------------- // Now call the santize routine to make // html and nasties safe. VITAL!! //----------------------------------------- $t = $this->_clean_post( $t ); //----------------------------------------- // Debug? //----------------------------------------- if ( $this->debug ) { print "<hr>"; print nl2br(htmlspecialchars($ot));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?