Opened 19 years ago
Closed 13 years ago
#232 closed New Feature (wontfix)
New code for PHP classe of FCKeditor
| Reported by: | Joly, Alexandre | Owned by: | |
|---|---|---|---|
| Priority: | Normal | Milestone: | |
| Component: | Server : PHP | Version: | FCKeditor 2.4 |
| Keywords: | 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 (5)
comment:1 Changed 19 years ago by
| Keywords: | Classe SIngleton PHP 5 removed |
|---|
comment:2 Changed 18 years ago by
comment:3 Changed 18 years ago by
| Owner: | Frederico Caldeira Knabben deleted |
|---|
comment:4 Changed 18 years ago by
| Keywords: | Confirmed HasPatch added |
|---|
comment:5 Changed 13 years ago by
| Resolution: | → wontfix |
|---|---|
| Status: | confirmed → closed |
FCKeditor was retired and is no longer supported. All active development was moved to its successor, CKEditor 3.x, that is a fully mature and far superior product. We recommend you upgrade as soon as possible.

Another proposed version was in https://sourceforge.net/tracker/index.php?func=detail&aid=1109049&group_id=75348&atid=543655
Introduced visibility specifiers (private, public) for member variables and methods.
Fixed XHTML validity (slash at the end of input tag).
Code style (indenting, one-true brackets etc.) adjusted to PEAR coding standards, as well as naming of variables and methods (first char in lowercase).
<?php /* * FCKeditor - The text editor for internet * Copyright (C) 2003-2004 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/ * * 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. * * Version: 2.0 RC2 * Modified: 2004-11-29 17:56:52 * * File Authors: * Frederico Caldeira Knabben (fredck@fckeditor.net) */ class FCKeditor { public $instanceName; public $basePath; public $width; public $height; public $toolbarSet; public $value; public $config; public function __construct($instanceName) { $this->instanceName = $instanceName; $this->basePath = '/FCKeditor/'; $this->width = '100%'; $this->height = '200'; $this->toolbarSet = 'Default'; $this->value = ''; $this->config = array(); } public function create() { echo $this->createHtml(); } private function createHtml() { $htmlValue = htmlspecialchars($this->value); $html = '<div>'; if ($this->isCompatible()) { $link = $this->basePath . 'editor/fckeditor.html?InstanceName=' . $this->instanceName; if ($this->toolbarSet!='') { $link .= '&Toolbar=' . $this->toolbarSet; } // Render the linked hidden field. $html .= '<input type="hidden" id="' . $this->instanceName . '" name="' . $this->instanceName . '" value="' . $htmlValue . '" />'; // Render the configurations hidden field. $html .= '<input type="hidden" id="' . $this->instanceName . '___Config" name="' . $this->instanceName . '___Config" value="' . $this->getConfigFieldString() . '" />'; // Render the editor IFRAME. $html .= '<iframe id="' . $this->instanceName . '___Frame" src="' . $link . '" width="' . $this->width . '" height="' . $this->height . '" frameborder="no" scrolling="no"></iframe>'; } else { if (strpos($this->width, '%')===false) { $widthCSS = $this->width . 'px'; } else { $widthCSS = $this->width; } if (strpos($this->height, '%')===false) { $heightCSS = $this->height . 'px'; } else { $heightCSS = $this->height; } $html .= '<textarea id="' . $this->instanceName . '" name="' . $this->instanceName . '" rows="4" cols="40" style="width: ' . $widthCSS . '; height: ' . $heightCSS . '" wrap="virtual">' . $htmlValue . '</textarea>'; } $html .= '</div>'; return $html; } private function isCompatible() { $sAgent = $_SERVER['HTTP_USER_AGENT']; if (strpos($sAgent, 'MSIE')!==false && strpos($sAgent, 'mac')===false && strpos($sAgent, 'Opera')===false) { $iVersion = (int)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3); return ($iVersion >= 5.5); } elseif (strpos($sAgent, 'Gecko')!==false) { $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8); return ($iVersion>=20030210); } else { return false; } } private function getConfigFieldString() { $sParams = ''; $bFirst = true; foreach ($this->config as $sKey => $sValue) { if ($bFirst==false) { $sParams .= '&'; } else { $bFirst = false; } if ($sValue===true) { $sParams .= htmlspecialchars($sKey) . '=true'; } elseif ($sValue===false) { $sParams .= htmlspecialchars($sKey) . '=false'; } else { $sParams .= htmlspecialchars($sKey) . '=' . htmlspecialchars($sValue); } } return $sParams; } } ?>