XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
xoopseditor.php
Go to the documentation of this file.
1 <?php
19 defined('XOOPS_ROOT_PATH') or die('Restricted access');
20 
22 
23 class XoopsEditor extends XoopsFormTextArea
24 {
26  var $configs;
27  var $rootPath;
28  var $_rows = 5;
29  var $_cols = 50;
30 
34  function __construct()
35  {
36  $args = func_get_args();
37  // For backward compatibility
38  if (!is_array($args[0])) {
39  $i = 0;
40  foreach (array('caption' , 'name' , 'value' , 'rows' , 'cols' , 'hiddentext') as $key) {
41  if (isset($args[$i])) {
42  $configs[$key] = $args[$i];
43  }
44  $i ++;
45  }
46  $configs = (isset($args[$i]) && is_array($args[$i])) ? array_merge($configs, $args[$i]) : $configs;
47  } else {
48  $configs = $args[0];
49  }
50  // TODO: switch to property_exists() as of PHP 5.1.0
51  $vars = get_class_vars(__CLASS__);
52  foreach ($configs as $key => $val) {
53  if (method_exists($this, "set" . ucfirst($key))) {
54  $this->{"set" . ucfirst($key)}($val);
55  } else if (array_key_exists("_{$key}", $vars)) {
56  $this->{"_{$key}"} = $val;
57  } else if (array_key_exists($key, $vars)) {
58  $this->{$key} = $val;
59  } else {
60  $this->configs[$key] = $val;
61  }
62  }
63  $this->isActive();
64  }
65 
66  function XoopsEditor($configs)
67  {
68  $this->__construct($configs);
69  }
70 
71  function isActive()
72  {
73  $this->isEnabled = true;
74  return $this->isEnabled;
75  }
76 }
77 
88 {
89  // static $instance;
90  var $root_path = "";
91  var $nohtml = false;
92  var $allowed_editors = array();
97  function __construct()
98  {
99  $this->root_path = XOOPS_ROOT_PATH . '/class/xoopseditor';
100  }
101 
103  {
104  $this->__construct();
105  }
106 
114  function &getInstance()
115  {
116  static $instance;
117  if (!isset($instance)) {
118  $class = __CLASS__;
119  $instance = new $class();
120  }
121  return $instance;
122  }
123 
131  function get($name = '', $options = null, $noHtml = false, $OnFailure = '')
132  {
133  if (array_key_exists($name, $this->getList($noHtml)) && $editor = $this->_loadEditor($name, $options)) {
134  return $editor;
135  }
136  $list = array_keys($this->getList($noHtml));
137  if (empty($OnFailure) || !in_array($OnFailure, $list)) {
138  $OnFailure = $list[0];
139  }
140  $editor = $this->_loadEditor($OnFailure, $options);
141  return $editor;
142  }
143 
150  function getList($noHtml = false)
151  {
152  /*
153  Do NOT use this method statically, please use
154  $editor_handler = XoopsEditorHandler::getInstance();
155  $result = array_flip($editor_handler->getList());
156  */
157  if (!isset($this->root_path)) {
158  $this->root_path = XOOPS_ROOT_PATH . '/class/xoopseditor';
159  $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . '() should not be called statically.');
160  }
161 
162  xoops_load('XoopsCache');
163  $list = XoopsCache::read('editorlist');
164  if (empty($list)) {
165  $list = array();
166  $order = array();
167  xoops_load('XoopsLists');
168  $_list = XoopsLists::getDirListAsArray($this->root_path . '/');
169  foreach ($_list as $item) {
170  if (file_exists($file = $this->root_path . '/' . $item . '/language/' . $GLOBALS['xoopsConfig']['language'] . '.php')) {
171  include_once $file;
172  } else if (file_exists($file = $this->root_path . '/' . $item . '/language/english.php')) {
173  include_once $file;
174  }
175  if (file_exists($file = $this->root_path . '/' . $item . '/editor_registry.php')) {
176  include $file;
177  if (empty($config['order']))
178  continue;
179  $order[] = $config['order'];
180  $list[$item] = array('title' => $config['title'] , 'nohtml' => $config['nohtml']);
181  }
182  }
183  array_multisort($order, $list);
184  XoopsCache::write('editorlist', $list);
185  }
186 
187  $editors = array_keys($list);
188  if (!empty($this->allowed_editors)) {
189  $editors = array_intersect($editors, $this->allowed_editors);
190  }
191  $_list = array();
192  foreach ($editors as $name) {
193  if (!empty($noHtml) && empty($list[$name]['nohtml']))
194  continue;
195  $_list[$name] = $list[$name]['title'];
196  }
197  return $_list;
198  }
199 
206  function render($editor)
207  {
208  trigger_error(__CLASS__ . '::' . __FUNCTION__ . '() deprecated', E_USER_WARNING);
209  return $editor->render();
210  }
211 
220  {
221  if (method_exists($editor, 'setConfig')) {
222  $editor->setConfig($options);
223  } else {
224  foreach ($options as $key => $val) {
225  $editor->$key = $val;
226  }
227  }
228  }
229 
237  function _loadEditor($name, $options = null)
238  {
239  $editor = null;
240  if (empty($name) || !array_key_exists($name, $this->getList())) {
241  return $editor;
242  }
243  $editor_path = $this->root_path . '/' . $name;
244  if (file_exists($file = $editor_path . '/language/' . $GLOBALS['xoopsConfig']['language'] . '.php')) {
245  include_once $file;
246  } else if (file_exists($file = $editor_path . '/language/english.php')) {
247  include_once $file;
248  }
249  if (file_exists($file = $editor_path . '/editor_registry.php')) {
250  include $file;
251  } else {
252  return $editor;
253  }
254  if (empty($config['order'])) {
255  return $editor;
256  }
257  include_once $config['file'];
258  $editor = new $config['class']($options);
259  return $editor;
260  }
261 }
262 
263 ?>