📄 class.em_index.php
字号:
$counter = 1; foreach($loadedExtensions as $extKey) { $percentDone = intval (($counter / count($loadedExtensions)) * 100); echo (' <script> document.getElementById("progress-bar").style.width = "'.$percentDone.'%"; document.getElementById("transparent-bar").style.width = "'.(100-$percentDone).'%"; document.getElementById("progress-message").firstChild.data="Updating translation for extension \"'.$extKey.'\" ..."; </script> '); flush(); $translationStatusArr = $this->terConnection->fetchTranslationStatus($extKey,$mirrorURL); echo ('<tr class="bgColor4"><td>'.$extKey.'</td>'); if(is_array($translationStatusArr)) { foreach($selectedLanguages as $lang) { // remote unknown -> no l10n available if(!isset($translationStatusArr[$lang])) { echo ('<td title="No translation available">N/A</td>'); continue; } // determine local md5 from zip if(is_file(PATH_site.'typo3temp/'.$extKey.'-l10n-'.$lang.'.zip')) { $localmd5 = md5_file(PATH_site.'typo3temp/'.$extKey.'-l10n-'.$lang.'.zip'); } else { $localmd5 = 'zzz'; } // local!=remote or not installed -> needs update if($localmd5 != $translationStatusArr[$lang]['md5']) { $ret = $this->updateTranslation($extKey, $lang, $mirrorURL); if($ret === true) { echo ('<td title="Has been updated" style="background-color:#69a550">UPD</td>'); } else { echo ('<td title="'.htmlspecialchars($ret).'" style="background-color:#cb3352">ERR</td>'); } continue; } echo ('<td title="Is up to date" style="background-color:#69a550">OK</td>'); } } else { echo ('<td colspan="'.count($selectedLanguages).'" title="Possible reasons: network problems, allow_url_fopen off, curl not enabled in Install tool.">Could not fetch translation status</td>'); } echo ('</tr>'); $counter++; } echo '</table> <script> document.getElementById("progress-message").firstChild.data="Update done."; </script> '; echo $this->doc->endPage(); return ''; } $this->content.=$this->doc->section('Translation status',$content,0,1); } } /** * Install translations for all selected languages for an extension * * @param string $extKey The extension key to install the translations for * @param string $lang Language code of translation to fetch * @param string $mirrorURL Mirror URL to fetch data from * @return mixed true on success, error string on fauilure */ function updateTranslation($extKey, $lang, $mirrorURL) { $l10n = $this->terConnection->fetchTranslation($extKey, $lang, $mirrorURL); if(is_array($l10n)) { $file = PATH_site.'typo3temp/'.$extKey.'-l10n-'.$lang.'.zip'; $path = 'l10n/'.$lang.'/'; if(!is_dir(PATH_typo3conf.$path)) t3lib_div::mkdir_deep(PATH_typo3conf,$path); t3lib_div::writeFile($file, $l10n[0]); if($this->unzip($file, PATH_typo3conf.$path)) { return true; } else { return 'Unpacking the language pack failed!'; } } else { return $l10n; } } /** * Install translations for all selected languages for an extension * * @param string $extKey The extension key to install the translations for * @param string $mirrorURL Mirror URL to fetch data from * @return mixed true on success, error string on fauilure */ function installTranslationsForExtension($extKey, $mirrorURL) { $selectedLanguages = unserialize($this->MOD_SETTINGS['selectedLanguages']); if(!is_array($selectedLanguages)) $selectedLanguages = array(); foreach($selectedLanguages as $lang) { $l10n = $this->terConnection->fetchTranslation($extKey, $lang, $mirrorURL); if(is_array($l10n)) { $file = PATH_typo3conf.'l10n/'.$extKey.'-l10n-'.$lang.'.zip'; $path = 'l10n/'.$lang.'/'.$extKey; t3lib_div::writeFile($file, $l10n[0]); if(!is_dir(PATH_typo3conf.$path)) t3lib_div::mkdir_deep(PATH_typo3conf,$path); if($this->unzip($file, PATH_typo3conf.$path)) { return true; } else { return 'Unpacking the language pack failed!'; } } else { return $l10n; } } } /** * Unzips a zip file in the given path. * * Uses unzip binary if available, otherwise a pure PHP unzip is used. * * @param string $file Full path to zip file * @param string $path Path to change to before extracting * @return boolean True on success, false in failure */ function unzip($file, $path) { if(strlen($GLOBALS['TYPO3_CONF_VARS']['BE']['unzip_path'])) { chdir($path); $cmd = $GLOBALS['TYPO3_CONF_VARS']['BE']['unzip_path'].' -o '.escapeshellarg($file); exec($cmd, $list, $ret); return ($ret === 0); } else { // we use a pure PHP unzip $unzip = new em_unzip($file); $ret = $unzip->extract(array('add_path'=>$path)); return (is_array($ret)); } } /********************************* * * Command Applications (triggered by GET var) * *********************************/ /** * Returns detailed info about an extension in the online repository * * @param string Extension repository uid + optional "private key": [uid]-[key]. * @param [type] $version: ... * @return void */ function importExtInfo($extKey, $version='') { // "Go back" link $content = '<a href="index.php" class="typo3-goBack"><img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/goback.gif','width="14" height="14"').' alt="" /> Go back</a>'; $this->content.= $this->doc->section('',$content); $content = ''; // Fetch remote data: $this->xmlhandler->searchExtensionsXML($extKey, '', '', true, true); list($fetchData,) = $this->prepareImportExtList(true); $versions = array_keys($fetchData[$extKey]['versions']); $version = ($version == '') ? end($versions) : $version; $opt = array(); foreach(array_keys($fetchData[$extKey]['versions']) as $ver) { $opt[]='<option value="'.$ver.'"'.(($version == $ver) ? ' selected="selected"' : '').'>'.$ver.'</option>'; } // "Select version" box: $onClick = 'window.location.href=\'index.php?CMD[importExtInfo]='.$extKey.'&CMD[extVersion]=\'+document.pageform.extVersion.options[document.pageform.extVersion.selectedIndex].value; return false;'; $select='<select name="extVersion">'.implode('',$opt).'</select> <input type="submit" value="Load details" onclick="'.htmlspecialchars($onClick).'" /> or<br /><br />'; if ($this->importAtAll()) { $onClick = ' window.location.href=\'index.php?CMD[importExt]='.$extKey.'\' +\'&CMD[extVersion]=\'+document.pageform.extVersion.options[document.pageform.extVersion.selectedIndex].value +\'&CMD[loc]=\'+document.pageform.loc.options[document.pageform.loc.selectedIndex].value; return false;'; $select.=' <input type="submit" value="Import/Update" onclick="'.htmlspecialchars($onClick).'"> to: <select name="loc">'. ($this->importAsType('G',$fetchData['emconf_lockType'])?'<option value="G">Global: '.$this->typePaths['G'].$extKey.'/'.(@is_dir(PATH_site.$this->typePaths['G'].$extKey)?' (OVERWRITE)':' (empty)').'</option>':''). ($this->importAsType('L',$fetchData['emconf_lockType'])?'<option value="L">Local: '.$this->typePaths['L'].$extKey.'/'.(@is_dir(PATH_site.$this->typePaths['L'].$extKey)?' (OVERWRITE)':' (empty)').'</option>':''). ($this->importAsType('S',$fetchData['emconf_lockType'])?'<option value="S">System: '.$this->typePaths['S'].$extKey.'/'.(@is_dir(PATH_site.$this->typePaths['S'].$extKey)?' (OVERWRITE)':' (empty)').'</option>':''). '</select>'; } else $select.= $this->noImportMsg(); $content.= $select; $this->content.= $this->doc->section('Select command',$content,0,1); // Details: $eInfo = $fetchData[$extKey]['versions'][$version]; $content='<strong>'.$fetchData[$extKey]['_ICON'].' '.$eInfo['EM_CONF']['title'].' ('.$extKey.', '.$version.')</strong><br /><br />'; $content.=$this->extInformationArray($extKey,$eInfo,1); $this->content.=$this->doc->spacer(10); $this->content.=$this->doc->section('Remote Extension Details',$content,0,1); } /** * Fetches metadata and stores it to the corresponding place. This includes the mirror list, * extension XML files. * * @param string Type of data to fetch: (mirrors) * @param boolean If true the method doesn't produce any output * @return void */ function fetchMetaData($metaType) { global $TYPO3_CONF_VARS; switch($metaType) { case 'mirrors': $mfile = t3lib_div::tempnam('mirrors'); $mirrorsFile = t3lib_div::getURL($this->MOD_SETTINGS['mirrorListURL']); if($mirrorsFile===false) { t3lib_div::unlink_tempfile($mfile); $content = '<p>The mirror list was not updated, it could not be fetched from '.$this->MOD_SETTINGS['mirrorListURL'].'. Possible reasons: network problems, allow_url_fopen is off, curl is not enabled in Install tool.</p>'; } else { t3lib_div::writeFile($mfile, $mirrorsFile); $mirrors = implode('',gzfile($mfile)); t3lib_div::unlink_tempfile($mfile); $mirrors = $this->xmlhandler->parseMirrorsXML($mirrors); if(is_array($mirrors) && count($mirrors)) { t3lib_BEfunc::getModuleData($this->MOD_MENU, array('extMirrors' => serialize($mirrors)), $this->MCONF['name'], '', 'extMirrors'); $this->MOD_SETTINGS['extMirrors'] = serialize($mirrors); $content = '<p>The mirror list has been updated and now contains '.count($mirrors).' entries.</p>'; } else { $content = '<p>'.$mirrors.'<br />The mirror list was not updated as it contained no entries.</p>'; } } break; case 'extensions': $this->fetchMetaData('mirrors'); // if we fetch the extensions anyway, we can as well keep this up-to-date $mirror = $this->getMirrorURL(); $extfile = $mirror.'extensions.xml.gz'; $extmd5 = t3lib_div::getURL($mirror.'extensions.md5'); if(is_file(PATH_site.'typo3temp/extensions.xml.gz')) $localmd5 = md5_file(PATH_site.'typo3temp/extensions.xml.gz'); if($extmd5 === false) { $content .= '<p>Error: The extension MD5 sum could not be fetched from '.$mirror.'extensions.md5. Possible reasons: network problems, allow_url_fopen is off, curl is not enabled in Install tool.</p>'; } elseif($extmd5 == $localmd5) { $content .= '<p>The extension list has not changed remotely, it has thus not been fetched.</p>'; } else { $extXML = t3lib_div::getURL($extfile); if($extXML === false) { $content .= '<p>Error: The extension list could not be fetched from '.$extfile.'. Possible reasons: network problems, allow_url_fopen is off, curl is not enabled in Install tool.</p>'; } else { t3lib_div::writeFile(PATH_site.'typo3temp/extensions.xml.gz', $extXML); $content .= $this->xmlhandler->parseExtensionsXML(PATH_site.'typo3temp/extensions.xml.gz'); } } break; } return $content; } /** * Returns the base URL for the slected or a random mirror. * * @return string The URL for the selected or a random mirror */ function getMirrorURL() { if(strlen($this->MOD_SETTINGS['rep_url'])) return $this->MOD_SETTINGS['rep_url']; $mirrors = unserialize($this->MOD_SETTINGS['extMirrors']); if(!is_array($mirrors)) { $this->fetchMetaData('mirrors'); $mirrors = unserialize($this->MOD_SETTINGS['extMirrors']); if(!is_array($mirrors)) return false; } if($this->MOD_SETTINGS['selectedMirror']=='') { srand((float) microtime() * 10000000); // not needed after PHP 4.2.0... $rand = array_rand($mirrors); $url = 'http://'.$mirrors[$rand]['host'].$mirrors[$rand]['path']; } else { $url = 'http://'.$mirrors[$this->MOD_SETTINGS['selectedMirror']]['host'].$mirrors[$this->MOD_SETTINGS['selectedMirror']]['path']; } return $url; } /** * Installs (activates) an extension * * For $mode use the three constants EM_INSTALL_VERSION_MIN, EM_INSTALL_VERSION_MAX, EM_INSTALL_VERSION_STRICT * * If an extension is loaded or imported already and the version requirement is matched, it will not be * fetched from the repository. This means, if you use EM_INSTALL_VERSION_MIN, you will not always get the latest * version of an extension! * * @param string $extKey The extension key to install * @param string $version A version number that should be installed * @param int $mode If a version is requested, this determines if it is the min, max or strict version requested * @return [type] ... * @todo Make the method able to handle needed interaction somehow (unmatched dependencies) */ function installExtension($ex
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -