| 1: | <?php | 
| 2: | /** | 
| 3: | * Formatted textarea form | 
| 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-2017 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 Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/ | 
| 18: | * @author Taiwen Jiang <phppp@users.sourceforge.net> | 
| 19: | * @author Vinod <smartvinu@gmail.com> | 
| 20: | */ | 
| 21: | defined('XOOPS_ROOT_PATH') || exit('Restricted access'); | 
| 22: | |
| 23: | /** | 
| 24: | * base class | 
| 25: | */ | 
| 26: | xoops_load('XoopsFormTextArea'); | 
| 27: | |
| 28: | /** | 
| 29: | * A textarea with xoopsish formatting and smilie buttons | 
| 30: | * | 
| 31: | */ | 
| 32: | class XoopsFormDhtmlTextArea extends XoopsFormTextArea | 
| 33: | { | 
| 34: | /** | 
| 35: | * Extended HTML editor | 
| 36: | * | 
| 37: | * <p>If an extended HTML editor is set, the renderer will be replaced by the specified editor, usually a visual or WYSIWYG editor.</p> | 
| 38: | * | 
| 39: | * <ul>Developer and user guide: | 
| 40: | * <li><ul>For run-time settings per call | 
| 41: | * <li>To use an editor pre-configured by {@link XoopsEditor}, e.g. 'fckeditor': <code>$options['editor'] = 'fckeditor';</code></li> | 
| 42: | * <li>To use a custom editor, e.g. 'MyEditor' class located in "/modules/myeditor/myeditor.php": <code>$options['editor'] = array('MyEditor', XOOPS_ROOT_PATH . "/modules/myeditor/myeditor.php");</code></li> | 
| 43: | * </ul></li> | 
| 44: | * <li><ul>For pre-configured settings, which will force to use an editor if no specific editor is set for call | 
| 45: | * <li><ul>Set up custom configs: in XOOPS_VAR_PATH . '/configs/xoopsconfig.php' set an editor as default, e.g. | 
| 46: | * <li>a pre-configured editor 'fckeditor': <code>return array('editor' => 'fckeditor');</code></li> | 
| 47: | * <li>a custom editor 'MyEditor' class located in "/modules/myeditor/myeditor.php": <code>return array('editor' => array('MyEditor', XOOPS_ROOT_PATH . "/modules/myeditor/myeditor.php");</code></li> | 
| 48: | * </ul></li> | 
| 49: | * <li>To disable the default editor, in XOOPS_VAR_PATH . '/configs/xoopsconfig.php': <code>return array();</code></li> | 
| 50: | * <li>To disable the default editor for a specific call: <code>$options['editor'] = 'dhtmltextarea';</code></li> | 
| 51: | * </ul></li> | 
| 52: | * </ul> | 
| 53: | */ | 
| 54: | public $htmlEditor = array(); | 
| 55: | |
| 56: | /** | 
| 57: | * Hidden text | 
| 58: | * | 
| 59: | * @var string | 
| 60: | * @access private | 
| 61: | */ | 
| 62: | public $_hiddenText; | 
| 63: | |
| 64: | public $skipPreview = false; | 
| 65: | public $doHtml = false; | 
| 66: | public $js = ''; | 
| 67: | |
| 68: | /** | 
| 69: | * Constructor | 
| 70: | * | 
| 71: | * @param string $caption Caption | 
| 72: | * @param string $name "name" attribute | 
| 73: | * @param string $value Initial text | 
| 74: | * @param int $rows Number of rows | 
| 75: | * @param int $cols Number of columns | 
| 76: | * @param string $hiddentext Identifier for hidden Text | 
| 77: | * @param array $options Extra options | 
| 78: | */ | 
| 79: | public function __construct($caption, $name, $value = '', $rows = 5, $cols = 50, $hiddentext = 'xoopsHiddenText', $options = array()) | 
| 80: | { | 
| 81: | global $xoopsConfig; | 
| 82: | static $inLoop = 0; | 
| 83: | |
| 84: | ++$inLoop; | 
| 85: | // Second loop, invalid, return directly | 
| 86: | if ($inLoop > 2) { | 
| 87: | return null; | 
| 88: | } | 
| 89: | // Else, initialize | 
| 90: | parent::__construct($caption, $name, $value, $rows, $cols); | 
| 91: | $this->_hiddenText = $hiddentext; | 
| 92: | |
| 93: | if ($inLoop > 1) { | 
| 94: | return null; | 
| 95: | } | 
| 96: | if (!isset($options['editor'])) { | 
| 97: | if (isset($xoopsConfig['editor'])) { | 
| 98: | $options['editor'] = $xoopsConfig['editor']; | 
| 99: | } | 
| 100: | } | 
| 101: | |
| 102: | if (!empty($this->htmlEditor) || !empty($options['editor'])) { | 
| 103: | $options['name'] = $this->getName(); | 
| 104: | $options['value'] = $this->getValue(); | 
| 105: | if (!empty($options['editor'])) { | 
| 106: | $this->htmlEditor = is_array($options['editor']) ? $options['editor'] : array($options['editor']); | 
| 107: | } | 
| 108: | |
| 109: | if (count($this->htmlEditor) == 1) { | 
| 110: | xoops_load('XoopsEditorHandler'); | 
| 111: | $editor_handler = XoopsEditorHandler::getInstance(); | 
| 112: | $this->htmlEditor = $editor_handler->get($this->htmlEditor[0], $options); | 
| 113: | if ($inLoop > 1) { | 
| 114: | $this->htmlEditor = null; | 
| 115: | } | 
| 116: | } else { | 
| 117: | list($class, $path) = $this->htmlEditor; | 
| 118: | include_once XOOPS_ROOT_PATH . $path; | 
| 119: | if (class_exists($class)) { | 
| 120: | $this->htmlEditor = new $class($options); | 
| 121: | } | 
| 122: | if ($inLoop > 1) { | 
| 123: | $this->htmlEditor = null; | 
| 124: | } | 
| 125: | } | 
| 126: | } | 
| 127: | |
| 128: | $inLoop = 0; | 
| 129: | } | 
| 130: | |
| 131: | /** | 
| 132: | * Prepare HTML for output | 
| 133: | * | 
| 134: | * @return string HTML | 
| 135: | */ | 
| 136: | public function render() | 
| 137: | { | 
| 138: | if ($this->htmlEditor && is_object($this->htmlEditor)) { | 
| 139: | if (!isset($this->htmlEditor->isEnabled) || $this->htmlEditor->isEnabled) { | 
| 140: | return $this->htmlEditor->render(); | 
| 141: | } | 
| 142: | } | 
| 143: | |
| 144: | return XoopsFormRenderer::getInstance()->get()->renderFormDhtmlTextArea($this); | 
| 145: | } | 
| 146: | |
| 147: | /** | 
| 148: | * XoopsFormDhtmlTextArea::renderValidationJS() | 
| 149: | * | 
| 150: | * @return bool|string | 
| 151: | */ | 
| 152: | public function renderValidationJS() | 
| 153: | { | 
| 154: | if ($this->htmlEditor && is_object($this->htmlEditor) && method_exists($this->htmlEditor, 'renderValidationJS')) { | 
| 155: | if (!isset($this->htmlEditor->isEnabled) || $this->htmlEditor->isEnabled) { | 
| 156: | return $this->htmlEditor->renderValidationJS(); | 
| 157: | } | 
| 158: | } | 
| 159: | |
| 160: | return parent::renderValidationJS(); | 
| 161: | } | 
| 162: | } | 
| 163: |