TYPO3 CMS  TYPO3_6-2
Language.php
Go to the documentation of this file.
1 <?php
3 
22 
23  protected $extensionKey = 'rtehtmlarea';
24 
25  // The key of the extension that is extending htmlArea RTE
26  protected $pluginName = 'Language';
27 
28  // The name of the plugin registered by the extension
29  protected $relativePathToLocallangFile = 'extensions/Language/locallang.xlf';
30 
31  // Path to this main locallang file of the extension relative to the extension dir.
32  protected $relativePathToSkin = 'extensions/Language/skin/htmlarea.css';
33 
34  // Path to the skin (css) file relative to the extension dir.
35  protected $htmlAreaRTE;
36 
37  // Reference to the invoking object
38  protected $thisConfig;
39 
40  // Reference to RTE PageTSConfig
41  protected $toolbar;
42 
43  // Reference to RTE toolbar array
44  protected $LOCAL_LANG;
45 
46  // Frontend language array
47  protected $pluginButtons = 'lefttoright,righttoleft,language,showlanguagemarks';
48 
50  'lefttoright' => 'LeftToRight',
51  'righttoleft' => 'RightToLeft',
52  'language' => 'Language',
53  'showlanguagemarks' => 'ShowLanguageMarks'
54  );
55 
56  public function main($parentObject) {
57  if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables')) {
58  $this->pluginButtons = \TYPO3\CMS\Core\Utility\GeneralUtility::rmFromList('language', $this->pluginButtons);
59  }
60  return parent::main($parentObject);
61  }
62 
69  public function buildJavascriptConfiguration($RTEcounter) {
70  $button = 'language';
71  $registerRTEinJavascriptString = '';
72  if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][($button . '.')])) {
73  $registerRTEinJavascriptString .= '
74  RTEarea[' . $RTEcounter . '].buttons.' . $button . ' = new Object();';
75  }
76  if ($this->htmlAreaRTE->is_FE()) {
77  $first = $GLOBALS['TSFE']->getLLL('No language mark', $this->LOCAL_LANG);
78  } else {
79  $first = $GLOBALS['LANG']->getLL('No language mark');
80  }
81  $languages = array('none' => $first);
82  $languages = array_flip(array_merge($languages, $this->getLanguages()));
83  $languagesJSArray = array();
84  foreach ($languages as $key => $value) {
85  $languagesJSArray[] = array('text' => $key, 'value' => $value);
86  }
87  $languagesJSArray = json_encode(array('options' => $languagesJSArray));
88  $registerRTEinJavascriptString .= '
89  RTEarea[' . $RTEcounter . '].buttons.' . $button . '.dataUrl = "' . ($this->htmlAreaRTE->is_FE() && $GLOBALS['TSFE']->absRefPrefix ? $GLOBALS['TSFE']->absRefPrefix : '') . $this->htmlAreaRTE->writeTemporaryFile('', ($button . '_' . $this->htmlAreaRTE->contentLanguageUid), 'js', $languagesJSArray) . '";';
90  return $registerRTEinJavascriptString;
91  }
92 
102  public function getLanguages() {
103  $nameArray = array();
104  if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables')) {
105  $where = '1=1';
106  $table = 'static_languages';
107  $lang = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getCurrentLanguage();
108  $titleFields = \SJBR\StaticInfoTables\Utility\LocalizationUtility::getLabelFields($table, $lang);
109  $prefixedTitleFields = array();
110  foreach ($titleFields as $titleField) {
111  $prefixedTitleFields[] = $table . '.' . $titleField;
112  }
113  $labelFields = implode(',', $prefixedTitleFields);
114  // Restrict to certain languages
115  if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['language.']) && isset($this->thisConfig['buttons.']['language.']['restrictToItems'])) {
116  $languageList = implode('\',\'', \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_DB']->fullQuoteStr(strtoupper($this->thisConfig['buttons.']['language.']['restrictToItems']), $table)));
117  $where .= ' AND ' . $table . '.lg_iso_2 IN (' . $languageList . ')';
118  }
119  $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)));
120  $prefixLabelWithCode = (boolean)$this->thisConfig['buttons.']['language.']['prefixLabelWithCode'];
121  $postfixLabelWithCode = (boolean)$this->thisConfig['buttons.']['language.']['postfixLabelWithCode'];
122  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
123  $code = strtolower($row['lg_iso_2']) . ($row['lg_country_iso_2'] ? '-' . strtoupper($row['lg_country_iso_2']) : '');
124  foreach ($titleFields as $titleField) {
125  if ($row[$titleField]) {
126  $nameArray[$code] = $prefixLabelWithCode ? $code . ' - ' . $row[$titleField] : ($postfixLabelWithCode ? $row[$titleField] . ' - ' . $code : $row[$titleField]);
127  break;
128  }
129  }
130  }
131  $GLOBALS['TYPO3_DB']->sql_free_result($res);
132  uasort($nameArray, 'strcoll');
133  }
134  return $nameArray;
135  }
136 
143  public function applyToolbarConstraints($show) {
144  if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables')) {
145  return array_diff($show, array('language'));
146  } else {
147  return $show;
148  }
149  }
150 
151 }
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static deleteClause($table, $tableAlias='')