[TASK] Make Backend Ajax URLs absolute
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / Extension / Spellchecker.php
1 <?php
2 namespace TYPO3\CMS\Rtehtmlarea\Extension;
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
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18
19 /**
20 * Spell Checker plugin for htmlArea RTE
21 *
22 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
23 */
24 class Spellchecker extends \TYPO3\CMS\Rtehtmlarea\RteHtmlAreaApi {
25
26 /**
27 * The key of the extension that is extending htmlArea RTE
28 *
29 * @var string
30 */
31 protected $extensionKey = 'rtehtmlarea';
32
33 /**
34 * The name of the plugin registered by the extension
35 *
36 * @var string
37 */
38 protected $pluginName = 'SpellChecker';
39
40 /**
41 * Path to this main locallang file of the extension relative to the extension directory
42 *
43 * @var string
44 */
45 protected $relativePathToLocallangFile = '';
46
47 /**
48 * Path to the skin file relative to the extension directory
49 *
50 * @var string
51 */
52 protected $relativePathToSkin = 'Resources/Public/Css/Skin/Plugins/spell-checker.css';
53
54 /**
55 * Reference to the invoking object
56 *
57 * @var \TYPO3\CMS\Rtehtmlarea\RteHtmlAreaBase
58 */
59 protected $htmlAreaRTE;
60
61 protected $thisConfig;
62
63 // Reference to RTE PageTSConfig
64 protected $toolbar;
65
66 // Reference to RTE toolbar array
67 protected $LOCAL_LANG;
68
69 // Frontend language array
70 protected $pluginButtons = 'spellcheck';
71
72 protected $convertToolbarForHtmlAreaArray = array(
73 'spellcheck' => 'SpellCheck'
74 );
75
76 protected $spellCheckerModes = array('ultra', 'fast', 'normal', 'bad-spellers');
77
78 public function main($parentObject) {
79 return parent::main($parentObject) && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables') && !in_array($this->htmlAreaRTE->language, \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->htmlAreaRTE->ID]['plugins'][$pluginName]['noSpellCheckLanguages'])) && ($this->htmlAreaRTE->contentCharset == 'iso-8859-1' || $this->htmlAreaRTE->contentCharset == 'utf-8');
80 }
81
82 /**
83 * Return JS configuration of the htmlArea plugins registered by the extension
84 *
85 * @param int Relative id of the RTE editing area in the form
86 * @return string JS configuration for registered plugins
87 */
88 public function buildJavascriptConfiguration($RTEcounter) {
89 $button = 'spellcheck';
90 // Set the SpellChecker mode
91 $spellCheckerMode = isset($GLOBALS['BE_USER']->userTS['options.']['HTMLAreaPspellMode']) ? trim($GLOBALS['BE_USER']->userTS['options.']['HTMLAreaPspellMode']) : 'normal';
92 if (!in_array($spellCheckerMode, $this->spellCheckerModes)) {
93 $spellCheckerMode = 'normal';
94 }
95 // Set the use of personal dictionary
96 $enablePersonalDicts = $this->thisConfig['buttons.'][$button . '.']['enablePersonalDictionaries'] ? (isset($GLOBALS['BE_USER']->userTS['options.']['enablePersonalDicts']) && $GLOBALS['BE_USER']->userTS['options.']['enablePersonalDicts'] ? TRUE : FALSE) : FALSE;
97 if ($this->htmlAreaRTE->is_FE()) {
98 $enablePersonalDicts = FALSE;
99 }
100 $registerRTEinJavascriptString = '';
101 if (in_array($button, $this->toolbar)) {
102 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][($button . '.')])) {
103 $registerRTEinJavascriptString .= '
104 RTEarea[' . $RTEcounter . '].buttons.' . $button . ' = new Object();';
105 }
106 $registerRTEinJavascriptString .= '
107 RTEarea[' . $RTEcounter . '].buttons.' . $button . '.contentTypo3Language = "' . $this->htmlAreaRTE->contentTypo3Language . '";
108 RTEarea[' . $RTEcounter . '].buttons.' . $button . '.contentISOLanguage = "' . $this->htmlAreaRTE->contentISOLanguage . '";
109 RTEarea[' . $RTEcounter . '].buttons.' . $button . '.contentCharset = "' . $this->htmlAreaRTE->contentCharset . '";
110 RTEarea[' . $RTEcounter . '].buttons.' . $button . '.spellCheckerMode = "' . $spellCheckerMode . '";
111 RTEarea[' . $RTEcounter . '].buttons.' . $button . '.enablePersonalDicts = ' . ($enablePersonalDicts ? 'true' : 'false') . ';';
112 $registerRTEinJavascriptString .= '
113 RTEarea[' . $RTEcounter . '].buttons.' . $button . '.path = "' . ($this->htmlAreaRTE->is_FE() || $this->htmlAreaRTE->isFrontendEditActive() ? ($GLOBALS['TSFE']->absRefPrefix ? $GLOBALS['TSFE']->absRefPrefix : '') . 'index.php?eID=rtehtmlarea_spellchecker' : BackendUtility::getAjaxUrl('rtehtmlarea::spellchecker')) . '";';
114 }
115 return $registerRTEinJavascriptString;
116 }
117
118 }