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