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