TYPO3 CMS  TYPO3_7-6
Language.php
Go to the documentation of this file.
1 <?php
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 
23 
27 class Language extends RteHtmlAreaApi
28 {
34  protected $pluginName = 'Language';
35 
41  protected $pluginButtons = 'lefttoright,righttoleft,language,showlanguagemarks';
42 
49  'lefttoright' => 'LeftToRight',
50  'righttoleft' => 'RightToLeft',
51  'language' => 'Language',
52  'showlanguagemarks' => 'ShowLanguageMarks'
53  ];
54 
61  public function main(array $configuration)
62  {
63  if (!ExtensionManagementUtility::isLoaded('static_info_tables')) {
64  $this->pluginButtons = GeneralUtility::rmFromList('language', $this->pluginButtons);
65  }
66  return parent::main($configuration);
67  }
68 
74  public function buildJavascriptConfiguration()
75  {
76  $button = 'language';
77  $jsArray = [];
78  if (!is_array($this->configuration['thisConfig']['buttons.']) || !is_array($this->configuration['thisConfig']['buttons.'][$button . '.'])) {
79  $jsArray[] = 'RTEarea[editornumber].buttons.' . $button . ' = new Object();';
80  }
81  $languages = [
82  'none' => $this->getLanguageService()->sL(
83  'LLL:EXT:rtehtmlarea/Resources/Private/Language/Plugins/Language/locallang.xlf:No language mark'
84  ),
85  ];
86  $languages = array_flip(array_merge($languages, $this->getLanguages()));
87  $languagesJSArray = [];
88  foreach ($languages as $key => $value) {
89  $languagesJSArray[] = ['text' => $key, 'value' => $value];
90  }
91  $languagesJSArray = json_encode(['options' => $languagesJSArray]);
92  $jsArray[] = 'RTEarea[editornumber].buttons.' . $button . '.dataUrl = "' . $this->writeTemporaryFile($button . '_' . $this->configuration['contentLanguageUid'], 'js', $languagesJSArray) . '";';
93  return implode(LF, $jsArray);
94  }
95 
104  protected function getLanguages()
105  {
106  $databaseConnection = $this->getDatabaseConnection();
107  $nameArray = [];
108  if (ExtensionManagementUtility::isLoaded('static_info_tables')) {
109  $where = '1=1';
110  $table = 'static_languages';
111  $lang = LocalizationUtility::getCurrentLanguage();
112  $titleFields = LocalizationUtility::getLabelFields($table, $lang);
113  $prefixedTitleFields = [];
114  foreach ($titleFields as $titleField) {
115  $prefixedTitleFields[] = $table . '.' . $titleField;
116  }
117  $labelFields = implode(',', $prefixedTitleFields);
118  // Restrict to certain languages
119  if (is_array($this->configuration['thisConfig']['buttons.']) && is_array($this->configuration['thisConfig']['buttons.']['language.']) && isset($this->configuration['thisConfig']['buttons.']['language.']['restrictToItems'])) {
120  $languageList = implode('\',\'', GeneralUtility::trimExplode(',', $databaseConnection->fullQuoteStr(strtoupper($this->configuration['thisConfig']['buttons.']['language.']['restrictToItems']), $table)));
121  $where .= ' AND ' . $table . '.lg_iso_2 IN (' . $languageList . ')';
122  }
123  $res = $databaseConnection->exec_SELECTquery(
124  $table . '.lg_iso_2,' . $table . '.lg_country_iso_2,' . $labelFields,
125  $table,
126  $where . ' AND lg_constructed = 0 ' . BackendUtility::BEenableFields($table) . BackendUtility::deleteClause($table)
127  );
128  $prefixLabelWithCode = (bool)$this->configuration['thisConfig']['buttons.']['language.']['prefixLabelWithCode'];
129  $postfixLabelWithCode = (bool)$this->configuration['thisConfig']['buttons.']['language.']['postfixLabelWithCode'];
130  while ($row = $databaseConnection->sql_fetch_assoc($res)) {
131  $code = strtolower($row['lg_iso_2']) . ($row['lg_country_iso_2'] ? '-' . strtoupper($row['lg_country_iso_2']) : '');
132  foreach ($titleFields as $titleField) {
133  if ($row[$titleField]) {
134  $nameArray[$code] = $prefixLabelWithCode ? $code . ' - ' . $row[$titleField] : ($postfixLabelWithCode ? $row[$titleField] . ' - ' . $code : $row[$titleField]);
135  break;
136  }
137  }
138  }
139  $databaseConnection->sql_free_result($res);
140  uasort($nameArray, 'strcoll');
141  }
142  return $nameArray;
143  }
144 
151  public function applyToolbarConstraints($show)
152  {
153  if (!ExtensionManagementUtility::isLoaded('static_info_tables')) {
154  return array_diff($show, ['language']);
155  } else {
156  return $show;
157  }
158  }
159 
163  protected function getDatabaseConnection()
164  {
165  return $GLOBALS['TYPO3_DB'];
166  }
167 }
static BEenableFields($table, $inv=false)
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']
static deleteClause($table, $tableAlias='')