Fixed bug #16574: PHP notices from XCLASS inclusions
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / extensions / Language / class.tx_rtehtmlarea_language.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008-2010 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 * TYPO3 SVN ID: $Id$
30 *
31 */
32 class tx_rtehtmlarea_language extends tx_rtehtmlarea_api {
33
34 protected $extensionKey = 'rtehtmlarea'; // The key of the extension that is extending htmlArea RTE
35 protected $pluginName = 'Language'; // The name of the plugin registered by the extension
36 protected $relativePathToLocallangFile = 'extensions/Language/locallang.xml'; // Path to this main locallang file of the extension relative to the extension dir.
37 protected $relativePathToSkin = 'extensions/Language/skin/htmlarea.css'; // Path to the skin (css) file relative to the extension dir.
38 protected $htmlAreaRTE; // Reference to the invoking object
39 protected $thisConfig; // Reference to RTE PageTSConfig
40 protected $toolbar; // Reference to RTE toolbar array
41 protected $LOCAL_LANG; // Frontend language array
42
43 protected $pluginButtons = 'lefttoright,righttoleft,language,showlanguagemarks';
44 protected $convertToolbarForHtmlAreaArray = array (
45 'lefttoright' => 'LeftToRight',
46 'righttoleft' => 'RightToLeft',
47 'language' => 'Language',
48 'showlanguagemarks' => 'ShowLanguageMarks',
49 );
50
51 public function main($parentObject) {
52 if (!t3lib_extMgm::isLoaded('static_info_tables')) {
53 $this->pluginButtons = t3lib_div::rmFromList('language', $this->pluginButtons);
54 } else {
55 require_once(t3lib_extMgm::extPath('static_info_tables').'class.tx_staticinfotables_div.php');
56 }
57 return parent::main($parentObject);
58 }
59
60 /**
61 * Return JS configuration of the htmlArea plugins registered by the extension
62 *
63 * @param integer Relative id of the RTE editing area in the form
64 *
65 * @return string JS configuration for registered plugins
66 *
67 * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
68 * Each of the instructions should be of the form:
69 * RTEarea['.$RTEcounter.'].buttons.button-id.property = "value";
70 */
71 public function buildJavascriptConfiguration($RTEcounter) {
72 $button = 'language';
73 $registerRTEinJavascriptString = '';
74 if (in_array($button, $this->toolbar)) {
75 if (!is_array( $this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][$button . '.'])) {
76 $registerRTEinJavascriptString .= '
77 RTEarea['.$RTEcounter.'].buttons.'. $button .' = new Object();';
78 }
79 if ($this->htmlAreaRTE->is_FE()) {
80 $first = $GLOBALS['TSFE']->getLLL('No language mark',$this->LOCAL_LANG);
81 } else {
82 $first = $GLOBALS['LANG']->getLL('No language mark');
83 }
84 $languages = array('none' => $first);
85 $languages = array_flip(array_merge($languages, $this->getLanguages()));
86 $languagesJSArray = array();
87 foreach ($languages as $key => $value) {
88 $languagesJSArray[] = array('text' => $key, 'value' => $value);
89 }
90 if ($this->htmlAreaRTE->is_FE()) {
91 $GLOBALS['TSFE']->csConvObj->convArray($languagesJSArray, $this->htmlAreaRTE->OutputCharset, 'utf-8');
92 } else {
93 $GLOBALS['LANG']->csConvObj->convArray($languagesJSArray, $GLOBALS['LANG']->charSet, 'utf-8');
94 }
95 $languagesJSArray = json_encode(array('options' => $languagesJSArray));
96 $registerRTEinJavascriptString .= '
97 RTEarea['.$RTEcounter.'].buttons.'. $button .'.dataUrl = "' . $this->htmlAreaRTE->writeTemporaryFile('', $button . '_' . $this->htmlAreaRTE->contentLanguageUid, 'js', $languagesJSArray) . '";';
98 }
99 return $registerRTEinJavascriptString;
100 }
101 /**
102 * Getting all languages into an array
103 * where the key is the ISO alpha-2 code of the language
104 * and where the value are the name of the language in the current language
105 * Note: we exclude sacred and constructed languages
106 *
107 * @return array An array of names of languages
108 */
109 function getLanguages() {
110 $where = '1=1';
111 $table = 'static_languages';
112 $lang = tx_staticinfotables_div::getCurrentLanguage();
113 $nameArray = array();
114 $titleFields = tx_staticinfotables_div::getTCAlabelField($table, TRUE, $lang);
115 $prefixedTitleFields = array();
116 foreach ($titleFields as $titleField) {
117 $prefixedTitleFields[] = $table.'.'.$titleField;
118 }
119 $labelFields = implode(',', $prefixedTitleFields);
120 // Restrict to certain languages
121 if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['language.']) && isset($this->thisConfig['buttons.']['language.']['restrictToItems'])) {
122 $languageList = implode("','", t3lib_div::trimExplode(',', $GLOBALS['TYPO3_DB']->fullQuoteStr(strtoupper($this->thisConfig['buttons.']['language.']['restrictToItems']), $table)));
123 $where .= ' AND '. $table . '.lg_iso_2 IN (' . $languageList . ')';
124 }
125 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
126 $table.'.lg_iso_2,'.$table.'.lg_country_iso_2,'.$labelFields,
127 $table,
128 $where.' AND lg_constructed = 0 '.
129 ($this->htmlAreaRTE->is_FE() ? $GLOBALS['TSFE']->sys_page->enableFields($table) : t3lib_BEfunc::BEenableFields($table) . t3lib_BEfunc::deleteClause($table))
130 );
131 $prefixLabelWithCode = !$this->thisConfig['buttons.']['language.']['prefixLabelWithCode'] ? false : true;
132 $postfixLabelWithCode = !$this->thisConfig['buttons.']['language.']['postfixLabelWithCode'] ? false : true;
133 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
134 $code = strtolower($row['lg_iso_2']).($row['lg_country_iso_2']?'-'.strtoupper($row['lg_country_iso_2']):'');
135 foreach ($titleFields as $titleField) {
136 if ($row[$titleField]) {
137 $nameArray[$code] = $prefixLabelWithCode ? ($code . ' - ' . $row[$titleField]) : ($postfixLabelWithCode ? ($row[$titleField] . ' - ' . $code) : $row[$titleField]);
138 break;
139 }
140 }
141 }
142 $GLOBALS['TYPO3_DB']->sql_free_result($res);
143 if ($this->htmlAreaRTE->is_FE()) {
144 $GLOBALS['TSFE']->csConvObj->convArray($nameArray, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['static_info_tables']['charset'], $this->htmlAreaRTE->OutputCharset);
145 } else {
146 $GLOBALS['LANG']->csConvObj->convArray($nameArray, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['static_info_tables']['charset'], $GLOBALS['LANG']->charSet);
147 }
148 uasort($nameArray, 'strcoll');
149 return $nameArray;
150 }
151
152 /**
153 * Return an updated array of toolbar enabled buttons
154 *
155 * @param array $show: array of toolbar elements that will be enabled, unless modified here
156 *
157 * @return array toolbar button array, possibly updated
158 */
159 public function applyToolbarConstraints($show) {
160 if (!t3lib_extMgm::isLoaded('static_info_tables')) {
161 return array_diff($show, array('language'));
162 } else {
163 return $show;
164 }
165 }
166 }
167 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/Language/class.tx_rtehtmlarea_language.php'])) {
168 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/Language/class.tx_rtehtmlarea_language.php']);
169 }
170 ?>