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 XoopsFormTinymce extends XoopsEditor
|
29: | {
|
30: | public $config;
|
31: | public $language;
|
32: | public $width = '100%';
|
33: | public $height = '500px';
|
34: |
|
35: | public $editor;
|
36: |
|
37: | |
38: | |
39: | |
40: | |
41: |
|
42: | public function __construct($configs)
|
43: | {
|
44: | $current_path = __FILE__;
|
45: | if (DIRECTORY_SEPARATOR !== '/') {
|
46: | $current_path = str_replace(strpos($current_path, "\\\\", 2) ? "\\\\" : DIRECTORY_SEPARATOR, '/', $current_path);
|
47: | }
|
48: |
|
49: | $this->rootPath = '/class/xoopseditor/tinymce';
|
50: | parent::__construct($configs);
|
51: | $this->configs['elements'] = $this->getName();
|
52: | $this->configs['language'] = $this->getLanguage();
|
53: | $this->configs['rootpath'] = $this->rootPath;
|
54: | $this->configs['area_width'] = isset($this->configs['width']) ? $this->configs['width'] : $this->width;
|
55: | $this->configs['area_height'] = isset($this->configs['height']) ? $this->configs['height'] : $this->height;
|
56: | $this->configs['fonts'] = $this->getFonts();
|
57: |
|
58: | require_once __DIR__ . '/tinymce.php';
|
59: | $this->editor = new TinyMCE($this->configs);
|
60: | }
|
61: |
|
62: | |
63: | |
64: | |
65: | |
66: | |
67: | |
68: | |
69: |
|
70: | public function renderValidationJS()
|
71: | {
|
72: | if ($this->isRequired() && $eltname = $this->getName()) {
|
73: |
|
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: | |
89: | |
90: | |
91: |
|
92: | public function getLanguage()
|
93: | {
|
94: | if ($this->language) {
|
95: | return $this->language;
|
96: | }
|
97: | if (defined('_XOOPS_EDITOR_TINYMCE_LANGUAGE')) {
|
98: | $this->language = strtolower(constant('_XOOPS_EDITOR_TINYMCE_LANGUAGE'));
|
99: | } else {
|
100: | $this->language = str_replace('_', '-', strtolower(_LANGCODE));
|
101: | if (strtolower(_CHARSET) === 'utf-8') {
|
102: | $this->language .= '_utf8';
|
103: | }
|
104: | }
|
105: |
|
106: | return $this->language;
|
107: | }
|
108: |
|
109: | |
110: | |
111: |
|
112: | public function getFonts()
|
113: | {
|
114: | if (empty($this->config['fonts']) && defined('_XOOPS_EDITOR_TINYMCE_FONTS')) {
|
115: | $this->config['fonts'] = constant('_XOOPS_EDITOR_TINYMCE_FONTS');
|
116: | }
|
117: |
|
118: | return isset($this->config['fonts']) ? $this->config['fonts'] : null;
|
119: | }
|
120: |
|
121: | |
122: | |
123: | |
124: | |
125: |
|
126: | public function render()
|
127: | {
|
128: | $ret = $this->editor->render();
|
129: | $ret .= parent::render();
|
130: |
|
131: | return $ret;
|
132: | }
|
133: |
|
134: | |
135: | |
136: | |
137: | |
138: |
|
139: | public function isActive()
|
140: | {
|
141: | return is_readable(XOOPS_ROOT_PATH . $this->rootPath . '/tinymce.php');
|
142: | }
|
143: | }
|
144: | |