PageRenderTime 63ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/class/doleditor.class.php

https://github.com/asterix14/dolibarr
PHP | 239 lines | 139 code | 28 blank | 72 comment | 21 complexity | 8b069d596291a25eb11e4a36908102ba MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. * or see http://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/class/doleditor.class.php
  20. * \brief Class to manage a WYSIWYG editor
  21. */
  22. /**
  23. * \class DolEditor
  24. * \brief Class to manage a WYSIWYG editor.
  25. * Usage: $doleditor=new DolEditor('body',$message,320,'toolbar_mailing');
  26. * $doleditor->Create();
  27. */
  28. class DolEditor
  29. {
  30. var $tool; // Store the selected tool
  31. // If using fckeditor
  32. var $editor;
  33. // If not using fckeditor
  34. var $content;
  35. var $htmlname;
  36. var $toolbarname;
  37. var $toolbarstartexpanded;
  38. var $rows;
  39. var $cols;
  40. var $height;
  41. var $width;
  42. /**
  43. * Create an object to build an HTML area to edit a large string content
  44. *
  45. * @param string $htmlname HTML name of WYSIWIG form
  46. * @param string $content Content of WYSIWIG form
  47. * @param int $width Width in pixel of edit area (auto by default)
  48. * @param int $height Height in pixel of edit area (200px by default)
  49. * @param string $toolbarname Name of bar set to use ('Full', 'dolibarr_notes', 'dolibarr_details', 'dolibarr_mailings')
  50. * @param string $toolbarlocation Where bar is stored :
  51. * 'In' each window has its own toolbar
  52. * 'Out:name' share toolbar into the div called 'name'
  53. * @param boolean $toolbarstartexpanded Bar is visible or not at start
  54. * @param int $uselocalbrowser Enabled to add links to local object with local browser. If false, only external images can be added in content.
  55. * @param int $okforextendededitor True=Allow usage of extended editor tool (like fckeditor)
  56. * @param int $rows Size of rows for textarea tool
  57. * @param int $cols Size of cols for textarea tool
  58. */
  59. function DolEditor($htmlname,$content,$width='',$height=200,$toolbarname='Basic',$toolbarlocation='In',$toolbarstartexpanded=false,$uselocalbrowser=true,$okforextendededitor=true,$rows=0,$cols=0)
  60. {
  61. global $conf,$langs;
  62. dol_syslog("DolEditor::DolEditor htmlname=".$htmlname." tool=".$tool);
  63. if (! $rows) $rows=round($height/20);
  64. if (! $cols) $cols=($width?round($width/6):80);
  65. // Name of extended editor to use (FCKEDITOR_EDITORNAME can be 'ckeditor' or 'fckeditor')
  66. $defaulteditor='ckeditor';
  67. $this->tool=empty($conf->global->FCKEDITOR_EDITORNAME)?$defaulteditor:$conf->global->FCKEDITOR_EDITORNAME;
  68. $this->uselocalbrowser=$uselocalbrowser;
  69. // Check if extended editor is ok. If not we force textarea
  70. if (empty($conf->fckeditor->enabled) || ! $okforextendededitor)
  71. {
  72. $this->tool = 'textarea';
  73. }
  74. // Define content and some properties
  75. if ($this->tool == 'ckeditor')
  76. {
  77. $content=dol_htmlentitiesbr($content); // If content is not HTML, we convert to HTML.
  78. }
  79. if ($this->tool == 'fckeditor')
  80. {
  81. require_once(DOL_DOCUMENT_ROOT."/includes/fckeditor/fckeditor.php");
  82. $content=dol_htmlentitiesbr($content); // If content is not HTML, we convert to HTML.
  83. $this->editor = new FCKeditor($htmlname);
  84. $this->editor->BasePath = DOL_URL_ROOT.'/includes/fckeditor/' ;
  85. $this->editor->Value = $content;
  86. $this->editor->Height = $height;
  87. if (! empty($width)) $this->editor->Width = $width;
  88. $this->editor->ToolbarSet = $toolbarname;
  89. $this->editor->Config['AutoDetectLanguage'] = 'true';
  90. $this->editor->Config['ToolbarLocation'] = $toolbarlocation ? $toolbarlocation : 'In';
  91. $this->editor->Config['ToolbarStartExpanded'] = $toolbarstartexpanded;
  92. // Rem: Le forcage de ces 2 parametres ne semble pas fonctionner.
  93. // Dolibarr utilise toujours liens avec modulepart='fckeditor' quelque soit modulepart.
  94. // Ou se trouve donc cette valeur /viewimage.php?modulepart=fckeditor&file=' ?
  95. $modulepart='fckeditor';
  96. $this->editor->Config['UserFilesPath'] = '/viewimage.php?modulepart='.$modulepart.'&file=';
  97. $this->editor->Config['UserFilesAbsolutePath'] = DOL_DATA_ROOT.'/'.$modulepart.'/' ;
  98. $this->editor->Config['LinkBrowser']=($uselocalbrowser?'true':'false');
  99. $this->editor->Config['ImageBrowser']=($uselocalbrowser?'true':'false');
  100. if (file_exists(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/fckeditor/fckconfig.js'))
  101. {
  102. $this->editor->Config['CustomConfigurationsPath'] = DOL_URL_ROOT.'/theme/'.$conf->theme.'/fckeditor/fckconfig.js';
  103. $this->editor->Config['SkinPath'] = DOL_URL_ROOT.'/theme/'.$conf->theme.'/fckeditor/';
  104. }
  105. }
  106. // Define some properties
  107. if (in_array($this->tool,array('textarea','ckeditor')))
  108. {
  109. $this->content = $content;
  110. $this->htmlname = $htmlname;
  111. $this->toolbarname = $toolbarname;
  112. $this->toolbarstartexpanded = $toolbarstartexpanded;
  113. $this->rows = max(ROWS_3,$rows);
  114. $this->cols = max(40,$cols);
  115. $this->height = $height;
  116. $this->width = $width;
  117. }
  118. }
  119. /**
  120. * Output edit area inside the HTML stream.
  121. * Output depends on this->tool (fckeditor, ckeditor, texatrea, ...)
  122. *
  123. * @param noprint 1=Return HTML string instead of printing it to output
  124. */
  125. function Create($noprint=0)
  126. {
  127. global $conf;
  128. $found=0;
  129. $out='';
  130. if ($this->tool == 'fckeditor')
  131. {
  132. $found=1;
  133. $this->editor->Create();
  134. }
  135. if (in_array($this->tool,array('textarea','ckeditor')))
  136. {
  137. $found=1;
  138. $out.= '<textarea id="'.$this->htmlname.'" name="'.$this->htmlname.'" rows="'.$this->rows.'" cols="'.$this->cols.'" class="flat">';
  139. $out.= $this->content;
  140. $out.= '</textarea>';
  141. if ($this->tool == 'ckeditor')
  142. {
  143. if (! defined('REQUIRE_CKEDITOR')) define('REQUIRE_CKEDITOR','1');
  144. //$skin='kama';
  145. //$skin='office2003';
  146. //$skin='v2';
  147. $skin='kama';
  148. $out.= '<script type="text/javascript">
  149. jQuery(document).ready(function () {
  150. /* if (CKEDITOR.loadFullCore) CKEDITOR.loadFullCore(); */
  151. CKEDITOR.replace(\''.$this->htmlname.'\',
  152. {
  153. customConfig : \''.dol_buildpath('/theme/'.$conf->theme.'/ckeditor/config.js',1).'\',
  154. toolbar: \''.$this->toolbarname.'\',
  155. toolbarStartupExpanded: '.($this->toolbarstartexpanded ? 'true' : 'false').',
  156. width: '.($this->width ? $this->width : '\'\'').',
  157. height: '.$this->height.',
  158. skin: \''.$skin.'\',
  159. on :
  160. {
  161. instanceReady : function( ev )
  162. {
  163. // Output paragraphs as <p>Text</p>.
  164. this.dataProcessor.writer.setRules( \'p\',
  165. {
  166. indent : false,
  167. breakBeforeOpen : true,
  168. breakAfterOpen : false,
  169. breakBeforeClose : false,
  170. breakAfterClose : true
  171. });
  172. }
  173. }';
  174. if ($this->uselocalbrowser)
  175. {
  176. $out.= ','."\n";
  177. // To use filemanager with old fckeditor (GPL)
  178. $out.= ' filebrowserBrowseUrl : \''.DOL_URL_ROOT.'/core/filemanagerdol/browser/default/browser.php?Connector='.DOL_URL_ROOT.'/core/filemanagerdol/connectors/php/connector.php\',';
  179. $out.= ' filebrowserImageBrowseUrl : \''.DOL_URL_ROOT.'/core/filemanagerdol/browser/default/browser.php?Type=Image&Connector='.DOL_URL_ROOT.'/core/filemanagerdol/connectors/php/connector.php\',';
  180. //$out.= ' filebrowserUploadUrl : \''.DOL_URL_ROOT.'/includes/fckeditor/editor/filemanagerdol/connectors/php/upload.php?Type=File\',';
  181. //$out.= ' filebrowserImageUploadUrl : \''.DOL_URL_ROOT.'/includes/fckeditor/editor/filemanagerdol/connectors/php/upload.php?Type=Image\',';
  182. $out.= "\n";
  183. // To use filemanager with ckfinder (Non free) and ckfinder directory is inside htdocs/includes
  184. /* $out.= ' filebrowserBrowseUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/ckfinder.html\',
  185. filebrowserImageBrowseUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/ckfinder.html?Type=Images\',
  186. filebrowserFlashBrowseUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/ckfinder.html?Type=Flash\',
  187. filebrowserUploadUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files\',
  188. filebrowserImageUploadUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images\',
  189. filebrowserFlashUploadUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash\','."\n";
  190. */
  191. $out.= ' filebrowserWindowWidth : \'900\',
  192. filebrowserWindowHeight : \'500\',
  193. filebrowserImageWindowWidth : \'900\',
  194. filebrowserImageWindowHeight : \'500\'';
  195. }
  196. $out.= '
  197. });
  198. });
  199. </script>';
  200. }
  201. }
  202. if (empty($found))
  203. {
  204. $out.= 'Error, unknown value for tool '.$this->tool.' in DolEditor Create function.';
  205. }
  206. if ($noprint) return $out;
  207. else print $out;
  208. }
  209. }
  210. ?>