Back to index

moin  1.9.0~rc2
fckeditor_php4.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  * FCKeditor - The text editor for Internet - http://www.fckeditor.net
00004  * Copyright (C) 2003-2009 Frederico Caldeira Knabben
00005  *
00006  * == BEGIN LICENSE ==
00007  *
00008  * Licensed under the terms of any of the following licenses at your
00009  * choice:
00010  *
00011  *  - GNU General Public License Version 2 or later (the "GPL")
00012  *    http://www.gnu.org/licenses/gpl.html
00013  *
00014  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
00015  *    http://www.gnu.org/licenses/lgpl.html
00016  *
00017  *  - Mozilla Public License Version 1.1 or later (the "MPL")
00018  *    http://www.mozilla.org/MPL/MPL-1.1.html
00019  *
00020  * == END LICENSE ==
00021  *
00022  * This is the integration file for PHP 4.
00023  *
00024  * It defines the FCKeditor class that can be used to create editor
00025  * instances in PHP pages on server side.
00026  */
00027 
00034 function FCKeditor_IsCompatibleBrowser()
00035 {
00036        if ( isset( $_SERVER ) ) {
00037               $sAgent = $_SERVER['HTTP_USER_AGENT'] ;
00038        }
00039        else {
00040               global $HTTP_SERVER_VARS ;
00041               if ( isset( $HTTP_SERVER_VARS ) ) {
00042                      $sAgent = $HTTP_SERVER_VARS['HTTP_USER_AGENT'] ;
00043               }
00044               else {
00045                      global $HTTP_USER_AGENT ;
00046                      $sAgent = $HTTP_USER_AGENT ;
00047               }
00048        }
00049 
00050        if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false )
00051        {
00052               $iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3) ;
00053               return ($iVersion >= 5.5) ;
00054        }
00055        else if ( strpos($sAgent, 'Gecko/') !== false )
00056        {
00057               $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ;
00058               return ($iVersion >= 20030210) ;
00059        }
00060        else if ( strpos($sAgent, 'Opera/') !== false )
00061        {
00062               $fVersion = (float)substr($sAgent, strpos($sAgent, 'Opera/') + 6, 4) ;
00063               return ($fVersion >= 9.5) ;
00064        }
00065        else if ( preg_match( "|AppleWebKit/(\d+)|i", $sAgent, $matches ) )
00066        {
00067               $iVersion = $matches[1] ;
00068               return ( $matches[1] >= 522 ) ;
00069        }
00070        else
00071               return false ;
00072 }
00073 
00074 class FCKeditor
00075 {
00082        var $InstanceName ;
00088        var $BasePath ;
00095        var $Width ;
00102        var $Height ;
00108        var $ToolbarSet ;
00114        var $Value ;
00122        var $Config ;
00123 
00130        function FCKeditor( $instanceName )
00131        {
00132               $this->InstanceName  = $instanceName ;
00133               $this->BasePath             = '/fckeditor/' ;
00134               $this->Width         = '100%' ;
00135               $this->Height        = '200' ;
00136               $this->ToolbarSet    = 'Default' ;
00137               $this->Value         = '' ;
00138 
00139               $this->Config        = array() ;
00140        }
00141 
00146        function Create()
00147        {
00148               echo $this->CreateHtml() ;
00149        }
00150 
00156        function CreateHtml()
00157        {
00158               $HtmlValue = htmlspecialchars( $this->Value ) ;
00159 
00160               $Html = '' ;
00161 
00162               if ( !isset( $_GET ) ) {
00163                      global $HTTP_GET_VARS ;
00164                      $_GET = $HTTP_GET_VARS ;
00165               }
00166 
00167               if ( $this->IsCompatible() )
00168               {
00169                      if ( isset( $_GET['fcksource'] ) && $_GET['fcksource'] == "true" )
00170                             $File = 'fckeditor.original.html' ;
00171                      else
00172                             $File = 'fckeditor.html' ;
00173 
00174                      $Link = "{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}" ;
00175 
00176                      if ( $this->ToolbarSet != '' )
00177                             $Link .= "&amp;Toolbar={$this->ToolbarSet}" ;
00178 
00179                      // Render the linked hidden field.
00180                      $Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" style=\"display:none\" />" ;
00181 
00182                      // Render the configurations hidden field.
00183                      $Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" style=\"display:none\" />" ;
00184 
00185                      // Render the editor IFRAME.
00186                      $Html .= "<iframe id=\"{$this->InstanceName}___Frame\" src=\"{$Link}\" width=\"{$this->Width}\" height=\"{$this->Height}\" frameborder=\"0\" scrolling=\"no\"></iframe>" ;
00187               }
00188               else
00189               {
00190                      if ( strpos( $this->Width, '%' ) === false )
00191                             $WidthCSS = $this->Width . 'px' ;
00192                      else
00193                             $WidthCSS = $this->Width ;
00194 
00195                      if ( strpos( $this->Height, '%' ) === false )
00196                             $HeightCSS = $this->Height . 'px' ;
00197                      else
00198                             $HeightCSS = $this->Height ;
00199 
00200                      $Html .= "<textarea name=\"{$this->InstanceName}\" rows=\"4\" cols=\"40\" style=\"width: {$WidthCSS}; height: {$HeightCSS}\">{$HtmlValue}</textarea>" ;
00201               }
00202 
00203               return $Html ;
00204        }
00205 
00211        function IsCompatible()
00212        {
00213               return FCKeditor_IsCompatibleBrowser() ;
00214        }
00215 
00222        function GetConfigFieldString()
00223        {
00224               $sParams = '' ;
00225               $bFirst = true ;
00226 
00227               foreach ( $this->Config as $sKey => $sValue )
00228               {
00229                      if ( $bFirst == false )
00230                             $sParams .= '&amp;' ;
00231                      else
00232                             $bFirst = false ;
00233 
00234                      if ( $sValue === true )
00235                             $sParams .= $this->EncodeConfig( $sKey ) . '=true' ;
00236                      else if ( $sValue === false )
00237                             $sParams .= $this->EncodeConfig( $sKey ) . '=false' ;
00238                      else
00239                             $sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ;
00240               }
00241 
00242               return $sParams ;
00243        }
00244 
00253        function EncodeConfig( $valueToEncode )
00254        {
00255               $chars = array(
00256                      '&' => '%26',
00257                      '=' => '%3D',
00258                      '"' => '%22' ) ;
00259 
00260               return strtr( $valueToEncode,  $chars ) ;
00261        }
00262 }