PageRenderTime 82ms CodeModel.GetById 26ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/fields/class.Editor.php

https://github.com/reshadf/Library
PHP | 276 lines | 117 code | 29 blank | 130 comment | 28 complexity | 8e897bee529a9d8ab1be90101beccc53 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * class Editor
  4. *
  5. * Create a Editor on the given form
  6. *
  7. * @author Teye Heimans
  8. * @package FormHandler
  9. * @subpackage Fields
  10. *
  11. * converted to ckeditor
  12. * @since 2011-07-04
  13. * @author Jphan Wiegel @ PHP-GLOBE
  14. */
  15. class Editor extends Field
  16. {
  17. var $_oEditor; // FCKeditor: the object of the fck editor
  18. /**
  19. * Editor::Editor()
  20. *
  21. * Constructor: create a new Editor object
  22. *
  23. * @param object $oForm: The form where the field is located on
  24. * @return Editor
  25. * @access public
  26. * @author Teye Heimans
  27. */
  28. function Editor( &$oForm, $sName )
  29. {
  30. $this->_oEditor = new ckeditor( $sName );
  31. $this->_oEditor->returnOutput = true;
  32. $this->_oEditor->basePath = FH_FHTML_DIR . 'ckeditor/';
  33. // &nbsp; added as workarround IE9
  34. $this->_oEditor->Value = isset( $this->_mValue ) ? $this->_mValue : '';
  35. $this->setToolbar( 'Default' ); // Default or Basic
  36. $this->setServerPath( '' );
  37. parent::Field( $oForm, $sName );
  38. // set the language
  39. $this->_oEditor->config['language'] = str_replace('-utf8', '', $oForm->_lang);
  40. // default height & width
  41. $this->setWidth ( 720 );
  42. $this->setHeight( 400 );
  43. // default, silver or office2003
  44. $this->setSkin( 'v2' );
  45. }
  46. /**
  47. * Editor::setHeight()
  48. *
  49. * Set the height of the editor (in pixels!)
  50. *
  51. * @param integer $iHeight: the height
  52. * @return void
  53. * @access public
  54. * @author Teye Heimans
  55. */
  56. function setHeight( $iHeight )
  57. {
  58. $this->_oEditor->config['height'] = $iHeight;
  59. }
  60. /**
  61. * Editor::setValue()
  62. *
  63. * Set the value of the field
  64. *
  65. * @param string $sValue: The html to set into the field
  66. * @return void
  67. * @access public
  68. * @author Teye Heimans
  69. */
  70. function setValue( $sValue )
  71. {
  72. $this->_mValue = $sValue;
  73. $this->_oEditor->Value = $sValue;
  74. }
  75. /**
  76. * Editor::setWidth()
  77. *
  78. * Set the width of the editor (in pixels!)
  79. *
  80. * @param integer $iWidth: the width
  81. * @return void
  82. * @access public
  83. * @author Teye Heimans
  84. */
  85. function setWidth( $iWidth)
  86. {
  87. $this->_oEditor->config['width'] = $iWidth;
  88. }
  89. /**
  90. * Editor::setToolbar()
  91. *
  92. * Set the toolbar we should use for the editor
  93. *
  94. * @param string $sToolbar: The toolbar we should use
  95. * @return void
  96. * @access public
  97. * @author Teye Heimans
  98. */
  99. function setToolbar( $sToolbar )
  100. {
  101. $this->_oEditor->config['toolbar'] = $sToolbar;
  102. }
  103. /**
  104. * Editor::setConfig()
  105. *
  106. * Set extra config options for the editor
  107. *
  108. * @param array $config: The config array with extra config options to set for the fckeditor
  109. * @return void
  110. * @access public
  111. * @author Teye Heimans
  112. */
  113. function setConfig( $config )
  114. {
  115. $this->_oEditor->config = array_merge( $this->_oEditor->config, $config );
  116. }
  117. /**
  118. * Editor::setServerPath()
  119. *
  120. * Set the server path used for browsing and uploading images
  121. *
  122. * @param string $sPath: The path
  123. * @return void
  124. * @access public
  125. * @author Teye Heimans
  126. */
  127. function setServerPath( $sPath )
  128. {
  129. if( $sPath === false )
  130. {
  131. $this->_oEditor->Config['LinkBrowser'] = false;
  132. $this->_oEditor->Config['ImageBrowser'] = false;
  133. $this->_oEditor->Config['FlashBrowser'] = false;
  134. return;
  135. }
  136. // get the dir where the script is located in
  137. $sSelfPath = $_SERVER['PHP_SELF'] ;
  138. $sSelfPath = substr( $sSelfPath, 0, strrpos( $sSelfPath, '/' ) ) ;
  139. // get the dir where the user want's to upload the dir in
  140. $sPath = $this->_getServerPath( $sPath, $sSelfPath );
  141. // path (URL) to the FCKeditor...
  142. $char = substr(FH_FHTML_DIR, 0, 1);
  143. $pre = ($char != '/' && $char != '\\' && strtolower(substr(FH_FHTML_DIR, 0, 4)) != 'http') ? str_replace('//', '/', dirname( $_SERVER['PHP_SELF'] ).'/') : '';
  144. $sURL =
  145. $pre . FH_FHTML_DIR .
  146. 'filemanager/browser/default/browser.html?'.
  147. 'Type=%s&Connector=../../connectors/php/connector.php?ServerPath='.$sPath
  148. ;
  149. $this->_oEditor->config['filebrowserImageBrowseUrl'] = ( sprintf( $sURL, 'Image', $sPath ) );
  150. $this->_oEditor->config['filebrowserBrowseUrl'] = ( sprintf( $sURL, 'File', $sPath ) );
  151. $this->_oEditor->config['filebrowserFlashBrowseUrl'] = ( sprintf( $sURL, 'Flash', $sPath ) );
  152. }
  153. /**
  154. * Editor::setSkin()
  155. *
  156. * Set the skin used for the FCKeditor
  157. *
  158. * @param string $skin
  159. * @return void
  160. * @access public
  161. * @author Teye Heimans
  162. */
  163. function setSkin( $sSkin )
  164. {
  165. $this->_oEditor->config['skin'] = $sSkin;
  166. }
  167. /**
  168. * Editor::getField()
  169. *
  170. * Return the HTML of the field
  171. *
  172. * @return string: The HTML of the editor
  173. * @access public
  174. * @author Teye Heimans
  175. */
  176. function getField()
  177. {
  178. // view mode enabled ?
  179. if( $this -> getViewMode() )
  180. {
  181. // get the view value..
  182. return $this -> _getViewValue();
  183. }
  184. /*@var _oEditor CKEditor*/
  185. return $this->_oEditor->editor( $this->_sName, $this->_oEditor->Value ).
  186. (isset($this->_sExtraAfter) ? $this->_sExtraAfter :'');
  187. }
  188. /**
  189. * Editor::_getServerPath()
  190. *
  191. * Get the dir which should be used for browsing...
  192. *
  193. * @param string $sDir: The dir given by the user
  194. * @param string $sServerPath: The dir where the script is located on the server
  195. * @return void
  196. * @access private
  197. * @author Teye Heimans
  198. */
  199. function _getServerPath( $sDir, $sServerPath )
  200. {
  201. // remove ending slash at the server path
  202. if( substr($sServerPath, -1) == '/' )
  203. {
  204. $sServerPath = substr( $sServerPath, 0, -1);
  205. }
  206. // when no dir is given, just return the path where the script is located
  207. if( $sDir == '' )
  208. {
  209. return $sServerPath;
  210. }
  211. // dir starting with a /? Then start at the root...
  212. if( $sDir{0} == '/' )
  213. {
  214. return $sDir;
  215. }
  216. // dir starting with ./? Then relative from the dir where the script is located
  217. else if( substr( $sDir, 0, 2) == './' )
  218. {
  219. return $sServerPath.'/'.substr($sDir, 2);
  220. }
  221. // if we are at the root of the server, return the dir..
  222. else if( $sServerPath == '/' || $sServerPath == '')
  223. {
  224. if( $sDir{0} != '.' && $sDir{0} != '/' )
  225. {
  226. $sDir = '/'.$sDir;
  227. }
  228. return $sDir;
  229. }
  230. // go a dir lower...
  231. else if( substr($sDir, 0, 3) == '../' )
  232. {
  233. $sServerPath = substr($sServerPath, 0, -strlen( strrchr($sServerPath, "/") ));
  234. return $this->_getServerPath( substr($sDir, 3), $sServerPath);
  235. }
  236. // none of the above, then return the dir!
  237. else
  238. {
  239. if( $sDir{0} == '/' )
  240. {
  241. $sDir = substr( $sDir, 1);
  242. }
  243. return $sServerPath.'/'.$sDir;
  244. }
  245. }
  246. }
  247. ?>