XOOPS  2.6.0
formtinymce.php
Go to the documentation of this file.
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 
25 //xoops_load('XoopsEditor');
26 
28 {
29  public $language;
30  public $width = "100%";
31  public $height = "500px";
32 
33  public $editor;
34 
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 
68  public function renderValidationJS()
69  {
70  if ($this->isRequired() && $eltname = $this->getName()) {
71  //$eltname = $this->getName();
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 
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 
121  public function render()
122  {
123  $ret = $this->editor->render();
124  $ret .= parent::render();
125 
126  return $ret;
127  }
128 
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 }
$current_path
Definition: config.php:3
const F_ENTER
Definition: en_US.php:408
__construct($configs)
Definition: formtinymce.php:40
defined('DS') or define('DS' DIRECTORY_SEPARATOR
Definition: common.php:41
if(DIRECTORY_SEPARATOR!="/") $xoops_root_path
Definition: config.php:7
static get($name)
const _LANGCODE
Definition: install.php:171