|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2010 Steffen Kamper (info@sk-typo3.de) 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 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00027 /** 00028 * Module: Extension manager, developer module 00029 * 00030 * This class handles all Ajax calls coming from ExtJS 00031 * 00032 * $Id: class.tx_em_Connection_ExtDirectServer.php 2083 2010-03-22 00:48:31Z steffenk $ 00033 * 00034 * @author Steffen Kamper <info@sk-typo3.de> 00035 */ 00036 00037 00038 class tx_em_Connection_ExtDirectServer { 00039 /** 00040 * @var tx_em_Tools_XmlHandler 00041 */ 00042 var $xmlHandler; 00043 00044 /** 00045 * Class for printing extension lists 00046 * 00047 * @var tx_em_Extensions_List 00048 */ 00049 public $extensionList; 00050 00051 /** 00052 * Class for extension details 00053 * 00054 * @var tx_em_Extensions_Details 00055 */ 00056 public $extensionDetails; 00057 00058 /** 00059 * Keeps instance of settings class. 00060 * 00061 * @var tx_em_Settings 00062 */ 00063 static protected $objSettings; 00064 00065 protected $globalSettings; 00066 00067 /*********************************************************************/ 00068 /* General */ 00069 /*********************************************************************/ 00070 00071 /** 00072 * Constructor 00073 * 00074 * @param boolean $createTemplateInstance: set to FALSE if no instance of template class needs to be created 00075 * @return void 00076 */ 00077 public function __construct($createTemplateInstance = TRUE) { 00078 if ($createTemplateInstance) { 00079 $this->template = t3lib_div::makeInstance('template'); 00080 } 00081 $this->globalSettings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['em']); 00082 } 00083 00084 00085 /** 00086 * Method returns instance of settings class. 00087 * 00088 * @access protected 00089 * @return em_settings instance of settings class 00090 */ 00091 protected function getSettingsObject() { 00092 if (!is_object(self::$objSettings) && !(self::$objSettings instanceof tx_em_Settings)) { 00093 self::$objSettings = t3lib_div::makeInstance('tx_em_Settings'); 00094 } 00095 return self::$objSettings; 00096 } 00097 00098 00099 /*********************************************************************/ 00100 /* Local Extension List */ 00101 /*********************************************************************/ 00102 00103 00104 /** 00105 * Render local extension list 00106 * 00107 * @return string $content 00108 */ 00109 public function getExtensionList() { 00110 /** @var $list tx_em_Extensions_List */ 00111 $list = t3lib_div::makeInstance('tx_em_Extensions_List'); 00112 $extList = $list->getInstalledExtensions(TRUE); 00113 00114 00115 return array( 00116 'length' => count($extList), 00117 'data' => $extList 00118 ); 00119 00120 } 00121 00122 public function getFlatExtensionList() { 00123 $list = $this->getExtensionList(); 00124 $flatList = array(); 00125 foreach ($list['data'] as $entry) { 00126 $flatList[$entry['extkey']] = array( 00127 'version' => $entry['version'], 00128 'intversion' => t3lib_div::int_from_ver($entry['version']), 00129 'installed' => $entry['installed'], 00130 'typeShort' => $entry['typeShort'], 00131 ); 00132 } 00133 return array( 00134 'length' => count($flatList), 00135 'data' => $flatList 00136 ); 00137 } 00138 00139 /** 00140 * Render extensionlist for languages 00141 * 00142 * @return unknown 00143 */ 00144 public function getInstalledExtkeys() { 00145 $list = $this->getExtensionList(); 00146 $extList = $list['data']; 00147 00148 $selectedLanguages = t3lib_div::trimExplode(',', $this->globalSettings['selectedLanguages']); 00149 00150 $keys = array(); 00151 $i = 0; 00152 foreach ($extList as $ext) { 00153 if ($ext['installed']) { 00154 $keys[$i] = array( 00155 'extkey' => $ext['extkey'], 00156 'icon' => $ext['icon'], 00157 'stype' => $ext['typeShort'], 00158 ); 00159 $keys[$i]['lang'] = array(); 00160 if (count($selectedLanguages)) { 00161 foreach ($selectedLanguages as $language) { 00162 $keys[$i]['lang'][] = $GLOBALS['LANG']->sL('LLL:EXT:setup/mod/locallang.xml:lang_' . $language); 00163 } 00164 } 00165 $i++; 00166 } 00167 } 00168 00169 return array( 00170 'length' => count($keys), 00171 'data' => $keys, 00172 ); 00173 } 00174 00175 /** 00176 * Render module content 00177 * 00178 * @return string $content 00179 */ 00180 public function getExtensionDetails() { 00181 /** @var $list tx_em_Extensions_List */ 00182 $list = t3lib_div::makeInstance('tx_em_Extensions_List'); 00183 $extList = $list->getInstalledExtensions(TRUE); 00184 00185 00186 return array( 00187 'length' => count($extList), 00188 'data' => $extList 00189 ); 00190 00191 } 00192 00193 /** 00194 * Render extension update 00195 * 00196 * @var string $extKey 00197 * @return string $content 00198 */ 00199 public function getExtensionUpdate($extKey) { 00200 if (isset($GLOBALS['TYPO3_LOADED_EXT'][$extKey])) { 00201 /** @var $install tx_em_Install */ 00202 $install = t3lib_div::makeInstance('tx_em_Install'); 00203 /** @var $extension tx_em_Extensions_List */ 00204 $extension = t3lib_div::makeInstance('tx_em_Extensions_List'); 00205 00206 00207 $extPath = t3lib_extMgm::extPath($extKey); 00208 $type = tx_em_Tools::getExtTypeFromPath($extPath); 00209 $typePath = tx_em_Tools::typePath($type); 00210 $extInfo = array(); 00211 00212 $extension->singleExtInfo($extKey, $typePath, $extInfo); 00213 $extInfo = $extInfo[0]; 00214 $extInfo['type'] = $extInfo['typeShort']; 00215 $update = $install->checkDBupdates($extKey, $extInfo); 00216 if ($update) { 00217 $update = $GLOBALS['LANG']->getLL('ext_details_new_tables_fields_select') . 00218 $update . 00219 '<br /><input type="submit" name="write" id="update-submit-' . htmlspecialchars($extKey) . '" value="' . 00220 htmlspecialchars($GLOBALS['LANG']->getLL('updatesForm_make_updates')) . '" />'; 00221 } 00222 return $update ? $update : $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_dbUpToDate'); 00223 } else { 00224 return sprintf($GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_extNotInstalled') ,htmlspecialchars($extKey)); 00225 } 00226 } 00227 00228 00229 /** 00230 * Render extension configuration 00231 * 00232 * @var string $extKey 00233 * @return string $content 00234 */ 00235 public function getExtensionConfiguration($extKey) { 00236 /** @var $extensionList tx_em_Extensions_List */ 00237 $extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this); 00238 list($list,) = $extensionList->getInstalledExtensions(); 00239 /** @var $install tx_em_Install */ 00240 $install = t3lib_div::makeInstance('tx_em_Install'); 00241 $install->setSilentMode(TRUE); 00242 00243 $form = $install->updatesForm($extKey, $list[$extKey], 1, '', '', FALSE, TRUE); 00244 if (!$form) { 00245 return '<p>' . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_extNoConfiguration') . '</p>'; 00246 } else { 00247 //$form = preg_replace('/<form([^>]+)>/', '', $form); 00248 //$form = str_replace('</form>', '', $form); 00249 return $form; 00250 } 00251 } 00252 00253 /** 00254 * Save extension configuration 00255 * 00256 * @formHandler 00257 * @param array $parameter 00258 * @return array 00259 */ 00260 public function saveExtensionConfiguration($parameter) { 00261 00262 $extKey = $parameter['extkey']; 00263 $extType = $parameter['exttype']; 00264 $noSave = $parameter['noSave']; 00265 00266 $absPath = tx_em_Tools::getExtPath($extKey, $extType); 00267 $relPath = tx_em_Tools::typeRelPath($extType) . $extKey . '/'; 00268 00269 /** @var $extensionList tx_em_Extensions_List */ 00270 $extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this); 00271 list($list,) = $extensionList->getInstalledExtensions(); 00272 00273 00274 $arr = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extKey]); 00275 $arr = is_array($arr) ? $arr : array(); 00276 00277 /** @var $tsStyleConfig t3lib_tsStyleConfig */ 00278 $tsStyleConfig = t3lib_div::makeInstance('t3lib_tsStyleConfig'); 00279 $tsStyleConfig->doNotSortCategoriesBeforeMakingForm = TRUE; 00280 $theConstants = $tsStyleConfig->ext_initTSstyleConfig( 00281 t3lib_div::getUrl($absPath . 'ext_conf_template.txt'), 00282 $relPath, 00283 $absPath, 00284 $GLOBALS['BACK_PATH'] 00285 ); 00286 00287 $tsStyleConfig->ext_procesInput($parameter, array(), $theConstants, array()); 00288 $arr = $tsStyleConfig->ext_mergeIncomingWithExisting($arr); 00289 00290 00291 /** @var $install tx_em_Install */ 00292 $install = t3lib_div::makeInstance('tx_em_Install'); 00293 $install->setSilentMode(TRUE); 00294 $install->install->INSTALL = $parameter['TYPO3_INSTALL']; 00295 $install->checkDBupdates($extKey, $list[$extKey]); 00296 00297 $html = ''; 00298 if ($noSave) { 00299 $html = $install->updatesForm($extKey, $list[$extKey], 1); 00300 } else { 00301 $install->writeTsStyleConfig($extKey, $arr); 00302 } 00303 00304 return array( 00305 'success' => true, 00306 'data' => $parameter['data'], 00307 'html' => $html, 00308 ); 00309 } 00310 00311 /** 00312 * Cleans EMConf of extension 00313 * 00314 * @param string $extKey 00315 * @return array 00316 */ 00317 public function cleanEmConf($extKey) { 00318 00319 /** @var $extensionList tx_em_Extensions_List */ 00320 $extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this); 00321 list($list,) = $extensionList->getInstalledExtensions(); 00322 /** @var $extensionDetails tx_em_Extensions_Details */ 00323 $this->extensionDetails = t3lib_div::makeInstance('tx_em_Extensions_Details', $this); 00324 00325 $result = $this->extensionDetails->updateLocalEM_CONF($extKey, $list[$extKey]); 00326 00327 return array( 00328 'success' => TRUE, 00329 'extkey' => $extKey, 00330 'result' => $result 00331 ); 00332 } 00333 00334 /** 00335 * Delete extension 00336 * 00337 * @param $extKey 00338 * @return array 00339 */ 00340 public function deleteExtension($extKey) { 00341 00342 /** @var $extensionList tx_em_Extensions_List */ 00343 $extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this); 00344 list($list,) = $extensionList->getInstalledExtensions(); 00345 $type = $list[$extKey]['type']; 00346 $absPath = tx_em_Tools::getExtPath($extKey, $type); 00347 00348 /** @var $extensionDetails tx_em_Install */ 00349 $install = t3lib_div::makeInstance('tx_em_Install'); 00350 $install->setSilentMode(TRUE); 00351 00352 $res = $install->removeExtDirectory($absPath); 00353 $error = ''; 00354 $success = TRUE; 00355 00356 if ($res) { 00357 $res = nl2br($res); 00358 $error = sprintf($GLOBALS['LANG']->getLL('extDelete_remove_dir_failed'), $absPath); 00359 $success = FALSE; 00360 } 00361 return array( 00362 'success' => $success, 00363 'extkey' => $extKey, 00364 'result' => $res, 00365 'error' => $error 00366 ); 00367 } 00368 00369 /** 00370 * genereates a file tree 00371 * 00372 * @param object $parameter 00373 * @return array 00374 */ 00375 public function getExtFileTree($parameter) { 00376 $type = $parameter->typeShort; 00377 $node = substr($parameter->node, 0, 6) !== 'xnode-' ? $parameter->node : $parameter->baseNode; 00378 00379 $path = PATH_site . $node; 00380 $fileArray = array(); 00381 00382 $dirs = t3lib_div::get_dirs($path); 00383 $files = t3lib_div::getFilesInDir($path, '', FALSE, '', ''); 00384 00385 00386 00387 if (!is_array($dirs) && !is_array($files)) { 00388 return array(); 00389 } 00390 00391 foreach ($dirs as $dir) { 00392 if ($dir{0} !== '.') { 00393 $fileArray[] = array( 00394 'id' => ($node == '' ? '' : $node . '/') . $dir, 00395 'text' => htmlspecialchars($dir), 00396 'leaf' => false, 00397 'qtip' => '' 00398 ); 00399 } 00400 } 00401 00402 00403 foreach ($files as $key => $file) { 00404 $fileInfo = $this->getFileInfo($file); 00405 00406 $fileArray[] = array( 00407 'id' => $node . '/' . $file, 00408 'text' => $fileInfo[0], 00409 'leaf' => true, 00410 'qtip' => $fileInfo[1], 00411 'iconCls' => $fileInfo[4], 00412 'fileType' => $fileInfo[3], 00413 'ext' => $fileInfo[2] 00414 ); 00415 } 00416 00417 return $fileArray; 00418 } 00419 00420 00421 /** 00422 * Read extension file and send content 00423 * 00424 * @param string $path 00425 * @return string file content 00426 */ 00427 public function readExtFile($path) { 00428 $path = PATH_site . $path; 00429 if (@file_exists($path)) { 00430 return t3lib_div::getURL($path); 00431 } 00432 return ''; 00433 } 00434 00435 /** 00436 * Save extension file 00437 * 00438 * @param string $file 00439 * @param string $content 00440 * @return boolean success 00441 */ 00442 public function saveExtFile($file, $content) { 00443 $path = PATH_site . $file; 00444 $error = ''; 00445 $fileSaveAllowed = $GLOBALS['TYPO3_CONF_VARS']['EXT']['noEdit'] == 0; 00446 $fileExists = @file_exists($path); 00447 $fileSaveable = is_writable($path); 00448 00449 if ($fileExists && $fileSaveable && $fileSaveAllowed) { 00450 $success = t3lib_div::writeFile($path, $content); 00451 } else { 00452 $success = FALSE; 00453 $error = $fileSaveAllowed 00454 ? ($fileSaveable 00455 ? $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_fileNotExists', TRUE) 00456 : $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_fileWriteProtected', TRUE) 00457 ) 00458 : $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_saving_disabled', TRUE); 00459 } 00460 00461 if ($success) { 00462 $GLOBALS['BE_USER']->writelog(9, 0, 0, 0, sprintf('File "%s" has been modified', $file)); 00463 } 00464 return array( 00465 'success' => $success, 00466 'path' => $path, 00467 'file' => basename($path), 00468 'content' => $content, 00469 'error' => $error 00470 ); 00471 } 00472 00473 /** 00474 * Create a new file 00475 * 00476 * @param string $folder 00477 * @param string $file 00478 * @param boolean $isFolder 00479 * @return array result 00480 */ 00481 public function createNewFile($folder, $file, $isFolder) { 00482 $result = tx_em_Tools::createNewFile($folder, $file, $isFolder); 00483 00484 $node = array(); 00485 00486 if ($result[0] === TRUE) { 00487 if ($isFolder) { 00488 $node = array( 00489 'id' => htmlspecialchars(substr($result[1], strlen(PATH_site))), 00490 'text' => htmlspecialchars(basename($result[1])), 00491 'leaf' => FALSE, 00492 'qtip' => '' 00493 ); 00494 } else { 00495 $fileInfo = $this->getFileInfo($result[1]); 00496 $node = array( 00497 'id' => substr($fileInfo[0], strlen(PATH_site)), 00498 'text' => basename($fileInfo[0]), 00499 'leaf' => !$isFolder, 00500 'qtip' => $fileInfo[1], 00501 'iconCls' => $fileInfo[4], 00502 'fileType' => $fileInfo[3], 00503 'ext' => $fileInfo[2] 00504 ); 00505 } 00506 } 00507 return array( 00508 'success' => $result[0], 00509 'created' => $result[1], 00510 'node' => $node, 00511 'error' => $result[2] 00512 ); 00513 } 00514 00515 /** 00516 * Rename a file/folder 00517 * 00518 * @param string $file 00519 * @param string $newName 00520 * @param boolean $isFolder 00521 * @return array result 00522 */ 00523 public function renameFile($file, $newName, $isFolder) { 00524 $src = basename($file); 00525 $newFile = substr($file, 0, -1 * strlen($src)) . $newName; 00526 00527 $success = tx_em_Tools::renameFile($file, $newFile); 00528 00529 return array( 00530 'success' => $success, 00531 'oldFile' => $file, 00532 'newFile' => $newFile, 00533 'newFilename' => basename($newFile), 00534 ); 00535 } 00536 00537 00538 /** 00539 * Moves a file to new destination 00540 * 00541 * @param string $file 00542 * @param string $destination 00543 * @param boolean $isFolder 00544 * @return array 00545 */ 00546 public function moveFile($file, $destination, $isFolder) { 00547 return array( 00548 'success' => TRUE, 00549 'file' => $file, 00550 'destination' => $destination, 00551 'isFolder' => $isFolder 00552 ); 00553 } 00554 00555 /** 00556 * Deletes a file/folder 00557 * 00558 * @param string $file 00559 * @param boolean $isFolder 00560 * @return array 00561 */ 00562 public function deleteFile($file, $isFolder) { 00563 00564 $file = str_replace('//', '/', PATH_site . $file); 00565 $command['delete'][] = array( 00566 'data' => $file 00567 ); 00568 $result = $this->fileOperation($command); 00569 00570 return array( 00571 'success' => TRUE, 00572 'file' => $file, 00573 'isFolder' => $isFolder, 00574 'command' => $command, 00575 'result' => $result 00576 ); 00577 } 00578 00579 /** 00580 * Shows a diff of content changes of a file 00581 * 00582 * @param string $file 00583 * @param string $content 00584 * @return array 00585 */ 00586 public function makeDiff($original, $content) { 00587 $diff = t3lib_div::makeInstance('t3lib_diff'); 00588 $result = $diff->makeDiffDisplay($original, $content); 00589 //debug(array($original, $content, $result)); 00590 return array( 00591 'success' => TRUE, 00592 'diff' => '<pre>' . $result . '</pre>' 00593 ); 00594 } 00595 00596 /** 00597 * Load upload form for extension upload to TER 00598 * 00599 * @formcHandler 00600 * @return array 00601 */ 00602 public function loadUploadExtToTer() { 00603 $settings = $this->getSettings(); 00604 return array( 00605 'success' => TRUE, 00606 'data' => array( 00607 'fe_u' => $settings['fe_u'], 00608 'fe_p' => $settings['fe_p'] 00609 ) 00610 ); 00611 } 00612 00613 /** 00614 * Upload extension to TER 00615 * 00616 * @formHandler 00617 * 00618 * @param string $parameter 00619 * @return array 00620 */ 00621 public function uploadExtToTer($parameter) { 00622 $repository = $this->getSelectedRepository(); 00623 $wsdlURL = $repository['wsdl_url']; 00624 00625 $parameter['user']['fe_u'] = $parameter['fe_u']; 00626 $parameter['user']['fe_p'] = $parameter['fe_p']; 00627 $parameter['upload']['mode'] = $parameter['newversion']; 00628 $parameter['upload']['comment'] = $parameter['uploadcomment']; 00629 00630 /** @var $extensionList tx_em_Extensions_List */ 00631 $extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this); 00632 list($list,) = $extensionList->getInstalledExtensions(); 00633 /** @var $extensionDetails tx_em_Extensions_Details */ 00634 $this->extensionDetails = t3lib_div::makeInstance('tx_em_Extensions_Details', $this); 00635 00636 /** @var $terConnection tx_em_Connection_Ter*/ 00637 $terConnection = t3lib_div::makeInstance('tx_em_Connection_Ter', $this); 00638 $terConnection->wsdlURL = $wsdlURL; 00639 00640 $parameter['extInfo'] = $list[$parameter['extKey']]; 00641 $response = $terConnection->uploadToTER($parameter); 00642 00643 if (!is_array($response)) { 00644 return array( 00645 'success' => FALSE, 00646 'error' => $response, 00647 'params' => $parameter, 00648 ); 00649 } 00650 if ($response['resultCode'] == 10504) { //success 00651 $parameter['extInfo']['EM_CONF']['version'] = $response['version']; 00652 $response['resultMessages'][] = sprintf( 00653 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:terCommunication_ext_version'), 00654 $response['version'] 00655 ); 00656 $response['resultMessages'][] = $this->extensionDetails->updateLocalEM_CONF($parameter['extKey'], $parameter['extInfo']); 00657 } 00658 00659 return array( 00660 'success' => TRUE, 00661 'params' => $parameter, 00662 'response' => $response 00663 ); 00664 } 00665 00666 /** 00667 * Prints developer information 00668 * 00669 * @param string $parameter 00670 * @return string 00671 */ 00672 public function getExtensionDevelopInfo($extKey) { 00673 /** @var $extensionList tx_em_Extensions_List*/ 00674 $extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this); 00675 list($list,) = $extensionList->getInstalledExtensions(); 00676 /** @var $extensionDetails tx_em_Extensions_Details */ 00677 $extensionDetails = t3lib_div::makeInstance('tx_em_Extensions_Details', $this); 00678 00679 return $extensionDetails->extInformationarray($extKey, $list[$extKey]); 00680 } 00681 00682 00683 /** 00684 * Prints backupdelete 00685 * 00686 * @param string $parameter 00687 * @return string 00688 */ 00689 public function getExtensionBackupDelete($extKey) { 00690 $content=''; 00691 /** @var $extensionList tx_em_Extensions_List*/ 00692 $extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this); 00693 /** @var $extensionDetails tx_em_Extensions_Details */ 00694 $extensionDetails = t3lib_div::makeInstance('tx_em_Extensions_Details'); 00695 /** @var $extensionDetails tx_em_Connection_Ter */ 00696 $terConnection = t3lib_div::makeInstance('tx_em_Connection_Ter', $this); 00697 /** @var $extensionDetails tx_em_Install */ 00698 $install = t3lib_div::makeInstance('tx_em_Install'); 00699 /** @var $api tx_em_API */ 00700 $api = t3lib_div::makeInstance('tx_em_API'); 00701 00702 00703 list($list,) = $extensionList->getInstalledExtensions(); 00704 $uploadArray = $extensionDetails->makeUploadarray($extKey, $list[$extKey]); 00705 00706 if (is_array($uploadArray)) { 00707 $backUpData = $terConnection->makeUploadDataFromarray($uploadArray); 00708 $filename = 'T3X_' . $extKey . '-' . str_replace('.', '_', $list[$extKey]['EM_CONF']['version']) . '-z-' . date('YmdHi') . '.t3x'; 00709 00710 $techInfo = $install->makeDetailedExtensionAnalysis($extKey, $list[$extKey]); 00711 $lines = array(); 00712 00713 // Backup 00714 $lines[] = '<tr class="t3-row-header"><td colspan="2">' . 00715 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_backup') . '</td></tr>'; 00716 $lines[] = '<tr class="bgColor4"><td><strong>' . 00717 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extBackup_files') . '</strong></td><td>' . 00718 '<a class="t3-link" href="' . htmlspecialchars(t3lib_div::linkThisScript(array( 00719 'CMD[doBackup]' => 1, 00720 'CMD[showExt]' => $extKey, 00721 'SET[singleDetails]' => 'backup' 00722 ))) . 00723 '">' . sprintf($GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extBackup_download'), 00724 $extKey 00725 ) . '</a><br /> 00726 (' . $filename . ', <br />' . 00727 t3lib_div::formatSize(strlen($backUpData)) . ', <br />' . 00728 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extBackup_md5') . ' ' . md5($backUpData) . ') 00729 <br /></td></tr>'; 00730 00731 00732 if (is_array($techInfo['tables'])) { 00733 $lines[] = '<tr class="bgColor4"><td><strong>' . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extBackup_data_tables') . 00734 '</strong></td><td>' . 00735 tx_em_Database::dumpDataTablesLine($techInfo['tables'], $extKey, array('SET[singleDetails]' => 'backup')) . 00736 '</td></tr>'; 00737 } 00738 if (is_array($techInfo['static'])) { 00739 $lines[] = '<tr class="bgColor4"><td><strong>' . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extBackup_static_tables') . 00740 '</strong></td><td>' . 00741 tx_em_Database::dumpDataTablesLine($techInfo['static'], $extKey, array('SET[singleDetails]' => 'backup')) . 00742 '</td></tr>'; 00743 } 00744 00745 // Delete 00746 if (!t3lib_extMgm::isLoaded($extKey)) { 00747 // check ext scope 00748 if (tx_em_Tools::deleteAsType($list[$extKey]['type']) && t3lib_div::inList('G,L', $list[$extKey]['type'])) { 00749 $lines[] = '<tr class="t3-row-header"><td colspan="2">' . 00750 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_delete') . '</td></tr>'; 00751 $lines[] = '<tr class="bgColor4"><td colspan="2">' . $install->extDelete($extKey, $list[$extKey], '') . '</td></tr>'; 00752 } 00753 } 00754 // EM_CONF 00755 $lines[] = '<tr class="t3-row-header"><td colspan="2">' . 00756 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_update_em_conf') . '</td></tr>'; 00757 00758 00759 $updateEMConf = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extUpdateEMCONF_file'); 00760 $lines[] = '<tr class="bgColor4"><td colspan="2">' . 00761 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extUpdateEMCONF_info_changes') . '<br /> 00762 ' . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extUpdateEMCONF_info_reset') . 00763 '<br /><br />' . 00764 '<a class="t3-link emconfLink" href="#"><strong>' . $updateEMConf . '</strong> ' . 00765 sprintf($GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extDelete_from_location'), 00766 $api->typeLabels[$list[$extKey]['type']], 00767 substr(tx_em_Tools::getExtPath($extKey, $list[$extKey]['type']['type']), strlen(PATH_site)) 00768 ) . '</a>' 00769 . '</td></tr>'; 00770 00771 00772 // mod menu for singleDetails 00773 $modMenu = $GLOBALS['TBE_MODULES_EXT']['tools_em']['MOD_MENU']['singleDetails']; 00774 if (isset($modMenu) && is_array($modMenu)) { 00775 $lines[] = '<tr class="t3-row-header"><td colspan="2">' . 00776 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_externActions') . '</td></tr>'; 00777 $menuLinks = ''; 00778 foreach ($modMenu as $menuEntry) { 00779 $onClick = htmlspecialchars('jumpToUrl(\'mod.php?&id=0&M=tools_em&SET[singleDetails]=' . $menuEntry['name'] . '&CMD[showExt]=' . $extKey . '\');'); 00780 $menuLinks .= '<a class="t3-link" href="#" onclick="' . $onClick . '" >' . 00781 $GLOBALS['LANG']->sL($menuEntry['title'], TRUE) . '</a><br />'; 00782 } 00783 $lines[] = '<tr class="bgColor4"><td colspan="2"><p>' . $menuLinks . '</p></td></tr>'; 00784 } 00785 00786 $content = '<table border="0" cellpadding="2" cellspacing="2">' . implode('', $lines) . '</table>'; 00787 00788 00789 00790 return $this->replaceLinks($content); 00791 } 00792 } 00793 00794 /** 00795 * Execute update script 00796 * 00797 * @param $extkey 00798 * @return array 00799 */ 00800 public function getExtensionUpdateScript($extkey) { 00801 $updateScript = t3lib_extMgm::extPath($extkey) . 'class.ext_update.php'; 00802 require_once($updateScript); 00803 $updateObj = new ext_update; 00804 $access = FALSE; 00805 if ($updateObj->access()) { 00806 $access = TRUE; 00807 } 00808 00809 return array( 00810 'success' => $access, 00811 ); 00812 00813 } 00814 /*********************************************************************/ 00815 /* Remote Extension List */ 00816 /*********************************************************************/ 00817 00818 00819 /** 00820 * Render remote extension list 00821 * 00822 * @param object $parameters 00823 * @return string $content 00824 */ 00825 public function getRemoteExtensionList($parameters) { 00826 $repositoryId = $parameters->repository; 00827 $mirrorUrl = $this->getMirrorUrl($repositoryId); 00828 00829 $list = $this->getFlatExtensionList(); 00830 $localList = $list['data']; 00831 00832 $search = htmlspecialchars($parameters->query); 00833 $limit = htmlspecialchars($parameters->start . ', ' . $parameters->limit); 00834 $orderBy = htmlspecialchars($parameters->sort); 00835 $orderDir = htmlspecialchars($parameters->dir); 00836 if ($orderBy == '') { 00837 $orderBy = 'relevance'; 00838 $orderDir = 'ASC'; 00839 } 00840 if ($orderBy === 'statevalue') { 00841 $orderBy = 'cache_extensions.state ' . $orderDir; 00842 } elseif ($orderBy === 'relevance') { 00843 $orderBy = 'relevance ' . $orderDir . ', cache_extensions.title ' . $orderDir; 00844 } else { 00845 $orderBy = 'cache_extensions.' . $orderBy . ' ' . $orderDir; 00846 } 00847 $installedOnly = $parameters->installedOnly; 00848 00849 $where = $addFields = ''; 00850 00851 if ($search === '' && !$installedOnly) { 00852 return array( 00853 'length' => 0, 00854 'data' => array(), 00855 ); 00856 } elseif ($search === '*') { 00857 00858 } else { 00859 $quotedSearch = $GLOBALS['TYPO3_DB']->escapeStrForLike( 00860 $GLOBALS['TYPO3_DB']->quoteStr($search, 'cache_extensions'), 00861 'cache_extensions' 00862 ); 00863 $addFields = ' 00864 (CASE WHEN cache_extensions.extkey = "' . $search . '" THEN 100 ELSE 5 END) + 00865 (CASE WHEN cache_extensions.title = "' . $search . '" THEN 80 ELSE 5 END) + 00866 (CASE WHEN cache_extensions.extkey LIKE \'%' . $quotedSearch . '%\' THEN 60 ELSE 5 END) + 00867 (CASE WHEN cache_extensions.title LIKE \'%' . $quotedSearch . '%\' THEN 40 ELSE 5 END) 00868 AS relevance'; 00869 00870 if (t3lib_extMgm::isLoaded('dbal')) { 00871 // as dbal can't use the sum, make it more easy for dbal 00872 $addFields = 'CASE WHEN cache_extensions.extkey = \'' . $search . '\' THEN 100 ELSE 10 END AS relevance'; 00873 } 00874 $where = ' AND (cache_extensions.extkey LIKE \'%' . $quotedSearch . '%\' OR cache_extensions.title LIKE \'%' . $quotedSearch . '%\')'; 00875 00876 } 00877 // check for filter 00878 $where .= $this->makeFilterQuery(get_object_vars($parameters)); 00879 00880 if ($installedOnly) { 00881 $temp = array(); 00882 foreach ($localList as $key => $value) { 00883 if ($value['installed']) { 00884 $temp[] = '"' . $key . '"'; 00885 } 00886 } 00887 $where .= ' AND cache_extensions.extkey IN(' . implode(',', $temp) . ')'; 00888 $limit = ''; 00889 } 00890 00891 00892 $list = tx_em_Database::getExtensionListFromRepository( 00893 $repositoryId, 00894 $addFields, 00895 $where, 00896 $orderBy, 00897 $limit 00898 ); 00899 00900 $updateKeys = array(); 00901 00902 // transform array 00903 foreach ($list['results'] as $key => $value) { 00904 $list['results'][$key]['dependencies'] = unserialize($value['dependencies']); 00905 $extPath = t3lib_div::strtolower($value['extkey']); 00906 $list['results'][$key]['statevalue'] = $value['state']; 00907 $list['results'][$key]['state'] = tx_em_Tools::getDefaultState(intval($value['state'])); 00908 $list['results'][$key]['stateCls'] = 'state-' . $list['results'][$key]['state']; 00909 $list['results'][$key]['version'] = tx_em_Tools::versionFromInt($value['maxintversion']); 00910 $list['results'][$key]['icon'] = '<img alt="" src="' . $mirrorUrl . $extPath{0} . '/' . $extPath{1} . '/' . $extPath . '_' . $list['results'][$key]['version'] . '.gif" />'; 00911 00912 $list['results'][$key]['exists'] = 0; 00913 $list['results'][$key]['installed'] = 0; 00914 $list['results'][$key]['versionislower'] = 0; 00915 $list['results'][$key]['existingVersion'] = ''; 00916 if (isset($localList[$value['extkey']])) { 00917 $isUpdatable = ($localList[$value['extkey']]['intversion'] < $value['maxintversion']); 00918 $list['results'][$key]['exists'] = 1; 00919 $list['results'][$key]['installed'] = $localList[$value['extkey']]['installed']; 00920 $list['results'][$key]['versionislower'] = $isUpdatable; 00921 $list['results'][$key]['existingVersion'] = $localList[$value['extkey']]['version']; 00922 if ($isUpdatable) { 00923 $updateKeys[] = $key; 00924 } 00925 } 00926 } 00927 // updatable only 00928 if ($installedOnly == 2) { 00929 $temp = array(); 00930 if (count($updateKeys)) { 00931 foreach ($updateKeys as $key) { 00932 $temp[]= $list['results'][$key]; 00933 } 00934 } 00935 $list['results'] = $temp; 00936 $list['count'] -= count($updateKeys); 00937 } 00938 00939 return array( 00940 'length' => $list['count'], 00941 'data' => $list['results'], 00942 ); 00943 00944 } 00945 00946 00947 /** 00948 * Loads repositories 00949 * 00950 * @return array 00951 */ 00952 public function getRepositories() { 00953 $settings = $this->getSettings(); 00954 $repositories = tx_em_Database::getRepositories(); 00955 $data = array(); 00956 00957 foreach ($repositories as $uid => $repository) { 00958 $data[] = array( 00959 'title' => $repository['title'], 00960 'uid' => $repository['uid'], 00961 'description' => $repository['description'], 00962 'wsdl_url' => $repository['wsdl_url'], 00963 'mirror_url' => $repository['mirror_url'], 00964 'count' => $repository['extCount'], 00965 'updated' => $repository['lastUpdated'] ? date('d/m/Y H:i', $repository['lastUpdated']) : 'never', 00966 'selected' => $repository['uid'] === $settings['selectedRepository'], 00967 ); 00968 } 00969 00970 return array( 00971 'length' => count($data), 00972 'data' => $data, 00973 ); 00974 } 00975 00976 00977 /** 00978 * Get Mirrors for selected repository 00979 * 00980 * @param object $parameter 00981 * @return array 00982 */ 00983 public function getMirrors($parameter) { 00984 $data = array(); 00985 /** @var $objRepository tx_em_Repository */ 00986 $objRepository = t3lib_div::makeInstance('tx_em_Repository', $parameter->repository); 00987 00988 if ($objRepository->getMirrorListUrl()) { 00989 $objRepositoryUtility = t3lib_div::makeInstance('tx_em_Repository_Utility', $objRepository); 00990 $mirrors = $objRepositoryUtility->getMirrors(TRUE)->getMirrors(); 00991 00992 00993 if (count($mirrors)) { 00994 $data = array( 00995 array( 00996 'title' => $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:mirror_use_random'), 00997 'country' => '', 00998 'host' => '', 00999 'path' => '', 01000 'sponsor' => '', 01001 'link' => '', 01002 'logo' => '', 01003 ) 01004 ); 01005 foreach ($mirrors as $mirror) { 01006 $data[] = array( 01007 'title' => $mirror['title'], 01008 'country' => $mirror['country'], 01009 'host' => $mirror['host'], 01010 'path' => $mirror['path'], 01011 'sponsor' => $mirror['sponsorname'], 01012 'link' => $mirror['sponsorlink'], 01013 'logo' => $mirror['sponsorlogo'], 01014 ); 01015 } 01016 } 01017 } 01018 01019 return array( 01020 'length' => count($data), 01021 'data' => $data, 01022 ); 01023 01024 } 01025 01026 /** 01027 * Edit / Create repository 01028 * 01029 * @formHandler 01030 * @param array $parameter 01031 * @return array 01032 */ 01033 public function repositoryEditFormSubmit($parameter) { 01034 $repId = intval($parameter['rep']); 01035 01036 /** @var $repository tx_em_Repository */ 01037 $repository = t3lib_div::makeInstance('tx_em_Repository', $repId); 01038 $repository->setTitle($parameter['title']); 01039 $repository->setDescription($parameter['description']); 01040 $repository->setWsdlUrl($parameter['wsdl_url']); 01041 $repository->setMirrorListUrl($parameter['mirror_url']); 01042 $repositoryData = array( 01043 'title' => $repository->getTitle(), 01044 'description' => $repository->getDescription(), 01045 'wsdl_url' => $repository->getWsdlUrl(), 01046 'mirror_url' => $repository->getMirrorListUrl(), 01047 'lastUpdated' => $repository->getLastUpdate(), 01048 'extCount' => $repository->getExtensionCount(), 01049 ); 01050 01051 if ($repId === 0) { 01052 // create a new repository 01053 $id = tx_em_Database::insertRepository($repository); 01054 return array( 01055 'success' => TRUE, 01056 'newId' => $id, 01057 'params' => $repositoryData 01058 ); 01059 01060 } else { 01061 tx_em_Database::updateRepository($repository); 01062 return array( 01063 'success' => TRUE, 01064 'params' => $repositoryData 01065 ); 01066 } 01067 } 01068 01069 01070 /** 01071 * Delete repository 01072 * 01073 * @param int $uid 01074 * @return array 01075 */ 01076 public function deleteRepository($uid) { 01077 if (intval($uid) < 2) { 01078 return array( 01079 'success' => FALSE, 01080 'error' => $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:repository_main_nodelete') 01081 ); 01082 } 01083 $repository = t3lib_div::makeInstance('tx_em_Repository', intval($uid)); 01084 tx_em_Database::deleteRepository($repository); 01085 return array( 01086 'success' => TRUE, 01087 'uid' => intval($uid) 01088 ); 01089 } 01090 /** 01091 * Update repository 01092 * 01093 * @param array $parameter 01094 * @return array 01095 */ 01096 public function repositoryUpdate($repositoryId) { 01097 01098 if (!intval($repositoryId)) { 01099 return array( 01100 'success' => FALSE, 01101 'errors' => 'no repository choosen', 01102 'rep' => 0 01103 ); 01104 } 01105 01106 /** @var $objRepository tx_em_Repository */ 01107 $objRepository = t3lib_div::makeInstance('tx_em_Repository', intval($repositoryId)); 01108 /** @var $objRepositoryUtility tx_em_Repository_Utility */ 01109 $objRepositoryUtility = t3lib_div::makeInstance('tx_em_Repository_Utility', $objRepository); 01110 $count = $objRepositoryUtility->updateExtList(); 01111 $time = $GLOBALS['EXEC_TIME']; 01112 01113 if ($count) { 01114 $objRepository->setExtensionCount($count); 01115 $objRepository->setLastUpdate($time); 01116 tx_em_Database::updateRepository($objRepository); 01117 return array( 01118 'success' => TRUE, 01119 'data' => array( 01120 'count' => $count, 01121 'updated' => date('d/m/Y H:i', $time) 01122 ), 01123 'rep' => intval($repositoryId) 01124 ); 01125 } else { 01126 return array( 01127 'success' => FALSE, 01128 'errormsg' => $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:repository_upToDate'), 01129 'rep' => intval($repositoryId) 01130 ); 01131 } 01132 } 01133 01134 01135 /*********************************************************************/ 01136 /* Translation Handling */ 01137 /*********************************************************************/ 01138 01139 01140 /** 01141 * Gets the system languages 01142 * 01143 * @return array 01144 */ 01145 public function getLanguages() { 01146 $this->globalSettings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['em']); 01147 $selected = t3lib_div::trimExplode(',', $this->globalSettings['selectedLanguages'], TRUE); 01148 01149 $theLanguages = t3lib_div::trimExplode('|', TYPO3_languages); 01150 //drop default 01151 array_shift($theLanguages); 01152 $lang = $meta = array(); 01153 foreach ($theLanguages as $language) { 01154 $label = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:setup/mod/locallang.xml:lang_' . $language)); 01155 $lang[] = array( 01156 'label' => $label, 01157 'lang' => $language, 01158 'selected' => is_array($selected) && in_array($language, $selected) ? 1 : 0 01159 ); 01160 $meta[] = array( 01161 'hidden' => is_array($selected) && in_array($language, $selected) ? 'false' : 'true', 01162 'header' => $language, 01163 'dataIndex' => $language, 01164 'width' => '100', 01165 'fixed' => TRUE, 01166 'sortable' => FALSE, 01167 'hidable' => FALSE, 01168 'menuDisabled' => TRUE, 01169 ); 01170 } 01171 return array( 01172 'length' => count($lang), 01173 'data' => $lang, 01174 'meta' => $meta, 01175 ); 01176 01177 } 01178 01179 /** 01180 * Saves language selection 01181 * 01182 * @param array $parameter 01183 * @return string 01184 */ 01185 public function saveLanguageSelection($parameter) { 01186 $this->globalSettings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['em']); 01187 $selected = t3lib_div::trimExplode(',', $this->globalSettings['selectedLanguages'], TRUE); 01188 01189 $dir = count($parameter) - count($selected); 01190 $diff = $dir < 0 ? array_diff($selected, $parameter) : array_diff($parameter, $selected); 01191 $type = tx_em_Tools::getExtTypeFromPath(t3lib_extMgm::extPath('em')); 01192 01193 $params = array( 01194 'extkey' => 'em', 01195 'exttype' => $type, 01196 'data' => array( 01197 'selectedLanguages' => implode(',', $parameter) 01198 ) 01199 ); 01200 $this->saveExtensionConfiguration($params); 01201 01202 return array( 01203 'success' => TRUE, 01204 'dir' => $dir, 01205 'diff' => implode('', $diff) 01206 ); 01207 } 01208 01209 01210 /** 01211 * Fetches translation from server 01212 * 01213 * @param string $extkey 01214 * @param string $type 01215 * @param array $selection 01216 * @return array 01217 */ 01218 public function fetchTranslations($extkey, $type, $selection) { 01219 $result = array(); 01220 if (is_array($selection) && count($selection)) { 01221 $terConnection = t3lib_div::makeInstance('tx_em_Connection_Ter', $this); 01222 $this->xmlHandler = t3lib_div::makeInstance('tx_em_Tools_XmlHandler'); 01223 $this->xmlHandler->emObj = $this; 01224 $mirrorURL = $this->getSettingsObject()->getMirrorURL(); 01225 01226 $infoIcon = '<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-info"> </span>'; 01227 $updateIcon = '<span class="t3-icon t3-icon-actions t3-icon-actions-system t3-icon-system-extension-update"> </span>'; 01228 $newIcon = '<span class="t3-icon t3-icon-actions t3-icon-actions-system t3-icon-system-extension-import"> </span>'; 01229 $okIcon = '<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-checked"> </span>'; 01230 $errorIcon = '<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-permission-denied"> </span>'; 01231 01232 foreach ($selection as $lang) { 01233 $fetch = $terConnection->fetchTranslationStatus($extkey, $mirrorURL); 01234 01235 $localmd5 = ''; 01236 if (!isset($fetch[$lang])) { 01237 //no translation available 01238 $result[$lang] = $infoIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:translation_n_a'); 01239 } else { 01240 $zip = PATH_site . 'typo3temp/' . $extkey . '-l10n-' . $lang . '.zip'; 01241 if (is_file($zip)) { 01242 $localmd5 = md5_file($zip); 01243 } 01244 if ($localmd5 !== $fetch[$lang]['md5']) { 01245 if ($type) { 01246 //fetch translation 01247 $ret = $terConnection->updateTranslation($extkey, $lang, $mirrorURL); 01248 01249 $result[$lang] = $ret 01250 ? $okIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_updated') 01251 : $errorIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_failed'); 01252 } else { 01253 //translation status 01254 $result[$lang] = $localmd5 !== '' 01255 ? $updateIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:translation_status_update') 01256 : $newIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:translation_status_new'); 01257 } 01258 } else { 01259 //translation is up to date 01260 $result[$lang] = $okIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:translation_status_uptodate');; 01261 } 01262 } 01263 01264 01265 } 01266 } 01267 return $result; 01268 } 01269 01270 01271 /*********************************************************************/ 01272 /* Settings */ 01273 /*********************************************************************/ 01274 01275 /** 01276 * Returns settings object. 01277 * 01278 * @access public 01279 * @return tx_em_Settings instance of settings object 01280 */ 01281 public function getSettings() { 01282 return $this->getSettingsObject()->getSettings(); 01283 } 01284 01285 /** 01286 * Enter description here... 01287 * 01288 * @param string $name 01289 * @param mixed $value 01290 * @return boolean 01291 */ 01292 public function saveSetting($name, $value) { 01293 $this->getSettingsObject()->saveSetting($name, $value); 01294 return TRUE; 01295 } 01296 01297 /** 01298 * Load form values for settings form 01299 * 01300 * @return array FormValues 01301 */ 01302 public function settingsFormLoad() { 01303 $settings = $this->getSettings(); 01304 01305 return array( 01306 'success' => TRUE, 01307 'data' => array( 01308 'display_unchecked' => $settings['display_unchecked'], 01309 'fe_u' => $settings['fe_u'], 01310 'fe_p' => $settings['fe_p'], 01311 'selectedMirror' => $settings['selectedMirror'], 01312 'selectedRepository' => $settings['selectedRepository'], 01313 ) 01314 ); 01315 } 01316 01317 /** 01318 * Save settings from form submit 01319 * 01320 * @formHandler 01321 * @param array $parameter 01322 * @return array 01323 */ 01324 public function settingsFormSubmit($parameter) { 01325 $settings = $this->getSettingsObject()->saveSettings(array( 01326 'display_unchecked' => isset($parameter['display_unchecked']), 01327 'fe_u' => $parameter['fe_u'], 01328 'fe_p' => $parameter['fe_p'], 01329 'selectedMirror' => $parameter['selectedMirror'], 01330 'selectedRepository' => $parameter['selectedRepository'], 01331 )); 01332 return array( 01333 'success' => TRUE, 01334 'data' => $parameter, 01335 'settings' => $settings 01336 ); 01337 } 01338 01339 01340 /*********************************************************************/ 01341 /* EM Tools */ 01342 /*********************************************************************/ 01343 01344 /** 01345 * Upload an extension 01346 * 01347 * @formHandler 01348 * 01349 * @access public 01350 * @param $parameter composed parameter from $POST and $_FILES 01351 * @return array status 01352 */ 01353 public function uploadExtension($parameter) { 01354 $uploadedTempFile = isset($parameter['extfile']) ? $parameter['extfile'] : t3lib_div::upload_to_tempfile($parameter['extupload-path']['tmp_name']); 01355 $location = ($parameter['loc'] === 'G' || $parameter['loc'] === 'S') ? $parameter['loc'] : 'L'; 01356 $uploadOverwrite = $parameter['uploadOverwrite'] ? TRUE : FALSE; 01357 01358 $install = t3lib_div::makeInstance('tx_em_Install', $this); 01359 $this->extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this); 01360 $this->extensionDetails = t3lib_div::makeInstance('tx_em_Extensions_Details', $this); 01361 01362 $upload = $install->uploadExtensionFile($uploadedTempFile, $location, $uploadOverwrite); 01363 01364 if ($upload[0] === FALSE) { 01365 return array( 01366 'success' => FALSE, 01367 'error' => $upload[1] 01368 ); 01369 } 01370 01371 $extKey = $upload[1][0]['extKey']; 01372 $version = ''; 01373 $dontDelete = TRUE; 01374 $result = $install->installExtension($upload[1], $location, $version, $uploadedTempFile, $dontDelete); 01375 return array( 01376 'success' => TRUE, 01377 'data' => $result, 01378 'extKey' => $extKey 01379 ); 01380 01381 } 01382 01383 /** 01384 * Enables an extension 01385 * 01386 * @param $extensionKey 01387 * @return void 01388 */ 01389 public function enableExtension($extensionKey) { 01390 $this->extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this); 01391 $install = t3lib_div::makeInstance('tx_em_Install', $this); 01392 01393 list($installedList,) = $this->extensionList->getInstalledExtensions(); 01394 $newExtensionList = $this->extensionList->addExtToList($extensionKey, $installedList); 01395 01396 $install->writeNewExtensionList($newExtensionList); 01397 tx_em_Tools::refreshGlobalExtList(); 01398 $install->forceDBupdates($extensionKey, $installedList[$extensionKey]); 01399 } 01400 01401 /** 01402 * Reset all states for current user 01403 * 01404 * @return void 01405 */ 01406 public function resetStates() { 01407 unset($GLOBALS['BE_USER']->uc['moduleData']['tools_em']['States']); 01408 $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc); 01409 return array('success' => TRUE); 01410 } 01411 01412 /** 01413 * Gets the mirror url from selected mirror 01414 * 01415 * @param $repositoryId 01416 * @return string 01417 */ 01418 protected function getMirrorUrl($repositoryId) { 01419 $settings = $this->getSettings(); 01420 /** @var $objRepository tx_em_Repository */ 01421 $objRepository = t3lib_div::makeInstance('tx_em_Repository', $repositoryId); 01422 /** @var $objRepositoryUtility tx_em_Repository_Utility */ 01423 $objRepositoryUtility = t3lib_div::makeInstance('tx_em_Repository_Utility', $objRepository); 01424 $mirrors = $objRepositoryUtility->getMirrors(TRUE)->getMirrors(); 01425 01426 01427 if ($settings['selectedMirror'] == '') { 01428 $randomMirror = array_rand($mirrors); 01429 $mirrorUrl = $mirrors[$randomMirror]['host'] . $mirrors[$randomMirror]['path']; 01430 } else { 01431 foreach($mirrors as $mirror) { 01432 if ($mirror['host'] == $settings['selectedMirror']) { 01433 $mirrorUrl = $mirror['host'] . $mirror['path']; 01434 break; 01435 } 01436 } 01437 } 01438 01439 return 'http://' . $mirrorUrl; 01440 } 01441 01442 /** 01443 * Resolves the filter settings from repository list and makes a whereClause 01444 * 01445 * @param array $parameter 01446 * @return string additional whereClause 01447 */ 01448 protected function makeFilterQuery($parameter) { 01449 $where = ''; 01450 $filter = $found = array(); 01451 01452 foreach ($parameter as $key => $value) { 01453 if (substr($key, 0, 6) === 'filter') { 01454 eval('$' . $key . ' = \'' . $value . '\';'); 01455 } 01456 } 01457 01458 01459 if (count($filter)) { 01460 foreach ($filter as $value) { 01461 switch ($value['data']['type']) { 01462 case 'list': 01463 if ($value['field'] === 'statevalue') { 01464 $where .= ' AND cache_extensions.state IN(' . htmlspecialchars($value['data']['value']) . ')'; 01465 } 01466 if ($value['field'] === 'category') { 01467 $where .= ' AND cache_extensions.category IN(' . htmlspecialchars($value['data']['value']) . ')'; 01468 } 01469 break; 01470 default: 01471 $quotedSearch = $GLOBALS['TYPO3_DB']->escapeStrForLike( 01472 $GLOBALS['TYPO3_DB']->quoteStr($value['data']['value'], 'cache_extensions'), 01473 'cache_extensions' 01474 ); 01475 $where .= ' AND cache_extensions.' . htmlspecialchars($value['field']) . ' LIKE "%' . $quotedSearch . '%"'; 01476 } 01477 } 01478 } 01479 return $where; 01480 } 01481 01482 /** 01483 * Replace links that are created with t3lib_div::linkThisScript to point to module 01484 * 01485 * @param string $string 01486 * @return string 01487 */ 01488 protected function replaceLinks($string) { 01489 return str_replace( 01490 'ajax.php?ajaxID=ExtDirect%3A%3Aroute&namespace=TYPO3.EM', 01491 'mod.php?M=tools_em', 01492 $string 01493 ); 01494 } 01495 01496 /** 01497 * Get the selected repository 01498 * 01499 * @return array 01500 */ 01501 protected function getSelectedRepository() { 01502 $settings = $this->getSettings(); 01503 $repositories = tx_em_Database::getRepositories(); 01504 $selectedRepository = array(); 01505 01506 foreach ($repositories as $uid => $repository) { 01507 if ($repository['uid'] == $settings['selectedRepository']) { 01508 $selectedRepository = array( 01509 'title' => $repository['title'], 01510 'uid' => $repository['uid'], 01511 'description' => $repository['description'], 01512 'wsdl_url' => $repository['wsdl_url'], 01513 'mirror_url' => $repository['mirror_url'], 01514 'count' => $repository['extCount'], 01515 'updated' => $repository['lastUpdated'] ? date('d/m/Y H:i', $repository['lastUpdated']) : 'never', 01516 'selected' => $repository['uid'] === $settings['selectedRepository'], 01517 ); 01518 } 01519 } 01520 01521 return $selectedRepository; 01522 } 01523 01524 /** 01525 * Gets file info for ExtJs tree node 01526 * 01527 * @param $file 01528 * @return array 01529 */ 01530 protected function getFileInfo($file) { 01531 $unknownType = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_file_unknownType'); 01532 $imageType = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_file_imageType'); 01533 $textType = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_file_textType'); 01534 $extType = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_file_extType'); 01535 01536 $editTypes = explode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext']); 01537 $imageTypes = array('gif', 'jpg', 'png'); 01538 01539 $fileExt = ''; 01540 $type = ''; 01541 $cls = t3lib_iconWorks::mapFileExtensionToSpriteIconClass(''); 01542 if (strrpos($file, '.') !== FALSE) { 01543 $fileExt = strtolower(substr($file, strrpos($file, '.') + 1)); 01544 } 01545 01546 if ($fileExt && in_array($fileExt, $imageTypes) || in_array($fileExt, $editTypes)) { 01547 $cls = t3lib_iconWorks::mapFileExtensionToSpriteIconClass($fileExt); 01548 $type = in_array($fileExt, $imageTypes) ? 'image' : 'text'; 01549 } 01550 01551 if (t3lib_div::strtolower($file) === 'changelog') { 01552 $cls = t3lib_iconWorks::mapFileExtensionToSpriteIconClass('txt'); 01553 $type = 'text'; 01554 } 01555 01556 switch($type) { 01557 CASE 'image': 01558 $label = $imageType; 01559 break; 01560 CASE 'text': 01561 $label = $textType; 01562 break; 01563 default: 01564 $label = $fileExt ? sprintf($extType, $fileExt) : $unknownType; 01565 } 01566 01567 return array( 01568 htmlspecialchars($file), 01569 $label, 01570 htmlspecialchars($fileExt), 01571 $type, 01572 $cls 01573 ); 01574 01575 } 01576 01577 01578 /** 01579 * File operations like delete, copy, move 01580 * @param $file commandMap, @see 01581 * @return 01582 */ 01583 protected function fileOperation($file) { 01584 $mount = array(0 => array( 01585 'name' => 'root', 01586 'path' => PATH_site, 01587 'type' => '' 01588 )); 01589 $files = array(0 => array( 01590 'webspace' => array('allow' => '*', 'deny' => ''), 01591 'ftpspace' => array('allow' => '*', 'deny' => '') 01592 )); 01593 $fileProcessor = t3lib_div::makeInstance('t3lib_extFileFunctions'); 01594 $fileProcessor->init($mount, $files); 01595 $fileProcessor->init_actionPerms($GLOBALS['BE_USER']->getFileoperationPermissions()); 01596 $fileProcessor->dontCheckForUnique = 0; 01597 01598 // Checking referer / executing: 01599 $refInfo = parse_url(t3lib_div::getIndpEnv('HTTP_REFERER')); 01600 $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY'); 01601 if ($httpHost != $refInfo['host'] 01602 && $this->vC != $GLOBALS['BE_USER']->veriCode() 01603 && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer'] 01604 && $GLOBALS['CLIENT']['BROWSER'] != 'flash') { 01605 $fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost)); 01606 } else { 01607 $fileProcessor->start($file); 01608 $fileData = $fileProcessor->processData(); 01609 } 01610 01611 return $fileData; 01612 } 01613 01614 } 01615 01616 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/connection/class.tx_em_connectionextdirectserver.php'])) { 01617 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/connection/class.tx_em_connection_extdirectserver.php']); 01618 } 01619 01620 ?>
1.8.0