--- /dev/null
+<?php\r
+/*\r
+ * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
+ * Copyright (C) 2003-2008 Frederico Caldeira Knabben\r
+ *\r
+ * == BEGIN LICENSE ==\r
+ *\r
+ * Licensed under the terms of any of the following licenses at your\r
+ * choice:\r
+ *\r
+ * - GNU General Public License Version 2 or later (the "GPL")\r
+ * http://www.gnu.org/licenses/gpl.html\r
+ *\r
+ * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
+ * http://www.gnu.org/licenses/lgpl.html\r
+ *\r
+ * - Mozilla Public License Version 1.1 or later (the "MPL")\r
+ * http://www.mozilla.org/MPL/MPL-1.1.html\r
+ *\r
+ * == END LICENSE ==\r
+ *\r
+ * This is the integration file for PHP 5.\r
+ *\r
+ * It defines the FCKeditor class that can be used to create editor\r
+ * instances in PHP pages on server side.\r
+ */\r
+\r
+/**\r
+ * Check if browser is compatible with FCKeditor.\r
+ * Return true if is compatible.\r
+ *\r
+ * @return boolean\r
+ */\r
+function FCKeditor_IsCompatibleBrowser()\r
+{\r
+ if ( isset( $_SERVER ) ) {\r
+ $sAgent = $_SERVER['HTTP_USER_AGENT'] ;\r
+ }\r
+ else {\r
+ global $HTTP_SERVER_VARS ;\r
+ if ( isset( $HTTP_SERVER_VARS ) ) {\r
+ $sAgent = $HTTP_SERVER_VARS['HTTP_USER_AGENT'] ;\r
+ }\r
+ else {\r
+ global $HTTP_USER_AGENT ;\r
+ $sAgent = $HTTP_USER_AGENT ;\r
+ }\r
+ }\r
+\r
+ if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false )\r
+ {\r
+ $iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3) ;\r
+ return ($iVersion >= 5.5) ;\r
+ }\r
+ else if ( strpos($sAgent, 'Gecko/') !== false )\r
+ {\r
+ $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ;\r
+ return ($iVersion >= 20030210) ;\r
+ }\r
+ else if ( strpos($sAgent, 'Opera/') !== false )\r
+ {\r
+ $fVersion = (float)substr($sAgent, strpos($sAgent, 'Opera/') + 6, 4) ;\r
+ return ($fVersion >= 9.5) ;\r
+ }\r
+ else if ( preg_match( "|AppleWebKit/(\d+)|i", $sAgent, $matches ) )\r
+ {\r
+ $iVersion = $matches[1] ;\r
+ return ( $matches[1] >= 522 ) ;\r
+ }\r
+ else\r
+ return false ;\r
+}\r
+\r
+class FCKeditor\r
+{\r
+ /**\r
+ * Name of the FCKeditor instance.\r
+ *\r
+ * @access protected\r
+ * @var string\r
+ */\r
+ public $InstanceName ;\r
+ /**\r
+ * Path to FCKeditor relative to the document root.\r
+ *\r
+ * @var string\r
+ */\r
+ public $BasePath ;\r
+ /**\r
+ * Width of the FCKeditor.\r
+ * Examples: 100%, 600\r
+ *\r
+ * @var mixed\r
+ */\r
+ public $Width ;\r
+ /**\r
+ * Height of the FCKeditor.\r
+ * Examples: 400, 50%\r
+ *\r
+ * @var mixed\r
+ */\r
+ public $Height ;\r
+ /**\r
+ * Name of the toolbar to load.\r
+ *\r
+ * @var string\r
+ */\r
+ public $ToolbarSet ;\r
+ /**\r
+ * Initial value.\r
+ *\r
+ * @var string\r
+ */\r
+ public $Value ;\r
+ /**\r
+ * This is where additional configuration can be passed.\r
+ * Example:\r
+ * $oFCKeditor->Config['EnterMode'] = 'br';\r
+ *\r
+ * @var array\r
+ */\r
+ public $Config ;\r
+\r
+ /**\r
+ * Main Constructor.\r
+ * Refer to the _samples/php directory for examples.\r
+ *\r
+ * @param string $instanceName\r
+ */\r
+ public function __construct( $instanceName )\r
+ {\r
+ $this->InstanceName = $instanceName ;\r
+ $this->BasePath = '/fckeditor/' ;\r
+ $this->Width = '100%' ;\r
+ $this->Height = '200' ;\r
+ $this->ToolbarSet = 'Default' ;\r
+ $this->Value = '' ;\r
+\r
+ $this->Config = array() ;\r
+ }\r
+\r
+ /**\r
+ * Display FCKeditor.\r
+ *\r
+ */\r
+ public function Create()\r
+ {\r
+ echo $this->CreateHtml() ;\r
+ }\r
+\r
+ /**\r
+ * Return the HTML code required to run FCKeditor.\r
+ *\r
+ * @return string\r
+ */\r
+ public function CreateHtml()\r
+ {\r
+ $HtmlValue = htmlspecialchars( $this->Value ) ;\r
+\r
+ $Html = '' ;\r
+\r
+ if ( $this->IsCompatible() )\r
+ {\r
+ if ( isset( $_GET['fcksource'] ) && $_GET['fcksource'] == "true" )\r
+ $File = 'fckeditor.original.html' ;\r
+ else\r
+ $File = 'fckeditor.html' ;\r
+\r
+ $Link = "{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}" ;\r
+\r
+ if ( $this->ToolbarSet != '' )\r
+ $Link .= "&Toolbar={$this->ToolbarSet}" ;\r
+\r
+ // Render the linked hidden field.\r
+ $Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" style=\"display:none\" />" ;\r
+\r
+ // Render the configurations hidden field.\r
+ $Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" style=\"display:none\" />" ;\r
+\r
+ // Render the editor IFRAME.\r
+ $Html .= "<iframe id=\"{$this->InstanceName}___Frame\" src=\"{$Link}\" width=\"{$this->Width}\" height=\"{$this->Height}\" frameborder=\"0\" scrolling=\"no\"></iframe>" ;\r
+ }\r
+ else\r
+ {\r
+ if ( strpos( $this->Width, '%' ) === false )\r
+ $WidthCSS = $this->Width . 'px' ;\r
+ else\r
+ $WidthCSS = $this->Width ;\r
+\r
+ if ( strpos( $this->Height, '%' ) === false )\r
+ $HeightCSS = $this->Height . 'px' ;\r
+ else\r
+ $HeightCSS = $this->Height ;\r
+\r
+ $Html .= "<textarea name=\"{$this->InstanceName}\" rows=\"4\" cols=\"40\" style=\"width: {$WidthCSS}; height: {$HeightCSS}\">{$HtmlValue}</textarea>" ;\r
+ }\r
+\r
+ return $Html ;\r
+ }\r
+\r
+ /**\r
+ * Returns true if browser is compatible with FCKeditor.\r
+ *\r
+ * @return boolean\r
+ */\r
+ public function IsCompatible()\r
+ {\r
+ return FCKeditor_IsCompatibleBrowser() ;\r
+ }\r
+\r
+ /**\r
+ * Get settings from Config array as a single string.\r
+ *\r
+ * @access protected\r
+ * @return string\r
+ */\r
+ public function GetConfigFieldString()\r
+ {\r
+ $sParams = '' ;\r
+ $bFirst = true ;\r
+\r
+ foreach ( $this->Config as $sKey => $sValue )\r
+ {\r
+ if ( $bFirst == false )\r
+ $sParams .= '&' ;\r
+ else\r
+ $bFirst = false ;\r
+\r
+ if ( $sValue === true )\r
+ $sParams .= $this->EncodeConfig( $sKey ) . '=true' ;\r
+ else if ( $sValue === false )\r
+ $sParams .= $this->EncodeConfig( $sKey ) . '=false' ;\r
+ else\r
+ $sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ;\r
+ }\r
+\r
+ return $sParams ;\r
+ }\r
+\r
+ /**\r
+ * Encode characters that may break the configuration string\r
+ * generated by GetConfigFieldString().\r
+ *\r
+ * @access protected\r
+ * @param string $valueToEncode\r
+ * @return string\r
+ */\r
+ public function EncodeConfig( $valueToEncode )\r
+ {\r
+ $chars = array(\r
+ '&' => '%26',\r
+ '=' => '%3D',\r
+ '"' => '%22' ) ;\r
+\r
+ return strtr( $valueToEncode, $chars ) ;\r
+ }\r
+}\r