1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: |
|
10: |
|
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: |
|
22: |
|
23: | xoops_load('XoopsEditor');
|
24: |
|
25: | |
26: | |
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: | |
38: | |
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/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: | |
62: | |
63: | |
64: | |
65: | |
66: | |
67: |
|
68: | public function renderValidationJS()
|
69: | {
|
70: | if ($this->isRequired() && $eltname = $this->getName()) {
|
71: |
|
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: | |
87: | |
88: | |
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: | |
109: | |
110: | |
111: |
|
112: | public function render()
|
113: | {
|
114: | $ret = $this->editor->render();
|
115: | $ret .= parent::render();
|
116: |
|
117: | return $ret;
|
118: | }
|
119: |
|
120: | |
121: | |
122: | |
123: | |
124: |
|
125: | public function isActive()
|
126: | {
|
127: | return is_readable(XOOPS_ROOT_PATH . $this->rootPath . '/tinymce5.php');
|
128: | }
|
129: | }
|
130: | |