1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
You may not change or alter any portion of this comment or credits |
5
|
|
|
of supporting developers from this source code or any supporting source code |
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
7
|
|
|
|
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
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* TinyMCE adapter for XOOPS |
15
|
|
|
* |
16
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
17
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU public license |
18
|
|
|
* @package class |
19
|
|
|
* @subpackage editor |
20
|
|
|
* @since 2.3.0 |
21
|
|
|
* @author Taiwen Jiang <[email protected]> |
22
|
|
|
* @version $Id: formtinymce.php 8066 2011-11-06 05:09:33Z beckmi $ |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
xoops_load('XoopsEditor'); |
26
|
|
|
|
27
|
|
View Code Duplication |
class XoopsFormTinymce4Bootstrap extends XoopsEditor |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
public $language; |
30
|
|
|
public $width = '100%'; |
31
|
|
|
public $height = '500px'; |
32
|
|
|
|
33
|
|
|
public $editor; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Constructor |
37
|
|
|
* |
38
|
|
|
* @param array $configs Editor Options |
39
|
|
|
*/ |
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/tinymce4bootstrap'; |
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
|
|
|
$this->configs['fonts'] = $this->getFonts(); |
56
|
|
|
|
57
|
|
|
require_once __DIR__ . '/tinymce.php'; |
58
|
|
|
$this->editor = new TinyMCE($this->configs); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Renders the Javascript function needed for client-side for validation |
63
|
|
|
* |
64
|
|
|
* I'VE USED THIS EXAMPLE TO WRITE VALIDATION CODE |
65
|
|
|
* http://tinymce.moxiecode.com/punbb/viewtopic.php?id=12616 |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
|
70
|
|
|
public function renderValidationJS() |
71
|
|
|
{ |
72
|
|
|
if ($this->isRequired() && $eltname = $this->getName()) { |
73
|
|
|
//$eltname = $this->getName(); |
74
|
|
|
$eltcaption = $this->getCaption(); |
75
|
|
|
$eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
76
|
|
|
$eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
77
|
|
|
$ret = "\n"; |
78
|
|
|
$ret .= "if ( tinyMCE.get('{$eltname}').getContent() == \"\" || tinyMCE.get('{$eltname}').getContent() == null) "; |
79
|
|
|
$ret .= "{ window.alert(\"{$eltmsg}\"); tinyMCE.get('{$eltname}').focus(); return false; }"; |
80
|
|
|
|
81
|
|
|
return $ret; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return ''; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* get language |
89
|
|
|
* |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
|
93
|
|
|
public function getLanguage() |
94
|
|
|
{ |
95
|
|
|
if ($this->language) { |
96
|
|
|
return $this->language; |
97
|
|
|
} |
98
|
|
|
if (defined('_XOOPS_EDITOR_TINYMCE4_LANGUAGE')) { |
99
|
|
|
$this->language = strtolower(constant('_XOOPS_EDITOR_TINYMCE4_LANGUAGE')); |
100
|
|
|
} else { |
101
|
|
|
$this->language = str_replace('_', '-', strtolower(_LANGCODE)); |
102
|
|
|
if ('utf-8' === strtolower(_CHARSET)) { |
103
|
|
|
$this->language .= '_utf8'; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return $this->language; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function getFonts() |
|
|
|
|
111
|
|
|
{ |
112
|
|
|
if (empty($this->config['fonts']) && defined('_XOOPS_EDITOR_TINYMCE4_FONTS')) { |
113
|
|
|
$this->config['fonts'] = constant('_XOOPS_EDITOR_TINYMCE4_FONTS'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return @$this->config['fonts']; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* prepare HTML for output |
121
|
|
|
* |
122
|
|
|
* @return sting HTML |
123
|
|
|
*/ |
|
|
|
|
124
|
|
|
|
125
|
|
|
public function render() |
126
|
|
|
{ |
127
|
|
|
$ret = $this->editor->render(); |
128
|
|
|
$ret .= parent::render(); |
129
|
|
|
|
130
|
|
|
return $ret; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Check if compatible |
135
|
|
|
* |
136
|
|
|
* @return bool |
137
|
|
|
*/ |
138
|
|
|
|
139
|
|
|
public function isActive() |
140
|
|
|
{ |
141
|
|
|
return is_readable(XOOPS_ROOT_PATH . $this->rootPath . '/tinymce.php'); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.