TYPO3 API  SVNRelease
class.tx_em_install.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2010 Steffen Kamper (info@sk-typo3.de)
00006  *  All rights reserved
00007  *
00008  *  This script is part of the TYPO3 project. The TYPO3 project is
00009  *  free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  The GNU General Public License can be found at
00015  *  http://www.gnu.org/copyleft/gpl.html.
00016  *  A copy is found in the textfile GPL.txt and important notices to the license
00017  *  from the author is found in LICENSE.txt distributed with these scripts.
00018  *
00019  *
00020  *  This script is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU General Public License for more details.
00024  *
00025  *  This copyright notice MUST APPEAR in all copies of the script!
00026  ***************************************************************/
00027 /**
00028  * Module: Extension manager, (un-)install extensions
00029  *
00030  * $Id: class.tx_em_install.php 2073 2010-03-19 10:42:38Z steffenk $
00031  *
00032  * @author  Steffen Kamper <info@sk-typo3.de>
00033  */
00034 
00035 
00036 class tx_em_Install {
00037 
00038     /**
00039      * Parent module object
00040      *
00041      * @var SC_mod_tools_em_index
00042      */
00043     protected $parentObject;
00044 
00045     /**
00046      * Instance of EM API
00047      *
00048      * @var tx_em_API
00049      */
00050     protected $api;
00051 
00052     /**
00053      *
00054      * @var t3lib_install
00055      */
00056     public $install;
00057 
00058 
00059     /**
00060      * @var integer
00061      */
00062     protected $systemInstall = 0; // If "1" then installs in the sysext directory is allowed. Default: 0
00063 
00064     /**
00065      * @var boolean
00066      */
00067     protected $silentMode;
00068 
00069     /**
00070      * Constructor
00071      *
00072      * @param SC_mod_tools_em_index $parentObject
00073      */
00074     public function __construct($parentObject = NULL) {
00075         $GLOBALS['LANG']->includeLLFile(t3lib_extMgm::extPath('em', 'language/locallang.xml'));
00076         $this->parentObject = $parentObject;
00077         $this->api = t3lib_div::makeInstance('tx_em_API');
00078         $this->install = t3lib_div::makeInstance('t3lib_install');
00079         $this->install->INSTALL = t3lib_div::_GP('TYPO3_INSTALL');
00080         $this->systemInstall = isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['allowSystemInstall']) && $GLOBALS['TYPO3_CONF_VARS']['EXT']['allowSystemInstall'];
00081     }
00082 
00083     /**
00084      * Set silent mode to prevent flashmessages
00085      *
00086      * @param  boolean $silentMode
00087      * @return void
00088      */
00089     public function setSilentMode($silentMode) {
00090         $this->silentMode = $silentMode ? TRUE : FALSE;
00091     }
00092 
00093     /**
00094      * Imports the data of an extension  from upload
00095      *
00096      * @param  $uploadedTempFile
00097      * @param  $location
00098      * @param bool $uploadOverwrite
00099      * @return array
00100      */
00101     public function uploadExtensionFile($uploadedTempFile, $location, $uploadOverwrite = FALSE) {
00102         $error = '';
00103         $fileContent = t3lib_div::getUrl($uploadedTempFile);
00104         if (!$fileContent) {
00105             return array(
00106                 'success' => FALSE,
00107                 'error' => $GLOBALS['LANG']->getLL('ext_import_file_empty')
00108             );
00109         }
00110 
00111         // Decode file data:
00112         $terConnection = t3lib_div::makeInstance('tx_em_Connection_Ter', $this);
00113         $fetchData = $terConnection->decodeExchangeData($fileContent);
00114         if (is_array($fetchData)) {
00115             $extKey = $fetchData[0]['extKey'];
00116             if ($extKey) {
00117                 if (!$uploadOverwrite) {
00118                     $comingExtPath = tx_em_Tools::typePath($location) . $extKey . '/';
00119                     if (@is_dir($comingExtPath)) {
00120                         $error = sprintf($GLOBALS['LANG']->getLL('ext_import_ext_present_no_overwrite'), $comingExtPath) .
00121                                 '<br />' . $GLOBALS['LANG']->getLL('ext_import_ext_present_nothing_done');
00122 
00123                     } // ... else go on, install...
00124                 } // ... else go on, install...
00125             } else {
00126                 $error = $GLOBALS['LANG']->getLL('ext_import_no_key');
00127             }
00128         } else {
00129             $error = sprintf($GLOBALS['LANG']->getLL('ext_import_wrong_file_format'), $fetchData);
00130         }
00131 
00132         if ($error) {
00133             return array(FALSE, $error);
00134         } else {
00135             return array(TRUE, $fetchData);
00136         }
00137 
00138     }
00139 
00140     /**
00141      * Installs an extension.
00142      *
00143      * @param  $fetchData
00144      * @param  $loc
00145      * @param  $version
00146      * @param  $uploadedTempFile
00147      * @param  $dontDelete
00148      * @return mixed|string
00149      */
00150     public function installExtension($fetchData, $loc, $version, $uploadedTempFile, $dontDelete) {
00151         $xmlHandler =& $this->parentObject->xmlHandler;
00152         $extensionList =& $this->parentObject->extensionList;
00153         $extensionDetails =& $this->parentObject->extensionDetails;
00154         $content = '';
00155 
00156         if (tx_em_Tools::importAsType($loc)) {
00157             if (is_array($fetchData)) { // There was some data successfully transferred
00158                 if ($fetchData[0]['extKey'] && is_array($fetchData[0]['FILES'])) {
00159                     $extKey = $fetchData[0]['extKey'];
00160                     if (!isset($fetchData[0]['EM_CONF']['constraints'])) {
00161                         $fetchData[0]['EM_CONF']['constraints'] = $xmlHandler->extensionsXML[$extKey]['versions'][$version]['dependencies'];
00162                     }
00163                     $EM_CONF = tx_em_Tools::fixEMCONF($fetchData[0]['EM_CONF']);
00164                     if (!$EM_CONF['lockType'] || !strcmp($EM_CONF['lockType'], $loc)) {
00165                         // check dependencies, act accordingly if ext is loaded
00166                         list($instExtInfo,) = $extensionList->getInstalledExtensions();
00167                         $depStatus = $this->checkDependencies($extKey, $EM_CONF, $instExtInfo);
00168                         if (t3lib_extMgm::isLoaded($extKey) && !$depStatus['returnCode']) {
00169                             $content .= $depStatus['html'];
00170                             if ($uploadedTempFile) {
00171                                 $content .= '<input type="hidden" name="CMD[alreadyUploaded]" value="' . $uploadedTempFile . '" />';
00172                             }
00173                         } else {
00174                             $res = $this->clearAndMakeExtensionDir($fetchData[0], $loc, $dontDelete);
00175                             if (is_array($res)) {
00176                                 $extDirPath = trim($res[0]);
00177                                 if ($extDirPath && @is_dir($extDirPath) && substr($extDirPath, -1) == '/') {
00178 
00179                                     $emConfFile = $extensionDetails->construct_ext_emconf_file($extKey, $EM_CONF);
00180                                     $dirs = tx_em_Tools::extractDirsFromFileList(array_keys($fetchData[0]['FILES']));
00181 
00182                                     $res = tx_em_Tools::createDirsInPath($dirs, $extDirPath);
00183                                     if (!$res) {
00184                                         $writeFiles = $fetchData[0]['FILES'];
00185                                         $writeFiles['ext_emconf.php']['content'] = $emConfFile;
00186                                         $writeFiles['ext_emconf.php']['content_md5'] = md5($emConfFile);
00187 
00188                                         // Write files:
00189                                         foreach ($writeFiles as $theFile => $fileData) {
00190                                             t3lib_div::writeFile($extDirPath . $theFile, $fileData['content']);
00191                                             if (!@is_file($extDirPath . $theFile)) {
00192                                                 if (!$this->silentMode) {
00193                                                     $flashMessage = t3lib_div::makeInstance(
00194                                                         't3lib_FlashMessage',
00195                                                         sprintf($GLOBALS['LANG']->getLL('ext_import_file_not_created'),
00196                                                         $extDirPath . $theFile),
00197                                                         '',
00198                                                         t3lib_FlashMessage::ERROR
00199                                                     );
00200                                                     $content .= $flashMessage->render();
00201                                                 } else {
00202                                                     if (!$this->silentMode) {
00203                                                         $flashMessage = t3lib_div::makeInstance(
00204                                                             't3lib_FlashMessage',
00205                                                             sprintf($GLOBALS['LANG']->getLL('ext_import_file_not_created'), $extDirPath . $theFile),
00206                                                             '',
00207                                                             t3lib_FlashMessage::ERROR
00208                                                         );
00209                                                         $content .= $flashMessage->render();
00210                                                     } else {
00211                                                         $content .= sprintf($GLOBALS['LANG']->getLL('ext_import_file_not_created'),
00212                                                                 $extDirPath . $theFile) . '<br />';
00213                                                     }
00214                                                 }
00215                                             } elseif (md5(t3lib_div::getUrl($extDirPath . $theFile)) != $fileData['content_md5']) {
00216                                                 $content .= sprintf($GLOBALS['LANG']->getLL('ext_import_file_corrupted'),
00217                                                         $extDirPath . $theFile) . '<br />';
00218                                             }
00219                                         }
00220 
00221                                         t3lib_div::fixPermissions($extDirPath, TRUE);
00222 
00223                                         // No content, no errors. Create success output here:
00224                                         if (!$content) {
00225                                             $messageContent = sprintf($GLOBALS['LANG']->getLL('ext_import_success_folder'), $extDirPath) . '<br />';
00226 
00227                                             $uploadSucceed = true;
00228 
00229                                             // Fix TYPO3_MOD_PATH for backend modules in extension:
00230                                             $modules = t3lib_div::trimExplode(',', $EM_CONF['module'], 1);
00231                                             if (count($modules)) {
00232                                                 foreach ($modules as $mD) {
00233                                                     $confFileName = $extDirPath . $mD . '/conf.php';
00234                                                     if (@is_file($confFileName)) {
00235                                                         $messageContent .= tx_em_Tools::writeTYPO3_MOD_PATH($confFileName, $loc, $extKey . '/' . $mD . '/') . '<br />';
00236                                                     } else {
00237                                                         $messageContent .= sprintf($GLOBALS['LANG']->getLL('ext_import_no_conf_file'),
00238                                                             $confFileName) . '<br />';
00239                                                     }
00240                                                 }
00241                                             }
00242                                             // 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.
00243                                             // But this order of the code works.... (using the empty Array with type, EMCONF and files hereunder).
00244 
00245                                             // Writing to ext_emconf.php:
00246                                             $sEMD5A = $extensionDetails->serverExtensionMD5array($extKey, array('type' => $loc, 'EM_CONF' => array(), 'files' => array()));
00247                                             $EM_CONF['_md5_values_when_last_written'] = serialize($sEMD5A);
00248                                             $emConfFile = $extensionDetails->construct_ext_emconf_file($extKey, $EM_CONF);
00249                                             t3lib_div::writeFile($extDirPath . 'ext_emconf.php', $emConfFile);
00250 
00251                                             $messageContent .= 'ext_emconf.php: ' . $extDirPath . 'ext_emconf.php<br />';
00252                                             $messageContent .= $GLOBALS['LANG']->getLL('ext_import_ext_type') . ' ';
00253                                             $messageContent .= $this->api->typeLabels[$loc] . '<br />';
00254                                             $messageContent .= '<br />';
00255 
00256                                             // Remove cache files:
00257                                             $updateContent = '';
00258                                             if (t3lib_extMgm::isLoaded($extKey)) {
00259                                                 if (t3lib_extMgm::removeCacheFiles()) {
00260                                                     $messageContent .= $GLOBALS['LANG']->getLL('ext_import_cache_files_removed') . '<br />';
00261                                                 }
00262 
00263                                                 list($new_list) = $this->parentObject->extensionList->getInstalledExtensions();
00264                                                 $updateContent = $this->updatesForm($extKey, $new_list[$extKey], 1, t3lib_div::linkThisScript(array(
00265                                                     'CMD[showExt]' => $extKey,
00266                                                     'SET[singleDetails]' => 'info'
00267                                                 )));
00268                                             }
00269 
00270                                             if (!$this->silentMode) {
00271                                                 $flashMessage = t3lib_div::makeInstance(
00272                                                     't3lib_FlashMessage',
00273                                                     $messageContent,
00274                                                     $GLOBALS['LANG']->getLL('ext_import_success')
00275                                                 );
00276                                                 $content = $flashMessage->render();
00277                                             } else {
00278                                                 $content = $updateContent;
00279                                             }
00280 
00281 
00282                                             // Install / Uninstall:
00283                                             if (!$this->parentObject->CMD['standAlone']) {
00284                                                 $content .= '<h3>' . $GLOBALS['LANG']->getLL('ext_import_install_uninstall') . '</h3>';
00285                                                 $content .= $new_list[$extKey] ?
00286                                                         '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array(
00287                                                             'CMD[showExt]' => $extKey,
00288                                                             'CMD[remove]' => 1,
00289                                                             'CMD[clrCmd]' => 1,
00290                                                             'SET[singleDetails]' => 'info'
00291                                                         ))) . '">' .
00292                                                                 tx_em_Tools::removeButton() . ' ' . $GLOBALS['LANG']->getLL('ext_import_uninstall') . '</a>' :
00293                                                         '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array(
00294                                                             'CMD[showExt]' => $extKey,
00295                                                             'CMD[load]' => 1,
00296                                                             'CMD[clrCmd]' => 1,
00297                                                             'SET[singleDetails]' => 'info'
00298                                                         ))) . '">' .
00299                                                                 tx_em_Tools::installButton() . ' ' . $GLOBALS['LANG']->getLL('ext_import_install') . '</a>';
00300                                             } else {
00301                                                 $content = $GLOBALS['LANG']->getLL('ext_import_imported') .
00302                                                         '<br /><br />';
00303                                                 if ($this->silentMode || t3lib_div::_GP('nodoc')) {
00304                                                     $content .= '<a id="closewindow" href="javascript:parent.TYPO3.EM.Tools.closeImportWindow();">' . $GLOBALS['LANG']->getLL('ext_import_close') . '</a>';
00305                                                 } else {
00306                                                     $content .= '<a href="javascript:opener.top.list.iframe.document.forms[0].submit();window.close();">' .
00307                                                         $GLOBALS['LANG']->getLL('ext_import_close_check') . '</a>';
00308                                                 }
00309 
00310                                             }
00311                                         }
00312                                     } else {
00313                                         if (!$this->silentMode) {
00314                                             $flashMessage = t3lib_div::makeInstance(
00315                                                 't3lib_FlashMessage',
00316                                                 $res,
00317                                                 '',
00318                                                 t3lib_FlashMessage::ERROR
00319                                             );
00320                                             $content = $flashMessage->render();
00321                                         } else {
00322                                             $content = $res;
00323                                         }
00324                                     }
00325                                 } else {
00326                                     if (!$this->silentMode) {
00327                                         $flashMessage = t3lib_div::makeInstance(
00328                                             't3lib_FlashMessage',
00329                                             sprintf($GLOBALS['LANG']->getLL('ext_import_ext_path_different'), $extDirPath),
00330                                             '',
00331                                             t3lib_FlashMessage::ERROR
00332                                         );
00333                                         $content = $flashMessage->render();
00334                                     } else {
00335                                         $content = sprintf($GLOBALS['LANG']->getLL('ext_import_ext_path_different'), $extDirPath);
00336                                     }
00337                                 }
00338                             } else {
00339                                 if (!$this->silentMode) {
00340                                     $flashMessage = t3lib_div::makeInstance(
00341                                         't3lib_FlashMessage',
00342                                         $res,
00343                                         '',
00344                                         t3lib_FlashMessage::ERROR
00345                                     );
00346                                     $content = $flashMessage->render();
00347                                 } else {
00348                                     $content = $res;
00349                                 }
00350                             }
00351                         }
00352                     } else {
00353                         if (!$this->silentMode) {
00354                             $flashMessage = t3lib_div::makeInstance(
00355                                 't3lib_FlashMessage',
00356                                 sprintf($GLOBALS['LANG']->getLL('ext_import_ext_only_here'),
00357                                     $this->typePaths[$EM_CONF['lockType']], $EM_CONF['lockType']),
00358                                 '',
00359                                 t3lib_FlashMessage::ERROR
00360                             );
00361                             $content = $flashMessage->render();
00362                         } else {
00363                             $content = sprintf($GLOBALS['LANG']->getLL('ext_import_ext_only_here'),
00364                                 tx_em_Tools::typePath($EM_CONF['lockType']), $EM_CONF['lockType']);
00365                         }
00366                     }
00367                 } else {
00368                     if (!$this->silentMode) {
00369                         $flashMessage = t3lib_div::makeInstance(
00370                             't3lib_FlashMessage',
00371                             $GLOBALS['LANG']->getLL('ext_import_no_ext_key_files'),
00372                             '',
00373                             t3lib_FlashMessage::ERROR
00374                         );
00375                         $content = $flashMessage->render();
00376                     } else {
00377                         $content = $GLOBALS['LANG']->getLL('ext_import_no_ext_key_files');
00378                     }
00379                 }
00380             } else {
00381                 if (!$this->silentMode) {
00382                     $flashMessage = t3lib_div::makeInstance(
00383                         't3lib_FlashMessage',
00384                         sprintf($GLOBALS['LANG']->getLL('ext_import_data_transfer'), $fetchData),
00385                         '',
00386                         t3lib_FlashMessage::ERROR
00387                     );
00388                     $content = $flashMessage->render();
00389                 } else {
00390                     $content = sprintf($GLOBALS['LANG']->getLL('ext_import_data_transfer'), $fetchData);
00391                 }
00392             }
00393         } else {
00394             if (!$this->silentMode) {
00395                 $flashMessage = t3lib_div::makeInstance(
00396                     't3lib_FlashMessage',
00397                     sprintf($GLOBALS['LANG']->getLL('ext_import_no_install_here'), $this->typePaths[$loc]),
00398                     '',
00399                     t3lib_FlashMessage::ERROR
00400                 );
00401                 $content = $flashMessage->render();
00402             } else {
00403                 $content = sprintf($GLOBALS['LANG']->getLL('ext_import_no_install_here'), tx_em_Tools::typePath($loc));
00404             }
00405         }
00406 
00407         return $content;
00408     }
00409 
00410     /**
00411      *Check extension dependencies
00412      *
00413      * @param   string      $extKey
00414      * @param   array       $conf
00415      * @param   array       $instExtInfo
00416      * @return  array
00417      */
00418     function checkDependencies($extKey, $conf, $instExtInfo) {
00419         $content = '';
00420         $depError = false;
00421         $depIgnore = false;
00422         $msg = array();
00423         $depsolver = t3lib_div::_POST('depsolver');
00424 
00425         if (isset($conf['constraints']['depends']) && is_array($conf['constraints']['depends'])) {
00426             foreach ($conf['constraints']['depends'] as $depK => $depV) {
00427                 if ($depsolver['ignore'][$depK]) {
00428                     $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_ignored'),
00429                         $depK) . '
00430                         <input type="hidden" value="1" name="depsolver[ignore][' . $depK . ']" />';
00431                     $depIgnore = true;
00432                     continue;
00433                 }
00434                 if ($depK == 'php') {
00435                     if (!$depV) {
00436                         continue;
00437                     }
00438                     $versionRange = tx_em_Tools::splitVersionRange($depV);
00439                     $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!
00440                     if ($versionRange[0] != '0.0.0' && version_compare($phpv, $versionRange[0], '<')) {
00441                         $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_php_too_low'),
00442                             $phpv, $versionRange[0]);
00443                         $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $depK . ']" id="checkIgnore_' . $depK . '" />
00444                             <label for="checkIgnore_' . $depK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_requirement') . '</label>';
00445                         $depError = true;
00446                         continue;
00447                     } elseif ($versionRange[1] != '0.0.0' && version_compare($phpv, $versionRange[1], '>')) {
00448                         $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_php_too_high'),
00449                             $phpv, $versionRange[1]);
00450                         $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $depK . ']" id="checkIgnore_' . $depK . '" />
00451                             <label for="checkIgnore_' . $depK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_requirement') . '</label>';
00452                         $depError = true;
00453                         continue;
00454                     }
00455 
00456                 } elseif ($depK == 'typo3') {
00457                     if (!$depV) {
00458                         continue;
00459                     }
00460 
00461                     // if the current TYPO3 version is a development version (like TYPO3 4.4-dev),
00462                     // then it should behave like TYPO3 4.4.0
00463                     $t3version = TYPO3_version;
00464                     if (stripos($t3version, '-dev')
00465                             || stripos($t3version, '-alpha')
00466                             || stripos($t3version, '-beta')
00467                             || stripos($t3version, '-RC')) {
00468                         // find the last occurence of "-" and replace that part with a ".0"
00469                         $t3version = substr($t3version, 0, strrpos($t3version, '-')) . '.0';
00470                     }
00471 
00472                     $versionRange = tx_em_Tools::splitVersionRange($depV);
00473                     if ($versionRange[0] != '0.0.0' && version_compare($t3version, $versionRange[0], '<')) {
00474                         $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_typo3_too_low'),
00475                             $t3version, $versionRange[0]);
00476                         $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $depK . ']" id="checkIgnore_' . $depK . '" />
00477                             <label for="checkIgnore_' . $depK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_requirement') . '</label>';
00478                         $depError = true;
00479                         continue;
00480                     } elseif ($versionRange[1] != '0.0.0' && version_compare($t3version, $versionRange[1], '>')) {
00481                         $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_typo3_too_high'),
00482                             $t3version, $versionRange[1]);
00483                         $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $depK . ']" id="checkIgnore_' . $depK . '" />
00484                             <label for="checkIgnore_' . $depK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_requirement') . '</label>';
00485                         $depError = true;
00486                         continue;
00487                     }
00488                 } elseif (strlen($depK) && !t3lib_extMgm::isLoaded($depK)) { // strlen check for braindead empty dependencies coming from extensions...
00489                     if (!isset($instExtInfo[$depK])) {
00490                         $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_ext_not_available'),
00491                             $depK);
00492                         $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;' . t3lib_iconWorks::getSpriteIcon('actions-system-extension-import', array('title' => $GLOBALS['LANG']->getLL('checkDependencies_import_ext'))) . '&nbsp;
00493                             <a href="' . t3lib_div::linkThisUrl($this->parentObject->script, array(
00494                             'CMD[importExt]' => $depK,
00495                             'CMD[loc]' => 'L',
00496                             'CMD[standAlone]' => 1
00497                         )) . '" target="_blank">' . $GLOBALS['LANG']->getLL('checkDependencies_import_now') . '</a>';
00498                         $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $depK . ']" id="checkIgnore_' . $depK . '" />
00499                             <label for="checkIgnore_' . $depK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_ext_requirement') . '</label>';
00500                     } else {
00501                         $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_ext_not_installed'),
00502                             $depK, $instExtInfo[$depK]['EM_CONF']['title']);
00503                         $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;' . tx_em_Tools::installButton() . '&nbsp;
00504                             <a href="' . t3lib_div::linkThisUrl($this->parentObject->script, array(
00505                             'CMD[showExt]' => $depK,
00506                             'CMD[load]' => 1,
00507                             'CMD[clrCmd]' => 1,
00508                             'CMD[standAlone]' => 1,
00509                             'SET[singleDetails]' => 'info'
00510                         )) .
00511                                 '" target="_blank">' . $GLOBALS['LANG']->getLL('checkDependencies_install_now') . '</a>';
00512                         $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $depK . ']" id="checkIgnore_' . $depK . '" />
00513                             <label for="checkIgnore_' . $depK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_ext_requirement') . '</label>';
00514                     }
00515                     $depError = true;
00516                 } else {
00517                     $versionRange = tx_em_Tools::splitVersionRange($depV);
00518                     if ($versionRange[0] != '0.0.0' && version_compare($instExtInfo[$depK]['EM_CONF']['version'], $versionRange[0], '<')) {
00519                         $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_ext_too_low'),
00520                             $depK, $instExtInfo[$depK]['EM_CONF']['version'], $versionRange[0]);
00521                         $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $depK . ']" id="checkIgnore_' . $depK . '" />
00522                             <label for="checkIgnore_' . $depK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_requirement') . '</label>';
00523                         $depError = true;
00524                         continue;
00525                     } elseif ($versionRange[1] != '0.0.0' && version_compare($instExtInfo[$depK]['EM_CONF']['version'], $versionRange[1], '>')) {
00526                         $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_ext_too_high'),
00527                             $depK, $instExtInfo[$depK]['EM_CONF']['version'], $versionRange[1]);
00528                         $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $depK . ']" id="checkIgnore_' . $depK . '" />
00529                             <label for="checkIgnore_' . $depK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_requirement') . '</label>';
00530                         $depError = true;
00531                         continue;
00532                     }
00533                 }
00534             }
00535         }
00536 
00537         if (($depError || $depIgnore) && $this->parentObject instanceof SC_mod_tools_em_index) {
00538             $content .= $this->parentObject->doc->section(
00539                 $GLOBALS['LANG']->getLL('removeExtFromList_dependency_error'),
00540                 implode('<br />', $msg), 0, 1, 2
00541             );
00542         }
00543 
00544         // Check conflicts with other extensions:
00545         $conflictError = false;
00546         $conflictIgnore = false;
00547         $msg = array();
00548 
00549         if (isset($conf['constraints']['conflicts']) && is_array($conf['constraints']['conflicts'])) {
00550             foreach ((array) $conf['constraints']['conflicts'] as $conflictK => $conflictV) {
00551                 if ($depsolver['ignore'][$conflictK]) {
00552                     $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_conflict_ignored'),
00553                         $conflictK) . '
00554                         <input type="hidden" value="1" name="depsolver[ignore][' . $conflictK . ']" />';
00555                     $conflictIgnore = true;
00556                     continue;
00557                 }
00558                 if (t3lib_extMgm::isLoaded($conflictK)) {
00559                     $versionRange = tx_em_Tools::splitVersionRange($conflictV);
00560                     if ($versionRange[0] != '0.0.0' && version_compare($instExtInfo[$conflictK]['EM_CONF']['version'], $versionRange[0], '<')) {
00561                         continue;
00562                     }
00563                     elseif ($versionRange[1] != '0.0.0' && version_compare($instExtInfo[$conflictK]['EM_CONF']['version'], $versionRange[1], '>')) {
00564                         continue;
00565                     }
00566                     $msg[] = sprintf($GLOBALS['LANG']->getLL('checkDependencies_conflict_remove'),
00567                         $extKey, $conflictK, $instExtInfo[$conflictK]['EM_CONF']['title'], $conflictK, $extKey);
00568                     $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;' . tx_em_Tools::removeButton() . '&nbsp;
00569                         <a href="' . htmlspecialchars(t3lib_div::linkThisScript(array(
00570                         'CMD[showExt]' => $conflictK,
00571                         'CMD[remove]' => 1,
00572                         'CMD[clrCmd]' => 1,
00573                         'CMD[standAlone]' => 1,
00574                         'SET[singleDetails]' => 'info'
00575                     ))) .
00576                             '" target="_blank">' . $GLOBALS['LANG']->getLL('checkDependencies_remove_now') . '</a>';
00577                     $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $conflictK . ']" id="checkIgnore_' . $conflictK . '" />
00578                         <label for="checkIgnore_' . $conflictK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_conflict') . '</label>';
00579                     $conflictError = true;
00580                 }
00581             }
00582         }
00583         if ($conflictError || $conflictIgnore) {
00584             $content .= $this->parentObject->doc->section(
00585                 $GLOBALS['LANG']->getLL('checkDependencies_conflict_error'), implode('<br />', $msg), 0, 1, 2
00586             );
00587         }
00588 
00589         // Check suggests on other extensions:
00590         if (isset($conf['constraints']['suggests']) && is_array($conf['constraints']['suggests'])) {
00591             $suggestion = false;
00592             $suggestionIgnore = false;
00593             $msg = array();
00594             foreach ($conf['constraints']['suggests'] as $suggestK => $suggestV) {
00595                 if ($depsolver['ignore'][$suggestK]) {
00596                     $msg[] = '<br />' . sprintf($GLOBALS['LANG']->getLL('checkDependencies_suggestion_ignored'),
00597                         $suggestK) . '
00598                 <input type="hidden" value="1" name="depsolver[ignore][' . $suggestK . ']" />';
00599                     $suggestionIgnore = true;
00600                     continue;
00601                 }
00602                 if (!t3lib_extMgm::isLoaded($suggestK)) {
00603                     if (!isset($instExtInfo[$suggestK])) {
00604                         $msg[] = sprintf($GLOBALS['LANG']->getLL('checkDependencies_suggest_import'),
00605                             $suggestK);
00606                         $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;' . t3lib_iconWorks::getSpriteIcon('actions-system-extension-import', array('title' => $GLOBALS['LANG']->getLL('checkDependencies_import_ext'))) . '&nbsp;
00607                             <a href="' . t3lib_div::linkThisScript(array(
00608                             'CMD[importExt]' => $suggestK,
00609                             'CMD[loc]' => 'L',
00610                             'CMD[standAlone]' => 1
00611                         )) . '" target="_blank">' . $GLOBALS['LANG']->getLL('checkDependencies_import_now') . '</a>';
00612                         $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $suggestK . ']" id="checkIgnore_' . $suggestK . '" />
00613                             <label for="checkIgnore_' . $suggestK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_suggestion') . '</label>';
00614                     } else {
00615                         $msg[] = sprintf($GLOBALS['LANG']->getLL('checkDependencies_suggest_installation'),
00616                             $suggestK, $instExtInfo[$suggestK]['EM_CONF']['title']);
00617                         $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;' . tx_em_Tools::installButton() . '&nbsp;
00618                             <a href="' . htmlspecialchars(t3lib_div::linkThisScript(array(
00619                             'CMD[showExt]' => $suggestK,
00620                             'CMD[load]' => 1,
00621                             'CMD[clrCmd]' => 1,
00622                             'CMD[standAlone]' => 1,
00623                             'SET[singleDetails]' => 'info'
00624                         ))) .
00625                                 '" target="_blank">' . $GLOBALS['LANG']->getLL('checkDependencies_install_now') . '</a>';
00626                         $msg[] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="depsolver[ignore][' . $suggestK . ']" id="checkIgnore_' . $suggestK . '" />
00627                             <label for="checkIgnore_' . $suggestK . '">' . $GLOBALS['LANG']->getLL('checkDependencies_ignore_suggestion') . '</label>';
00628                     }
00629                     $suggestion = true;
00630                 }
00631             }
00632             if ($suggestion || $suggestionIgnore) {
00633                 $content .= $this->parentObject->doc->section(
00634                     sprintf($GLOBALS['LANG']->getLL('checkDependencies_exts_suggested_by_ext'), $extKey),
00635                     implode('<br />', $msg), 0, 1, 1
00636                 );
00637             }
00638         }
00639 
00640         if ($depError || $conflictError || $suggestion) {
00641             foreach ($this->parentObject->CMD as $k => $v) {
00642                 $content .= '<input type="hidden" name="CMD[' . $k . ']" value="' . $v . '" />';
00643             }
00644             $content .= '<br /><br /><input type="submit" value="' . $GLOBALS['LANG']->getLL('checkDependencies_try_again') . '" />';
00645 
00646             if (t3lib_div::_GP('nodoc')) {
00647                 $content .= '<input type="hidden" name="nodoc" value="1" />';
00648             }
00649 
00650             return array(
00651                 'returnCode' => FALSE,
00652                 'html' => '<form action="' . $this->parentObject->script . '" method="post" name="depform">' . $content . '</form>');
00653         }
00654 
00655         return array(
00656             'returnCode' => TRUE
00657         );
00658     }
00659 
00660 
00661     /**
00662      * Delete extension from the file system
00663      *
00664      * @param   string      Extension key
00665      * @param   array       Extension info array
00666      * @return  string      Returns message string about the status of the operation
00667      */
00668     function extDelete($extKey, $extInfo, $command) {
00669         $content = '';
00670         $absPath = tx_em_Tools::getExtPath($extKey, $extInfo['type']);
00671         if (t3lib_extMgm::isLoaded($extKey)) {
00672             return $GLOBALS['LANG']->getLL('extDelete_ext_active');
00673         } elseif (!tx_em_Tools::deleteAsType($extInfo['type'])) {
00674             return sprintf($GLOBALS['LANG']->getLL('extDelete_wrong_scope'),
00675                 $this->api->typeLabels[$extInfo['type']]
00676             );
00677         } elseif (t3lib_div::inList('G,L', $extInfo['type'])) {
00678             if ($command['doDelete'] && !strcmp($absPath, urldecode($command['absPath']))) {
00679                 $res = $this->removeExtDirectory($absPath);
00680                 if ($res) {
00681                     if (!$this->silentMode) {
00682                         $flashMessage = t3lib_div::makeInstance(
00683                             't3lib_FlashMessage',
00684                             nl2br($res),
00685                             sprintf($GLOBALS['LANG']->getLL('extDelete_remove_dir_failed'), $absPath),
00686                             t3lib_FlashMessage::ERROR
00687                         );
00688                         return $flashMessage->render();
00689                     }
00690                     return '';
00691                 } else {
00692                     if (!$this->silentMode) {
00693                         $flashMessage = t3lib_div::makeInstance(
00694                             't3lib_FlashMessage',
00695                             sprintf($GLOBALS['LANG']->getLL('extDelete_removed'), $absPath),
00696                             $GLOBALS['LANG']->getLL('extDelete_removed_header'),
00697                             t3lib_FlashMessage::OK
00698                         );
00699                         return $flashMessage->render();
00700                     }
00701                     return '';
00702                 }
00703             } else {
00704                 $areYouSure = $GLOBALS['LANG']->getLL('extDelete_sure');
00705                 $deleteFromServer = $GLOBALS['LANG']->getLL('extDelete_from_server');
00706                 $onClick = "if (confirm('$areYouSure')) {window.location.href='" . t3lib_div::linkThisScript(array(
00707                     'CMD[showExt]' => $extKey,
00708                     'CMD[doDelete]' => 1,
00709                     'CMD[absPath]' => rawurlencode($absPath)
00710                 )) . "';}";
00711                 $content .= '<a class="t3-link deleteLink" href="#" onclick="' . htmlspecialchars($onClick) .
00712                         ' return false;"><strong>' . $deleteFromServer . '</strong> ' .
00713                         sprintf($GLOBALS['LANG']->getLL('extDelete_from_location'),
00714                             $this->api->typeLabels[$extInfo['type']],
00715                             substr($absPath, strlen(PATH_site))
00716                         ) . '</a>';
00717                 $content .= '<br /><br />' . $GLOBALS['LANG']->getLL('extDelete_backup');
00718                 return $content;
00719             }
00720         } else {
00721             return $GLOBALS['LANG']->getLL('extDelete_neither_global_nor_local');
00722         }
00723     }
00724 
00725     /**
00726      * Removes the extension directory (including content)
00727      *
00728      * @param   string      Extension directory to remove (with trailing slash)
00729      * @param   boolean     If set, will leave the extension directory
00730      * @return  boolean     False on success, otherwise error string.
00731      */
00732     function removeExtDirectory($removePath, $removeContentOnly = 0) {
00733         $errors = array();
00734         if (@is_dir($removePath) && substr($removePath, -1) == '/' && (
00735                 t3lib_div::isFirstPartOfStr($removePath, tx_em_Tools::typePath('G')) ||
00736                         t3lib_div::isFirstPartOfStr($removePath, tx_em_Tools::typePath('L')) ||
00737                         (t3lib_div::isFirstPartOfStr($removePath, tx_em_Tools::typePath('S')) && $this->systemInstall) ||
00738                         t3lib_div::isFirstPartOfStr($removePath, PATH_site . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . '_temp_/')) // Playing-around directory...
00739         ) {
00740 
00741             // All files in extension directory:
00742             $fileArr = t3lib_div::getAllFilesAndFoldersInPath(array(), $removePath, '', 1);
00743             if (is_array($fileArr)) {
00744 
00745                 // Remove files in dirs:
00746                 foreach ($fileArr as $removeFile) {
00747                     if (!@is_dir($removeFile)) {
00748                         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!
00749                             @unlink($removeFile);
00750                             clearstatcache();
00751                             if (@is_file($removeFile)) {
00752                                 $errors[] = sprintf($GLOBALS['LANG']->getLL('rmExtDir_could_not_be_deleted'),
00753                                     $removeFile
00754                                 );
00755                             }
00756                         } else {
00757                             $errors[] = sprintf($GLOBALS['LANG']->getLL('rmExtDir_error_file'),
00758                                 $removeFile, $removePath
00759                             );
00760                         }
00761                     }
00762                 }
00763 
00764                 // Remove directories:
00765                 $remDirs = tx_em_Tools::extractDirsFromFileList(t3lib_div::removePrefixPathFromList($fileArr, $removePath));
00766                 $remDirs = array_reverse($remDirs); // Must delete outer directories first...
00767                 foreach ($remDirs as $removeRelDir) {
00768                     $removeDir = $removePath . $removeRelDir;
00769                     if (@is_dir($removeDir)) {
00770                         @rmdir($removeDir);
00771                         clearstatcache();
00772                         if (@is_dir($removeDir)) {
00773                             $errors[] = sprintf($GLOBALS['LANG']->getLL('rmExtDir_error_files_left'),
00774                                 $removeDir
00775                             );
00776                         }
00777                     } else {
00778                         $errors[] = sprintf($GLOBALS['LANG']->getLL('rmExtDir_error_no_dir'),
00779                             $removeDir
00780                         );
00781                     }
00782                 }
00783 
00784                 // If extension dir should also be removed:
00785                 if (!$removeContentOnly) {
00786                     @rmdir($removePath);
00787                     clearstatcache();
00788                     if (@is_dir($removePath)) {
00789                         $errors[] = sprintf($GLOBALS['LANG']->getLL('rmExtDir_error_folders_left'),
00790                             $removePath
00791                         );
00792                     }
00793                 }
00794             } else {
00795                 $errors[] = $GLOBALS['LANG']->getLL('rmExtDir_error') . ' ' . $fileArr;
00796             }
00797         } else {
00798             $errors[] = $GLOBALS['LANG']->getLL('rmExtDir_error_unallowed_path') . ' ' . $removePath;
00799         }
00800 
00801         // Return errors if any:
00802         return implode(LF, $errors);
00803     }
00804 
00805     /**
00806      * Validates the database according to extension requirements
00807      * Prints form for changes if any. If none, returns blank. If an update is ordered, empty is returned as well.
00808      * DBAL compliant (based on Install Tool code)
00809      *
00810      * @param   string      Extension key
00811      * @param   array       Extension information array
00812      * @param   boolean     If true, returns array with info.
00813      * @return  mixed       If $infoOnly, returns array with information. Otherwise performs update.
00814      */
00815     function checkDBupdates($extKey, $extInfo, $infoOnly = 0) {
00816 
00817 
00818         $dbStatus = array();
00819         $content = '';
00820 
00821         // Updating tables and fields?
00822         if (is_array($extInfo['files']) && in_array('ext_tables.sql', $extInfo['files'])) {
00823             $path = tx_em_Tools::getExtPath($extKey, $extInfo['type']);
00824             $fileContent = t3lib_div::getUrl($path . 'ext_tables.sql');
00825 
00826             $FDfile = $this->install->getFieldDefinitions_fileContent($fileContent);
00827             if (count($FDfile)) {
00828                 $FDdb = $this->install->getFieldDefinitions_database(TYPO3_db);
00829                 $diff = $this->install->getDatabaseExtra($FDfile, $FDdb);
00830                 $update_statements = $this->install->getUpdateSuggestions($diff);
00831 
00832                 $dbStatus['structure']['tables_fields'] = $FDfile;
00833                 $dbStatus['structure']['diff'] = $diff;
00834 
00835                 // Updating database...
00836                 if (!$infoOnly && is_array($this->install->INSTALL['database_update'])) {
00837                     $this->install->performUpdateQueries($update_statements['add'], $this->install->INSTALL['database_update']);
00838                     $this->install->performUpdateQueries($update_statements['change'], $this->install->INSTALL['database_update']);
00839                     $this->install->performUpdateQueries($update_statements['create_table'], $this->install->INSTALL['database_update']);
00840                 } else {
00841                     $content .= $this->install->generateUpdateDatabaseForm_checkboxes(
00842                         $update_statements['add'], $GLOBALS['LANG']->getLL('checkDBupdates_add_fields'));
00843                     $content .= $this->install->generateUpdateDatabaseForm_checkboxes(
00844                         $update_statements['change'], $GLOBALS['LANG']->getLL('checkDBupdates_changing_fields'), 1, 0, $update_statements['change_currentValue']);
00845                     $content .= $this->install->generateUpdateDatabaseForm_checkboxes(
00846                         $update_statements['create_table'], $GLOBALS['LANG']->getLL('checkDBupdates_add_tables'));
00847                 }
00848             }
00849         }
00850 
00851         // Importing static tables?
00852         if (is_array($extInfo['files']) && in_array('ext_tables_static+adt.sql', $extInfo['files'])) {
00853             $fileContent = t3lib_div::getUrl(tx_em_Tools::getExtPath($extKey, $extInfo['type']) . 'ext_tables_static+adt.sql');
00854 
00855             $statements = $this->install->getStatementarray($fileContent, 1);
00856             list($statements_table, $insertCount) = $this->install->getCreateTables($statements, 1);
00857 
00858             // Execute import of static table content:
00859             if (!$infoOnly && is_array($this->install->INSTALL['database_import'])) {
00860 
00861                 // Traverse the tables
00862                 foreach ($this->install->INSTALL['database_import'] as $table => $md5str) {
00863                     if ($md5str == md5($statements_table[$table])) {
00864                         $GLOBALS['TYPO3_DB']->admin_query('DROP TABLE IF EXISTS ' . $table);
00865                         $GLOBALS['TYPO3_DB']->admin_query($statements_table[$table]);
00866 
00867                         if ($insertCount[$table]) {
00868                             $statements_insert = $this->install->getTableInsertStatements($statements, $table);
00869 
00870                             foreach ($statements_insert as $v) {
00871                                 $GLOBALS['TYPO3_DB']->admin_query($v);
00872                             }
00873                         }
00874                     }
00875                 }
00876             } else {
00877                 $whichTables = $this->install->getListOfTables();
00878                 if (count($statements_table)) {
00879                     $out = '';
00880                     foreach ($statements_table as $table => $definition) {
00881                         $exist = isset($whichTables[$table]);
00882 
00883                         $dbStatus['static'][$table]['exists'] = $exist;
00884                         $dbStatus['static'][$table]['count'] = $insertCount[$table];
00885 
00886                         $out .= '<tr>
00887                             <td><input type="checkbox" name="TYPO3_INSTALL[database_import][' . $table . ']" checked="checked" value="' . md5($definition) . '" /></td>
00888                             <td><strong>' . $table . '</strong></td>
00889                             <td><img src="clear.gif" width="10" height="1" alt="" /></td>
00890                             <td nowrap="nowrap">' .
00891                                 ($insertCount[$table] ?
00892                                         $GLOBALS['LANG']->getLL('checkDBupdates_rows') . ' ' . $insertCount[$table]
00893                                         : '') .
00894                                 '</td>
00895                             <td><img src="clear.gif" width="10" height="1" alt="" /></td>
00896                             <td nowrap="nowrap">' .
00897                                 ($exist ?
00898                                         t3lib_iconWorks::getSpriteIcon('status-dialog-warning') .
00899                                                 $GLOBALS['LANG']->getLL('checkDBupdates_table_exists')
00900                                         : '') .
00901                                 '</td>
00902                             </tr>';
00903                     }
00904                     $content .= '
00905                         <br />
00906                         <h3>' . $GLOBALS['LANG']->getLL('checkDBupdates_import_static_data') . '</h3>
00907                         <table border="0" cellpadding="0" cellspacing="0">' . $out . '</table>
00908                         ';
00909                 }
00910             }
00911         }
00912 
00913         // Return array of information if $infoOnly, otherwise content.
00914         return $infoOnly ? $dbStatus : $content;
00915     }
00916 
00917     /**
00918      * Removes the current extension of $type and creates the base folder for the new one (which is going to be imported)
00919      *
00920      * @param   array       Data for imported extension
00921      * @param   string      Extension installation scope (L,G,S)
00922      * @param   boolean     If set, nothing will be deleted (neither directory nor files)
00923      * @return  mixed       Returns array on success (with extension directory), otherwise an error string.
00924      */
00925     function clearAndMakeExtensionDir($importedData, $type, $dontDelete = 0) {
00926         if (!$importedData['extKey']) {
00927             return $GLOBALS['LANG']->getLL('clearMakeExtDir_no_ext_key');
00928         }
00929 
00930         // Setting install path (L, G, S or fileadmin/_temp_/)
00931         $path = '';
00932         switch ((string) $type) {
00933             case 'G':
00934             case 'L':
00935                 $path = tx_em_Tools::typePath($type);
00936                 $suffix = '';
00937 
00938                 // Creates the typo3conf/ext/ directory if it does NOT already exist:
00939                 if ((string) $type == 'L' && !@is_dir($path)) {
00940                     t3lib_div::mkdir($path);
00941                 }
00942                 break;
00943             default:
00944                 if ($this->systemInstall && (string) $type == 'S') {
00945                     $path = tx_em_Tools::typePath($type);
00946                     $suffix = '';
00947                 } else {
00948                     $path = PATH_site . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . '_temp_/';
00949                     $suffix = '_' . date('dmy-His');
00950                 }
00951                 break;
00952         }
00953 
00954         // If the install path is OK...
00955         if ($path && @is_dir($path)) {
00956 
00957             // Set extension directory:
00958             $extDirPath = $path . $importedData['extKey'] . $suffix . '/';
00959 
00960             // Install dir was found, remove it then:
00961             if (@is_dir($extDirPath)) {
00962                 if ($dontDelete) {
00963                     return array($extDirPath);
00964                 }
00965                 $res = $this->removeExtDirectory($extDirPath);
00966                 if ($res) {
00967                     if (!$this->silentMode) {
00968                         $flashMessage = t3lib_div::makeInstance(
00969                             't3lib_FlashMessage',
00970                             nl2br($res),
00971                             sprintf($GLOBALS['LANG']->getLL('clearMakeExtDir_could_not_remove_dir'), $extDirPath),
00972                             t3lib_FlashMessage::ERROR
00973                         );
00974                         return $flashMessage->render();
00975                     }
00976                     return '';
00977                 }
00978             }
00979 
00980             // We go create...
00981             t3lib_div::mkdir($extDirPath);
00982             if (!is_dir($extDirPath)) {
00983                 return sprintf($GLOBALS['LANG']->getLL('clearMakeExtDir_could_not_create_dir'),
00984                     $extDirPath);
00985             }
00986             return array($extDirPath);
00987         } else {
00988             return sprintf($GLOBALS['LANG']->getLL('clearMakeExtDir_no_dir'),
00989                 $path);
00990         }
00991     }
00992 
00993 
00994     /*******************************
00995      *
00996      * Extension analyzing (detailed information)
00997      *
00998      ******************************/
00999 
01000     /**
01001      * Perform a detailed, technical analysis of the available extension on server!
01002      * Includes all kinds of verifications
01003      * Takes some time to process, therfore use with care, in particular in listings.
01004      *
01005      * @param   string      Extension key
01006      * @param   array       Extension information
01007      * @param   boolean     If set, checks for validity of classes etc.
01008      * @return  array       Information in an array.
01009      */
01010     function makeDetailedExtensionAnalysis($extKey, $extInfo, $validity = 0) {
01011 
01012         // Get absolute path of the extension
01013         $absPath = tx_em_Tools::getExtPath($extKey, $extInfo['type']);
01014         $extensionDetails = t3lib_div::makeInstance('tx_em_Extensions_Details', $this);
01015         $infoArray = array();
01016 
01017         $table_class_prefix = substr($extKey, 0, 5) == 'user_' ? 'user_' : 'tx_' . str_replace('_', '', $extKey) . '_';
01018         $module_prefix = substr($extKey, 0, 5) == 'user_' ? 'u' : 'tx' . str_replace('_', '', $extKey);
01019 
01020         // Database status:
01021         $dbInfo = $this->checkDBupdates($extKey, $extInfo, 1);
01022 
01023         // Database structure required:
01024         if (is_array($dbInfo['structure']['tables_fields'])) {
01025             $modify_tables = t3lib_div::trimExplode(',', $extInfo['EM_CONF']['modify_tables'], 1);
01026             $infoArray['dump_tf'] = array();
01027 
01028             foreach ($dbInfo['structure']['tables_fields'] as $tN => $d) {
01029                 if (in_array($tN, $modify_tables)) {
01030                     $infoArray['fields'][] = $tN . ': <i>' .
01031                             (is_array($d['fields']) ? implode(', ', array_keys($d['fields'])) : '') .
01032                             (is_array($d['keys']) ?
01033                                     ' + ' . count($d['keys']) . ' ' . $GLOBALS['LANG']->getLL('detailedExtAnalysis_keys') : '') .
01034                             '</i>';
01035                     if (is_array($d['fields'])) {
01036                         foreach ($d['fields'] as $fN => $value) {
01037                             $infoArray['dump_tf'][] = $tN . '.' . $fN;
01038                             if (!t3lib_div::isFirstPartOfStr($fN, $table_class_prefix)) {
01039                                 $infoArray['NSerrors']['fields'][$fN] = $fN;
01040                             } else {
01041                                 $infoArray['NSok']['fields'][$fN] = $fN;
01042                             }
01043                         }
01044                     }
01045                     if (is_array($d['keys'])) {
01046                         foreach ($d['keys'] as $fN => $value) {
01047                             $infoArray['dump_tf'][] = $tN . '.KEY:' . $fN;
01048                         }
01049                     }
01050                 } else {
01051                     $infoArray['dump_tf'][] = $tN;
01052                     $infoArray['tables'][] = $tN;
01053                     if (!t3lib_div::isFirstPartOfStr($tN, $table_class_prefix)) {
01054                         $infoArray['NSerrors']['tables'][$tN] = $tN;
01055                     } else {
01056                         $infoArray['NSok']['tables'][$tN] = $tN;
01057                     }
01058                 }
01059             }
01060             if (count($dbInfo['structure']['diff']['diff']) || count($dbInfo['structure']['diff']['extra'])) {
01061                 $msg = array();
01062                 if (count($dbInfo['structure']['diff']['diff'])) {
01063                     $msg[] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_tables_are_missing');
01064                 }
01065                 if (count($dbInfo['structure']['diff']['extra'])) {
01066                     $msg[] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_tables_are_of_wrong_type');
01067                 }
01068                 $infoArray['tables_error'] = 1;
01069                 if (t3lib_extMgm::isLoaded($extKey)) {
01070                     $infoArray['errors'][] = sprintf($GLOBALS['LANG']->getLL('detailedExtAnalysis_tables_are'),
01071                         implode(' ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:and') . ' ', $msg)
01072                     );
01073                 }
01074             }
01075         }
01076 
01077         // Static tables?
01078         if (is_array($dbInfo['static'])) {
01079             $infoArray['static'] = array_keys($dbInfo['static']);
01080 
01081             foreach ($dbInfo['static'] as $tN => $d) {
01082                 if (!$d['exists']) {
01083                     $infoArray['static_error'] = 1;
01084                     if (t3lib_extMgm::isLoaded($extKey)) {
01085                         $infoArray['errors'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_static_tables_missing');
01086                     }
01087                     if (!t3lib_div::isFirstPartOfStr($tN, $table_class_prefix)) {
01088                         $infoArray['NSerrors']['tables'][$tN] = $tN;
01089                     } else {
01090                         $infoArray['NSok']['tables'][$tN] = $tN;
01091                     }
01092                 }
01093             }
01094         }
01095 
01096         // Backend Module-check:
01097         $knownModuleList = t3lib_div::trimExplode(',', $extInfo['EM_CONF']['module'], 1);
01098         foreach ($knownModuleList as $mod) {
01099             if (@is_dir($absPath . $mod)) {
01100                 if (@is_file($absPath . $mod . '/conf.php')) {
01101                     $confFileInfo = $extensionDetails->modConfFileAnalysis($absPath . $mod . '/conf.php');
01102                     if (is_array($confFileInfo['TYPO3_MOD_PATH'])) {
01103                         $shouldBePath = tx_em_Tools::typeRelPath($extInfo['type']) . $extKey . '/' . $mod . '/';
01104                         if (strcmp($confFileInfo['TYPO3_MOD_PATH'][1][1], $shouldBePath)) {
01105                             $infoArray['errors'][] = sprintf($GLOBALS['LANG']->getLL('detailedExtAnalysis_wrong_mod_path'),
01106                                 $confFileInfo['TYPO3_MOD_PATH'][1][1],
01107                                 $shouldBePath
01108                             );
01109                         }
01110                     } else {
01111                         // It seems like TYPO3_MOD_PATH and therefore also this warning is no longer needed.
01112                         // $infoArray['errors'][] = 'No definition of TYPO3_MOD_PATH constant found inside!';
01113                     }
01114                     if (is_array($confFileInfo['MCONF_name'])) {
01115                         $mName = $confFileInfo['MCONF_name'][1][1];
01116                         $mNameParts = explode('_', $mName);
01117                         $infoArray['moduleNames'][] = $mName;
01118                         if (!t3lib_div::isFirstPartOfStr($mNameParts[0], $module_prefix) &&
01119                                 (!$mNameParts[1] || !t3lib_div::isFirstPartOfStr($mNameParts[1], $module_prefix))) {
01120                             $infoArray['NSerrors']['modname'][] = $mName;
01121                         } else {
01122                             $infoArray['NSok']['modname'][] = $mName;
01123                         }
01124                     } else {
01125                         $infoArray['errors'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_mconf_missing');
01126                     }
01127                 } else  {
01128                     $infoArray['errors'][] = sprintf($GLOBALS['LANG']->getLL('detailedExtAnalysis_be_module_conf_missing'),
01129                             $mod . '/conf.php'
01130                     );
01131                 }
01132             } else {
01133                 $infoArray['errors'][] = sprintf($GLOBALS['LANG']->getLL('detailedExtAnalysis_module_folder_missing'),
01134                         $mod . '/'
01135                 );
01136             }
01137         }
01138         $dirs = t3lib_div::get_dirs($absPath);
01139         if (is_array($dirs)) {
01140             reset($dirs);
01141             while (list(, $mod) = each($dirs)) {
01142                 if (!in_array($mod, $knownModuleList) && @is_file($absPath . $mod . '/conf.php')) {
01143                     $confFileInfo = $extensionDetails->modConfFileAnalysis($absPath . $mod . '/conf.php');
01144                     if (is_array($confFileInfo)) {
01145                         $infoArray['errors'][] = sprintf($GLOBALS['LANG']->getLL('detailedExtAnalysis_unconfigured_module'),
01146                                 $mod . '/conf.php'
01147                         );
01148                     }
01149                 }
01150             }
01151         }
01152 
01153         // ext_tables.php:
01154         if (@is_file($absPath . 'ext_tables.php')) {
01155             $content = t3lib_div::getUrl($absPath . 'ext_tables.php');
01156             if (stristr($content, 't3lib_extMgm::addModule')) {
01157                 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_module');
01158             }
01159             if (stristr($content, 't3lib_extMgm::insertModuleFunction')) {
01160                 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_module_and_more');
01161             }
01162             if (stristr($content, 't3lib_div::loadTCA')) {
01163                 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_loadTCA');
01164             }
01165             if (stristr($content, '$TCA[')) {
01166                 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_TCA');
01167             }
01168             if (stristr($content, 't3lib_extMgm::addPlugin')) {
01169                 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_plugin');
01170             }
01171         }
01172 
01173         // ext_localconf.php:
01174         if (@is_file($absPath . 'ext_localconf.php')) {
01175             $content = t3lib_div::getUrl($absPath . 'ext_localconf.php');
01176             if (stristr($content, 't3lib_extMgm::addPItoST43')) {
01177                 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_plugin_st43');
01178             }
01179             if (stristr($content, 't3lib_extMgm::addPageTSConfig')) {
01180                 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_page_ts');
01181             }
01182             if (stristr($content, 't3lib_extMgm::addUserTSConfig')) {
01183                 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_user_ts');
01184             }
01185             if (stristr($content, 't3lib_extMgm::addTypoScriptSetup')) {
01186                 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_ts_setup');
01187             }
01188             if (stristr($content, 't3lib_extMgm::addTypoScriptConstants')) {
01189                 $infoArray['flags'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_ts_constants');
01190             }
01191         }
01192 
01193         if (@is_file($absPath . 'ext_typoscript_constants.txt')) {
01194             $infoArray['TSfiles'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_constants');
01195         }
01196         if (@is_file($absPath . 'ext_typoscript_setup.txt')) {
01197             $infoArray['TSfiles'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_setup');
01198         }
01199         if (@is_file($absPath . 'ext_conf_template.txt')) {
01200             $infoArray['conf'] = 1;
01201         }
01202 
01203         // Classes:
01204         if ($validity) {
01205             $filesInside = tx_em_Tools::getClassIndexLocallangFiles($absPath, $table_class_prefix, $extKey);
01206             if (is_array($filesInside['errors'])) {
01207                 $infoArray['errors'] = array_merge((array) $infoArray['errors'], $filesInside['errors']);
01208             }
01209             if (is_array($filesInside['NSerrors'])) {
01210                 $infoArray['NSerrors'] = array_merge((array) $infoArray['NSerrors'], $filesInside['NSerrors']);
01211             }
01212             if (is_array($filesInside['NSok'])) {
01213                 $infoArray['NSok'] = array_merge((array) $infoArray['NSok'], $filesInside['NSok']);
01214             }
01215             $infoArray['locallang'] = $filesInside['locallang'];
01216             $infoArray['classes'] = $filesInside['classes'];
01217         }
01218 
01219         // Upload folders
01220         if ($extInfo['EM_CONF']['uploadfolder']) {
01221             $infoArray['uploadfolder'] = tx_em_Tools::uploadFolder($extKey);
01222             if (!@is_dir(PATH_site . $infoArray['uploadfolder'])) {
01223                 $infoArray['errors'][] = sprintf($GLOBALS['LANG']->getLL('detailedExtAnalysis_no_upload_folder'),
01224                     $infoArray['uploadfolder']
01225                 );
01226                 $infoArray['uploadfolder'] = '';
01227             }
01228         }
01229 
01230         // Create directories:
01231         if ($extInfo['EM_CONF']['createDirs']) {
01232             $infoArray['createDirs'] = array_unique(t3lib_div::trimExplode(',', $extInfo['EM_CONF']['createDirs'], 1));
01233             foreach ($infoArray['createDirs'] as $crDir) {
01234                 if (!@is_dir(PATH_site . $crDir)) {
01235                     $infoArray['errors'][] = sprintf($GLOBALS['LANG']->getLL('detailedExtAnalysis_no_upload_folder'),
01236                         $crDir
01237                     );
01238                 }
01239             }
01240         }
01241 
01242         // Return result array:
01243         return $infoArray;
01244     }
01245 
01246 
01247     /**
01248      * Produces the config form for an extension (if any template file, ext_conf_template.txt is found)
01249      *
01250      * @param   string      Extension key
01251      * @param   array       Extension information array
01252      * @param   boolean     If true, the form HTML content is returned, otherwise the content is set in $this->content.
01253      * @param   string      Submit-to URL (supposedly)
01254      * @param   string      Additional form fields to include.
01255      * @return  string      Depending on $output. Can return the whole form.
01256      */
01257     function tsStyleConfigForm($extKey, $extInfo, $output = 0, $script = '', $addFields = '') {
01258         global $TYPO3_CONF_VARS;
01259 
01260             // Initialize:
01261         $absPath = tx_em_Tools::getExtPath($extKey, $extInfo['type']);
01262         $relPath = tx_em_Tools::typeRelPath($extInfo['type']) . $extKey . '/';
01263 
01264         $form = '';
01265 
01266             // Look for template file for form:
01267         if (t3lib_extMgm::isLoaded($extKey) && @is_file($absPath . 'ext_conf_template.txt')) {
01268 
01269                 // Load tsStyleConfig class and parse configuration template:
01270             $tsStyleConfig = t3lib_div::makeInstance('t3lib_tsStyleConfig');
01271             $tsStyleConfig->doNotSortCategoriesBeforeMakingForm = TRUE;
01272             $theConstants = $tsStyleConfig->ext_initTSstyleConfig(
01273                 t3lib_div::getUrl($absPath . 'ext_conf_template.txt'),
01274                 $relPath,
01275                 $absPath,
01276                 $GLOBALS['BACK_PATH']
01277             );
01278 
01279                 // Load the list of resources.
01280             $tsStyleConfig->ext_loadResources($absPath . 'res/');
01281 
01282                 // Load current value:
01283             $arr = unserialize($TYPO3_CONF_VARS['EXT']['extConf'][$extKey]);
01284             $arr = is_array($arr) ? $arr : array();
01285 
01286                 // Call processing function for constants config and data before write and form rendering:
01287             if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/mod/tools/em/index.php']['tsStyleConfigForm'])) {
01288                 $_params = array('fields' => &$theConstants, 'data' => &$arr, 'extKey' => $extKey);
01289                 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/mod/tools/em/index.php']['tsStyleConfigForm'] as $_funcRef) {
01290                     t3lib_div::callUserFunction($_funcRef, $_params, $this);
01291                 }
01292                 unset($_params);
01293             }
01294 
01295                 // If saving operation is done:
01296             if (t3lib_div::_POST('submit')) {
01297                 $tsStyleConfig->ext_procesInput(t3lib_div::_POST(), array(), $theConstants, array());
01298                 $arr = $tsStyleConfig->ext_mergeIncomingWithExisting($arr);
01299                 $this->writeTsStyleConfig($extKey, $arr);
01300             }
01301 
01302                 // Setting value array
01303             $tsStyleConfig->ext_setValuearray($theConstants, $arr);
01304 
01305                 // Getting session data:
01306             $MOD_MENU = array();
01307             $MOD_MENU['constant_editor_cat'] = $tsStyleConfig->ext_getCategoriesForModMenu();
01308             $MOD_SETTINGS = t3lib_BEfunc::getModuleData($MOD_MENU, t3lib_div::_GP('SET'), 'xMod_test');
01309 
01310                 // Resetting the menu (stop)
01311             if (count($MOD_MENU['constant_editor_cat']) > 1) {
01312                 $menu = $GLOBALS['LANG']->getLL('extInfoArray_category') . ' ' .
01313                         t3lib_BEfunc::getFuncMenu(0, 'SET[constant_editor_cat]', $MOD_SETTINGS['constant_editor_cat'], $MOD_MENU['constant_editor_cat'], '', '&CMD[showExt]=' . $extKey);
01314                     // add class to select
01315                 $menu = str_replace('<select', '<select class="mod-menu-template-select"', $menu);
01316                 if ($this->silentMode) {
01317                     $menu = str_replace('jumpToUrl', 'abc', $menu);
01318                 }
01319 
01320                 if ($this->parentObject instanceof SC_mod_tools_em_index) {
01321                     $this->parentObject->content .= $this->parentObject->doc->section('', '<span class="nobr">' . $menu . '</span>');
01322                     $this->parentObject->content .= $this->parentObject->doc->spacer(10);
01323                 } else {
01324                     $form .= '<h3>' . '<span class="nobr">' . $menu . '</span></h3>';
01325                 }
01326             }
01327 
01328                 // Category and constant editor config:
01329             $form .= '
01330                 <table border="0" cellpadding="0" cellspacing="0" width="600">
01331                     <tr>
01332                         <td>' . $tsStyleConfig->ext_getForm(
01333                             $MOD_SETTINGS['constant_editor_cat'],
01334                             $theConstants,
01335                             $script,
01336                             $addFields,
01337                             $extKey,
01338                             !$this->silentMode
01339                         ) . ($this->silentMode ? '' : '</form>') .'</td>
01340                     </tr>
01341                 </table>';
01342         } else {
01343             if (!$this->silentMode) {
01344                 $flashMessage = t3lib_div::makeInstance(
01345                     't3lib_FlashMessage',
01346                     $GLOBALS['LANG']->getLL('tsStyleConfigForm_additional_config'),
01347                     '',
01348                     t3lib_FlashMessage::INFO
01349                 );
01350             }
01351 
01352             $form = '
01353                 <table border="0" cellpadding="0" cellspacing="0" width="600">
01354                     <tr>
01355                         <td>
01356                             <form action="' . htmlspecialchars($script) . '" method="post">' .
01357                     $addFields .
01358                     ($this->silentMode ? '' : $flashMessage->render()) .
01359                     (t3lib_div::_GP('nodoc') ? '<input type="hidden" name="nodoc" value="1" />' : '') .
01360                     '<br /><input type="submit" id="configuration-submit-' . $extKey . '" name="write" value="' . $GLOBALS['LANG']->getLL('updatesForm_make_updates') . '" />
01361                             </form>
01362                         </td>
01363                     </tr>
01364                 </table>';
01365         }
01366 
01367 
01368         return $form;
01369 
01370     }
01371 
01372     /**
01373      * Writes the TSstyleconf values to "localconf.php"
01374      * Removes the temp_CACHED* files before return.
01375      *
01376      * @param   string      Extension key
01377      * @param   array       Configuration array to write back
01378      * @return  void
01379      */
01380     function writeTsStyleConfig($extKey, $arr) {
01381 
01382         // Instance of install tool
01383         $instObj = new t3lib_install;
01384         $instObj->allowUpdateLocalConf = 1;
01385         $instObj->updateIdentity = 'TYPO3 Extension Manager';
01386 
01387         // Get lines from localconf file
01388         $lines = $instObj->writeToLocalconf_control();
01389         $instObj->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXT\'][\'extConf\'][\'' . $extKey . '\']', serialize($arr)); // This will be saved only if there are no linebreaks in it !
01390         $instObj->writeToLocalconf_control($lines);
01391 
01392         t3lib_extMgm::removeCacheFiles();
01393     }
01394 
01395 
01396     /**
01397      * Creates a form for an extension which contains all options for configuration, updates of database, clearing of cache etc.
01398      *
01399      * @param  string  $extKey  Extension key
01400      * @param  array  $extInfo  Extension information array
01401      * @param  boolean  $notSilent  If set, the form will ONLY show if fields/tables should be updated (suppressing forms like general configuration and cache clearing).
01402      * @param  string  $script  Alternative action=""-script
01403      * @param  string  $addFields  Additional form fields
01404      * @param  boolean  $addFormTags  TRUE if it shopuld be wrapped with form tag
01405      * @param  boolean  $excludeDatabaseCheck  TRUE if no database check should be done
01406      * @return  string
01407      */
01408     function updatesForm($extKey, $extInfo, $notSilent = FALSE, $script = '', $addFields = '', $addFormTag = TRUE, $excludeDatabaseCheck = FALSE) {
01409         $script = $script ? $script : t3lib_div::linkThisScript();
01410         if ($addFormTag) {
01411             $formWrap = array('<form action="' . htmlspecialchars($script) . '" method="POST">', '</form>');
01412         } else {
01413             $formWrap = array('', '');
01414         }
01415         $extensionDetails = t3lib_div::makeInstance('tx_em_Extensions_Details', $this);
01416         $updates = '';
01417 
01418         if (!$excludeDatabaseCheck) {
01419             $updates .= $this->checkDBupdates($extKey, $extInfo);
01420         }
01421 
01422         $uCache = $this->checkClearCache($extInfo);
01423         if ($notSilent) {
01424             $updates .= $uCache;
01425         }
01426         $updates .= $extensionDetails->checkUploadFolder($extKey, $extInfo);
01427 
01428         $absPath = tx_em_Tools::getExtPath($extKey, $extInfo['type']);
01429         if ($notSilent && @is_file($absPath . 'ext_conf_template.txt')) {
01430             $configForm = $this->tsStyleConfigForm($extKey, $extInfo, 1, $script, $updates . $addFields . '<br />');
01431         }
01432 
01433         if ($updates || $configForm) {
01434             if ($configForm) {
01435                 $updates = $configForm;
01436             } else {
01437                 $updates = $formWrap[0] . $updates . $addFields . '
01438                     <br /><input type="submit" name="write" id="update-submit-' . $extKey . '" value="' . $GLOBALS['LANG']->getLL('updatesForm_make_updates') . '" />
01439                 ' . $formWrap[1];
01440             }
01441         }
01442 
01443         return $updates;
01444     }
01445 
01446 
01447     /**
01448      * Check if clear-cache should be performed, otherwise show form (for installation of extension)
01449      * Shown only if the extension has the clearCacheOnLoad flag set.
01450      *
01451      * @param   string      Extension key
01452      * @param   array       Extension information array
01453      * @return  string      HTML output (if form is shown)
01454      */
01455     function checkClearCache($extInfo) {
01456         $content = '';
01457         if ($extInfo['EM_CONF']['clearCacheOnLoad']) {
01458             if (t3lib_div::_POST('_clear_all_cache')) { // Action: Clearing the cache
01459                 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
01460                 $tce->stripslashes_values = 0;
01461                 $tce->start(array(), array());
01462                 $tce->clear_cacheCmd('all');
01463             } else { // Show checkbox for clearing cache:
01464                 $content .= '
01465                     <br />
01466                     <h3>' . $GLOBALS['LANG']->getLL('checkUploadFolder_clear_cache') . '</h3>
01467                     <p>' . $GLOBALS['LANG']->getLL('checkUploadFolder_clear_cache_requested') . '<br />
01468                         <label for="check_clear_all_cache">' . $GLOBALS['LANG']->getLL('checkUploadFolder_clear_all_cache') . '</label>
01469                         <input type="checkbox" name="_clear_all_cache" id="check_clear_all_cache" checked="checked" value="1" /><br />
01470                     </p>
01471                 ';
01472             }
01473         }
01474         return $content;
01475     }
01476 
01477     /**
01478      * Writes the extension list to "localconf.php" file
01479      * Removes the temp_CACHED* files before return.
01480      *
01481      * @param   string      List of extensions
01482      * @return  void
01483      */
01484     function writeNewExtensionList($newExtList) {
01485         $strippedExtensionList = $this->stripNonFrontendExtensions($newExtList);
01486 
01487         // Instance of install tool
01488         $instObj = new t3lib_install;
01489         $instObj->allowUpdateLocalConf = 1;
01490         $instObj->updateIdentity = 'TYPO3 Extension Manager';
01491 
01492         // Get lines from localconf file
01493         $lines = $instObj->writeToLocalconf_control();
01494         $instObj->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXT\'][\'extList\']', $newExtList);
01495         $instObj->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXT\'][\'extList_FE\']', $strippedExtensionList);
01496         $instObj->writeToLocalconf_control($lines);
01497 
01498         $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'] = $newExtList;
01499         $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList_FE'] = $strippedExtensionList;
01500         t3lib_extMgm::removeCacheFiles();
01501     }
01502 
01503     /**
01504      * Removes unneeded extensions from the frontend based on
01505      * EMCONF doNotLoadInFE = 1
01506      *
01507      * @param string $extList
01508      * @return string
01509      */
01510     function stripNonFrontendExtensions($extList) {
01511         $fullExtList = $this->parentObject->extensionList->getInstalledExtensions();
01512         $extListArray = t3lib_div::trimExplode(',', $extList);
01513         foreach ($extListArray as $arrayKey => $extKey) {
01514             if ($fullExtList[0][$extKey]['EM_CONF']['doNotLoadInFE'] == 1) {
01515                 unset($extListArray[$arrayKey]);
01516             }
01517         }
01518         $nonFEList = implode(',', $extListArray);
01519         return $nonFEList;
01520     }
01521 
01522     /**
01523      * Updates the database according to extension requirements
01524      * DBAL compliant (based on Install Tool code)
01525      *
01526      * @param   string      Extension key
01527      * @param   array       Extension information array
01528      * @return  void
01529      */
01530     function forceDBupdates($extKey, $extInfo) {
01531         $instObj = new t3lib_install;
01532 
01533         // Updating tables and fields?
01534         if (is_array($extInfo['files']) && in_array('ext_tables.sql', $extInfo['files'])) {
01535             $fileContent = t3lib_div::getUrl(tx_em_Tools::getExtPath($extKey, $extInfo['type']) . 'ext_tables.sql');
01536 
01537             $FDfile = $instObj->getFieldDefinitions_fileContent($fileContent);
01538             if (count($FDfile)) {
01539                 $FDdb = $instObj->getFieldDefinitions_database(TYPO3_db);
01540                 $diff = $instObj->getDatabaseExtra($FDfile, $FDdb);
01541                 $update_statements = $instObj->getUpdateSuggestions($diff);
01542 
01543                 foreach ((array) $update_statements['add'] as $string) {
01544                     $GLOBALS['TYPO3_DB']->admin_query($string);
01545                 }
01546                 foreach ((array) $update_statements['change'] as $string) {
01547                     $GLOBALS['TYPO3_DB']->admin_query($string);
01548                 }
01549                 foreach ((array) $update_statements['create_table'] as $string) {
01550                     $GLOBALS['TYPO3_DB']->admin_query($string);
01551                 }
01552             }
01553         }
01554 
01555         // Importing static tables?
01556         if (is_array($extInfo['files']) && in_array('ext_tables_static+adt.sql', $extInfo['files'])) {
01557             $fileContent = t3lib_div::getUrl(tx_em_Tools::getExtPath($extKey, $extInfo['type']) . 'ext_tables_static+adt.sql');
01558 
01559             $statements = $instObj->getStatementarray($fileContent, 1);
01560             list($statements_table, $insertCount) = $instObj->getCreateTables($statements, 1);
01561 
01562             // Traverse the tables
01563             foreach ($statements_table as $table => $query) {
01564                 $GLOBALS['TYPO3_DB']->admin_query('DROP TABLE IF EXISTS ' . $table);
01565                 $GLOBALS['TYPO3_DB']->admin_query($query);
01566 
01567                 if ($insertCount[$table]) {
01568                     $statements_insert = $instObj->getTableInsertStatements($statements, $table);
01569 
01570                     foreach ($statements_insert as $v) {
01571                         $GLOBALS['TYPO3_DB']->admin_query($v);
01572                     }
01573                 }
01574             }
01575         }
01576     }
01577 
01578 }
01579 
01580 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/install/class.tx_em_install.php'])) {
01581     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/install/class.tx_em_install.php']);
01582 }
01583 
01584 ?>