TYPO3 CMS  TYPO3_7-6
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() && $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 
281  protected function getFullFileName($filename)
282  {
283  if (substr($filename, 0, 4) === 'EXT:') {
284  // extension
285  list($extKey, $local) = explode('/', substr($filename, 4), 2);
286  $newFilename = '';
287  if ((string)$extKey !== '' && ExtensionManagementUtility::isLoaded($extKey) && (string)$local !== '') {
288  $newFilename = ($this->isFrontend() || $this->isFrontendEditActive()
291  . $local;
292  }
293  } else {
294  $path = ($this->isFrontend() || $this->isFrontendEditActive() ? '' : '../');
295  $newFilename = $path . ($filename[0] === '/' ? substr($filename, 1) : $filename);
296  }
297  return GeneralUtility::resolveBackPath($newFilename);
298  }
299 
309  protected function writeTemporaryFile($label, $fileExtension = 'js', $contents = '')
310  {
311  $relativeFilename = 'typo3temp/RteHtmlArea/' . str_replace('-', '_', $label) . '_' . GeneralUtility::shortMD5($contents, 20) . '.' . $fileExtension;
312  $destination = PATH_site . $relativeFilename;
313  if (!file_exists($destination)) {
314  $minifiedJavaScript = '';
315  if ($fileExtension === 'js' && $contents !== '') {
316  $minifiedJavaScript = GeneralUtility::minifyJavaScript($contents);
317  }
318  $failure = GeneralUtility::writeFileToTypo3tempDir($destination, $minifiedJavaScript ? $minifiedJavaScript : $contents);
319  if ($failure) {
320  throw new \RuntimeException($failure, 1294585668);
321  }
322  }
323  if ($this->isFrontend() || $this->isFrontendEditActive()) {
324  $fileName = $relativeFilename;
325  } else {
326  $fileName = '../' . $relativeFilename;
327  }
328  return GeneralUtility::resolveBackPath($fileName);
329  }
330 
336  protected function getLanguageService()
337  {
338  return $GLOBALS['LANG'];
339  }
340 }
static minifyJavaScript($script, &$error='')
static writeFileToTypo3tempDir($filepath, $content)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
writeTemporaryFile($label, $fileExtension='js', $contents='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']