fckeditor.lib.php 4.0 KB

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