* Invision Power Services * IP.Board v3.3.4 * Editor Library: RTE (WYSIWYG) Class * Last Updated: $Date: 2012-06-12 10:14:49 -0400 (Tue, 12 Jun 2012) $ * * * @author $Author: bfarber $ * @copyright (c) 2001 - 2009 Invision Power Services, Inc. * @license http://www.invisionpower.com/company/standards.php#license * @package IP.Board * @link http://www.invisionpower.com * @since 9th March 2005 11:03 * @version $Revision: 10914 $ */ if ( ! defined( 'IN_IPB' ) ) { print "
' && substr( $content, -4 ) == '
' ) { return true; } return false; } /** * Auto save via ajax * @param string $content * @param string $autoSaveKey */ public function autoSave( $content, $autoSaveKey ) { /* Convert the data so it is safe to store and preview */ $content = IPSText::getTextClass('bbcode')->preEditParse( $this->_rteProcess( $content, IPS_EDITOR_NO_SANITIZE ) ); /* Pretty much just dump it in the DB */ $this->DB->replace( 'core_editor_autosave', array( 'eas_key' => $autoSaveKey, 'eas_member_id' => $this->memberData['member_id'], 'eas_app' => IPS_APP_COMPONENT, 'eas_section' => $this->request['module'] . '.' . $this->request['section'], 'eas_updated' => time(), 'eas_content' => $content ), array( 'eas_key' ) ); return true; } /** * Switch content from one mode t'other * * @param string Content * @param int Is RTE? */ public function switchContent( $content, $isRte ) { IPSText::getTextClass('bbcode')->parse_html = false; IPSText::getTextClass('bbcode')->parse_nl2br = 0; IPSText::getTextClass('bbcode')->parse_smilies = ( ! empty( $this->request['noSmilies'] ) ) ? false : true; IPSText::getTextClass('bbcode')->parse_bbcode = true; IPSText::getTextClass('bbcode')->parsing_section = 'topics'; /* Default state for ACP */ if ( IN_ACP && $this->getAllowHtml() === null ) { IPSText::getTextClass('bbcode')->parse_html = true; } if ( $isRte ) { $this->_isSwitchingFrom = 'std'; /* Assume RTE text has been sent in and we want BBCode */ $content = str_replace( '\\', '\', $content ); # Makes manually entered < safe if ( ! $this->getAllowHtml() ) { //IPSDebug::addLogMessage( $content, 'stdeditor', $_POST, true, true ); $content = $this->_rteProcess( $content, IPS_EDITOR_NO_SANITIZE ); //IPSDebug::addLogMessage( $content, 'stdeditor', false, true, false ); $content = IPSText::getTextClass('bbcode')->preEditParse( $content ); //IPSDebug::addLogMessage( $content, 'stdeditor', false, true, false ); $content = $this->_stdPreShow( $content ); //IPSDebug::addLogMessage( $content, 'stdeditor', false, true, false ); } $content = str_replace( '\', '\\', $content ); } else { $this->_isSwitchingFrom = 'rte'; /* Assume BBCode has been sent in and we want RTE */ if ( ! $this->getAllowHtml() ) { //IPSDebug::addLogMessage( $content, 'editor', $_POST, true, true ); $content = $this->_stdProcess( $content, IPS_EDITOR_NO_SANITIZE ); //IPSDebug::addLogMessage( $content, 'editor', false, true, false ); $content = IPSText::getTextClass('bbcode')->convertForRTE( $content ); //IPSDebug::addLogMessage( $content, 'editor', false, true, false ); $content = $this->_rtePreShow( $content, false, true ); //IPSDebug::addLogMessage( $content, 'editor', false, true, false ); } } $this->_isSwitchingFrom = null; return $content; } /** * Processes text ready for non RTE * * @access public * @param string Raw text * @return string Text ready for editor */ public function _stdPreShow( $t ) { $t = str_replace( array( "\r\n", "\r" ), "\n", $t ); IPSDebug::fireBug( 'info', array( 'Start (std): ' . nl2br($t) ) ); $t = IPSText::decodeNamedHtmlEntities( $t ); $t = str_replace( '!', '!', $t ); $t = str_replace( '"', '"', $t ); $t = str_replace( '"', '"', $t ); $t = str_replace( '<', '<', $t ); $t = str_replace( '>', '>', $t ); $t = str_replace( '<', '<', $t ); $t = str_replace( '>', '>', $t ); $t = str_replace( ''', "'", $t ); $t = str_replace( '$', "$", $t ); $t = str_replace( '$', "$", $t ); $t = str_replace( '\', '\\', $t ); $t = str_replace( '\', '\\', $t ); $t = str_replace( ' ', ' ', $t ); $t = str_replace( '[', '[', $t ); $t = str_replace( ']', ']', $t ); $t = str_replace( '{', '{', $t ); $t = str_replace( '}', '}', $t ); $t = str_replace( ' ', ' ', $t ); $t = str_replace( "\t" , ' ', $t ); /* We replace \ to 092 so convert it back */ $t = str_replace( '\', '\\', $t ); if ( ! IPS_IS_AJAX ) { $t = str_replace( '&', '&', $t ); } $t = str_replace( '_allowNonUtf8CharsWhenNotUsingUtf8Doc( $t ); /* Sect breaks on std editor @link http://community.invisionpower.com/tracker/issue-37498-gets-converted-into-sect%3B-when-editing-a-post/ */ $t = $this->_convertNumericEntityToNamed( $t ); /* We make paths safe in clean globals */ $t = str_replace( '../', '../', $t ); IPSDebug::fireBug( 'info', array( 'End (std): ' . nl2br($t) ) ); return $t; } /** * Processes text for RTE * * @access public * @param string Raw text * @param bool Double encode entities (not needed for switching, only for full editor) * @param bool Ajax request * @return string Text ready for editor */ public function _rtePreShow( $t, $encodeEntities=false ) { IPSDebug::fireBug( 'info', array( 'Start (rte): ' . nl2br($t) ) ); /* Trim and remove comments */ $t = preg_replace( '#\<\!\-\-(.+?)\-\-\>#is', "", $t ); $t = rtrim($t); /* Parsing can kill img URLs as they are made 'safe' to not parse */ $t = str_replace( 'http:', 'http:', $t ); /* Convert single/double quotes */ if ( strtolower(IPS_DOC_CHAR_SET) != 'utf-8' ) { $t = str_replace(chr(145), chr(39), $t); $t = str_replace(chr(146), chr(39), $t); $t = str_replace(chr(147), chr(34), $t); $t = str_replace(chr(148), chr(34), $t); } $t = str_replace( "\t", "{'tab'}", $t ); /* Remove CR/LF */ $t = str_replace(chr(10), "", $t); $t = str_replace(chr(13), "", $t); /* Fix some entities to display correctly */ $t = str_replace( array( '(\s+?)?
* @link http://www.php.net/manual/en/function.nl2br.php#97643 * @author James bandit.co dot nz * @param string $string */ protected function _convertBrToWrappedP( $string ) { return '
' . $string . '
'; /*return ''
. preg_replace('#(
\s*?){2,}#', '
', $string ) . '
'; */ } /** * Take content from STD and make safe * @param string $content * @return string */ protected function _stdProcess( $content, $NO_SANITIZE=false ) { $content = str_replace( array( "\r\n", "\r" ), "\n", $content ); $content = preg_replace( '#^([ ]+?)\n#m', "\n", $content ); /* We make paths safe in clean globals */ $content = str_replace( '../', '../', $content ); $content = trim( $this->_clean( $content, $NO_SANITIZE, false ) ); return $content; } /** * Process the content before passing off to the bbcode library * * @access public * @param string Form field name OR Raw text * @param boolean Does not run _clean() to santize HTML. Used when 'switching' editors via ajax * @return string Text ready for editor */ protected function _rteProcess( $content, $NO_SANITIZE=false ) { //----------------------------------------- // Save some processing if no content //----------------------------------------- if ( ! $content ) { return $content; } $ot = $content; $content = str_replace( array( "\r\n", "\n" ), "\n", $content ); /* Using P mode? CKEditor will send data like so *test
*More data
*(\s+?)?