PageRenderTime 25ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/editor/fckeditor_php4.php

http://avecms.googlecode.com/
PHP | 266 lines | 131 code | 27 blank | 108 comment | 27 complexity | 049ad6f545d8921995c304a90692a1b1 MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause, BSD-2-Clause, Apache-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. * FCKeditor - The text editor for Internet - http://www.fckeditor.net
  4. * Copyright (C) 2003-2010 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. /**
  28. * Check if browser is compatible with FCKeditor.
  29. * Return true if is compatible.
  30. *
  31. * @return boolean
  32. */
  33. function FCKeditor_IsCompatibleBrowser()
  34. {
  35. if ( isset( $_SERVER ) ) {
  36. $sAgent = $_SERVER['HTTP_USER_AGENT'] ;
  37. }
  38. else {
  39. global $HTTP_SERVER_VARS ;
  40. if ( isset( $HTTP_SERVER_VARS ) ) {
  41. $sAgent = $HTTP_SERVER_VARS['HTTP_USER_AGENT'] ;
  42. }
  43. else {
  44. global $HTTP_USER_AGENT ;
  45. $sAgent = $HTTP_USER_AGENT ;
  46. }
  47. }
  48. if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false )
  49. {
  50. $iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3) ;
  51. return ($iVersion >= 5.5) ;
  52. }
  53. else if ( strpos($sAgent, 'Gecko/') !== false )
  54. {
  55. $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ;
  56. return ($iVersion >= 20030210) ;
  57. }
  58. else if ( strpos($sAgent, 'Opera/') !== false )
  59. {
  60. $fVersion = (float)substr($sAgent, strpos($sAgent, 'Opera/') + 6, 4) ;
  61. return ($fVersion >= 9.5) ;
  62. }
  63. else if ( preg_match( "|AppleWebKit/(\d+)|i", $sAgent, $matches ) )
  64. {
  65. $iVersion = $matches[1] ;
  66. return ( $matches[1] >= 522 ) ;
  67. }
  68. else
  69. return false ;
  70. }
  71. class FCKeditor
  72. {
  73. /**
  74. * Name of the FCKeditor instance.
  75. *
  76. * @access protected
  77. * @var string
  78. */
  79. var $InstanceName ;
  80. /**
  81. * Path to FCKeditor relative to the document root.
  82. *
  83. * @var string
  84. */
  85. var $BasePath ;
  86. /**
  87. * Width of the FCKeditor.
  88. * Examples: 100%, 600
  89. *
  90. * @var mixed
  91. */
  92. var $Width ;
  93. /**
  94. * Height of the FCKeditor.
  95. * Examples: 400, 50%
  96. *
  97. * @var mixed
  98. */
  99. var $Height ;
  100. /**
  101. * Name of the toolbar to load.
  102. *
  103. * @var string
  104. */
  105. var $ToolbarSet ;
  106. /**
  107. * Initial value.
  108. *
  109. * @var string
  110. */
  111. var $Value ;
  112. /**
  113. * This is where additional configuration can be passed.
  114. * Example:
  115. * $oFCKeditor->Config['EnterMode'] = 'br';
  116. *
  117. * @var array
  118. */
  119. var $Config ;
  120. /**
  121. * Main Constructor.
  122. * Refer to the _samples/php directory for examples.
  123. *
  124. * @param string $instanceName
  125. */
  126. function FCKeditor( $instanceName )
  127. {
  128. $this->InstanceName = $instanceName ;
  129. $this->BasePath = 'editor/' ;
  130. $this->Width = '100%' ;
  131. $this->Height = '200' ;
  132. $this->ToolbarSet = 'cpengine' ;
  133. $this->Value = '' ;
  134. $this->Config = array() ;
  135. }
  136. /**
  137. * Display FCKeditor.
  138. *
  139. */
  140. function Create($aid='')
  141. {
  142. return $this->CreateHtml($aid) ;
  143. }
  144. /**
  145. * Return the HTML code required to run FCKeditor.
  146. *
  147. * @return string
  148. */
  149. function CreateHtml($aid='')
  150. {
  151. $this->Value = str_replace(array('\r\n\r\n','\n ','\n ','\n '),'',$this->Value);
  152. $HtmlValue = htmlspecialchars( $this->Value ) ;
  153. $Html = '<div>' ;
  154. if ( !isset( $_GET ) ) {
  155. global $HTTP_GET_VARS ;
  156. $_GET = $HTTP_GET_VARS ;
  157. }
  158. if ( $this->IsCompatible() )
  159. {
  160. if ( isset( $_GET['fcksource'] ) && $_GET['fcksource'] == "true" )
  161. $File = 'fckeditor.original.html' ;
  162. else
  163. $File = 'fckeditor.html' ;
  164. $Link = "{$this->BasePath}editor/{$File}?InstanceName={$this->InstanceName}" ;
  165. if ( $this->ToolbarSet != '' )
  166. $Link .= "&amp;Toolbar={$this->ToolbarSet}" ;
  167. // Render the linked hidden field.
  168. $Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" style=\"display:none\" />" ;
  169. // Render the configurations hidden field.
  170. $Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" style=\"display:none\" />" ;
  171. // Render the editor IFRAME.
  172. $Html .= "<a name=\"$aid\"></a><div id=\"feld_$aid\"><iframe id=\"{$this->InstanceName}___Frame\" src=\"{$Link}\" width=\"{$this->Width}\" height=\"{$this->Height}\" frameborder=\"0\" scrolling=\"no\"></iframe></div>" ;
  173. }
  174. else
  175. {
  176. if ( strpos( $this->Width, '%' ) === false )
  177. $WidthCSS = $this->Width . 'px' ;
  178. else
  179. $WidthCSS = $this->Width ;
  180. if ( strpos( $this->Height, '%' ) === false )
  181. $HeightCSS = $this->Height . 'px' ;
  182. else
  183. $HeightCSS = $this->Height ;
  184. $Html .= "<textarea name=\"{$this->InstanceName}\" rows=\"4\" cols=\"40\" style=\"width: {$WidthCSS}; height: {$HeightCSS}\">{$HtmlValue}</textarea>" ;
  185. }
  186. $Html .= '</div>' ;
  187. return $Html ;
  188. }
  189. /**
  190. * Returns true if browser is compatible with FCKeditor.
  191. *
  192. * @return boolean
  193. */
  194. function IsCompatible()
  195. {
  196. return FCKeditor_IsCompatibleBrowser() ;
  197. }
  198. /**
  199. * Get settings from Config array as a single string.
  200. *
  201. * @access protected
  202. * @return string
  203. */
  204. function GetConfigFieldString()
  205. {
  206. $sParams = '' ;
  207. $bFirst = true ;
  208. foreach ( $this->Config as $sKey => $sValue )
  209. {
  210. if ( $bFirst == false )
  211. $sParams .= '&amp;' ;
  212. else
  213. $bFirst = false ;
  214. if ( $sValue === true )
  215. $sParams .= $this->EncodeConfig( $sKey ) . '=true' ;
  216. else if ( $sValue === false )
  217. $sParams .= $this->EncodeConfig( $sKey ) . '=false' ;
  218. else
  219. $sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ;
  220. }
  221. return $sParams ;
  222. }
  223. /**
  224. * Encode characters that may break the configuration string
  225. * generated by GetConfigFieldString().
  226. *
  227. * @access protected
  228. * @param string $valueToEncode
  229. * @return string
  230. */
  231. function EncodeConfig( $valueToEncode )
  232. {
  233. $chars = array(
  234. '&' => '%26',
  235. '=' => '%3D',
  236. '"' => '%22' ) ;
  237. return strtr( $valueToEncode, $chars ) ;
  238. }
  239. }