forked from mambax7/tinymce5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformtinymce5.php
More file actions
129 lines (114 loc) · 3.82 KB
/
formtinymce5.php
File metadata and controls
129 lines (114 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* TinyMCE5 adapter for XOOPS
*
* @category XoopsEditor
* @package TinyMCE5
* @author Gregory Mage
* @author Taiwen Jiang <phppp@users.sourceforge.net>
* @copyright 2020 XOOPS Project (http://xoops.org)
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
* @link http://xoops.org
*/
xoops_load('XoopsEditor');
/**
* Class XoopsFormTinymce
*/
class XoopsFormTinymce5 extends XoopsEditor
{
public $language;
public $width = '100%';
public $height = '500px';
public $editor;
/**
* Constructor
*
* @param array $configs Editor Options
*/
public function __construct($configs)
{
$current_path = __FILE__;
if (DIRECTORY_SEPARATOR !== '/') {
$current_path = str_replace(strpos($current_path, "\\\\", 2) ? "\\\\" : DIRECTORY_SEPARATOR, '/', $current_path);
}
$this->rootPath = '/class/xoopseditor/tinymce5';
parent::__construct($configs);
$this->configs['elements'] = $this->getName();
$this->configs['language'] = $this->getLanguage();
$this->configs['rootpath'] = $this->rootPath;
$this->configs['area_width'] = isset($this->configs['width']) ? $this->configs['width'] : $this->width;
$this->configs['area_height'] = isset($this->configs['height']) ? $this->configs['height'] : $this->height;
require_once __DIR__ . '/tinymce5.php';
$this->editor = new TinyMCE($this->configs);
}
/**
* Renders the Javascript function needed for client-side for validation
*
* I'VE USED THIS EXAMPLE TO WRITE VALIDATION CODE
* http://tinymce.moxiecode.com/punbb/viewtopic.php?id=12616
*
* @return string
*/
public function renderValidationJS()
{
if ($this->isRequired() && $eltname = $this->getName()) {
//$eltname = $this->getName();
$eltcaption = $this->getCaption();
$eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption);
$eltmsg = str_replace('"', '\"', stripslashes($eltmsg));
$ret = "\n";
$ret .= "if ( tinyMCE.get('{$eltname}').getContent() == \"\" || tinyMCE.get('{$eltname}').getContent() == null) ";
$ret .= "{ window.alert(\"{$eltmsg}\"); tinyMCE.get('{$eltname}').focus(); return false; }";
return $ret;
}
return '';
}
/**
* get language
*
* @return string
*/
public function getLanguage()
{
if ($this->language) {
return $this->language;
}
if (defined('_XOOPS_EDITOR_TINYMCE5_LANGUAGE')) {
$this->language = strtolower(constant('_XOOPS_EDITOR_TINYMCE5_LANGUAGE'));
} else {
$this->language = str_replace('_', '-', strtolower(_LANGCODE));
if (strtolower(_CHARSET) === 'utf-8') {
$this->language .= '_utf8';
}
}
return $this->language;
}
/**
* prepare HTML for output
*
* @return string HTML
*/
public function render()
{
$ret = $this->editor->render();
$ret .= parent::render();
return $ret;
}
/**
* Check if compatible
*
* @return bool
*/
public function isActive()
{
return is_readable(XOOPS_ROOT_PATH . $this->rootPath . '/tinymce5.php');
}
}