[TASK] RTE: Remove unused css files
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / Extension / Language.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\Core\Utility\ExtensionManagementUtility;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Rtehtmlarea\RteHtmlAreaApi;
20 use TYPO3\CMS\Rtehtmlarea\RteHtmlAreaBase;
21
22 /**
23 * Language plugin for htmlArea RTE
24 *
25 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
26 */
27 class Language extends RteHtmlAreaApi {
28
29 /**
30 * The name of the plugin registered by the extension
31 *
32 * @var string
33 */
34 protected $pluginName = 'Language';
35
36 /**
37 * The comma-separated list of button names that the registered plugin is adding to the htmlArea RTE toolbar
38 *
39 * @var string
40 */
41 protected $pluginButtons = 'lefttoright,righttoleft,language,showlanguagemarks';
42
43 /**
44 * The name-converting array, converting the button names used in the RTE PageTSConfing to the button id's used by the JS scripts
45 *
46 * @var array
47 */
48 protected $convertToolbarForHtmlAreaArray = array(
49 'lefttoright' => 'LeftToRight',
50 'righttoleft' => 'RightToLeft',
51 'language' => 'Language',
52 'showlanguagemarks' => 'ShowLanguageMarks'
53 );
54
55 /**
56 * Returns TRUE if the plugin is available and correctly initialized
57 *
58 * @param RteHtmlAreaBase $parentObject parent object
59 * @return bool TRUE if this plugin object should be made available in the current environment and is correctly initialized
60 */
61 public function main($parentObject) {
62 if (!ExtensionManagementUtility::isLoaded('static_info_tables')) {
63 $this->pluginButtons = GeneralUtility::rmFromList('language', $this->pluginButtons);
64 }
65 return parent::main($parentObject);
66 }
67
68 /**
69 * Return JS configuration of the htmlArea plugins registered by the extension
70 *
71 * @param string $rteNumberPlaceholder A dummy string for JS arrays
72 * @return string JS configuration for registered plugins
73 */
74 public function buildJavascriptConfiguration($rteNumberPlaceholder) {
75 $button = 'language';
76 $registerRTEinJavascriptString = '';
77 if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][($button . '.')])) {
78 $registerRTEinJavascriptString .= '
79 RTEarea[' . $rteNumberPlaceholder . '].buttons.' . $button . ' = new Object();';
80 }
81 if ($this->htmlAreaRTE->is_FE()) {
82 $first = $GLOBALS['TSFE']->getLLL('No language mark', $this->LOCAL_LANG);
83 } else {
84 $first = $GLOBALS['LANG']->getLL('No language mark');
85 }
86 $languages = array('none' => $first);
87 $languages = array_flip(array_merge($languages, $this->getLanguages()));
88 $languagesJSArray = array();
89 foreach ($languages as $key => $value) {
90 $languagesJSArray[] = array('text' => $key, 'value' => $value);
91 }
92 $languagesJSArray = json_encode(array('options' => $languagesJSArray));
93 $registerRTEinJavascriptString .= '
94 RTEarea[' . $rteNumberPlaceholder . '].buttons.' . $button . '.dataUrl = "' . ($this->htmlAreaRTE->is_FE() && $GLOBALS['TSFE']->absRefPrefix ? $GLOBALS['TSFE']->absRefPrefix : '') . $this->htmlAreaRTE->writeTemporaryFile('', ($button . '_' . $this->htmlAreaRTE->contentLanguageUid), 'js', $languagesJSArray) . '";';
95 return $registerRTEinJavascriptString;
96 }
97
98 /**
99 * Getting all languages into an array
100 * where the key is the ISO alpha-2 code of the language
101 * and where the value are the name of the language in the current language
102 * Note: we exclude sacred and constructed languages
103 *
104 * @return array An array of names of languages
105 */
106 public function getLanguages() {
107 $nameArray = array();
108 if (ExtensionManagementUtility::isLoaded('static_info_tables')) {
109 $where = '1=1';
110 $table = 'static_languages';
111 $lang = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getCurrentLanguage();
112 $titleFields = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getLabelFields($table, $lang);
113 $prefixedTitleFields = array();
114 foreach ($titleFields as $titleField) {
115 $prefixedTitleFields[] = $table . '.' . $titleField;
116 }
117 $labelFields = implode(',', $prefixedTitleFields);
118 // Restrict to certain languages
119 if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['language.']) && isset($this->thisConfig['buttons.']['language.']['restrictToItems'])) {
120 $languageList = implode('\',\'', GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_DB']->fullQuoteStr(strtoupper($this->thisConfig['buttons.']['language.']['restrictToItems']), $table)));
121 $where .= ' AND ' . $table . '.lg_iso_2 IN (' . $languageList . ')';
122 }
123 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($table . '.lg_iso_2,' . $table . '.lg_country_iso_2,' . $labelFields, $table, $where . ' AND lg_constructed = 0 ' . ($this->htmlAreaRTE->is_FE() ? $GLOBALS['TSFE']->sys_page->enableFields($table) : \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields($table) . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table)));
124 $prefixLabelWithCode = (bool)$this->thisConfig['buttons.']['language.']['prefixLabelWithCode'];
125 $postfixLabelWithCode = (bool)$this->thisConfig['buttons.']['language.']['postfixLabelWithCode'];
126 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
127 $code = strtolower($row['lg_iso_2']) . ($row['lg_country_iso_2'] ? '-' . strtoupper($row['lg_country_iso_2']) : '');
128 foreach ($titleFields as $titleField) {
129 if ($row[$titleField]) {
130 $nameArray[$code] = $prefixLabelWithCode ? $code . ' - ' . $row[$titleField] : ($postfixLabelWithCode ? $row[$titleField] . ' - ' . $code : $row[$titleField]);
131 break;
132 }
133 }
134 }
135 $GLOBALS['TYPO3_DB']->sql_free_result($res);
136 uasort($nameArray, 'strcoll');
137 }
138 return $nameArray;
139 }
140
141 /**
142 * Return an updated array of toolbar enabled buttons
143 *
144 * @param array $show: array of toolbar elements that will be enabled, unless modified here
145 * @return array toolbar button array, possibly updated
146 */
147 public function applyToolbarConstraints($show) {
148 if (!ExtensionManagementUtility::isLoaded('static_info_tables')) {
149 return array_diff($show, array('language'));
150 } else {
151 return $show;
152 }
153 }
154
155 }