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