1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
18: defined('XOOPS_ROOT_PATH') || exit('Restricted access');
19:
20: xoops_load('XoopsFormTextArea');
21:
22: 23: 24:
25: class XoopsEditor extends XoopsFormTextArea
26: {
27: public $isEnabled;
28: public $configs;
29: public $rootPath;
30: public $_rows = 5;
31: public $_cols = 50;
32:
33: 34: 35:
36: public function __construct()
37: {
38: $args = func_get_args();
39:
40: if (!is_array($args[0])) {
41: $i = 0;
42: foreach (array('caption', 'name', 'value', 'rows', 'cols', 'hiddentext') as $key) {
43: if (isset($args[$i])) {
44: $configs[$key] = $args[$i];
45: }
46: ++$i;
47: }
48: $configs = (isset($args[$i]) && is_array($args[$i])) ? array_merge($configs, $args[$i]) : $configs;
49: } else {
50: $configs = $args[0];
51: }
52:
53: $vars = get_class_vars(__CLASS__);
54: foreach ($configs as $key => $val) {
55: if (method_exists($this, 'set' . ucfirst($key))) {
56: $this->{'set' . ucfirst($key)}($val);
57: } elseif (array_key_exists("_{$key}", $vars)) {
58: $this->{"_{$key}"} = $val;
59: } elseif (array_key_exists($key, $vars)) {
60: $this->{$key} = $val;
61: } else {
62: $this->configs[$key] = $val;
63: }
64: }
65: $this->isActive();
66: }
67:
68: 69: 70:
71: public function isActive()
72: {
73: $this->isEnabled = true;
74:
75: return $this->isEnabled;
76: }
77: }
78:
79: 80: 81: 82: 83: 84: 85: 86: 87:
88: class XoopsEditorHandler
89: {
90:
91: public $root_path = '';
92: public $nohtml = false;
93: public $allowed_editors = array();
94:
95: 96: 97: 98:
99: public function __construct()
100: {
101: $this->root_path = XOOPS_ROOT_PATH . '/class/xoopseditor';
102: }
103:
104: 105: 106: 107: 108: 109: 110:
111: public static function getInstance()
112: {
113: static $instance;
114: if (!isset($instance)) {
115: $class = __CLASS__;
116: $instance = new $class();
117: }
118:
119: return $instance;
120: }
121:
122: 123: 124: 125: 126: 127: 128: 129: 130:
131: public 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:
142: return $editor;
143: }
144:
145: 146: 147: 148: 149: 150: 151:
152: public function getList($noHtml = false)
153: {
154: 155: 156: 157: 158:
159: if (!isset($this->root_path)) {
160: $this->root_path = XOOPS_ROOT_PATH . '/class/xoopseditor';
161: $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . '() should not be called statically.');
162: }
163:
164: xoops_load('XoopsCache');
165: $list = XoopsCache::read('editorlist');
166: if (empty($list)) {
167: $list = array();
168: $order = array();
169: xoops_load('XoopsLists');
170: $_list = XoopsLists::getDirListAsArray($this->root_path . '/');
171: foreach ($_list as $item) {
172: if (file_exists($file = $this->root_path . '/' . $item . '/language/' . $GLOBALS['xoopsConfig']['language'] . '.php')) {
173: include_once $file;
174: } elseif (file_exists($file = $this->root_path . '/' . $item . '/language/english.php')) {
175: include_once $file;
176: }
177: if (file_exists($file = $this->root_path . '/' . $item . '/editor_registry.php')) {
178: include $file;
179: if (empty($config['order'])) {
180: continue;
181: }
182: $order[] = $config['order'];
183: $list[$item] = array('title' => $config['title'], 'nohtml' => $config['nohtml']);
184: }
185: }
186: array_multisort($order, $list);
187: XoopsCache::write('editorlist', $list);
188: }
189:
190: $editors = array_keys($list);
191: if (!empty($this->allowed_editors)) {
192: $editors = array_intersect($editors, $this->allowed_editors);
193: }
194: $_list = array();
195: foreach ($editors as $name) {
196: if (!empty($noHtml) && empty($list[$name]['nohtml'])) {
197: continue;
198: }
199: $_list[$name] = $list[$name]['title'];
200: }
201:
202: return $_list;
203: }
204:
205: 206: 207: 208: 209: 210:
211: public function render($editor)
212: {
213: trigger_error(__CLASS__ . '::' . __FUNCTION__ . '() deprecated', E_USER_WARNING);
214:
215: return $editor->render();
216: }
217:
218: 219: 220: 221: 222: 223: 224:
225: public function setConfig($editor, $options)
226: {
227: if (method_exists($editor, 'setConfig')) {
228: $editor->setConfig($options);
229: } else {
230: foreach ($options as $key => $val) {
231: $editor->$key = $val;
232: }
233: }
234: }
235:
236: 237: 238: 239: 240: 241: 242:
243: public function _loadEditor($name, $options = null)
244: {
245: $editor = null;
246: if (empty($name) || !array_key_exists($name, $this->getList())) {
247: return $editor;
248: }
249: $editor_path = $this->root_path . '/' . $name;
250: if (file_exists($file = $editor_path . '/language/' . $GLOBALS['xoopsConfig']['language'] . '.php')) {
251: include_once $file;
252: } elseif (file_exists($file = $editor_path . '/language/english.php')) {
253: include_once $file;
254: }
255: if (file_exists($file = $editor_path . '/editor_registry.php')) {
256: include $file;
257: } else {
258: return $editor;
259: }
260: if (empty($config['order'])) {
261: return $editor;
262: }
263: include_once $config['file'];
264: $editor = new $config['class']($options);
265:
266: return $editor;
267: }
268: }
269: