[ Index ]
 

Code source de FCKeditor 2.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/ -> fckeditor_php5.php (source)

   1  <?php 
   2  /*
   3   * FCKeditor - The text editor for Internet - http://www.fckeditor.net
   4   * Copyright (C) 2003-2007 Frederico Caldeira Knabben
   5   * 
   6   * == BEGIN LICENSE ==
   7   * 
   8   * Licensed under the terms of any of the following licenses at your
   9   * choice:
  10   * 
  11   *  - GNU General Public License Version 2 or later (the "GPL")
  12   *    http://www.gnu.org/licenses/gpl.html
  13   * 
  14   *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  15   *    http://www.gnu.org/licenses/lgpl.html
  16   * 
  17   *  - Mozilla Public License Version 1.1 or later (the "MPL")
  18   *    http://www.mozilla.org/MPL/MPL-1.1.html
  19   * 
  20   * == END LICENSE ==
  21   * 
  22   * File Name: fckeditor_php5.php
  23   *     This is the integration file for PHP 5.
  24   *     
  25   *     It defines the FCKeditor class that can be used to create editor
  26   *     instances in PHP pages on server side.
  27   * 
  28   * File Authors:
  29   *         Frederico Caldeira Knabben (www.fckeditor.net)
  30   */
  31  
  32  class FCKeditor
  33  {
  34      var $InstanceName ;
  35      var $BasePath ;
  36      var $Width ;
  37      var $Height ;
  38      var $ToolbarSet ;
  39      var $Value ;
  40      var $Config ;
  41  
  42      // PHP 5 Constructor (by Marcus Bointon <coolbru@users.sourceforge.net>)
  43  	function __construct( $instanceName )
  44       {
  45          $this->InstanceName    = $instanceName ;
  46          $this->BasePath        = '/fckeditor/' ;
  47          $this->Width        = '100%' ;
  48          $this->Height        = '200' ;
  49          $this->ToolbarSet    = 'Default' ;
  50          $this->Value        = '' ;
  51  
  52          $this->Config        = array() ;
  53      }
  54  
  55  	function Create()
  56      {
  57          echo $this->CreateHtml() ;
  58      }
  59      
  60  	function CreateHtml()
  61      {
  62          $HtmlValue = htmlspecialchars( $this->Value ) ;
  63  
  64          $Html = '<div>' ;
  65          
  66          if ( $this->IsCompatible() )
  67          {
  68              if ( isset( $_GET['fcksource'] ) && $_GET['fcksource'] == "true" )
  69                  $File = 'fckeditor.original.html' ;
  70              else
  71                  $File = 'fckeditor.html' ;
  72  
  73              $Link = "{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}" ;
  74              
  75              if ( $this->ToolbarSet != '' )
  76                  $Link .= "&amp;Toolbar={$this->ToolbarSet}" ;
  77  
  78              // Render the linked hidden field.
  79              $Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" style=\"display:none\" />" ;
  80  
  81              // Render the configurations hidden field.
  82              $Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" style=\"display:none\" />" ;
  83  
  84              // Render the editor IFRAME.
  85              $Html .= "<iframe id=\"{$this->InstanceName}___Frame\" src=\"{$Link}\" width=\"{$this->Width}\" height=\"{$this->Height}\" frameborder=\"0\" scrolling=\"no\"></iframe>" ;
  86          }
  87          else
  88          {
  89              if ( strpos( $this->Width, '%' ) === false )
  90                  $WidthCSS = $this->Width . 'px' ;
  91              else
  92                  $WidthCSS = $this->Width ;
  93  
  94              if ( strpos( $this->Height, '%' ) === false )
  95                  $HeightCSS = $this->Height . 'px' ;
  96              else
  97                  $HeightCSS = $this->Height ;
  98  
  99              $Html .= "<textarea name=\"{$this->InstanceName}\" rows=\"4\" cols=\"40\" style=\"width: {$WidthCSS}; height: {$HeightCSS}\">{$HtmlValue}</textarea>" ;
 100          }
 101  
 102          $Html .= '</div>' ;
 103          
 104          return $Html ;
 105      }
 106  
 107  	function IsCompatible()
 108      {
 109          global $HTTP_USER_AGENT ;
 110  
 111          if ( isset( $HTTP_USER_AGENT ) )
 112              $sAgent = $HTTP_USER_AGENT ;
 113          else
 114              $sAgent = $_SERVER['HTTP_USER_AGENT'] ;
 115  
 116          if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false )
 117          {
 118              $iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3) ;
 119              return ($iVersion >= 5.5) ;
 120          }
 121          else if ( strpos($sAgent, 'Gecko/') !== false )
 122          {
 123              $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ;
 124              return ($iVersion >= 20030210) ;
 125          }
 126          else
 127              return false ;
 128      }
 129  
 130  	function GetConfigFieldString()
 131      {
 132          $sParams = '' ;
 133          $bFirst = true ;
 134  
 135          foreach ( $this->Config as $sKey => $sValue )
 136          {
 137              if ( $bFirst == false )
 138                  $sParams .= '&amp;' ;
 139              else
 140                  $bFirst = false ;
 141              
 142              if ( $sValue === true )
 143                  $sParams .= $this->EncodeConfig( $sKey ) . '=true' ;
 144              else if ( $sValue === false )
 145                  $sParams .= $this->EncodeConfig( $sKey ) . '=false' ;
 146              else
 147                  $sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ;
 148          }
 149          
 150          return $sParams ;
 151      }
 152  
 153  	function EncodeConfig( $valueToEncode )
 154      {
 155          $chars = array( 
 156              '&' => '%26', 
 157              '=' => '%3D', 
 158              '"' => '%22' ) ;
 159  
 160          return strtr( $valueToEncode,  $chars ) ;
 161      }
 162  }
 163  
 164  ?>


Généré le : Sun Feb 25 15:28:05 2007 par Balluche grâce à PHPXref 0.7