1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: namespace Xoops\Form;
13:
14: /**
15: * SelectEditor
16: *
17: * @category Xoops\Form\SelectEditor
18: * @package Xoops\Form
19: * @author Taiwen Jiang <phppp@users.sourceforge.net>
20: * @copyright 2001-2015 XOOPS Project (http://xoops.org)
21: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
22: * @link http://xoops.org
23: */
24: class SelectEditor extends ElementTray
25: {
26: /**
27: * @var array
28: */
29: public $allowed_editors = array();
30:
31: /**
32: * @var Form
33: */
34: public $form;
35:
36: /**
37: * @var string
38: */
39: public $value;
40:
41: /**
42: * @var string
43: */
44: public $name;
45:
46: /**
47: * @var bool
48: */
49: public $nohtml;
50:
51: /**
52: * Constructor
53: *
54: * @param Form $form the form calling the editor selection
55: * @param string $name editor name
56: * @param string $value Pre-selected text value
57: * @param boolean $nohtml dohtml disabled
58: * @param array $allowed_editors allowed editors
59: */
60: public function __construct(
61: Form $form,
62: $name = 'editor',
63: $value = null,
64: $nohtml = false,
65: $allowed_editors = array()
66: ) {
67: parent::__construct(\XoopsLocale::A_SELECT);
68: $this->allowed_editors = $allowed_editors;
69: $this->form = $form;
70: $this->name = $name;
71: $this->value = $value;
72: $this->nohtml = $nohtml;
73: }
74:
75: /**
76: * render
77: *
78: * @return string
79: */
80: public function render()
81: {
82: $editor_handler = \XoopsEditorHandler::getInstance();
83: $editor_handler->allowed_editors = $this->allowed_editors;
84: $option_select = new Select("", $this->name, $this->value);
85: $onchangeCode = '"if(this.options[this.selectedIndex].value.length > 0 ){window.document.forms.'
86: . $this->form->getName() . '.submit();}"';
87: $option_select->set('onchange', $onchangeCode);
88: $option_select->addOptionArray($editor_handler->getList($this->nohtml));
89: $this->addElement($option_select);
90: return parent::render();
91: }
92: }
93: