XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
tinyeditor.php
Go to the documentation of this file.
1 <?php
2 // $Id: tinyeditor.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 
16 {
17  public $configuration = array();
18 
19  function getInstance(){
20  static $instance;
21  if (!isset($instance)) {
22  $instance = new TinyEditor();
23  }
24  return $instance;
25  }
26 
27  // Configuración
28  public function add_config($names,$values, $replace=false){
29  if (is_array($names) && is_array($values)){
30  foreach ($names as $i => $name){
31  // Replace if needed
32  if ($replace){
33  $this->configuration[$name] = $values[$i];
34  } else {
35  // Not replace, verify...
36  $this->configuration[$name] = isset($this->configuration[$name]) ? ",".$values[$i] : $values[$i];
37  }
38  }
39  } else {
40  if ($replace || !isset($this->configuration[$names]))
41  $this->configuration[$names] = $values;
42  else
43  $this->configuration[$names] .= isset($this->configuration[$names]) ? ",$values" : $values;
44  }
45 
46  }
47 
48  public function remove_config($name){
49  if (empty($this->configuration)) return;
50 
51  unset($this->configuration[$name]);
52 
53  }
54 
55  public function get_js(){
56 
57  $rtn = 'tinyMCE.init({';
58  $configs = ''; $i = 0;
59  foreach ($this->configuration as $name => $value){
60  $i++;
61  $configs .= $name.' : "'.$value.'"'.($i>count($this->configuration) ? '' : ',')."\n";
62  }
63  $rtn .= $configs . '
64  setup: function(ed){
65  ed.onKeyUp.add(function(ed, e){
66  if (tinyMCE.activeEditor.isDirty())
67  ed.save();
68  });
69  }
70  });';
71 
72  return $rtn;
73  }
74 }