3 * FCKeditor - The text editor for internet
4 * Copyright (C) 2003-2005 Frederico Caldeira Knabben
6 * Licensed under the terms of the GNU Lesser General Public License:
7 * http://www.opensource.org/licenses/lgpl-license.php
9 * For further information visit:
10 * http://www.fckeditor.net/
12 * "Support Open Source software. What about a donation today?"
14 * File Name: fckeditor.php
15 * This is the integration file for PHP.
17 * It defines the FCKeditor class that can be used to create editor
18 * instances in PHP pages on server side.
21 * Frederico Caldeira Knabben (fredck@fckeditor.net)
34 // PHP 5 Constructor (by Marcus Bointon <coolbru@users.sourceforge.net>)
35 function __construct( $instanceName )
37 $this->InstanceName = $instanceName ;
38 $this->BasePath = '/FCKeditor/' ;
39 $this->Width = '100%' ;
40 $this->Height = '200' ;
41 $this->ToolbarSet = 'Default' ;
44 $this->Config = array() ;
48 function FCKeditor( $instanceName )
50 $this->__construct( $instanceName ) ;
55 echo $this->CreateHtml() ;
60 $HtmlValue = htmlspecialchars( $this->Value ) ;
64 if ( $this->IsCompatible() )
66 if ( isset( $_GET['fcksource'] ) && $_GET['fcksource'] == "true" )
67 $File = 'fckeditor.original.html' ;
69 $File = 'fckeditor.html' ;
71 $Link = "{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}" ;
73 if ( $this->ToolbarSet != '' )
74 $Link .= "&Toolbar={$this->ToolbarSet}" ;
76 // Render the linked hidden field.
77 $Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" style=\"display:none\" />" ;
79 // Render the configurations hidden field.
80 $Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" style=\"display:none\" />" ;
82 // Render the editor IFRAME.
83 $Html .= "<iframe id=\"{$this->InstanceName}___Frame\" src=\"{$Link}\" width=\"{$this->Width}\" height=\"{$this->Height}\" frameborder=\"no\" scrolling=\"no\"></iframe>" ;
87 if ( strpos( $this->Width, '%' ) === false )
88 $WidthCSS = $this->Width . 'px' ;
90 $WidthCSS = $this->Width ;
92 if ( strpos( $this->Height, '%' ) === false )
93 $HeightCSS = $this->Height . 'px' ;
95 $HeightCSS = $this->Height ;
97 $Html .= "<textarea name=\"{$this->InstanceName}\" rows=\"4\" cols=\"40\" style=\"width: {$WidthCSS}; height: {$HeightCSS}\">{$HtmlValue}</textarea>" ;
105 function IsCompatible()
107 global $HTTP_USER_AGENT ;
109 if ( isset( $HTTP_USER_AGENT ) )
110 $sAgent = $HTTP_USER_AGENT ;
112 $sAgent = $_SERVER['HTTP_USER_AGENT'] ;
114 if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false )
116 $iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3) ;
117 return ($iVersion >= 5.5) ;
119 else if ( strpos($sAgent, 'Gecko/') !== false )
121 $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ;
122 return ($iVersion >= 20030210) ;
128 function GetConfigFieldString()
133 foreach ( $this->Config as $sKey => $sValue )
135 if ( $bFirst == false )
136 $sParams .= '&' ;
140 if ( $sValue === true )
141 $sParams .= $this->EncodeConfig( $sKey ) . '=true' ;
142 else if ( $sValue === false )
143 $sParams .= $this->EncodeConfig( $sKey ) . '=false' ;
145 $sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ;
151 function EncodeConfig( $valueToEncode )
158 return strtr( $valueToEncode, $chars ) ;