fckeditor_php4.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. /*
  3. * FCKeditor - The text editor for Internet - http://www.fckeditor.net
  4. * Copyright (C) 2003-2008 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. * This is the integration file for PHP 4.
  23. *
  24. * It defines the FCKeditor class that can be used to create editor
  25. * instances in PHP pages on server side.
  26. */
  27. class FCKeditor
  28. {
  29. /**
  30. * Name of the FCKeditor instance.
  31. *
  32. * @access protected
  33. * @var string
  34. */
  35. var $InstanceName ;
  36. /**
  37. * Path to FCKeditor relative to the document root.
  38. *
  39. * @var string
  40. */
  41. var $BasePath ;
  42. /**
  43. * Width of the FCKeditor.
  44. * Examples: 100%, 600
  45. *
  46. * @var mixed
  47. */
  48. var $Width ;
  49. /**
  50. * Height of the FCKeditor.
  51. * Examples: 400, 50%
  52. *
  53. * @var mixed
  54. */
  55. var $Height ;
  56. /**
  57. * Name of the toolbar to load.
  58. *
  59. * @var string
  60. */
  61. var $ToolbarSet ;
  62. /**
  63. * Initial value.
  64. *
  65. * @var string
  66. */
  67. var $Value ;
  68. /**
  69. * This is where additional configuration can be passed.
  70. * Example:
  71. * $oFCKeditor->Config['EnterMode'] = 'br';
  72. *
  73. * @var array
  74. */
  75. var $Config ;
  76. /**
  77. * Main Constructor.
  78. * Refer to the _samples/php directory for examples.
  79. *
  80. * @param string $instanceName
  81. */
  82. function FCKeditor( $instanceName )
  83. {
  84. $this->InstanceName = $instanceName ;
  85. $this->BasePath = '/fckeditor/' ;
  86. $this->Width = '100%' ;
  87. $this->Height = '200' ;
  88. $this->ToolbarSet = 'Default' ;
  89. $this->Value = '' ;
  90. $this->Config = array() ;
  91. }
  92. /**
  93. * Display FCKeditor.
  94. *
  95. */
  96. function Create()
  97. {
  98. echo $this->CreateHtml() ;
  99. }
  100. /**
  101. * Return the HTML code required to run FCKeditor.
  102. *
  103. * @return string
  104. */
  105. function CreateHtml()
  106. {
  107. $HtmlValue = htmlspecialchars( $this->Value ) ;
  108. $Html = '' ;
  109. if ( !isset( $_GET ) ) {
  110. global $HTTP_GET_VARS ;
  111. $_GET = $HTTP_GET_VARS ;
  112. }
  113. if ( $this->IsCompatible() )
  114. {
  115. if ( isset( $_GET['fcksource'] ) && $_GET['fcksource'] == "true" )
  116. $File = 'fckeditor.original.html' ;
  117. else
  118. $File = 'fckeditor.html' ;
  119. $Link = "{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}" ;
  120. if ( $this->ToolbarSet != '' )
  121. $Link .= "&amp;Toolbar={$this->ToolbarSet}" ;
  122. // Render the linked hidden field.
  123. $Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" style=\"display:none\" />" ;
  124. // Render the configurations hidden field.
  125. $Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" style=\"display:none\" />" ;
  126. // Render the editor IFRAME.
  127. $Html .= "<iframe id=\"{$this->InstanceName}___Frame\" src=\"{$Link}\" width=\"{$this->Width}\" height=\"{$this->Height}\" frameborder=\"0\" scrolling=\"no\"></iframe>" ;
  128. }
  129. else
  130. {
  131. if ( strpos( $this->Width, '%' ) === false )
  132. $WidthCSS = $this->Width . 'px' ;
  133. else
  134. $WidthCSS = $this->Width ;
  135. if ( strpos( $this->Height, '%' ) === false )
  136. $HeightCSS = $this->Height . 'px' ;
  137. else
  138. $HeightCSS = $this->Height ;
  139. $Html .= "<textarea name=\"{$this->InstanceName}\" rows=\"4\" cols=\"40\" style=\"width: {$WidthCSS}; height: {$HeightCSS}\">{$HtmlValue}</textarea>" ;
  140. }
  141. return $Html ;
  142. }
  143. /**
  144. * Returns true if browser is compatible with FCKeditor.
  145. *
  146. * @return boolean
  147. */
  148. function IsCompatible()
  149. {
  150. return FCKeditor_IsCompatibleBrowser() ;
  151. }
  152. /**
  153. * Get settings from Config array as a single string.
  154. *
  155. * @access protected
  156. * @return string
  157. */
  158. function GetConfigFieldString()
  159. {
  160. $sParams = '' ;
  161. $bFirst = true ;
  162. foreach ( $this->Config as $sKey => $sValue )
  163. {
  164. if ( $bFirst == false )
  165. $sParams .= '&amp;' ;
  166. else
  167. $bFirst = false ;
  168. if ( $sValue === true )
  169. $sParams .= $this->EncodeConfig( $sKey ) . '=true' ;
  170. else if ( $sValue === false )
  171. $sParams .= $this->EncodeConfig( $sKey ) . '=false' ;
  172. else
  173. $sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ;
  174. }
  175. return $sParams ;
  176. }
  177. /**
  178. * Encode characters that may break the configuration string
  179. * generated by GetConfigFieldString().
  180. *
  181. * @access protected
  182. * @param string $valueToEncode
  183. * @return string
  184. */
  185. function EncodeConfig( $valueToEncode )
  186. {
  187. $chars = array(
  188. '&' => '%26',
  189. '=' => '%3D',
  190. '"' => '%22' ) ;
  191. return strtr( $valueToEncode, $chars ) ;
  192. }
  193. }