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