Fixed bug #3069: Extension manager crashed because of some PHP bug with version_compa...
[Packages/TYPO3.CMS.git] / typo3 / mod / tools / em / class.em_index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * (c) 2005-2006 Karsten Dambekalns <karsten@typo3.org>
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
19 *
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28 /**
29 * Module: Extension manager
30 *
31 * $Id$
32 *
33 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
34 * @author Karsten Dambekalns <karsten@typo3.org>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 194: class SC_mod_tools_em_index extends t3lib_SCbase
42 *
43 * SECTION: Standard module initialization
44 * 337: function init()
45 * 417: function handleExternalFunctionValue($MM_key='function', $MS_value=NULL)
46 * 431: function menuConfig()
47 * 508: function main()
48 * 584: function printContent()
49 *
50 * SECTION: Function Menu Applications
51 * 609: function extensionList_loaded()
52 * 664: function extensionList_installed()
53 * 736: function extensionList_import()
54 * 903: function alterSettings()
55 *
56 * SECTION: Command Applications (triggered by GET var)
57 * 1005: function importExtInfo($extKey, $version='')
58 * 1062: function fetchMetaData($metaType)
59 * 1125: function getMirrorURL()
60 * 1158: function installExtension($extKey, $version=null, $mode=EM_INSTALL_VERSION_MIN)
61 * 1279: function importExtFromRep($extKey,$version,$loc,$uploadFlag=0,$dontDelete=0,$directInput='')
62 * 1425: function showExtDetails($extKey)
63 *
64 * SECTION: Application Sub-functions (HTML parts)
65 * 1737: function updatesForm($extKey,$extInfo,$notSilent=0,$script='',$addFields='')
66 * 1768: function extDumpTables($extKey,$extInfo)
67 * 1835: function getFileListOfExtension($extKey,$conf)
68 * 1889: function extDelete($extKey,$extInfo)
69 * 1920: function extUpdateEMCONF($extKey,$extInfo)
70 * 1940: function extBackup($extKey,$extInfo)
71 * 1987: function extBackup_dumpDataTablesLine($tablesArray,$extKey)
72 * 2015: function extInformationArray($extKey,$extInfo,$remote=0)
73 * 2097: function extInformationArray_dbReq($techInfo,$tableHeader=0)
74 * 2110: function extInformationArray_dbInst($dbInst,$current)
75 * 2129: function getRepositoryUploadForm($extKey,$extInfo)
76 *
77 * SECTION: Extension list rendering
78 * 2190: function extensionListRowHeader($trAttrib,$cells,$import=0)
79 * 2251: function extensionListRow($extKey,$extInfo,$cells,$bgColorClass='',$inst_list=array(),$import=0,$altLinkUrl='')
80 *
81 * SECTION: Output helper functions
82 * 2367: function wrapEmail($str,$email)
83 * 2380: function helpCol($key)
84 * 2396: function labelInfo($str)
85 * 2408: function extensionTitleIconHeader($extKey,$extInfo,$align='top')
86 * 2423: function removeButton()
87 * 2432: function installButton()
88 * 2441: function noImportMsg()
89 * 2454: function depToString($dep,$type='depends')
90 * 2473: function stringToDep($dep)
91 *
92 * SECTION: Read information about all available extensions
93 * 2503: function getInstalledExtensions()
94 * 2530: function getInstExtList($path,&$list,&$cat,$type)
95 * 2561: function fixEMCONF($emConf)
96 * 2600: function splitVersionRange($ver)
97 * 2616: function prepareImportExtList()
98 * 2660: function setCat(&$cat,$listArrayPart,$extKey)
99 *
100 * SECTION: Extension analyzing (detailed information)
101 * 2710: function makeDetailedExtensionAnalysis($extKey,$extInfo,$validity=0)
102 * 2892: function getClassIndexLocallangFiles($absPath,$table_class_prefix,$extKey)
103 * 2962: function modConfFileAnalysis($confFilePath)
104 * 2990: function serverExtensionMD5Array($extKey,$conf)
105 * 3015: function findMD5ArrayDiff($current,$past)
106 *
107 * SECTION: File system operations
108 * 3047: function createDirsInPath($dirs,$extDirPath)
109 * 3065: function removeExtDirectory($removePath,$removeContentOnly=0)
110 * 3128: function clearAndMakeExtensionDir($importedData,$type,$dontDelete=0)
111 * 3182: function removeCacheFiles()
112 * 3192: function extractDirsFromFileList($files)
113 * 3218: function getExtPath($extKey,$type)
114 *
115 * SECTION: Writing to "conf.php" and "localconf.php" files
116 * 3252: function writeTYPO3_MOD_PATH($confFilePath,$type,$mP)
117 * 3289: function writeNewExtensionList($newExtList)
118 * 3312: function writeTsStyleConfig($extKey,$arr)
119 * 3334: function updateLocalEM_CONF($extKey,$extInfo)
120 *
121 * SECTION: Compiling upload information, emconf-file etc.
122 * 3376: function construct_ext_emconf_file($extKey,$EM_CONF)
123 * 3407: function arrayToCode($array, $level=0)
124 * 3433: function makeUploadArray($extKey,$conf)
125 * 3502: function getSerializedLocalLang($file,$content)
126 *
127 * SECTION: Managing dependencies, conflicts, priorities, load order of extension keys
128 * 3538: function addExtToList($extKey,$instExtInfo)
129 * 3569: function checkDependencies($extKey, $conf, $instExtInfo)
130 * 3709: function removeExtFromList($extKey,$instExtInfo)
131 * 3746: function removeRequiredExtFromListArr($listArr)
132 * 3761: function managesPriorities($listArr,$instExtInfo)
133 *
134 * SECTION: System Update functions (based on extension requirements)
135 * 3813: function checkClearCache($extInfo)
136 * 3840: function checkUploadFolder($extKey,$extInfo)
137 * 3925: function checkDBupdates($extKey,$extInfo,$infoOnly=0)
138 * 4022: function forceDBupdates($extKey, $extInfo)
139 * 4080: function tsStyleConfigForm($extKey,$extInfo,$output=0,$script='',$addFields='')
140 *
141 * SECTION: Dumping database (MySQL compliant)
142 * 4175: function dumpTableAndFieldStructure($arr)
143 * 4200: function dumpStaticTables($tableList)
144 * 4229: function dumpHeader()
145 * 4246: function dumpTableHeader($table,$fieldKeyInfo,$dropTableIfExists=0)
146 * 4288: function dumpTableContent($table,$fieldStructure)
147 * 4323: function getTableAndFieldStructure($parts)
148 *
149 * SECTION: TER Communication functions
150 * 4373: function uploadExtensionToTER($em)
151 *
152 * SECTION: Various helper functions
153 * 4411: function listOrderTitle($listOrder,$key)
154 * 4436: function makeVersion($v,$mode)
155 * 4448: function renderVersion($v,$raise='')
156 * 4485: function ulFolder($extKey)
157 * 4494: function importAtAll()
158 * 4505: function importAsType($type,$lockType='')
159 * 4527: function deleteAsType($type)
160 * 4548: function versionDifference($v1,$v2,$div=1)
161 * 4560: function first_in_array($str,$array,$caseInsensitive=FALSE)
162 * 4578: function includeEMCONF($path,$_EXTKEY)
163 * 4593: function searchExtension($extKey,$row)
164 *
165 * TOTAL FUNCTIONS: 90
166 * (This index is automatically created/updated by the extension "extdeveval")
167 *
168 */
169
170 // Include classes needed:
171 require_once(PATH_t3lib.'class.t3lib_tcemain.php');
172 require_once(PATH_t3lib.'class.t3lib_install.php');
173 require_once(PATH_t3lib.'class.t3lib_tsstyleconfig.php');
174 require_once(PATH_t3lib.'class.t3lib_scbase.php');
175
176 require_once('class.em_xmlhandler.php');
177 require_once('class.em_terconnection.php');
178 require_once('class.em_unzip.php');
179
180 // from tx_ter by Robert Lemke
181 define('TX_TER_RESULT_EXTENSIONSUCCESSFULLYUPLOADED', '10504');
182
183 define('EM_INSTALL_VERSION_MIN', 1);
184 define('EM_INSTALL_VERSION_MAX', 2);
185 define('EM_INSTALL_VERSION_STRICT', 3);
186
187 /**
188 * Module: Extension manager
189 *
190 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
191 * @author Karsten Dambekalns <karsten@typo3.org>
192 * @package TYPO3
193 * @subpackage core
194 */
195 class SC_mod_tools_em_index extends t3lib_SCbase {
196
197 // Internal, static:
198 var $versionDiffFactor = 1; // This means that version difference testing for import is detected for sub-versions only, not dev-versions. Default: 1000
199 var $systemInstall = 0; // If "1" then installs in the sysext directory is allowed. Default: 0
200 var $requiredExt = ''; // List of required extension (from TYPO3_CONF_VARS)
201 var $maxUploadSize = 31457280; // Max size in bytes of extension upload to repository
202 var $kbMax = 500; // Max size in kilobytes for files to be edited.
203 var $doPrintContent = true; // If set (default), the function printContent() will echo the content which was collected in $this->content. You can set this to FALSE in order to echo content from elsewhere, fx. when using outbut buffering
204 var $listingLimit = 500; // List that many extension maximally at one time (fixing memory problems)
205 var $listingLimitAuthor = 250; // List that many extension maximally at one time (fixing memory problems)
206
207 /**
208 * Internal variable loaded with extension categories (for display/listing). Should reflect $categories above
209 * Dynamic var.
210 */
211 var $defaultCategories = Array(
212 'cat' => Array (
213 'be' => array(),
214 'module' => array(),
215 'fe' => array(),
216 'plugin' => array(),
217 'misc' => array(),
218 'services' => array(),
219 'templates' => array(),
220 'example' => array(),
221 'doc' => array()
222 )
223 );
224
225 /**
226 * Extension Categories (static var)
227 * Content must be redundant with the same internal variable as in class.tx_extrep.php!
228 */
229 var $categories = Array(
230 'be' => 'Backend',
231 'module' => 'Backend Modules',
232 'fe' => 'Frontend',
233 'plugin' => 'Frontend Plugins',
234 'misc' => 'Miscellaneous',
235 'services' => 'Services',
236 'templates' => 'Templates',
237 'example' => 'Examples',
238 'doc' => 'Documentation'
239 );
240
241 /**
242 * Extension States
243 * Content must be redundant with the same internal variable as in class.tx_extrep.php!
244 */
245 var $states = Array (
246 'alpha' => 'Alpha',
247 'beta' => 'Beta',
248 'stable' => 'Stable',
249 'experimental' => 'Experimental',
250 'test' => 'Test',
251 'obsolete' => 'Obsolete',
252 );
253
254 /**
255 * Colors for extension states
256 */
257 var $stateColors = Array (
258 'alpha' => '#d12438',
259 'beta' => '#97b17e',
260 'stable' => '#3bb65c',
261 'experimental' => '#007eba',
262 'test' => '#979797',
263 'obsolete' => '#000000',
264 );
265
266 /**
267 * "TYPE" information; labels, paths, description etc.
268 */
269 var $typeLabels = Array (
270 'S' => 'System',
271 'G' => 'Global',
272 'L' => 'Local',
273 );
274 var $typeDescr = Array (
275 'S' => 'System extension (typo3/sysext/) - Always distributed with source code (Static).',
276 'G' => 'Global extensions (typo3/ext/) - Available for shared source on server (Dynamic).',
277 'L' => 'Local extensions (typo3conf/ext/) - Local for this TYPO3 installation only (Dynamic).',
278 );
279 var $typePaths = Array(); // Also static, set in init()
280 var $typeBackPaths = Array(); // Also static, set in init()
281
282 var $typeRelPaths = Array (
283 'S' => 'sysext/',
284 'G' => 'ext/',
285 'L' => '../typo3conf/ext/',
286 );
287
288 var $detailCols = Array (
289 0 => 2,
290 1 => 5,
291 2 => 6,
292 3 => 6,
293 4 => 4,
294 5 => 1
295 );
296
297 var $fe_user = array(
298 'username' => '',
299 'password' => '',
300 );
301
302 var $privacyNotice = 'When you interact with the online repository, server information may be sent and stored in the repository for statistics.';
303 var $securityHint = '<strong>Found a security problem? Please get in touch with us!</strong><br />If you think you have found a security issue in TYPO3 or an extension, please contact the <a href="http://typo3.org/teams/security/" target="_blank">TYPO3 security team</a>! Thank you!';
304 var $editTextExtensions = 'html,htm,txt,css,tmpl,inc,php,sql,conf,cnf,pl,pm,sh,xml,ChangeLog';
305 var $nameSpaceExceptions = 'beuser_tracking,design_components,impexp,static_file_edit,cms,freesite,quickhelp,classic_welcome,indexed_search,sys_action,sys_workflows,sys_todos,sys_messages,direct_mail,sys_stat,tt_address,tt_board,tt_calender,tt_guest,tt_links,tt_news,tt_poll,tt_rating,tt_products,setup,taskcenter,tsconfig_help,context_help,sys_note,tstemplate,lowlevel,install,belog,beuser,phpmyadmin,aboutmodules,imagelist,setup,taskcenter,sys_notepad,viewpage,adodb';
306
307
308
309
310
311 // Default variables for backend modules
312 var $MCONF = array(); // Module configuration
313 var $MOD_MENU = array(); // Module menu items
314 var $MOD_SETTINGS = array(); // Module session settings
315 var $doc; // Document Template Object
316 var $content; // Accumulated content
317
318 var $inst_keys = array(); // Storage of installed extensions
319 var $gzcompress = 0; // Is set true, if system support compression.
320
321 var $terConnection; // instance of TER connection handler
322
323 // GPvars:
324 var $CMD = array(); // CMD array
325 var $listRemote; // If set, connects to remote repository
326 var $lookUpStr; // Search string when listing local extensions
327
328
329
330
331 /*********************************
332 *
333 * Standard module initialization
334 *
335 *********************************/
336
337 /**
338 * Standard init function of a module.
339 *
340 * @return void
341 */
342 function init() {
343 global $BE_USER,$LANG,$BACK_PATH,$TYPO3_CONF_VARS;
344
345 // Setting paths of install scopes:
346 $this->typePaths = Array (
347 'S' => TYPO3_mainDir.'sysext/',
348 'G' => TYPO3_mainDir.'ext/',
349 'L' => 'typo3conf/ext/'
350 );
351 $this->typeBackPaths = Array (
352 'S' => '../../../',
353 'G' => '../../../',
354 'L' => '../../../../'.TYPO3_mainDir
355 );
356
357 $this->excludeForPackaging = $GLOBALS['TYPO3_CONF_VARS']['EXT']['excludeForPackaging'];
358
359 // Setting module configuration:
360 $this->MCONF = $GLOBALS['MCONF'];
361
362 // Setting GPvars:
363 $this->CMD = t3lib_div::_GP('CMD');
364 $this->lookUpStr = trim(t3lib_div::_GP('_lookUp'));
365 $this->listRemote = t3lib_div::_GP('ter_connect');
366 $this->listRemote_search = trim(t3lib_div::_GP('ter_search'));
367
368
369 // Configure menu
370 $this->menuConfig();
371
372 // Setting internal static:
373 if ($TYPO3_CONF_VARS['EXT']['allowSystemInstall']) $this->systemInstall = 1;
374 $this->requiredExt = t3lib_div::trimExplode(',',$TYPO3_CONF_VARS['EXT']['requiredExt'],1);
375
376
377 // Initialize helper object
378 $this->terConnection = t3lib_div::makeInstance('SC_mod_tools_em_terconnection');
379 $this->terConnection->emObj =& $this;
380 $this->terConnection->wsdlURL = $TYPO3_CONF_VARS['EXT']['em_wsdlURL'];
381 $this->xmlhandler = t3lib_div::makeInstance('SC_mod_tools_em_xmlhandler');
382 $this->xmlhandler->emObj =& $this;
383 $this->xmlhandler->useUnchecked = $this->MOD_SETTINGS['display_unchecked'];
384 $this->xmlhandler->useObsolete = $this->MOD_SETTINGS['display_obsolete'];
385
386 // Initialize Document Template object:
387 $this->doc = t3lib_div::makeInstance('noDoc');
388 $this->doc->backPath = $BACK_PATH;
389 $this->doc->docType = 'xhtml_trans';
390
391 // JavaScript
392 $this->doc->JScode = $this->doc->wrapScriptTags('
393 script_ended = 0;
394 function jumpToUrl(URL) { //
395 window.location.href = URL;
396 }
397 ');
398 $this->doc->form = '<form action="index.php" method="post" name="pageform">';
399
400 // Descriptions:
401 $this->descrTable = '_MOD_'.$this->MCONF['name'];
402 if ($BE_USER->uc['edit_showFieldHelp']) {
403 $LANG->loadSingleTableDescription($this->descrTable);
404 }
405
406 // Setting username/password etc. for upload-user:
407 $this->fe_user['username'] = $this->MOD_SETTINGS['fe_u'];
408 $this->fe_user['password'] = $this->MOD_SETTINGS['fe_p'];
409 parent::init();
410 $this->handleExternalFunctionValue('singleDetails');
411 }
412
413 /**
414 * This function is a copy of the same function in t3lib_SCbase with one modification:
415 * In contrast to t3lib_SCbase::handleExternalFunctionValue() this function merges the $this->extClassConf array
416 * instead of overwriting it. That was necessary for including the Kickstarter as a submodule into the 'singleDetails'
417 * selectorbox as well as in the main 'function' selectorbox.
418 *
419 * @param string Mod-setting array key
420 * @param string Mod setting value, overriding the one in the key
421 * @return void
422 * @see t3lib_SCbase::handleExternalFunctionValue()
423 */
424 function handleExternalFunctionValue($MM_key='function', $MS_value=NULL) {
425 $MS_value = is_null($MS_value) ? $this->MOD_SETTINGS[$MM_key] : $MS_value;
426 $externalItems = $this->getExternalItemConfig($this->MCONF['name'],$MM_key,$MS_value);
427 if (is_array($externalItems)) $this->extClassConf = array_merge($externalItems,is_array($this->extClassConf)?$this->extClassConf:array());
428 if (is_array($this->extClassConf) && $this->extClassConf['path']) {
429 $this->include_once[]=$this->extClassConf['path'];
430 }
431 }
432
433 /**
434 * Configuration of which mod-menu items can be used
435 *
436 * @return void
437 */
438 function menuConfig() {
439 global $BE_USER, $TYPO3_CONF_VARS;
440
441 // MENU-ITEMS:
442 $this->MOD_MENU = array(
443 'function' => array(
444 0 => 'Loaded extensions',
445 1 => 'Install extensions',
446 2 => 'Import extensions',
447 4 => 'Translation handling',
448 3 => 'Settings',
449 ),
450 'listOrder' => array(
451 'cat' => 'Category',
452 'author_company' => 'Author',
453 'state' => 'State',
454 'type' => 'Type'
455 ),
456 'display_details' => array(
457 1 => 'Details',
458 0 => 'Description',
459 2 => 'More details',
460
461 3 => 'Technical (takes time!)',
462 4 => 'Validating (takes time!)',
463 5 => 'Changed? (takes time!)',
464 ),
465 'display_shy' => '',
466 'display_own' => '',
467 'display_unchecked' => '',
468 'display_obsolete' => '',
469
470 'singleDetails' => array(
471 'info' => 'Information',
472 'edit' => 'Edit files',
473 'backup' => 'Backup/Delete',
474 'dump' => 'Dump DB',
475 'upload' => 'Upload to TER',
476 'updateModule' => 'UPDATE!',
477 ),
478 'fe_u' => '',
479 'fe_p' => '',
480
481 'mirrorListURL' => '',
482 'rep_url' => '',
483 'extMirrors' => '',
484 'selectedMirror' => '',
485
486 'selectedLanguages' => ''
487 );
488
489 $this->MOD_MENU['singleDetails'] = $this->mergeExternalItems($this->MCONF['name'],'singleDetails',$this->MOD_MENU['singleDetails']);
490
491 // page/be_user TSconfig settings and blinding of menu-items
492 if (!$BE_USER->getTSConfigVal('mod.'.$this->MCONF['name'].'.allowTVlisting')) {
493 unset($this->MOD_MENU['display_details'][3]);
494 unset($this->MOD_MENU['display_details'][4]);
495 unset($this->MOD_MENU['display_details'][5]);
496 }
497
498 // CLEANSE SETTINGS
499 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
500
501 if ($this->MOD_SETTINGS['function']==2) {
502 // If listing from online repository, certain items are removed though:
503 unset($this->MOD_MENU['listOrder']['type']);
504 unset($this->MOD_MENU['display_details'][2]);
505 unset($this->MOD_MENU['display_details'][3]);
506 unset($this->MOD_MENU['display_details'][4]);
507 unset($this->MOD_MENU['display_details'][5]);
508 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
509 }
510 parent::menuConfig();
511 }
512
513 /**
514 * Main function for Extension Manager module.
515 *
516 * @return void
517 */
518 function main() {
519 global $BE_USER,$LANG,$TYPO3_CONF_VARS;
520
521 if (empty($this->MOD_SETTINGS['mirrorListURL'])) $this->MOD_SETTINGS['mirrorListURL'] = $TYPO3_CONF_VARS['EXT']['em_mirrorListURL'];
522
523 // Starting page:
524 $this->content.=$this->doc->startPage('Extension Manager');
525 $this->content.=$this->doc->header('Extension Manager');
526 $this->content.=$this->doc->spacer(5);
527
528 // Commands given which is executed regardless of main menu setting:
529 if ($this->CMD['showExt']) { // Show details for a single extension
530 $this->showExtDetails($this->CMD['showExt']);
531 } elseif ($this->CMD['requestInstallExtensions']) { // Show details for a single extension
532 $this->requestInstallExtensions($this->CMD['requestInstallExtensions']);
533 } elseif ($this->CMD['importExt'] || $this->CMD['uploadExt']) { // Imports an extension from online rep.
534 $err = $this->importExtFromRep($this->CMD['importExt'],$this->CMD['extVersion'],$this->CMD['loc'],$this->CMD['uploadExt']);
535 if ($err) {
536 $this->content.=$this->doc->section('',$GLOBALS['TBE_TEMPLATE']->rfw($err));
537 }
538 if(!$err && $this->CMD['importExt']) {
539 $this->installTranslationsForExtension($this->CMD['importExt'], $this->getMirrorURL());
540 }
541 } elseif ($this->CMD['importExtInfo']) { // Gets detailed information of an extension from online rep.
542 $this->importExtInfo($this->CMD['importExtInfo'],$this->CMD['extVersion']);
543 } else { // No command - we show what the menu setting tells us:
544
545 $menu = $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.menu').' '.
546 t3lib_BEfunc::getFuncMenu(0,'SET[function]',$this->MOD_SETTINGS['function'],$this->MOD_MENU['function']);
547
548 if (t3lib_div::inList('0,1,2',$this->MOD_SETTINGS['function'])) {
549 $menu.='&nbsp;Group by:&nbsp;'.t3lib_BEfunc::getFuncMenu(0,'SET[listOrder]',$this->MOD_SETTINGS['listOrder'],$this->MOD_MENU['listOrder']).
550 '&nbsp;&nbsp;Show:&nbsp;'.t3lib_BEfunc::getFuncMenu(0,'SET[display_details]',$this->MOD_SETTINGS['display_details'],$this->MOD_MENU['display_details']).'<br />';
551 }
552 if (t3lib_div::inList('0,1',$this->MOD_SETTINGS['function'])) {
553 $menu.='Display shy extensions:&nbsp;&nbsp;'.t3lib_BEfunc::getFuncCheck(0,'SET[display_shy]',$this->MOD_SETTINGS['display_shy']);
554 }
555 if (t3lib_div::inList('2',$this->MOD_SETTINGS['function']) && strlen($this->fe_user['username'])) {
556 $menu.='Only my extensions:&nbsp;&nbsp;'.t3lib_BEfunc::getFuncCheck(0,'SET[display_own]',$this->MOD_SETTINGS['display_own']);
557 }
558 if (t3lib_div::inList('0,1,2',$this->MOD_SETTINGS['function'])) {
559 $menu.='&nbsp;&nbsp;Show obsolete:&nbsp;&nbsp;'.t3lib_BEfunc::getFuncCheck(0,'SET[display_obsolete]',$this->MOD_SETTINGS['display_obsolete']);
560 }
561
562 $this->content.=$this->doc->section('','<span class="nobr">'.$menu.'</span>');
563 $this->content.=$this->doc->spacer(10);
564
565 switch((string)$this->MOD_SETTINGS['function']) {
566 case '0':
567 // Lists loaded (installed) extensions
568 $this->extensionList_loaded();
569 break;
570 case '1':
571 // Lists the installed (available) extensions
572 $this->extensionList_installed();
573 break;
574 case '2':
575 // Lists the extensions available from online rep.
576 $this->extensionList_import();
577 break;
578 case '3':
579 // Shows the settings screen
580 $this->alterSettings();
581 break;
582 case '4':
583 // Allows to set the translation preferences and check the status
584 $this->translationHandling();
585 break;
586 default:
587 $this->extObjContent();
588 break;
589 }
590 }
591
592 // Shortcuts:
593 if ($BE_USER->mayMakeShortcut()) {
594 $this->content.=$this->doc->spacer(20).$this->doc->section('',$this->doc->makeShortcutIcon('CMD','function',$this->MCONF['name']));
595 }
596 }
597
598 /**
599 * Print module content. Called as last thing in the global scope.
600 *
601 * @return void
602 */
603 function printContent() {
604 if ($this->doPrintContent) {
605 $this->content.= $this->doc->endPage();
606 echo $this->content;
607 }
608 }
609
610
611
612
613
614
615
616
617
618
619 /*********************************
620 *
621 * Function Menu Applications
622 *
623 *********************************/
624
625 /**
626 * Listing of loaded (installed) extensions
627 *
628 * @return void
629 */
630 function extensionList_loaded() {
631 global $TYPO3_LOADED_EXT;
632
633 list($list,$cat) = $this->getInstalledExtensions();
634
635 // Loaded extensions
636 $content = '';
637 $lines = array();
638
639 // Available extensions
640 if (is_array($cat[$this->MOD_SETTINGS['listOrder']])) {
641 $content='';
642 $lines=array();
643 $lines[] = $this->extensionListRowHeader(' class="bgColor5"',array('<td><img src="clear.gif" width="1" height="1" alt="" /></td>'));
644
645 foreach($cat[$this->MOD_SETTINGS['listOrder']] as $catName => $extEkeys) {
646 natcasesort($extEkeys);
647 reset($extEkeys);
648 $extensions = array();
649 while(list($extKey)=each($extEkeys)) {
650 if (array_key_exists($extKey,$TYPO3_LOADED_EXT) && ($this->MOD_SETTINGS['display_shy'] || !$list[$extKey]['EM_CONF']['shy']) && $this->searchExtension($extKey,$list[$extKey])) {
651 if (in_array($extKey, $this->requiredExt)) {
652 $loadUnloadLink = '<strong>'.$GLOBALS['TBE_TEMPLATE']->rfw('Rq').'</strong>';
653 } else {
654 $loadUnloadLink = '<a href="'.htmlspecialchars('index.php?CMD[showExt]='.$extKey.'&CMD[remove]=1').'">'.$this->removeButton().'</a>';
655 }
656
657 $extensions[] = $this->extensionListRow($extKey,$list[$extKey],array('<td class="bgColor">'.$loadUnloadLink.'</td>'));
658 }
659 }
660 if(count($extensions)) {
661 $lines[]='<tr><td colspan="'.(3+$this->detailCols[$this->MOD_SETTINGS['display_details']]).'"><br /></td></tr>';
662 $lines[]='<tr><td colspan="'.(3+$this->detailCols[$this->MOD_SETTINGS['display_details']]).'"><img src="'.$GLOBALS['BACK_PATH'].'gfx/i/sysf.gif" width="18" height="16" align="top" alt="" /><strong>'.$this->listOrderTitle($this->MOD_SETTINGS['listOrder'],$catName).'</strong></td></tr>';
663 $lines[] = implode(chr(10),$extensions);
664 }
665 }
666 }
667
668 $content.= t3lib_BEfunc::cshItem('_MOD_tools_em', 'loaded', $GLOBALS['BACK_PATH'],'');
669
670 $content.= 'Look up: <input type="text" name="_lookUp" value="'.htmlspecialchars($this->lookUpStr).'" /><input type="submit" value="Search"/><br/><br/>';
671
672 $content.= '
673
674 <!-- Loaded Extensions List -->
675 <table border="0" cellpadding="2" cellspacing="1">'.implode('',$lines).'</table>';
676
677 $this->content.=$this->doc->section('Loaded Extensions',$content,0,1);
678 }
679
680 /**
681 * Listing of available (installed) extensions
682 *
683 * @return void
684 */
685 function extensionList_installed() {
686 global $TYPO3_LOADED_EXT;
687
688 list($list,$cat)=$this->getInstalledExtensions();
689
690 // Available extensions
691 if (is_array($cat[$this->MOD_SETTINGS['listOrder']])) {
692 $content='';
693 $lines=array();
694 $lines[]=$this->extensionListRowHeader(' class="bgColor5"',array('<td><img src="clear.gif" width="18" height="1" alt="" /></td>'));
695
696 $allKeys=array();
697 foreach($cat[$this->MOD_SETTINGS['listOrder']] as $catName => $extEkeys) {
698 if(!$this->MOD_SETTINGS['display_obsolete'] && $catName=='obsolete') continue;
699
700 $allKeys[]='';
701 $allKeys[]='TYPE: '.$catName;
702
703 natcasesort($extEkeys);
704 reset($extEkeys);
705 $extensions = array();
706 while(list($extKey)=each($extEkeys)) {
707 $allKeys[]=$extKey;
708 if ((!$list[$extKey]['EM_CONF']['shy'] || $this->MOD_SETTINGS['display_shy']) &&
709 ($list[$extKey]['EM_CONF']['state']!='obsolete' || $this->MOD_SETTINGS['display_obsolete'])
710 && $this->searchExtension($extKey,$list[$extKey])) {
711 $loadUnloadLink = t3lib_extMgm::isLoaded($extKey)?
712 '<a href="'.htmlspecialchars('index.php?CMD[showExt]='.$extKey.'&CMD[remove]=1&CMD[clrCmd]=1&SET[singleDetails]=info').'">'.$this->removeButton().'</a>':
713 '<a href="'.htmlspecialchars('index.php?CMD[showExt]='.$extKey.'&CMD[load]=1&CMD[clrCmd]=1&SET[singleDetails]=info').'">'.$this->installButton().'</a>';
714 if (in_array($extKey,$this->requiredExt)) {
715 $loadUnloadLink='<strong>'.$GLOBALS['TBE_TEMPLATE']->rfw('Rq').'</strong>';
716 }
717 $theRowClass = t3lib_extMgm::isLoaded($extKey)? 'em-listbg1' : 'em-listbg2';
718 $extensions[]=$this->extensionListRow($extKey,$list[$extKey],array('<td class="bgColor">'.$loadUnloadLink.'</td>'),$theRowClass);
719 }
720 }
721 if(count($extensions)) {
722 $lines[]='<tr><td colspan="'.(3+$this->detailCols[$this->MOD_SETTINGS['display_details']]).'"><br /></td></tr>';
723 $lines[]='<tr><td colspan="'.(3+$this->detailCols[$this->MOD_SETTINGS['display_details']]).'"><img src="'.$GLOBALS['BACK_PATH'].'gfx/i/sysf.gif" width="18" height="16" align="top" alt="" /><strong>'.$this->listOrderTitle($this->MOD_SETTINGS['listOrder'],$catName).'</strong></td></tr>';
724 $lines[] = implode(chr(10),$extensions);
725 }
726 }
727
728 $content.='
729
730
731 <!--
732 EXTENSION KEYS:
733
734 '.trim(implode(chr(10),$allKeys)).'
735
736 -->
737
738 ';
739
740 $content.= t3lib_BEfunc::cshItem('_MOD_tools_em', 'avail', $GLOBALS['BACK_PATH'],'|<br/>');
741 $content.= 'If you want to use an extension in TYPO3, you should simply click the "plus" button '.$this->installButton().' . <br />
742 Installed extensions can also be removed again - just click the remove button '.$this->removeButton().' .<br /><br />';
743
744 $content.= 'Look up: <input type="text" name="_lookUp" value="'.htmlspecialchars($this->lookUpStr).'" /><input type="submit" value="Search"/><br/><br/>';
745 $content.= $this->securityHint.'<br /><br />';
746
747 $content.= '<table border="0" cellpadding="2" cellspacing="1">'.implode('',$lines).'</table>';
748
749 $this->content.=$this->doc->section('Available Extensions - Grouped by: '.$this->MOD_MENU['listOrder'][$this->MOD_SETTINGS['listOrder']],$content,0,1);
750 }
751 }
752
753 /**
754 * Listing remote extensions from online repository
755 *
756 * @return void
757 */
758 function extensionList_import() {
759 global $TYPO3_LOADED_EXT;
760 $content='';
761
762 // Listing from online repository:
763 if ($this->listRemote) {
764 list($inst_list,) = $this->getInstalledExtensions();
765 $this->inst_keys = array_flip(array_keys($inst_list));
766
767 $this->detailCols[1]+=6;
768
769 // see if we have an extensionlist at all
770 $this->extensionCount = $this->xmlhandler->countExtensions();
771 if (!$this->extensionCount) {
772 $content .= $this->fetchMetaData('extensions');
773 }
774
775 if($this->MOD_SETTINGS['listOrder']=='author_company') {
776 $this->listingLimit = $this->listingLimitAuthor;
777 }
778
779 $this->pointer = intval(t3lib_div::_GP('pointer'));
780 $offset = $this->listingLimit*$this->pointer;
781
782 if($this->MOD_SETTINGS['display_own'] && strlen($this->fe_user['username'])) {
783 $this->xmlhandler->searchExtensionsXML($this->listRemote_search, $this->fe_user['username'], $this->MOD_SETTINGS['listOrder']);
784 } else {
785 $this->xmlhandler->searchExtensionsXML($this->listRemote_search, '', $this->MOD_SETTINGS['listOrder'], false, false, $offset, $this->listingLimit);
786 }
787 if (count($this->xmlhandler->extensionsXML)) {
788 list($list,$cat) = $this->prepareImportExtList(true);
789
790 // Available extensions
791 if (is_array($cat[$this->MOD_SETTINGS['listOrder']])) {
792 $lines=array();
793 $lines[]=$this->extensionListRowHeader(' class="bgColor5"',array('<td><img src="clear.gif" width="18" height="1" alt="" /></td>'),1);
794
795 foreach($cat[$this->MOD_SETTINGS['listOrder']] as $catName => $extEkeys) {
796 if (count($extEkeys)) {
797 $lines[]='<tr><td colspan="'.(3+$this->detailCols[$this->MOD_SETTINGS['display_details']]).'"><br /></td></tr>';
798 $lines[]='<tr><td colspan="'.(3+$this->detailCols[$this->MOD_SETTINGS['display_details']]).'"><img src="'.$GLOBALS['BACK_PATH'].'gfx/i/sysf.gif" width="18" height="16" align="top" alt="" /><strong>'.$this->listOrderTitle($this->MOD_SETTINGS['listOrder'],$catName).'</strong></td></tr>';
799
800 natcasesort($extEkeys);
801 reset($extEkeys);
802 while(list($extKey)=each($extEkeys)) {
803 $version = array_keys($list[$extKey]['versions']);
804 $version = end($version);
805 $ext = $list[$extKey]['versions'][$version];
806 $ext['downloadcounter_all'] = $list[$extKey]['downloadcounter'];
807 $ext['_ICON'] = $list[$extKey]['_ICON'];
808 $loadUnloadLink='';
809 if ($inst_list[$extKey]['type']!='S' && (!isset($inst_list[$extKey]) || $this->versionDifference($version,$inst_list[$extKey]['EM_CONF']['version'],$this->versionDiffFactor))) {
810 if (isset($inst_list[$extKey])) {
811 // update
812 $loc= ($inst_list[$extKey]['type']=='G'?'G':'L');
813 $aUrl = 'index.php?CMD[importExt]='.$extKey.'&CMD[extVersion]='.$version.'&CMD[loc]='.$loc;
814 $loadUnloadLink.= '<a href="'.htmlspecialchars($aUrl).'"><img src="'.$GLOBALS['BACK_PATH'].'gfx/import_update.gif" width="12" height="12" title="Update the extension in \''.($loc=='G'?'global':'local').'\' from online repository to server" alt="" /></a>';
815 } else {
816 // import
817 $aUrl = 'index.php?CMD[importExt]='.$extKey.'&CMD[extVersion]='.$version.'&CMD[loc]=L';
818 $loadUnloadLink.= '<a href="'.htmlspecialchars($aUrl).'"><img src="'.$GLOBALS['BACK_PATH'].'gfx/import.gif" width="12" height="12" title="Import this extension to \'local\' dir typo3conf/ext/ from online repository." alt="" /></a>';
819 }
820 } else {
821 $loadUnloadLink = '&nbsp;';
822 }
823
824 if (isset($inst_list[$extKey])) {
825 $theRowClass = t3lib_extMgm::isLoaded($extKey) ? 'em-listbg1' : 'em-listbg2';
826 } else {
827 $theRowClass = 'em-listbg3';
828 }
829
830 $lines[]=$this->extensionListRow($extKey,$ext,array('<td class="bgColor">'.$loadUnloadLink.'</td>'),$theRowClass,$inst_list,1,'index.php?CMD[importExtInfo]='.rawurlencode($extKey));
831 unset($list[$extKey]);
832 }
833 }
834 }
835 unset($list);
836
837 // CSH:
838 $content.= t3lib_BEfunc::cshItem('_MOD_tools_em', 'import_ter', $GLOBALS['BACK_PATH'],'|<br/>');
839 $onsubmit = "window.location.href='index.php?ter_connect=1&ter_search='+escape(this.elements['_lookUp'].value);return false;";
840 $content.= '</form><form action="index.php" method="post" onsubmit="'.htmlspecialchars($onsubmit).'">List or look up <strong'.($this->MOD_SETTINGS['display_unchecked']?' style="color:#900;">all':' style="color:#090;">reviewed').'</strong> extensions<br />
841 <input type="text" name="_lookUp" value="'.htmlspecialchars($this->listRemote_search).'" /> <input type="submit" value="Look up" /><br /><br />';
842
843 $content .= $this->browseLinks();
844
845 $content.= '
846
847 <!-- TER Extensions list -->
848 <table border="0" cellpadding="2" cellspacing="1">'.implode(chr(10),$lines).'</table>';
849 $content .= '<br />'.$this->browseLinks();
850 $content.= '<br /><br />'.$this->securityHint;
851 $content.= '<br /><br /><strong>PRIVACY NOTICE:</strong><br /> '.$this->privacyNotice;
852
853 $this->content.=$this->doc->section('Extensions in TYPO3 Extension Repository (online) - Grouped by: '.$this->MOD_MENU['listOrder'][$this->MOD_SETTINGS['listOrder']],$content,0,1);
854
855 // Plugins which are NOT uploaded to repository but present on this server.
856 $content='';
857 $lines=array();
858 if (count($this->inst_keys)) {
859 reset($this->inst_keys);
860 while(list($extKey)=each($this->inst_keys)) {
861 if(strlen($this->listRemote_search) && !stristr($extKey,$this->listRemote_search)) continue;
862
863 $loadUnloadLink = t3lib_extMgm::isLoaded($extKey)?
864 '<a href="'.htmlspecialchars('index.php?CMD[showExt]='.$extKey.'&CMD[remove]=1&CMD[clrCmd]=1&SET[singleDetails]=info').'">'.$this->removeButton().'</a>':
865 '<a href="'.htmlspecialchars('index.php?CMD[showExt]='.$extKey.'&CMD[load]=1&CMD[clrCmd]=1&SET[singleDetails]=info').'">'.$this->installButton().'</a>';
866 if (in_array($extKey,$this->requiredExt)) $loadUnloadLink='<strong>'.$GLOBALS['TBE_TEMPLATE']->rfw('Rq').'</strong>';
867 $lines[]=$this->extensionListRow($extKey,$inst_list[$extKey],array('<td class="bgColor">'.$loadUnloadLink.'</td>'),t3lib_extMgm::isLoaded($extKey)?'em-listbg1':'em-listbg2');
868 }
869 }
870 if(count($lines)) {
871 $content.= 'This is the list of extensions which are available locally, but not in the repository.<br />They might be user-defined and should be prepended user_ then.<br /><br />';
872 $content.= '<table border="0" cellpadding="2" cellspacing="1">'.
873 $this->extensionListRowHeader(' class="bgColor5"',array('<td><img src="clear.gif" width="18" height="1" alt="" /></td>')).
874 implode('',$lines).'</table>';
875 $this->content.=$this->doc->spacer(20);
876 $this->content.=$this->doc->section('Extensions found only on this server',$content,0,1);
877 }
878 }
879 } else {
880 $content.= t3lib_BEfunc::cshItem('_MOD_tools_em', 'import_ter', $GLOBALS['BACK_PATH'],'|<br/>');
881 $onsubmit = "window.location.href='index.php?ter_connect=1&ter_search='+escape(this.elements['_lookUp'].value);return false;";
882 $content.= '</form><form action="index.php" method="post" onsubmit="'.htmlspecialchars($onsubmit).'">List or look up <strong'.($this->MOD_SETTINGS['display_unchecked']?' style="color:#900;">all':' style="color:#090;">reviewed').'</strong> extensions<br />
883 <input type="text" name="_lookUp" value="'.htmlspecialchars($this->listRemote_search).'" /> <input type="submit" value="Look up" /><br /><br />';
884
885 $content.= '<p><strong>No matching extensions found.</strong></p>';
886
887 $content.= '<br /><br /><strong>PRIVACY NOTICE:</strong><br /> '.$this->privacyNotice;
888 $this->content.=$this->doc->section('Extensions in TYPO3 Extension Repository (online) - Grouped by: '.$this->MOD_MENU['listOrder'][$this->MOD_SETTINGS['listOrder']],$content,0,1);
889 }
890 } else {
891 // CSH
892 $content.= t3lib_BEfunc::cshItem('_MOD_tools_em', 'import', $GLOBALS['BACK_PATH'],'|<br/>');
893
894 $onsubmit = "window.location.href='index.php?ter_connect=1&ter_search='+escape(this.elements['_lookUp'].value);return false;";
895 $content.= '</form><form action="index.php" method="post" onsubmit="'.htmlspecialchars($onsubmit).'">List or look up <strong'.($this->MOD_SETTINGS['display_unchecked']?' style="color:#900;">all':' style="color:#090;">reviewed').'</strong> extensions<br />
896 <input type="text" name="_lookUp" value="" /> <input type="submit" value="Look up" /><br /><br />';
897
898 if ($this->CMD['fetchMetaData']) { // fetches mirror/extension data from online rep.
899 $content .= $this->fetchMetaData($this->CMD['fetchMetaData']);
900 } else {
901 $onCLick = "window.location.href='index.php?CMD[fetchMetaData]=extensions';return false;";
902 $content.= 'Connect to the current mirror and retrieve the current list of available plugins from the TYPO3 Extension Repository.<br />
903 <input type="submit" value="Retrieve/Update" onclick="'.htmlspecialchars($onCLick).'" />';
904 if(is_file(PATH_site.'typo3temp/extensions.bin')) {
905 $content .= ' (last update: '.date('Y-m-d H:i',filemtime(PATH_site.'typo3temp/extensions.xml.gz')).')';
906 }
907 }
908 $content.= '<br /><br />'.$this->securityHint;
909 $content.= '<br /><br /><strong>PRIVACY NOTICE:</strong><br />'.$this->privacyNotice;
910
911 $this->content.=$this->doc->section('Extensions in TYPO3 Extension Repository',$content,0,1);
912 }
913
914 // Upload:
915 if ($this->importAtAll()) {
916 $content= '</form><form action="index.php" enctype="'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'].'" method="post">
917 Upload extension file (.t3x):<br />
918 <input type="file" size="60" name="upload_ext_file" /><br />
919 ... to location:<br />
920 <select name="CMD[loc]">';
921 if ($this->importAsType('L')) $content.='<option value="L">Local (../typo3conf/ext/)</option>';
922 if ($this->importAsType('G')) $content.='<option value="G">Global (typo3/ext/)</option>';
923 if ($this->importAsType('S')) $content.='<option value="S">System (typo3/sysext/)</option>';
924 $content.='</select><br />
925 <input type="checkbox" value="1" name="CMD[uploadOverwrite]" /> Overwrite any existing extension!<br />
926 <input type="submit" name="CMD[uploadExt]" value="Upload extension file" /><br />
927 ';
928 } else $content=$this->noImportMsg();
929
930 $this->content.=$this->doc->spacer(20);
931 $this->content.=$this->doc->section('Upload extension file directly (.t3x):',$content,0,1);
932 }
933
934 /**
935 * Generates a link to the next page of extensions
936 *
937 * @return void
938 */
939 function browseLinks() {
940 $content = '';
941 if ($this->pointer) {
942 $content .= '<a href="'.t3lib_div::linkThisScript(array('pointer' => $this->pointer-1)).'" class="typo3-prevPage"><img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/pilleft_n.gif','width="14" height="14"').' alt="Prev page" /> Prev page</a>';
943 }
944 if ($content) $content .= '&nbsp;&nbsp;&nbsp;';
945 if (intval($this->xmlhandler->matchingCount/$this->listingLimit)>$this->pointer) {
946 $content .= '<a href="'.t3lib_div::linkThisScript(array('pointer' => $this->pointer+1)).'" class="typo3-nextPage"><img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/pilright_n.gif','width="14" height="14"').' alt="Next page" /> Next page</a>';
947 }
948 $upper = (($this->pointer+1)*$this->listingLimit);
949 if ($upper>$this->xmlhandler->matchingCount) {
950 $upper = $this->xmlhandler->matchingCount;
951 }
952 if ($content) $content .= '<br /><br />Showing extensions <strong>'.($this->pointer*$this->listingLimit+1).'</strong> to <strong>'.$upper.'</strong>';
953 if ($content) $content .= '<br /><br />';
954 return $content;
955 }
956
957 /**
958 * Allows changing of settings
959 *
960 * @return void
961 */
962 function alterSettings() {
963
964 // Prepare the HTML output:
965 $content.= '
966 '.t3lib_BEfunc::cshItem('_MOD_tools_em', 'settings', $GLOBALS['BACK_PATH'],'|<br/>').'
967 <fieldset><legend>Security Settings</legend>
968 <table border="0" cellpadding="2" cellspacing="2">
969 <tr class="bgColor4">
970 <td>Enable extensions without review (basic security check):</td>
971 <td>'.t3lib_BEfunc::getFuncCheck(0,'SET[display_unchecked]',$this->MOD_SETTINGS['display_unchecked']).'</td>
972 </tr>
973 </table>
974 <strong>Notice:</strong> Make sure you know what consequences enabling this checkbox might have. Check the <a href="http://typo3.org/extensions/what-are-reviews/" target="_blank">information on typo3.org about security reviewing</a>!
975 </fieldset>
976 <br />
977 <br />
978 <fieldset><legend>User Settings</legend>
979 <table border="0" cellpadding="2" cellspacing="2">
980 <tr class="bgColor4">
981 <td>Enter repository username:</td>
982 <td><input type="text" name="SET[fe_u]" value="'.htmlspecialchars($this->MOD_SETTINGS['fe_u']).'" /></td>
983 </tr>
984 <tr class="bgColor4">
985 <td>Enter repository password:</td>
986 <td><input type="password" name="SET[fe_p]" value="'.htmlspecialchars($this->MOD_SETTINGS['fe_p']).'" /></td>
987 </tr>
988 </table>
989 <strong>Notice:</strong> This is <em>not</em> your password to the TYPO3 backend! This user information is what is needed to log in at typo3.org with your account there!
990 </fieldset>
991 <br />
992 <br />
993 <fieldset><legend>Mirror selection</legend>
994 <table border="0" cellpadding="2" cellspacing="2">
995 <tr class="bgColor4">
996 <td>Enter mirror list URL:</td>
997 <td><input type="text" size="50" name="SET[mirrorListURL]" value="'.htmlspecialchars($this->MOD_SETTINGS['mirrorListURL']).'" /></td>
998 </tr>
999 </table>
1000 <br />
1001 <p>Select a mirror from below. This list is built from the online mirror list retrieved from the URL above.<br /><br /></p>
1002 <fieldset><legend>Mirror list</legend>';
1003 if(!empty($this->MOD_SETTINGS['mirrorListURL'])) {
1004 if ($this->CMD['fetchMetaData']) { // fetches mirror/extension data from online rep.
1005 $content .= $this->fetchMetaData($this->CMD['fetchMetaData']);
1006 } else {
1007 $content.= '<a href="index.php?CMD[fetchMetaData]=mirrors">Click here to reload the list.</a>';
1008 }
1009 }
1010 $content .= '<br />
1011 <table cellspacing="4" style="text-align:left; vertical-alignment:top;">
1012 <tr><td>Use</td><td>Name</td><td>URL</td><td>Country</td><td>Sponsored by</td></tr>
1013 ';
1014
1015 if (!strlen($this->MOD_SETTINGS['extMirrors'])) $this->fetchMetaData('mirrors');
1016 $extMirrors = unserialize($this->MOD_SETTINGS['extMirrors']);
1017 $extMirrors[''] = array('title'=>'Random (recommended!)');
1018 ksort($extMirrors);
1019 if(is_array($extMirrors)) {
1020 foreach($extMirrors as $k => $v) {
1021 if(isset($v['sponsor'])) {
1022 $sponsor = '<a href="'.htmlspecialchars($v['sponsor']['link']).'" target="_new"><img src="'.$v['sponsor']['logo'].'" title="'.htmlspecialchars($v['sponsor']['name']).'" alt="'.htmlspecialchars($v['sponsor']['name']).'" /></a>';
1023 }
1024 $selected = ($this->MOD_SETTINGS['selectedMirror']==$k) ? 'checked="checked"' : '';
1025 $content.='<tr class="bgColor4">
1026 <td><input type="radio" name="SET[selectedMirror]" value="'.$k.'" '.$selected.'/></td><td>'.htmlspecialchars($v['title']).'</td><td>'.htmlspecialchars($v['host'].$v['path']).'</td><td>'.$v['country'].'</td><td>'.$sponsor.'</td></tr>';
1027 }
1028 }
1029 $content.= '
1030 </table>
1031 </fieldset>
1032 <br />
1033 <table border="0" cellpadding="2" cellspacing="2">
1034 <tr class="bgColor4">
1035 <td>Enter repository URL:</td>
1036 <td><input type="text" size="50" name="SET[rep_url]" value="'.htmlspecialchars($this->MOD_SETTINGS['rep_url']).'" /></td>
1037 </tr>
1038 </table>
1039
1040 If you set a repository URL, this overrides the use of a mirror. Use this to select a specific (private) repository.<br />
1041 </fieldset>
1042 <br />
1043 <input type="submit" value="Update" />
1044 ';
1045
1046 $this->content.=$this->doc->section('Repository settings',$content,0,1);
1047 }
1048
1049 /**
1050 * Allows to set the translation preferences and check the status
1051 *
1052 * @return void
1053 */
1054 function translationHandling() {
1055 global $LANG, $TYPO3_LOADED_EXT;
1056 $LANG->includeLLFile('EXT:setup/mod/locallang.xml');
1057
1058 $incoming = t3lib_div::_POST('SET');
1059 if(isset($incoming['selectedLanguages']) && is_array($incoming['selectedLanguages'])) {
1060 t3lib_BEfunc::getModuleData($this->MOD_MENU, array('selectedLanguages' => serialize($incoming['selectedLanguages'])), $this->MCONF['name'], '', 'selectedLanguages');
1061 $this->MOD_SETTINGS['selectedLanguages'] = serialize($incoming['selectedLanguages']);
1062 }
1063
1064 $selectedLanguages = unserialize($this->MOD_SETTINGS['selectedLanguages']);
1065 if(count($selectedLanguages)==1 && empty($selectedLanguages[0])) $selectedLanguages = array();
1066 $theLanguages = t3lib_div::trimExplode('|',TYPO3_languages);
1067 foreach($theLanguages as $val) {
1068 if ($val!='default') {
1069 $localLabel = ' - ['.htmlspecialchars($GLOBALS['LOCAL_LANG']['default']['lang_'.$val]).']';
1070 $selected = (is_array($selectedLanguages) && in_array($val, $selectedLanguages)) ? ' selected="selected"' : '';
1071 $opt[$GLOBALS['LOCAL_LANG']['default']['lang_'.$val].'--'.$val]='
1072 <option value="'.$val.'"'.$selected.'>'.$LANG->getLL('lang_'.$val,1).$localLabel.'</option>';
1073 }
1074 }
1075 ksort($opt);
1076
1077 // Prepare the HTML output:
1078 $content.= '
1079 '.t3lib_BEfunc::cshItem('_MOD_tools_em', 'translation', $GLOBALS['BACK_PATH'],'|<br/>').'
1080 <fieldset><legend>Translation Settings</legend>
1081 <table border="0" cellpadding="2" cellspacing="2">
1082 <tr class="bgColor4">
1083 <td>Languages to fetch:</td>
1084 <td>
1085 <select name="SET[selectedLanguages][]" multiple="multiple" size="10">
1086 <option></option>'.
1087 implode('',$opt).'
1088 </select>
1089 </td>
1090 </tr>
1091 </table>
1092 <br />
1093 <p>For the selected languages the EM tries to download and install translation files if available, whenever an extension is installed. (This replaces the <code>csh_*</code> extensions that were used to install core translations before TYPO3 version 4!)<br />
1094 <br />To request an update/install for already loaded extensions, see below.</p>
1095 </fieldset>
1096 <br />
1097 <input type="submit" value="Save selection" />
1098 <br />
1099 </fieldset>';
1100
1101 $this->content.=$this->doc->section('Translation settings',$content,0,1);
1102
1103 if(count($selectedLanguages)>0) {
1104 $mirrorURL = $this->getMirrorURL();
1105 $content = '<input type="button" value="Check status against repository" onclick="document.location.href=\''.t3lib_div::linkThisScript(array('l10n'=>'check')).'\'" />&nbsp;<input type="button" value="Update from repository" onclick="document.location.href=\''.t3lib_div::linkThisScript(array('l10n'=>'update')).'\'" />';
1106
1107 if(t3lib_div::_GET('l10n') == 'check') {
1108 $loadedExtensions = array_keys($TYPO3_LOADED_EXT);
1109 $loadedExtensions = array_diff($loadedExtensions,array('_CACHEFILE'));
1110
1111 // Override content output - we now do that ourself:
1112 echo ($this->content . $this->doc->section('Translation status',$content,0,1));
1113 $this->doPrintContent = FALSE;
1114 flush();
1115
1116 echo '
1117 <br />
1118 <br />
1119 <p id="progress-message">
1120 Checking translation status, please wait ...
1121 </p>
1122 <br />
1123 <div style="width:100%; height:20px; border: 1px solid black;">
1124 <div id="progress-bar" style="float: left; width: 0%; height: 20px; background-color:green;">&nbsp;</div>
1125 <div id="transparent-bar" style="float: left; width: 100%; height: 20px; background-color:'.$this->doc->bgColor2.';">&nbsp;</div>
1126 </div>
1127 <br />
1128 <br /><p>This table shows the status of the loaded extension\'s translations.</p><br />
1129 <table border="0" cellpadding="2" cellspacing="2">
1130 <tr class="bgColor2"><td>Extension key</td>
1131 ';
1132
1133 foreach($selectedLanguages as $lang) {
1134 echo ('<td>'.$LANG->getLL('lang_'.$lang,1).'</td>');
1135 }
1136 echo ('</tr>');
1137
1138 $counter = 1;
1139 foreach($loadedExtensions as $extKey) {
1140
1141 $percentDone = intval (($counter / count($loadedExtensions)) * 100);
1142 echo ('
1143 <script>
1144 document.getElementById("progress-bar").style.width = "'.$percentDone.'%";
1145 document.getElementById("transparent-bar").style.width = "'.(100-$percentDone).'%";
1146 document.getElementById("progress-message").firstChild.data="Checking translation status for extension \"'.$extKey.'\" ...";
1147 </script>
1148 ');
1149
1150 flush();
1151 $translationStatusArr = $this->terConnection->fetchTranslationStatus($extKey,$mirrorURL);
1152
1153 echo ('<tr class="bgColor4"><td>'.$extKey.'</td>');
1154 foreach($selectedLanguages as $lang) {
1155 // remote unknown -> keine l10n
1156 if(!isset($translationStatusArr[$lang])) {
1157 echo ('<td title="No translation available">N/A</td>');
1158 continue;
1159 }
1160 // determine local md5 from zip
1161 if(is_file(PATH_site.'typo3temp/'.$extKey.'-l10n-'.$lang.'.zip')) {
1162 $localmd5 = md5_file(PATH_site.'typo3temp/'.$extKey.'-l10n-'.$lang.'.zip');
1163 } else {
1164 echo ('<td title="Not installed / Unknown" style="background-color:#ff0">???</td>');
1165 continue;
1166 }
1167 // local!=remote -> needs update
1168 if($localmd5 != $translationStatusArr[$lang]['md5']) {
1169 echo ('<td title="Needs update" style="background-color:#ff0">UPD</td>');
1170 continue;
1171 }
1172 echo ('<td title="Is up to date" style="background-color:#69a550">OK</td>');
1173 }
1174 echo ('</tr>');
1175
1176 $counter ++;
1177 }
1178 echo '</table>
1179 <script>
1180 document.getElementById("progress-message").firstChild.data="Check done.";
1181 </script>
1182 ';
1183 echo $this->doc->endPage();
1184 return '';
1185
1186 } elseif(t3lib_div::_GET('l10n') == 'update') {
1187 $loadedExtensions = array_keys($TYPO3_LOADED_EXT);
1188 $loadedExtensions = array_diff($loadedExtensions,array('_CACHEFILE'));
1189
1190 // Override content output - we now do that ourself:
1191 echo ($this->content . $this->doc->section('Translation status',$content,0,1));
1192 $this->doPrintContent = FALSE;
1193 flush();
1194
1195 echo ('
1196 <br />
1197 <br />
1198 <p id="progress-message">
1199 Updating translations, please wait ...
1200 </p>
1201 <br />
1202 <div style="width:100%; height:20px; border: 1px solid black;">
1203 <div id="progress-bar" style="float: left; width: 0%; height: 20px; background-color:green;">&nbsp;</div>
1204 <div id="transparent-bar" style="float: left; width: 100%; height: 20px; background-color:'.$this->doc->bgColor2.';">&nbsp;</div>
1205 </div>
1206 <br />
1207 <br /><p>This table shows the update results of the loaded extension\'s translations.<br />
1208 <em>If you want to force a full check/update, delete the l10n zip-files from the typo3temp folder.</em></p><br />
1209 <table border="0" cellpadding="2" cellspacing="2">
1210 <tr class="bgColor2"><td>Extension key</td>
1211 ');
1212
1213 foreach($selectedLanguages as $lang) {
1214 echo '<td>'.$LANG->getLL('lang_'.$lang,1).'</td>';
1215 }
1216 echo '</tr>';
1217
1218 $counter = 1;
1219 foreach($loadedExtensions as $extKey) {
1220 $percentDone = intval (($counter / count($loadedExtensions)) * 100);
1221 echo ('
1222 <script>
1223 document.getElementById("progress-bar").style.width = "'.$percentDone.'%";
1224 document.getElementById("transparent-bar").style.width = "'.(100-$percentDone).'%";
1225 document.getElementById("progress-message").firstChild.data="Updating translation for extension \"'.$extKey.'\" ...";
1226 </script>
1227 ');
1228
1229 flush();
1230 $translationStatusArr = $this->terConnection->fetchTranslationStatus($extKey,$mirrorURL);
1231
1232 echo ('<tr class="bgColor4"><td>'.$extKey.'</td>');
1233 if(is_array($translationStatusArr)) {
1234 foreach($selectedLanguages as $lang) {
1235 // remote unknown -> no l10n available
1236 if(!isset($translationStatusArr[$lang])) {
1237 echo ('<td title="No translation available">N/A</td>');
1238 continue;
1239 }
1240 // determine local md5 from zip
1241 if(is_file(PATH_site.'typo3temp/'.$extKey.'-l10n-'.$lang.'.zip')) {
1242 $localmd5 = md5_file(PATH_site.'typo3temp/'.$extKey.'-l10n-'.$lang.'.zip');
1243 } else {
1244 $localmd5 = 'zzz';
1245 }
1246 // local!=remote or not installed -> needs update
1247 if($localmd5 != $translationStatusArr[$lang]['md5']) {
1248 $ret = $this->updateTranslation($extKey, $lang, $mirrorURL);
1249 if($ret === true) {
1250 echo ('<td title="Has been updated" style="background-color:#69a550">UPD</td>');
1251 } else {
1252 echo ('<td title="'.htmlspecialchars($ret).'" style="background-color:#cb3352">ERR</td>');
1253 }
1254 continue;
1255 }
1256 echo ('<td title="Is up to date" style="background-color:#69a550">OK</td>');
1257 }
1258 } else {
1259 echo ('<td colspan="'.count($selectedLanguages).'" title="Possible reasons: network problems, allow_url_fopen off, curl not enabled in Install tool.">Could not fetch translation status</td>');
1260 }
1261 echo ('</tr>');
1262 $counter++;
1263 }
1264 echo '</table>
1265 <script>
1266 document.getElementById("progress-message").firstChild.data="Update done.";
1267 </script>
1268 ';
1269 echo $this->doc->endPage();
1270 return '';
1271 }
1272
1273 $this->content.=$this->doc->section('Translation status',$content,0,1);
1274 }
1275 }
1276
1277 /**
1278 * Install translations for all selected languages for an extension
1279 *
1280 * @param string $extKey The extension key to install the translations for
1281 * @param string $lang Language code of translation to fetch
1282 * @param string $mirrorURL Mirror URL to fetch data from
1283 * @return mixed true on success, error string on fauilure
1284 */
1285 function updateTranslation($extKey, $lang, $mirrorURL) {
1286 $l10n = $this->terConnection->fetchTranslation($extKey, $lang, $mirrorURL);
1287 if(is_array($l10n)) {
1288 $file = PATH_site.'typo3temp/'.$extKey.'-l10n-'.$lang.'.zip';
1289 $path = 'l10n/'.$lang.'/';
1290 if(!is_dir(PATH_typo3conf.$path)) t3lib_div::mkdir_deep(PATH_typo3conf,$path);
1291 t3lib_div::writeFile($file, $l10n[0]);
1292 if($this->unzip($file, PATH_typo3conf.$path)) {
1293 return true;
1294 } else {
1295 return 'Unpacking the language pack failed!';
1296 }
1297 } else {
1298 return $l10n;
1299 }
1300 }
1301
1302 /**
1303 * Install translations for all selected languages for an extension
1304 *
1305 * @param string $extKey The extension key to install the translations for
1306 * @param string $mirrorURL Mirror URL to fetch data from
1307 * @return mixed true on success, error string on fauilure
1308 */
1309 function installTranslationsForExtension($extKey, $mirrorURL) {
1310 $selectedLanguages = unserialize($this->MOD_SETTINGS['selectedLanguages']);
1311 if(!is_array($selectedLanguages)) $selectedLanguages = array();
1312 foreach($selectedLanguages as $lang) {
1313 $l10n = $this->terConnection->fetchTranslation($extKey, $lang, $mirrorURL);
1314 if(is_array($l10n)) {
1315 $file = PATH_typo3conf.'l10n/'.$extKey.'-l10n-'.$lang.'.zip';
1316 $path = 'l10n/'.$lang.'/'.$extKey;
1317 t3lib_div::writeFile($file, $l10n[0]);
1318 if(!is_dir(PATH_typo3conf.$path)) t3lib_div::mkdir_deep(PATH_typo3conf,$path);
1319 if($this->unzip($file, PATH_typo3conf.$path)) {
1320 return true;
1321 } else {
1322 return 'Unpacking the language pack failed!';
1323 }
1324 } else {
1325 return $l10n;
1326 }
1327 }
1328 }
1329
1330 /**
1331 * Unzips a zip file in the given path.
1332 *
1333 * Uses unzip binary if available, otherwise a pure PHP unzip is used.
1334 *
1335 * @param string $file Full path to zip file
1336 * @param string $path Path to change to before extracting
1337 * @return boolean True on success, false in failure
1338 */
1339 function unzip($file, $path) {
1340 if(strlen($GLOBALS['TYPO3_CONF_VARS']['BE']['unzip_path'])) {
1341 chdir($path);
1342 $cmd = $GLOBALS['TYPO3_CONF_VARS']['BE']['unzip_path'].' -o '.escapeshellarg($file);
1343 exec($cmd, $list, $ret);
1344 return ($ret === 0);
1345 } else {
1346 // we use a pure PHP unzip
1347 $unzip = new em_unzip($file);
1348 $ret = $unzip->extract(array('add_path'=>$path));
1349 return (is_array($ret));
1350 }
1351 }
1352
1353
1354
1355 /*********************************
1356 *
1357 * Command Applications (triggered by GET var)
1358 *
1359 *********************************/
1360
1361 /**
1362 * Returns detailed info about an extension in the online repository
1363 *
1364 * @param string Extension repository uid + optional "private key": [uid]-[key].
1365 * @param [type] $version: ...
1366 * @return void
1367 */
1368 function importExtInfo($extKey, $version='') {
1369
1370 // "Go back" link
1371 $content = '<a href="index.php" class="typo3-goBack"><img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/goback.gif','width="14" height="14"').' alt="" /> Go back</a>';
1372 $this->content.= $this->doc->section('',$content);
1373 $content = '';
1374
1375 // Fetch remote data:
1376 $this->xmlhandler->searchExtensionsXML($extKey, '', '', true, true);
1377 list($fetchData,) = $this->prepareImportExtList(true);
1378
1379 $versions = array_keys($fetchData[$extKey]['versions']);
1380 $version = ($version == '') ? end($versions) : $version;
1381
1382 $opt = array();
1383 foreach(array_keys($fetchData[$extKey]['versions']) as $ver) {
1384 $opt[]='<option value="'.$ver.'"'.(($version == $ver) ? ' selected="selected"' : '').'>'.$ver.'</option>';
1385 }
1386
1387 // "Select version" box:
1388 $onClick = 'window.location.href=\'index.php?CMD[importExtInfo]='.$extKey.'&CMD[extVersion]=\'+document.pageform.extVersion.options[document.pageform.extVersion.selectedIndex].value; return false;';
1389 $select='<select name="extVersion">'.implode('',$opt).'</select> <input type="submit" value="Load details" onclick="'.htmlspecialchars($onClick).'" /> or<br /><br />';
1390
1391 if ($this->importAtAll()) {
1392 $onClick = '
1393 window.location.href=\'index.php?CMD[importExt]='.$extKey.'\'
1394 +\'&CMD[extVersion]=\'+document.pageform.extVersion.options[document.pageform.extVersion.selectedIndex].value
1395 +\'&CMD[loc]=\'+document.pageform.loc.options[document.pageform.loc.selectedIndex].value;
1396 return false;';
1397 $select.='
1398 <input type="submit" value="Import/Update" onclick="'.htmlspecialchars($onClick).'"> to:
1399 <select name="loc">'.
1400 ($this->importAsType('G',$fetchData['emconf_lockType'])?'<option value="G">Global: '.$this->typePaths['G'].$extKey.'/'.(@is_dir(PATH_site.$this->typePaths['G'].$extKey)?' (OVERWRITE)':' (empty)').'</option>':'').
1401 ($this->importAsType('L',$fetchData['emconf_lockType'])?'<option value="L">Local: '.$this->typePaths['L'].$extKey.'/'.(@is_dir(PATH_site.$this->typePaths['L'].$extKey)?' (OVERWRITE)':' (empty)').'</option>':'').
1402 ($this->importAsType('S',$fetchData['emconf_lockType'])?'<option value="S">System: '.$this->typePaths['S'].$extKey.'/'.(@is_dir(PATH_site.$this->typePaths['S'].$extKey)?' (OVERWRITE)':' (empty)').'</option>':'').
1403 '</select>';
1404 } else $select.= $this->noImportMsg();
1405 $content.= $select;
1406 $this->content.= $this->doc->section('Select command',$content,0,1);
1407
1408 // Details:
1409 $eInfo = $fetchData[$extKey]['versions'][$version];
1410 $content='<strong>'.$fetchData[$extKey]['_ICON'].' &nbsp;'.$eInfo['EM_CONF']['title'].' ('.$extKey.', '.$version.')</strong><br /><br />';
1411 $content.=$this->extInformationArray($extKey,$eInfo,1);
1412 $this->content.=$this->doc->spacer(10);
1413 $this->content.=$this->doc->section('Remote Extension Details',$content,0,1);
1414 }
1415
1416 /**
1417 * Fetches metadata and stores it to the corresponding place. This includes the mirror list,
1418 * extension XML files.
1419 *
1420 * @param string Type of data to fetch: (mirrors)
1421 * @param boolean If true the method doesn't produce any output
1422 * @return void
1423 */
1424 function fetchMetaData($metaType) {
1425 global $TYPO3_CONF_VARS;
1426
1427 switch($metaType) {
1428 case 'mirrors':
1429 $mfile = t3lib_div::tempnam('mirrors');
1430 $mirrorsFile = t3lib_div::getURL($this->MOD_SETTINGS['mirrorListURL']);
1431 if($mirrorsFile===false) {
1432 t3lib_div::unlink_tempfile($mfile);
1433 $content = '<p>The mirror list was not updated, it could not be fetched from '.$this->MOD_SETTINGS['mirrorListURL'].'. Possible reasons: network problems, allow_url_fopen is off, curl is not enabled in Install tool.</p>';
1434 } else {
1435 t3lib_div::writeFile($mfile, $mirrorsFile);
1436 $mirrors = implode('',gzfile($mfile));
1437 t3lib_div::unlink_tempfile($mfile);
1438
1439 $mirrors = $this->xmlhandler->parseMirrorsXML($mirrors);
1440 if(is_array($mirrors) && count($mirrors)) {
1441 t3lib_BEfunc::getModuleData($this->MOD_MENU, array('extMirrors' => serialize($mirrors)), $this->MCONF['name'], '', 'extMirrors');
1442 $this->MOD_SETTINGS['extMirrors'] = serialize($mirrors);
1443 $content = '<p>The mirror list has been updated and now contains '.count($mirrors).' entries.</p>';
1444 }
1445 else {
1446 $content = '<p>'.$mirrors.'<br />The mirror list was not updated as it contained no entries.</p>';
1447 }
1448 }
1449 break;
1450 case 'extensions':
1451 $this->fetchMetaData('mirrors'); // if we fetch the extensions anyway, we can as well keep this up-to-date
1452
1453 $mirror = $this->getMirrorURL();
1454 $extfile = $mirror.'extensions.xml.gz';
1455 $extmd5 = t3lib_div::getURL($mirror.'extensions.md5');
1456 if(is_file(PATH_site.'typo3temp/extensions.xml.gz')) $localmd5 = md5_file(PATH_site.'typo3temp/extensions.xml.gz');
1457
1458 if($extmd5 === false) {
1459 $content .= '<p>Error: The extension MD5 sum could not be fetched from '.$mirror.'extensions.md5. Possible reasons: network problems, allow_url_fopen is off, curl is not enabled in Install tool.</p>';
1460 } elseif($extmd5 == $localmd5) {
1461 $content .= '<p>The extension list has not changed remotely, it has thus not been fetched.</p>';
1462 } else {
1463 $extXML = t3lib_div::getURL($extfile);
1464 if($extXML === false) {
1465 $content .= '<p>Error: The extension list could not be fetched from '.$extfile.'. Possible reasons: network problems, allow_url_fopen is off, curl is not enabled in Install tool.</p>';
1466 } else {
1467 t3lib_div::writeFile(PATH_site.'typo3temp/extensions.xml.gz', $extXML);
1468 $content .= $this->xmlhandler->parseExtensionsXML(PATH_site.'typo3temp/extensions.xml.gz');
1469 }
1470 }
1471 break;
1472 }
1473
1474 return $content;
1475 }
1476
1477 /**
1478 * Returns the base URL for the slected or a random mirror.
1479 *
1480 * @return string The URL for the selected or a random mirror
1481 */
1482 function getMirrorURL() {
1483 if(strlen($this->MOD_SETTINGS['rep_url'])) return $this->MOD_SETTINGS['rep_url'];
1484
1485 $mirrors = unserialize($this->MOD_SETTINGS['extMirrors']);
1486 if(!is_array($mirrors)) {
1487 $this->fetchMetaData('mirrors');
1488 $mirrors = unserialize($this->MOD_SETTINGS['extMirrors']);
1489 if(!is_array($mirrors)) return false;
1490 }
1491 if($this->MOD_SETTINGS['selectedMirror']=='') {
1492 srand((float) microtime() * 10000000); // not needed after PHP 4.2.0...
1493 $rand = array_rand($mirrors);
1494 $url = 'http://'.$mirrors[$rand]['host'].$mirrors[$rand]['path'];
1495 }
1496 else {
1497 $url = 'http://'.$mirrors[$this->MOD_SETTINGS['selectedMirror']]['host'].$mirrors[$this->MOD_SETTINGS['selectedMirror']]['path'];
1498 }
1499
1500 return $url;
1501 }
1502
1503
1504
1505 /**
1506 * Installs (activates) an extension
1507 *
1508 * For $mode use the three constants EM_INSTALL_VERSION_MIN, EM_INSTALL_VERSION_MAX, EM_INSTALL_VERSION_STRICT
1509 *
1510 * If an extension is loaded or imported already and the version requirement is matched, it will not be
1511 * fetched from the repository. This means, if you use EM_INSTALL_VERSION_MIN, you will not always get the latest
1512 * version of an extension!
1513 *
1514 * @param string $extKey The extension key to install
1515 * @param string $version A version number that should be installed
1516 * @param int $mode If a version is requested, this determines if it is the min, max or strict version requested
1517 * @return [type] ...
1518 * @todo Make the method able to handle needed interaction somehow (unmatched dependencies)
1519 */
1520 function installExtension($extKey, $version=null, $mode=EM_INSTALL_VERSION_MIN) {
1521 list($inst_list,) = $this->getInstalledExtensions();
1522
1523 // check if it is already installed and loaded with sufficient version
1524 if(isset($inst_list[$extKey])) {
1525 $currentVersion = $inst_list[$extKey]['EM_CONF']['version'];
1526
1527 if(t3lib_extMgm::isLoaded($extKey)) {
1528 if($version===null) {
1529 return array(true, 'Extension already installed and loaded.');
1530 } else {
1531 switch($mode) {
1532 case EM_INSTALL_VERSION_STRICT:
1533 if ($currentVersion == $version) {
1534 return array(true, 'Extension already installed and loaded.');
1535 }
1536 break;
1537 case EM_INSTALL_VERSION_MIN:
1538 if (version_compare($currentVersion, $version, '>=')) {
1539 return array(true, 'Extension already installed and loaded.');
1540 }
1541 break;
1542 case EM_INSTALL_VERSION_MAX:
1543 if (version_compare($currentVersion, $version, '<=')) {
1544 return array(true, 'Extension already installed and loaded.');
1545 }
1546 break;
1547 }
1548 }
1549 } else {
1550 if (!t3lib_extMgm::isLocalconfWritable()) {
1551 return array(false, 'localconf.php is not writable!');
1552 }
1553 $newExtList = -1;
1554 switch($mode) {
1555 case EM_INSTALL_VERSION_STRICT:
1556 if ($currentVersion == $version) {
1557 $newExtList = $this->addExtToList($extKey, $inst_list);
1558 }
1559 break;
1560 case EM_INSTALL_VERSION_MIN:
1561 if (version_compare($currentVersion, $version, '>=')) {
1562 $newExtList = $this->addExtToList($extKey, $inst_list);
1563 }
1564 break;
1565 case EM_INSTALL_VERSION_MAX:
1566 if (version_compare($currentVersion, $version, '<=')) {
1567 $newExtList = $this->addExtToList($extKey, $inst_list);
1568 }
1569 break;
1570 }
1571 if ($newExtList!=-1) {
1572 $this->writeNewExtensionList($newExtList);
1573 $this->refreshGlobalExtList();
1574 $this->forceDBupdates($extKey, $inst_list[$extKey]);
1575 return array(true, 'Extension was already installed, it has been loaded.');
1576 }
1577 }
1578 }
1579
1580 // at this point we know we need to import (a matching version of) the extension from TER2
1581
1582 // see if we have an extensionlist at all
1583 if (!$this->xmlhandler->countExtensions()) {
1584 $this->fetchMetaData('extensions');
1585 }
1586 $this->xmlhandler->searchExtensionsXML($extKey, '', '', true);
1587
1588 // check if extension can be fetched
1589 if(isset($this->xmlhandler->extensionsXML[$extKey])) {
1590 $versions = array_keys($this->xmlhandler->extensionsXML[$extKey]['versions']);
1591 $latestVersion = end($versions);
1592 switch($mode) {
1593 case EM_INSTALL_VERSION_STRICT:
1594 if(!isset($this->xmlhandler->extensionsXML[$extKey]['versions'][$version])) {
1595 return array(false, 'Extension not available in matching version');
1596 }
1597 break;
1598 case EM_INSTALL_VERSION_MIN:
1599 if (version_compare($latestVersion, $version, '>=')) {
1600 $version = $latestVersion;
1601 } else {
1602 return array(false, 'Extension not available in matching version');
1603 }
1604 break;
1605 case EM_INSTALL_VERSION_MAX:
1606 while (($v = array_pop($versions)) && version_compare($v, $version, '>=')) {
1607 // Loop until a version is found
1608 }
1609
1610 if ($v !== null && version_compare($v, $version, '<=')) {
1611 $version = $v;
1612 } else {
1613 return array(false, 'Extension not available in matching version');
1614 }
1615 break;
1616 }
1617 $this->importExtFromRep($extKey, $version, 'L');
1618 $newExtList = $this->addExtToList($extKey, $inst_list);
1619 if ($newExtList!=-1) {
1620 $this->writeNewExtensionList($newExtList);
1621 $this->refreshGlobalExtList();
1622 $this->forceDBupdates($extKey, $inst_list[$extKey]);
1623 $this->installTranslationsForExtension($extKey, $this->getMirrorURL());
1624 return array(true, 'Extension has been imported from repository and loaded.');
1625 } else {
1626 return array(false, 'Extension is in repository, but could not be loaded.');
1627 }
1628 } else {
1629 return array(false, 'Extension not available in repository');
1630 }
1631 }
1632
1633 function refreshGlobalExtList() {
1634 global $TYPO3_LOADED_EXT;
1635
1636 $TYPO3_LOADED_EXT = t3lib_extMgm::typo3_loadExtensions();
1637 if ($TYPO3_LOADED_EXT['_CACHEFILE']) {
1638 require(PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_localconf.php');
1639 }
1640 return;
1641
1642 $GLOBALS['TYPO3_LOADED_EXT'] = t3lib_extMgm::typo3_loadExtensions();
1643 if ($TYPO3_LOADED_EXT['_CACHEFILE']) {
1644 require(PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_localconf.php');
1645 } else {
1646 $temp_TYPO3_LOADED_EXT = $TYPO3_LOADED_EXT;
1647 reset($temp_TYPO3_LOADED_EXT);
1648 while(list($_EXTKEY,$temp_lEDat)=each($temp_TYPO3_LOADED_EXT)) {
1649 if (is_array($temp_lEDat) && $temp_lEDat['ext_localconf.php']) {
1650 $_EXTCONF = $TYPO3_CONF_VARS['EXT']['extConf'][$_EXTKEY];
1651 require($temp_lEDat['ext_localconf.php']);
1652 }
1653 }
1654 }
1655 }
1656
1657
1658 /**
1659 * Imports an extensions from the online repository
1660 * NOTICE: in version 4.0 this changed from "importExtFromRep_old($extRepUid,$loc,$uploadFlag=0,$directInput='',$recentTranslations=0,$incManual=0,$dontDelete=0)"
1661 *
1662 * @param string Extension key
1663 * @param string Version
1664 * @param string Install scope: "L" or "G" or "S"
1665 * @param boolean If true, extension is uploaded as file
1666 * @param boolean If true, extension directory+files will not be deleted before writing the new ones. That way custom files stored in the extension folder will be kept.
1667 * @param array Direct input array (like from kickstarter)
1668 * @return string Return false on success, returns error message if error.
1669 */
1670 function importExtFromRep($extKey,$version,$loc,$uploadFlag=0,$dontDelete=0,$directInput='') {
1671
1672 $uploadSucceed = false;
1673 $uploadedTempFile = '';
1674 if (is_array($directInput)) {
1675 $fetchData = array($directInput,'');
1676 $loc = ($loc==='G'||$loc==='S') ? $loc : 'L';
1677 } elseif ($uploadFlag) {
1678 if (($uploadedTempFile = $this->CMD['alreadyUploaded']) || $_FILES['upload_ext_file']['tmp_name']) {
1679
1680 // Read uploaded file:
1681 if (!$uploadedTempFile) {
1682 if (!is_uploaded_file($_FILES['upload_ext_file']['tmp_name'])) {
1683 t3lib_div::sysLog('Possible file upload attack: '.$_FILES['upload_ext_file']['tmp_name'], 'Extension Manager', 3);
1684
1685 return 'File was not uploaded?!?';
1686 }
1687
1688 $uploadedTempFile = t3lib_div::upload_to_tempfile($_FILES['upload_ext_file']['tmp_name']);
1689 }
1690 $fileContent = t3lib_div::getUrl($uploadedTempFile);
1691
1692 if (!$fileContent) return 'File is empty!';
1693
1694 // Decode file data:
1695 $fetchData = $this->terConnection->decodeExchangeData($fileContent);
1696
1697 if (is_array($fetchData)) {
1698 $extKey = $fetchData[0]['extKey'];
1699 if ($extKey) {
1700 if (!$this->CMD['uploadOverwrite']) {
1701 $loc = ($loc==='G'||$loc==='S') ? $loc : 'L';
1702 $comingExtPath = PATH_site.$this->typePaths[$loc].$extKey.'/';
1703 if (@is_dir($comingExtPath)) {
1704 return 'Extension was already present in "'.$comingExtPath.'" - and the overwrite flag was not set! So nothing done...';
1705 } // ... else go on, install...
1706 } // ... else go on, install...
1707 } else return 'No extension key in file. Strange...';
1708 } else return 'Wrong file format. No data recognized, '.$fetchData;
1709 } else return 'No file uploaded! Probably the file was too large for PHPs internal limit for uploadable files.';
1710 } else {
1711 $this->xmlhandler->searchExtensionsXML($extKey, '', '', true);
1712
1713 // Fetch extension from TER:
1714 if(!strlen($version)) {
1715 $versions = array_keys($this->xmlhandler->extensionsXML[$extKey]['versions']);
1716 $version = end($versions);
1717 }
1718 $fetchData = $this->terConnection->fetchExtension($extKey, $version, $this->xmlhandler->extensionsXML[$extKey]['versions'][$version]['t3xfilemd5'], $this->getMirrorURL());
1719 }
1720
1721 // At this point the extension data should be present; so we want to write it to disc:
1722 if ($this->importAsType($loc)) {
1723 if (is_array($fetchData)) { // There was some data successfully transferred
1724 if ($fetchData[0]['extKey'] && is_array($fetchData[0]['FILES'])) {
1725 $extKey = $fetchData[0]['extKey'];
1726 if(!isset($fetchData[0]['EM_CONF']['constraints'])) $fetchData[0]['EM_CONF']['constraints'] = $this->xmlhandler->extensionsXML[$extKey]['versions'][$version]['dependencies'];
1727 $EM_CONF = $this->fixEMCONF($fetchData[0]['EM_CONF']);
1728 if (!$EM_CONF['lockType'] || !strcmp($EM_CONF['lockType'],$loc)) {
1729 // check dependencies, act accordingly if ext is loaded
1730 list($instExtInfo,)=$this->getInstalledExtensions();
1731 $depStatus = $this->checkDependencies($extKey, $EM_CONF, $instExtInfo);
1732 if(t3lib_extMgm::isLoaded($extKey) && !$depStatus['returnCode']) {
1733 $this->content .= $depStatus['html'];
1734 if ($uploadedTempFile) {
1735 $this->content .= '<input type="hidden" name="CMD[alreadyUploaded]" value="'.$uploadedTempFile.'" />';
1736 }
1737 } else {
1738 $res = $this->clearAndMakeExtensionDir($fetchData[0],$loc,$dontDelete);
1739 if (is_array($res)) {
1740 $extDirPath = trim($res[0]);
1741 if ($extDirPath && @is_dir($extDirPath) && substr($extDirPath,-1)=='/') {
1742
1743 $emConfFile = $this->construct_ext_emconf_file($extKey,$EM_CONF);
1744 $dirs = $this->extractDirsFromFileList(array_keys($fetchData[0]['FILES']));
1745
1746 $res = $this->createDirsInPath($dirs,$extDirPath);
1747 if (!$res) {
1748 $writeFiles = $fetchData[0]['FILES'];
1749 $writeFiles['ext_emconf.php']['content'] = $emConfFile;
1750 $writeFiles['ext_emconf.php']['content_md5'] = md5($emConfFile);
1751
1752 // Write files:
1753 foreach($writeFiles as $theFile => $fileData) {
1754 t3lib_div::writeFile($extDirPath.$theFile,$fileData['content']);
1755 if (!@is_file($extDirPath.$theFile)) {
1756 $content.='Error: File "'.$extDirPath.$theFile.'" could not be created!!!<br />';
1757 } elseif (md5(t3lib_div::getUrl($extDirPath.$theFile)) != $fileData['content_md5']) {
1758 $content.='Error: File "'.$extDirPath.$theFile.'" MD5 was different from the original files MD5 - so the file is corrupted!<br />';
1759 }
1760 }
1761
1762 // No content, no errors. Create success output here:
1763 if (!$content) {
1764 $content='SUCCESS: '.$extDirPath.'<br />';
1765
1766 $uploadSucceed = true;
1767
1768 // Fix TYPO3_MOD_PATH for backend modules in extension:
1769 $modules = t3lib_div::trimExplode(',',$EM_CONF['module'],1);
1770 if (count($modules)) {
1771 foreach($modules as $mD) {
1772 $confFileName = $extDirPath.$mD.'/conf.php';
1773 if (@is_file($confFileName)) {
1774 $content.= $this->writeTYPO3_MOD_PATH($confFileName,$loc,$extKey.'/'.$mD.'/').'<br />';
1775 } else $content.='Error: Couldn\'t find "'.$confFileName.'"<br />';
1776 }
1777 }
1778 // NOTICE: I used two hours trying to find out why a script, ext_emconf.php, written twice and in between included by PHP did not update correct the second time. Probably something with PHP-A cache and mtime-stamps.
1779 // But this order of the code works.... (using the empty Array with type, EMCONF and files hereunder).
1780
1781 // Writing to ext_emconf.php:
1782 $sEMD5A = $this->serverExtensionMD5Array($extKey,array('type' => $loc, 'EM_CONF' => array(), 'files' => array()));
1783 $EM_CONF['_md5_values_when_last_written'] = serialize($sEMD5A);
1784 $emConfFile = $this->construct_ext_emconf_file($extKey,$EM_CONF);
1785 t3lib_div::writeFile($extDirPath.'ext_emconf.php',$emConfFile);
1786
1787 $content.='ext_emconf.php: '.$extDirPath.'ext_emconf.php<br />';
1788 $content.='Type: '.$loc.'<br />';
1789
1790 // Remove cache files:
1791 if (t3lib_extMgm::isLoaded($extKey)) {
1792 if ($this->removeCacheFiles()) {
1793 $content.='Cache-files are removed and will be re-written upon next hit<br />';
1794 }
1795
1796 list($new_list)=$this->getInstalledExtensions();
1797 $content.=$this->updatesForm($extKey,$new_list[$extKey],1,'index.php?CMD[showExt]='.$extKey.'&SET[singleDetails]=info');
1798 }
1799
1800 // Install / Uninstall:
1801 if(!$this->CMD['standAlone']) {
1802 $content = '<a href="index.php" class="typo3-goBack"><img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/goback.gif','width="14" height="14"').' alt="" /> Go back</a><br />'.$content;
1803 $content.='<h3>Install / Uninstall Extension:</h3>';
1804 $content.= $new_list[$extKey] ?
1805 '<a href="'.htmlspecialchars('index.php?CMD[showExt]='.$extKey.'&CMD[remove]=1&CMD[clrCmd]=1&SET[singleDetails]=info').'">'.$this->removeButton().' Uninstall extension</a>' :
1806 '<a href="'.htmlspecialchars('index.php?CMD[showExt]='.$extKey.'&CMD[load]=1&CMD[clrCmd]=1&SET[singleDetails]=info').'">'.$this->installButton().' Install extension</a>';
1807 } else {
1808 $content = 'Extension has been imported.<br /><br /><a href="javascript:opener.top.content.document.forms[0].submit();window.close();">Close window and recheck dependencies</a>';
1809 }
1810
1811 }
1812 } else $content = $res;
1813 } else $content = 'Error: The extension path "'.$extDirPath.'" was different than expected...';
1814 } else $content = $res;
1815 }
1816 } else $content = 'Error: The extension can only be installed in the path '.$this->typePaths[$EM_CONF['lockType']].' (lockType='.$EM_CONF['lockType'].')';
1817 } else $content = 'Error: No extension key!!! Why? - nobody knows... (Or no files in the file-array...)';
1818 } else $content = 'Error: The datatransfer did not succeed. '.$fetchData;
1819 } else $content = 'Error: Installation is not allowed in this path ('.$this->typePaths[$loc].')';
1820
1821 $this->content.=$this->doc->section('Extension import results',$content,0,1);
1822
1823 if ($uploadSucceed && $uploadedTempFile) {
1824 t3lib_div::unlink_tempfile($uploadedTempFile);
1825 }
1826
1827 return false;
1828 }
1829
1830 /**
1831 * Display extensions details.
1832 *
1833 * @param string Extension key
1834 * @return void Writes content to $this->content
1835 */
1836 function showExtDetails($extKey) {
1837 global $TYPO3_LOADED_EXT;
1838
1839 list($list,)=$this->getInstalledExtensions();
1840 $absPath = $this->getExtPath($extKey,$list[$extKey]['type']);
1841
1842 // Check updateModule:
1843 if (@is_file($absPath.'class.ext_update.php')) {
1844 require_once($absPath.'class.ext_update.php');
1845 $updateObj = new ext_update;
1846 if (!$updateObj->access()) {
1847 unset($this->MOD_MENU['singleDetails']['updateModule']);
1848 }
1849 } else {
1850 unset($this->MOD_MENU['singleDetails']['updateModule']);
1851 }
1852
1853 if($this->CMD['doDelete']) {
1854 $this->MOD_MENU['singleDetails'] = array();
1855 }
1856
1857 // Function menu here:
1858 if(!$this->CMD['standAlone'] && !t3lib_div::_GP('standAlone')) {
1859 $content = '
1860 <table border="0" cellpadding="0" cellspacing="0" width="100%">
1861 <tr>
1862 <td nowrap="nowrap">Extension:&nbsp;<strong>'.$this->extensionTitleIconHeader($extKey,$list[$extKey]).'</strong> ('.$extKey.')</td>
1863 <td align="right" nowrap="nowrap">'.
1864 t3lib_BEfunc::getFuncMenu(0,'SET[singleDetails]',$this->MOD_SETTINGS['singleDetails'],$this->MOD_MENU['singleDetails'],'','&CMD[showExt]='.$extKey).' &nbsp; &nbsp; '.
1865 '<a href="index.php" class="typo3-goBack"><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/goback.gif','width="14" height="14"').' class="absmiddle" alt="" /> Go back</a></td>
1866 </tr>
1867 </table>';
1868 $this->content.=$this->doc->section('',$content);
1869 }
1870
1871 // Show extension details:
1872 if ($list[$extKey]) {
1873
1874 // Checking if a command for install/uninstall is executed:
1875 if (($this->CMD['remove'] || $this->CMD['load']) && !in_array($extKey,$this->requiredExt)) {
1876
1877 // Install / Uninstall extension here:
1878 if (t3lib_extMgm::isLocalconfWritable()) {
1879 // Check dependencies:
1880 $depStatus = $this->checkDependencies($extKey, $list[$extKey]['EM_CONF'], $list);
1881 if(!$this->CMD['remove'] && !$depStatus['returnCode']) {
1882 $this->content .= $depStatus['html'];
1883 $newExtList = -1;
1884 } elseif ($this->CMD['remove']) {
1885 $newExtList = $this->removeExtFromList($extKey,$list);
1886 } else {
1887 $newExtList = $this->addExtToList($extKey,$list);
1888 }
1889
1890 // Success-installation:
1891 if ($newExtList!=-1) {
1892 $updates = '';
1893 if ($this->CMD['load']) {
1894 if($_SERVER['REQUEST_METHOD'] == 'POST') {
1895 $script = t3lib_div::linkThisScript(array('CMD[showExt]' => $extKey, 'CMD[load]' => 1, 'CMD[clrCmd]' => $this->CMD['clrCmd'], 'SET[singleDetails]' => 'info'));
1896 } else {
1897 $script = '';
1898 }
1899 $updates = $this->updatesForm($extKey,$list[$extKey],1,$script,'<input type="hidden" name="_do_install" value="1" /><input type="hidden" name="_clrCmd" value="'.$this->CMD['clrCmd'].'" />');
1900 if ($updates) {
1901 $updates = 'Before the extension can be installed the database needs to be updated with new tables or fields. Please select which operations to perform:'.$updates;
1902 if($this->CMD['standAlone']) $updates .= '<input type="hidden" name="standAlone" value="1" />';
1903 $depsolver = t3lib_div::_POST('depsolver');
1904 if(is_array($depsolver['ignore'])) {
1905 foreach($depsolver['ignore'] as $depK => $depV) {
1906 $updates .= '<input type="hidden" name="depsolver[ignore]['.$depK.']" value="1" />';
1907 }
1908 }
1909
1910 $this->content.=$this->doc->section('Installing '.$this->extensionTitleIconHeader($extKey,$list[$extKey]).strtoupper(': Database needs to be updated'),$updates,1,1,1,1);
1911 }
1912 } elseif ($this->CMD['remove']) {
1913 $updates.= $this->checkClearCache($list[$extKey]);
1914 if ($updates) {
1915 $updates = '
1916 </form><form action="'.t3lib_div::linkThisScript().'" method="post">'.$updates.'
1917 <br /><input type="submit" name="write" value="Remove extension" />
1918 <input type="hidden" name="_do_install" value="1" />
1919 <input type="hidden" name="_clrCmd" value="'.$this->CMD['clrCmd'].'" />
1920 <input type="hidden" name="standAlone" value="'.$this->CMD['standAlone'].'" />
1921 ';
1922 $this->content.=$this->doc->section('Removing '.$this->extensionTitleIconHeader($extKey,$list[$extKey]).strtoupper(': Database needs to be updated'),$updates,1,1,1,1);
1923 }
1924 }
1925 if (!$updates || t3lib_div::_GP('_do_install')) {
1926 $this->writeNewExtensionList($newExtList);
1927 $GLOBALS['BE_USER']->writelog(5,1,0,0,'Extension list has been changed, extension %s has been %s',array($extKey,($this->CMD['load']?'installed':'removed')));
1928 if ($this->CMD['clrCmd'] || t3lib_div::_GP('_clrCmd')) {
1929 $vA = array('CMD'=>'');
1930 } else {
1931 $vA = array('CMD'=>Array('showExt'=>$extKey));
1932 }
1933 if($this->CMD['standAlone'] || t3lib_div::_GP('standAlone')) {
1934 $this->content .= 'Extension has been '.($this->CMD['load'] ? 'installed' : 'removed').'.<br /><br /><a href="javascript:opener.top.content.document.forms[0].submit();window.close();">Close window and recheck dependencies</a>';
1935 } else {
1936 header('Location: '.t3lib_div::linkThisScript($vA));
1937 }
1938 }
1939 }
1940 } else {
1941 $this->content.=$this->doc->section('Installing '.$this->extensionTitleIconHeader($extKey,$list[$extKey]).strtoupper(': Write access error'),'typo3conf/localconf.php seems not to be writable, so the extension cannot be installed automatically!',1,1,2,1);
1942 }
1943
1944 } elseif ($this->CMD['downloadFile'] && !in_array($extKey,$this->requiredExt)) {
1945
1946 // Link for downloading extension has been clicked - deliver content stream:
1947 $dlFile = $this->CMD['downloadFile'];
1948 if (t3lib_div::isFirstPartOfStr($dlFile,PATH_site) && t3lib_div::isFirstPartOfStr($dlFile,$absPath) && @is_file($dlFile)) {
1949 $mimeType = 'application/octet-stream';
1950 Header('Content-Type: '.$mimeType);
1951 Header('Content-Disposition: attachment; filename='.basename($dlFile));
1952 echo t3lib_div::getUrl($dlFile);
1953 exit;
1954 } else die('Error while trying to download extension file...');
1955
1956 } elseif ($this->CMD['editFile'] && !in_array($extKey,$this->requiredExt)) {
1957
1958 // Editing extension file:
1959 $editFile = $this->CMD['editFile'];
1960 if (t3lib_div::isFirstPartOfStr($editFile,PATH_site) && t3lib_div::isFirstPartOfStr($editFile,$absPath)) { // Paranoia...
1961
1962 $fI = t3lib_div::split_fileref($editFile);
1963 if (@is_file($editFile) && t3lib_div::inList($this->editTextExtensions,($fI['fileext']?$fI['fileext']:$fI['filebody']))) {
1964 if (filesize($editFile)<($this->kbMax*1024)) {
1965 $outCode = '';
1966 $info = '';
1967 $submittedContent = t3lib_div::_POST('edit');
1968 $saveFlag = 0;
1969
1970 if(isset($submittedContent['file']) && !$GLOBALS['TYPO3_CONF_VARS']['EXT']['noEdit']) { // Check referer here?
1971 $oldFileContent = t3lib_div::getUrl($editFile);
1972 if($oldFileContent != $submittedContent['file']) {
1973 $oldMD5 = md5(str_replace(chr(13),'',$oldFileContent));
1974 $info.= 'MD5: <b>'.$oldMD5.'</b> (Previous File)<br />';
1975 t3lib_div::writeFile($editFile,$submittedContent['file']);
1976 $saveFlag = 1;
1977 } else {
1978 $info .= 'No changes to the file detected!<br />';
1979 }
1980 }
1981
1982 $fileContent = t3lib_div::getUrl($editFile);
1983
1984 $outCode.= 'File: <b>'.substr($editFile,strlen($absPath)).'</b> ('.t3lib_div::formatSize(filesize($editFile)).')<br />';
1985 $fileMD5 = md5(str_replace(chr(13),'',$fileContent));
1986 $info.= 'MD5: <b>'.$fileMD5.'</b> (Current File)<br />';
1987 if($saveFlag) {
1988 $saveMD5 = md5(str_replace(chr(13),'',$submittedContent['file']));
1989 $info.= 'MD5: <b>'.$saveMD5.'</b> (Submitted)<br />';
1990 if($fileMD5!=$saveMD5) $info .= $GLOBALS['TBE_TEMPLATE']->rfw('<br /><strong>Saving failed, the content was not correctly written to disk. Changes have been lost!</strong>').'<br />';
1991 else $info.= $GLOBALS['TBE_TEMPLATE']->rfw('<br /><strong>File saved.</strong>').'<br />';
1992 }
1993
1994 $outCode.= '<textarea name="edit[file]" rows="35" wrap="off"'.$this->doc->formWidthText(48,'width:98%;height:70%','off').' class="fixed-font enable-tab">'.t3lib_div::formatForTextarea($fileContent).'</textarea>';
1995 $outCode.= '<input type="hidden" name="edit[filename]" value="'.$editFile.'" />';
1996 $outCode.= '<input type="hidden" name="CMD[editFile]" value="'.htmlspecialchars($editFile).'" />';
1997 $outCode.= '<input type="hidden" name="CMD[showExt]" value="'.$extKey.'" />';
1998 $outCode.= $info;
1999
2000 if (!$GLOBALS['TYPO3_CONF_VARS']['EXT']['noEdit']) {
2001 $outCode.='<br /><input type="submit" name="save_file" value="Save file" />';
2002 } else $outCode.=$GLOBALS['TBE_TEMPLATE']->rfw('<br />[SAVING IS DISABLED - can be enabled by the $TYPO3_CONF_VARS[\'EXT\'][\'noEdit\']-flag] ');
2003
2004 $onClick = 'window.location.href=\'index.php?CMD[showExt]='.$extKey.'\';return false;';
2005 $outCode.='<input type="submit" name="cancel" value="Cancel" onclick="'.htmlspecialchars($onClick).'" />';
2006
2007 $theOutput.=$this->doc->spacer(15);
2008 $theOutput.=$this->doc->section('Edit file:','',0,1);
2009 $theOutput.=$this->doc->sectionEnd().$outCode;
2010 $this->content.=$theOutput;
2011 } else {
2012 $theOutput.=$this->doc->spacer(15);
2013 $theOutput.=$this->doc->section('Filesize exceeded '.$this->kbMax.' Kbytes','Files larger than '.$this->kbMax.' KBytes are not allowed to be edited.');
2014 }
2015 }
2016 } else die('Fatal Edit error: File "'.$editFile.'" was not inside the correct path of the TYPO3 Extension!');
2017 } else {
2018
2019 // MAIN:
2020 switch((string)$this->MOD_SETTINGS['singleDetails']) {
2021 case 'info':
2022 // Loaded / Not loaded:
2023 if (!in_array($extKey,$this->requiredExt)) {
2024 if ($TYPO3_LOADED_EXT[$extKey]) {
2025 $content = '<strong>The extension is installed (loaded and running)!</strong><br />'.
2026 '<a href="'.htmlspecialchars('index.php?CMD[showExt]='.$extKey.'&CMD[remove]=1').'">Click here to remove the extension: '.$this->removeButton().'</a>';
2027 } else {
2028 $content = 'The extension is <strong>not</strong> installed yet.<br />'.
2029 '<a href="'.htmlspecialchars('index.php?CMD[showExt]='.$extKey.'&CMD[load]=1').'">Click here to install the extension: '.$this->installButton().'</a>';
2030 }
2031 } else {
2032 $content = 'This extension is entered in the TYPO3_CONF_VARS[SYS][requiredExt] list and is therefore always loaded.';
2033 }
2034 $this->content.=$this->doc->spacer(10);
2035 $this->content.=$this->doc->section('Active status:',$content,0,1);
2036
2037 if (t3lib_extMgm::isLoaded($extKey)) {
2038 $updates=$this->updatesForm($extKey,$list[$extKey]);
2039 if ($updates) {
2040 $this->content.=$this->doc->spacer(10);
2041 $this->content.=$this->doc->section('Update needed:',$updates.'<br /><br />Notice: "Static data" may not <em>need</em> to be updated. You will only have to import static data each time you upgrade the extension.',0,1);
2042 }
2043 }
2044
2045 // Config:
2046 if (@is_file($absPath.'ext_conf_template.txt')) {
2047 $this->content.=$this->doc->spacer(10);
2048 $this->content.=$this->doc->section('Configuration:','(<em>Notice: You may need to clear the cache after configuration of the extension. This is required if the extension adds TypoScript depending on these settings.</em>)<br /><br />',0,1);
2049 $this->tsStyleConfigForm($extKey,$list[$extKey]);
2050 }
2051
2052 // Show details:
2053 $content = t3lib_BEfunc::cshItem('_MOD_tools_em', 'info', $GLOBALS['BACK_PATH'],'|<br/>');
2054 $content.= $this->extInformationArray($extKey,$list[$extKey]);
2055
2056 $this->content.=$this->doc->spacer(10);
2057 $this->content.=$this->doc->section('Details:',$content,0,1);
2058 break;
2059 case 'upload':
2060 $em = t3lib_div::_POST('em');
2061 if($em['action'] == 'doUpload') {
2062 $em['extKey'] = $extKey;
2063 $em['extInfo'] = $list[$extKey];
2064 $content = $this->uploadExtensionToTER($em);
2065 $content .= $this->doc->spacer(10);
2066 // Must reload this, because EM_CONF information has been updated!
2067 list($list,)=$this->getInstalledExtensions();
2068 } else {
2069 // CSH:
2070 $content = t3lib_BEfunc::cshItem('_MOD_tools_em', 'upload', $GLOBALS['BACK_PATH'],'|<br/>');
2071
2072 // Upload:
2073 if (substr($extKey,0,5)!='user_') {
2074 $content.= $this->getRepositoryUploadForm($extKey,$list[$extKey]);
2075 $eC=0;
2076 } else {
2077 $content.='The extensions has an extension key prefixed "user_" which indicates that it is a user-defined extension with no official unique identification. Therefore it cannot be uploaded.';
2078 $eC=2;
2079 }
2080 if (!$this->fe_user['username']) {
2081 $content.= '<br /><br /><img src="'.$GLOBALS['BACK_PATH'].'gfx/icon_note.gif" width="18" height="16" align="top" alt="" />You have not configured a default username/password yet. <a href="index.php?SET[function]=3">Go to "Settings"</a> if you want to do that.<br />';
2082 }
2083 }
2084 $this->content.=$this->doc->section('Upload extension to repository',$content,0,1,$eC);
2085 break;
2086 case 'backup':
2087 if($this->CMD['doDelete']) {
2088 $content = $this->extDelete($extKey,$list[$extKey]);
2089 $this->content.=$this->doc->section('Delete',$content,0,1);
2090 } else {
2091 $content = t3lib_BEfunc::cshItem('_MOD_tools_em', 'backup_delete', $GLOBALS['BACK_PATH'],'|<br/>');
2092 $content.= $this->extBackup($extKey,$list[$extKey]);
2093 $this->content.=$this->doc->section('Backup',$content,0,1);
2094
2095 $content = $this->extDelete($extKey,$list[$extKey]);
2096 $this->content.=$this->doc->section('Delete',$content,0,1);
2097
2098 $content = $this->extUpdateEMCONF($extKey,$list[$extKey]);
2099 $this->content.=$this->doc->section('Update EM_CONF',$content,0,1);
2100 }
2101 break;
2102 case 'dump':
2103 $this->extDumpTables($extKey,$list[$extKey]);
2104 break;
2105 case 'edit':
2106 $content = t3lib_BEfunc::cshItem('_MOD_tools_em', 'editfiles', $GLOBALS['BACK_PATH'],'|<br/>');
2107 $content.= $this->getFileListOfExtension($extKey,$list[$extKey]);
2108
2109 $this->content.=$this->doc->section('Extension files',$content,0,1);
2110 break;
2111 case 'updateModule':
2112 $this->content.=$this->doc->section('Update:',is_object($updateObj) ? $updateObj->main() : 'No update object',0,1);
2113 break;
2114 default:
2115 $this->extObjContent();
2116 break;
2117 }
2118 }
2119 }
2120 }
2121
2122 /**
2123 * Outputs a screen from where you can install multiple extensions in one go
2124 * This can be called from external modules with "...index.php?CMD[requestInstallExtensions]=
2125 *
2126 * @param string Comma list of extension keys to install. Renders a screen with checkboxes for all extensions not already imported or installed
2127 * @return void
2128 */
2129 function requestInstallExtensions($extList) {
2130
2131 // Return URL:
2132 $returnUrl = t3lib_div::_GP('returnUrl');
2133 $installOrImportExtension = t3lib_div::_POST('installOrImportExtension');
2134
2135 // Extension List:
2136 $extArray = explode(',',$extList);
2137 $outputRow = array();
2138 $outputRow[] = '
2139 <tr class="bgColor5 tableheader">
2140 <td>Install/Import:</td>
2141 <td>Extension Key:</td>
2142 </tr>
2143 ';
2144
2145 foreach($extArray as $extKey) {
2146
2147 // Check for the request:
2148 if ($installOrImportExtension[$extKey]) {
2149 $this->installExtension($extKey);
2150 }
2151
2152 // Display:
2153 if (!t3lib_extMgm::isLoaded($extKey)) {
2154 $outputRow[] = '
2155 <tr class="bgColor4">
2156 <td><input type="checkbox" name="'.htmlspecialchars('installOrImportExtension['.$extKey.']').'" value="1" checked="checked" /></td>
2157 <td>'.htmlspecialchars($extKey).'</td>
2158 </tr>
2159 ';
2160 }
2161 }
2162
2163 if (count($outputRow)>1 || !$returnUrl) {
2164 $content = '
2165 </form> <!-- ending page form ... -->
2166 <form action="'.htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')).'" method="post">
2167 <table border="0" cellpadding="1" cellspacing="1">'.implode('',$outputRow).'</table>
2168 <input type="submit" name="_" value="Import and Install selected" />
2169 </form>
2170 <form> <!-- continuing page form... -->';
2171
2172 if ($returnUrl) {
2173 $content.= '
2174 <br/>
2175 <br/>
2176 <a href="'.htmlspecialchars($returnUrl).'">Return</a>
2177 ';
2178 }
2179
2180 $this->content.= $this->doc->section('Import/Install Extensions:',$content,0,1);
2181 } else {
2182 header('Location: '.t3lib_div::locationHeaderUrl($returnUrl));
2183 }
2184 }
2185
2186
2187
2188
2189
2190
2191
2192
2193 /***********************************
2194 *
2195 * Application Sub-functions (HTML parts)
2196 *
2197 **********************************/
2198
2199 /**
2200 * Creates a form for an extension which contains all options for configuration, updates of database, clearing of cache etc.
2201 * This form is shown when
2202 *
2203 * @param string Extension key
2204 * @param array Extension information array
2205 * @param boolean If set, the form will ONLY show if fields/tables should be updated (suppressing forms like general configuration and cache clearing).
2206 * @param string Alternative action=""-script
2207 * @param string HTML: Additional form fields
2208 * @return string HTML
2209 */
2210 function updatesForm($extKey,$extInfo,$notSilent=0,$script='',$addFields='') {
2211 $script = $script ? $script : t3lib_div::linkThisScript();
2212 $updates.= $this->checkDBupdates($extKey,$extInfo);
2213 $uCache = $this->checkClearCache($extInfo);
2214 if ($notSilent) $updates.= $uCache;
2215 $updates.= $this->checkUploadFolder($extKey,$extInfo);
2216
2217 $absPath = $this->getExtPath($extKey,$extInfo['type']);
2218 if ($notSilent && @is_file($absPath.'ext_conf_template.txt')) {
2219 $cForm = $this->tsStyleConfigForm($extKey,$extInfo,1,$script,$updates.$addFields.'<br />');
2220 }
2221
2222 if ($updates || $cForm) {
2223 if ($cForm) {
2224 $updates = '</form>'.$cForm.'<form>';
2225 } else {
2226 $updates = '</form><form action="'.htmlspecialchars($script).'" method="post">'.$updates.$addFields.'
2227 <br /><input type="submit" name="write" value="Make updates" />
2228 ';
2229 }
2230 }
2231 return $updates;
2232 }
2233
2234 /**
2235 * Creates view for dumping static tables and table/fields structures...
2236 *
2237 * @param string Extension key
2238 * @param array Extension information array
2239 * @return void
2240 */
2241 function extDumpTables($extKey,$extInfo) {
2242
2243 // Get dbInfo which holds the structure known from the tables.sql file
2244 $techInfo = $this->makeDetailedExtensionAnalysis($extKey,$extInfo);
2245 $absPath = $this->getExtPath($extKey,$extInfo['type']);
2246
2247 // Static tables:
2248 if (is_array($techInfo['static'])) {
2249 if ($this->CMD['writeSTATICdump']) { // Writing static dump:
2250 $writeFile = $absPath.'ext_tables_static+adt.sql';
2251 if (@is_file($writeFile)) {
2252 $dump_static = $this->dumpStaticTables(implode(',',$techInfo['static']));
2253 t3lib_div::writeFile($writeFile,$dump_static);
2254 $this->content.=$this->doc->section('Table and field structure required',t3lib_div::formatSize(strlen($dump_static)).'bytes written to '.substr($writeFile,strlen(PATH_site)),0,1);
2255 }
2256 } else { // Showing info about what tables to dump - and giving the link to execute it.
2257 $msg = 'Dumping table content for static tables:<br />';
2258 $msg.= '<br />'.implode('<br />',$techInfo['static']).'<br />';
2259
2260 // ... then feed that to this function which will make new CREATE statements of the same fields but based on the current database content.
2261 $this->content.=$this->doc->section('Static tables',$msg.'<hr /><strong><a href="'.htmlspecialchars('index.php?CMD[showExt]='.$extKey.'&CMD[writeSTATICdump]=1').'">Write current static table contents to ext_tables_static+adt.sql now!</a></strong>',0,1);
2262 $this->content.=$this->doc->spacer(20);
2263 }
2264 }
2265
2266 // Table and field definitions:
2267 if (is_array($techInfo['dump_tf'])) {
2268 $dump_tf_array = $this->getTableAndFieldStructure($techInfo['dump_tf']);
2269 $dump_tf = $this->dumpTableAndFieldStructure($dump_tf_array);
2270 if ($this->CMD['writeTFdump']) {
2271 $writeFile = $absPath.'ext_tables.sql';
2272 if (@is_file($writeFile)) {
2273 t3lib_div::writeFile($writeFile,$dump_tf);
2274 $this->content.=$this->doc->section('Table and field structure required',t3lib_div::formatSize(strlen($dump_tf)).'bytes written to '.substr($writeFile,strlen(PATH_site)),0,1);
2275 }
2276 } else {
2277 $msg = 'Dumping current database structure for:<br />';
2278 if (is_array($techInfo['tables'])) {
2279 $msg.= '<br /><strong>Tables:</strong><br />'.implode('<br />',$techInfo['tables']).'<br />';
2280 }
2281 if (is_array($techInfo['fields'])) {
2282 $msg.= '<br /><strong>Solo-fields:</strong><br />'.implode('<br />',$techInfo['fields']).'<br />';
2283 }
2284
2285 // ... then feed that to this function which will make new CREATE statements of the same fields but based on the current database content.
2286 $this->content.=$this->doc->section('Table and field structure required',$msg.'<hr /><strong><a href="'.htmlspecialchars('index.php?CMD[showExt]='.$extKey.'&CMD[writeTFdump]=1').'">Write this dump to ext_tables.sql now!</a></strong><hr />
2287 <pre>'.htmlspecialchars($dump_tf).'</pre>',0,1);
2288
2289
2290 $details = ' This dump is based on two factors:<br />
2291 <ul>
2292 <li>1) All tablenames in ext_tables.sql which are <em>not</em> found in the "modify_tables" list in ext_emconf.php are dumped with the current database structure.</li>
2293 <li>2) For any tablenames which <em>are</em> listed in "modify_tables" all fields and keys found for the table in ext_tables.sql will be re-dumped with the fresh equalents from the database.</li>
2294 </ul>
2295 Bottomline is: Whole tables are dumped from database with no regard to which fields and keys are defined in ext_tables.sql. But for tables which are only modified, any NEW fields added to the database must in some form or the other exist in the ext_tables.sql file as well.<br />';
2296 $this->content.=$this->doc->section('',$details);
2297 }
2298 }
2299 }
2300
2301 /**
2302 * Returns file-listing of an extension
2303 *
2304 * @param string Extension key
2305 * @param array Extension information array
2306 * @return string HTML table.
2307 */
2308 function getFileListOfExtension($extKey,$conf) {
2309 $content = '';
2310 $extPath = $this->getExtPath($extKey,$conf['type']);
2311
2312 if ($extPath) {
2313 // Read files:
2314 $fileArr = array();
2315 $fileArr = t3lib_div::getAllFilesAndFoldersInPath($fileArr,$extPath,'',0,99,$this->excludeForPackaging);
2316
2317 // Start table:
2318 $lines = array();
2319 $totalSize = 0;
2320
2321 // Header:
2322 $lines[] = '
2323 <tr class="bgColor5">
2324 <td>File:</td>
2325 <td>Size:</td>
2326 <td>Edit:</td>
2327 </tr>';
2328
2329 foreach($fileArr as $file) {
2330 $fI = t3lib_div::split_fileref($file);
2331 $lines[] = '
2332 <tr class="bgColor4">
2333 <td><a href="'.htmlspecialchars('index.php?CMD[showExt]='.$extKey.'&CMD[downloadFile]='.rawurlencode($file)).'" title="Download...">'.substr($file,strlen($extPath)).'</a></td>
2334 <td>'.t3lib_div::formatSize(filesize($file)).'</td>
2335 <td>'.(!in_array($extKey,$this->requiredExt)&&t3lib_div::inList($this->editTextExtensions,($fI['fileext']?$fI['fileext']:$fI['filebody']))?'<a href="'.htmlspecialchars('index.php?CMD[showExt]='.$extKey.'&CMD[editFile]='.rawurlencode($file)).'">Edit file</a>':'').'</td>
2336 </tr>';
2337 $totalSize+=filesize($file);
2338 }
2339
2340 $lines[] = '
2341 <tr class="bgColor6">
2342 <td><strong>Total:</strong></td>
2343 <td><strong>'.t3lib_div::formatSize($totalSize).'</strong></td>
2344 <td>&nbsp;</td>
2345 </tr>';
2346
2347 $content = '
2348 Path: '.$extPath.'<br /><br />
2349 <table border="0" cellpadding="1" cellspacing="2">'.implode('',$lines).'</table>';
2350 }
2351
2352 return $content;
2353 }
2354
2355 /**
2356 * Delete extension from the file system
2357 *
2358 * @param string Extension key
2359 * @param array Extension info array
2360 * @return string Returns message string about the status of the operation
2361 */
2362 function extDelete($extKey,$extInfo) {
2363 $absPath = $this->getExtPath($extKey,$extInfo['type']);
2364 if (t3lib_extMgm::isLoaded($extKey)) {
2365 return 'This extension is currently installed (loaded and active) and so cannot be deleted!';
2366 } elseif (!$this->deleteAsType($extInfo['type'])) {
2367 return 'You cannot delete (and install/update) extensions in the '.$this->typeLabels[$extInfo['type']].' scope.';
2368 } elseif (t3lib_div::inList('G,L',$extInfo['type'])) {
2369 if ($this->CMD['doDelete'] && !strcmp($absPath,$this->CMD['absPath'])) {
2370 $res = $this->removeExtDirectory($absPath);
2371 if ($res) {
2372 return 'ERROR: Could not remove extension directory "'.$absPath.'". Had the following errors:<br /><br />'.
2373 nl2br($res);
2374 } else {
2375 return 'Removed extension in path "'.$absPath.'"!';
2376 }
2377 } else {
2378 $onClick = "if (confirm('Are you sure you want to delete this extension from the server?')) {window.location.href='index.php?CMD[showExt]=".$extKey.'&CMD[doDelete]=1&CMD[absPath]='.rawurlencode($absPath)."';}";
2379 $content.= '<a href="#" onclick="'.htmlspecialchars($onClick).' return false;"><strong>DELETE EXTENSION FROM SERVER</strong> (in the "'.$this->typeLabels[$extInfo['type']].'" location "'.substr($absPath,strlen(PATH_site)).'")!</a>';
2380 $content.= '<br /><br />(Maybe you should make a backup first, see above.)';
2381 return $content;
2382 }
2383 } else return 'Extension is not a global or local extension and cannot be removed.';
2384 }
2385
2386 /**
2387 * Update extension EM_CONF...
2388 *
2389 * @param string Extension key
2390 * @param array Extension information array
2391 * @return string HTML content.
2392 */
2393 function extUpdateEMCONF($extKey,$extInfo) {
2394 $absPath = $this->getExtPath($extKey,$extInfo['type']);
2395 if ($this->CMD['doUpdateEMCONF']) {
2396 return $this->updateLocalEM_CONF($extKey,$extInfo);
2397 } else {
2398 $onClick = "if (confirm('Are you sure you want to update EM_CONF?')) {window.location.href='index.php?CMD[showExt]=".$extKey."&CMD[doUpdateEMCONF]=1';}";
2399 $content.= '<a href="#" onclick="'.htmlspecialchars($onClick).' return false;"><strong>Update extension EM_CONF file</strong> (in the "'.$this->typeLabels[$extInfo['type']].'" location "'.substr($absPath,strlen(PATH_site)).'")!</a>';
2400 $content.= '<br /><br />If files are changed, added or removed to an extension this is normally detected and displayed so you know that this extension has been locally altered and may need to be uploaded or at least not overridden.<br />
2401 Updating this file will first of all reset this registration.';
2402 return $content;
2403 }
2404 }
2405
2406 /**
2407 * Download extension as file / make backup
2408 *
2409 * @param string Extension key
2410 * @param array Extension information array
2411 * @return string HTML content
2412 */
2413 function extBackup($extKey,$extInfo) {
2414 $uArr = $this->makeUploadArray($extKey,$extInfo);
2415 if (is_array($uArr)) {
2416 $backUpData = $this->terConnection->makeUploadDataFromArray($uArr);
2417 $filename = 'T3X_'.$extKey.'-'.str_replace('.','_',$extInfo['EM_CONF']['version']).'-z-'.date('YmdHi').'.t3x';
2418 if (intval($this->CMD['doBackup'])==1) {
2419 header('Content-Type: application/octet-stream');
2420 header('Content-Disposition: attachment; filename='.$filename);
2421 echo $backUpData;
2422 exit;
2423 } elseif ($this->CMD['dumpTables']) {
2424 $filename='T3X_'.$extKey;
2425 $cTables = count(explode(',',$this->CMD['dumpTables']));
2426 if ($cTables>1) {
2427 $filename.='-'.$cTables.'tables';
2428 } else {
2429 $filename.='-'.$this->CMD['dumpTables'];
2430 }
2431 $filename.='+adt.sql';
2432
2433 header('Content-Type: application/octet-stream');
2434 header('Content-Disposition: attachment; filename='.$filename);
2435 echo $this->dumpStaticTables($this->CMD['dumpTables']);
2436 exit;
2437 } else {
2438 $techInfo = $this->makeDetailedExtensionAnalysis($extKey,$extInfo);
2439 $lines=array();
2440 $lines[]='<tr class="bgColor5"><td colspan="2"><strong>Make selection:</strong></td></tr>';
2441 $lines[]='<tr class="bgColor4"><td><strong>Extension files:</strong></td><td>'.
2442 '<a href="'.htmlspecialchars('index.php?CMD[doBackup]=1&CMD[showExt]='.$extKey).'">Download extension "'.$extKey.'" as a file</a><br />('.$filename.', '.t3lib_div::formatSize(strlen($backUpData)).', MD5: '.md5($backUpData).')<br /></td></tr>';
2443
2444 if (is_array($techInfo['tables'])) { $lines[]='<tr class="bgColor4"><td><strong>Data tables:</strong></td><td>'.$this->extBackup_dumpDataTablesLine($techInfo['tables'],$extKey).'</td></tr>'; }
2445 if (is_array($techInfo['static'])) { $lines[]='<tr class="bgColor4"><td><strong>Static tables:</strong></td><td>'.$this->extBackup_dumpDataTablesLine($techInfo['static'],$extKey).'</td></tr>'; }
2446
2447 $content = '<table border="0" cellpadding="2" cellspacing="2">'.implode('',$lines).'</table>';
2448 return $content;
2449 }
2450 } else die('Error...');
2451 }
2452
2453 /**
2454 * Link to dump of database tables
2455 *
2456 * @param string Extension key
2457 * @param array Extension information array
2458 * @return string HTML
2459 */
2460 function extBackup_dumpDataTablesLine($tablesArray,$extKey) {
2461 $tables = array();
2462 $tablesNA = array();
2463
2464 foreach($tablesArray as $tN) {
2465 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', $tN, '');
2466 if (!$GLOBALS['TYPO3_DB']->sql_error()) {
2467 $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
2468 $tables[$tN]='<tr><td>&nbsp;</td><td><a href="'.htmlspecialchars('index.php?CMD[dumpTables]='.rawurlencode($tN).'&CMD[showExt]='.$extKey).'" title="Dump table \''.$tN.'\'">'.$tN.'</a></td><td>&nbsp;&nbsp;&nbsp;</td><td>'.$row[0].' records</td></tr>';
2469 } else {
2470 $tablesNA[$tN]='<tr><td>&nbsp;</td><td>'.$tN.'</td><td>&nbsp;</td><td>Did not exist.</td></tr>';
2471 }
2472 }
2473 $label = '<table border="0" cellpadding="0" cellspacing="0">'.implode('',array_merge($tables,$tablesNA)).'</table>';// Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
2474 if (count($tables)) {
2475 $label = '<a href="'.htmlspecialchars('index.php?CMD[dumpTables]='.rawurlencode(implode(',',array_keys($tables))).'&CMD[showExt]='.$extKey).'" title="Dump all existing tables.">Download all data from:</a><br /><br />'.$label;
2476 } else $label = 'Nothing to dump...<br /><br />'.$label;
2477 return $label;
2478 }
2479
2480 /**
2481 * Prints a table with extension information in it.
2482 *
2483 * @param string Extension key
2484 * @param array Extension information array
2485 * @param boolean If set, the information array shows information for a remote extension in TER, not a local one.
2486 * @return string HTML content.
2487 */
2488 function extInformationArray($extKey,$extInfo,$remote=0) {
2489 $lines=array();
2490 $lines[]='<tr class="bgColor5"><td colspan="2"><strong>General information:</strong></td>'.$this->helpCol('').'</tr>';
2491 $lines[]='<tr class="bgColor4"><td>Title:</td><td>'.$extInfo['EM_CONF']['_icon'].$extInfo['EM_CONF']['title'].'</td>'.$this->helpCol('title').'</tr>';
2492 $lines[]='<tr class="bgColor4"><td>Description:</td><td>'.nl2br(htmlspecialchars($extInfo['EM_CONF']['description'])).'</td>'.$this->helpCol('description').'</tr>';
2493 $lines[]='<tr class="bgColor4"><td>Author:</td><td>'.$this->wrapEmail($extInfo['EM_CONF']['author'].($extInfo['EM_CONF']['author_email'] ? ' <'.$extInfo['EM_CONF']['author_email'].'>' : ''),$extInfo['EM_CONF']['author_email']).($extInfo['EM_CONF']['author_company']?', '.$extInfo['EM_CONF']['author_company']:'').
2494 '</td>'.$this->helpCol('description').'</tr>';
2495
2496 $lines[]='<tr class="bgColor4"><td>Version:</td><td>'.$extInfo['EM_CONF']['version'].'</td>'.$this->helpCol('version').'</tr>';
2497 $lines[]='<tr class="bgColor4"><td>Category:</td><td>'.$this->categories[$extInfo['EM_CONF']['category']].'</td>'.$this->helpCol('category').'</tr>';
2498 $lines[]='<tr class="bgColor4"><td>State:</td><td>'.$this->states[$extInfo['EM_CONF']['state']].'</td>'.$this->helpCol('state').'</tr>';
2499 $lines[]='<tr class="bgColor4"><td>Shy?</td><td>'.($extInfo['EM_CONF']['shy']?'Yes':'').'</td>'.$this->helpCol('shy').'</tr>';
2500 $lines[]='<tr class="bgColor4"><td>Internal?</td><td>'.($extInfo['EM_CONF']['internal']?'Yes':'').'</td>'.$this->helpCol('internal').'</tr>';
2501
2502 $lines[]='<tr class="bgColor4"><td>Depends on:</td><td>'.$this->depToString($extInfo['EM_CONF']['constraints']).'</td>'.$this->helpCol('dependencies').'</tr>';
2503 $lines[]='<tr class="bgColor4"><td>Conflicts with:</td><td>'.$this->depToString($extInfo['EM_CONF']['constraints'],'conflicts').'</td>'.$this->helpCol('dependencies').'</tr>';
2504 $lines[]='<tr class="bgColor4"><td>Suggests:</td><td>'.$this->depToString($extInfo['EM_CONF']['constraints'],'suggests').'</td>'.$this->helpCol('dependencies').'</tr>';
2505 if (!$remote) {
2506 $lines[]='<tr class="bgColor4"><td>Priority:</td><td>'.$extInfo['EM_CONF']['priority'].'</td>'.$this->helpCol('priority').'</tr>';
2507 $lines[]='<tr class="bgColor4"><td>Clear cache?</td><td>'.($extInfo['EM_CONF']['clearCacheOnLoad']?'Yes':'').'</td>'.$this->helpCol('clearCacheOnLoad').'</tr>';
2508 $lines[]='<tr class="bgColor4"><td>Includes modules:</td><td>'.$extInfo['EM_CONF']['module'].'</td>'.$this->helpCol('module').'</tr>';
2509 $lines[]='<tr class="bgColor4"><td>Lock Type?</td><td>'.($extInfo['EM_CONF']['lockType']?$extInfo['EM_CONF']['lockType']:'').'</td>'.$this->helpCol('lockType').'</tr>';
2510 $lines[]='<tr class="bgColor4"><td>Modifies tables:</td><td>'.$extInfo['EM_CONF']['modify_tables'].'</td>'.$this->helpCol('modify_tables').'</tr>';
2511
2512 // Installation status:
2513 $techInfo = $this->makeDetailedExtensionAnalysis($extKey,$extInfo,1);
2514 $lines[]='<tr><td>&nbsp;</td><td></td>'.$this->helpCol('').'</tr>';
2515 $lines[]='<tr class="bgColor5"><td colspan="2"><strong>Installation status:</strong></td>'.$this->helpCol('').'</tr>';
2516 $lines[]='<tr class="bgColor4"><td>Type of install:</td><td>'.$this->typeLabels[$extInfo['type']].' - <em>'.$this->typeDescr[$extInfo['type']].'</em></td>'.$this->helpCol('type').'</tr>';
2517 $lines[]='<tr class="bgColor4"><td>Double installs?</td><td>'.$this->extInformationArray_dbInst($extInfo['doubleInstall'],$extInfo['type']).'</td>'.$this->helpCol('doubleInstall').'</tr>';
2518 if (is_array($extInfo['files'])) {
2519 sort($extInfo['files']);
2520 $lines[]='<tr class="bgColor4"><td>Root files:</td><td>'.implode('<br />',$extInfo['files']).'</td>'.$this->helpCol('rootfiles').'</tr>';
2521 }
2522
2523 if ($techInfo['tables']||$techInfo['static']||$techInfo['fields']) {
2524 if (!$remote && t3lib_extMgm::isLoaded($extKey)) {
2525 $tableStatus = $GLOBALS['TBE_TEMPLATE']->rfw(($techInfo['tables_error']?'<strong>Table error!</strong><br />Probably one or more required fields/tables are missing in the database!':'').
2526 ($techInfo['static_error']?'<strong>Static table error!</strong><br />The static tables are missing or empty!':''));
2527 } else {
2528 $tableStatus = $techInfo['tables_error']||$techInfo['static_error'] ? 'The database will need to be updated when this extension is installed.' : 'All required tables are already in the database!';
2529 }
2530 }
2531
2532 $lines[]='<tr class="bgColor4"><td>Database requirements:</td><td>'.$this->extInformationArray_dbReq($techInfo,1).'</td>'.$this->helpCol('dbReq').'</tr>';
2533 $lines[]='<tr class="bgColor4"><td>Database status:</td><td>'.$tableStatus.'</td>'.$this->helpCol('dbStatus').'</tr>';
2534 $lines[]='<tr class="bgColor4"><td>Flags:</td><td>'.(is_array($techInfo['flags'])?implode('<br />',$techInfo['flags']):'').'</td>'.$this->helpCol('flags').'</tr>';
2535 $lines[]='<tr class="bgColor4"><td>Config template?</td><td>'.($techInfo['conf']?'Yes':'').'</td>'.$this->helpCol('conf').'</tr>';
2536 $lines[]='<tr class="bgColor4"><td>TypoScript files:</td><td>'.(is_array($techInfo['TSfiles'])?implode('<br />',$techInfo['TSfiles']):'').'</td>'.$this->helpCol('TSfiles').'</tr>';
2537 $lines[]='<tr class="bgColor4"><td>Language files:</td><td>'.(is_array($techInfo['locallang'])?implode('<br />',$techInfo['locallang']):'').'</td>'.$this->helpCol('locallang').'</tr>';
2538 $lines[]='<tr class="bgColor4"><td>Upload folder:</td><td>'.($techInfo['uploadfolder']?$techInfo['uploadfolder']:'').'</td>'.$this->helpCol('uploadfolder').'</tr>';
2539 $lines[]='<tr class="bgColor4"><td>Create directories:</td><td>'.(is_array($techInfo['createDirs'])?implode('<br />',$techInfo['createDirs']):'').'</td>'.$this->helpCol('createDirs').'</tr>';
2540 $lines[]='<tr class="bgColor4"><td>Module names:</td><td>'.(is_array($techInfo['moduleNames'])?implode('<br />',$techInfo['moduleNames']):'').'</td>'.$this->helpCol('moduleNames').'</tr>';
2541 $lines[]='<tr class="bgColor4"><td>Class names:</td><td>'.(is_array($techInfo['classes'])?implode('<br />',$techInfo['classes']):'').'</td>'.$this->helpCol('classNames').'</tr>';
2542 $lines[]='<tr class="bgColor4"><td>Code warnings:<br />(developer-relevant)</td><td>'.(is_array($techInfo['errors'])?$GLOBALS['TBE_TEMPLATE']->rfw(implode('<br />',$techInfo['errors'])):'').'</td>'.$this->helpCol('errors').'</tr>';
2543 $lines[]='<tr class="bgColor4"><td>Naming annoyances:<br />(developer-relevant)</td><td>'.(is_array($techInfo['NSerrors']) ? (!t3lib_div::inList($this->nameSpaceExceptions,$extKey)?t3lib_div::view_array($techInfo['NSerrors']):$GLOBALS['TBE_TEMPLATE']->dfw('[exception]')) : '').'</td>'.$this->helpCol('NSerrors').'</tr>';
2544
2545 $currentMd5Array = $this->serverExtensionMD5Array($extKey,$extInfo);
2546 $affectedFiles='';
2547
2548 $msgLines=array();
2549 if (strcmp($extInfo['EM_CONF']['_md5_values_when_last_written'],serialize($currentMd5Array))) {
2550 $msgLines[] = $GLOBALS['TBE_TEMPLATE']->rfw('<br /><strong>A difference between the originally installed version and the current was detected!</strong>');
2551 $affectedFiles = $this->findMD5ArrayDiff($currentMd5Array,unserialize($extInfo['EM_CONF']['_md5_values_when_last_written']));
2552 if (count($affectedFiles)) $msgLines[] = '<br /><strong>Modified files:</strong><br />'.$GLOBALS['TBE_TEMPLATE']->rfw(implode('<br />',$affectedFiles));
2553 }
2554 $lines[]='<tr class="bgColor4"><td>Files changed?</td><td>'.implode('<br />',$msgLines).'</td>'.$this->helpCol('filesChanged').'</tr>';
2555 }
2556
2557 return '<table border="0" cellpadding="1" cellspacing="2">
2558 '.implode('
2559 ',$lines).'
2560 </table>';
2561 }
2562
2563 /**
2564 * Returns HTML with information about database requirements
2565 *
2566 * @param array Technical information array
2567 * @param boolean Table header displayed
2568 * @return string HTML content.
2569 */
2570 function extInformationArray_dbReq($techInfo,$tableHeader=0) {
2571 return nl2br(trim((is_array($techInfo['tables'])?($tableHeader?"\n\n<strong>Tables:</strong>\n":'').implode(chr(10),$techInfo['tables']):'').
2572 (is_array($techInfo['static'])?"\n\n<strong>Static tables:</strong>\n".implode(chr(10),$techInfo['static']):'').
2573 (is_array($techInfo['fields'])?"\n\n<strong>Additional fields:</strong>\n".implode('<hr />',$techInfo['fields']):'')));
2574 }
2575
2576 /**
2577 * Double install warning.
2578 *
2579 * @param string Double-install string, eg. "LG" etc.
2580 * @param string Current scope, eg. "L" or "G" or "S"
2581 * @return string Message