2 /***************************************************************
5 * (c) 2010 Steffen Kamper (info@sk-typo3.de)
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.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Module: Extension manager, developer module
30 * This class handles all Ajax calls coming from ExtJS
32 * @author Steffen Kamper <info@sk-typo3.de>
36 class tx_em_Connection_ExtDirectServer
{
38 * @var tx_em_Tools_XmlHandler
43 * Class for printing extension lists
45 * @var tx_em_Extensions_List
47 public $extensionList;
50 * Class for extension details
52 * @var tx_em_Extensions_Details
54 public $extensionDetails;
57 * Keeps instance of settings class.
61 static protected $objSettings;
63 protected $globalSettings;
65 /*********************************************************************/
67 /*********************************************************************/
72 * @param boolean $createTemplateInstance: set to FALSE if no instance of template class needs to be created
75 public function __construct($createTemplateInstance = TRUE) {
76 if ($createTemplateInstance) {
77 $this->template
= t3lib_div
::makeInstance('template');
79 $this->globalSettings
= unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['em']);
84 * Method returns instance of settings class.
87 * @return em_settings instance of settings class
89 protected function getSettingsObject() {
90 if (!is_object(self
::$objSettings) && !(self
::$objSettings instanceof tx_em_Settings
)) {
91 self
::$objSettings = t3lib_div
::makeInstance('tx_em_Settings');
93 return self
::$objSettings;
97 /*********************************************************************/
98 /* Local Extension List */
99 /*********************************************************************/
103 * Render local extension list
105 * @return string $content
107 public function getExtensionList() {
108 /** @var $list tx_em_Extensions_List */
109 $list = t3lib_div
::makeInstance('tx_em_Extensions_List');
110 $extList = $list->getInstalledExtensions(TRUE);
114 'length' => count($extList),
120 public function getFlatExtensionList() {
121 $list = $this->getExtensionList();
123 foreach ($list['data'] as $entry) {
124 $flatList[$entry['extkey']] = array(
125 'version' => $entry['version'],
126 'intversion' => t3lib_utility_VersionNumber
::convertVersionNumberToInteger($entry['version']),
127 'installed' => $entry['installed'],
128 'typeShort' => $entry['typeShort'],
132 'length' => count($flatList),
138 * Render extensionlist for languages
142 public function getInstalledExtkeys() {
143 $list = $this->getExtensionList();
144 $extList = $list['data'];
146 $selectedLanguages = t3lib_div
::trimExplode(',', $this->globalSettings
['selectedLanguages']);
150 foreach ($extList as $ext) {
151 if ($ext['installed']) {
153 'extkey' => $ext['extkey'],
154 'icon' => $ext['icon'],
155 'stype' => $ext['typeShort'],
157 $keys[$i]['lang'] = array();
158 if (count($selectedLanguages)) {
159 foreach ($selectedLanguages as $language) {
160 $keys[$i]['lang'][] = $GLOBALS['LANG']->sL('LLL:EXT:setup/mod/locallang.xml:lang_' . $language);
168 'length' => count($keys),
174 * Render module content
176 * @return string $content
178 public function getExtensionDetails() {
179 /** @var $list tx_em_Extensions_List */
180 $list = t3lib_div
::makeInstance('tx_em_Extensions_List');
181 $extList = $list->getInstalledExtensions(TRUE);
185 'length' => count($extList),
192 * Render extension update
194 * @var string $extKey
195 * @return string $content
197 public function getExtensionUpdate($extKey) {
198 if (isset($GLOBALS['TYPO3_LOADED_EXT'][$extKey])) {
199 /** @var $install tx_em_Install */
200 $install = t3lib_div
::makeInstance('tx_em_Install');
201 /** @var $extension tx_em_Extensions_List */
202 $extension = t3lib_div
::makeInstance('tx_em_Extensions_List');
205 $extPath = t3lib_extMgm
::extPath($extKey);
206 $type = tx_em_Tools
::getExtTypeFromPath($extPath);
207 $typePath = tx_em_Tools
::typePath($type);
210 $extension->singleExtInfo($extKey, $typePath, $extInfo);
211 $extInfo = $extInfo[0];
212 $extInfo['type'] = $extInfo['typeShort'];
213 $update = $install->checkDBupdates($extKey, $extInfo);
215 $update = $GLOBALS['LANG']->getLL('ext_details_new_tables_fields_select') .
217 '<br /><input type="submit" name="write" id="update-submit-' . htmlspecialchars($extKey) . '" value="' .
218 htmlspecialchars($GLOBALS['LANG']->getLL('updatesForm_make_updates')) . '" />';
220 return $update ?
$update : $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_dbUpToDate');
222 return sprintf($GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_extNotInstalled') ,htmlspecialchars($extKey));
228 * Render extension configuration
230 * @var string $extKey
231 * @return string $content
233 public function getExtensionConfiguration($extKey) {
234 /** @var $extensionList tx_em_Extensions_List */
235 $extensionList = t3lib_div
::makeInstance('tx_em_Extensions_List', $this);
236 list($list,) = $extensionList->getInstalledExtensions();
237 /** @var $install tx_em_Install */
238 $install = t3lib_div
::makeInstance('tx_em_Install');
239 $install->setSilentMode(TRUE);
241 $form = $install->updatesForm($extKey, $list[$extKey], 1, '', '', FALSE, TRUE);
243 return '<p>' . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_extNoConfiguration') . '</p>';
245 //$form = preg_replace('/<form([^>]+)>/', '', $form);
246 //$form = str_replace('</form>', '', $form);
252 * Save extension configuration
255 * @param array $parameter
258 public function saveExtensionConfiguration($parameter) {
260 $extKey = $parameter['extkey'];
261 $extType = $parameter['exttype'];
262 $noSave = $parameter['noSave'];
264 $absPath = tx_em_Tools
::getExtPath($extKey, $extType);
265 $relPath = tx_em_Tools
::typeRelPath($extType) . $extKey . '/';
267 /** @var $extensionList tx_em_Extensions_List */
268 $extensionList = t3lib_div
::makeInstance('tx_em_Extensions_List', $this);
269 list($list,) = $extensionList->getInstalledExtensions();
272 $arr = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extKey]);
273 $arr = is_array($arr) ?
$arr : array();
275 /** @var $tsStyleConfig t3lib_tsStyleConfig */
276 $tsStyleConfig = t3lib_div
::makeInstance('t3lib_tsStyleConfig');
277 $tsStyleConfig->doNotSortCategoriesBeforeMakingForm
= TRUE;
278 $theConstants = $tsStyleConfig->ext_initTSstyleConfig(
279 t3lib_div
::getUrl($absPath . 'ext_conf_template.txt'),
282 $GLOBALS['BACK_PATH']
285 $tsStyleConfig->ext_procesInput($parameter, array(), $theConstants, array());
286 $arr = $tsStyleConfig->ext_mergeIncomingWithExisting($arr);
289 /** @var $install tx_em_Install */
290 $install = t3lib_div
::makeInstance('tx_em_Install');
291 $install->setSilentMode(TRUE);
292 $install->install
->INSTALL
= $parameter['TYPO3_INSTALL'];
293 $install->checkDBupdates($extKey, $list[$extKey]);
297 $html = $install->updatesForm($extKey, $list[$extKey], 1);
299 $install->writeTsStyleConfig($extKey, $arr);
304 'data' => $parameter['data'],
310 * Cleans EMConf of extension
312 * @param string $extKey
315 public function cleanEmConf($extKey) {
317 /** @var $extensionList tx_em_Extensions_List */
318 $extensionList = t3lib_div
::makeInstance('tx_em_Extensions_List', $this);
319 list($list,) = $extensionList->getInstalledExtensions();
320 /** @var $extensionDetails tx_em_Extensions_Details */
321 $this->extensionDetails
= t3lib_div
::makeInstance('tx_em_Extensions_Details', $this);
323 $result = $this->extensionDetails
->updateLocalEM_CONF($extKey, $list[$extKey]);
338 public function deleteExtension($extKey) {
340 /** @var $extensionList tx_em_Extensions_List */
341 $extensionList = t3lib_div
::makeInstance('tx_em_Extensions_List', $this);
342 list($list,) = $extensionList->getInstalledExtensions();
343 $type = $list[$extKey]['type'];
344 $absPath = tx_em_Tools
::getExtPath($extKey, $type);
346 /** @var $extensionDetails tx_em_Install */
347 $install = t3lib_div
::makeInstance('tx_em_Install');
348 $install->setSilentMode(TRUE);
350 $res = $install->removeExtDirectory($absPath);
356 $error = sprintf($GLOBALS['LANG']->getLL('extDelete_remove_dir_failed'), $absPath);
360 'success' => $success,
368 * genereates a file tree
370 * @param object $parameter
373 public function getExtFileTree($parameter) {
374 $type = $parameter->typeShort
;
375 $node = substr($parameter->node
, 0, 6) !== 'xnode-' ?
$parameter->node
: $parameter->baseNode
;
377 $path = PATH_site
. $node;
378 $fileArray = array();
380 $dirs = t3lib_div
::get_dirs($path);
381 $files = t3lib_div
::getFilesInDir($path, '', FALSE, '', '');
385 if (!is_array($dirs) && !is_array($files)) {
389 foreach ($dirs as $dir) {
390 if ($dir{0} !== '.') {
391 $fileArray[] = array(
392 'id' => ($node == '' ?
'' : $node . '/') . $dir,
393 'text' => htmlspecialchars($dir),
401 foreach ($files as $key => $file) {
402 $fileInfo = $this->getFileInfo($file);
404 $fileArray[] = array(
405 'id' => $node . '/' . $file,
406 'text' => $fileInfo[0],
408 'qtip' => $fileInfo[1],
409 'iconCls' => $fileInfo[4],
410 'fileType' => $fileInfo[3],
411 'ext' => $fileInfo[2]
420 * Read extension file and send content
422 * @param string $path
423 * @return string file content
425 public function readExtFile($path) {
426 $path = PATH_site
. $path;
427 if (@file_exists
($path)) {
428 return t3lib_div
::getUrl($path);
434 * Save extension file
436 * @param string $file
437 * @param string $content
438 * @return boolean success
440 public function saveExtFile($file, $content) {
441 $path = PATH_site
. $file;
443 $fileSaveAllowed = $GLOBALS['TYPO3_CONF_VARS']['EXT']['noEdit'] == 0;
444 $fileExists = @file_exists
($path);
445 $fileSaveable = is_writable($path);
447 if ($fileExists && $fileSaveable && $fileSaveAllowed) {
448 $success = t3lib_div
::writeFile($path, $content);
451 $error = $fileSaveAllowed
453 ?
$GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_fileNotExists', TRUE)
454 : $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_fileWriteProtected', TRUE)
456 : $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_saving_disabled', TRUE);
460 $GLOBALS['BE_USER']->writelog(9, 0, 0, 0, sprintf('File "%s" has been modified', $file));
463 'success' => $success,
465 'file' => basename($path),
466 'content' => $content,
474 * @param string $folder
475 * @param string $file
476 * @param boolean $isFolder
477 * @return array result
479 public function createNewFile($folder, $file, $isFolder) {
480 $result = tx_em_Tools
::createNewFile($folder, $file, $isFolder);
484 if ($result[0] === TRUE) {
487 'id' => htmlspecialchars(substr($result[1], strlen(PATH_site
))),
488 'text' => htmlspecialchars(basename($result[1])),
493 $fileInfo = $this->getFileInfo($result[1]);
495 'id' => substr($fileInfo[0], strlen(PATH_site
)),
496 'text' => basename($fileInfo[0]),
497 'leaf' => !$isFolder,
498 'qtip' => $fileInfo[1],
499 'iconCls' => $fileInfo[4],
500 'fileType' => $fileInfo[3],
501 'ext' => $fileInfo[2]
506 'success' => $result[0],
507 'created' => $result[1],
509 'error' => $result[2]
514 * Rename a file/folder
516 * @param string $file
517 * @param string $newName
518 * @param boolean $isFolder
519 * @return array result
521 public function renameFile($file, $newName, $isFolder) {
522 $src = basename($file);
523 $newFile = substr($file, 0, -1 * strlen($src)) . $newName;
525 $success = tx_em_Tools
::renameFile($file, $newFile);
528 'success' => $success,
530 'newFile' => $newFile,
531 'newFilename' => basename($newFile),
537 * Moves a file to new destination
539 * @param string $file
540 * @param string $destination
541 * @param boolean $isFolder
544 public function moveFile($file, $destination, $isFolder) {
548 'destination' => $destination,
549 'isFolder' => $isFolder
554 * Deletes a file/folder
556 * @param string $file
557 * @param boolean $isFolder
560 public function deleteFile($file, $isFolder) {
562 $file = str_replace('//', '/', PATH_site
. $file);
563 $command['delete'][] = array(
566 $result = $this->fileOperation($command);
571 'isFolder' => $isFolder,
572 'command' => $command,
578 * Shows a diff of content changes of a file
580 * @param string $file
581 * @param string $content
584 public function makeDiff($original, $content) {
585 $diff = t3lib_div
::makeInstance('t3lib_diff');
586 $result = $diff->makeDiffDisplay($original, $content);
587 //debug(array($original, $content, $result));
590 'diff' => '<pre>' . $result . '</pre>'
595 * Load upload form for extension upload to TER
600 public function loadUploadExtToTer() {
601 $settings = $this->getSettings();
605 'fe_u' => $settings['fe_u'],
606 'fe_p' => $settings['fe_p']
612 * Upload extension to TER
616 * @param string $parameter
619 public function uploadExtToTer($parameter) {
620 $repository = $this->getSelectedRepository();
621 $wsdlURL = $repository['wsdl_url'];
623 $parameter['user']['fe_u'] = $parameter['fe_u'];
624 $parameter['user']['fe_p'] = $parameter['fe_p'];
625 $parameter['upload']['mode'] = $parameter['newversion'];
626 $parameter['upload']['comment'] = $parameter['uploadcomment'];
628 /** @var $extensionList tx_em_Extensions_List */
629 $extensionList = t3lib_div
::makeInstance('tx_em_Extensions_List', $this);
630 list($list,) = $extensionList->getInstalledExtensions();
631 /** @var $extensionDetails tx_em_Extensions_Details */
632 $this->extensionDetails
= t3lib_div
::makeInstance('tx_em_Extensions_Details', $this);
634 /** @var $terConnection tx_em_Connection_Ter*/
635 $terConnection = t3lib_div
::makeInstance('tx_em_Connection_Ter', $this);
636 $terConnection->wsdlURL
= $wsdlURL;
638 $parameter['extInfo'] = $list[$parameter['extKey']];
639 $response = $terConnection->uploadToTER($parameter);
641 if (!is_array($response)) {
644 'error' => $response,
645 'params' => $parameter,
648 if ($response['resultCode'] == 10504) { //success
649 $parameter['extInfo']['EM_CONF']['version'] = $response['version'];
650 $response['resultMessages'][] = sprintf(
651 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:terCommunication_ext_version'),
654 $response['resultMessages'][] = $this->extensionDetails
->updateLocalEM_CONF($parameter['extKey'], $parameter['extInfo']);
659 'params' => $parameter,
660 'response' => $response
665 * Prints developer information
667 * @param string $parameter
670 public function getExtensionDevelopInfo($extKey) {
671 /** @var $extensionList tx_em_Extensions_List*/
672 $extensionList = t3lib_div
::makeInstance('tx_em_Extensions_List', $this);
673 list($list,) = $extensionList->getInstalledExtensions();
674 /** @var $extensionDetails tx_em_Extensions_Details */
675 $extensionDetails = t3lib_div
::makeInstance('tx_em_Extensions_Details', $this);
677 return $extensionDetails->extInformationarray($extKey, $list[$extKey]);
682 * Prints backupdelete
684 * @param string $parameter
687 public function getExtensionBackupDelete($extKey) {
689 /** @var $extensionList tx_em_Extensions_List*/
690 $extensionList = t3lib_div
::makeInstance('tx_em_Extensions_List', $this);
691 /** @var $extensionDetails tx_em_Extensions_Details */
692 $extensionDetails = t3lib_div
::makeInstance('tx_em_Extensions_Details');
693 /** @var $terConnection tx_em_Connection_Ter */
694 $terConnection = t3lib_div
::makeInstance('tx_em_Connection_Ter', $this);
695 /** @var $install tx_em_Install */
696 $install = t3lib_div
::makeInstance('tx_em_Install');
697 /** @var $api tx_em_API */
698 $api = t3lib_div
::makeInstance('tx_em_API');
701 list($list,) = $extensionList->getInstalledExtensions();
702 $uploadArray = $extensionDetails->makeUploadarray($extKey, $list[$extKey]);
704 if (is_array($uploadArray)) {
705 $backUpData = $terConnection->makeUploadDataFromarray($uploadArray);
706 $filename = 'T3X_' . $extKey . '-' . str_replace('.', '_', $list[$extKey]['EM_CONF']['version']) . '-z-' . date('YmdHi') . '.t3x';
708 $techInfo = $install->makeDetailedExtensionAnalysis($extKey, $list[$extKey], FALSE, FALSE);
712 $lines[] = '<tr class="t3-row-header"><td colspan="2">' .
713 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_backup') . '</td></tr>';
714 $lines[] = '<tr class="bgColor4"><td><strong>' .
715 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extBackup_files') . '</strong></td><td>' .
716 '<a class="t3-link" href="' . htmlspecialchars(t3lib_div
::linkThisScript(array(
717 'CMD[doBackup]' => 1,
718 'CMD[showExt]' => $extKey,
719 'SET[singleDetails]' => 'backup'
721 '">' . sprintf($GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extBackup_download'),
724 (' . $filename . ', <br />' .
725 t3lib_div
::formatSize(strlen($backUpData)) . ', <br />' .
726 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extBackup_md5') . ' ' . md5($backUpData) . ')
730 if (is_array($techInfo['tables'])) {
731 $lines[] = '<tr class="bgColor4"><td><strong>' . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extBackup_data_tables') .
732 '</strong></td><td>' .
733 tx_em_Database
::dumpDataTablesLine($techInfo['tables'], $extKey, array('SET[singleDetails]' => 'backup')) .
736 if (is_array($techInfo['static'])) {
737 $lines[] = '<tr class="bgColor4"><td><strong>' . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extBackup_static_tables') .
738 '</strong></td><td>' .
739 tx_em_Database
::dumpDataTablesLine($techInfo['static'], $extKey, array('SET[singleDetails]' => 'backup')) .
744 if (!t3lib_extMgm
::isLoaded($extKey)) {
746 if (tx_em_Tools
::deleteAsType($list[$extKey]['type']) && t3lib_div
::inList('G,L', $list[$extKey]['type'])) {
747 $lines[] = '<tr class="t3-row-header"><td colspan="2">' .
748 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_delete') . '</td></tr>';
749 $lines[] = '<tr class="bgColor4"><td colspan="2">' . $install->extDelete($extKey, $list[$extKey], '') . '</td></tr>';
753 $lines[] = '<tr class="t3-row-header"><td colspan="2">' .
754 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_update_em_conf') . '</td></tr>';
757 $updateEMConf = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extUpdateEMCONF_file');
758 $lines[] = '<tr class="bgColor4"><td colspan="2">' .
759 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extUpdateEMCONF_info_changes') . '<br />
760 ' . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extUpdateEMCONF_info_reset') .
762 '<a class="t3-link emconfLink" href="#"><strong>' . $updateEMConf . '</strong> ' .
763 sprintf($GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extDelete_from_location'),
764 $api->typeLabels
[$list[$extKey]['type']],
765 substr(tx_em_Tools
::getExtPath($extKey, $list[$extKey]['type']['type']), strlen(PATH_site
))
770 // mod menu for singleDetails
771 $modMenu = $GLOBALS['TBE_MODULES_EXT']['tools_em']['MOD_MENU']['singleDetails'];
772 if (isset($modMenu) && is_array($modMenu)) {
773 $lines[] = '<tr class="t3-row-header"><td colspan="2">' .
774 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_externActions') . '</td></tr>';
776 foreach ($modMenu as $menuEntry) {
777 $onClick = htmlspecialchars('jumpToUrl(\'mod.php?&id=0&M=tools_em&SET[singleDetails]=' . $menuEntry['name'] . '&CMD[showExt]=' . $extKey . '\');');
778 $menuLinks .= '<a class="t3-link" href="#" onclick="' . $onClick . '" >' .
779 $GLOBALS['LANG']->sL($menuEntry['title'], TRUE) . '</a><br />';
781 $lines[] = '<tr class="bgColor4"><td colspan="2"><p>' . $menuLinks . '</p></td></tr>';
784 $content = '<table border="0" cellpadding="2" cellspacing="2">' . implode('', $lines) . '</table>';
788 return $this->replaceLinks($content);
793 * Execute update script
798 public function getExtensionUpdateScript($extkey) {
799 $updateScript = t3lib_extMgm
::extPath($extkey) . 'class.ext_update.php';
800 require_once($updateScript);
801 $updateObj = new ext_update
;
803 if ($updateObj->access()) {
808 'success' => $access,
812 /*********************************************************************/
813 /* Remote Extension List */
814 /*********************************************************************/
818 * Render remote extension list
820 * @param object $parameters
821 * @return string $content
823 public function getRemoteExtensionList($parameters) {
824 $repositoryId = $parameters->repository
;
825 $mirrorUrl = $this->getMirrorUrl($repositoryId);
827 $list = $this->getFlatExtensionList();
828 $localList = $list['data'];
830 $search = htmlspecialchars($parameters->query
);
831 $limit = htmlspecialchars($parameters->start
. ', ' . $parameters->limit
);
832 $orderBy = htmlspecialchars($parameters->sort
);
833 $orderDir = htmlspecialchars($parameters->dir
);
834 if ($orderBy == '') {
835 $orderBy = 'relevance';
838 if ($orderBy === 'statevalue') {
839 $orderBy = 'cache_extensions.state ' . $orderDir;
840 } elseif ($orderBy === 'relevance') {
841 $orderBy = 'relevance ' . $orderDir . ', cache_extensions.title ' . $orderDir;
843 $orderBy = 'cache_extensions.' . $orderBy . ' ' . $orderDir;
845 $installedOnly = $parameters->installedOnly
;
847 $where = $addFields = '';
849 if ($search === '' && !$installedOnly) {
854 } elseif ($search === '*') {
857 $quotedSearch = $GLOBALS['TYPO3_DB']->escapeStrForLike(
858 $GLOBALS['TYPO3_DB']->quoteStr($search, 'cache_extensions'),
862 (CASE WHEN cache_extensions.extkey = "' . $search . '" THEN 100 ELSE 5 END) +
863 (CASE WHEN cache_extensions.title = "' . $search . '" THEN 80 ELSE 5 END) +
864 (CASE WHEN cache_extensions.extkey LIKE \'%' . $quotedSearch . '%\' THEN 60 ELSE 5 END) +
865 (CASE WHEN cache_extensions.title LIKE \'%' . $quotedSearch . '%\' THEN 40 ELSE 5 END)
868 if (t3lib_extMgm
::isLoaded('dbal')) {
869 // as dbal can't use the sum, make it more easy for dbal
870 $addFields = 'CASE WHEN cache_extensions.extkey = \'' . $search . '\' THEN 100 ELSE 10 END AS relevance';
872 $where = ' AND (cache_extensions.extkey LIKE \'%' . $quotedSearch . '%\' OR cache_extensions.title LIKE \'%' . $quotedSearch . '%\')';
876 $where .= $this->makeFilterQuery(get_object_vars($parameters));
878 if ($installedOnly) {
880 foreach ($localList as $key => $value) {
881 if ($value['installed']) {
882 $temp[] = '"' . $key . '"';
885 $where .= ' AND cache_extensions.extkey IN(' . implode(',', $temp) . ')';
890 $list = tx_em_Database
::getExtensionListFromRepository(
898 $updateKeys = array();
901 foreach ($list['results'] as $key => $value) {
902 $list['results'][$key]['dependencies'] = unserialize($value['dependencies']);
903 $extPath = t3lib_div
::strtolower($value['extkey']);
904 $list['results'][$key]['statevalue'] = $value['state'];
905 $list['results'][$key]['state'] = tx_em_Tools
::getDefaultState(intval($value['state']));
906 $list['results'][$key]['stateCls'] = 'state-' . $list['results'][$key]['state'];
907 $list['results'][$key]['version'] = tx_em_Tools
::versionFromInt($value['maxintversion']);
908 $list['results'][$key]['icon'] = '<img alt="" src="' . $mirrorUrl . $extPath{0} . '/' . $extPath{1} . '/' . $extPath . '_' . $list['results'][$key]['version'] . '.gif" />';
910 $list['results'][$key]['exists'] = 0;
911 $list['results'][$key]['installed'] = 0;
912 $list['results'][$key]['versionislower'] = 0;
913 $list['results'][$key]['existingVersion'] = '';
914 if (isset($localList[$value['extkey']])) {
915 $isUpdatable = ($localList[$value['extkey']]['intversion'] < $value['maxintversion']);
916 $list['results'][$key]['exists'] = 1;
917 $list['results'][$key]['installed'] = $localList[$value['extkey']]['installed'];
918 $list['results'][$key]['versionislower'] = $isUpdatable;
919 $list['results'][$key]['existingVersion'] = $localList[$value['extkey']]['version'];
921 $updateKeys[] = $key;
926 if ($installedOnly == 2) {
928 if (count($updateKeys)) {
929 foreach ($updateKeys as $key) {
930 $temp[]= $list['results'][$key];
933 $list['results'] = $temp;
934 $list['count'] -= count($updateKeys);
938 'length' => $list['count'],
939 'data' => $list['results'],
950 public function getRepositories() {
951 $settings = $this->getSettings();
952 $repositories = tx_em_Database
::getRepositories();
955 foreach ($repositories as $uid => $repository) {
957 'title' => $repository['title'],
958 'uid' => $repository['uid'],
959 'description' => $repository['description'],
960 'wsdl_url' => $repository['wsdl_url'],
961 'mirror_url' => $repository['mirror_url'],
962 'count' => $repository['extCount'],
963 'updated' => $repository['lastUpdated'] ?
date('d/m/Y H:i', $repository['lastUpdated']) : 'never',
964 'selected' => $repository['uid'] === $settings['selectedRepository'],
969 'length' => count($data),
976 * Get Mirrors for selected repository
978 * @param object $parameter
981 public function getMirrors($parameter) {
983 /** @var $objRepository tx_em_Repository */
984 $objRepository = t3lib_div
::makeInstance('tx_em_Repository', $parameter->repository
);
986 if ($objRepository->getMirrorListUrl()) {
987 $objRepositoryUtility = t3lib_div
::makeInstance('tx_em_Repository_Utility', $objRepository);
988 $mirrors = $objRepositoryUtility->getMirrors(TRUE)->getMirrors();
991 if (count($mirrors)) {
994 'title' => $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:mirror_use_random'),
1003 foreach ($mirrors as $mirror) {
1005 'title' => $mirror['title'],
1006 'country' => $mirror['country'],
1007 'host' => $mirror['host'],
1008 'path' => $mirror['path'],
1009 'sponsor' => $mirror['sponsorname'],
1010 'link' => $mirror['sponsorlink'],
1011 'logo' => $mirror['sponsorlogo'],
1018 'length' => count($data),
1025 * Edit / Create repository
1028 * @param array $parameter
1031 public function repositoryEditFormSubmit($parameter) {
1032 $repId = intval($parameter['rep']);
1034 /** @var $repository tx_em_Repository */
1035 $repository = t3lib_div
::makeInstance('tx_em_Repository', $repId);
1036 $repository->setTitle($parameter['title']);
1037 $repository->setDescription($parameter['description']);
1038 $repository->setWsdlUrl($parameter['wsdl_url']);
1039 $repository->setMirrorListUrl($parameter['mirror_url']);
1040 $repositoryData = array(
1041 'title' => $repository->getTitle(),
1042 'description' => $repository->getDescription(),
1043 'wsdl_url' => $repository->getWsdlUrl(),
1044 'mirror_url' => $repository->getMirrorListUrl(),
1045 'lastUpdated' => $repository->getLastUpdate(),
1046 'extCount' => $repository->getExtensionCount(),
1050 // create a new repository
1051 $id = tx_em_Database
::insertRepository($repository);
1055 'params' => $repositoryData
1059 tx_em_Database
::updateRepository($repository);
1062 'params' => $repositoryData
1074 public function deleteRepository($uid) {
1075 if (intval($uid) < 2) {
1078 'error' => $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:repository_main_nodelete')
1081 $repository = t3lib_div
::makeInstance('tx_em_Repository', intval($uid));
1082 tx_em_Database
::deleteRepository($repository);
1085 'uid' => intval($uid)
1091 * @param array $parameter
1094 public function repositoryUpdate($repositoryId) {
1096 if (!intval($repositoryId)) {
1099 'errors' => 'no repository choosen',
1104 /** @var $objRepository tx_em_Repository */
1105 $objRepository = t3lib_div
::makeInstance('tx_em_Repository', intval($repositoryId));
1106 /** @var $objRepositoryUtility tx_em_Repository_Utility */
1107 $objRepositoryUtility = t3lib_div
::makeInstance('tx_em_Repository_Utility', $objRepository);
1108 $count = $objRepositoryUtility->updateExtList();
1109 $time = $GLOBALS['EXEC_TIME'];
1112 $objRepository->setExtensionCount($count);
1113 $objRepository->setLastUpdate($time);
1114 tx_em_Database
::updateRepository($objRepository);
1119 'updated' => date('d/m/Y H:i', $time)
1121 'rep' => intval($repositoryId)
1126 'errormsg' => $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:repository_upToDate'),
1127 'rep' => intval($repositoryId)
1133 /*********************************************************************/
1134 /* Translation Handling */
1135 /*********************************************************************/
1139 * Gets the system languages
1143 public function getLanguages() {
1144 $this->globalSettings
= unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['em']);
1145 $selected = t3lib_div
::trimExplode(',', $this->globalSettings
['selectedLanguages'], TRUE);
1147 /** @var $locales t3lib_l10n_Locales */
1148 $locales = t3lib_div
::makeInstance('t3lib_l10n_Locales');
1149 $theLanguages = $locales->getLanguages();
1151 array_shift($theLanguages);
1152 $lang = $meta = array();
1153 foreach ($theLanguages as $language => $name) {
1154 $label = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:setup/mod/locallang.xml:lang_' . $language));
1155 if ($label === '') {
1156 $label = htmlspecialchars($name);
1160 'lang' => $language,
1161 'selected' => is_array($selected) && in_array($language, $selected) ?
1 : 0
1164 'hidden' => is_array($selected) && in_array($language, $selected) ?
'false' : 'true',
1165 'header' => $language,
1166 'dataIndex' => $language,
1169 'sortable' => FALSE,
1171 'menuDisabled' => TRUE,
1175 'length' => count($lang),
1183 * Saves language selection
1185 * @param array $parameter
1188 public function saveLanguageSelection($parameter) {
1189 // Add possible dependencies for selected languages
1190 /** @var $locales t3lib_l10n_Locales */
1191 $locales = t3lib_div
::makeInstance('t3lib_l10n_Locales');
1192 $dependencies = array();
1193 foreach ($parameter as $language) {
1194 $dependencies = array_merge($dependencies, $locales->getLocaleDependencies($language));
1196 if (count($dependencies) > 0) {
1197 $parameter = array_unique(array_merge($parameter, $dependencies));
1200 $this->globalSettings
= unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['em']);
1201 $selected = t3lib_div
::trimExplode(',', $this->globalSettings
['selectedLanguages'], TRUE);
1203 $dir = count($parameter) - count($selected);
1204 $diff = $dir < 0 ?
array_diff($selected, $parameter) : array_diff($parameter, $selected);
1205 $type = tx_em_Tools
::getExtTypeFromPath(t3lib_extMgm
::extPath('em'));
1211 'selectedLanguages' => implode(',', $parameter)
1214 $this->saveExtensionConfiguration($params);
1217 'success' => count($diff) > 0,
1219 'diff' => array_values($diff),
1220 'languages' => $parameter
1226 * Fetches translation from server
1228 * @param string $extkey
1229 * @param string $type
1230 * @param array $selection
1233 public function fetchTranslations($extkey, $type, $selection) {
1235 if (is_array($selection) && count($selection)) {
1236 /** @var $terConnection tx_em_Connection_Ter */
1237 $terConnection = t3lib_div
::makeInstance('tx_em_Connection_Ter', $this);
1238 /** @var $xmlHandler tx_em_Tools_XmlHandler */
1239 $this->xmlHandler
= t3lib_div
::makeInstance('tx_em_Tools_XmlHandler');
1240 $this->xmlHandler
->emObj
= $this;
1241 $mirrorURL = $this->getSettingsObject()->getMirrorURL();
1243 $infoIcon = '<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-info"> </span>';
1244 $updateIcon = '<span class="t3-icon t3-icon-actions t3-icon-actions-system t3-icon-system-extension-update"> </span>';
1245 $newIcon = '<span class="t3-icon t3-icon-actions t3-icon-actions-system t3-icon-system-extension-import"> </span>';
1246 $okIcon = '<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-checked"> </span>';
1247 $errorIcon = '<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-permission-denied"> </span>';
1249 foreach ($selection as $lang) {
1250 $fetch = $terConnection->fetchTranslationStatus($extkey, $mirrorURL);
1253 if (!isset($fetch[$lang])) {
1254 //no translation available
1255 $result[$lang] = $infoIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:translation_n_a');
1257 $zip = PATH_site
. 'typo3temp/' . $extkey . '-l10n-' . $lang . '.zip';
1258 if (is_file($zip)) {
1259 $localmd5 = md5_file($zip);
1261 if ($localmd5 !== $fetch[$lang]['md5']) {
1264 $ret = $terConnection->updateTranslation($extkey, $lang, $mirrorURL);
1266 $result[$lang] = $ret
1267 ?
$okIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_updated')
1268 : $errorIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_failed');
1270 //translation status
1271 $result[$lang] = $localmd5 !== ''
1272 ?
$updateIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:translation_status_update')
1273 : $newIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:translation_status_new');
1276 //translation is up to date
1277 $result[$lang] = $okIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:translation_status_uptodate');
1288 /*********************************************************************/
1290 /*********************************************************************/
1293 * Returns settings object.
1296 * @return tx_em_Settings instance of settings object
1298 public function getSettings() {
1299 return $this->getSettingsObject()->getSettings();
1303 * Enter description here...
1305 * @param string $name
1306 * @param mixed $value
1309 public function saveSetting($name, $value) {
1310 $this->getSettingsObject()->saveSetting($name, $value);
1315 * Load form values for settings form
1317 * @return array FormValues
1319 public function settingsFormLoad() {
1320 $settings = $this->getSettings();
1325 'display_unchecked' => $settings['display_unchecked'],
1326 'fe_u' => $settings['fe_u'],
1327 'fe_p' => $settings['fe_p'],
1328 'selectedMirror' => $settings['selectedMirror'],
1329 'selectedRepository' => $settings['selectedRepository'],
1335 * Save settings from form submit
1338 * @param array $parameter
1341 public function settingsFormSubmit($parameter) {
1342 $settings = $this->getSettingsObject()->saveSettings(array(
1343 'display_unchecked' => isset($parameter['display_unchecked']),
1344 'fe_u' => $parameter['fe_u'],
1345 'fe_p' => $parameter['fe_p'],
1346 'selectedMirror' => $parameter['selectedMirror'],
1347 'selectedRepository' => $parameter['selectedRepository'],
1351 'data' => $parameter,
1352 'settings' => $settings
1357 /*********************************************************************/
1359 /*********************************************************************/
1362 * Upload an extension
1367 * @param $parameter composed parameter from $POST and $_FILES
1368 * @return array status
1370 public function uploadExtension($parameter) {
1371 $uploadedTempFile = isset($parameter['extfile']) ?
$parameter['extfile'] : t3lib_div
::upload_to_tempfile($parameter['extupload-path']['tmp_name']);
1372 $location = ($parameter['loc'] === 'G' ||
$parameter['loc'] === 'S') ?
$parameter['loc'] : 'L';
1373 $uploadOverwrite = $parameter['uploadOverwrite'] ?
TRUE : FALSE;
1375 $install = t3lib_div
::makeInstance('tx_em_Install', $this);
1376 $this->extensionList
= t3lib_div
::makeInstance('tx_em_Extensions_List', $this);
1377 $this->extensionDetails
= t3lib_div
::makeInstance('tx_em_Extensions_Details', $this);
1379 $upload = $install->uploadExtensionFile($uploadedTempFile, $location, $uploadOverwrite);
1381 if ($upload[0] === FALSE) {
1384 'error' => $upload[1]
1388 $extKey = $upload[1][0]['extKey'];
1391 $result = $install->installExtension($upload[1], $location, $version, $uploadedTempFile, $dontDelete);
1401 * Enables an extension
1403 * @param $extensionKey
1406 public function enableExtension($extensionKey) {
1407 $this->extensionList
= t3lib_div
::makeInstance('tx_em_Extensions_List', $this);
1408 $install = t3lib_div
::makeInstance('tx_em_Install', $this);
1410 list($installedList,) = $this->extensionList
->getInstalledExtensions();
1411 $newExtensionList = $this->extensionList
->addExtToList($extensionKey, $installedList);
1413 $install->writeNewExtensionList($newExtensionList);
1414 tx_em_Tools
::refreshGlobalExtList();
1415 $install->forceDBupdates($extensionKey, $installedList[$extensionKey]);
1419 * Reset all states for current user
1423 public function resetStates() {
1424 unset($GLOBALS['BE_USER']->uc
['moduleData']['tools_em']['States']);
1425 $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc
);
1426 return array('success' => TRUE);
1430 * Gets the mirror url from selected mirror
1432 * @param $repositoryId
1435 protected function getMirrorUrl($repositoryId) {
1436 $settings = $this->getSettings();
1437 /** @var $objRepository tx_em_Repository */
1438 $objRepository = t3lib_div
::makeInstance('tx_em_Repository', $repositoryId);
1439 /** @var $objRepositoryUtility tx_em_Repository_Utility */
1440 $objRepositoryUtility = t3lib_div
::makeInstance('tx_em_Repository_Utility', $objRepository);
1441 $mirrors = $objRepositoryUtility->getMirrors(TRUE)->getMirrors();
1444 if ($settings['selectedMirror'] == '') {
1445 $randomMirror = array_rand($mirrors);
1446 $mirrorUrl = $mirrors[$randomMirror]['host'] . $mirrors[$randomMirror]['path'];
1448 foreach($mirrors as $mirror) {
1449 if ($mirror['host'] == $settings['selectedMirror']) {
1450 $mirrorUrl = $mirror['host'] . $mirror['path'];
1456 return 'http://' . $mirrorUrl;
1460 * Resolves the filter settings from repository list and makes a whereClause
1462 * @param array $parameter
1463 * @return string additional whereClause
1465 protected function makeFilterQuery($parameter) {
1467 $filter = $found = array();
1469 foreach ($parameter as $key => $value) {
1470 if (substr($key, 0, 6) === 'filter') {
1471 eval('$' . $key . ' = \'' . $value . '\';');
1476 if (count($filter)) {
1477 foreach ($filter as $value) {
1478 switch ($value['data']['type']) {
1480 if ($value['field'] === 'statevalue') {
1481 $where .= ' AND cache_extensions.state IN(' . htmlspecialchars($value['data']['value']) . ')';
1483 if ($value['field'] === 'category') {
1484 $where .= ' AND cache_extensions.category IN(' . htmlspecialchars($value['data']['value']) . ')';
1488 $quotedSearch = $GLOBALS['TYPO3_DB']->escapeStrForLike(
1489 $GLOBALS['TYPO3_DB']->quoteStr($value['data']['value'], 'cache_extensions'),
1492 $where .= ' AND cache_extensions.' . htmlspecialchars($value['field']) . ' LIKE "%' . $quotedSearch . '%"';
1500 * Replace links that are created with t3lib_div::linkThisScript to point to module
1502 * @param string $string
1505 protected function replaceLinks($string) {
1507 'ajax.php?ajaxID=ExtDirect%3A%3Aroute&namespace=TYPO3.EM',
1508 'mod.php?M=tools_em',
1514 * Get the selected repository
1518 protected function getSelectedRepository() {
1519 $settings = $this->getSettings();
1520 $repositories = tx_em_Database
::getRepositories();
1521 $selectedRepository = array();
1523 foreach ($repositories as $uid => $repository) {
1524 if ($repository['uid'] == $settings['selectedRepository']) {
1525 $selectedRepository = array(
1526 'title' => $repository['title'],
1527 'uid' => $repository['uid'],
1528 'description' => $repository['description'],
1529 'wsdl_url' => $repository['wsdl_url'],
1530 'mirror_url' => $repository['mirror_url'],
1531 'count' => $repository['extCount'],
1532 'updated' => $repository['lastUpdated'] ?
date('d/m/Y H:i', $repository['lastUpdated']) : 'never',
1533 'selected' => $repository['uid'] === $settings['selectedRepository'],
1538 return $selectedRepository;
1542 * Gets file info for ExtJs tree node
1547 protected function getFileInfo($file) {
1548 $unknownType = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_file_unknownType');
1549 $imageType = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_file_imageType');
1550 $textType = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_file_textType');
1551 $extType = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_file_extType');
1553 $editTypes = explode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext']);
1554 $imageTypes = array('gif', 'jpg', 'png');
1558 $cls = t3lib_iconWorks
::mapFileExtensionToSpriteIconClass('');
1559 if (strrpos($file, '.') !== FALSE) {
1560 $fileExt = strtolower(substr($file, strrpos($file, '.') +
1));
1563 if ($fileExt && in_array($fileExt, $imageTypes) ||
in_array($fileExt, $editTypes)) {
1564 $cls = t3lib_iconWorks
::mapFileExtensionToSpriteIconClass($fileExt);
1565 $type = in_array($fileExt, $imageTypes) ?
'image' : 'text';
1568 if (t3lib_div
::strtolower($file) === 'changelog') {
1569 $cls = t3lib_iconWorks
::mapFileExtensionToSpriteIconClass('txt');
1575 $label = $imageType;
1581 $label = $fileExt ?
sprintf($extType, $fileExt) : $unknownType;
1585 htmlspecialchars($file),
1587 htmlspecialchars($fileExt),
1596 * File operations like delete, copy, move
1597 * @param $file commandMap, @see
1600 protected function fileOperation($file) {
1601 $mount = array(0 => array(
1603 'path' => PATH_site
,
1606 $files = array(0 => array(
1607 'webspace' => array('allow' => '*', 'deny' => ''),
1608 'ftpspace' => array('allow' => '*', 'deny' => '')
1610 $fileProcessor = t3lib_div
::makeInstance('t3lib_extFileFunctions');
1611 $fileProcessor->init($mount, $files);
1612 $fileProcessor->init_actionPerms($GLOBALS['BE_USER']->getFileoperationPermissions());
1613 $fileProcessor->dontCheckForUnique
= 0;
1615 // Checking referer / executing:
1616 $refInfo = parse_url(t3lib_div
::getIndpEnv('HTTP_REFERER'));
1617 $httpHost = t3lib_div
::getIndpEnv('TYPO3_HOST_ONLY');
1618 if ($httpHost != $refInfo['host']
1619 && $this->vC
!= $GLOBALS['BE_USER']->veriCode()
1620 && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']
1621 && $GLOBALS['CLIENT']['BROWSER'] != 'flash') {
1622 $fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost));
1624 $fileProcessor->start($file);
1625 $fileData = $fileProcessor->processData();
1633 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['typo3/sysext/em/classes/connection/class.tx_em_connectionextdirectserver.php'])) {
1634 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['typo3/sysext/em/classes/connection/class.tx_em_connection_extdirectserver.php']);