|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /* ************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) webservices.nl 00006 * (c) 2006-2010 Karsten Dambekalns <karsten@typo3.org> 00007 * All rights reserved 00008 * 00009 * This script is part of the TYPO3 project. The TYPO3 project is 00010 * free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * The GNU General Public License can be found at 00016 * http://www.gnu.org/copyleft/gpl.html. 00017 * A copy is found in the textfile GPL.txt and important notices to the license 00018 * from the author is found in LICENSE.txt distributed with these scripts. 00019 * 00020 * 00021 * This script is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00024 * GNU General Public License for more details. 00025 * 00026 * This copyright notice MUST APPEAR in all copies of the script! 00027 ***************************************************************/ 00028 /* $Id: class.tx_em_translations.php 2018 2010-03-14 12:25:58Z steffenk $ */ 00029 00030 /** 00031 * Class for handling translations 00032 * 00033 */ 00034 class tx_em_Translations { 00035 00036 00037 protected $parentObject; 00038 protected $terConnection; 00039 00040 00041 /** 00042 * Constructor 00043 * 00044 * @param object $parentObject 00045 * @return void 00046 */ 00047 public function __construct($parentObject) { 00048 $this->parentObject = $parentObject; 00049 $this->terConnection = t3lib_div::makeInstance('tx_em_Connection_Ter', $this); 00050 $this->terConnection->wsdlURL = $GLOBALS['TYPO3_CONF_VARS']['EXT']['em_wsdlURL']; 00051 } 00052 00053 00054 /** 00055 * Install translations for all selected languages for an extension 00056 * 00057 * @param string $extKey The extension key to install the translations for 00058 * @param string $mirrorURL Mirror URL to fetch data from 00059 * @return mixed true on success, error string on fauilure 00060 */ 00061 function installTranslationsForExtension($extKey, $mirrorURL) { 00062 $selectedLanguages = unserialize($this->parentObject->MOD_SETTINGS['selectedLanguages']); 00063 if (!is_array($selectedLanguages)) { 00064 $selectedLanguages = array(); 00065 } 00066 foreach ($selectedLanguages as $lang) { 00067 $l10n = $this->parentObject->terConnection->fetchTranslation($extKey, $lang, $mirrorURL); 00068 if (is_array($l10n)) { 00069 $file = PATH_typo3conf . 'l10n/' . $extKey . '-l10n-' . $lang . '.zip'; 00070 $path = 'l10n/' . $lang . '/' . $extKey; 00071 t3lib_div::writeFile($file, $l10n[0]); 00072 if (!is_dir(PATH_typo3conf . $path)) { 00073 t3lib_div::mkdir_deep(PATH_typo3conf, $path); 00074 } 00075 if (tx_em_Tools::unzip($file, PATH_typo3conf . $path)) { 00076 return true; 00077 } else { 00078 return $GLOBALS['LANG']->getLL('translation_unpacking_failed'); 00079 } 00080 } else { 00081 return $l10n; 00082 } 00083 } 00084 } 00085 00086 /** 00087 * Install translations for all selected languages for an extension 00088 * 00089 * @param string $extKey The extension key to install the translations for 00090 * @param string $lang Language code of translation to fetch 00091 * @param string $mirrorURL Mirror URL to fetch data from 00092 * @return mixed true on success, error string on fauilure 00093 */ 00094 function updateTranslation($extKey, $lang, $mirrorURL) { 00095 $l10n = $this->parentObject->terConnection->fetchTranslation($extKey, $lang, $mirrorURL); 00096 if (is_array($l10n)) { 00097 $file = PATH_site . 'typo3temp/' . $extKey . '-l10n-' . $lang . '.zip'; 00098 $path = 'l10n/' . $lang . '/'; 00099 if (!is_dir(PATH_typo3conf . $path)) { 00100 t3lib_div::mkdir_deep(PATH_typo3conf, $path); 00101 } 00102 t3lib_div::writeFile($file, $l10n[0]); 00103 // this prevent first update having errors 00104 t3lib_div::rmdir(PATH_typo3conf . $path . $extKey, TRUE); 00105 00106 if (tx_em_Tools::unzip($file, PATH_typo3conf . $path)) { 00107 return TRUE; 00108 } else { 00109 return $GLOBALS['LANG']->getLL('translation_unpacking_failed'); 00110 } 00111 } else { 00112 return $l10n; 00113 } 00114 } 00115 00116 /** 00117 * Renders translation module 00118 * 00119 * @return string or direct output 00120 */ 00121 public function translationHandling() { 00122 global $LANG, $TYPO3_LOADED_EXT; 00123 $LANG->includeLLFile('EXT:setup/mod/locallang.xml'); 00124 00125 //prepare docheader 00126 $docHeaderButtons = $this->parentObject->getButtons(); 00127 $markers = array( 00128 'CSH' => $docHeaderButtons['csh'], 00129 'FUNC_MENU' => $this->parentObject->getFuncMenu(), 00130 ); 00131 $content = ''; 00132 00133 $incoming = t3lib_div::_POST('SET'); 00134 if (isset($incoming['selectedLanguages']) && is_array($incoming['selectedLanguages'])) { 00135 t3lib_BEfunc::getModuleData($this->parentObject->MOD_MENU, array('selectedLanguages' => serialize($incoming['selectedLanguages'])), $this->parentObject->MCONF['name'], '', 'selectedLanguages'); 00136 $this->parentObject->MOD_SETTINGS['selectedLanguages'] = serialize($incoming['selectedLanguages']); 00137 } 00138 00139 $selectedLanguages = unserialize($this->parentObject->MOD_SETTINGS['selectedLanguages']); 00140 if (count($selectedLanguages) == 1 && empty($selectedLanguages[0])) { 00141 $selectedLanguages = array(); 00142 } 00143 $theLanguages = t3lib_div::trimExplode('|', TYPO3_languages); 00144 foreach ($theLanguages as $val) { 00145 if ($val != 'default') { 00146 $localLabel = ' - [' . htmlspecialchars($GLOBALS['LOCAL_LANG']['default']['lang_' . $val]) . ']'; 00147 $selected = (is_array($selectedLanguages) && in_array($val, $selectedLanguages)) ? ' selected="selected"' : ''; 00148 $opt[$GLOBALS['LANG']->getLL('lang_' . $val, 1) . '--' . $val] = ' 00149 <option value="' . $val . '"' . $selected . '>' . $LANG->getLL('lang_' . $val, 1) . $localLabel . '</option>'; 00150 } 00151 } 00152 ksort($opt); 00153 00154 $headline = $GLOBALS['LANG']->getLL('translation_settings'); 00155 $headline = t3lib_BEfunc::wrapInHelp('_MOD_tools_em', 'translation', $headline); 00156 00157 // Prepare the HTML output: 00158 $content .= ' 00159 <form action="' . $this->parentObject->script . '" method="post" name="translationform"> 00160 <fieldset><legend>' . $GLOBALS['LANG']->getLL('translation_settings') . '</legend> 00161 <table border="0" cellpadding="2" cellspacing="2"> 00162 <tr class="bgColor4"> 00163 <td>' . $GLOBALS['LANG']->getLL('languages_to_fetch') . '</td> 00164 <td> 00165 <select name="SET[selectedLanguages][]" multiple="multiple" size="10"> 00166 <option> </option>' . 00167 implode('', $opt) . ' 00168 </select> 00169 </td> 00170 </tr> 00171 </table> 00172 <br /> 00173 <p>' . $GLOBALS['LANG']->getLL('translation_info') . '<br /> 00174 <br />' . $GLOBALS['LANG']->getLL('translation_loaded_exts') . '</p> 00175 </fieldset> 00176 <br /> 00177 <input type="submit" value="' . $GLOBALS['LANG']->getLL('translation_save_selection') . '" /> 00178 <br /> 00179 </form>'; 00180 00181 $this->parentObject->content .= $this->parentObject->doc->section($headline, $content, FALSE, TRUE, FALSE, TRUE); 00182 00183 if (count($selectedLanguages) > 0) { 00184 $mirrorURL = $this->parentObject->getMirrorURL(); 00185 $content = '<input type="button" value="' . $GLOBALS['LANG']->getLL('translation_check_status_button') . 00186 '" onclick="document.location.href=\'' . htmlspecialchars(t3lib_div::linkThisScript(array('l10n' => 'check'))) . 00187 '\'" /> <input type="button" value="' . $GLOBALS['LANG']->getLL('translation_update_button') . 00188 '" onclick="document.location.href=\'' . htmlspecialchars(t3lib_div::linkThisScript(array('l10n' => 'update'))) . 00189 '\'" />'; 00190 00191 // as this page loads dynamically, quit output buffering caused by ob_gzhandler 00192 t3lib_div::cleanOutputBuffers(); 00193 00194 if (t3lib_div::_GET('l10n') == 'check') { 00195 $loadedExtensions = array_keys($TYPO3_LOADED_EXT); 00196 $loadedExtensions = array_diff($loadedExtensions, array('_CACHEFILE')); 00197 00198 // Override content output - we now do that ourselves: 00199 $this->parentObject->content .= $this->parentObject->doc->section($GLOBALS['LANG']->getLL('translation_status'), $content, 0, 1); 00200 // Setting up the buttons and markers for docheader 00201 $content = $this->parentObject->doc->startPage('Extension Manager'); 00202 $content .= $this->parentObject->doc->moduleBody($this->parentObject->pageinfo, $docHeaderButtons, $markers); 00203 $contentParts = explode('###CONTENT###', $content); 00204 00205 echo $contentParts[0] . $this->parentObject->content; 00206 00207 $this->parentObject->doPrintContent = FALSE; 00208 flush(); 00209 00210 echo ' 00211 <br /> 00212 <br /> 00213 <p id="progress-message"> 00214 ' . $GLOBALS['LANG']->getLL('translation_check_status') . ' 00215 </p> 00216 <br /> 00217 <div style="width:100%; height:20px; border: 1px solid black;"> 00218 <div id="progress-bar" style="float: left; width: 0%; height: 20px; background-color:green;"> </div> 00219 <div id="transparent-bar" style="float: left; width: 100%; height: 20px; background-color:' . $this->parentObject->doc->bgColor2 . ';"> </div> 00220 </div> 00221 <br /> 00222 <br /><p>' . $GLOBALS['LANG']->getLL('translation_table_check') . '</p><br /> 00223 <table border="0" cellpadding="2" cellspacing="2"> 00224 <tr class="t3-row-header"><td>' . $GLOBALS['LANG']->getLL('translation_extension_key') . '</td> 00225 '; 00226 00227 foreach ($selectedLanguages as $lang) { 00228 echo ('<td>' . $LANG->getLL('lang_' . $lang, 1) . '</td>'); 00229 } 00230 echo ('</tr>'); 00231 00232 $counter = 1; 00233 foreach ($loadedExtensions as $extKey) { 00234 00235 $percentDone = intval(($counter / count($loadedExtensions)) * 100); 00236 echo (' 00237 <script type="text/javascript"> 00238 document.getElementById("progress-bar").style.width = "' . $percentDone . '%"; 00239 document.getElementById("transparent-bar").style.width = "' . (100 - $percentDone) . '%"; 00240 document.getElementById("progress-message").firstChild.data="' . 00241 sprintf($GLOBALS['LANG']->getLL('translation_checking_extension'), $extKey) . '"; 00242 </script> 00243 '); 00244 00245 flush(); 00246 $translationStatusArr = $this->parentObject->terConnection->fetchTranslationStatus($extKey, $mirrorURL); 00247 00248 echo ('<tr class="bgColor4"><td>' . $extKey . '</td>'); 00249 foreach ($selectedLanguages as $lang) { 00250 // remote unknown -> no l10n available 00251 if (!isset($translationStatusArr[$lang])) { 00252 echo ('<td title="' . $GLOBALS['LANG']->getLL('translation_no_translation') . '">' . 00253 $GLOBALS['LANG']->getLL('translation_n_a') . '</td>'); 00254 continue; 00255 } 00256 // determine local md5 from zip 00257 if (is_file(PATH_site . 'typo3temp/' . $extKey . '-l10n-' . $lang . '.zip')) { 00258 $localmd5 = md5_file(PATH_site . 'typo3temp/' . $extKey . '-l10n-' . $lang . '.zip'); 00259 } else { 00260 echo ('<td title="' . $GLOBALS['LANG']->getLL('translation_not_installed') . 00261 '" style="background-color:#ff0">' . $GLOBALS['LANG']->getLL('translation_status_unknown') . 00262 '</td>'); 00263 continue; 00264 } 00265 // local!=remote -> needs update 00266 if ($localmd5 != $translationStatusArr[$lang]['md5']) { 00267 echo ('<td title="' . $GLOBALS['LANG']->getLL('translation_needs_update') . 00268 '" style="background-color:#ff0">' . $GLOBALS['LANG']->getLL('translation_status_update') . 00269 '</td>'); 00270 continue; 00271 } 00272 echo ('<td title="' . $GLOBALS['LANG']->getLL('translation_is_ok') . 00273 '" style="background-color:#69a550">' . $GLOBALS['LANG']->getLL('translation_status_ok') . 00274 '</td>'); 00275 } 00276 echo ('</tr>'); 00277 00278 $counter++; 00279 } 00280 echo '</table> 00281 <script type="text/javascript"> 00282 document.getElementById("progress-message").firstChild.data="' . 00283 $GLOBALS['LANG']->getLL('translation_check_done') . '"; 00284 </script> 00285 '; 00286 echo $contentParts[1] . $this->parentObject->doc->endPage(); 00287 exit; 00288 00289 } elseif (t3lib_div::_GET('l10n') == 'update') { 00290 $loadedExtensions = array_keys($TYPO3_LOADED_EXT); 00291 $loadedExtensions = array_diff($loadedExtensions, array('_CACHEFILE')); 00292 00293 // Override content output - we now do that ourselves: 00294 $this->parentObject->content .= $this->parentObject->doc->section($GLOBALS['LANG']->getLL('translation_status'), $content, 0, 1); 00295 // Setting up the buttons and markers for docheader 00296 $content = $this->parentObject->doc->startPage('Extension Manager'); 00297 $content .= $this->parentObject->doc->moduleBody($this->parentObject->pageinfo, $docHeaderButtons, $markers); 00298 $contentParts = explode('###CONTENT###', $content); 00299 00300 echo $contentParts[0] . $this->parentObject->content; 00301 00302 $this->parentObject->doPrintContent = FALSE; 00303 flush(); 00304 00305 echo (' 00306 <br /> 00307 <br /> 00308 <p id="progress-message"> 00309 ' . $GLOBALS['LANG']->getLL('translation_update_status') . ' 00310 </p> 00311 <br /> 00312 <div style="width:100%; height:20px; border: 1px solid black;"> 00313 <div id="progress-bar" style="float: left; width: 0%; height: 20px; background-color:green;"> </div> 00314 <div id="transparent-bar" style="float: left; width: 100%; height: 20px; background-color:' . $this->parentObject->doc->bgColor2 . ';"> </div> 00315 </div> 00316 <br /> 00317 <br /><p>' . $GLOBALS['LANG']->getLL('translation_table_update') . '<br /> 00318 <em>' . $GLOBALS['LANG']->getLL('translation_full_check_update') . '</em></p><br /> 00319 <table border="0" cellpadding="2" cellspacing="2"> 00320 <tr class="t3-row-header"><td>' . $GLOBALS['LANG']->getLL('translation_extension_key') . '</td> 00321 '); 00322 00323 foreach ($selectedLanguages as $lang) { 00324 echo '<td>' . $LANG->getLL('lang_' . $lang, 1) . '</td>'; 00325 } 00326 echo '</tr>'; 00327 00328 $counter = 1; 00329 foreach ($loadedExtensions as $extKey) { 00330 $percentDone = intval(($counter / count($loadedExtensions)) * 100); 00331 echo (' 00332 <script type="text/javascript"> 00333 document.getElementById("progress-bar").style.width = "' . $percentDone . '%"; 00334 document.getElementById("transparent-bar").style.width = "' . (100 - $percentDone) . '%"; 00335 document.getElementById("progress-message").firstChild.data="' . 00336 sprintf($GLOBALS['LANG']->getLL('translation_updating_extension'), $extKey) . '"; 00337 </script> 00338 '); 00339 00340 flush(); 00341 $translationStatusArr = $this->parentObject->terConnection->fetchTranslationStatus($extKey, $mirrorURL); 00342 00343 echo ('<tr class="bgColor4"><td>' . $extKey . '</td>'); 00344 if (is_array($translationStatusArr)) { 00345 foreach ($selectedLanguages as $lang) { 00346 // remote unknown -> no l10n available 00347 if (!isset($translationStatusArr[$lang])) { 00348 echo ('<td title="' . $GLOBALS['LANG']->getLL('translation_no_translation') . 00349 '">' . $GLOBALS['LANG']->getLL('translation_n_a') . '</td>'); 00350 continue; 00351 } 00352 // determine local md5 from zip 00353 if (is_file(PATH_site . 'typo3temp/' . $extKey . '-l10n-' . $lang . '.zip')) { 00354 $localmd5 = md5_file(PATH_site . 'typo3temp/' . $extKey . '-l10n-' . $lang . '.zip'); 00355 } else { 00356 $localmd5 = 'zzz'; 00357 } 00358 // local!=remote or not installed -> needs update 00359 if ($localmd5 != $translationStatusArr[$lang]['md5']) { 00360 $ret = $this->updateTranslation($extKey, $lang, $mirrorURL); 00361 if ($ret === true) { 00362 echo ('<td title="' . $GLOBALS['LANG']->getLL('translation_has_been_updated') . 00363 '" style="background-color:#69a550">' . $GLOBALS['LANG']->getLL('translation_status_update') . 00364 '</td>'); 00365 } else { 00366 echo ('<td title="' . htmlspecialchars($ret) . 00367 '" style="background-color:#cb3352">' . $GLOBALS['LANG']->getLL('translation_status_error') . 00368 '</td>'); 00369 } 00370 continue; 00371 } 00372 echo ('<td title="' . $GLOBALS['LANG']->getLL('translation_is_ok') . 00373 '" style="background-color:#69a550">' . $GLOBALS['LANG']->getLL('translation_status_ok') . '</td>'); 00374 } 00375 } else { 00376 echo ('<td colspan="' . count($selectedLanguages) . 00377 '" title="' . $GLOBALS['LANG']->getLL('translation_problems') . 00378 '">' . $GLOBALS['LANG']->getLL('translation_status_could_not_fetch') . '</td>'); 00379 } 00380 echo ('</tr>'); 00381 $counter++; 00382 } 00383 echo '</table> 00384 <script type="text/javascript"> 00385 document.getElementById("progress-message").firstChild.data="' . 00386 $GLOBALS['LANG']->getLL('translation_update_done') . '"; 00387 </script> 00388 '; 00389 00390 // Fix permissions on unzipped language xml files in the entire l10n folder and all subfolders 00391 t3lib_div::fixPermissions(PATH_typo3conf . 'l10n', TRUE); 00392 00393 echo $contentParts[1] . $this->parentObject->doc->endPage(); 00394 exit; 00395 } 00396 00397 $this->parentObject->content .= $this->parentObject->doc->section($GLOBALS['LANG']->getLL('translation_status'), $content, 0, 1); 00398 } 00399 } 00400 00401 00402 } 00403 00404 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/translations/class.tx_em_translations.php'])) { 00405 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/translations/class.tx_em_translations.php']); 00406 } 00407 00408 ?>
1.8.0