3
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
4
* Copyright (C) 2003-2010 Frederico Caldeira Knabben
8
* Licensed under the terms of any of the following licenses at your
11
* - GNU General Public License Version 2 or later (the "GPL")
12
* http://www.gnu.org/licenses/gpl.html
14
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
15
* http://www.gnu.org/licenses/lgpl.html
17
* - Mozilla Public License Version 1.1 or later (the "MPL")
18
* http://www.mozilla.org/MPL/MPL-1.1.html
22
* This is the integration file for PHP 5.
24
* It defines the FCKeditor class that can be used to create editor
25
* instances in PHP pages on server side.
29
* Check if browser is compatible with FCKeditor.
30
* Return true if is compatible.
34
function FCKeditor_IsCompatibleBrowser()
36
if ( isset( $_SERVER ) ) {
37
$sAgent = $_SERVER['HTTP_USER_AGENT'] ;
40
global $HTTP_SERVER_VARS ;
41
if ( isset( $HTTP_SERVER_VARS ) ) {
42
$sAgent = $HTTP_SERVER_VARS['HTTP_USER_AGENT'] ;
45
global $HTTP_USER_AGENT ;
46
$sAgent = $HTTP_USER_AGENT ;
50
if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false )
52
$iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3) ;
53
return ($iVersion >= 5.5) ;
55
else if ( strpos($sAgent, 'Gecko/') !== false )
57
$iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ;
58
return ($iVersion >= 20030210) ;
60
else if ( strpos($sAgent, 'Opera/') !== false )
62
$fVersion = (float)substr($sAgent, strpos($sAgent, 'Opera/') + 6, 4) ;
63
return ($fVersion >= 9.5) ;
65
else if ( preg_match( "|AppleWebKit/(\d+)|i", $sAgent, $matches ) )
67
$iVersion = $matches[1] ;
68
return ( $matches[1] >= 522 ) ;
77
* Name of the FCKeditor instance.
82
public $InstanceName ;
84
* Path to FCKeditor relative to the document root.
90
* Width of the FCKeditor.
97
* Height of the FCKeditor.
104
* Name of the toolbar to load.
116
* This is where additional configuration can be passed.
118
* $oFCKeditor->Config['EnterMode'] = 'br';
126
* Refer to the _samples/php directory for examples.
128
* @param string $instanceName
130
public function __construct( $instanceName )
132
$this->InstanceName = $instanceName ;
133
$this->BasePath = '/fckeditor/' ;
134
$this->Width = '100%' ;
135
$this->Height = '200' ;
136
$this->ToolbarSet = 'Default' ;
139
$this->Config = array() ;
146
public function Create()
148
echo $this->CreateHtml() ;
152
* Return the HTML code required to run FCKeditor.
156
public function CreateHtml()
158
$HtmlValue = htmlspecialchars( $this->Value ) ;
162
if ( $this->IsCompatible() )
164
if ( isset( $_GET['fcksource'] ) && $_GET['fcksource'] == "true" )
165
$File = 'fckeditor.original.html' ;
167
$File = 'fckeditor.html' ;
169
$Link = "{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}" ;
171
if ( $this->ToolbarSet != '' )
172
$Link .= "&Toolbar={$this->ToolbarSet}" ;
174
// Render the linked hidden field.
175
$Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" style=\"display:none\" />" ;
177
// Render the configurations hidden field.
178
$Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" style=\"display:none\" />" ;
180
// Render the editor IFRAME.
181
$Html .= "<iframe id=\"{$this->InstanceName}___Frame\" src=\"{$Link}\" width=\"{$this->Width}\" height=\"{$this->Height}\" frameborder=\"0\" scrolling=\"no\"></iframe>" ;
185
if ( strpos( $this->Width, '%' ) === false )
186
$WidthCSS = $this->Width . 'px' ;
188
$WidthCSS = $this->Width ;
190
if ( strpos( $this->Height, '%' ) === false )
191
$HeightCSS = $this->Height . 'px' ;
193
$HeightCSS = $this->Height ;
195
$Html .= "<textarea name=\"{$this->InstanceName}\" rows=\"4\" cols=\"40\" style=\"width: {$WidthCSS}; height: {$HeightCSS}\">{$HtmlValue}</textarea>" ;
202
* Returns true if browser is compatible with FCKeditor.
206
public function IsCompatible()
208
return FCKeditor_IsCompatibleBrowser() ;
212
* Get settings from Config array as a single string.
217
public function GetConfigFieldString()
222
foreach ( $this->Config as $sKey => $sValue )
224
if ( $bFirst == false )
225
$sParams .= '&' ;
229
if ( $sValue === true )
230
$sParams .= $this->EncodeConfig( $sKey ) . '=true' ;
231
else if ( $sValue === false )
232
$sParams .= $this->EncodeConfig( $sKey ) . '=false' ;
234
$sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ;
241
* Encode characters that may break the configuration string
242
* generated by GetConfigFieldString().
245
* @param string $valueToEncode
248
public function EncodeConfig( $valueToEncode )
255
return strtr( $valueToEncode, $chars ) ;