Fixed bug #17787: Filtering in repository state does not work
[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->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]['stateCls'] = 'state-' . $list['results'][$key]['state'];
909 $list['results'][$key]['version'] = tx_em_Tools::versionFromInt($value['maxintversion']);
910 $list['results'][$key]['icon'] = '<img alt="" src="' . $mirrorUrl . $extPath{0} . '/' . $extPath{1} . '/' . $extPath . '_' . $list['results'][$key]['version'] . '.gif" />';
911
912 $list['results'][$key]['exists'] = 0;
913 $list['results'][$key]['installed'] = 0;
914 $list['results'][$key]['versionislower'] = 0;
915 $list['results'][$key]['existingVersion'] = '';
916 if (isset($localList[$value['extkey']])) {
917 $isUpdatable = ($localList[$value['extkey']]['intversion'] < $value['maxintversion']);
918 $list['results'][$key]['exists'] = 1;
919 $list['results'][$key]['installed'] = $localList[$value['extkey']]['installed'];
920 $list['results'][$key]['versionislower'] = $isUpdatable;
921 $list['results'][$key]['existingVersion'] = $localList[$value['extkey']]['version'];
922 if ($isUpdatable) {
923 $updateKeys[] = $key;
924 }
925 }
926 }
927 // updatable only
928 if ($installedOnly == 2) {
929 $temp = array();
930 if (count($updateKeys)) {
931 foreach ($updateKeys as $key) {
932 $temp[]= $list['results'][$key];
933 }
934 }
935 $list['results'] = $temp;
936 $list['count'] -= count($updateKeys);
937 }
938
939 return array(
940 'length' => $list['count'],
941 'data' => $list['results'],
942 );
943
944 }
945
946
947 /**
948 * Loads repositories
949 *
950 * @return array
951 */
952 public function getRepositories() {
953 $settings = $this->getSettings();
954 $repositories = tx_em_Database::getRepositories();
955 $data = array();
956
957 foreach ($repositories as $uid => $repository) {
958 $data[] = array(
959 'title' => $repository['title'],
960 'uid' => $repository['uid'],
961 'description' => $repository['description'],
962 'wsdl_url' => $repository['wsdl_url'],
963 'mirror_url' => $repository['mirror_url'],
964 'count' => $repository['extCount'],
965 'updated' => $repository['lastUpdated'] ? date('d/m/Y H:i', $repository['lastUpdated']) : 'never',
966 'selected' => $repository['uid'] === $settings['selectedRepository'],
967 );
968 }
969
970 return array(
971 'length' => count($data),
972 'data' => $data,
973 );
974 }
975
976
977 /**
978 * Get Mirrors for selected repository
979 *
980 * @param object $parameter
981 * @return array
982 */
983 public function getMirrors($parameter) {
984 $data = array();
985 /** @var $objRepository tx_em_Repository */
986 $objRepository = t3lib_div::makeInstance('tx_em_Repository', $parameter->repository);
987
988 if ($objRepository->getMirrorListUrl()) {
989 $objRepositoryUtility = t3lib_div::makeInstance('tx_em_Repository_Utility', $objRepository);
990 $mirrors = $objRepositoryUtility->getMirrors(TRUE)->getMirrors();
991
992
993 if (count($mirrors)) {
994 $data = array(
995 array(
996 'title' => $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:mirror_use_random'),
997 'country' => '',
998 'host' => '',
999 'path' => '',
1000 'sponsor' => '',
1001 'link' => '',
1002 'logo' => '',
1003 )
1004 );
1005 foreach ($mirrors as $mirror) {
1006 $data[] = array(
1007 'title' => $mirror['title'],
1008 'country' => $mirror['country'],
1009 'host' => $mirror['host'],
1010 'path' => $mirror['path'],
1011 'sponsor' => $mirror['sponsorname'],
1012 'link' => $mirror['sponsorlink'],
1013 'logo' => $mirror['sponsorlogo'],
1014 );
1015 }
1016 }
1017 }
1018
1019 return array(
1020 'length' => count($data),
1021 'data' => $data,
1022 );
1023
1024 }
1025
1026 /**
1027 * Edit / Create repository
1028 *
1029 * @formHandler
1030 * @param array $parameter
1031 * @return array
1032 */
1033 public function repositoryEditFormSubmit($parameter) {
1034 $repId = intval($parameter['rep']);
1035
1036 /** @var $repository tx_em_Repository */
1037 $repository = t3lib_div::makeInstance('tx_em_Repository', $repId);
1038 $repository->setTitle($parameter['title']);
1039 $repository->setDescription($parameter['description']);
1040 $repository->setWsdlUrl($parameter['wsdl_url']);
1041 $repository->setMirrorListUrl($parameter['mirror_url']);
1042 $repositoryData = array(
1043 'title' => $repository->getTitle(),
1044 'description' => $repository->getDescription(),
1045 'wsdl_url' => $repository->getWsdlUrl(),
1046 'mirror_url' => $repository->getMirrorListUrl(),
1047 'lastUpdated' => $repository->getLastUpdate(),
1048 'extCount' => $repository->getExtensionCount(),
1049 );
1050
1051 if ($repId === 0) {
1052 // create a new repository
1053 $id = tx_em_Database::insertRepository($repository);
1054 return array(
1055 'success' => TRUE,
1056 'newId' => $id,
1057 'params' => $repositoryData
1058 );
1059
1060 } else {
1061 tx_em_Database::updateRepository($repository);
1062 return array(
1063 'success' => TRUE,
1064 'params' => $repositoryData
1065 );
1066 }
1067 }
1068
1069
1070 /**
1071 * Delete repository
1072 *
1073 * @param int $uid
1074 * @return array
1075 */
1076 public function deleteRepository($uid) {
1077 if (intval($uid) < 2) {
1078 return array(
1079 'success' => FALSE,
1080 'error' => $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:repository_main_nodelete')
1081 );
1082 }
1083 $repository = t3lib_div::makeInstance('tx_em_Repository', intval($uid));
1084 tx_em_Database::deleteRepository($repository);
1085 return array(
1086 'success' => TRUE,
1087 'uid' => intval($uid)
1088 );
1089 }
1090 /**
1091 * Update repository
1092 *
1093 * @param array $parameter
1094 * @return array
1095 */
1096 public function repositoryUpdate($repositoryId) {
1097
1098 if (!intval($repositoryId)) {
1099 return array(
1100 'success' => FALSE,
1101 'errors' => 'no repository choosen',
1102 'rep' => 0
1103 );
1104 }
1105
1106 /** @var $objRepository tx_em_Repository */
1107 $objRepository = t3lib_div::makeInstance('tx_em_Repository', intval($repositoryId));
1108 /** @var $objRepositoryUtility tx_em_Repository_Utility */
1109 $objRepositoryUtility = t3lib_div::makeInstance('tx_em_Repository_Utility', $objRepository);
1110 $count = $objRepositoryUtility->updateExtList();
1111 $time = $GLOBALS['EXEC_TIME'];
1112
1113 if ($count) {
1114 $objRepository->setExtensionCount($count);
1115 $objRepository->setLastUpdate($time);
1116 tx_em_Database::updateRepository($objRepository);
1117 return array(
1118 'success' => TRUE,
1119 'data' => array(
1120 'count' => $count,
1121 'updated' => date('d/m/Y H:i', $time)
1122 ),
1123 'rep' => intval($repositoryId)
1124 );
1125 } else {
1126 return array(
1127 'success' => FALSE,
1128 'errormsg' => $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:repository_upToDate'),
1129 'rep' => intval($repositoryId)
1130 );
1131 }
1132 }
1133
1134
1135 /*********************************************************************/
1136 /* Translation Handling */
1137 /*********************************************************************/
1138
1139
1140 /**
1141 * Gets the system languages
1142 *
1143 * @return array
1144 */
1145 public function getLanguages() {
1146 $this->globalSettings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['em']);
1147 $selected = t3lib_div::trimExplode(',', $this->globalSettings['selectedLanguages'], TRUE);
1148
1149 $theLanguages = t3lib_div::trimExplode('|', TYPO3_languages);
1150 //drop default
1151 array_shift($theLanguages);
1152 $lang = $meta = array();
1153 foreach ($theLanguages as $language) {
1154 $label = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:setup/mod/locallang.xml:lang_' . $language));
1155 $lang[] = array(
1156 'label' => $label,
1157 'lang' => $language,
1158 'selected' => is_array($selected) && in_array($language, $selected) ? 1 : 0
1159 );
1160 $meta[] = array(
1161 'hidden' => is_array($selected) && in_array($language, $selected) ? 'false' : 'true',
1162 'header' => $language,
1163 'dataIndex' => $language,
1164 'width' => '100',
1165 'fixed' => TRUE,
1166 'sortable' => FALSE,
1167 'hidable' => FALSE,
1168 'menuDisabled' => TRUE,
1169 );
1170 }
1171 return array(
1172 'length' => count($lang),
1173 'data' => $lang,
1174 'meta' => $meta,
1175 );
1176
1177 }
1178
1179 /**
1180 * Saves language selection
1181 *
1182 * @param array $parameter
1183 * @return string
1184 */
1185 public function saveLanguageSelection($parameter) {
1186 $this->globalSettings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['em']);
1187 $selected = t3lib_div::trimExplode(',', $this->globalSettings['selectedLanguages'], TRUE);
1188
1189 $dir = count($parameter) - count($selected);
1190 $diff = $dir < 0 ? array_diff($selected, $parameter) : array_diff($parameter, $selected);
1191 $type = tx_em_Tools::getExtTypeFromPath(t3lib_extMgm::extPath('em'));
1192
1193 $params = array(
1194 'extkey' => 'em',
1195 'exttype' => $type,
1196 'data' => array(
1197 'selectedLanguages' => implode(',', $parameter)
1198 )
1199 );
1200 $this->saveExtensionConfiguration($params);
1201
1202 return array(
1203 'success' => TRUE,
1204 'dir' => $dir,
1205 'diff' => implode('', $diff)
1206 );
1207 }
1208
1209
1210 /**
1211 * Fetches translation from server
1212 *
1213 * @param string $extkey
1214 * @param string $type
1215 * @param array $selection
1216 * @return array
1217 */
1218 public function fetchTranslations($extkey, $type, $selection) {
1219 $result = array();
1220 if (is_array($selection) && count($selection)) {
1221 $terConnection = t3lib_div::makeInstance('tx_em_Connection_Ter', $this);
1222 $this->xmlHandler = t3lib_div::makeInstance('tx_em_Tools_XmlHandler');
1223 $this->xmlHandler->emObj = $this;
1224 $mirrorURL = $this->getSettingsObject()->getMirrorURL();
1225
1226 $infoIcon = '<span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-info">&nbsp;</span>';
1227 $updateIcon = '<span class="t3-icon t3-icon-actions t3-icon-actions-system t3-icon-system-extension-update">&nbsp;</span>';
1228 $newIcon = '<span class="t3-icon t3-icon-actions t3-icon-actions-system t3-icon-system-extension-import">&nbsp;</span>';
1229 $okIcon = '<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-checked">&nbsp;</span>';
1230 $errorIcon = '<span class="t3-icon t3-icon-status t3-icon-status-status t3-icon-status-permission-denied">&nbsp;</span>';
1231
1232 foreach ($selection as $lang) {
1233 $fetch = $terConnection->fetchTranslationStatus($extkey, $mirrorURL);
1234
1235 $localmd5 = '';
1236 if (!isset($fetch[$lang])) {
1237 //no translation available
1238 $result[$lang] = $infoIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:translation_n_a');
1239 } else {
1240 $zip = PATH_site . 'typo3temp/' . $extkey . '-l10n-' . $lang . '.zip';
1241 if (is_file($zip)) {
1242 $localmd5 = md5_file($zip);
1243 }
1244 if ($localmd5 !== $fetch[$lang]['md5']) {
1245 if ($type) {
1246 //fetch translation
1247 $ret = $terConnection->updateTranslation($extkey, $lang, $mirrorURL);
1248
1249 $result[$lang] = $ret
1250 ? $okIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_updated')
1251 : $errorIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:msg_failed');
1252 } else {
1253 //translation status
1254 $result[$lang] = $localmd5 !== ''
1255 ? $updateIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:translation_status_update')
1256 : $newIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:translation_status_new');
1257 }
1258 } else {
1259 //translation is up to date
1260 $result[$lang] = $okIcon . $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:translation_status_uptodate');;
1261 }
1262 }
1263
1264
1265 }
1266 }
1267 return $result;
1268 }
1269
1270
1271 /*********************************************************************/
1272 /* Settings */
1273 /*********************************************************************/
1274
1275 /**
1276 * Returns settings object.
1277 *
1278 * @access public
1279 * @return tx_em_Settings instance of settings object
1280 */
1281 public function getSettings() {
1282 return $this->getSettingsObject()->getSettings();
1283 }
1284
1285 /**
1286 * Enter description here...
1287 *
1288 * @param string $name
1289 * @param mixed $value
1290 * @return boolean
1291 */
1292 public function saveSetting($name, $value) {
1293 $this->getSettingsObject()->saveSetting($name, $value);
1294 return TRUE;
1295 }
1296
1297 /**
1298 * Load form values for settings form
1299 *
1300 * @return array FormValues
1301 */
1302 public function settingsFormLoad() {
1303 $settings = $this->getSettings();
1304
1305 return array(
1306 'success' => TRUE,
1307 'data' => array(
1308 'display_unchecked' => $settings['display_unchecked'],
1309 'fe_u' => $settings['fe_u'],
1310 'fe_p' => $settings['fe_p'],
1311 'selectedMirror' => $settings['selectedMirror'],
1312 'selectedRepository' => $settings['selectedRepository'],
1313 )
1314 );
1315 }
1316
1317 /**
1318 * Save settings from form submit
1319 *
1320 * @formHandler
1321 * @param array $parameter
1322 * @return array
1323 */
1324 public function settingsFormSubmit($parameter) {
1325 $settings = $this->getSettingsObject()->saveSettings(array(
1326 'display_unchecked' => isset($parameter['display_unchecked']),
1327 'fe_u' => $parameter['fe_u'],
1328 'fe_p' => $parameter['fe_p'],
1329 'selectedMirror' => $parameter['selectedMirror'],
1330 'selectedRepository' => $parameter['selectedRepository'],
1331 ));
1332 return array(
1333 'success' => TRUE,
1334 'data' => $parameter,
1335 'settings' => $settings
1336 );
1337 }
1338
1339
1340 /*********************************************************************/
1341 /* EM Tools */
1342 /*********************************************************************/
1343
1344 /**
1345 * Upload an extension
1346 *
1347 * @formHandler
1348 *
1349 * @access public
1350 * @param $parameter composed parameter from $POST and $_FILES
1351 * @return array status
1352 */
1353 public function uploadExtension($parameter) {
1354 $uploadedTempFile = isset($parameter['extfile']) ? $parameter['extfile'] : t3lib_div::upload_to_tempfile($parameter['extupload-path']['tmp_name']);
1355 $location = ($parameter['loc'] === 'G' || $parameter['loc'] === 'S') ? $parameter['loc'] : 'L';
1356 $uploadOverwrite = $parameter['uploadOverwrite'] ? TRUE : FALSE;
1357
1358 $install = t3lib_div::makeInstance('tx_em_Install', $this);
1359 $this->extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this);
1360 $this->extensionDetails = t3lib_div::makeInstance('tx_em_Extensions_Details', $this);
1361
1362 $upload = $install->uploadExtensionFile($uploadedTempFile, $location, $uploadOverwrite);
1363
1364 if ($upload[0] === FALSE) {
1365 return array(
1366 'success' => FALSE,
1367 'error' => $upload[1]
1368 );
1369 }
1370
1371 $extKey = $upload[1][0]['extKey'];
1372 $version = '';
1373 $dontDelete = TRUE;
1374 $result = $install->installExtension($upload[1], $location, $version, $uploadedTempFile, $dontDelete);
1375 return array(
1376 'success' => TRUE,
1377 'data' => $result,
1378 'extKey' => $extKey
1379 );
1380
1381 }
1382
1383 /**
1384 * Enables an extension
1385 *
1386 * @param $extensionKey
1387 * @return void
1388 */
1389 public function enableExtension($extensionKey) {
1390 $this->extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this);
1391 $install = t3lib_div::makeInstance('tx_em_Install', $this);
1392
1393 list($installedList,) = $this->extensionList->getInstalledExtensions();
1394 $newExtensionList = $this->extensionList->addExtToList($extensionKey, $installedList);
1395
1396 $install->writeNewExtensionList($newExtensionList);
1397 tx_em_Tools::refreshGlobalExtList();
1398 $install->forceDBupdates($extensionKey, $installedList[$extensionKey]);
1399 }
1400
1401 /**
1402 * Reset all states for current user
1403 *
1404 * @return void
1405 */
1406 public function resetStates() {
1407 unset($GLOBALS['BE_USER']->uc['moduleData']['tools_em']['States']);
1408 $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc);
1409 return array('success' => TRUE);
1410 }
1411
1412 /**
1413 * Gets the mirror url from selected mirror
1414 *
1415 * @param $repositoryId
1416 * @return string
1417 */
1418 protected function getMirrorUrl($repositoryId) {
1419 $settings = $this->getSettings();
1420 /** @var $objRepository tx_em_Repository */
1421 $objRepository = t3lib_div::makeInstance('tx_em_Repository', $repositoryId);
1422 /** @var $objRepositoryUtility tx_em_Repository_Utility */
1423 $objRepositoryUtility = t3lib_div::makeInstance('tx_em_Repository_Utility', $objRepository);
1424 $mirrors = $objRepositoryUtility->getMirrors(TRUE)->getMirrors();
1425
1426
1427 if ($settings['selectedMirror'] == '') {
1428 $randomMirror = array_rand($mirrors);
1429 $mirrorUrl = $mirrors[$randomMirror]['host'] . $mirrors[$randomMirror]['path'];
1430 } else {
1431 foreach($mirrors as $mirror) {
1432 if ($mirror['host'] == $settings['selectedMirror']) {
1433 $mirrorUrl = $mirror['host'] . $mirror['path'];
1434 break;
1435 }
1436 }
1437 }
1438
1439 return 'http://' . $mirrorUrl;
1440 }
1441
1442 /**
1443 * Resolves the filter settings from repository list and makes a whereClause
1444 *
1445 * @param array $parameter
1446 * @return string additional whereClause
1447 */
1448 protected function makeFilterQuery($parameter) {
1449 $where = '';
1450 $filter = $found = array();
1451
1452 foreach ($parameter as $key => $value) {
1453 if (substr($key, 0, 6) === 'filter') {
1454 eval('$' . $key . ' = \'' . $value . '\';');
1455 }
1456 }
1457
1458
1459 if (count($filter)) {
1460 foreach ($filter as $value) {
1461 switch ($value['data']['type']) {
1462 case 'list':
1463 if ($value['field'] === 'statevalue') {
1464 $where .= ' AND cache_extensions.state IN(' . htmlspecialchars($value['data']['value']) . ')';
1465 }
1466 if ($value['field'] === 'category') {
1467 $where .= ' AND cache_extensions.category IN(' . htmlspecialchars($value['data']['value']) . ')';
1468 }
1469 break;
1470 default:
1471 $quotedSearch = $GLOBALS['TYPO3_DB']->escapeStrForLike(
1472 $GLOBALS['TYPO3_DB']->quoteStr($value['data']['value'], 'cache_extensions'),
1473 'cache_extensions'
1474 );
1475 $where .= ' AND cache_extensions.' . htmlspecialchars($value['field']) . ' LIKE "%' . $quotedSearch . '%"';
1476 }
1477 }
1478 }
1479 return $where;
1480 }
1481
1482 /**
1483 * Replace links that are created with t3lib_div::linkThisScript to point to module
1484 *
1485 * @param string $string
1486 * @return string
1487 */
1488 protected function replaceLinks($string) {
1489 return str_replace(
1490 'ajax.php?ajaxID=ExtDirect%3A%3Aroute&amp;namespace=TYPO3.EM',
1491 'mod.php?M=tools_em',
1492 $string
1493 );
1494 }
1495
1496 /**
1497 * Get the selected repository
1498 *
1499 * @return array
1500 */
1501 protected function getSelectedRepository() {
1502 $settings = $this->getSettings();
1503 $repositories = tx_em_Database::getRepositories();
1504 $selectedRepository = array();
1505
1506 foreach ($repositories as $uid => $repository) {
1507 if ($repository['uid'] == $settings['selectedRepository']) {
1508 $selectedRepository = array(
1509 'title' => $repository['title'],
1510 'uid' => $repository['uid'],
1511 'description' => $repository['description'],
1512 'wsdl_url' => $repository['wsdl_url'],
1513 'mirror_url' => $repository['mirror_url'],
1514 'count' => $repository['extCount'],
1515 'updated' => $repository['lastUpdated'] ? date('d/m/Y H:i', $repository['lastUpdated']) : 'never',
1516 'selected' => $repository['uid'] === $settings['selectedRepository'],
1517 );
1518 }
1519 }
1520
1521 return $selectedRepository;
1522 }
1523
1524 /**
1525 * Gets file info for ExtJs tree node
1526 *
1527 * @param $file
1528 * @return array
1529 */
1530 protected function getFileInfo($file) {
1531 $unknownType = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_file_unknownType');
1532 $imageType = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_file_imageType');
1533 $textType = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_file_textType');
1534 $extType = $GLOBALS['LANG']->sL('LLL:EXT:em/language/locallang.xml:ext_details_file_extType');
1535
1536 $editTypes = explode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext']);
1537 $imageTypes = array('gif', 'jpg', 'png');
1538
1539 $fileExt = '';
1540 $type = '';
1541 $cls = t3lib_iconWorks::mapFileExtensionToSpriteIconClass('');
1542 if (strrpos($file, '.') !== FALSE) {
1543 $fileExt = strtolower(substr($file, strrpos($file, '.') + 1));
1544 }
1545
1546 if ($fileExt && in_array($fileExt, $imageTypes) || in_array($fileExt, $editTypes)) {
1547 $cls = t3lib_iconWorks::mapFileExtensionToSpriteIconClass($fileExt);
1548 $type = in_array($fileExt, $imageTypes) ? 'image' : 'text';
1549 }
1550
1551 if (t3lib_div::strtolower($file) === 'changelog') {
1552 $cls = t3lib_iconWorks::mapFileExtensionToSpriteIconClass('txt');
1553 $type = 'text';
1554 }
1555
1556 switch($type) {
1557 CASE 'image':
1558 $label = $imageType;
1559 break;
1560 CASE 'text':
1561 $label = $textType;
1562 break;
1563 default:
1564 $label = $fileExt ? sprintf($extType, $fileExt) : $unknownType;
1565 }
1566
1567 return array(
1568 htmlspecialchars($file),
1569 $label,
1570 htmlspecialchars($fileExt),
1571 $type,
1572 $cls
1573 );
1574
1575 }
1576
1577
1578 /**
1579 * File operations like delete, copy, move
1580 * @param $file commandMap, @see
1581 * @return
1582 */
1583 protected function fileOperation($file) {
1584 $mount = array(0 => array(
1585 'name' => 'root',
1586 'path' => PATH_site,
1587 'type' => ''
1588 ));
1589 $files = array(0 => array(
1590 'webspace' => array('allow' => '*', 'deny' => ''),
1591 'ftpspace' => array('allow' => '*', 'deny' => '')
1592 ));
1593 $fileProcessor = t3lib_div::makeInstance('t3lib_extFileFunctions');
1594 $fileProcessor->init($mount, $files);
1595 $fileProcessor->init_actionPerms($GLOBALS['BE_USER']->getFileoperationPermissions());
1596 $fileProcessor->dontCheckForUnique = 0;
1597
1598 // Checking referer / executing:
1599 $refInfo = parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
1600 $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');
1601 if ($httpHost != $refInfo['host']
1602 && $this->vC != $GLOBALS['BE_USER']->veriCode()
1603 && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']
1604 && $GLOBALS['CLIENT']['BROWSER'] != 'flash') {
1605 $fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost));
1606 } else {
1607 $fileProcessor->start($file);
1608 $fileData = $fileProcessor->processData();
1609 }
1610
1611 return $fileData;
1612 }
1613
1614 }
1615
1616 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/connection/class.tx_em_connectionextdirectserver.php'])) {
1617 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/connection/class.tx_em_connection_extdirectserver.php']);
1618 }
1619
1620 ?>