HEX
Server: Apache/2.4.59 (Debian)
System: Linux skycube.cz 4.19.0-25-amd64 #1 SMP Debian 4.19.289-2 (2023-08-08) x86_64
User: ilya (534)
PHP: 7.3.31-1~deb10u7
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /var/www/ilya/data/www/kamforum.ru/sources/classes/editor/class_editor.php
<?php

/*
+--------------------------------------------------------------------------
|   Invision Power Board v2.1.5
|   =============================================
|   by Matthew Mecham
|   (c) 2001 - 2005 Invision Power Services, Inc.
|   http://www.invisionpower.com
|   =============================================
|   Web: http://www.invisionboard.com
|   Time: Tue, 18 Oct 2005 19:30:11 GMT
|   Release: 95f5a3c9ea538e4ebb097b9464fc22d2
|   Licence Info: http://www.invisionboard.com/?license
+---------------------------------------------------------------------------
|   > $Date: 2005-10-10 14:03:20 +0100 (Mon, 10 Oct 2005) $
|   > $Revision: 22 $
|   > $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
*/
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 &lt; upon smilie
	// save from ACP, so we don't want to use that.
	/*-------------------------------------------------------------------------*/
	
	/**
	* unhtml smilie emoid: Replaces < and > to ascii as < is &lt; 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( '<', '&#60;', $emoid );
		$emoid  = str_replace( '>', '&#62;', $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( '&#60;', '<', $emoid );
		$emoid  = str_replace( '&#62;', '>', $emoid );
		$emoid  = str_replace( '&quot;', '-', $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( '<', '&lt;', $url );
		$url  = str_replace( '>', '&gt;', $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("'"     , "&#39;", $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( '&#39;'  , "'", $t );
		$t = str_replace( '&#039;' , "'", $t );
		$t = str_replace( '&#33;'  , "!", $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( "&"            , "&amp;"         , $t );
    	$t = str_replace( "<!--"         , "&#60;&#33;--"  , $t );
    	$t = str_replace( "-->"          , "--&#62;"       , $t );
    	$t = preg_replace( "/<script/i"  , "&#60;script"   , $t );
    	$t = str_replace( ">"            , "&gt;"          , $t );
    	$t = str_replace( "<"            , "&lt;"          , $t );
    	$t = str_replace( '"'            , "&quot;"        , $t );
    	$t = preg_replace( "/\n/"        , "<br />"        , $t );
    	$t = preg_replace( "/\\\$/"      , "&#036;"        , $t );
    	$t = preg_replace( "/\r/"        , ""              , $t );
    	$t = str_replace( "!"            , "&#33;"         , $t );
    	$t = str_replace( "'"            , "&#39;"         , $t );
    	
    	//-----------------------------------------
    	// Ensure unicode chars are OK
    	//-----------------------------------------
    	
    	if ( $this->allow_unicode )
		{
			$t = preg_replace("/&amp;#([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( "/\\\(?!&amp;#|\?#)/", "&#092;", $t ); 
    	
    	return $t;
    }
	
}


?>