XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
editor.class.php
Go to the documentation of this file.
1 <?php
2 // $Id: editor.class.php 1016 2012-08-26 23:28:48Z i.bitcero $
3 // --------------------------------------------------------------
4 // Red México Common Utilities
5 // A framework for Red México Modules
6 // Author: Eduardo Cortés <i.bitcero@gmail.com>
7 // Email: i.bitcero@gmail.com
8 // License: GPL 2.0
9 // --------------------------------------------------------------
10 
15 {
16  private $_width = '';
17  private $_height = '';
18  private $_default = '';
19  private $_type = 'tiny';
20  private $_theme = '';
21  private $_action = '';
25  private $_change = 0;
30  private $_eles = array();
34  private $_tinycss = '';
38  private $ex_plugins = 'dropdown,texts,fonts,email,link,xcode,xquote,rmimage,emotions,more,chars';
39  private $ex_buttons = 'bold,italic,underline,strikeout,separator_t,left,center,right,separator_t,fontsize,font,fontcolor,separator_t,more,bottom,top,separator_b,link,email,xcode,xquote,separator_b,images,emotions,separator_b,chars,page';
48  function __construct($caption, $name, $width='100%', $height='300px', $default='', $type='', $change=1, $ele=array('op')){
49 
50  $rmc_config = RMFunctions::get()->configs();
51 
52  $tcleaner = TextCleaner::getInstance();
53  $this->setCaption($caption);
54  $this->setName($name);
55  $this->_width = $width;
56  $this->_height = $height;
57  $this->_default = isset($_REQUEST[$name]) ? $tcleaner->stripslashes($_REQUEST[$name]) : $tcleaner->stripslashes($default);
58  $this->_type = $type=='' ? $rmc_config['editor_type'] : $type;
59  $this->_type = strtolower($this->_type);
60  $this->_change = $change;
61  $this->_eles = $ele;
62 
63  }
67  public function setType($value){
68  $this->_type = $value;
69  }
70  public function getType(){
71  return $this->_type;
72  }
76  public function setTheme($theme){
77  $this->_theme = $theme;
78  }
82  public function editorFormAction($action){
83  $this->_action = $action;
84  }
89  public function render(){
93  $ret = '';
94 
95  switch ($this->_type){
96  case 'simple':
97  $ret .= $this->renderTArea();
98  break;
99  case 'xoops':
100  $ret .= $this->renderExmCode();
101  break;
102  case 'html':
103  $ret .= $this->renderHTML();
104  break;
105  case 'tiny':
106  default:
107  $ret .= $this->renderTiny();
108  break;
109  }
110 
111  return $ret;
112  }
113 
114  public function renderTArea(){
115  RMTemplate::get()->add_style('xoops-editor.css', 'rmcommon');
116  $rtn = "<div class=\"ed-container\" style=\"width: $this->_width\">";
117  $plugins = array();
118  $plugins = RMEvents::get()->run_event('rmcommon.simple.editor.plugins', $plugins, $this->getName());
119  if (!empty($plugins)){
120  $rtn .= '<div class="ed-plugins">';
121  $rtn .= implode("", $plugins);
122  $rtn .= "</div>";
123  }
124  $rtn .= "<textarea class='xc-editor' id='".$this->getName()."' name='".$this->getName()."' style='width: 99%; height: ".$this->_height.";'>".$this->_default."</textarea>
125  </div>";
126  return $rtn;
127  }
131  public function tinyCSS($url, EXMForm &$form){
132  $form->tinyCSS($url);
133  }
134 
139  private function renderTiny(){
140  global $rmc_config, $xoopsUser;
141  TinyEditor::getInstance()->add_config('elements',$this->id(), true);
142  RMTemplate::get()->add_xoops_style('mce_editor.css','rmcommon');
143  RMTemplate::get()->add_local_script('editor.js','rmcommon','include');
144  RMTemplate::get()->add_local_script('quicktags.js','rmcommon','include');
145  RMTemplate::get()->add_script(RMCURL.'/api/editors/tinymce/tiny_mce.js');
146  RMTemplate::get()->add_head_script(TinyEditor::getInstance()->get_js());
147 
148  $rtn = "\n
149  <div class=\"ed-container\" id=\"ed-cont-".$this->id()."\" style=\"width: $this->_width\">
150  <div class=\"es-editor\" style=\"width: $this->_width;\">
151  <a class=\"edButtonHTML\" onclick=\"switchEditors.go('".$this->id()."', 'html');\">HTML</a>
152  <a class=\"edButtonPreview\" onclick=\"switchEditors.go('".$this->id()."', 'tinymce');\">Visual</a>
153  </div>
154  <div class=\"quicktags\"><script type=\"text/javascript\">edToolbar('".$this->id()."')</script></div>
155  <textarea onchange=\"tinyMCE.activeEditor.save();\" id='".$this->id()."' name='".$this->getName()."' style='width: 100%; height: ".$this->_height.";' class='".$this->getClass()."'>".$this->_default."</textarea></div>";
156  return $rtn;
157  }
158 
163  private function renderHTML(){
164  RMTemplate::get()->add_script(RMCURL."/include/js/quicktags.js");
165  RMTemplate::get()->add_style('editor_html.css','rmcommon');
166  $rtn = "\n<div class='ed-container html_editor_container' style='width: $this->_width;' id='".$this->id()."-ed-container'>";
167  $plugins = array();
168  // Get external plugins
169  $plugins = RMEvents::get()->run_event('rmcommon.html.editor.plugins', $plugins, $this->id());
170 
171  $rtn .= "<div class=\"quicktags\"><script type=\"text/javascript\">edToolbar('".$this->id()."')</script>".(!empty($plugins) ? "<div class='ed_plugins'>".implode(" ", $plugins)."</div>" : '')."</div>
172  <div class='txtarea_container'><textarea id='".$this->id()."' name='".$this->getName()."' style='width: ".$this->_width."; height: ".$this->_height.";' class='".$this->getClass()."'>".$this->_default."</textarea></div>
173  </div>";
174  return $rtn;
175  }
176 
177  private function renderExmCode(){
178  RMTemplate::get()->add_script(RMCURL."/api/editors/exmcode/editor-exmcode.php?id=".$this->id());
179  RMTemplate::get()->add_script(RMCURL."/include/js/colorpicker.js");
180  RMTemplate::get()->add_style('editor-exmcode.css','rmcommon');
181  RMTemplate::get()->add_style('colorpicker.css','rmcommon');
182  $rtn = "<div class='ed-container' id='".$this->id()."-ed-container' width='$this->_width'>";
183  $rtn .= "<div class='ed_buttons' id='".$this->id()."-ec-container'>";
184  $rtn .= "<div class='row_top'></div><div class='row_bottom'></div>";
185  $rtn .= "</div>";
186  $rtn .= "<textarea id='".$this->id()."' name='".$this->getName()."' style='width: 99%; height: ".$this->_height.";' class='".$this->getClass()."'>".$this->_default."</textarea>";
187  $rtn .= "</div>";
188  // buttons
189  $tplugins = RMEvents::get()->run_event('rmcommon.exmcode.plugins', $this->ex_plugins);
190  $tplugins = explode(',',$tplugins);
191  $plugins = '';
192  foreach ($tplugins as $p){
193  $plugins .= $plugins=='' ? $p.': true' : ','.$p.': true';
194  }
195  RMTemplate::get()->add_head("<script type=\"text/javascript\">\nvar ".$this->id()."_buttons = \"".RMEvents::get()->run_event('rmcommon.exmcode.buttons', $this->ex_buttons)."\";\nvar ".$this->id()."_plugins = {".$plugins."};\n</script>");
196  return $rtn;
197  }
198 
204  public function exmcode_buttons($buttons){
205  if ($buttons=='') return;
206 
207  $this->ex_buttons = $buttons;
208  }
209 }