421 lines
11 KiB
PHP
421 lines
11 KiB
PHP
<?php
|
|
|
|
/*
|
|
+--------------------------------------------------------------------------
|
|
| Invision Power Board 2.2.2
|
|
| =============================================
|
|
| by Matthew Mecham
|
|
| (c) 2001 - 2006 Invision Power Services, Inc.
|
|
| http://www.invisionpower.com
|
|
| =============================================
|
|
| Web: http://www.invisionboard.com
|
|
| http://www.ibresource.ru/products/invisionpowerboard/
|
|
| Time: Monday 05th of March 2007 10:10:54 PM
|
|
| Release: e3790216629e5a2aaf37070b32237f06
|
|
| Licence Info: http://www.invisionboard.com/?license
|
|
| http://www.ibresource.ru/license
|
|
+---------------------------------------------------------------------------
|
|
| INVISION POWER BOARD IS NOT FREE / OPEN SOURCE!
|
|
+---------------------------------------------------------------------------
|
|
| INVISION POWER BOARD ÍÅ ßÂËßÅÒÑß ÁÅÑÏËÀÒÍÛÌ ÏÐÎÃÐÀÌÌÍÛÌ ÎÁÅÑÏÅ×ÅÍÈÅÌ!
|
|
| Ïðàâà íà ÏÎ ïðèíàäëåæàò Invision Power Services
|
|
| Ïðàâà íà ïåðåâîä IBResource (http://www.ibresource.ru)
|
|
+---------------------------------------------------------------------------
|
|
| > $Date: 2006-10-31 05:08:21 -0600 (Tue, 31 Oct 2006) $
|
|
| > $Revision: 686 $
|
|
| > $Author: matt $
|
|
+---------------------------------------------------------------------------
|
|
|
|
|
| > 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
|
|
*/
|
|
|
|
if ( ! defined( 'IN_IPB' ) )
|
|
{
|
|
print "<h1>Íåêîððåêòíûé àäðåñ</h1>Âû íå èìååòå äîñòóïà ê ýòîìó ôàéëó íàïðÿìóþ. Åñëè âû íåäàâíî îáíîâëÿëè ôîðóì, âû äîëæíû îáíîâèòü âñå ñîîòâåòñòâóþùèå ôàéëû.";
|
|
exit();
|
|
}
|
|
|
|
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( $matches=array() )
|
|
{
|
|
$emoid = stripslashes( $matches[2] );
|
|
|
|
$emoid = str_replace( '<', '<', $emoid );
|
|
$emoid = str_replace( '>', '>', $emoid );
|
|
|
|
return 'emoid="' . $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( $matches=array() )
|
|
{
|
|
$emoid = stripslashes( $matches[2] );
|
|
|
|
$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( $matches=array() )
|
|
{
|
|
$url = stripslashes( $matches[3] );
|
|
$type = stripslashes( $matches[1] ? $matches[1] : 'a href' );
|
|
|
|
$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)
|
|
{
|
|
$t = $matches[1];
|
|
$t2 = $matches[2];
|
|
|
|
$tmp = array_map( "trim", explode( ",", $t ) );
|
|
return 'color: ' . 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;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
?>
|