PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/Main/Source/Web/FCKeditor/fckeditor.php

#
PHP | 155 lines | 105 code | 26 blank | 24 comment | 16 complexity | c32d16d6c48fdb68169af65c1dc1880c MD5 | raw file
Possible License(s): LGPL-2.1
  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. * File Name: fckeditor.php
  13. * This is the integration file for PHP.
  14. *
  15. * It defines the FCKeditor class that can be used to create editor
  16. * instances in PHP pages on server side.
  17. *
  18. * File Authors:
  19. * Frederico Caldeira Knabben (fredck@fckeditor.net)
  20. */
  21. class FCKeditor
  22. {
  23. var $InstanceName ;
  24. var $BasePath ;
  25. var $Width ;
  26. var $Height ;
  27. var $ToolbarSet ;
  28. var $Value ;
  29. var $Config ;
  30. // PHP 5 Constructor (by Marcus Bointon <coolbru@users.sourceforge.net>)
  31. function __construct( $instanceName )
  32. {
  33. $this->InstanceName = $instanceName ;
  34. $this->BasePath = '/FCKeditor/' ;
  35. $this->Width = '100%' ;
  36. $this->Height = '200' ;
  37. $this->ToolbarSet = 'Default' ;
  38. $this->Value = '' ;
  39. $this->Config = array() ;
  40. }
  41. // PHP 4 Contructor
  42. function FCKeditor( $instanceName )
  43. {
  44. $this->__construct( $instanceName ) ;
  45. }
  46. function Create()
  47. {
  48. echo $this->CreateHtml() ;
  49. }
  50. function CreateHtml()
  51. {
  52. $HtmlValue = htmlspecialchars( $this->Value ) ;
  53. $Html = '<div>' ;
  54. if ( $this->IsCompatible() )
  55. {
  56. $Link = "{$this->BasePath}editor/fckeditor.html?InstanceName={$this->InstanceName}" ;
  57. if ( $this->ToolbarSet != '' )
  58. $Link .= "&amp;Toolbar={$this->ToolbarSet}" ;
  59. // Render the linked hidden field.
  60. $Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}\" name=\"{$this->InstanceName}\" value=\"{$HtmlValue}\" />" ;
  61. // Render the configurations hidden field.
  62. $Html .= "<input type=\"hidden\" id=\"{$this->InstanceName}___Config\" value=\"" . $this->GetConfigFieldString() . "\" />" ;
  63. // Render the editor IFRAME.
  64. $Html .= "<iframe id=\"{$this->InstanceName}___Frame\" src=\"{$Link}\" width=\"{$this->Width}\" height=\"{$this->Height}\" frameborder=\"no\" scrolling=\"no\"></iframe>" ;
  65. }
  66. else
  67. {
  68. if ( strpos( $this->Width, '%' ) === false )
  69. $WidthCSS = $this->Width . 'px' ;
  70. else
  71. $WidthCSS = $this->Width ;
  72. if ( strpos( $this->Height, '%' ) === false )
  73. $HeightCSS = $this->Height . 'px' ;
  74. else
  75. $HeightCSS = $this->Height ;
  76. $Html .= "<textarea name=\"{$this->InstanceName}\" rows=\"4\" cols=\"40\" style=\"width: {$WidthCSS}; height: {$HeightCSS}\" wrap=\"virtual\">{$HtmlValue}</textarea>" ;
  77. }
  78. $Html .= '</div>' ;
  79. return $Html ;
  80. }
  81. function IsCompatible()
  82. {
  83. global $HTTP_USER_AGENT ;
  84. if ( isset( $HTTP_USER_AGENT ) )
  85. $sAgent = $HTTP_USER_AGENT ;
  86. else
  87. $sAgent = $_SERVER['HTTP_USER_AGENT'] ;
  88. if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false )
  89. {
  90. $iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3) ;
  91. return ($iVersion >= 5.5) ;
  92. }
  93. else if ( strpos($sAgent, 'Gecko/') !== false )
  94. {
  95. $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ;
  96. return ($iVersion >= 20030210) ;
  97. }
  98. else
  99. return false ;
  100. }
  101. function GetConfigFieldString()
  102. {
  103. $sParams = '' ;
  104. $bFirst = true ;
  105. foreach ( $this->Config as $sKey => $sValue )
  106. {
  107. if ( $bFirst == false )
  108. $sParams .= '&amp;' ;
  109. else
  110. $bFirst = false ;
  111. if ( $sValue === true )
  112. $sParams .= $this->EncodeConfig( $sKey ) . '=true' ;
  113. else if ( $sValue === false )
  114. $sParams .= $this->EncodeConfig( $sKey ) . '=false' ;
  115. else
  116. $sParams .= $this->EncodeConfig( $sKey ) . '=' . $this->EncodeConfig( $sValue ) ;
  117. }
  118. return $sParams ;
  119. }
  120. function EncodeConfig( $valueToEncode )
  121. {
  122. $chars = array(
  123. '&' => '%26',
  124. '=' => '%3D',
  125. '"' => '%22' ) ;
  126. return strtr( $valueToEncode, $chars ) ;
  127. }
  128. }
  129. ?>