Added feature #10182: htmlArea RTE: Add support for editing lang attribute
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / extensions / Language / class.tx_rtehtmlarea_language.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008-2009 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
33 require_once(t3lib_extMgm::extPath('rtehtmlarea').'class.tx_rtehtmlareaapi.php');
34
35 class tx_rtehtmlarea_language extends tx_rtehtmlareaapi {
36
37 protected $extensionKey = 'rtehtmlarea'; // The key of the extension that is extending htmlArea RTE
38 protected $pluginName = 'Language'; // The name of the plugin registered by the extension
39 protected $relativePathToLocallangFile = 'extensions/Language/locallang.xml'; // Path to this main locallang file of the extension relative to the extension dir.
40 protected $relativePathToSkin = 'extensions/Language/skin/htmlarea.css'; // Path to the skin (css) file relative to the extension dir.
41 protected $htmlAreaRTE; // Reference to the invoking object
42 protected $thisConfig; // Reference to RTE PageTSConfig
43 protected $toolbar; // Reference to RTE toolbar array
44 protected $LOCAL_LANG; // Frontend language array
45
46 protected $pluginButtons = 'lefttoright,righttoleft,language,showlanguagemarks';
47 protected $convertToolbarForHtmlAreaArray = array (
48 'lefttoright' => 'LeftToRight',
49 'righttoleft' => 'RightToLeft',
50 'language' => 'Language',
51 'showlanguagemarks' => 'ShowLanguageMarks',
52 );
53
54 public function main($parentObject) {
55 if (!t3lib_extMgm::isLoaded('static_info_tables')) {
56 $this->pluginButtons = t3lib_div::rmFromList('language', $this->pluginButtons);
57 } else {
58 require_once(t3lib_extMgm::extPath('static_info_tables').'class.tx_staticinfotables_div.php');
59 }
60 return parent::main($parentObject);
61 }
62
63 /**
64 * Return JS configuration of the htmlArea plugins registered by the extension
65 *
66 * @param integer Relative id of the RTE editing area in the form
67 *
68 * @return string JS configuration for registered plugins
69 *
70 * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
71 * Each of the instructions should be of the form:
72 * RTEarea['.$RTEcounter.'].buttons.button-id.property = "value";
73 */
74 public function buildJavascriptConfiguration($RTEcounter) {
75 global $TSFE, $LANG;
76
77 $registerRTEinJavascriptString = '';
78 if (in_array('language', $this->toolbar)) {
79 if (!is_array( $this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.']['language.'])) {
80 $registerRTEinJavascriptString .= '
81 RTEarea['.$RTEcounter.'].buttons.language = new Object();';
82 }
83 $prefixLabelWithCode = !$this->thisConfig['buttons.']['language.']['prefixLabelWithCode'] ? false : true;
84 $postfixLabelWithCode = !$this->thisConfig['buttons.']['language.']['postfixLabelWithCode'] ? false : true;
85 $languageCodes = t3lib_div::trimExplode(',', $this->thisConfig['buttons.']['language.']['items'] ? $this->thisConfig['buttons.']['language.']['items'] : 'en', 1);
86 $labelsArray = $this->getStaticInfoName(implode(',', $languageCodes));
87 if ($this->htmlAreaRTE->is_FE()) {
88 $first = $GLOBALS['TSFE']->getLLL('No language mark',$this->LOCAL_LANG);
89 } else {
90 $first = $GLOBALS['LANG']->getLL('No language mark');
91 }
92 // Generating the JavaScript options
93 $languageOptions = '{
94 "'. $first.'" : "none"';
95 foreach ($languageCodes as $index => $code) {
96 $label = ($prefixLabelWithCode ? ($code . ' - ') : '') . $labelsArray[$index] . ($postfixLabelWithCode ? (' - ' . $code) : '');
97 $label = (!$this->htmlAreaRTE->is_FE() && $this->htmlAreaRTE->TCEform->inline->isAjaxCall) ? $GLOBALS['LANG']->csConvObj->utf8_encode($label, $GLOBALS['LANG']->charSet) : $label;
98 $languageOptions .= ',
99 "' . $label . '" : "' . $code . '"';
100 }
101 $languageOptions .= '};';
102
103 $registerRTEinJavascriptString .= '
104 RTEarea['.$RTEcounter.'].buttons.language.dropDownOptions = '. $languageOptions;
105 }
106 return $registerRTEinJavascriptString;
107 }
108
109 /**
110 * Getting the name of a language
111 * We assume that the Static Info Tables are in
112 *
113 * @param string $code: the ISO alpha-2 code of a language; or a comma-separated list of such
114 * @param boolean $local: local name only - if set local title is returned
115 * @return array names of the language(s) in the current language
116 */
117 function getStaticInfoName($code, $local=FALSE) {
118 $table = 'static_languages';
119 $lang = tx_staticinfotables_div::getCurrentLanguage();
120 if (!t3lib_extMgm::isLoaded('static_info_tables_'.strtolower($lang))) {
121 $lang = '';
122 }
123 $codeArray = t3lib_div::trimExplode(',', $code);
124 $namesArray = array();
125 foreach ($codeArray as $isoCode){
126 $isoCodeArray = t3lib_div::trimExplode( '_', $isoCode, 1);
127 $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, $lang, $local);
128 if (!$name && $lang != 'EN') {
129 // use the default English name if there is not text in another language
130 $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, '', $local);
131 }
132 if ($this->htmlAreaRTE->is_FE()) {
133 $namesArray[] = $GLOBALS['TSFE']->csConvObj->conv($name, 'utf-8', $this->htmlAreaRTE->OutputCharset);
134 } else {
135 $namesArray[] = $GLOBALS['LANG']->csConvObj->conv($name, 'utf-8', $this->htmlAreaRTE->OutputCharset);
136 }
137 }
138 return $namesArray;
139 }
140
141 } // end of class
142
143 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/Language/class.tx_rtehtmlarea_language.php']) {
144 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/Language/class.tx_rtehtmlarea_language.php']);
145 }
146
147 ?>