|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2008-2011 Stanislas Rolland <typo3(arobas)sjbr.ca> 00006 * All rights reserved 00007 * 00008 * This script is part of the Typo3 project. The Typo3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 /** 00025 * Language plugin for htmlArea RTE 00026 * 00027 * @author Stanislas Rolland <typo3(arobas)sjbr.ca> 00028 * 00029 * TYPO3 SVN ID: $Id: class.tx_rtehtmlarea_language.php 10361 2011-02-01 16:48:34Z stan $ 00030 * 00031 */ 00032 class tx_rtehtmlarea_language extends tx_rtehtmlarea_api { 00033 00034 protected $extensionKey = 'rtehtmlarea'; // The key of the extension that is extending htmlArea RTE 00035 protected $pluginName = 'Language'; // The name of the plugin registered by the extension 00036 protected $relativePathToLocallangFile = 'extensions/Language/locallang.xml'; // Path to this main locallang file of the extension relative to the extension dir. 00037 protected $relativePathToSkin = 'extensions/Language/skin/htmlarea.css'; // Path to the skin (css) file relative to the extension dir. 00038 protected $htmlAreaRTE; // Reference to the invoking object 00039 protected $thisConfig; // Reference to RTE PageTSConfig 00040 protected $toolbar; // Reference to RTE toolbar array 00041 protected $LOCAL_LANG; // Frontend language array 00042 00043 protected $pluginButtons = 'lefttoright,righttoleft,language,showlanguagemarks'; 00044 protected $convertToolbarForHtmlAreaArray = array ( 00045 'lefttoright' => 'LeftToRight', 00046 'righttoleft' => 'RightToLeft', 00047 'language' => 'Language', 00048 'showlanguagemarks' => 'ShowLanguageMarks', 00049 ); 00050 00051 public function main($parentObject) { 00052 if (!t3lib_extMgm::isLoaded('static_info_tables')) { 00053 $this->pluginButtons = t3lib_div::rmFromList('language', $this->pluginButtons); 00054 } else { 00055 require_once(t3lib_extMgm::extPath('static_info_tables').'class.tx_staticinfotables_div.php'); 00056 } 00057 return parent::main($parentObject); 00058 } 00059 00060 /** 00061 * Return JS configuration of the htmlArea plugins registered by the extension 00062 * 00063 * @param integer Relative id of the RTE editing area in the form 00064 * 00065 * @return string JS configuration for registered plugins 00066 * 00067 * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s) 00068 * Each of the instructions should be of the form: 00069 * RTEarea['.$RTEcounter.'].buttons.button-id.property = "value"; 00070 */ 00071 public function buildJavascriptConfiguration($RTEcounter) { 00072 $button = 'language'; 00073 $registerRTEinJavascriptString = ''; 00074 if (!is_array( $this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][$button . '.'])) { 00075 $registerRTEinJavascriptString .= ' 00076 RTEarea['.$RTEcounter.'].buttons.'. $button .' = new Object();'; 00077 } 00078 if ($this->htmlAreaRTE->is_FE()) { 00079 $first = $GLOBALS['TSFE']->getLLL('No language mark',$this->LOCAL_LANG); 00080 } else { 00081 $first = $GLOBALS['LANG']->getLL('No language mark'); 00082 } 00083 $languages = array('none' => $first); 00084 $languages = array_flip(array_merge($languages, $this->getLanguages())); 00085 $languagesJSArray = array(); 00086 foreach ($languages as $key => $value) { 00087 $languagesJSArray[] = array('text' => $key, 'value' => $value); 00088 } 00089 if ($this->htmlAreaRTE->is_FE()) { 00090 $GLOBALS['TSFE']->csConvObj->convArray($languagesJSArray, $this->htmlAreaRTE->OutputCharset, 'utf-8'); 00091 } else { 00092 $GLOBALS['LANG']->csConvObj->convArray($languagesJSArray, $GLOBALS['LANG']->charSet, 'utf-8'); 00093 } 00094 $languagesJSArray = json_encode(array('options' => $languagesJSArray)); 00095 $registerRTEinJavascriptString .= ' 00096 RTEarea['.$RTEcounter.'].buttons.'. $button .'.dataUrl = "' . $this->htmlAreaRTE->writeTemporaryFile('', $button . '_' . $this->htmlAreaRTE->contentLanguageUid, 'js', $languagesJSArray) . '";'; 00097 return $registerRTEinJavascriptString; 00098 } 00099 /** 00100 * Getting all languages into an array 00101 * where the key is the ISO alpha-2 code of the language 00102 * and where the value are the name of the language in the current language 00103 * Note: we exclude sacred and constructed languages 00104 * 00105 * @return array An array of names of languages 00106 */ 00107 function getLanguages() { 00108 $nameArray = array(); 00109 if (t3lib_extMgm::isLoaded('static_info_tables')) { 00110 $where = '1=1'; 00111 $table = 'static_languages'; 00112 $lang = tx_staticinfotables_div::getCurrentLanguage(); 00113 $titleFields = tx_staticinfotables_div::getTCAlabelField($table, TRUE, $lang); 00114 $prefixedTitleFields = array(); 00115 foreach ($titleFields as $titleField) { 00116 $prefixedTitleFields[] = $table.'.'.$titleField; 00117 } 00118 $labelFields = implode(',', $prefixedTitleFields); 00119 // Restrict to certain languages 00120 if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['language.']) && isset($this->thisConfig['buttons.']['language.']['restrictToItems'])) { 00121 $languageList = implode("','", t3lib_div::trimExplode(',', $GLOBALS['TYPO3_DB']->fullQuoteStr(strtoupper($this->thisConfig['buttons.']['language.']['restrictToItems']), $table))); 00122 $where .= ' AND '. $table . '.lg_iso_2 IN (' . $languageList . ')'; 00123 } 00124 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 00125 $table.'.lg_iso_2,'.$table.'.lg_country_iso_2,'.$labelFields, 00126 $table, 00127 $where.' AND lg_constructed = 0 '. 00128 ($this->htmlAreaRTE->is_FE() ? $GLOBALS['TSFE']->sys_page->enableFields($table) : t3lib_BEfunc::BEenableFields($table) . t3lib_BEfunc::deleteClause($table)) 00129 ); 00130 $prefixLabelWithCode = !$this->thisConfig['buttons.']['language.']['prefixLabelWithCode'] ? false : true; 00131 $postfixLabelWithCode = !$this->thisConfig['buttons.']['language.']['postfixLabelWithCode'] ? false : true; 00132 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00133 $code = strtolower($row['lg_iso_2']).($row['lg_country_iso_2']?'-'.strtoupper($row['lg_country_iso_2']):''); 00134 foreach ($titleFields as $titleField) { 00135 if ($row[$titleField]) { 00136 $nameArray[$code] = $prefixLabelWithCode ? ($code . ' - ' . $row[$titleField]) : ($postfixLabelWithCode ? ($row[$titleField] . ' - ' . $code) : $row[$titleField]); 00137 break; 00138 } 00139 } 00140 } 00141 $GLOBALS['TYPO3_DB']->sql_free_result($res); 00142 if ($this->htmlAreaRTE->is_FE()) { 00143 $GLOBALS['TSFE']->csConvObj->convArray($nameArray, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['static_info_tables']['charset'], $this->htmlAreaRTE->OutputCharset); 00144 } else { 00145 $GLOBALS['LANG']->csConvObj->convArray($nameArray, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['static_info_tables']['charset'], $GLOBALS['LANG']->charSet); 00146 } 00147 uasort($nameArray, 'strcoll'); 00148 } 00149 return $nameArray; 00150 } 00151 00152 /** 00153 * Return an updated array of toolbar enabled buttons 00154 * 00155 * @param array $show: array of toolbar elements that will be enabled, unless modified here 00156 * 00157 * @return array toolbar button array, possibly updated 00158 */ 00159 public function applyToolbarConstraints($show) { 00160 if (!t3lib_extMgm::isLoaded('static_info_tables')) { 00161 return array_diff($show, array('language')); 00162 } else { 00163 return $show; 00164 } 00165 } 00166 } 00167 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/Language/class.tx_rtehtmlarea_language.php'])) { 00168 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/Language/class.tx_rtehtmlarea_language.php']); 00169 } 00170 ?>
1.8.0