1: | <?php |
2: | /** |
3: | * XOOPS Form Class Elements |
4: | * |
5: | * You may not change or alter any portion of this comment or credits |
6: | * of supporting developers from this source code or any supporting source code |
7: | * which is considered copyrighted (c) material of the original comment or credit authors. |
8: | * This program is distributed in the hope that it will be useful, |
9: | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10: | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11: | * |
12: | * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
13: | * @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html) |
14: | * @package kernel |
15: | * @subpackage form |
16: | * @since 2.0.0 |
17: | * @author Taiwen Jiang <phppp@users.sourceforge.net> |
18: | */ |
19: | defined('XOOPS_ROOT_PATH') || exit('Restricted access'); |
20: | |
21: | xoops_load('XoopsFormTextArea'); |
22: | |
23: | /** |
24: | * XOOPS Form Editor |
25: | * |
26: | */ |
27: | class XoopsFormEditor extends XoopsFormTextArea |
28: | { |
29: | public $editor; |
30: | |
31: | /** |
32: | * Constructor |
33: | * |
34: | * @param string $caption Caption |
35: | * @param string $name Name for textarea field |
36: | * @param array $configs configures: editor - editor identifier; name - textarea field name; width, height - dimensions for textarea; value - text content |
37: | * @param bool $nohtml use non-WYSIWYG editor onfailure |
38: | * @param string $OnFailure editor to be used if current one failed |
39: | * |
40: | */ |
41: | public function __construct($caption, $name, $configs = null, $nohtml = false, $OnFailure = '') |
42: | { |
43: | // Backward compatibility: $name -> editor name; $configs['name'] -> textarea field name |
44: | if (!isset($configs['editor'])) { |
45: | $configs['editor'] = $name; |
46: | $name = $configs['name']; |
47: | // New: $name -> textarea field name; $configs['editor'] -> editor name; $configs['name'] -> textarea field name |
48: | } else { |
49: | $configs['name'] = $name; |
50: | } |
51: | parent::__construct($caption, $name); |
52: | xoops_load('XoopsEditorHandler'); |
53: | $editor_handler = XoopsEditorHandler::getInstance(); |
54: | $this->editor = $editor_handler->get($configs['editor'], $configs, $nohtml, $OnFailure); |
55: | } |
56: | |
57: | /** |
58: | * renderValidationJS |
59: | * TEMPORARY SOLUTION to 'override' original renderValidationJS method |
60: | * with custom XoopsEditor's renderValidationJS method |
61: | */ |
62: | public function renderValidationJS() |
63: | { |
64: | if (is_object($this->editor) && $this->isRequired()) { |
65: | if (method_exists($this->editor, 'renderValidationJS')) { |
66: | $this->editor->setName($this->getName()); |
67: | $this->editor->setCaption($this->getCaption()); |
68: | $this->editor->_required = $this->isRequired(); |
69: | $ret = $this->editor->renderValidationJS(); |
70: | |
71: | return $ret; |
72: | } else { |
73: | parent::renderValidationJS(); |
74: | } |
75: | } |
76: | |
77: | return false; |
78: | } |
79: | |
80: | /** |
81: | * XoopsFormEditor::render() |
82: | * |
83: | * @return string|null |
84: | */ |
85: | public function render() |
86: | { |
87: | if (is_object($this->editor)) { |
88: | return $this->editor->render(); |
89: | } |
90: | return null; |
91: | } |
92: | } |
93: |