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