[TASK] EM: show updatable extensions in Local Extension List
[Packages/TYPO3.CMS.git] / typo3 / sysext / em / classes / connection / class.tx_em_connection_extdirectserver.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Steffen Kamper (info@sk-typo3.de)
6 * All rights reserved
7 *
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.
13 *
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.
18 *
19 *
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.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Module: Extension manager, developer module
29 *
30 * This class handles all Ajax calls coming from ExtJS
31 *
32 * @author Steffen Kamper <info@sk-typo3.de>
33 */
34
35
36 class tx_em_Connection_ExtDirectServer {
37 /**
38 * @var tx_em_Tools_XmlHandler
39 */
40 var $xmlHandler;
41
42 /**
43 * Class for printing extension lists
44 *
45 * @var tx_em_Extensions_List
46 */
47 public $extensionList;
48
49 /**
50 * Class for extension details
51 *
52 * @var tx_em_Extensions_Details
53 */
54 public $extensionDetails;
55
56 /**
57 * Keeps instance of settings class.
58 *
59 * @var tx_em_Settings
60 */
61 static protected $objSettings;
62
63 protected $globalSettings;
64
65 /*********************************************************************/
66 /* General */
67 /*********************************************************************/
68
69 /**
70 * Constructor
71 *
72 * @param boolean $createTemplateInstance: set to FALSE if no instance of template class needs to be created
73 * @return void
74 */
75 public function __construct($createTemplateInstance = TRUE) {
76 if ($createTemplateInstance) {
77 $this->template = t3lib_div::makeInstance('template');
78 }
79 $this->globalSettings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['em']);
80 }
81
82
83 /**
84 * Method returns instance of settings class.
85 *
86 * @access protected
87 * @return em_settings instance of settings class
88 */
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');
92 }
93 return self::$objSettings;
94 }
95
96
97 /*********************************************************************/
98 /* Local Extension List */
99 /*********************************************************************/
100
101
102 /**
103 * Render local extension list
104 *
105 * @param object $parameters
106 * @return array
107 */
108 public function getExtensionList($parameters) {
109 $repositoryId = $parameters->repository;
110
111 /** @var $list tx_em_Extensions_List */
112 $list = t3lib_div::makeInstance('tx_em_Extensions_List');
113 $extList = $list->getInstalledExtensions(TRUE);
114
115 $temp = array();
116 $localList = array();
117 foreach ($extList as $entry) {
118 $temp[] = '"' . $entry['extkey'] . '"';
119 $entry['intversion'] = t3lib_utility_VersionNumber::convertVersionNumberToInteger($entry['version']);
120 $localList[$entry['extkey']] = $entry;
121 }
122
123 $where = ' AND cache_extensions.extkey IN (' . implode(',', $temp) . ')';
124 $additionalData = tx_em_Database::getExtensionListFromRepository(
125 $repositoryId,
126 '',
127 $where
128 );
129
130 foreach ($additionalData['results'] as $key => $value) {
131 $isUpdatable = ($localList[$value['extkey']]['intversion'] < $value['maxintversion']);
132 $localList[$value['extkey']]['versionislower'] = $isUpdatable;
133 $localList[$value['extkey']]['maxversion'] = tx_em_Tools::versionFromInt($value['maxintversion']);
134 }
135
136 return array(
137 'length' => count($localList),
138 'data' => array_values($localList)
139 );
140 }
141
142 /**
143 * Returns the list of extensions with additional data
144 *
145 * @return array
146 */
147 public function getFlatExtensionList() {
148 /** @var $list tx_em_Extensions_List */
149 $list = t3lib_div::makeInstance('tx_em_Extensions_List');
150 $extList = $list->getInstalledExtensions(TRUE);
151
152 $flatList = array();
153 foreach ($extList as $entry) {
154 $flatList[$entry['extkey']] = array(
155 'version' => $entry['version'],
156 'intversion' => t3lib_utility_VersionNumber::convertVersionNumberToInteger($entry['version']),
157 'installed' => $entry['installed'],
158 'typeShort' => $entry['typeShort'],
159 );
160 }
161 return array(
162 'length' => count($flatList),
163 'data' => $flatList
164 );
165 }
166
167 /**
168 * Render extensionlist for languages
169 *
170 * @param object $parameters
171 * @return array
172 */
173 public function getInstalledExtkeys($parameters) {
174 $list = $this->getExtensionList($parameters);
175 $extList = $list['data'];
176
177 $selectedLanguages = t3lib_div::trimExplode(',', $this->globalSettings['selectedLanguages']);
178
179 $keys = array();
180 $i = 0;
181 foreach ($extList as $ext) {
182 if ($ext['installed']) {
183 $keys[$i] = array(
184 'extkey' => $ext['extkey'],
185 'icon' => $ext['icon'],
186 'stype' => $ext['typeShort'],
187 );
188 $keys[$i]['lang'] = array();
189 if (count($selectedLanguages)) {
190 foreach ($selectedLanguages as $language) {
191 $keys[$i]['lang'][] = $GLOBALS['LANG']->sL('LLL:EXT:setup/mod/locallang.xml:lang_' . $language);
192 }
193 }
194 $i++;
195 }
196 }
197
198 return array(
199 'length' => count($keys),
200 'data' => $keys,
201 );
202 }
203
204 /**
205 * Render module content
206 *
207 * @return string $content
208 */
209 public function getExtensionDetails() {
210 /** @var $list tx_em_Extensions_List */
211 $list = t3lib_div::makeInstance('tx_em_Extensions_List');
212 $extList = $list->getInstalledExtensions(TRUE);
213
214
215 return array(
216 'length' => count($extList),
217 'data' => $extList
218 );
219
220 }
221
222 /**
223 * Render extension update
224 *
225 * @var string $extKey
226 * @return string $content
227 */
228 public function getExtensionUpdate($extKey) {
229 if (isset($GLOBALS['TYPO3_LOADED_EXT'][$extKey])) {
230 /** @var $install tx_em_Install */
231 $install = t3lib_div::makeInstance('tx_em_Install');
232 /** @var $extension tx_em_Extensions_List */
233 $extension = t3lib_div::makeInstance('tx_em_Extensions_List');
234
235
236 $extPath = t3lib_extMgm::extPath($extKey);
237 $type = tx_em_Tools::getExtTypeFromPath($extPath);
238 $typePath = tx_em_Tools::typePath($type);
239 $extInfo = array();
240
241 $extension->singleExtInfo($extKey, $typePath, $extInfo);
242 $extInfo = $extInfo[0];
243 $extInfo['type'] = $extInfo['typeShort'];
244 $update = $install->checkDBupdates($extKey, $extInfo);
245 if ($update) {
246 $update = $GLOBALS['LANG']->getLL('ext_details_new_tables_fields_select') .
247 $update .
248 '<br /><input type="submit" name="write" id="update-submit-' . htmlspecialchars($extKey) . '" value="' .
249 htmlspecialchars($GLOBALS['LANG']->getLL('updatesForm_make_updates')) . '" />';
250 }
251 return $update ? $update : $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_dbUpToDate');
252 } else {
253 return sprintf($GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_extNotInstalled') ,htmlspecialchars($extKey));
254 }
255 }
256
257
258 /**
259 * Render extension configuration
260 *
261 * @var string $extKey
262 * @return string $content
263 */
264 public function getExtensionConfiguration($extKey) {
265 /** @var $extensionList tx_em_Extensions_List */
266 $extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this);
267 list($list,) = $extensionList->getInstalledExtensions();
268 /** @var $install tx_em_Install */
269 $install = t3lib_div::makeInstance('tx_em_Install');
270 $install->setSilentMode(TRUE);
271
272 $form = $install->updatesForm($extKey, $list[$extKey], 1, '', '', FALSE, TRUE);
273 if (!$form) {
274 return '<p>' . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_extNoConfiguration') . '</p>';
275 } else {
276 //$form = preg_replace('/<form([^>]+)>/', '', $form);
277 //$form = str_replace('</form>', '', $form);
278 return $form;
279 }
280 }
281
282 /**
283 * Save extension configuration
284 *
285 * @formHandler
286 * @param array $parameter
287 * @return array
288 */
289 public function saveExtensionConfiguration($parameter) {
290
291 $extKey = $parameter['extkey'];
292 $extType = $parameter['exttype'];
293 $noSave = $parameter['noSave'];
294
295 $absPath = tx_em_Tools::getExtPath($extKey, $extType);
296 $relPath = tx_em_Tools::typeRelPath($extType) . $extKey . '/';
297
298 /** @var $extensionList tx_em_Extensions_List */
299 $extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this);
300 list($list,) = $extensionList->getInstalledExtensions();
301
302
303 $arr = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extKey]);
304 $arr = is_array($arr) ? $arr : array();
305
306 /** @var $tsStyleConfig t3lib_tsStyleConfig */
307 $tsStyleConfig = t3lib_div::makeInstance('t3lib_tsStyleConfig');
308 $tsStyleConfig->doNotSortCategoriesBeforeMakingForm = TRUE;
309 $theConstants = $tsStyleConfig->ext_initTSstyleConfig(
310 t3lib_div::getUrl($absPath . 'ext_conf_template.txt'),
311 $relPath,
312 $absPath,
313 $GLOBALS['BACK_PATH']
314 );
315
316 $tsStyleConfig->ext_procesInput($parameter, array(), $theConstants, array());
317 $arr = $tsStyleConfig->ext_mergeIncomingWithExisting($arr);
318
319
320 /** @var $install tx_em_Install */
321 $install = t3lib_div::makeInstance('tx_em_Install');
322 $install->setSilentMode(TRUE);
323 $install->install->INSTALL = $parameter['TYPO3_INSTALL'];
324 $install->checkDBupdates($extKey, $list[$extKey]);
325
326 $html = '';
327 if ($noSave) {
328 $html = $install->updatesForm($extKey, $list[$extKey], 1);
329 } else {
330 $install->writeTsStyleConfig($extKey, $arr);
331 }
332
333 return array(
334 'success' => TRUE,
335 'data' => $parameter['data'],
336 'html' => $html,
337 );
338 }
339
340 /**
341 * Cleans EMConf of extension
342 *
343 * @param string $extKey
344 * @return array
345 */
346 public function cleanEmConf($extKey) {
347
348 /** @var $extensionList tx_em_Extensions_List */
349 $extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this);
350 list($list,) = $extensionList->getInstalledExtensions();
351 /** @var $extensionDetails tx_em_Extensions_Details */
352 $this->extensionDetails = t3lib_div::makeInstance('tx_em_Extensions_Details', $this);
353
354 $result = $this->extensionDetails->updateLocalEM_CONF($extKey, $list[$extKey]);
355
356 return array(
357 'success' => TRUE,
358 'extkey' => $extKey,
359 'result' => $result
360 );
361 }
362
363 /**
364 * Delete extension
365 *
366 * @param $extKey
367 * @return array
368 */
369 public function deleteExtension($extKey) {
370
371 /** @var $extensionList tx_em_Extensions_List */
372 $extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this);
373 list($list,) = $extensionList->getInstalledExtensions();
374 $type = $list[$extKey]['type'];
375 $absPath = tx_em_Tools::getExtPath($extKey, $type);
376
377 /** @var $extensionDetails tx_em_Install */
378 $install = t3lib_div::makeInstance('tx_em_Install');
379 $install->setSilentMode(TRUE);
380
381 $res = $install->removeExtDirectory($absPath);
382 $error = '';
383 $success = TRUE;
384
385 if ($res) {
386 $res = nl2br($res);
387 $error = sprintf($GLOBALS['LANG']->getLL('extDelete_remove_dir_failed'), $absPath);
388 $success = FALSE;
389 }
390 return array(
391 'success' => $success,
392 'extkey' => $extKey,
393 'result' => $res,
394 'error' => $error
395 );
396 }
397
398 /**
399 * genereates a file tree
400 *
401 * @param object $parameter
402 * @return array
403 */
404 public function getExtFileTree($parameter) {
405 $type = $parameter->typeShort;
406 $node = substr($parameter->node, 0, 6) !== 'xnode-' ? $parameter->node : $parameter->baseNode;
407
408 $path = PATH_site . $node;
409 $fileArray = array();
410
411 $dirs = t3lib_div::get_dirs($path);
412 $files = t3lib_div::getFilesInDir($path, '', FALSE, '', '');
413
414
415
416 if (!is_array($dirs) && !is_array($files)) {
417 return array();
418 }
419
420 foreach ($dirs as $dir) {
421 if ($dir{0} !== '.') {
422 $fileArray[] = array(
423 'id' => ($node == '' ? '' : $node . '/') . $dir,
424 'text' => htmlspecialchars($dir),
425 'leaf' => FALSE,
426 'qtip' => ''
427 );
428 }
429 }
430
431
432 foreach ($files as $key => $file) {
433 $fileInfo = $this->getFileInfo($file);
434
435 $fileArray[] = array(
436 'id' => $node . '/' . $file,
437 'text' => $fileInfo[0],
438 'leaf' => TRUE,
439 'qtip' => $fileInfo[1],
440 'iconCls' => $fileInfo[4],
441 'fileType' => $fileInfo[3],
442 'ext' => $fileInfo[2]
443 );
444 }
445
446 return $fileArray;
447 }
448
449
450 /**
451 * Read extension file and send content
452 *
453 * @param string $path
454 * @return string file content
455 */
456 public function readExtFile($path) {
457 $path = PATH_site . $path;
458 if (@file_exists($path)) {
459 return t3lib_div::getUrl($path);
460 }
461 return '';
462 }
463
464 /**
465 * Save extension file
466 *
467 * @param string $file
468 * @param string $content
469 * @return boolean success
470 */
471 public function saveExtFile($file, $content) {
472 $path = PATH_site . $file;
473 $error = '';
474 $fileSaveAllowed = $GLOBALS['TYPO3_CONF_VARS']['EXT']['noEdit'] == 0;
475 $fileExists = @file_exists($path);
476 $fileSaveable = is_writable($path);
477
478 if ($fileExists && $fileSaveable && $fileSaveAllowed) {
479 $success = t3lib_div::writeFile($path, $content);
480 } else {
481 $success = FALSE;
482 $error = $fileSaveAllowed
483 ? ($fileSaveable
484 ? $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_fileNotExists', TRUE)
485 : $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_fileWriteProtected', TRUE)
486 )
487 : $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_saving_disabled', TRUE);
488 }
489
490 if ($success) {
491 $GLOBALS['BE_USER']->writelog(9, 0, 0, 0, sprintf('File "%s" has been modified', $file));
492 }
493 return array(
494 'success' => $success,
495 'path' => $path,
496 'file' => basename($path),
497 'content' => $content,
498 'error' => $error
499 );
500 }
501
502 /**
503 * Create a new file
504 *
505 * @param string $folder
506 * @param string $file
507 * @param boolean $isFolder
508 * @return array result
509 */
510 public function createNewFile($folder, $file, $isFolder) {
511 $result = tx_em_Tools::createNewFile($folder, $file, $isFolder);
512
513 $node = array();
514
515 if ($result[0] === TRUE) {
516 if ($isFolder) {
517 $node = array(
518 'id' => htmlspecialchars(substr($result[1], strlen(PATH_site))),
519 'text' => htmlspecialchars(basename($result[1])),
520 'leaf' => FALSE,
521 'qtip' => ''
522 );
523 } else {
524 $fileInfo = $this->getFileInfo($result[1]);
525 $node = array(
526 'id' => substr($fileInfo[0], strlen(PATH_site)),
527 'text' => basename($fileInfo[0]),
528 'leaf' => !$isFolder,
529 'qtip' => $fileInfo[1],
530 'iconCls' => $fileInfo[4],
531 'fileType' => $fileInfo[3],
532 'ext' => $fileInfo[2]
533 );
534 }
535 }
536 return array(
537 'success' => $result[0],
538 'created' => $result[1],
539 'node' => $node,
540 'error' => $result[2]
541 );
542 }
543
544 /**
545 * Rename a file/folder
546 *
547 * @param string $file
548 * @param string $newName
549 * @param boolean $isFolder
550 * @return array result
551 */
552 public function renameFile($file, $newName, $isFolder) {
553 $src = basename($file);
554 $newFile = substr($file, 0, -1 * strlen($src)) . $newName;
555
556 $success = tx_em_Tools::renameFile($file, $newFile);
557
558 return array(
559 'success' => $success,
560 'oldFile' => $file,
561 'newFile' => $newFile,
562 'newFilename' => basename($newFile),
563 );
564 }
565
566
567 /**
568 * Moves a file to new destination
569 *
570 * @param string $file
571 * @param string $destination
572 * @param boolean $isFolder
573 * @return array
574 */
575 public function moveFile($file, $destination, $isFolder) {
576 return array(
577 'success' => TRUE,
578 'file' => $file,
579 'destination' => $destination,
580 'isFolder' => $isFolder
581 );
582 }
583
584 /**
585 * Deletes a file/folder
586 *
587 * @param string $file
588 * @param boolean $isFolder
589 * @return array
590 */
591 public function deleteFile($file, $isFolder) {
592
593 $file = str_replace('//', '/', PATH_site . $file);
594 $command['delete'][] = array(
595 'data' => $file
596 );
597 $result = $this->fileOperation($command);
598
599 return array(
600 'success' => TRUE,
601 'file' => $file,
602 'isFolder' => $isFolder,
603 'command' => $command,
604 'result' => $result
605 );
606 }
607
608 /**
609 * Shows a diff of content changes of a file
610 *
611 * @param string $file
612 * @param string $content
613 * @return array
614 */
615 public function makeDiff($original, $content) {
616 $diff = t3lib_div::makeInstance('t3lib_diff');
617 $result = $diff->makeDiffDisplay($original, $content);
618 //debug(array($original, $content, $result));
619 return array(
620 'success' => TRUE,
621 'diff' => '<pre>' . $result . '</pre>'
622 );
623 }
624
625 /**
626 * Load upload form for extension upload to TER
627 *
628 * @formcHandler
629 * @return array
630 */
631 public function loadUploadExtToTer() {
632 $settings = $this->getSettings();
633 return array(
634 'success' => TRUE,
635 'data' => array(
636 'fe_u' => $settings['fe_u'],
637 'fe_p' => $settings['fe_p']
638 )
639 );
640 }
641
642 /**
643 * Upload extension to TER
644 *
645 * @formHandler
646 *
647 * @param string $parameter
648 * @return array
649 */
650 public function uploadExtToTer($parameter) {
651 $repository = $this->getSelectedRepository();
652 $wsdlURL = $repository['wsdl_url'];
653
654 $parameter['user']['fe_u'] = $parameter['fe_u'];
655 $parameter['user']['fe_p'] = $parameter['fe_p'];
656 $parameter['upload']['mode'] = $parameter['newversion'];
657 $parameter['upload']['comment'] = $parameter['uploadcomment'];
658
659 /** @var $extensionList tx_em_Extensions_List */
660 $extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this);
661 list($list,) = $extensionList->getInstalledExtensions();
662 /** @var $extensionDetails tx_em_Extensions_Details */
663 $this->extensionDetails = t3lib_div::makeInstance('tx_em_Extensions_Details', $this);
664
665 /** @var $terConnection tx_em_Connection_Ter*/
666 $terConnection = t3lib_div::makeInstance('tx_em_Connection_Ter', $this);
667 $terConnection->wsdlURL = $wsdlURL;
668
669 $parameter['extInfo'] = $list[$parameter['extKey']];
670 $response = $terConnection->uploadToTER($parameter);
671
672 if (!is_array($response)) {
673 return array(
674 'success' => FALSE,
675 'error' => $response,
676 'params' => $parameter,
677 );
678 }
679 if ($response['resultCode'] == 10504) { //success
680 $parameter['extInfo']['EM_CONF']['version'] = $response['version'];
681 $response['resultMessages'][] = sprintf(
682 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:terCommunication_ext_version'),
683 $response['version']
684 );
685 $response['resultMessages'][] = $this->extensionDetails->updateLocalEM_CONF($parameter['extKey'], $parameter['extInfo']);
686 }
687
688 return array(
689 'success' => TRUE,
690 'params' => $parameter,
691 'response' => $response
692 );
693 }
694
695 /**
696 * Prints developer information
697 *
698 * @param string $parameter
699 * @return string
700 */
701 public function getExtensionDevelopInfo($extKey) {
702 /** @var $extensionList tx_em_Extensions_List*/
703 $extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this);
704 list($list,) = $extensionList->getInstalledExtensions();
705 /** @var $extensionDetails tx_em_Extensions_Details */
706 $extensionDetails = t3lib_div::makeInstance('tx_em_Extensions_Details', $this);
707
708 return $extensionDetails->extInformationarray($extKey, $list[$extKey]);
709 }
710
711
712 /**
713 * Prints backupdelete
714 *
715 * @param string $parameter
716 * @return string
717 */
718 public function getExtensionBackupDelete($extKey) {
719 $content='';
720 /** @var $extensionList tx_em_Extensions_List*/
721 $extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this);
722 /** @var $extensionDetails tx_em_Extensions_Details */
723 $extensionDetails = t3lib_div::makeInstance('tx_em_Extensions_Details');
724 /** @var $terConnection tx_em_Connection_Ter */
725 $terConnection = t3lib_div::makeInstance('tx_em_Connection_Ter', $this);
726 /** @var $install tx_em_Install */
727 $install = t3lib_div::makeInstance('tx_em_Install');
728 /** @var $api tx_em_API */
729 $api = t3lib_div::makeInstance('tx_em_API');
730
731
732 list($list,) = $extensionList->getInstalledExtensions();
733 $uploadArray = $extensionDetails->makeUploadarray($extKey, $list[$extKey]);
734
735 if (is_array($uploadArray)) {
736 $backUpData = $terConnection->makeUploadDataFromarray($uploadArray);
737 $filename = 'T3X_' . $extKey . '-' . str_replace('.', '_', $list[$extKey]['EM_CONF']['version']) . '-z-' . date('YmdHi') . '.t3x';
738
739 $techInfo = $install->makeDetailedExtensionAnalysis($extKey, $list[$extKey], FALSE, FALSE);
740 $lines = array();
741
742 // Backup
743 $lines[] = '<tr class="t3-row-header"><td colspan="2">' .
744 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_backup') . '</td></tr>';
745 $lines[] = '<tr class="bgColor4"><td><strong>' .
746 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extBackup_files') . '</strong></td><td>' .
747 '<a class="t3-link" href="' . htmlspecialchars(t3lib_div::linkThisScript(array(
748 'CMD[doBackup]' => 1,
749 'CMD[showExt]' => $extKey,
750 'SET[singleDetails]' => 'backup'
751 ))) .
752 '">' . sprintf($GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extBackup_download'),
753 $extKey
754 ) . '</a><br />
755 (' . $filename . ', <br />' .
756 t3lib_div::formatSize(strlen($backUpData)) . ', <br />' .
757 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extBackup_md5') . ' ' . md5($backUpData) . ')
758 <br /></td></tr>';
759
760
761 if (is_array($techInfo['tables'])) {
762 $lines[] = '<tr class="bgColor4"><td><strong>' . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extBackup_data_tables') .
763 '</strong></td><td>' .
764 tx_em_Database::dumpDataTablesLine($techInfo['tables'], $extKey, array('SET[singleDetails]' => 'backup')) .
765 '</td></tr>';
766 }
767 if (is_array($techInfo['static'])) {
768 $lines[] = '<tr class="bgColor4"><td><strong>' . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extBackup_static_tables') .
769 '</strong></td><td>' .
770 tx_em_Database::dumpDataTablesLine($techInfo['static'], $extKey, array('SET[singleDetails]' => 'backup')) .
771 '</td></tr>';
772 }
773
774 // Delete
775 if (!t3lib_extMgm::isLoaded($extKey)) {
776 // check ext scope
777 if (tx_em_Tools::deleteAsType($list[$extKey]['type']) && t3lib_div::inList('G,L', $list[$extKey]['type'])) {
778 $lines[] = '<tr class="t3-row-header"><td colspan="2">' .
779 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_delete') . '</td></tr>';
780 $lines[] = '<tr class="bgColor4"><td colspan="2">' . $install->extDelete($extKey, $list[$extKey], '') . '</td></tr>';
781 }
782 }
783 // EM_CONF
784 $lines[] = '<tr class="t3-row-header"><td colspan="2">' .
785 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_update_em_conf') . '</td></tr>';
786
787
788 $updateEMConf = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extUpdateEMCONF_file');
789 $lines[] = '<tr class="bgColor4"><td colspan="2">' .
790 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extUpdateEMCONF_info_changes') . '<br />
791 ' . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extUpdateEMCONF_info_reset') .
792 '<br /><br />' .
793 '<a class="t3-link emconfLink" href="#"><strong>' . $updateEMConf . '</strong> ' .
794 sprintf($GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:extDelete_from_location'),
795 $api->typeLabels[$list[$extKey]['type']],
796 substr(tx_em_Tools::getExtPath($extKey, $list[$extKey]['type']['type']), strlen(PATH_site))
797 ) . '</a>'
798 . '</td></tr>';
799
800
801 // mod menu for singleDetails
802 $modMenu = $GLOBALS['TBE_MODULES_EXT']['tools_em']['MOD_MENU']['singleDetails'];
803 if (isset($modMenu) && is_array($modMenu)) {
804 $lines[] = '<tr class="t3-row-header"><td colspan="2">' .
805 $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_externActions') . '</td></tr>';
806 $menuLinks = '';
807 foreach ($modMenu as $menuEntry) {
808 $onClick = htmlspecialchars('jumpToUrl(\'mod.php?&id=0&M=tools_em&SET[singleDetails]=' . $menuEntry['name'] . '&CMD[showExt]=' . $extKey . '\');');
809 $menuLinks .= '<a class="t3-link" href="#" onclick="' . $onClick . '" >' .
810 $GLOBALS['LANG']->sL($menuEntry['title'], TRUE) . '</a><br />';
811 }
812 $lines[] = '<tr class="bgColor4"><td colspan="2"><p>' . $menuLinks . '</p></td></tr>';
813 }
814
815 $content = '<table border="0" cellpadding="2" cellspacing="2">' . implode('', $lines) . '</table>';
816
817
818
819 return $this->replaceLinks($content);
820 }
821 }
822
823 /**
824 * Execute update script
825 *
826 * @param $extkey
827 * @return array
828 */
829 public function getExtensionUpdateScript($extkey) {
830 $updateScript = t3lib_extMgm::extPath($extkey) . 'class.ext_update.php';
831 require_once($updateScript);
832 $updateObj = new ext_update;
833 $access = FALSE;
834 if ($updateObj->access()) {
835 $access = TRUE;
836 }
837
838 return array(
839 'success' => $access,
840 );
841
842 }
843 /*********************************************************************/
844 /* Remote Extension List */
845 /*********************************************************************/
846
847
848 /**
849 * Render remote extension list
850 *
851 * @param object $parameters
852 * @return string $content
853 */
854 public function getRemoteExtensionList($parameters) {
855 $repositoryId = $parameters->repository;
856 $mirrorUrl = $this->getMirrorUrl($repositoryId);
857
858 $list = $this->getFlatExtensionList();
859 $localList = $list['data'];
860
861 $search = htmlspecialchars($parameters->query);
862 $limit = htmlspecialchars($parameters->start . ', ' . $parameters->limit);
863 $orderBy = htmlspecialchars($parameters->sort);
864 $orderDir = htmlspecialchars($parameters->dir);
865 if ($orderBy == '') {
866 $orderBy = 'relevance';
867 $orderDir = 'ASC';
868 }
869 if ($orderBy === 'statevalue') {
870 $orderBy = 'cache_extensions.state ' . $orderDir;
871 } elseif ($orderBy === 'relevance') {
872 $orderBy = 'relevance ' . $orderDir . ', cache_extensions.title ' . $orderDir;
873 } else {
874 $orderBy = 'cache_extensions.' . $orderBy . ' ' . $orderDir;
875 }
876 $installedOnly = $parameters->installedOnly;
877
878 $where = $addFields = '';
879
880 if ($search === '' && !$installedOnly) {
881 return array(
882 'length' => 0,
883 'data' => array(),
884 );
885 } elseif ($search === '*') {
886
887 } else {
888 $quotedSearch = $GLOBALS['TYPO3_DB']->escapeStrForLike(
889 $GLOBALS['TYPO3_DB']->quoteStr($search, 'cache_extensions'),
890 'cache_extensions'
891 );
892 $addFields = '
893 (CASE WHEN cache_extensions.extkey = "' . $search . '" THEN 100 ELSE 5 END) +
894 (CASE WHEN cache_extensions.title = "' . $search . '" THEN 80 ELSE 5 END) +
895 (CASE WHEN cache_extensions.extkey LIKE \'%' . $quotedSearch . '%\' THEN 60 ELSE 5 END) +
896 (CASE WHEN cache_extensions.title LIKE \'%' . $quotedSearch . '%\' THEN 40 ELSE 5 END)
897 AS relevance';
898
899 if (t3lib_extMgm::isLoaded('dbal')) {
900 // as dbal can't use the sum, make it more easy for dbal
901 $addFields = 'CASE WHEN cache_extensions.extkey = \'' . $search . '\' THEN 100 ELSE 10 END AS relevance';
902 }
903 $where = ' AND (cache_extensions.extkey LIKE \'%' . $quotedSearch . '%\' OR cache_extensions.title LIKE \'%' . $quotedSearch . '%\')';
904
905 }
906 // check for filter
907 $where .= $this->makeFilterQuery(get_object_vars($parameters));
908
909 if ($installedOnly) {
910 $temp = array();
911 foreach ($localList as $key => $value) {
912 if ($value['installed']) {
913 $temp[] = '"' . $key . '"';
914 }
915 }
916 $where .= ' AND cache_extensions.extkey IN(' . implode(',', $temp) . ')';
917 $limit = '';
918 }
919
920
921 $list = tx_em_Database::getExtensionListFromRepository(
922 $repositoryId,
923 $addFields,
924 $where,
925 $orderBy,
926 $limit
927 );
928
929 $updateKeys = array();
930
931 // transform array
932 foreach ($list['results'] as $key => $value) {
933 $list['results'][$key]['dependencies'] = unserialize($value['dependencies']);
934 $extPath = t3lib_div::strtolower($value['extkey']);
935 $list['results'][$key]['statevalue'] = $value['state'];
936 $list['results'][$key]['state'] = tx_em_Tools::getDefaultState(intval($value['state']));
937 $list['results'][$key]['stateCls'] = 'state-' . $list['results'][$key]['state'];
938 $list['results'][$key]['version'] = tx_em_Tools::versionFromInt($value['maxintversion']);
939 $list['results'][$key]['icon'] = '<img alt="" src="' . $mirrorUrl . $extPath{0} . '/' . $extPath{1} . '/' . $extPath . '_' . $list['results'][$key]['version'] . '.gif" />';
940
941 $list['results'][$key]['exists'] = 0;
942 $list['results'][$key]['installed'] = 0;
943 $list['results'][$key]['versionislower'] = 0;
944 $list['results'][$key]['existingVersion'] = '';
945 if (isset($localList[$value['extkey']])) {
946 $isUpdatable = ($localList[$value['extkey']]['intversion'] < $value['maxintversion']);
947 $list['results'][$key]['exists'] = 1;
948 $list['results'][$key]['installed'] = $localList[$value['extkey']]['installed'];
949 $list['results'][$key]['versionislower'] = $isUpdatable;
950 $list['results'][$key]['existingVersion'] = $localList[$value['extkey']]['version'];
951 if ($isUpdatable) {
952 $updateKeys[] = $key;
953 }
954 }
955 }
956 // updatable only
957 if ($installedOnly == 2) {
958 $temp = array();
959 if (count($updateKeys)) {
960 foreach ($updateKeys as $key) {
961 $temp[]= $list['results'][$key];
962 }
963 }
964 $list['results'] = $temp;
965 $list['count'] -= count($updateKeys);
966 }
967
968 return array(
969 'length' => $list['count'],
970 'data' => $list['results'],
971 );
972
973 }
974
975
976 /**
977 * Loads repositories
978 *
979 * @return array
980 */
981 public function getRepositories() {
982 $settings = $this->getSettings();
983 $repositories = tx_em_Database::getRepositories();
984 $data = array();
985
986 foreach ($repositories as $uid => $repository) {
987 $data[] = array(
988 'title' => $repository['title'],
989 'uid' => $repository['uid'],
990 'description' => $repository['description'],
991 'wsdl_url' => $repository['wsdl_url'],
992 'mirror_url' => $repository['mirror_url'],
993 'count' => $repository['extCount'],
994 'updated' => $repository['lastUpdated'] ? date('d/m/Y H:i', $repository['lastUpdated']) : 'never',
995 'selected' => $repository['uid'] === $settings['selectedRepository'],
996 );
997 }
998
999 return array(
1000 'length' => count($data),
1001 'data' => $data,
1002 );
1003 }
1004
1005
1006 /**
1007 * Get Mirrors for selected repository
1008 *
1009 * @param object $parameter
1010 * @return array
1011 */
1012 public function getMirrors($parameter) {
1013 $data = array();
1014 /** @var $objRepository tx_em_Repository */
1015 $objRepository = t3lib_div::makeInstance('tx_em_Repository', $parameter->repository);
1016
1017 if ($objRepository->getMirrorListUrl()) {
1018 $objRepositoryUtility = t3lib_div::makeInstance('tx_em_Repository_Utility', $objRepository);
1019 $mirrors = $objRepositoryUtility->getMirrors(TRUE)->getMirrors();
1020
1021
1022 if (count($mirrors)) {
1023 $data = array(
1024 array(
1025 'title' => $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:mirror_use_random'),
1026 'country' => '',
1027 'host' => '',
1028 'path' => '',
1029 'sponsor' => '',
1030 'link' => '',
1031 'logo' => '',
1032 )
1033 );
1034 foreach ($mirrors as $mirror) {
1035 $data[] = array(
1036 'title' => $mirror['title'],
1037 'country' => $mirror['country'],
1038 'host' => $mirror['host'],
1039 'path' => $mirror['path'],
1040 'sponsor' => $mirror['sponsorname'],
1041 'link' => $mirror['sponsorlink'],
1042 'logo' => $mirror['sponsorlogo'],
1043 );
1044 }
1045 }
1046 }
1047
1048 return array(
1049 'length' => count($data),
1050 'data' => $data,
1051 );
1052
1053 }
1054
1055 /**
1056 * Edit / Create repository
1057 *
1058 * @formHandler
1059 * @param array $parameter
1060 * @return array
1061 */
1062 public function repositoryEditFormSubmit($parameter) {
1063 $repId = intval($parameter['rep']);
1064
1065 /** @var $repository tx_em_Repository */
1066 $repository = t3lib_div::makeInstance('tx_em_Repository', $repId);
1067 $repository->setTitle($parameter['title']);
1068 $repository->setDescription($parameter['description']);
1069 $repository->setWsdlUrl($parameter['wsdl_url']);
1070 $repository->setMirrorListUrl($parameter['mirror_url']);
1071 $repositoryData = array(
1072 'title' => $repository->getTitle(),
1073 'description' => $repository->getDescription(),
1074 'wsdl_url' => $repository->getWsdlUrl(),
1075 'mirror_url' => $repository->getMirrorListUrl(),
1076 'lastUpdated' => $repository->getLastUpdate(),
1077 'extCount' => $repository->getExtensionCount(),
1078 );
1079
1080 if ($repId === 0) {
1081 // create a new repository
1082 $id = tx_em_Database::insertRepository($repository);
1083 return array(
1084 'success' => TRUE,
1085 'newId' => $id,
1086 'params' => $repositoryData
1087 );
1088
1089 } else {
1090 tx_em_Database::updateRepository($repository);
1091 return array(
1092 'success' => TRUE,
1093 'params' => $repositoryData
1094 );
1095 }
1096 }
1097
1098
1099 /**
1100 * Delete repository
1101 *
1102 * @param int $uid
1103 * @return array
1104 */
1105 public function deleteRepository($uid) {
1106 if (intval($uid) < 2) {
1107 return array(
1108 'success' => FALSE,
1109 'error' => $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:repository_main_nodelete')
1110 );
1111 }
1112 $repository = t3lib_div::makeInstance('tx_em_Repository', intval($uid));
1113 tx_em_Database::deleteRepository($repository);
1114 return array(
1115 'success' => TRUE,
1116 'uid' => intval($uid)
1117 );
1118 }
1119 /**
1120 * Update repository
1121 *
1122 * @param array $parameter
1123 * @return array
1124 */
1125 public function repositoryUpdate($repositoryId) {
1126
1127 if (!intval($repositoryId)) {
1128 return array(
1129 'success' => FALSE,
1130 'errors' => 'no repository choosen',
1131 'rep' => 0
1132 );
1133 }
1134
1135 /** @var $objRepository tx_em_Repository */
1136 $objRepository = t3lib_div::makeInstance('tx_em_Repository', intval($repositoryId));
1137 /** @var $objRepositoryUtility tx_em_Repository_Utility */
1138 $objRepositoryUtility = t3lib_div::makeInstance('tx_em_Repository_Utility', $objRepository);
1139 $count = $objRepositoryUtility->updateExtList();
1140 $time = $GLOBALS['EXEC_TIME'];
1141
1142 if ($count) {
1143 $objRepository->setExtensionCount($count);
1144 $objRepository->setLastUpdate($time);
1145 tx_em_Database::updateRepository($objRepository);
1146 return array(
1147 'success' => TRUE,
1148 'data' => array(
1149 'count' => $count,
1150 'updated' => date('d/m/Y H:i', $time)
1151 ),
1152 'rep' => intval($repositoryId)
1153 );
1154 } else {
1155 return array(
1156 'success' => FALSE,
1157 'errormsg' => $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:repository_upToDate'),
1158 'rep' => intval($repositoryId)
1159 );
1160 }
1161 }
1162
1163
1164 /*********************************************************************/
1165 /* Translation Handling */
1166 /*********************************************************************/
1167
1168
1169 /**
1170 * Gets the system languages
1171 *
1172 * @return array
1173 */
1174 public function getLanguages() {
1175 $this->globalSettings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['em']);
1176 $selected = t3lib_div::trimExplode(',', $this->globalSettings['selectedLanguages'], TRUE);
1177
1178 /** @var $locales t3lib_l10n_Locales */
1179 $locales = t3lib_div::makeInstance('t3lib_l10n_Locales');
1180 $theLanguages = $locales->getLanguages();
1181 //drop default
1182 array_shift($theLanguages);
1183 $lang = $meta = array();
1184 foreach ($theLanguages as $language => $name) {
1185 $label = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:setup/mod/locallang.xml:lang_' . $language));
1186 if ($label === '') {
1187 $label = htmlspecialchars($name);
1188 }
1189 $lang[] = array(
1190 'label' => $label,
1191 'lang' => $language,
1192 'selected' => is_array($selected) && in_array($language, $selected) ? 1 : 0
1193 );
1194 $meta[] = array(
1195 'hidden' => is_array($selected) && in_array($language, $selected) ? 'false' : 'true',
1196 'header' => $language,
1197 'dataIndex' => $language,
1198 'width' => '100',
1199 'fixed' => TRUE,
1200 'sortable' => FALSE,
1201 'hidable' => FALSE,
1202 'menuDisabled' => TRUE,
1203 );
1204 }
1205 return array(
1206 'length' => count($lang),
1207 'data' => $lang,
1208 'meta' => $meta,
1209 );
1210
1211 }
1212
1213 /**
1214 * Saves language selection
1215 *
1216 * @param array $parameter
1217 * @return string
1218 */
1219 public function saveLanguageSelection($parameter) {
1220 // Add possible dependencies for selected languages
1221 /** @var $locales t3lib_l10n_Locales */
1222 $locales = t3lib_div::makeInstance('t3lib_l10n_Locales');
1223 $dependencies = array();
1224 foreach ($parameter as $language) {
1225 $dependencies = array_merge($dependencies, $locales->getLocaleDependencies($language));
1226 }
1227 if (count($dependencies) > 0) {
1228 $parameter = array_unique(array_merge($parameter, $dependencies));
1229 }
1230
1231 $this->globalSettings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['em']);
1232 $selected = t3lib_div::trimExplode(',', $this->globalSettings['selectedLanguages'], TRUE);
1233
1234 $dir = count($parameter) - count($selected);
1235 $diff = $dir < 0 ? array_diff($selected, $parameter) : array_diff($parameter, $selected);
1236 $type = tx_em_Tools::getExtTypeFromPath(t3lib_extMgm::extPath('em'));
1237
1238 $params = array(
1239 'extkey' => 'em',
1240 'exttype' => $type,
1241 'data' => array(
1242 'selectedLanguages' => implode(',', $parameter)
1243 )
1244 );
1245 $this->saveExtensionConfiguration($params);
1246
1247 return array(
1248 'success' => count($diff) > 0,
1249 'dir' => $dir,
1250 'diff' => array_values($diff),
1251 'languages' => $parameter
1252 );
1253 }
1254
1255
1256 /**
1257 * Fetches translation from server
1258 *
1259 * @param string $extkey
1260 * @param string $type
1261 * @param array $selection
1262 * @return array
1263 */
1264 public function fetchTranslations($extkey, $type, $selection) {
1265 $result = array();
1266 if (is_array($selection) && count($selection)) {
1267 /** @var $terConnection tx_em_Connection_Ter */
1268 $terConnection = t3lib_div::makeInstance('tx_em_Connection_Ter', $this);
1269 /** @var $xmlHandler tx_em_Tools_XmlHandler */
1270 $this->xmlHandler = t3lib_div::makeInstance('tx_em_Tools_XmlHandler');
1271 $this->xmlHandler->emObj = $this;
1272 $mirrorURL = $this->getSettingsObject()->getMirrorURL();
1273
1274 $infoIcon = '<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-info">&nbsp;</span>';
1275 $updateIcon = '<span class="t3-icon t3-icon-actions t3-icon-actions-system t3-icon-system-extension-update">&nbsp;</span>';
1276 $newIcon = '<span class="t3-icon t3-icon-actions t3-icon-actions-system t3-icon-system-extension-import">&nbsp;</span>';
1277 $okIcon = '<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-checked">&nbsp;</span>';
1278 $errorIcon = '<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-permission-denied">&nbsp;</span>';
1279
1280 foreach ($selection as $lang) {
1281 $fetch = $terConnection->fetchTranslationStatus($extkey, $mirrorURL);
1282
1283 $localmd5 = '';
1284 if (!isset($fetch[$lang])) {
1285 //no translation available
1286 $result[$lang] = $infoIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:translation_n_a');
1287 } else {
1288 $zip = PATH_site . 'typo3temp/' . $extkey . '-l10n-' . $lang . '.zip';
1289 if (is_file($zip)) {
1290 $localmd5 = md5_file($zip);
1291 }
1292 if ($localmd5 !== $fetch[$lang]['md5']) {
1293 if ($type) {
1294 //fetch translation
1295 $ret = $terConnection->updateTranslation($extkey, $lang, $mirrorURL);
1296
1297 $result[$lang] = $ret
1298 ? $okIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_updated')
1299 : $errorIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_failed');
1300 } else {
1301 //translation status
1302 $result[$lang] = $localmd5 !== ''
1303 ? $updateIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:translation_status_update')
1304 : $newIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:translation_status_new');
1305 }
1306 } else {
1307 //translation is up to date
1308 $result[$lang] = $okIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:translation_status_uptodate');
1309 }
1310 }
1311
1312
1313 }
1314 }
1315 return $result;
1316 }
1317
1318
1319 /*********************************************************************/
1320 /* Settings */
1321 /*********************************************************************/
1322
1323 /**
1324 * Returns settings object.
1325 *
1326 * @access public
1327 * @return tx_em_Settings instance of settings object
1328 */
1329 public function getSettings() {
1330 return $this->getSettingsObject()->getSettings();
1331 }
1332
1333 /**
1334 * Enter description here...
1335 *
1336 * @param string $name
1337 * @param mixed $value
1338 * @return boolean
1339 */
1340 public function saveSetting($name, $value) {
1341 $this->getSettingsObject()->saveSetting($name, $value);
1342 return TRUE;
1343 }
1344
1345 /**
1346 * Load form values for settings form
1347 *
1348 * @return array FormValues
1349 */
1350 public function settingsFormLoad() {
1351 $settings = $this->getSettings();
1352
1353 return array(
1354 'success' => TRUE,
1355 'data' => array(
1356 'display_unchecked' => $settings['display_unchecked'],
1357 'fe_u' => $settings['fe_u'],
1358 'fe_p' => $settings['fe_p'],
1359 'selectedMirror' => $settings['selectedMirror'],
1360 'selectedRepository' => $settings['selectedRepository'],
1361 )
1362 );
1363 }
1364
1365 /**
1366 * Save settings from form submit
1367 *
1368 * @formHandler
1369 * @param array $parameter
1370 * @return array
1371 */
1372 public function settingsFormSubmit($parameter) {
1373 $settings = $this->getSettingsObject()->saveSettings(array(
1374 'display_unchecked' => isset($parameter['display_unchecked']),
1375 'fe_u' => $parameter['fe_u'],
1376 'fe_p' => $parameter['fe_p'],
1377 'selectedMirror' => $parameter['selectedMirror'],
1378 'selectedRepository' => $parameter['selectedRepository'],
1379 ));
1380 return array(
1381 'success' => TRUE,
1382 'data' => $parameter,
1383 'settings' => $settings
1384 );
1385 }
1386
1387
1388 /*********************************************************************/
1389 /* EM Tools */
1390 /*********************************************************************/
1391
1392 /**
1393 * Upload an extension
1394 *
1395 * @formHandler
1396 *
1397 * @access public
1398 * @param $parameter composed parameter from $POST and $_FILES
1399 * @return array status
1400 */
1401 public function uploadExtension($parameter) {
1402 $uploadedTempFile = isset($parameter['extfile']) ? $parameter['extfile'] : t3lib_div::upload_to_tempfile($parameter['extupload-path']['tmp_name']);
1403 $location = ($parameter['loc'] === 'G' || $parameter['loc'] === 'S') ? $parameter['loc'] : 'L';
1404 $uploadOverwrite = $parameter['uploadOverwrite'] ? TRUE : FALSE;
1405
1406 $install = t3lib_div::makeInstance('tx_em_Install', $this);
1407 $this->extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this);
1408 $this->extensionDetails = t3lib_div::makeInstance('tx_em_Extensions_Details', $this);
1409
1410 $upload = $install->uploadExtensionFile($uploadedTempFile, $location, $uploadOverwrite);
1411
1412 if ($upload[0] === FALSE) {
1413 return array(
1414 'success' => FALSE,
1415 'error' => $upload[1]
1416 );
1417 }
1418
1419 $extKey = $upload[1][0]['extKey'];
1420 $version = '';
1421 $dontDelete = TRUE;
1422 $result = $install->installExtension($upload[1], $location, $version, $uploadedTempFile, $dontDelete);
1423 return array(
1424 'success' => TRUE,
1425 'data' => $result,
1426 'extKey' => $extKey
1427 );
1428
1429 }
1430
1431 /**
1432 * Enables an extension
1433 *
1434 * @param $extensionKey
1435 * @return void
1436 */
1437 public function enableExtension($extensionKey) {
1438 $this->extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this);
1439 $install = t3lib_div::makeInstance('tx_em_Install', $this);
1440
1441 list($installedList,) = $this->extensionList->getInstalledExtensions();
1442 $newExtensionList = $this->extensionList->addExtToList($extensionKey, $installedList);
1443
1444 $install->writeNewExtensionList($newExtensionList);
1445 tx_em_Tools::refreshGlobalExtList();
1446 $install->forceDBupdates($extensionKey, $installedList[$extensionKey]);
1447 }
1448
1449 /**
1450 * Reset all states for current user
1451 *
1452 * @return void
1453 */
1454 public function resetStates() {
1455 unset($GLOBALS['BE_USER']->uc['moduleData']['tools_em']['States']);
1456 $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc);
1457 return array('success' => TRUE);
1458 }
1459
1460 /**
1461 * Gets the mirror url from selected mirror
1462 *
1463 * @param $repositoryId
1464 * @return string
1465 */
1466 protected function getMirrorUrl($repositoryId) {
1467 $settings = $this->getSettings();
1468 /** @var $objRepository tx_em_Repository */
1469 $objRepository = t3lib_div::makeInstance('tx_em_Repository', $repositoryId);
1470 /** @var $objRepositoryUtility tx_em_Repository_Utility */
1471 $objRepositoryUtility = t3lib_div::makeInstance('tx_em_Repository_Utility', $objRepository);
1472 $mirrors = $objRepositoryUtility->getMirrors(TRUE)->getMirrors();
1473
1474
1475 if ($settings['selectedMirror'] == '') {
1476 $randomMirror = array_rand($mirrors);
1477 $mirrorUrl = $mirrors[$randomMirror]['host'] . $mirrors[$randomMirror]['path'];
1478 } else {
1479 foreach($mirrors as $mirror) {
1480 if ($mirror['host'] == $settings['selectedMirror']) {
1481 $mirrorUrl = $mirror['host'] . $mirror['path'];
1482 break;
1483 }
1484 }
1485 }
1486
1487 return 'http://' . $mirrorUrl;
1488 }
1489
1490 /**
1491 * Resolves the filter settings from repository list and makes a whereClause
1492 *
1493 * @param array $parameter
1494 * @return string additional whereClause
1495 */
1496 protected function makeFilterQuery($parameter) {
1497 $where = '';
1498 $filter = $found = array();
1499
1500 foreach ($parameter as $key => $value) {
1501 if (substr($key, 0, 6) === 'filter') {
1502 eval('$' . $key . ' = \'' . $value . '\';');
1503 }
1504 }
1505
1506
1507 if (count($filter)) {
1508 foreach ($filter as $value) {
1509 switch ($value['data']['type']) {
1510 case 'list':
1511 if ($value['field'] === 'statevalue') {
1512 $where .= ' AND cache_extensions.state IN(' . htmlspecialchars($value['data']['value']) . ')';
1513 }
1514 if ($value['field'] === 'category') {
1515 $where .= ' AND cache_extensions.category IN(' . htmlspecialchars($value['data']['value']) . ')';
1516 }
1517 break;
1518 default:
1519 $quotedSearch = $GLOBALS['TYPO3_DB']->escapeStrForLike(
1520 $GLOBALS['TYPO3_DB']->quoteStr($value['data']['value'], 'cache_extensions'),
1521 'cache_extensions'
1522 );
1523 $where .= ' AND cache_extensions.' . htmlspecialchars($value['field']) . ' LIKE "%' . $quotedSearch . '%"';
1524 }
1525 }
1526 }
1527 return $where;
1528 }
1529
1530 /**
1531 * Replace links that are created with t3lib_div::linkThisScript to point to module
1532 *
1533 * @param string $string
1534 * @return string
1535 */
1536 protected function replaceLinks($string) {
1537 return str_replace(
1538 'ajax.php?ajaxID=ExtDirect%3A%3Aroute&amp;namespace=TYPO3.EM',
1539 'mod.php?M=tools_em',
1540 $string
1541 );
1542 }
1543
1544 /**
1545 * Get the selected repository
1546 *
1547 * @return array
1548 */
1549 protected function getSelectedRepository() {
1550 $settings = $this->getSettings();
1551 $repositories = tx_em_Database::getRepositories();
1552 $selectedRepository = array();
1553
1554 foreach ($repositories as $uid => $repository) {
1555 if ($repository['uid'] == $settings['selectedRepository']) {
1556 $selectedRepository = array(
1557 'title' => $repository['title'],
1558 'uid' => $repository['uid'],
1559 'description' => $repository['description'],
1560 'wsdl_url' => $repository['wsdl_url'],
1561 'mirror_url' => $repository['mirror_url'],
1562 'count' => $repository['extCount'],
1563 'updated' => $repository['lastUpdated'] ? date('d/m/Y H:i', $repository['lastUpdated']) : 'never',
1564 'selected' => $repository['uid'] === $settings['selectedRepository'],
1565 );
1566 }
1567 }
1568
1569 return $selectedRepository;
1570 }
1571
1572 /**
1573 * Gets file info for ExtJs tree node
1574 *
1575 * @param $file
1576 * @return array
1577 */
1578 protected function getFileInfo($file) {
1579 $unknownType = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_file_unknownType');
1580 $imageType = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_file_imageType');
1581 $textType = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_file_textType');
1582 $extType = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_file_extType');
1583
1584 $editTypes = explode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext']);
1585 $imageTypes = array('gif', 'jpg', 'png');
1586
1587 $fileExt = '';
1588 $type = '';
1589 $cls = t3lib_iconWorks::mapFileExtensionToSpriteIconClass('');
1590 if (strrpos($file, '.') !== FALSE) {
1591 $fileExt = strtolower(substr($file, strrpos($file, '.') + 1));
1592 }
1593
1594 if ($fileExt && in_array($fileExt, $imageTypes) || in_array($fileExt, $editTypes)) {
1595 $cls = t3lib_iconWorks::mapFileExtensionToSpriteIconClass($fileExt);
1596 $type = in_array($fileExt, $imageTypes) ? 'image' : 'text';
1597 }
1598
1599 if (t3lib_div::strtolower($file) === 'changelog') {
1600 $cls = t3lib_iconWorks::mapFileExtensionToSpriteIconClass('txt');
1601 $type = 'text';
1602 }
1603
1604 switch($type) {
1605 CASE 'image':
1606 $label = $imageType;
1607 break;
1608 CASE 'text':
1609 $label = $textType;
1610 break;
1611 default:
1612 $label = $fileExt ? sprintf($extType, $fileExt) : $unknownType;
1613 }
1614
1615 return array(
1616 htmlspecialchars($file),
1617 $label,
1618 htmlspecialchars($fileExt),
1619 $type,
1620 $cls
1621 );
1622
1623 }
1624
1625
1626 /**
1627 * File operations like delete, copy, move
1628 * @param $file commandMap, @see
1629 * @return
1630 */
1631 protected function fileOperation($file) {
1632 $mount = array(0 => array(
1633 'name' => 'root',
1634 'path' => PATH_site,
1635 'type' => ''
1636 ));
1637 $files = array(0 => array(
1638 'webspace' => array('allow' => '*', 'deny' => ''),
1639 'ftpspace' => array('allow' => '*', 'deny' => '')
1640 ));
1641 $fileProcessor = t3lib_div::makeInstance('t3lib_extFileFunctions');
1642 $fileProcessor->init($mount, $files);
1643 $fileProcessor->init_actionPerms($GLOBALS['BE_USER']->getFileoperationPermissions());
1644 $fileProcessor->dontCheckForUnique = 0;
1645
1646 // Checking referer / executing:
1647 $refInfo = parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
1648 $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');
1649 if ($httpHost != $refInfo['host']
1650 && $this->vC != $GLOBALS['BE_USER']->veriCode()
1651 && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']
1652 && $GLOBALS['CLIENT']['BROWSER'] != 'flash') {
1653 $fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost));
1654 } else {
1655 $fileProcessor->start($file);
1656 $fileData = $fileProcessor->processData();
1657 }
1658
1659 return $fileData;
1660 }
1661
1662 }
1663
1664 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/connection/class.tx_em_connectionextdirectserver.php'])) {
1665 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/connection/class.tx_em_connection_extdirectserver.php']);
1666 }
1667
1668 ?>