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