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: * Editor - an editor element
16: *
17: * @category Xoops\Form\Editor
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: * @since 2.0.0
24: */
25: class Editor extends TextArea
26: {
27: /**
28: * @var null|object
29: */
30: public $editor;
31:
32: /**
33: * Constructor
34: *
35: * @param string $caption Caption
36: * @param string $name Name for textarea field
37: * @param array|null $configs configuration - keys:
38: * editor - editor identifier
39: * name - textarea field name
40: * width, height - dimensions for textarea
41: * value - text content
42: * @param bool $nohtml use non-WYSIWYG editor onfailure
43: * @param string $OnFailure editor to be used if current one failed
44: */
45: public function __construct($caption, $name, $configs = null, $nohtml = false, $OnFailure = '')
46: {
47: // Backward compatibility: $name -> editor name; $configs['name'] -> textarea field name
48: if (!isset($configs['editor'])) {
49: $configs['editor'] = $name;
50: $name = $configs['name'];
51: // New: $name -> textarea field name;
52: // $configs['editor'] -> editor name;
53: // $configs['name'] -> textarea field name
54: } else {
55: $configs['name'] = $name;
56: }
57: parent::__construct($caption, $name);
58: $editor_handler = \XoopsEditorHandler::getInstance();
59: $this->editor = $editor_handler->get($configs['editor'], $configs, $nohtml, $OnFailure);
60: }
61:
62: /**
63: * renderValidationJS
64: * TEMPORARY SOLUTION to 'override' original renderValidationJS method
65: * with custom XoopsEditor's renderValidationJS method
66: *
67: * @return string|false
68: */
69: public function renderValidationJS()
70: {
71: if ($this->editor instanceof \XoopsEditor && $this->isRequired()) {
72: if (method_exists($this->editor, 'renderValidationJS')) {
73: $this->editor->setName($this->getName());
74: $this->editor->setCaption($this->getCaption());
75: $this->editor->setRequired($this->isRequired());
76: $ret = $this->editor->renderValidationJS();
77: return $ret;
78: } else {
79: parent::renderValidationJS();
80: }
81: }
82: return false;
83: }
84:
85: /**
86: * render
87: *
88: * @return string
89: */
90: public function render()
91: {
92: if ($this->editor instanceof \XoopsEditor) {
93: return $this->editor->render();
94: }
95: return '';
96: }
97: }
98: