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