PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/RedSocial 32.0/public/javascripts/fckeditor/fckeditor_php5.php

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