TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
RteHtmlAreaApi.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Rtehtmlarea;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 
25 abstract class RteHtmlAreaApi
26 {
32  protected $extensionKey = 'rtehtmlarea';
33 
39  protected $pluginName;
40 
46  protected $relativePathToSkin = '';
47 
53  protected $toolbar;
54 
60  protected $pluginButtons = '';
61 
67  protected $pluginLabels = '';
68 
74  protected $pluginAddsButtons = true;
75 
82 
88  protected $requiresClassesConfiguration = false;
89 
95  protected $requiredPlugins = '';
96 
102  protected $configuration;
103 
110  public function main(array $configuration)
111  {
112  $this->configuration = $configuration;
113  // Set the value of this boolean based on the initial value of $this->pluginButtons
114  $this->pluginAddsButtons = !empty($this->pluginButtons);
115  // Check if the plugin should be disabled in frontend
116  if ($this->isFrontend() && !empty($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['plugins'][$this->pluginName]['disableInFE'])) {
117  return false;
118  }
119  return true;
120  }
121 
128  {
129  $jsArray = [];
130  $pluginButtons = GeneralUtility::trimExplode(',', $this->pluginButtons, true);
131  foreach ($pluginButtons as $button) {
132  if (in_array($button, $this->toolbar)) {
133  if (!is_array($this->configuration['thisConfig']['buttons.']) || !is_array($this->configuration['thisConfig']['buttons.'][$button . '.'])) {
134  $jsArray[] = 'RTEarea[editornumber].buttons.' . $button . ' = new Object();';
135  }
136  }
137  }
138  return implode(LF, $jsArray);
139  }
140 
146  public function getExtensionKey()
147  {
148  return $this->extensionKey;
149  }
150 
156  public function addsButtons()
157  {
159  }
160 
166  public function getPluginButtons()
167  {
168  return $this->pluginButtons;
169  }
170 
176  public function getPluginLabels()
177  {
178  return $this->pluginLabels;
179  }
180 
187  {
189  }
190 
197  {
199  }
200 
206  public function getRequiredPlugins()
207  {
208  return $this->requiredPlugins;
209  }
210 
216  public function setToolbar(array $toolbar)
217  {
218  $this->toolbar = $toolbar;
219  }
220 
227  protected function cleanList($str)
228  {
229  if (strstr($str, '*')) {
230  $str = '*';
231  } else {
232  $str = implode(',', array_unique(GeneralUtility::trimExplode(',', $str, true)));
233  }
234  return $str;
235  }
236 
243  protected function getPageConfigLabel($string)
244  {
245  $label = $this->getLanguageService()->sL(trim($string));
246  // @todo: find out why this is done and if it could be substituted with quoteJSvalue
247  $label = str_replace('"', '\\"', str_replace('\\\'', '\'', $label));
248  return $label;
249  }
250 
256  protected function isFrontend()
257  {
258  return is_object($GLOBALS['TSFE'])
259  && !$this->isFrontendEditActive()
260  && TYPO3_MODE == 'FE';
261  }
262 
268  protected function isFrontendEditActive()
269  {
270  return is_object($GLOBALS['TSFE'])
271  && $GLOBALS['TSFE']->beUserLogin
272  && $GLOBALS['BE_USER']->frontendEdit instanceof FrontendEditingController;
273  }
274 
284  protected function writeTemporaryFile($label, $fileExtension = 'js', $contents = '')
285  {
286  $relativeFilename = 'typo3temp/assets/js/rte_' . str_replace('-', '_', $label) . '_' . GeneralUtility::shortMD5($contents, 20) . '.' . $fileExtension;
287  $destination = PATH_site . $relativeFilename;
288  if (!file_exists($destination)) {
289  $minifiedJavaScript = '';
290  if ($fileExtension === 'js' && $contents !== '') {
291  $minifiedJavaScript = GeneralUtility::minifyJavaScript($contents);
292  }
293  $failure = GeneralUtility::writeFileToTypo3tempDir($destination, $minifiedJavaScript ? $minifiedJavaScript : $contents);
294  if ($failure) {
295  throw new \RuntimeException($failure, 1294585668);
296  }
297  }
298  return PathUtility::getAbsoluteWebPath($destination);
299  }
300 
306  protected function getLanguageService()
307  {
308  return $GLOBALS['LANG'];
309  }
310 }
static minifyJavaScript($script, &$error= '')
writeTemporaryFile($label, $fileExtension= 'js', $contents= '')
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static writeFileToTypo3tempDir($filepath, $content)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:40