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 $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/tinymce';
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: 63: 64: 65: 66: 67: 68:
69: public function renderValidationJS()
70: {
71: if ($this->isRequired() && $eltname = $this->getName()) {
72:
73: $eltcaption = $this->getCaption();
74: $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption);
75: $eltmsg = str_replace('"', '\"', stripslashes($eltmsg));
76: $ret = "\n";
77: $ret .= "if ( tinyMCE.get('{$eltname}').getContent() == \"\" || tinyMCE.get('{$eltname}').getContent() == null) ";
78: $ret .= "{ window.alert(\"{$eltmsg}\"); tinyMCE.get('{$eltname}').focus(); return false; }";
79:
80: return $ret;
81: }
82:
83: return '';
84: }
85:
86: 87: 88: 89: 90:
91: public function getLanguage()
92: {
93: if ($this->language) {
94: return $this->language;
95: }
96: if (defined('_XOOPS_EDITOR_TINYMCE_LANGUAGE')) {
97: $this->language = strtolower(constant('_XOOPS_EDITOR_TINYMCE_LANGUAGE'));
98: } else {
99: $this->language = str_replace('_', '-', strtolower(_LANGCODE));
100: if (strtolower(_CHARSET) === 'utf-8') {
101: $this->language .= '_utf8';
102: }
103: }
104:
105: return $this->language;
106: }
107:
108: 109: 110:
111: public function getFonts()
112: {
113: if (empty($this->config['fonts']) && defined('_XOOPS_EDITOR_TINYMCE_FONTS')) {
114: $this->config['fonts'] = constant('_XOOPS_EDITOR_TINYMCE_FONTS');
115: }
116:
117: return @$this->config['fonts'];
118: }
119:
120: 121: 122: 123: 124:
125: public function render()
126: {
127: $ret = $this->editor->render();
128: $ret .= parent::render();
129:
130: return $ret;
131: }
132:
133: 134: 135: 136: 137:
138: public function isActive()
139: {
140: return is_readable(XOOPS_ROOT_PATH . $this->rootPath . '/tinymce.php');
141: }
142: }
143: