Ticket #232 (new New Feature)
New code for PHP classe of FCKeditor
| Reported by: | inazo | Owned by: | |
|---|---|---|---|
| Priority: | Normal | Milestone: | |
| Component: | Server : PHP | Version: | FCKeditor 2.4 |
| Keywords: | Confirmed HasPatch | Cc: |
Description
Hello,
This ticket is here, for propose a new version of classe for PHP 5.x. This new classe using singleton, less ressource asked, and an implementation more easy in our script file.
We can to speak about it with that ticket and check how to ameliorate it.
The new code :
<?php
/*
* FCKeditor - The text editor for internet
* Copyright (C) 2003-2006 Frederico Caldeira Knabben
*
* Licensed under the terms of the GNU Lesser General Public License:
* http://www.opensource.org/licenses/lgpl-license.php
*
* For further information visit:
* http://www.fckeditor.net/
*
* "Support Open Source software. What about a donation today?"
*
* File Name: fckeditor.php
* This is the integration file for PHP.
*
* It defines the FCKeditor class that can be used to create editor
* instances in PHP pages on server side.
*
* File Authors:
* Frederico Caldeira Knabben (fredck@fckeditor.net)
* Modification Authors :
* Alexandre Joly (webmaster@game-anime.com)
* Modification description : Using Singleton
* For PHP > 5.x
*/
class FCKeditor
{
private static $Config ;
private function __construct(){}
static function CreateHtml($InstanceName, $BasePath='/fckeditor/', $ToolbarSet = 'Default', $Value = '', $Width = '100%', $Height = '200')
{
self::$Config = array();
$HtmlValue = htmlspecialchars( $Value ) ;
$Html = '<div>' ;
if ( self::IsCompatible() )
{
if ( isset( $_GET['fcksource'] ) && $_GET['fcksource'] == "true" )
$File = 'fckeditor.original.html' ;
else
$File = 'fckeditor.html' ;
$Link = $BasePath.'editor/'.$File.'?InstanceName='.$InstanceName;
if ( $ToolbarSet != '' )
$Link .= '&Toolbar='.$ToolbarSet;
/*
* First field : Render the linked hidden field.
* Seconde field : Render the configurations hidden field.
* Third field : Render the editor IFRAME.
*/
$Html .=
'<input type="hidden" id="'.$InstanceName.'" name="'.$InstanceName.'" value="'.$HtmlValue.'" style="display:none" />
<input type="hidden" id="'.$InstanceName.'___Config" value="" '.self::GetConfigFieldString().' style="display:none" />
<iframe id="'.$InstanceName.'___Frame" src="'.$Link.'" width="'.$Width.'" height="'.$Height.'" frameborder="0" scrolling="no"></iframe>';
}
else
{
if ( strpos( $Width, '%' ) === false )
$WidthCSS = $Width . 'px' ;
else
$WidthCSS = $Width ;
if ( strpos( $Height, '%' ) === false )
$HeightCSS = $Height . 'px' ;
else
$HeightCSS = $Height ;
$Html .= '<textarea name="'.$InstanceName.'" rows="4" cols="40" style="width: '.$WidthCSS.'; height: '.$HeightCSS.';">'.$HtmlValue.'</textarea>';
}
$Html .= '</div>' ;
return $Html ;
}
private static function IsCompatible()
{
$sAgent = $_SERVER['HTTP_USER_AGENT'] ;
if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false )
{
$iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3) ;
return ($iVersion >= 5.5) ;
}
else if ( strpos($sAgent, 'Gecko/') !== false )
{
$iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ;
return ($iVersion >= 20030210) ;
}
else
return false ;
}
private static function GetConfigFieldString()
{
$sParams = '' ;
$bFirst = true ;
foreach ( self::$Config as $sKey => $sValue )
{
if ( $bFirst == false )
$sParams .= '&' ;
else
$bFirst = false ;
if ( $sValue === true )
$sParams .= self::EncodeConfig( $sKey ) . '=true' ;
else if ( $sValue === false )
$sParams .= self::EncodeConfig( $sKey ) . '=false' ;
else
$sParams .= self::EncodeConfig( $sKey ) . '=' . self::EncodeConfig( $sValue ) ;
}
return $sParams ;
}
private static function EncodeConfig( $valueToEncode )
{
$chars = array(
'&' => '%26',
'=' => '%3D',
'"' => '%22' ) ;
return strtr( $valueToEncode, $chars ) ;
}
}
?>
Change History
Note: See
TracTickets for help on using
tickets.