[BUGFIX] htmlArea RTE: TV CE editing not possible
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / extensions / Language / class.tx_rtehtmlarea_language.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008-2011 Stanislas Rolland <typo3(arobas)sjbr.ca>
6 * All rights reserved
7 *
8 * This script is part of the Typo3 project. The Typo3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24 /**
25 * Language plugin for htmlArea RTE
26 *
27 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
28 *
29 */
30 class tx_rtehtmlarea_language extends tx_rtehtmlarea_api {
31
32 protected $extensionKey = 'rtehtmlarea'; // The key of the extension that is extending htmlArea RTE
33 protected $pluginName = 'Language'; // The name of the plugin registered by the extension
34 protected $relativePathToLocallangFile = 'extensions/Language/locallang.xml'; // Path to this main locallang file of the extension relative to the extension dir.
35 protected $relativePathToSkin = 'extensions/Language/skin/htmlarea.css'; // Path to the skin (css) file relative to the extension dir.
36 protected $htmlAreaRTE; // Reference to the invoking object
37 protected $thisConfig; // Reference to RTE PageTSConfig
38 protected $toolbar; // Reference to RTE toolbar array
39 protected $LOCAL_LANG; // Frontend language array
40
41 protected $pluginButtons = 'lefttoright,righttoleft,language,showlanguagemarks';
42 protected $convertToolbarForHtmlAreaArray = array (
43 'lefttoright' => 'LeftToRight',
44 'righttoleft' => 'RightToLeft',
45 'language' => 'Language',
46 'showlanguagemarks' => 'ShowLanguageMarks',
47 );
48
49 public function main($parentObject) {
50 if (t3lib_extMgm::isLoaded('static_info_tables') && file_exists(t3lib_extMgm::extPath('static_info_tables') . 'class.tx_staticinfotables_div.php')) {
51 require_once(t3lib_extMgm::extPath('static_info_tables') . 'class.tx_staticinfotables_div.php');
52 } else {
53 $this->pluginButtons = t3lib_div::rmFromList('language', $this->pluginButtons);
54 }
55 return parent::main($parentObject);
56 }
57
58 /**
59 * Return JS configuration of the htmlArea plugins registered by the extension
60 *
61 * @param integer Relative id of the RTE editing area in the form
62 *
63 * @return string JS configuration for registered plugins
64 *
65 * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
66 * Each of the instructions should be of the form:
67 * RTEarea['.$RTEcounter.'].buttons.button-id.property = "value";
68 */
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 if ($this->htmlAreaRTE->is_FE()) {
88 $GLOBALS['TSFE']->csConvObj->convArray($languagesJSArray, $this->htmlAreaRTE->OutputCharset, 'utf-8');
89 } else {
90 $GLOBALS['LANG']->csConvObj->convArray($languagesJSArray, $GLOBALS['LANG']->charSet, 'utf-8');
91 }
92 $languagesJSArray = json_encode(array('options' => $languagesJSArray));
93 $registerRTEinJavascriptString .= '
94 RTEarea['.$RTEcounter.'].buttons.'. $button .'.dataUrl = "' . $this->htmlAreaRTE->writeTemporaryFile('', $button . '_' . $this->htmlAreaRTE->contentLanguageUid, 'js', $languagesJSArray) . '";';
95 return $registerRTEinJavascriptString;
96 }
97 /**
98 * Getting all languages into an array
99 * where the key is the ISO alpha-2 code of the language
100 * and where the value are the name of the language in the current language
101 * Note: we exclude sacred and constructed languages
102 *
103 * @return array An array of names of languages
104 */
105 function getLanguages() {
106 $nameArray = array();
107 if (t3lib_extMgm::isLoaded('static_info_tables')) {
108 $where = '1=1';
109 $table = 'static_languages';
110 $lang = tx_staticinfotables_div::getCurrentLanguage();
111 $titleFields = tx_staticinfotables_div::getTCAlabelField($table, TRUE, $lang);
112 $prefixedTitleFields = array();
113 foreach ($titleFields as $titleField) {
114 $prefixedTitleFields[] = $table.'.'.$titleField;
115 }
116 $labelFields = implode(',', $prefixedTitleFields);
117 // Restrict to certain languages
118 if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['language.']) && isset($this->thisConfig['buttons.']['language.']['restrictToItems'])) {
119 $languageList = implode("','", t3lib_div::trimExplode(',', $GLOBALS['TYPO3_DB']->fullQuoteStr(strtoupper($this->thisConfig['buttons.']['language.']['restrictToItems']), $table)));
120 $where .= ' AND '. $table . '.lg_iso_2 IN (' . $languageList . ')';
121 }
122 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
123 $table.'.lg_iso_2,'.$table.'.lg_country_iso_2,'.$labelFields,
124 $table,
125 $where.' AND lg_constructed = 0 '.
126 ($this->htmlAreaRTE->is_FE() ? $GLOBALS['TSFE']->sys_page->enableFields($table) : t3lib_BEfunc::BEenableFields($table) . t3lib_BEfunc::deleteClause($table))
127 );
128 $prefixLabelWithCode = !$this->thisConfig['buttons.']['language.']['prefixLabelWithCode'] ? FALSE : TRUE;
129 $postfixLabelWithCode = !$this->thisConfig['buttons.']['language.']['postfixLabelWithCode'] ? FALSE : TRUE;
130 while ($row = $GLOBALS['TYPO3_DB']->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 $GLOBALS['TYPO3_DB']->sql_free_result($res);
140 if ($this->htmlAreaRTE->is_FE()) {
141 $GLOBALS['TSFE']->csConvObj->convArray($nameArray, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['static_info_tables']['charset'], $this->htmlAreaRTE->OutputCharset);
142 } else {
143 $GLOBALS['LANG']->csConvObj->convArray($nameArray, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['static_info_tables']['charset'], $GLOBALS['LANG']->charSet);
144 }
145 uasort($nameArray, 'strcoll');
146 }
147 return $nameArray;
148 }
149
150 /**
151 * Return an updated array of toolbar enabled buttons
152 *
153 * @param array $show: array of toolbar elements that will be enabled, unless modified here
154 *
155 * @return array toolbar button array, possibly updated
156 */
157 public function applyToolbarConstraints($show) {
158 if (!t3lib_extMgm::isLoaded('static_info_tables')) {
159 return array_diff($show, array('language'));
160 } else {
161 return $show;
162 }
163 }
164 }
165 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/Language/class.tx_rtehtmlarea_language.php'])) {
166 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/Language/class.tx_rtehtmlarea_language.php']);
167 }
168 ?>