Merge of extension manager for RC1
[Packages/TYPO3.CMS.git] / typo3 / sysext / em / classes / install / class.tx_em_install.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Steffen Kamper (info@sk-typo3.de)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Module: Extension manager, (un-)install extensions
29 *
30 * $Id: class.tx_em_install.php 2073 2010-03-19 10:42:38Z steffenk $
31 *
32 * @author Steffen Kamper <info@sk-typo3.de>
33 */
34
35
36 class tx_em_Install {
37
38 /**
39 * Parent module object
40 *
41 * @var SC_mod_tools_em_index
42 */
43 protected $parentObject;
44
45 /**
46 * Instance of EM API
47 *
48 * @var tx_em_API
49 */
50 protected $api;
51
52 /**
53 *
54 * @var t3lib_install
55 */
56 protected $install;
57
58
59 protected $systemInstall = 0; // If "1" then installs in the sysext directory is allowed. Default: 0
60
61 /**
62 * @var boolean
63 */
64 protected $silentMode;
65
66 /**
67 * Constructor
68 *
69 * @param SC_mod_tools_em_index $parentObject
70 */
71 public function __construct($parentObject = NULL) {
72 $GLOBALS['LANG']->includeLLFile(t3lib_extMgm::extPath('em', 'language/locallang.xml'));
73 $this->parentObject = $parentObject;
74 $this->api = t3lib_div::makeInstance('tx_em_API');
75 $this->install = t3lib_div::makeInstance('t3lib_install');
76 $this->install->INSTALL = t3lib_div::_GP('TYPO3_INSTALL');
77 $this->systemInstall = isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['allowSystemInstall']) && $GLOBALS['TYPO3_CONF_VARS']['EXT']['allowSystemInstall'];
78 }
79
80 /**
81 * Set silent mode to prevent flashmessages
82 *
83 * @param boolean $silentMode
84 * @return void
85 */
86 public function setSilentMode($silentMode) {
87 $this->silentMode = $silentMode ? TRUE : FALSE;
88 }
89
90 /**
91 * Imports the data of an extension from upload
92 *
93 * @param $uploadedTempFile
94 * @param $location
95 * @param bool $uploadOverwrite
96 * @return array
97 */
98 public function uploadExtensionFile($uploadedTempFile, $location, $uploadOverwrite = FALSE) {
99 $error = '';
100 $fileContent = t3lib_div::getUrl($uploadedTempFile);
101 if (!$fileContent) {
102 return array(
103 'success' => FALSE,
104 'error' => $GLOBALS['LANG']->getLL('ext_import_file_empty')
105 );
106 }
107
108 // Decode file data:
109 $terConnection = t3lib_div::makeInstance('tx_em_Connection_Ter', $this);
110 $fetchData = $terConnection->decodeExchangeData($fileContent);
111 if (is_array($fetchData)) {
112 $extKey = $fetchData[0]['extKey'];
113 if ($extKey) {
114 if (!$uploadOverwrite) {
115 $comingExtPath = tx_em_Tools::typePath($location) . $extKey . '/';
116 if (@is_dir($comingExtPath)) {
117 $error = sprintf($GLOBALS['LANG']->getLL('ext_import_ext_present_no_overwrite'), $comingExtPath) .
118 '<br />' . $GLOBALS['LANG']->getLL('ext_import_ext_present_nothing_done');
119
120 } // ... else go on, install...
121 } // ... else go on, install...
122 } else {
123 $error = $GLOBALS['LANG']->getLL('ext_import_no_key');
124 }
125 } else {
126 $error = sprintf($GLOBALS['LANG']->getLL('ext_import_wrong_file_format'), $fetchData);
127 }
128
129 if ($error) {
130 return array(FALSE, $error);
131 } else {
132 return array(TRUE, $fetchData);
133 }
134
135 }
136
137 /**
138 * Installs an extension.
139 *
140 * @param $fetchData
141 * @param $loc
142 * @param $version
143 * @param $uploadedTempFile
144 * @param $dontDelete
145 * @return mixed|string
146 */
147 public function installExtension($fetchData, $loc, $version, $uploadedTempFile, $dontDelete) {
148 $xmlHandler =& $this->parentObject->xmlHandler;
149 $extensionList =& $this->parentObject->extensionList;
150 $extensionDetails =& $this->parentObject->extensionDetails;
151 $content = '';
152
153 if (tx_em_Tools::importAsType($loc)) {
154 if (is_array($fetchData)) { // There was some data successfully transferred
155 if ($fetchData[0]['extKey'] && is_array($fetchData[0]['FILES'])) {
156 $extKey = $fetchData[0]['extKey'];
157 if (!isset($fetchData[0]['EM_CONF']['constraints'])) {
158 $fetchData[0]['EM_CONF']['constraints'] = $xmlHandler->extensionsXML[$extKey]['versions'][$version]['dependencies'];
159 }
160 $EM_CONF = tx_em_Tools::fixEMCONF($fetchData[0]['EM_CONF']);
161 if (!$EM_CONF['lockType'] || !strcmp($EM_CONF['lockType'], $loc)) {
162 // check dependencies, act accordingly if ext is loaded
163 list($instExtInfo,) = $extensionList->getInstalledExtensions();
164 $depStatus = $this->checkDependencies($extKey, $EM_CONF, $instExtInfo);
165 if (t3lib_extMgm::isLoaded($extKey) && !$depStatus['returnCode']) {
166 $content .= $depStatus['html'];
167 if ($uploadedTempFile) {
168 $content .= '<input type="hidden" name="CMD[alreadyUploaded]" value="' . $uploadedTempFile . '" />';
169 }
170 } else {
171 $res = $this->clearAndMakeExtensionDir($fetchData[0], $loc, $dontDelete);
172 if (is_array($res)) {
173 $extDirPath = trim($res[0]);
174 if ($extDirPath && @is_dir($extDirPath) && substr($extDirPath, -1) == '/') {
175
176 $emConfFile = $extensionDetails->construct_ext_emconf_file($extKey, $EM_CONF);
177 $dirs = tx_em_Tools::extractDirsFromFileList(array_keys($fetchData[0]['FILES']));
178
179 $res = tx_em_Tools::createDirsInPath($dirs, $extDirPath);
180 if (!$res) {
181 $writeFiles = $fetchData[0]['FILES'];
182 $writeFiles['ext_emconf.php']['content'] = $emConfFile;
183 $writeFiles['ext_emconf.php']['content_md5'] = md5($emConfFile);
184
185 // Write files:
186 foreach ($writeFiles as $theFile => $fileData) {
187 t3lib_div::writeFile($extDirPath . $theFile, $fileData['content']);
188 if (!@is_file($extDirPath . $theFile)) {
189 $content .= sprintf($GLOBALS['LANG']->getLL('ext_import_file_not_created'),
190 $extDirPath . $theFile) . '<br />';
191 } elseif (md5(t3lib_div::getUrl($extDirPath . $theFile)) != $fileData['content_md5']) {
192 $content .= sprintf($GLOBALS['LANG']->getLL('ext_import_file_corrupted'),
193 $extDirPath . $theFile) . '<br />';
194 }
195 }
196
197 t3lib_div::fixPermissions($extDirPath, TRUE);
198
199 // No content, no errors. Create success output here:
200 if (!$content) {
201 $messageContent = sprintf($GLOBALS['LANG']->getLL('ext_import_success_folder'), $extDirPath) . '<br />';
202
203 $uploadSucceed = true;
204
205 // Fix TYPO3_MOD_PATH for backend modules in extension:
206 $modules = t3lib_div::trimExplode(',', $EM_CONF['module'], 1);
207 if (count($modules)) {
208 foreach ($modules as $mD) {
209 $confFileName = $extDirPath . $mD . '/conf.php';
210 if (@is_file($confFileName)) {
211 $messageContent .= tx_em_Tools::writeTYPO3_MOD_PATH($confFileName, $loc, $extKey . '/' . $mD . '/') . '<br />';
212 } else {
213 $messageContent .= sprintf($GLOBALS['LANG']->getLL('ext_import_no_conf_file'),
214 $confFileName) . '<br />';
215 }
216 }
217 }
218 // 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.
219 // But this order of the code works.... (using the empty Array with type, EMCONF and files hereunder).
220
221 // Writing to ext_emconf.php:
222 $sEMD5A = $extensionDetails->serverExtensionMD5array($extKey, array('type' => $loc, 'EM_CONF' => array(), 'files' => array()));
223 $EM_CONF['_md5_values_when_last_written'] = serialize($sEMD5A);
224 $emConfFile = $extensionDetails->construct_ext_emconf_file($extKey, $EM_CONF);
225 t3lib_div::writeFile($extDirPath . 'ext_emconf.php', $emConfFile);
226
227 $messageContent .= 'ext_emconf.php: ' . $extDirPath . 'ext_emconf.php<br />';
228 $messageContent .= $GLOBALS['LANG']->getLL('ext_import_ext_type') . ' ';
229 $messageContent .= $this->api->typeLabels[$loc] . '<br />';
230 $messageContent .= '<br />';
231
232 // Remove cache files:
233 $updateContent = '';
234 if (t3lib_extMgm::isLoaded($extKey)) {
235 if (t3lib_extMgm::removeCacheFiles()) {
236 $messageContent .= $GLOBALS['LANG']->getLL('ext_import_cache_files_removed') . '<br />';
237 }
238
239 list($new_list) = $this->parentObject->extensionList->getInstalledExtensions();
240 $updateContent = $this->updatesForm($extKey, $new_list[$extKey], 1, t3lib_div::linkThisScript(array(
241 'CMD[showExt]' => $extKey,
242 'SET[singleDetails]' => 'info'
243 )));
244 }
245
246 if (!$this->silentMode) {
247 $flashMessage = t3lib_div::makeInstance(
248 't3lib_FlashMessage',
249 $messageContent,
250 $GLOBALS['LANG']->getLL('ext_import_success')
251 );
252 $content = $flashMessage->render();
253 } else {
254 $content = $updateContent;
255 }
256
257
258 // Install / Uninstall:
259 if (!$this->parentObject->CMD['standAlone']) {
260 $content .= '<h3>' . $GLOBALS['LANG']->getLL('ext_import_install_uninstall') . '</h3>';
261 $content .= $new_list[$extKey] ?
262 '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array(
263 'CMD[showExt]' => $extKey,
264 'CMD[remove]' => 1,
265 'CMD[clrCmd]' => 1,
266 'SET[singleDetails]' => 'info'
267 ))) . '">' .
268 tx_em_Tools::removeButton() . ' ' . $GLOBALS['LANG']->getLL('ext_import_uninstall') . '</a>' :
269 '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array(
270 'CMD[showExt]' => $extKey,
271 'CMD[load]' => 1,
272 'CMD[clrCmd]' => 1,
273 'SET[singleDetails]' => 'info'
274 ))) . '">' .
275 tx_em_Tools::installButton() . ' ' . $GLOBALS['LANG']->getLL('ext_import_install') . '</a>';
276 } else {
277 $content = $GLOBALS['LANG']->getLL('ext_import_imported') .
278 '<br /><br />';
279 if ($this->silentMode) {
280 $content .= '<a id="closewindow" href="javascript:parent.TYPO3.EM.Tools.closeImportWindow();">' . $GLOBALS['LANG']->getLL('ext_import_close') . '</a>';
281 } else {
282 $content .= '<a href="javascript:opener.top.list.iframe.document.forms[0].submit();window.close();">' .
283 $GLOBALS['LANG']->getLL('ext_import_close_check') . '</a>';
284 }
285
286 }
287 }
288 } else {
289 $content = $res;
290 }
291 } else {
292 $content = sprintf($GLOBALS['LANG']->getLL('ext_import_ext_path_different'), $extDirPath);
293 }
294 } else {
295 $content = $res;
296 }
297 }
298 } else {
299 $content = sprintf($GLOBALS['LANG']->getLL('ext_import_ext_only_here'),
300 tx_em_Tools::typePath($EM_CONF['lockType']), $EM_CONF['lockType']);
301 }
302 } else {
303 $content = $GLOBALS['LANG']->getLL('ext_import_no_ext_key_files');
304 }
305 } else {
306 $content = sprintf($GLOBALS['LANG']->getLL('ext_import_data_transfer'), $fetchData);
307 }
308 } else {
309 $content = sprintf($GLOBALS['LANG']->getLL('ext_import_no_install_here'), tx_em_Tools::typePath($loc));
310 }
311
312 return $content;
313 }
314
315 /**
316 *Check extension dependencies
317 *
318 * @param string $extKey
319 * @param array $conf
320 * @param array $instExtInfo
321 * @return array
322 */
323 function checkDependencies($extKey, $conf, $instExtInfo) {
324 $content = '';
325 $depError = false;
326 $depIgnore = false;
327 $msg = array();
328 $depsolver = t3lib_div::_POST('depsolver');
329
330 if (isset($conf['constraints']['depends']) && is_array($conf['constraints']['depends'])) {
331 foreach ($conf['constraints']['depends'] as $depK => $depV) {
332 if ($depsolver['ignore'][$depK]) {
333 $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_ignored'),
334 $depK) . '
335 <input type="hidden" value="1" name="depsolver[ignore][' . $depK . ']" />';
336 $depIgnore = true;
337 continue;
338 }
339 if ($depK == 'php') {
340 if (!$depV) {
341 continue;
342 }
343 $versionRange = tx_em_Tools::splitVersionRange($depV);
344 $phpv = strstr(PHP_VERSION, '-') ? substr(PHP_VERSION, 0, strpos(PHP_VERSION, '-')) : PHP_VERSION; // Linux distributors like to add suffixes, like in 5.1.2-1. Those must be ignored!
345 if ($versionRange[0] != '0.0.0' && version_compare($phpv, $versionRange[0], '<')) {
346 $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_php_too_low'),
347 $phpv, $versionRange[0]);
348 $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $depK . ']" id="checkIgnore_' . $depK . '" />
349 <label for="checkIgnore_' . $depK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_requirement') . '</label>';
350 $depError = true;
351 continue;
352 } elseif ($versionRange[1] != '0.0.0' && version_compare($phpv, $versionRange[1], '>')) {
353 $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_php_too_high'),
354 $phpv, $versionRange[1]);
355 $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $depK . ']" id="checkIgnore_' . $depK . '" />
356 <label for="checkIgnore_' . $depK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_requirement') . '</label>';
357 $depError = true;
358 continue;
359 }
360
361 } elseif ($depK == 'typo3') {
362 if (!$depV) {
363 continue;
364 }
365
366 // if the current TYPO3 version is a development version (like TYPO3 4.4-dev),
367 // then it should behave like TYPO3 4.4.0
368 $t3version = TYPO3_version;
369 if (stripos($t3version, '-dev')
370 || stripos($t3version, '-alpha')
371 || stripos($t3version, '-beta')
372 || stripos($t3version, '-RC')) {
373 // find the last occurence of "-" and replace that part with a ".0"
374 $t3version = substr($t3version, 0, strrpos($t3version, '-')) . '.0';
375 }
376
377 $versionRange = tx_em_Tools::splitVersionRange($depV);
378 if ($versionRange[0] != '0.0.0' && version_compare($t3version, $versionRange[0], '<')) {
379 $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_typo3_too_low'),
380 $t3version, $versionRange[0]);
381 $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $depK . ']" id="checkIgnore_' . $depK . '" />
382 <label for="checkIgnore_' . $depK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_requirement') . '</label>';
383 $depError = true;
384 continue;
385 } elseif ($versionRange[1] != '0.0.0' && version_compare($t3version, $versionRange[1], '>')) {
386 $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_typo3_too_high'),
387 $t3version, $versionRange[1]);
388 $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $depK . ']" id="checkIgnore_' . $depK . '" />
389 <label for="checkIgnore_' . $depK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_requirement') . '</label>';
390 $depError = true;
391 continue;
392 }
393 } elseif (strlen($depK) && !t3lib_extMgm::isLoaded($depK)) { // strlen check for braindead empty dependencies coming from extensions...
394 if (!isset($instExtInfo[$depK])) {
395 $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_ext_not_available'),
396 $depK);
397 $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;' . t3lib_iconWorks::getSpriteIcon('actions-system-extension-import', array('title' => $GLOBALS['LANG']->getLL('checkDependencies_import_ext'))) . '&nbsp;
398 <a href="' . t3lib_div::linkThisUrl($this->parentObject->script, array(
399 'CMD[importExt]' => $depK,
400 'CMD[loc]' => 'L',
401 'CMD[standAlone]' => 1
402 )) . '" target="_blank">' . $GLOBALS['LANG']->getLL('checkDependencies_import_now') . '</a>';
403 $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $depK . ']" id="checkIgnore_' . $depK . '" />
404 <label for="checkIgnore_' . $depK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_ext_requirement') . '</label>';
405 } else {
406 $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_ext_not_installed'),
407 $depK, $instExtInfo[$depK]['EM_CONF']['title']);
408 $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;' . tx_em_Tools::installButton() . '&nbsp;
409 <a href="' . t3lib_div::linkThisUrl($this->parentObject->script, array(
410 'CMD[showExt]' => $depK,
411 'CMD[load]' => 1,
412 'CMD[clrCmd]' => 1,
413 'CMD[standAlone]' => 1,
414 'SET[singleDetails]' => 'info'
415 )) .
416 '" target="_blank">' . $GLOBALS['LANG']->getLL('checkDependencies_install_now') . '</a>';
417 $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $depK . ']" id="checkIgnore_' . $depK . '" />
418 <label for="checkIgnore_' . $depK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_ext_requirement') . '</label>';
419 }
420 $depError = true;
421 } else {
422 $versionRange = tx_em_Tools::splitVersionRange($depV);
423 if ($versionRange[0] != '0.0.0' && version_compare($instExtInfo[$depK]['EM_CONF']['version'], $versionRange[0], '<')) {
424 $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_ext_too_low'),
425 $depK, $instExtInfo[$depK]['EM_CONF']['version'], $versionRange[0]);
426 $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $depK . ']" id="checkIgnore_' . $depK . '" />
427 <label for="checkIgnore_' . $depK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_requirement') . '</label>';
428 $depError = true;
429 continue;
430 } elseif ($versionRange[1] != '0.0.0' && version_compare($instExtInfo[$depK]['EM_CONF']['version'], $versionRange[1], '>')) {
431 $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_ext_too_high'),
432 $depK, $instExtInfo[$depK]['EM_CONF']['version'], $versionRange[1]);
433 $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $depK . ']" id="checkIgnore_' . $depK . '" />
434 <label for="checkIgnore_' . $depK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_requirement') . '</label>';
435 $depError = true;
436 continue;
437 }
438 }
439 }
440 }
441
442 if (($depError || $depIgnore) && $this->parentObject instanceof SC_mod_tools_em_index) {
443 $content .= $this->parentObject->doc->section(
444 $GLOBALS['LANG']->getLL('removeExtFromList_dependency_error'),
445 implode('<br />', $msg), 0, 1, 2
446 );
447 }
448
449 // Check conflicts with other extensions:
450 $conflictError = false;
451 $conflictIgnore = false;
452 $msg = array();
453
454 if (isset($conf['constraints']['conflicts']) && is_array($conf['constraints']['conflicts'])) {
455 foreach ((array) $conf['constraints']['conflicts'] as $conflictK => $conflictV) {
456 if ($depsolver['ignore'][$conflictK]) {
457 $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_conflict_ignored'),
458 $conflictK) . '
459 <input type="hidden" value="1" name="depsolver[ignore][' . $conflictK . ']" />';
460 $conflictIgnore = true;
461 continue;
462 }
463 if (t3lib_extMgm::isLoaded($conflictK)) {
464 $versionRange = tx_em_Tools::splitVersionRange($conflictV);
465 if ($versionRange[0] != '0.0.0' && version_compare($instExtInfo[$conflictK]['EM_CONF']['version'], $versionRange[0], '<')) {
466 continue;
467 }
468 elseif ($versionRange[1] != '0.0.0' && version_compare($instExtInfo[$conflictK]['EM_CONF']['version'], $versionRange[1], '>')) {
469 continue;
470 }
471 $msg[] = sprintf($GLOBALS['LANG']->getLL('checkDependencies_conflict_remove'),
472 $extKey, $conflictK, $instExtInfo[$conflictK]['EM_CONF']['title'], $conflictK, $extKey);
473 $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;' . tx_em_Tools::removeButton() . '&nbsp;
474 <a href="' . htmlspecialchars(t3lib_div::linkThisScript(array(
475 'CMD[showExt]' => $conflictK,
476 'CMD[remove]' => 1,
477 'CMD[clrCmd]' => 1,
478 'CMD[standAlone]' => 1,
479 'SET[singleDetails]' => 'info'
480 ))) .
481 '" target="_blank">' . $GLOBALS['LANG']->getLL('checkDependencies_remove_now') . '</a>';
482 $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $conflictK . ']" id="checkIgnore_' . $conflictK . '" />
483 <label for="checkIgnore_' . $conflictK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_conflict') . '</label>';
484 $conflictError = true;
485 }
486 }
487 }
488 if ($conflictError || $conflictIgnore) {
489 $content .= $this->parentObject->doc->section(
490 $GLOBALS['LANG']->getLL('checkDependencies_conflict_error'), implode('<br />', $msg), 0, 1, 2
491 );
492 }
493
494 // Check suggests on other extensions:
495 if (isset($conf['constraints']['suggests']) && is_array($conf['constraints']['suggests'])) {
496 $suggestion = false;
497 $suggestionIgnore = false;
498 $msg = array();
499 foreach ($conf['constraints']['suggests'] as $suggestK => $suggestV) {
500 if ($depsolver['ignore'][$suggestK]) {
501 $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_suggestion_ignored'),
502 $suggestK) . '
503 <input type="hidden" value="1" name="depsolver[ignore][' . $suggestK . ']" />';
504 $suggestionIgnore = true;
505 continue;
506 }
507 if (!t3lib_extMgm::isLoaded($suggestK)) {
508 if (!isset($instExtInfo[$suggestK])) {
509 $msg[] = sprintf($GLOBALS['LANG']->getLL('checkDependencies_suggest_import'),
510 $suggestK);
511 $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;' . t3lib_iconWorks::getSpriteIcon('actions-system-extension-import', array('title' => $GLOBALS['LANG']->getLL('checkDependencies_import_ext'))) . '&nbsp;
512 <a href="' . t3lib_div::linkThisScript(array(
513 'CMD[importExt]' => $suggestK,
514 'CMD[loc]' => 'L',
515 'CMD[standAlone]' => 1
516 )) . '" target="_blank">' . $GLOBALS['LANG']->getLL('checkDependencies_import_now') . '</a>';
517 $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $suggestK . ']" id="checkIgnore_' . $suggestK . '" />
518 <label for="checkIgnore_' . $suggestK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_suggestion') . '</label>';
519 } else {
520 $msg[] = sprintf($GLOBALS['LANG']->getLL('checkDependencies_suggest_installation'),
521 $suggestK, $instExtInfo[$suggestK]['EM_CONF']['title']);
522 $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;' . tx_em_Tools::installButton() . '&nbsp;
523 <a href="' . htmlspecialchars(t3lib_div::linkThisScript(array(
524 'CMD[showExt]' => $suggestK,
525 'CMD[load]' => 1,
526 'CMD[clrCmd]' => 1,
527 'CMD[standAlone]' => 1,
528 'SET[singleDetails]' => 'info'
529 ))) .
530 '" target="_blank">' . $GLOBALS['LANG']->getLL('checkDependencies_install_now') . '</a>';
531 $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $suggestK . ']" id="checkIgnore_' . $suggestK . '" />
532 <label for="checkIgnore_' . $suggestK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_suggestion') . '</label>';
533 }
534 $suggestion = true;
535 }
536 }
537 if ($suggestion || $suggestionIgnore) {
538 $content .= $this->parentObject->doc->section(
539 sprintf($GLOBALS['LANG']->getLL('checkDependencies_exts_suggested_by_ext'), $extKey),
540 implode('<br />', $msg), 0, 1, 1
541 );
542 }
543 }
544
545 if ($depError || $conflictError || $suggestion) {
546 foreach ($this->parentObject->CMD as $k => $v) {
547 $content .= '<input type="hidden" name="CMD[' . $k . ']" value="' . $v . '" />';
548 }
549 $content .= '<br /><br /><input type="submit" value="' . $GLOBALS['LANG']->getLL('checkDependencies_try_again') . '" />';
550
551 return array(
552 'returnCode' => FALSE,
553 'html' => '<form action="' . $this->parentObject->script . '" method="post" name="depform">' . $content . '</form>');
554 }
555
556 return array(
557 'returnCode' => TRUE
558 );
559 }
560
561
562 /**
563 * Delete extension from the file system
564 *
565 * @param string Extension key
566 * @param array Extension info array
567 * @return string Returns message string about the status of the operation
568 */
569 function extDelete($extKey, $extInfo, $command) {
570 $absPath = tx_em_Tools::getExtPath($extKey, $extInfo['type']);
571 if (t3lib_extMgm::isLoaded($extKey)) {
572 return $GLOBALS['LANG']->getLL('extDelete_ext_active');
573 } elseif (!tx_em_Tools::deleteAsType($extInfo['type'])) {
574 return sprintf($GLOBALS['LANG']->getLL('extDelete_wrong_scope'),
575 $this->api->typeLabels[$extInfo['type']]
576 );
577 } elseif (t3lib_div::inList('G,L', $extInfo['type'])) {
578 if ($command['doDelete'] && !strcmp($absPath, urldecode($command['absPath']))) {
579 $res = $this->removeExtDirectory($absPath);
580 if ($res) {
581 if (!$this->silentMode) {
582 $flashMessage = t3lib_div::makeInstance(
583 't3lib_FlashMessage',
584 nl2br($res),
585 sprintf($GLOBALS['LANG']->getLL('extDelete_remove_dir_failed'), $absPath),
586 t3lib_FlashMessage::ERROR
587 );
588 return $flashMessage->render();
589 }
590 return '';
591 } else {
592 if (!$this->silentMode) {
593 $flashMessage = t3lib_div::makeInstance(
594 't3lib_FlashMessage',
595 sprintf($GLOBALS['LANG']->getLL('extDelete_removed'), $absPath),
596 $GLOBALS['LANG']->getLL('extDelete_removed_header'),
597 t3lib_FlashMessage::OK
598 );
599 return $flashMessage->render();
600 }
601 return '';
602 }
603 } else {
604 $areYouSure = $GLOBALS['LANG']->getLL('extDelete_sure');
605 $deleteFromServer = $GLOBALS['LANG']->getLL('extDelete_from_server');
606 $onClick = "if (confirm('$areYouSure')) {window.location.href='" . t3lib_div::linkThisScript(array(
607 'CMD[showExt]' => $extKey,
608 'CMD[doDelete]' => 1,
609 'CMD[absPath]' => rawurlencode($absPath)
610 )) . "';}";
611 $content .= '<a class="t3-link" href="#" onclick="' . htmlspecialchars($onClick) .
612 ' return false;"><strong>' . $deleteFromServer . '</strong> ' .
613 sprintf($GLOBALS['LANG']->getLL('extDelete_from_location'),
614 $this->api->typeLabels[$extInfo['type']],
615 substr($absPath, strlen(PATH_site))
616 ) . '</a>';
617 $content .= '<br /><br />' . $GLOBALS['LANG']->getLL('extDelete_backup');
618 return $content;
619 }
620 } else {
621 return $GLOBALS['LANG']->getLL('extDelete_neither_global_nor_local');
622 }
623 }
624
625 /**
626 * Removes the extension directory (including content)
627 *
628 * @param string Extension directory to remove (with trailing slash)
629 * @param boolean If set, will leave the extension directory
630 * @return boolean False on success, otherwise error string.
631 */
632 function removeExtDirectory($removePath, $removeContentOnly = 0) {
633 $errors = array();
634 if (@is_dir($removePath) && substr($removePath, -1) == '/' && (
635 t3lib_div::isFirstPartOfStr($removePath, tx_em_Tools::typePath('G')) ||
636 t3lib_div::isFirstPartOfStr($removePath, tx_em_Tools::typePath('L')) ||
637 (t3lib_div::isFirstPartOfStr($removePath, tx_em_Tools::typePath('S')) && $this->systemInstall) ||
638 t3lib_div::isFirstPartOfStr($removePath, PATH_site . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . '_temp_/')) // Playing-around directory...
639 ) {
640
641 // All files in extension directory:
642 $fileArr = t3lib_div::getAllFilesAndFoldersInPath(array(), $removePath, '', 1);
643 if (is_array($fileArr)) {
644
645 // Remove files in dirs:
646 foreach ($fileArr as $removeFile) {
647 if (!@is_dir($removeFile)) {
648 if (@is_file($removeFile) && t3lib_div::isFirstPartOfStr($removeFile, $removePath) && strcmp($removeFile, $removePath)) { // ... we are very paranoid, so we check what cannot go wrong: that the file is in fact within the prefix path!
649 @unlink($removeFile);
650 clearstatcache();
651 if (@is_file($removeFile)) {
652 $errors[] = sprintf($GLOBALS['LANG']->getLL('rmExtDir_could_not_be_deleted'),
653 $removeFile
654 );
655 }
656 } else {
657 $errors[] = sprintf($GLOBALS['LANG']->getLL('rmExtDir_error_file'),
658 $removeFile, $removePath
659 );
660 }
661 }
662 }
663
664 // Remove directories:
665 $remDirs = tx_em_Tools::extractDirsFromFileList(t3lib_div::removePrefixPathFromList($fileArr, $removePath));
666 $remDirs = array_reverse($remDirs); // Must delete outer directories first...
667 foreach ($remDirs as $removeRelDir) {
668 $removeDir = $removePath . $removeRelDir;
669 if (@is_dir($removeDir)) {
670 @rmdir($removeDir);
671 clearstatcache();
672 if (@is_dir($removeDir)) {
673 $errors[] = sprintf($GLOBALS['LANG']->getLL('rmExtDir_error_files_left'),
674 $removeDir
675 );
676 }
677 } else {
678 $errors[] = sprintf($GLOBALS['LANG']->getLL('rmExtDir_error_no_dir'),
679 $removeDir
680 );
681 }
682 }
683
684 // If extension dir should also be removed:
685 if (!$removeContentOnly) {
686 @rmdir($removePath);
687 clearstatcache();
688 if (@is_dir($removePath)) {
689 $errors[] = sprintf($GLOBALS['LANG']->getLL('rmExtDir_error_folders_left'),
690 $removePath
691 );
692 }
693 }
694 } else {
695 $errors[] = $GLOBALS['LANG']->getLL('rmExtDir_error') . ' ' . $fileArr;
696 }
697 } else {
698 $errors[] = $GLOBALS['LANG']->getLL('rmExtDir_error_unallowed_path') . ' ' . $removePath;
699 }
700
701 // Return errors if any:
702 return implode(LF, $errors);
703 }
704
705 /**
706 * Validates the database according to extension requirements
707 * Prints form for changes if any. If none, returns blank. If an update is ordered, empty is returned as well.
708 * DBAL compliant (based on Install Tool code)
709 *
710 * @param string Extension key
711 * @param array Extension information array
712 * @param boolean If true, returns array with info.
713 * @return mixed If $infoOnly, returns array with information. Otherwise performs update.
714 */
715 function checkDBupdates($extKey, $extInfo, $infoOnly = 0) {
716
717
718 $dbStatus = array();
719 $content = '';
720
721 // Updating tables and fields?
722 if (is_array($extInfo['files']) && in_array('ext_tables.sql', $extInfo['files'])) {
723 $path = tx_em_Tools::getExtPath($extKey, $extInfo['type']);
724 $fileContent = t3lib_div::getUrl($path . 'ext_tables.sql');
725
726 $FDfile = $this->install->getFieldDefinitions_fileContent($fileContent);
727 if (count($FDfile)) {
728 $FDdb = $this->install->getFieldDefinitions_database(TYPO3_db);
729 $diff = $this->install->getDatabaseExtra($FDfile, $FDdb);
730 $update_statements = $this->install->getUpdateSuggestions($diff);
731
732 $dbStatus['structure']['tables_fields'] = $FDfile;
733 $dbStatus['structure']['diff'] = $diff;
734
735 // Updating database...
736 if (!$infoOnly && is_array($this->install->INSTALL['database_update'])) {
737 $this->install->performUpdateQueries($update_statements['add'], $this->install->INSTALL['database_update']);
738 $this->install->performUpdateQueries($update_statements['change'], $this->install->INSTALL['database_update']);
739 $this->install->performUpdateQueries($update_statements['create_table'], $this->install->INSTALL['database_update']);
740 } else {
741 $content .= $this->install->generateUpdateDatabaseForm_checkboxes(
742 $update_statements['add'], $GLOBALS['LANG']->getLL('checkDBupdates_add_fields'));
743 $content .= $this->install->generateUpdateDatabaseForm_checkboxes(
744 $update_statements['change'], $GLOBALS['LANG']->getLL('checkDBupdates_changing_fields'), 1, 0, $update_statements['change_currentValue']);
745 $content .= $this->install->generateUpdateDatabaseForm_checkboxes(
746 $update_statements['create_table'], $GLOBALS['LANG']->getLL('checkDBupdates_add_tables'));
747 }
748 }
749 }
750
751 // Importing static tables?
752 if (is_array($extInfo['files']) && in_array('ext_tables_static+adt.sql', $extInfo['files'])) {
753 $fileContent = t3lib_div::getUrl(tx_em_Tools::getExtPath($extKey, $extInfo['type']) . 'ext_tables_static+adt.sql');
754
755 $statements = $this->install->getStatementarray($fileContent, 1);
756 list($statements_table, $insertCount) = $this->install->getCreateTables($statements, 1);
757
758 // Execute import of static table content:
759 if (!$infoOnly && is_array($this->install->INSTALL['database_import'])) {
760
761 // Traverse the tables
762 foreach ($this->install->INSTALL['database_import'] as $table => $md5str) {
763 if ($md5str == md5($statements_table[$table])) {
764 $GLOBALS['TYPO3_DB']->admin_query('DROP TABLE IF EXISTS ' . $table);
765 $GLOBALS['TYPO3_DB']->admin_query($statements_table[$table]);
766
767 if ($insertCount[$table]) {
768 $statements_insert = $this->install->getTableInsertStatements($statements, $table);
769
770 foreach ($statements_insert as $v) {
771 $GLOBALS['TYPO3_DB']->admin_query($v);
772 }
773 }
774 }
775 }
776 } else {
777 $whichTables = $this->install->getListOfTables();
778 if (count($statements_table)) {
779 $out = '';
780 foreach ($statements_table as $table => $definition) {
781 $exist = isset($whichTables[$table]);
782
783 $dbStatus['static'][$table]['exists'] = $exist;
784 $dbStatus['static'][$table]['count'] = $insertCount[$table];
785
786 $out .= '<tr>
787 <td><input type="checkbox" name="TYPO3_INSTALL[database_import][' . $table . ']" checked="checked" value="' . md5($definition) . '" /></td>
788 <td><strong>' . $table . '</strong></td>
789 <td><img src="clear.gif" width="10" height="1" alt="" /></td>
790 <td nowrap="nowrap">' .
791 ($insertCount[$table] ?
792 $GLOBALS['LANG']->getLL('checkDBupdates_rows') . ' ' . $insertCount[$table]
793 : '') .
794 '</td>
795 <td><img src="clear.gif" width="10" height="1" alt="" /></td>
796 <td nowrap="nowrap">' .
797 ($exist ?
798 t3lib_iconWorks::getSpriteIcon('status-dialog-warning') .
799 $GLOBALS['LANG']->getLL('checkDBupdates_table_exists')
800 : '') .
801 '</td>
802 </tr>';
803 }
804 $content .= '
805 <br />
806 <h3>' . $GLOBALS['LANG']->getLL('checkDBupdates_import_static_data') . '</h3>
807 <table border="0" cellpadding="0" cellspacing="0">' . $out . '</table>
808 ';
809 }
810 }
811 }
812
813 // Return array of information if $infoOnly, otherwise content.
814 return $infoOnly ? $dbStatus : $content;
815 }
816
817 /**
818 * Removes the current extension of $type and creates the base folder for the new one (which is going to be imported)
819 *
820 * @param array Data for imported extension
821 * @param string Extension installation scope (L,G,S)
822 * @param boolean If set, nothing will be deleted (neither directory nor files)
823 * @return mixed Returns array on success (with extension directory), otherwise an error string.
824 */
825 function clearAndMakeExtensionDir($importedData, $type, $dontDelete = 0) {
826 if (!$importedData['extKey']) {
827 return $GLOBALS['LANG']->getLL('clearMakeExtDir_no_ext_key');
828 }
829
830 // Setting install path (L, G, S or fileadmin/_temp_/)
831 $path = '';
832 switch ((string) $type) {
833 case 'G':
834 case 'L':
835 $path = tx_em_Tools::typePath($type);
836 $suffix = '';
837
838 // Creates the typo3conf/ext/ directory if it does NOT already exist:
839 if ((string) $type == 'L' && !@is_dir($path)) {
840 t3lib_div::mkdir($path);
841 }
842 break;
843 default:
844 if ($this->systemInstall && (string) $type == 'S') {
845 $path = tx_em_Tools::typePath($type);
846 $suffix = '';
847 } else {
848 $path = PATH_site . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . '_temp_/';
849 $suffix = '_' . date('dmy-His');
850 }
851 break;
852 }
853
854 // If the install path is OK...
855 if ($path && @is_dir($path)) {
856
857 // Set extension directory:
858 $extDirPath = $path . $importedData['extKey'] . $suffix . '/';
859
860 // Install dir was found, remove it then:
861 if (@is_dir($extDirPath)) {
862 if ($dontDelete) {
863 return array($extDirPath);
864 }
865 $res = $this->removeExtDirectory($extDirPath);
866 if ($res) {
867 if (!$this->silentMode) {
868 $flashMessage = t3lib_div::makeInstance(
869 't3lib_FlashMessage',
870 nl2br($res),
871 sprintf($GLOBALS['LANG']->getLL('clearMakeExtDir_could_not_remove_dir'), $extDirPath),
872 t3lib_FlashMessage::ERROR
873 );
874 return $flashMessage->render();
875 }
876 return '';
877 }
878 }
879
880 // We go create...
881 t3lib_div::mkdir($extDirPath);
882 if (!is_dir($extDirPath)) {
883 return sprintf($GLOBALS['LANG']->getLL('clearMakeExtDir_could_not_create_dir'),
884 $extDirPath);
885 }
886 return array($extDirPath);
887 } else {
888 return sprintf($GLOBALS['LANG']->getLL('clearMakeExtDir_no_dir'),
889 $path);
890 }
891 }
892
893
894 /*******************************
895 *
896 * Extension analyzing (detailed information)
897 *
898 ******************************/
899
900 /**
901 * Perform a detailed, technical analysis of the available extension on server!
902 * Includes all kinds of verifications
903 * Takes some time to process, therfore use with care, in particular in listings.
904 *
905 * @param string Extension key
906 * @param array Extension information
907 * @param boolean If set, checks for validity of classes etc.
908 * @return array Information in an array.
909 */
910 function makeDetailedExtensionAnalysis($extKey, $extInfo, $validity = 0) {
911
912 // Get absolute path of the extension
913 $absPath = tx_em_Tools::getExtPath($extKey, $extInfo['type']);
914 $extensionDetails = t3lib_div::makeInstance('tx_em_Extensions_Details', $this);
915 $infoArray = array();
916
917 $table_class_prefix = substr($extKey, 0, 5) == 'user_' ? 'user_' : 'tx_' . str_replace('_', '', $extKey) . '_';
918 $module_prefix = substr($extKey, 0, 5) == 'user_' ? 'u' : 'tx' . str_replace('_', '', $extKey);
919
920 // Database status:
921 $dbInfo = $this->checkDBupdates($extKey, $extInfo, 1);
922
923 // Database structure required:
924 if (is_array($dbInfo['structure']['tables_fields'])) {
925 $modify_tables = t3lib_div::trimExplode(',', $extInfo['EM_CONF']['modify_tables'], 1);
926 $infoArray['dump_tf'] = array();
927
928 foreach ($dbInfo['structure']['tables_fields'] as $tN => $d) {
929 if (in_array($tN, $modify_tables)) {
930 $infoArray['fields'][] = $tN . ': <i>' .
931 (is_array($d['fields']) ? implode(', ', array_keys($d['fields'])) : '') .
932 (is_array($d['keys']) ?
933 ' + ' . count($d['keys']) . ' ' . $GLOBALS['LANG']->getLL('detailedExtAnalysis_keys') : '') .
934 '</i>';
935 if (is_array($d['fields'])) {
936 foreach ($d['fields'] as $fN => $value) {
937 $infoArray['dump_tf'][] = $tN . '.' . $fN;
938 if (!t3lib_div::isFirstPartOfStr($fN, $table_class_prefix)) {
939 $infoArray['NSerrors']['fields'][$fN] = $fN;
940 } else {
941 $infoArray['NSok']['fields'][$fN] = $fN;
942 }
943 }
944 }
945 if (is_array($d['keys'])) {
946 foreach ($d['keys'] as $fN => $value) {
947 $infoArray['dump_tf'][] = $tN . '.KEY:' . $fN;
948 }
949 }
950 } else {
951 $infoArray['dump_tf'][] = $tN;
952 $infoArray['tables'][] = $tN;
953 if (!t3lib_div::isFirstPartOfStr($tN, $table_class_prefix)) {
954 $infoArray['NSerrors']['tables'][$tN] = $tN;
955 } else {
956 $infoArray['NSok']['tables'][$tN] = $tN;
957 }
958 }
959 }
960 if (count($dbInfo['structure']['diff']['diff']) || count($dbInfo['structure']['diff']['extra'])) {
961 $msg = array();
962 if (count($dbInfo['structure']['diff']['diff'])) {
963 $msg[] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_tables_are_missing');
964 }
965 if (count($dbInfo['structure']['diff']['extra'])) {
966 $msg[] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_tables_are_of_wrong_type');
967 }
968 $infoArray['tables_error'] = 1;
969 if (t3lib_extMgm::isLoaded($extKey)) {
970 $infoArray['errors'][] = sprintf($GLOBALS['LANG']->getLL('detailedExtAnalysis_tables_are'),
971 implode(' ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:and') . ' ', $msg)
972 );
973 }
974 }
975 }
976
977 // Static tables?
978 if (is_array($dbInfo['static'])) {
979 $infoArray['static'] = array_keys($dbInfo['static']);
980
981 foreach ($dbInfo['static'] as $tN => $d) {
982 if (!$d['exists']) {
983 $infoArray['static_error'] = 1;
984 if (t3lib_extMgm::isLoaded($extKey)) {
985 $infoArray['errors'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_static_tables_missing');
986 }
987 if (!t3lib_div::isFirstPartOfStr($tN, $table_class_prefix)) {
988 $infoArray['NSerrors']['tables'][$tN] = $tN;
989 } else {
990 $infoArray['NSok']['tables'][$tN] = $tN;
991 }
992 }
993 }
994 }
995
996 // Backend Module-check:
997 $knownModuleList = t3lib_div::trimExplode(',', $extInfo['EM_CONF']['module'], 1);
998 foreach ($knownModuleList as $mod) {
999 if (@is_dir($absPath . $mod)) {
1000 if (@is_file($absPath . $mod . '/conf.php')) {
1001 $confFileInfo = $extensionDetails->modConfFileAnalysis($absPath . $mod . '/conf.php');
1002 if (is_array($confFileInfo['TYPO3_MOD_PATH'])) {
1003 $shouldBePath = tx_em_Tools::typeRelPath($extInfo['type']) . $extKey . '/' . $mod . '/';
1004 if (strcmp($confFileInfo['TYPO3_MOD_PATH'][1][1], $shouldBePath)) {
1005 $infoArray['errors'][] = sprintf($GLOBALS['LANG']->getLL('detailedExtAnalysis_wrong_mod_path'),
1006 $confFileInfo['TYPO3_MOD_PATH'][1][1],
1007 $shouldBePath
1008 );
1009 }
1010 } else {
1011 // It seems like TYPO3_MOD_PATH and therefore also this warning is no longer needed.
1012 // $infoArray['errors'][] = 'No definition of TYPO3_MOD_PATH constant found inside!';
1013 }
1014 if (is_array($confFileInfo['MCONF_name'])) {
1015 $mName = $confFileInfo['MCONF_name'][1][1];
1016 $mNameParts = explode('_', $mName);
1017 $infoArray['moduleNames'][] = $mName;
1018 if (!t3lib_div::isFirstPartOfStr($mNameParts[0], $module_prefix) &&
1019 (!$mNameParts[1] || !t3lib_div::isFirstPartOfStr($mNameParts[1], $module_prefix))) {
1020 $infoArray['NSerrors']['modname'][] = $mName;
1021 } else {
1022 $infoArray['NSok']['modname'][] = $mName;
1023 }
1024 } else {
1025 $infoArray['errors'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_mconf_missing');
1026 }
1027 } else {
1028 $infoArray['errors'][] = sprintf($GLOBALS['LANG']->getLL('detailedExtAnalysis_be_module_conf_missing'),
1029 $mod . '/conf.php'
1030 );
1031 }
1032 } else {
1033 $infoArray['errors'][] = sprintf($GLOBALS['LANG']->getLL('detailedExtAnalysis_module_folder_missing'),
1034 $mod . '/'
1035 );
1036 }
1037 }
1038 $dirs = t3lib_div::get_dirs($absPath);
1039 if (is_array($dirs)) {
1040 reset($dirs);
1041 while (list(, $mod) = each($dirs)) {
1042 if (!in_array($mod, $knownModuleList) && @is_file($absPath . $mod . '/conf.php')) {
1043 $confFileInfo = $extensionDetails->modConfFileAnalysis($absPath . $mod . '/conf.php');
1044 if (is_array($confFileInfo)) {
1045 $infoArray['errors'][] = sprintf($GLOBALS['LANG']->getLL('detailedExtAnalysis_unconfigured_module'),
1046 $mod . '/conf.php'
1047 );
1048 }
1049 }
1050 }
1051 }
1052
1053 // ext_tables.php:
1054 if (@is_file($absPath . 'ext_tables.php')) {
1055 $content = t3lib_div::getUrl($absPath . 'ext_tables.php');
1056 if (stristr($content, 't3lib_extMgm::addModule')) {
1057 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_module');
1058 }
1059 if (stristr($content, 't3lib_extMgm::insertModuleFunction')) {
1060 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_module_and_more');
1061 }
1062 if (stristr($content, 't3lib_div::loadTCA')) {
1063 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_loadTCA');
1064 }
1065 if (stristr($content, '$TCA[')) {
1066 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_TCA');
1067 }
1068 if (stristr($content, 't3lib_extMgm::addPlugin')) {
1069 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_plugin');
1070 }
1071 }
1072
1073 // ext_localconf.php:
1074 if (@is_file($absPath . 'ext_localconf.php')) {
1075 $content = t3lib_div::getUrl($absPath . 'ext_localconf.php');
1076 if (stristr($content, 't3lib_extMgm::addPItoST43')) {
1077 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_plugin_st43');
1078 }
1079 if (stristr($content, 't3lib_extMgm::addPageTSConfig')) {
1080 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_page_ts');
1081 }
1082 if (stristr($content, 't3lib_extMgm::addUserTSConfig')) {
1083 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_user_ts');
1084 }
1085 if (stristr($content, 't3lib_extMgm::addTypoScriptSetup')) {
1086 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_ts_setup');
1087 }
1088 if (stristr($content, 't3lib_extMgm::addTypoScriptConstants')) {
1089 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_ts_constants');
1090 }
1091 }
1092
1093 if (@is_file($absPath . 'ext_typoscript_constants.txt')) {
1094 $infoArray['TSfiles'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_constants');
1095 }
1096 if (@is_file($absPath . 'ext_typoscript_setup.txt')) {
1097 $infoArray['TSfiles'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_setup');
1098 }
1099 if (@is_file($absPath . 'ext_conf_template.txt')) {
1100 $infoArray['conf'] = 1;
1101 }
1102
1103 // Classes:
1104 if ($validity) {
1105 $filesInside = tx_em_Tools::getClassIndexLocallangFiles($absPath, $table_class_prefix, $extKey);
1106 if (is_array($filesInside['errors'])) {
1107 $infoArray['errors'] = array_merge((array) $infoArray['errors'], $filesInside['errors']);
1108 }
1109 if (is_array($filesInside['NSerrors'])) {
1110 $infoArray['NSerrors'] = array_merge((array) $infoArray['NSerrors'], $filesInside['NSerrors']);
1111 }
1112 if (is_array($filesInside['NSok'])) {
1113 $infoArray['NSok'] = array_merge((array) $infoArray['NSok'], $filesInside['NSok']);
1114 }
1115 $infoArray['locallang'] = $filesInside['locallang'];
1116 $infoArray['classes'] = $filesInside['classes'];
1117 }
1118
1119 // Upload folders
1120 if ($extInfo['EM_CONF']['uploadfolder']) {
1121 $infoArray['uploadfolder'] = tx_em_Tools::uploadFolder($extKey);
1122 if (!@is_dir(PATH_site . $infoArray['uploadfolder'])) {
1123 $infoArray['errors'][] = sprintf($GLOBALS['LANG']->getLL('detailedExtAnalysis_no_upload_folder'),
1124 $infoArray['uploadfolder']
1125 );
1126 $infoArray['uploadfolder'] = '';
1127 }
1128 }
1129
1130 // Create directories:
1131 if ($extInfo['EM_CONF']['createDirs']) {
1132 $infoArray['createDirs'] = array_unique(t3lib_div::trimExplode(',', $extInfo['EM_CONF']['createDirs'], 1));
1133 foreach ($infoArray['createDirs'] as $crDir) {
1134 if (!@is_dir(PATH_site . $crDir)) {
1135 $infoArray['errors'][] = sprintf($GLOBALS['LANG']->getLL('detailedExtAnalysis_no_upload_folder'),
1136 $crDir
1137 );
1138 }
1139 }
1140 }
1141
1142 // Return result array:
1143 return $infoArray;
1144 }
1145
1146
1147 /**
1148 * Produces the config form for an extension (if any template file, ext_conf_template.txt is found)
1149 *
1150 * @param string Extension key
1151 * @param array Extension information array
1152 * @param boolean If true, the form HTML content is returned, otherwise the content is set in $this->content.
1153 * @param string Submit-to URL (supposedly)
1154 * @param string Additional form fields to include.
1155 * @return string Depending on $output. Can return the whole form.
1156 */
1157 function tsStyleConfigForm($extKey, $extInfo, $output = 0, $script = '', $addFields = '') {
1158 global $TYPO3_CONF_VARS;
1159
1160 // Initialize:
1161 $absPath = tx_em_Tools::getExtPath($extKey, $extInfo['type']);
1162 $relPath = tx_em_Tools::typeRelPath($extInfo['type']) . $extKey . '/';
1163
1164 $form = '';
1165
1166 // Look for template file for form:
1167 if (t3lib_extMgm::isLoaded($extKey) && @is_file($absPath . 'ext_conf_template.txt')) {
1168
1169 // Load tsStyleConfig class and parse configuration template:
1170 $tsStyleConfig = t3lib_div::makeInstance('t3lib_tsStyleConfig');
1171 $tsStyleConfig->doNotSortCategoriesBeforeMakingForm = TRUE;
1172 $theConstants = $tsStyleConfig->ext_initTSstyleConfig(
1173 t3lib_div::getUrl($absPath . 'ext_conf_template.txt'),
1174 $relPath,
1175 $absPath,
1176 $GLOBALS['BACK_PATH']
1177 );
1178
1179 // Load the list of resources.
1180 $tsStyleConfig->ext_loadResources($absPath . 'res/');
1181
1182 // Load current value:
1183 $arr = unserialize($TYPO3_CONF_VARS['EXT']['extConf'][$extKey]);
1184 $arr = is_array($arr) ? $arr : array();
1185
1186 // Call processing function for constants config and data before write and form rendering:
1187 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/mod/tools/em/index.php']['tsStyleConfigForm'])) {
1188 $_params = array('fields' => &$theConstants, 'data' => &$arr, 'extKey' => $extKey);
1189 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/mod/tools/em/index.php']['tsStyleConfigForm'] as $_funcRef) {
1190 t3lib_div::callUserFunction($_funcRef, $_params, $this);
1191 }
1192 unset($_params);
1193 }
1194
1195 // If saving operation is done:
1196 if (t3lib_div::_POST('submit')) {
1197 $tsStyleConfig->ext_procesInput(t3lib_div::_POST(), array(), $theConstants, array());
1198 $arr = $tsStyleConfig->ext_mergeIncomingWithExisting($arr);
1199 $this->writeTsStyleConfig($extKey, $arr);
1200 }
1201
1202 // Setting value array
1203 $tsStyleConfig->ext_setValuearray($theConstants, $arr);
1204
1205 // Getting session data:
1206 $MOD_MENU = array();
1207 $MOD_MENU['constant_editor_cat'] = $tsStyleConfig->ext_getCategoriesForModMenu();
1208 $MOD_SETTINGS = t3lib_BEfunc::getModuleData($MOD_MENU, t3lib_div::_GP('SET'), 'xMod_test');
1209
1210 // Resetting the menu (stop)
1211 if (count($MOD_MENU['constant_editor_cat']) > 1) {
1212 $menu = $GLOBALS['LANG']->getLL('extInfoArray_category') . ' ' .
1213 t3lib_BEfunc::getFuncMenu(0, 'SET[constant_editor_cat]', $MOD_SETTINGS['constant_editor_cat'], $MOD_MENU['constant_editor_cat'], '', '&CMD[showExt]=' . $extKey);
1214 // add class to select
1215 $menu = str_replace('<select', '<select class="mod-menu-template-select"', $menu);
1216 $menu = str_replace('jumpToUrl', 'abc', $menu);
1217
1218 if ($this->parentObject instanceof SC_mod_tools_em_index) {
1219 $this->parentObject->content .= $this->parentObject->doc->section('', '<span class="nobr">' . $menu . '</span>');
1220 $this->parentObject->content .= $this->parentObject->doc->spacer(10);
1221 } else {
1222 $form .= '<h3>' . '<span class="nobr">' . $menu . '</span></h3>';
1223 }
1224 }
1225
1226 // Category and constant editor config:
1227 $form .= '
1228 <table border="0" cellpadding="0" cellspacing="0" width="600">
1229 <tr>
1230 <td>' . $tsStyleConfig->ext_getForm($MOD_SETTINGS['constant_editor_cat'], $theConstants, $script, $addFields, $extKey) . '</form></td>
1231 </tr>
1232 </table>';
1233 } else {
1234 if (!$this->silentMode) {
1235 $flashMessage = t3lib_div::makeInstance(
1236 't3lib_FlashMessage',
1237 $GLOBALS['LANG']->getLL('tsStyleConfigForm_additional_config'),
1238 '',
1239 t3lib_FlashMessage::INFO
1240 );
1241 }
1242 $form = '
1243 <table border="0" cellpadding="0" cellspacing="0" width="600">
1244 <tr>
1245 <td>
1246 <form action="' . htmlspecialchars($script) . '" method="post">' .
1247 $addFields .
1248 ($this->silentMode ? '' : $flashMessage->render()) .
1249 '<br /><input type="submit" id="configuration-submit-' . $extKey . '" name="write" value="' . $GLOBALS['LANG']->getLL('updatesForm_make_updates') . '" />
1250 </form>
1251 </td>
1252 </tr>
1253 </table>';
1254 }
1255
1256 #if ($output) {
1257 return $form;
1258 #} else {
1259 # $this->content.=$this->doc->section('', $form);
1260 #}
1261
1262
1263 }
1264
1265 /**
1266 * Writes the TSstyleconf values to "localconf.php"
1267 * Removes the temp_CACHED* files before return.
1268 *
1269 * @param string Extension key
1270 * @param array Configuration array to write back
1271 * @return void
1272 */
1273 function writeTsStyleConfig($extKey, $arr) {
1274
1275 // Instance of install tool
1276 $instObj = new t3lib_install;
1277 $instObj->allowUpdateLocalConf = 1;
1278 $instObj->updateIdentity = 'TYPO3 Extension Manager';
1279
1280 // Get lines from localconf file
1281 $lines = $instObj->writeToLocalconf_control();
1282 $instObj->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXT\'][\'extConf\'][\'' . $extKey . '\']', serialize($arr)); // This will be saved only if there are no linebreaks in it !
1283 $instObj->writeToLocalconf_control($lines);
1284
1285 t3lib_extMgm::removeCacheFiles();
1286 }
1287
1288
1289 /**
1290 * Creates a form for an extension which contains all options for configuration, updates of database, clearing of cache etc.
1291 *
1292 * @param string $extKey Extension key
1293 * @param array $extInfo Extension information array
1294 * @param boolean $notSilent If set, the form will ONLY show if fields/tables should be updated (suppressing forms like general configuration and cache clearing).
1295 * @param string $script Alternative action=""-script
1296 * @param string $addFields Additional form fields
1297 * @param boolean $addFormTags TRUE if it shopuld be wrapped with form tag
1298 * @param boolean $excludeDatabaseCheck TRUE if no database check should be done
1299 * @return string
1300 */
1301 function updatesForm($extKey, $extInfo, $notSilent = FALSE, $script = '', $addFields = '', $addFormTag = TRUE, $excludeDatabaseCheck = FALSE) {
1302 $script = $script ? $script : t3lib_div::linkThisScript();
1303 if ($addFormTag) {
1304 $formWrap = array('<form action="' . htmlspecialchars($script) . '" method="POST">', '</form>');
1305 } else {
1306 $formWrap = array('', '');
1307 }
1308 $extensionDetails = t3lib_div::makeInstance('tx_em_Extensions_Details', $this);
1309 $updates = '';
1310
1311 if (!$excludeDatabaseCheck) {
1312 $updates .= $this->checkDBupdates($extKey, $extInfo);
1313 }
1314
1315 $uCache = $this->checkClearCache($extInfo);
1316 if ($notSilent) {
1317 $updates .= $uCache;
1318 }
1319 $updates .= $extensionDetails->checkUploadFolder($extKey, $extInfo);
1320
1321 $absPath = tx_em_Tools::getExtPath($extKey, $extInfo['type']);
1322 if ($notSilent && @is_file($absPath . 'ext_conf_template.txt')) {
1323 $configForm = $this->tsStyleConfigForm($extKey, $extInfo, 1, $script, $updates . $addFields . '<br />');
1324 }
1325
1326 if ($updates || $configForm) {
1327 if ($configForm) {
1328 $updates = $configForm;
1329 } else {
1330 $updates = $formWrap[0] . $updates . $addFields . '
1331 <br /><input type="submit" name="write" id="update-submit-' . $extKey . '" value="' . $GLOBALS['LANG']->getLL('updatesForm_make_updates') . '" />
1332 ' . $formWrap[1];
1333 }
1334 }
1335
1336 return $updates;
1337 }
1338
1339
1340 /**
1341 * Check if clear-cache should be performed, otherwise show form (for installation of extension)
1342 * Shown only if the extension has the clearCacheOnLoad flag set.
1343 *
1344 * @param string Extension key
1345 * @param array Extension information array
1346 * @return string HTML output (if form is shown)
1347 */
1348 function checkClearCache($extInfo) {
1349 if ($extInfo['EM_CONF']['clearCacheOnLoad']) {
1350 if (t3lib_div::_POST('_clear_all_cache')) { // Action: Clearing the cache
1351 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
1352 $tce->stripslashes_values = 0;
1353 $tce->start(array(), array());
1354 $tce->clear_cacheCmd('all');
1355 } else { // Show checkbox for clearing cache:
1356 $content .= '
1357 <br />
1358 <h3>' . $GLOBALS['LANG']->getLL('checkUploadFolder_clear_cache') . '</h3>
1359 <p>' . $GLOBALS['LANG']->getLL('checkUploadFolder_clear_cache_requested') . '<br />
1360 <label for="check_clear_all_cache">' . $GLOBALS['LANG']->getLL('checkUploadFolder_clear_all_cache') . '</label>
1361 <input type="checkbox" name="_clear_all_cache" id="check_clear_all_cache" checked="checked" value="1" /><br />
1362 </p>
1363 ';
1364 }
1365 }
1366 return $content;
1367 }
1368
1369 /**
1370 * Writes the extension list to "localconf.php" file
1371 * Removes the temp_CACHED* files before return.
1372 *
1373 * @param string List of extensions
1374 * @return void
1375 */
1376 function writeNewExtensionList($newExtList) {
1377 $strippedExtensionList = $this->stripNonFrontendExtensions($newExtList);
1378
1379 // Instance of install tool
1380 $instObj = new t3lib_install;
1381 $instObj->allowUpdateLocalConf = 1;
1382 $instObj->updateIdentity = 'TYPO3 Extension Manager';
1383
1384 // Get lines from localconf file
1385 $lines = $instObj->writeToLocalconf_control();
1386 $instObj->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXT\'][\'extList\']', $newExtList);
1387 $instObj->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXT\'][\'extList_FE\']', $strippedExtensionList);
1388 $instObj->writeToLocalconf_control($lines);
1389
1390 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'] = $newExtList;
1391 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList_FE'] = $strippedExtensionList;
1392 t3lib_extMgm::removeCacheFiles();
1393 }
1394
1395 /**
1396 * Removes unneeded extensions from the frontend based on
1397 * EMCONF doNotLoadInFE = 1
1398 *
1399 * @param string $extList
1400 * @return string
1401 */
1402 function stripNonFrontendExtensions($extList) {
1403 $fullExtList = $this->parentObject->extensionList->getInstalledExtensions();
1404 $extListArray = t3lib_div::trimExplode(',', $extList);
1405 foreach ($extListArray as $arrayKey => $extKey) {
1406 if ($fullExtList[0][$extKey]['EM_CONF']['doNotLoadInFE'] == 1) {
1407 unset($extListArray[$arrayKey]);
1408 }
1409 }
1410 $nonFEList = implode(',', $extListArray);
1411 return $nonFEList;
1412 }
1413
1414 /**
1415 * Updates the database according to extension requirements
1416 * DBAL compliant (based on Install Tool code)
1417 *
1418 * @param string Extension key
1419 * @param array Extension information array
1420 * @return void
1421 */
1422 function forceDBupdates($extKey, $extInfo) {
1423 $instObj = new t3lib_install;
1424
1425 // Updating tables and fields?
1426 if (is_array($extInfo['files']) && in_array('ext_tables.sql', $extInfo['files'])) {
1427 $fileContent = t3lib_div::getUrl(tx_em_Tools::getExtPath($extKey, $extInfo['type']) . 'ext_tables.sql');
1428
1429 $FDfile = $instObj->getFieldDefinitions_fileContent($fileContent);
1430 if (count($FDfile)) {
1431 $FDdb = $instObj->getFieldDefinitions_database(TYPO3_db);
1432 $diff = $instObj->getDatabaseExtra($FDfile, $FDdb);
1433 $update_statements = $instObj->getUpdateSuggestions($diff);
1434
1435 foreach ((array) $update_statements['add'] as $string) {
1436 $GLOBALS['TYPO3_DB']->admin_query($string);
1437 }
1438 foreach ((array) $update_statements['change'] as $string) {
1439 $GLOBALS['TYPO3_DB']->admin_query($string);
1440 }
1441 foreach ((array) $update_statements['create_table'] as $string) {
1442 $GLOBALS['TYPO3_DB']->admin_query($string);
1443 }
1444 }
1445 }
1446
1447 // Importing static tables?
1448 if (is_array($extInfo['files']) && in_array('ext_tables_static+adt.sql', $extInfo['files'])) {
1449 $fileContent = t3lib_div::getUrl(tx_em_Tools::getExtPath($extKey, $extInfo['type']) . 'ext_tables_static+adt.sql');
1450
1451 $statements = $instObj->getStatementarray($fileContent, 1);
1452 list($statements_table, $insertCount) = $instObj->getCreateTables($statements, 1);
1453
1454 // Traverse the tables
1455 foreach ($statements_table as $table => $query) {
1456 $GLOBALS['TYPO3_DB']->admin_query('DROP TABLE IF EXISTS ' . $table);
1457 $GLOBALS['TYPO3_DB']->admin_query($query);
1458
1459 if ($insertCount[$table]) {
1460 $statements_insert = $instObj->getTableInsertStatements($statements, $table);
1461
1462 foreach ($statements_insert as $v) {
1463 $GLOBALS['TYPO3_DB']->admin_query($v);
1464 }
1465 }
1466 }
1467 }
1468 }
1469
1470 }
1471
1472 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/install/class.tx_em_install.php'])) {
1473 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/install/class.tx_em_install.php']);
1474 }
1475
1476 ?>