1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
24:
25:
26:
27: class XoopsFormTinymce4 extends XoopsEditor
28: {
29: public $language;
30: public $width = "100%";
31: public $height = "500px";
32:
33: public $editor;
34:
35: 36: 37: 38: 39:
40: public function __construct($configs)
41: {
42: $current_path = __FILE__;
43: if (DIRECTORY_SEPARATOR !== "/") {
44: $current_path = str_replace(strpos($current_path, "\\\\", 2) ? "\\\\" : DIRECTORY_SEPARATOR, "/", $current_path);
45: }
46:
47: $this->rootPath = "/class/xoopseditor/tinymce4";
48: parent::__construct($configs);
49: $this->configs["elements"] = $this->getName();
50: $this->configs["language"] = $this->getLanguage();
51: $this->configs["rootpath"] = $this->rootPath;
52: $this->configs["area_width"] = isset($this->configs["width"]) ? $this->configs["width"] : $this->width;
53: $this->configs["area_height"] = isset($this->configs["height"]) ? $this->configs["height"] : $this->height;
54: $this->configs["fonts"] = $this->getFonts();
55:
56: require_once __DIR__ . "/tinymce.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(XoopsLocale::F_ENTER, $eltname) : sprintf(XoopsLocale::F_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_TINYMCE4_LANGUAGE")) {
96: $this->language = strtolower(constant("_XOOPS_EDITOR_TINYMCE4_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: public function getFonts()
108: {
109: if (empty($this->config["fonts"]) && defined("_XOOPS_EDITOR_TINYMCE4_FONTS")) {
110: $this->config["fonts"] = constant("_XOOPS_EDITOR_TINYMCE4_FONTS");
111: }
112:
113: return @$this->config["fonts"];
114: }
115:
116: 117: 118: 119: 120:
121: public function render()
122: {
123: $ret = $this->editor->render();
124: $ret .= parent::render();
125:
126: return $ret;
127: }
128:
129: 130: 131: 132: 133:
134: public function isActive()
135: {
136: $xoops_root_path = \XoopsBaseConfig::get('root-path');
137: return is_readable($xoops_root_path . $this->rootPath . "/tinymce.php");
138: }
139: }
140: