/**
  * Calls addJsFile for each file in the given folder on the Instance of TYPO3\CMS\Core\Page\PageRenderer.
  *
  * @param string $name the file to include
  * @param string $extKey the extension, where the file is located
  * @param string $pathInsideExt the path to the file relative to the ext-folder
  * @param bool $recursive
  */
 public function render($name = null, $extKey = null, $pathInsideExt = 'Resources/Public/JavaScript/', $recursive = false)
 {
     if ($extKey == null) {
         $extKey = $this->controllerContext->getRequest()->getControllerExtensionKey();
     }
     $extPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($extKey);
     if (TYPO3_MODE === 'FE') {
         $extRelPath = substr($extPath, strlen(PATH_site));
     } else {
         $extRelPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($extKey);
     }
     $absFolderPath = $extPath . $pathInsideExt . $name;
     // $files will include all files relative to $pathInsideExt
     if ($recursive === false) {
         $files = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($absFolderPath);
         foreach ($files as $hash => $filename) {
             $files[$hash] = $name . $filename;
         }
     } else {
         $files = \TYPO3\CMS\Core\Utility\GeneralUtility::getAllFilesAndFoldersInPath([], $absFolderPath, '', 0, 99, '\\.svn');
         foreach ($files as $hash => $absPath) {
             $files[$hash] = str_replace($extPath . $pathInsideExt, '', $absPath);
         }
     }
     foreach ($files as $name) {
         $this->pageRenderer->addJsFile($extRelPath . $pathInsideExt . $name);
     }
 }
 /**
  * Deletes all files older than a specific time in a temporary upload folder.
  * Settings for the threshold time and the folder are made in TypoScript.
  *
  * @param integer $olderThanValue Delete files older than this value.
  * @param string $olderThanUnit The unit for $olderThan. May be seconds|minutes|hours|days
  * @return void
  * @author	Reinhard Führicht <*****@*****.**>
  */
 protected function clearTempFiles($olderThanValue, $olderThanUnit)
 {
     if (!$olderThanValue) {
         return;
     }
     $uploadFolders = $this->utilityFuncs->getAllTempUploadFolders();
     foreach ($uploadFolders as $uploadFolder) {
         //build absolute path to upload folder
         $path = $this->utilityFuncs->getDocumentRoot() . $uploadFolder;
         $path = $this->utilityFuncs->sanitizePath($path);
         //read files in directory
         $tmpFiles = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($path);
         $this->utilityFuncs->debugMessage('cleaning_temp_files', array($path));
         //calculate threshold timestamp
         $threshold = $this->utilityFuncs->getTimestamp($olderThanValue, $olderThanUnit);
         //for all files in temp upload folder
         foreach ($tmpFiles as $idx => $file) {
             //if creation timestamp is lower than threshold timestamp
             //delete the file
             $creationTime = filemtime($path . $file);
             //fix for different timezones
             $creationTime += date('O') / 100 * 60;
             if ($creationTime < $threshold) {
                 unlink($path . $file);
                 $this->utilityFuncs->debugMessage('deleting_file', array($file));
             }
         }
     }
 }
示例#3
0
 /**
  * Call this function at the end of your ext_tables.php to autoregister the flexforms
  * of the extension to the given plugins.
  *
  * @return void
  */
 public static function flexFormAutoLoader()
 {
     global $TCA, $_EXTKEY;
     $_extConfig = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['nn_address']);
     $FlexFormPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'Configuration/FlexForms/';
     $extensionName = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($_EXTKEY);
     $FlexForms = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($FlexFormPath, 'xml');
     foreach ($FlexForms as $FlexForm) {
         if (preg_match("/^Model_(.*)\$/", $FlexForm)) {
             continue;
         }
         $fileKey = str_replace('.xml', '', $FlexForm);
         $pluginSignature = strtolower($extensionName . '_' . $fileKey);
         #$TCA['tt_content']['types']['list']['subtypes_excludelist'][$pluginSignature] = 'layout,select_key,recursive';
         $TCA['tt_content']['types']['list']['subtypes_excludelist'][$pluginSignature] = 'select_key,recursive';
         $TCA['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';
         $fileFlexForm = 'FILE:EXT:' . $_EXTKEY . '/Configuration/FlexForms/' . $fileKey . '.xml';
         // Any flexform dir in extension config set?
         if ($_extConfig['flexFormPlugin'] != '') {
             if (is_dir(\TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($_extConfig['flexFormPlugin']))) {
                 // modify the relative path
                 $path = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($_extConfig['flexFormPlugin']);
                 $path = preg_match('/^(.*)\\/$/', $path) ? $path : $path . '/';
                 $fileFlexForm = 'FILE:' . $path . $fileKey . '.xml';
             }
         }
         \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($pluginSignature, $fileFlexForm);
     }
 }
 /**
  * Loads all stylesheet files registered through
  * \TYPO3\CMS\Backend\Sprite\SpriteManager::addIconSprite
  *
  * In fact the stylesheet-files are copied to \TYPO3\CMS\Backend\Sprite\SpriteManager::tempPath
  * where they automatically will be included from via
  * \TYPO3\CMS\Backend\Template\DocumentTemplate and
  * \TYPO3\CMS\Core\Resource\ResourceCompressor
  *
  * @return void
  */
 protected function loadRegisteredSprites()
 {
     // Saves which CSS Files are currently "allowed to be in place"
     $allowedCssFilesinTempDir = array(basename($this->cssTcaFile));
     // Process every registeres file
     foreach ((array) $GLOBALS['TBE_STYLES']['spritemanager']['cssFiles'] as $file) {
         $fileName = basename($file);
         // File should be present
         $allowedCssFilesinTempDir[] = $fileName;
         // get-Cache Filename
         $fileStatus = stat(PATH_site . $file);
         $unique = md5($fileName . $fileStatus['mtime'] . $fileStatus['size']);
         $cacheFile = PATH_site . SpriteManager::$tempPath . $fileName . $unique . '.css';
         if (!file_exists($cacheFile)) {
             copy(PATH_site . $file, $cacheFile);
         }
     }
     // Get all .css files in dir
     $cssFilesPresentInTempDir = GeneralUtility::getFilesInDir(PATH_site . SpriteManager::$tempPath, '.css', 0);
     // and delete old ones which are not needed anymore
     $filesToDelete = array_diff($cssFilesPresentInTempDir, $allowedCssFilesinTempDir);
     foreach ($filesToDelete as $file) {
         unlink(PATH_site . SpriteManager::$tempPath . $file);
     }
 }
示例#5
0
 /**
  * Retrieves backend layout files
  *
  * @return array Available backend layout files
  */
 protected function getBackendLayoutFiles()
 {
     $directory = GeneralUtility::getFileAbsFileName('EXT:bdp_template/Resources/Private/BackendLayouts');
     $filesInDirectory = GeneralUtility::getFilesInDir($directory, 'ts', TRUE);
     if (!is_array($filesInDirectory)) {
         $filesInDirectory = array();
     }
     return $filesInDirectory;
 }
示例#6
0
 /**
  * Get all files
  *
  * @return array
  * @throws \UnexpectedValueException
  */
 protected function getLayoutFiles()
 {
     $fileCollection = array();
     $path = ExtensionManagementUtility::extPath('theme') . self::LAYOUT_PATH;
     $filesOfDirectory = GeneralUtility::getFilesInDir($path, self::FILE_TYPES_LAYOUT, TRUE, 1);
     foreach ($filesOfDirectory as $file) {
         $this->addFileToCollection($file, $fileCollection);
     }
     return $fileCollection;
 }
示例#7
0
 /**
  * Get file information in the given folder
  *
  * @param string $dirPath
  * @param string $fileExtension
  * @param int $informationType
  *
  * @return array
  */
 protected static function getFileInformationInDir($dirPath, $fileExtension, $informationType)
 {
     if (!is_dir($dirPath)) {
         return [];
     }
     $files = GeneralUtility::getFilesInDir($dirPath, $fileExtension);
     foreach ($files as $key => $file) {
         $files[$key] = PathUtility::pathinfo($file, $informationType);
     }
     return array_values($files);
 }
 /**
  * GetLayoutFiles
  *
  * @return LayoutFileInfo[] Empty array if an error occurred
  */
 private function getLayoutFiles()
 {
     $absolutePath = ExtensionManagementUtility::extPath(self::EXTENSION_KEY, self::LAYOUT_PATH);
     $files = GeneralUtility::getFilesInDir($absolutePath, LayoutFileInfo::EXTENSION, true);
     if (!is_array($files)) {
         return [];
     }
     array_walk($files, function (&$file) {
         $absoluteFilePath = $file;
         $file = new LayoutFileInfo($absoluteFilePath);
     });
     return $files;
 }
    /**
     * Main Task center module
     *
     * @return string HTML content.
     * @todo Define visibility
     */
    public function main()
    {
        if ($id = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('display')) {
            return $this->urlInIframe($this->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('impexp') . 'app/index.php?tx_impexp[action]=export&preset[load]=1&preset[select]=' . $id, 1);
        } else {
            // Thumbnail folder and files:
            $tempDir = $this->userTempFolder();
            if ($tempDir) {
                $thumbnails = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($tempDir, 'png,gif,jpg', 1);
            }
            $clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
            $usernames = \TYPO3\CMS\Backend\Utility\BackendUtility::getUserNames();
            // Create preset links:
            $presets = $this->getPresets();
            $opt = array();
            $opt[] = '
			<tr class="bgColor5 tableheader">
				<td>Icon:</td>
				<td>Preset Title:</td>
				<td>Public</td>
				<td>Owner:</td>
				<td>Page:</td>
				<td>Path:</td>
				<td>Meta data:</td>
			</tr>';
            if (is_array($presets)) {
                foreach ($presets as $presetCfg) {
                    $configuration = unserialize($presetCfg['preset_data']);
                    $thumbnailFile = $thumbnails[$configuration['meta']['thumbnail']];
                    $title = strlen($presetCfg['title']) ? $presetCfg['title'] : '[' . $presetCfg['uid'] . ']';
                    $opt[] = '
					<tr class="bgColor4">
						<td>' . ($thumbnailFile ? '<img src="' . $this->backPath . '../' . substr($tempDir, strlen(PATH_site)) . basename($thumbnailFile) . '" hspace="2" width="70" style="border: solid black 1px;" alt="" /><br />' : '&nbsp;') . '</td>
						<td nowrap="nowrap"><a href="index.php?SET[function]=tx_impexp&display=' . $presetCfg['uid'] . '">' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($title, 30)) . '</a>&nbsp;</td>
						<td>' . ($presetCfg['public'] ? 'Yes' : '&nbsp;') . '</td>
						<td>' . ($presetCfg['user_uid'] === $GLOBALS['BE_USER']->user['uid'] ? 'Own' : '[' . $usernames[$presetCfg['user_uid']]['username'] . ']') . '</td>
						<td>' . ($configuration['pagetree']['id'] ? $configuration['pagetree']['id'] : '&nbsp;') . '</td>
						<td>' . htmlspecialchars($configuration['pagetree']['id'] ? \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordPath($configuration['pagetree']['id'], $clause, 20) : '[Single Records]') . '</td>
						<td>
							<strong>' . htmlspecialchars($configuration['meta']['title']) . '</strong><br />' . htmlspecialchars($configuration['meta']['description']) . ($configuration['meta']['notes'] ? '<br /><br /><strong>Notes:</strong> <em>' . htmlspecialchars($configuration['meta']['notes']) . '</em>' : '') . '
						</td>
					</tr>';
                }
                $content = '<table border="0" cellpadding="0" cellspacing="1" class="lrPadding">' . implode('', $opt) . '</table>';
            }
        }
        // Output:
        $theOutput .= $this->pObj->doc->spacer(5);
        $theOutput .= $this->pObj->doc->section('Export presets', $content, 0, 1);
        return $theOutput;
    }
示例#10
0
 /**
  * Disconnects from Doodle by removing all stored cookies whenever
  * TYPO3 administrator flushes all "general" caches.
  *
  * @param array $parameters
  * @param \TYPO3\CMS\Core\DataHandling\DataHandler $pObj
  * @return void
  */
 public function clearCacheCmd(array $parameters, \TYPO3\CMS\Core\DataHandling\DataHandler $pObj)
 {
     if ($parameters['cacheCmd'] !== 'all') {
         return;
     }
     $cookiePath = PATH_site . 'typo3temp/tx_doodle/';
     if (is_dir($cookiePath)) {
         $cookies = GeneralUtility::getFilesInDir($cookiePath);
         foreach ($cookies as $cookie) {
             if (preg_match('/^[0-9a-f]{40}$/', $cookie)) {
                 @unlink($cookiePath . $cookie);
             }
         }
     }
 }
示例#11
0
 /**
  * @return array
  */
 public function render()
 {
     $path = $this->arguments['path'];
     if (NULL === $path) {
         $path = $this->renderChildren();
         if (NULL === $path) {
             return array();
         }
     }
     $extensionList = $this->arguments['extensionList'];
     $prependPath = $this->arguments['prependPath'];
     $order = $this->arguments['order'];
     $excludePattern = $this->arguments['excludePattern'];
     $files = GeneralUtility::getFilesInDir($path, $extensionList, $prependPath, $order, $excludePattern);
     return $files;
 }
示例#12
0
 /**
  * Manipulating the input array, $params, adding new selectorbox items.
  *
  * @param	array	$params array of select field options (reference)
  * @param	object	$pObj parent object (reference)
  * @return	void
  */
 function main(&$params, &$pObj)
 {
     // get the current page ID
     $thePageId = $params['row']['pid'];
     /** @var TemplateService $template */
     $template = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\TemplateService');
     // do not log time-performance information
     $template->tt_track = 0;
     $template->init();
     /** @var PageRepository $sys_page */
     $sys_page = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
     $rootLine = $sys_page->getRootLine($thePageId);
     // generate the constants/config + hierarchy info for the template.
     $template->runThroughTemplates($rootLine);
     $template->generateConfig();
     // get value for the path containing the template files
     $readPath = GeneralUtility::getFileAbsFileName($template->setup['plugin.']['tx_ttaddress_pi1.']['templatePath']);
     // if that direcotry is valid and is a directory then select files in it
     if (@is_dir($readPath)) {
         $template_files = GeneralUtility::getFilesInDir($readPath, 'tmpl,html,htm', 1, 1);
         /** @var HtmlParser $parseHTML */
         $parseHTML = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Html\\HtmlParser');
         foreach ($template_files as $htmlFilePath) {
             // reset vars
             $selectorBoxItem_title = '';
             $selectorBoxItem_icon = '';
             // read template content
             $content = GeneralUtility::getUrl($htmlFilePath);
             // ... and extract content of the title-tags
             $parts = $parseHTML->splitIntoBlock('title', $content);
             $titleTagContent = $parseHTML->removeFirstAndLastTag($parts[1]);
             // set the item label
             $selectorBoxItem_title = trim($titleTagContent . ' (' . basename($htmlFilePath) . ')');
             // try to look up an image icon for the template
             $fI = GeneralUtility::split_fileref($htmlFilePath);
             $testImageFilename = $readPath . $fI['filebody'] . '.gif';
             if (@is_file($testImageFilename)) {
                 $selectorBoxItem_icon = '../' . substr($testImageFilename, strlen(PATH_site));
             }
             // finally add the new item
             $params['items'][] = array($selectorBoxItem_title, basename($htmlFilePath), $selectorBoxItem_icon);
         }
     }
 }
示例#13
0
 /**
  * Resolves a list (array) of class names (not instances) of
  * all classes in files in the specified sub-namespace of the
  * specified package name. Does not attempt to load the class.
  * Does not work recursively.
  *
  * @param string $packageName
  * @param string $subNamespace
  * @param string|NULL $requiredSuffix If specified, class name must use this suffix
  * @return array
  */
 public function resolveClassNamesInPackageSubNamespace($packageName, $subNamespace, $requiredSuffix = NULL)
 {
     $classNames = array();
     $extensionKey = ExtensionNamingUtility::getExtensionKey($packageName);
     $prefix = str_replace('.', '\\', $packageName);
     $suffix = TRUE === empty($subNamespace) ? '' : str_replace('/', '\\', $subNamespace) . '\\';
     $folder = ExtensionManagementUtility::extPath($extensionKey, 'Classes/' . $subNamespace);
     $files = GeneralUtility::getFilesInDir($folder, 'php');
     if (TRUE === is_array($files)) {
         foreach ($files as $file) {
             $filename = pathinfo($file, PATHINFO_FILENAME);
             // include if no required suffix is given or string ends with suffix
             if (NULL === $requiredSuffix || 1 === preg_match('/' . $requiredSuffix . '$/', $filename)) {
                 $classNames[] = $prefix . '\\' . $suffix . $filename;
             }
         }
     }
     return $classNames;
 }
示例#14
0
 /**
  * Add all *.css files of the directory $path to the stylesheets
  *
  * @param string $path directory to add
  * @return void
  */
 public function addStyleSheetDirectory($path)
 {
     // Calculation needed, when TYPO3 source is used via a symlink
     // absolute path to the stylesheets
     $filePath = GeneralUtility::getFileAbsFileName($path, false, true);
     // Clean the path
     $resolvedPath = GeneralUtility::resolveBackPath($filePath);
     // Read all files in directory and sort them alphabetically
     $files = GeneralUtility::getFilesInDir($resolvedPath, 'css', false, 1);
     foreach ($files as $file) {
         $this->pageRenderer->addCssFile($path . $file, 'stylesheet', 'all');
     }
 }
示例#15
0
 /**
  * Data for the typo3temp/ deletion view
  *
  * @return array Data array
  */
 protected function getTypo3TempStatistics()
 {
     $data = [];
     $pathTypo3Temp = PATH_site . 'typo3temp/';
     $postValues = $this->postValues['values'];
     $condition = '0';
     if (isset($postValues['condition'])) {
         $condition = $postValues['condition'];
     }
     $numberOfFilesToDelete = 0;
     if (isset($postValues['numberOfFiles'])) {
         $numberOfFilesToDelete = $postValues['numberOfFiles'];
     }
     $subDirectory = '';
     if (isset($postValues['subDirectory'])) {
         $subDirectory = $postValues['subDirectory'];
     }
     // Run through files
     $fileCounter = 0;
     $deleteCounter = 0;
     $criteriaMatch = 0;
     $timeMap = ['day' => 1, 'week' => 7, 'month' => 30];
     $directory = @dir($pathTypo3Temp . $subDirectory);
     if (is_object($directory)) {
         while ($entry = $directory->read()) {
             $absoluteFile = $pathTypo3Temp . $subDirectory . '/' . $entry;
             if (@is_file($absoluteFile)) {
                 $ok = false;
                 $fileCounter++;
                 if ($condition) {
                     if (MathUtility::canBeInterpretedAsInteger($condition)) {
                         if (filesize($absoluteFile) > $condition * 1024) {
                             $ok = true;
                         }
                     } else {
                         if (fileatime($absoluteFile) < $GLOBALS['EXEC_TIME'] - (int) $timeMap[$condition] * 60 * 60 * 24) {
                             $ok = true;
                         }
                     }
                 } else {
                     $ok = true;
                 }
                 if ($ok) {
                     $hashPart = substr(basename($absoluteFile), -14, 10);
                     // This is a kind of check that the file being deleted has a 10 char hash in it
                     if (!preg_match('/[^a-f0-9]/', $hashPart) || substr($absoluteFile, -6) === '.cache' || substr($absoluteFile, -4) === '.tbl' || substr($absoluteFile, -4) === '.css' || substr($absoluteFile, -3) === '.js' || substr($absoluteFile, -5) === '.gzip' || substr(basename($absoluteFile), 0, 8) === 'installTool') {
                         if ($numberOfFilesToDelete && $deleteCounter < $numberOfFilesToDelete) {
                             $deleteCounter++;
                             unlink($absoluteFile);
                         } else {
                             $criteriaMatch++;
                         }
                     }
                 }
             }
         }
         $directory->close();
     }
     $data['numberOfFilesMatchingCriteria'] = $criteriaMatch;
     $data['numberOfDeletedFiles'] = $deleteCounter;
     if ($deleteCounter > 0) {
         $message = GeneralUtility::makeInstance(OkStatus::class);
         $message->setTitle('Deleted ' . $deleteCounter . ' files from typo3temp/' . $subDirectory . '/');
         $this->actionMessages[] = $message;
     }
     $data['selectedCondition'] = $condition;
     $data['numberOfFiles'] = $numberOfFilesToDelete;
     $data['selectedSubDirectory'] = $subDirectory;
     // Set up sub directory data
     $data['subDirectories'] = ['' => ['name' => '', 'filesNumber' => count(GeneralUtility::getFilesInDir($pathTypo3Temp))]];
     $directories = dir($pathTypo3Temp);
     if (is_object($directories)) {
         while ($entry = $directories->read()) {
             if (is_dir($pathTypo3Temp . $entry) && $entry != '..' && $entry != '.') {
                 $data['subDirectories'][$entry]['name'] = $entry;
                 $data['subDirectories'][$entry]['filesNumber'] = count(GeneralUtility::getFilesInDir($pathTypo3Temp . $entry));
                 $data['subDirectories'][$entry]['selected'] = false;
                 if ($entry === $data['selectedSubDirectory']) {
                     $data['subDirectories'][$entry]['selected'] = true;
                 }
             }
         }
     }
     $data['numberOfFilesInSelectedDirectory'] = $data['subDirectories'][$data['selectedSubDirectory']]['filesNumber'];
     return $data;
 }
 /**
  * Searching for filename pattern recursively in the specified dir.
  *
  * @param string $basedir Base directory
  * @param string $pattern Match pattern
  * @param array $matching_files Array of matching files, passed by reference
  * @param integer $depth Depth to recurse
  * @return array Array with various information about the search result
  * @see func_filesearch()
  * @todo Define visibility
  */
 public function findFile($basedir, $pattern, &$matching_files, $depth)
 {
     $files_searched = 0;
     $dirs_searched = 0;
     $dirs_error = 0;
     // Traverse files:
     $files = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($basedir, '', 1);
     if (is_array($files)) {
         $files_searched += count($files);
         // Escape the regexp. Note: we cannot use preg_quote here because it will escape more than we need!
         $regExpPattern = str_replace('/', '\\/', $pattern);
         foreach ($files as $value) {
             if (preg_match('/' . $regExpPattern . '/i', basename($value))) {
                 $matching_files[] = substr($value, strlen(PATH_site));
             }
         }
     }
     // Traverse subdirs
     if ($depth > 0) {
         $dirs = \TYPO3\CMS\Core\Utility\GeneralUtility::get_dirs($basedir);
         if (is_array($dirs)) {
             $dirs_searched += count($dirs);
             foreach ($dirs as $value) {
                 $inf = $this->findFile($basedir . $value . '/', $pattern, $matching_files, $depth - 1);
                 $dirs_searched += $inf[0];
                 $files_searched += $inf[1];
                 $dirs_error = $inf[2];
             }
         }
     } else {
         $dirs = \TYPO3\CMS\Core\Utility\GeneralUtility::get_dirs($basedir);
         if (is_array($dirs) && count($dirs)) {
             // Means error - there were further subdirs!
             $dirs_error = 1;
         }
     }
     return array($dirs_searched, $files_searched, $dirs_error);
 }
示例#17
0
 /**
  * Add all *.css files of the directory $path to the stylesheets
  *
  * @param string $path directory to add
  * @return void
  */
 public function addStyleSheetDirectory($path)
 {
     // Calculation needed, when TYPO3 source is used via a symlink
     // absolute path to the stylesheets
     $filePath = dirname(GeneralUtility::getIndpEnv('SCRIPT_FILENAME')) . '/' . $GLOBALS['BACK_PATH'] . $path;
     // Clean the path
     $resolvedPath = GeneralUtility::resolveBackPath($filePath);
     // Read all files in directory and sort them alphabetically
     $files = GeneralUtility::getFilesInDir($resolvedPath, 'css', false, 1);
     foreach ($files as $file) {
         $this->pageRenderer->addCssFile($GLOBALS['BACK_PATH'] . $path . $file, 'stylesheet', 'all');
     }
 }
示例#18
0
 /**
  * Loads the css and javascript files of all registered navigation widgets
  *
  * @return void
  */
 protected function loadResourcesForRegisteredNavigationComponents()
 {
     if (!is_array($GLOBALS['TBE_MODULES']['_navigationComponents'])) {
         return;
     }
     $loadedComponents = array();
     foreach ($GLOBALS['TBE_MODULES']['_navigationComponents'] as $module => $info) {
         if (in_array($info['componentId'], $loadedComponents)) {
             continue;
         }
         $loadedComponents[] = $info['componentId'];
         $component = strtolower(substr($info['componentId'], strrpos($info['componentId'], '-') + 1));
         $componentDirectory = 'components/' . $component . '/';
         if ($info['isCoreComponent']) {
             $absoluteComponentPath = PATH_t3lib . 'js/extjs/' . $componentDirectory;
             $relativeComponentPath = '../' . str_replace(PATH_site, '', $absoluteComponentPath);
         } else {
             $absoluteComponentPath = \TYPO3\CMS\Core\Extension\ExtensionManager::extPath($info['extKey']) . $componentDirectory;
             $relativeComponentPath = \TYPO3\CMS\Core\Extension\ExtensionManager::extRelPath($info['extKey']) . $componentDirectory;
         }
         $cssFiles = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($absoluteComponentPath . 'css/', 'css');
         if (file_exists($absoluteComponentPath . 'css/loadorder.txt')) {
             // Don't allow inclusion outside directory
             $loadOrder = str_replace('../', '', \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($absoluteComponentPath . 'css/loadorder.txt'));
             $cssFilesOrdered = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(LF, $loadOrder, TRUE);
             $cssFiles = array_merge($cssFilesOrdered, $cssFiles);
         }
         foreach ($cssFiles as $cssFile) {
             $this->pageRenderer->addCssFile($relativeComponentPath . 'css/' . $cssFile);
         }
         $jsFiles = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($absoluteComponentPath . 'javascript/', 'js');
         if (file_exists($absoluteComponentPath . 'javascript/loadorder.txt')) {
             // Don't allow inclusion outside directory
             $loadOrder = str_replace('../', '', \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($absoluteComponentPath . 'javascript/loadorder.txt'));
             $jsFilesOrdered = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(LF, $loadOrder, TRUE);
             $jsFiles = array_merge($jsFilesOrdered, $jsFiles);
         }
         foreach ($jsFiles as $jsFile) {
             $this->pageRenderer->addJsFile($relativeComponentPath . 'javascript/' . $jsFile);
         }
     }
 }
 /**
  * Remove all export files in typo3temp/tx_powermail/
  *
  *        This task will clean up all (!) files which
  *        are located in typo3temp/tx_powermail/
  *        e.g.: old captcha images and old export files
  *        (from export task - if stored in typo3temp folder)
  *
  * @return void
  */
 public function cleanExportFilesCommand()
 {
     $files = GeneralUtility::getFilesInDir(GeneralUtility::getFileAbsFileName('typo3temp/tx_powermail/'), '', true);
     foreach ($files as $file) {
         unlink($file);
     }
 }
示例#20
0
    /**
     * The Database Analyzer
     *
     * @return void
     * @todo Define visibility
     */
    public function checkTheDatabase()
    {
        if (!$this->config_array['mysqlConnect']) {
            $this->message('Database Analyser', 'Your database connection failed', '
				<p>
					Please go to the \'Basic Configuration\' section and correct
					this problem first.
				</p>
			', 2);
            $this->output($this->outputWrapper($this->printAll()));
            return;
        }
        if ($this->config_array['no_database']) {
            $this->message('Database Analyser', 'No database selected', '
				<p>
					Please go to the \'Basic Configuration\' section and correct
					this problem first.
				</p>
			', 2);
            $this->output($this->outputWrapper($this->printAll()));
            return;
        }
        // Getting current tables
        $whichTables = $this->sqlHandler->getListOfTables();
        // Getting number of static_template records
        if ($whichTables['static_template']) {
            $static_template_count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid', 'static_template');
        }
        $static_template_count = intval($static_template_count);
        $headCode = 'Database Analyser';
        $this->message($headCode, 'What is it?', '
			<p>
				In this section you can get an overview of your currently
				selected database compared to sql-files. You can also import
				sql-data directly into the database or upgrade tables from
				earlier versions of TYPO3.
			</p>
		', 0);
        $this->message($headCode, 'Connected to SQL database successfully', '
			<dl id="t3-install-databaseconnected">
				<dt>
					Username:
				</dt>
				<dd>
					' . htmlspecialchars(TYPO3_db_username) . '
				</dd>
				<dt>
					Host:
				</dt>
				<dd>
					' . htmlspecialchars(TYPO3_db_host) . '
				</dd>
			</dl>
		', -1, 1);
        $this->message($headCode, 'Database', '
			<p>
				<strong>' . htmlspecialchars(TYPO3_db) . '</strong> is selected as database.
				<br />
				Has <strong>' . count($whichTables) . '</strong> tables.
			</p>
		', -1, 1);
        // Menu
        $sql_files = array_merge(\TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir(PATH_typo3conf, 'sql', 1, 1), array());
        $action_type = $this->INSTALL['database_type'];
        $actionParts = explode('|', $action_type);
        if (count($actionParts) < 2) {
            $action_type = '';
        }
        // Get the template file
        $templateFile = @file_get_contents(PATH_site . $this->templateFilePath . 'CheckTheDatabaseMenu.html');
        // Get the template part from the file
        $menu = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($templateFile, '###MENU###');
        $menuMarkers = array('action' => $this->action, 'updateRequiredTables' => 'Update required tables', 'compare' => 'COMPARE', 'noticeCmpFileCurrent' => $action_type == 'cmpFile|CURRENT_TABLES' ? ' class="notice"' : '', 'dumpStaticData' => 'Dump static data', 'import' => 'IMPORT', 'noticeImportCurrent' => $action_type == 'import|CURRENT_STATIC' ? ' class="notice"' : '', 'noticeCmpTca' => $action_type == 'cmpTCA|' ? ' class="notice"' : '', 'compareWithTca' => 'Compare with $TCA', 'noticeAdminUser' => $action_type == 'adminUser|' ? ' class="notice"' : '', 'createAdminUser' => 'Create "admin" user', 'noticeUc' => $action_type == 'UC|' ? ' class="notice"' : '', 'resetUserPreferences' => 'Reset user preferences', 'noticeCache' => $action_type == 'cache|' ? ' class="notice"' : '', 'clearTables' => 'Clear tables');
        // Get the subpart for extra SQL
        $extraSql = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($menu, '###EXTRASQL###');
        $directJump = '';
        $extraSqlFiles = array();
        foreach ($sql_files as $k => $file) {
            if ($this->mode == '123' && !count($whichTables) && strstr($file, '_testsite')) {
                $directJump = $this->action . '&TYPO3_INSTALL[database_type]=import|' . rawurlencode($file);
            }
            $lf = \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($k);
            $fShortName = substr($file, strlen(PATH_site));
            $spec1 = $spec2 = '';
            // Define the markers content
            $extraSqlMarkers = array('fileShortName' => $fShortName, 'fileSize' => \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize(filesize($file)), 'noticeCmpFile' => $action_type == 'cmpFile|' . $file ? ' class="notice"' : '', 'file' => rawurlencode($file), 'noticeImport' => $action_type == 'import|' . $file ? ' class="notice"' : '', 'specs' => $spec1 . $spec2, 'noticeView' => $action_type == 'view|' . $file ? ' class="notice"' : '', 'view' => 'VIEW');
            // Fill the markers in the subpart
            $extraSqlFiles[] = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($extraSql, $extraSqlMarkers, '###|###', TRUE, FALSE);
        }
        // Substitute the subpart for extra SQL
        $menu = \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpart($menu, '###EXTRASQL###', implode(LF, $extraSqlFiles));
        // Fill the markers
        $menu = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($menu, $menuMarkers, '###|###', TRUE, FALSE);
        if ($directJump) {
            if (!$action_type) {
                $this->message($headCode, 'Menu', '
					<script language="javascript" type="text/javascript">
						window.location.href = "' . $directJump . '";
					</script>', 0, 1);
            }
        } else {
            $this->message($headCode, 'Menu', '
				<p>
					From this menu you can select which of the available SQL
					files you want to either compare or import/merge with the
					existing database.
				</p>
				<dl id="t3-install-checkthedatabaseexplanation">
					<dt>
						COMPARE:
					</dt>
					<dd>
						Compares the tables and fields of the current database
						and the selected file. It also offers to \'update\' the
						difference found.
					</dd>
					<dt>
						IMPORT:
					</dt>
					<dd>
						Imports the SQL-dump file into the current database. You
						can either dump the raw file or choose which tables to
						import. In any case, you\'ll see a new screen where you
						must confirm the operation.
					</dd>
					<dt>
						VIEW:
					</dt>
					<dd>
						Shows the content of the SQL-file, limiting characters
						on a single line to a reader-friendly amount.
					</dd>
				</dl>
				<p>
					The SQL-files are selected from typo3conf/ (here you can put
					your own) and t3lib/stddb/ (TYPO3 distribution). The
					SQL-files should be made by the <em>mysqldump</em> tool or
					at least be formatted like that tool would do.
				</p>
			' . $menu, 0, 1);
        }
        if ($action_type) {
            switch ($actionParts[0]) {
                case 'cmpFile':
                    $tblFileContent = '';
                    $hookObjects = array();
                    // Load TCA first
                    $this->includeTCA();
                    if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['checkTheDatabase'])) {
                        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['checkTheDatabase'] as $classData) {
                            /** @var $hookObject Tx_Install_Interfaces_CheckTheDatabaseHook * */
                            $hookObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classData);
                            if (!$hookObject instanceof \TYPO3\CMS\Install\CheckTheDatabaseHookInterface) {
                                throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Install\\CheckTheDatabaseHookInterface', 1315554770);
                            }
                            $hookObjects[] = $hookObject;
                        }
                    }
                    if (!strcmp($actionParts[1], 'CURRENT_TABLES')) {
                        $tblFileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl(PATH_t3lib . 'stddb/tables.sql');
                        foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $extKey => $loadedExtConf) {
                            if (is_array($loadedExtConf) && $loadedExtConf['ext_tables.sql']) {
                                $extensionSqlContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($loadedExtConf['ext_tables.sql']);
                                $tblFileContent .= LF . LF . LF . LF . $extensionSqlContent;
                                foreach ($hookObjects as $hookObject) {
                                    /** @var $hookObject Tx_Install_Interfaces_CheckTheDatabaseHook * */
                                    $appendableTableDefinitions = $hookObject->appendExtensionTableDefinitions($extKey, $loadedExtConf, $extensionSqlContent, $this->sqlHandler, $this);
                                    if ($appendableTableDefinitions) {
                                        $tblFileContent .= $appendableTableDefinitions;
                                        break;
                                    }
                                }
                            }
                        }
                    } elseif (@is_file($actionParts[1])) {
                        $tblFileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($actionParts[1]);
                    }
                    foreach ($hookObjects as $hookObject) {
                        /** @var $hookObject Tx_Install_Interfaces_CheckTheDatabaseHook * */
                        $appendableTableDefinitions = $hookObject->appendGlobalTableDefinitions($tblFileContent, $this->sqlHandler, $this);
                        if ($appendableTableDefinitions) {
                            $tblFileContent .= $appendableTableDefinitions;
                            break;
                        }
                    }
                    // Add SQL content coming from the caching framework
                    $tblFileContent .= \TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions();
                    // Add SQL content coming from the category registry
                    $tblFileContent .= \TYPO3\CMS\Core\Category\CategoryRegistry::getInstance()->getDatabaseTableDefinitions();
                    if ($tblFileContent) {
                        $fileContent = implode(LF, $this->sqlHandler->getStatementArray($tblFileContent, 1, '^CREATE TABLE '));
                        $FDfile = $this->sqlHandler->getFieldDefinitions_fileContent($fileContent);
                        if (!count($FDfile)) {
                            die('Error: There were no \'CREATE TABLE\' definitions in the provided file');
                        }
                        // Updating database...
                        if (is_array($this->INSTALL['database_update'])) {
                            $FDdb = $this->sqlHandler->getFieldDefinitions_database();
                            $diff = $this->sqlHandler->getDatabaseExtra($FDfile, $FDdb);
                            $update_statements = $this->sqlHandler->getUpdateSuggestions($diff);
                            $diff = $this->sqlHandler->getDatabaseExtra($FDdb, $FDfile);
                            $remove_statements = $this->sqlHandler->getUpdateSuggestions($diff, 'remove');
                            $results = array();
                            $results[] = $this->sqlHandler->performUpdateQueries($update_statements['clear_table'], $this->INSTALL['database_update']);
                            $results[] = $this->sqlHandler->performUpdateQueries($update_statements['add'], $this->INSTALL['database_update']);
                            $results[] = $this->sqlHandler->performUpdateQueries($update_statements['change'], $this->INSTALL['database_update']);
                            $results[] = $this->sqlHandler->performUpdateQueries($remove_statements['change'], $this->INSTALL['database_update']);
                            $results[] = $this->sqlHandler->performUpdateQueries($remove_statements['drop'], $this->INSTALL['database_update']);
                            $results[] = $this->sqlHandler->performUpdateQueries($update_statements['create_table'], $this->INSTALL['database_update']);
                            $results[] = $this->sqlHandler->performUpdateQueries($remove_statements['change_table'], $this->INSTALL['database_update']);
                            $results[] = $this->sqlHandler->performUpdateQueries($remove_statements['drop_table'], $this->INSTALL['database_update']);
                            $this->databaseUpdateErrorMessages = array();
                            foreach ($results as $resultSet) {
                                if (is_array($resultSet)) {
                                    foreach ($resultSet as $key => $errorMessage) {
                                        $this->databaseUpdateErrorMessages[$key] = $errorMessage;
                                    }
                                }
                            }
                        }
                        // Init again / first time depending...
                        $FDdb = $this->sqlHandler->getFieldDefinitions_database();
                        $diff = $this->sqlHandler->getDatabaseExtra($FDfile, $FDdb);
                        $update_statements = $this->sqlHandler->getUpdateSuggestions($diff);
                        $diff = $this->sqlHandler->getDatabaseExtra($FDdb, $FDfile);
                        $remove_statements = $this->sqlHandler->getUpdateSuggestions($diff, 'remove');
                        $tLabel = 'Update database tables and fields';
                        if ($remove_statements || $update_statements) {
                            $formContent = $this->generateUpdateDatabaseForm('get_form', $update_statements, $remove_statements, $action_type);
                            $this->message($tLabel, 'Table and field definitions should be updated', '
								<p>
									There seems to be a number of differences
									between the database and the selected
									SQL-file.
									<br />
									Please select which statements you want to
									execute in order to update your database:
								</p>
							' . $formContent, 2);
                        } else {
                            $formContent = $this->generateUpdateDatabaseForm('get_form', $update_statements, $remove_statements, $action_type);
                            $this->message($tLabel, 'Table and field definitions are OK.', '
								<p>
									The tables and fields in the current
									database corresponds perfectly to the
									database in the selected SQL-file.
								</p>
							', -1);
                        }
                    }
                    break;
                case 'cmpTCA':
                    $this->includeTCA();
                    $FDdb = $this->sqlHandler->getFieldDefinitions_database();
                    // Displaying configured fields which are not in the database
                    $tLabel = 'Tables and fields in $TCA, but not in database';
                    $cmpTCA_DB = $this->compareTCAandDatabase($GLOBALS['TCA'], $FDdb);
                    if (!count($cmpTCA_DB['extra'])) {
                        $this->message($tLabel, 'Table and field definitions OK', '
							<p>
								All fields and tables configured in $TCA
								appeared to exist in the database as well
							</p>
						', -1);
                    } else {
                        $this->message($tLabel, 'Invalid table and field definitions in $TCA!', '
							<p>
								There are some tables and/or fields configured
								in the $TCA array which do not exist in the
								database!
								<br />
								This will most likely cause you trouble with the
								TYPO3 backend interface!
							</p>
						', 3);
                        foreach ($cmpTCA_DB['extra'] as $tableName => $conf) {
                            $this->message($tLabel, $tableName, $this->displayFields($conf['fields'], 0, 'Suggested database field:'), 2);
                        }
                    }
                    // Displaying tables that are not setup in
                    $cmpDB_TCA = $this->compareDatabaseAndTCA($FDdb, $GLOBALS['TCA']);
                    $excludeTables = 'be_sessions,fe_session_data,fe_sessions';
                    if (TYPO3_OS == 'WIN') {
                        $excludeTables = strtolower($excludeTables);
                    }
                    $excludeFields = array('be_users' => 'uc,lastlogin,usergroup_cached_list', 'fe_users' => 'uc,lastlogin,fe_cruser_id', 'pages' => 'SYS_LASTCHANGED', 'sys_dmail' => 'mailContent', 'tt_board' => 'doublePostCheck', 'tt_guest' => 'doublePostCheck', 'tt_products' => 'ordered');
                    $tCount = 0;
                    $fCount = 0;
                    $tLabel = 'Tables from database, but not in \\$TCA';
                    $fLabel = 'Fields from database, but not in \\$TCA';
                    $this->message($tLabel);
                    if (is_array($cmpDB_TCA['extra'])) {
                        foreach ($cmpDB_TCA['extra'] as $tableName => $conf) {
                            if (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList($excludeTables, $tableName) && substr($tableName, 0, 4) != 'sys_' && substr($tableName, -3) != '_mm' && substr($tableName, 0, 6) != 'index_' && substr($tableName, 0, 6) != 'cache_') {
                                if ($conf['whole_table']) {
                                    $this->message($tLabel, $tableName, $this->displayFields($conf['fields']), 1);
                                    $tCount++;
                                } else {
                                    list($theContent, $fC) = $this->displaySuggestions($conf['fields'], $excludeFields[$tableName]);
                                    $fCount += $fC;
                                    if ($fC) {
                                        $this->message($fLabel, $tableName, $theContent, 1);
                                    }
                                }
                            }
                        }
                    }
                    if (!$tCount) {
                        $this->message($tLabel, 'Correct number of tables in the database', '
							<p>
								There are no extra tables in the database
								compared to the configured tables in the $TCA
								array.
							</p>
						', -1);
                    } else {
                        $this->message($tLabel, 'Extra tables in the database', '
							<p>
								There are some tables in the database which are
								not configured in the $TCA array.
								<br />
								You should probably not worry about this, but
								please make sure that you know what these tables
								are about and why they are not configured in
								$TCA.
							</p>
						', 2);
                    }
                    if (!$fCount) {
                        $this->message($fLabel, 'Correct number of fields in the database', '
							<p>
								There are no additional fields in the database
								tables compared to the configured fields in the
								$TCA array.
							</p>
						', -1);
                    } else {
                        $this->message($fLabel, 'Extra fields in the database', '
							<p>
								There are some additional fields the database
								tables which are not configured in the $TCA
								array.
								<br />
								You should probably not worry about this, but
								please make sure that you know what these fields
								are about and why they are not configured in
								$TCA.
							</p>
						', 2);
                    }
                    // Displaying actual and suggested field database defitions
                    if (is_array($cmpTCA_DB['matching'])) {
                        $tLabel = 'Comparison between database and $TCA';
                        $this->message($tLabel, 'Actual and suggested field definitions', '
							<p>
								This table shows you the suggested field
								definitions which are calculated based on the
								configuration in $TCA.
								<br />
								If the suggested value differs from the actual
								current database value, you should not panic,
								but simply check if the datatype of that field
								is sufficient compared to the data, you want
								TYPO3 to put there.
							</p>
						', 0);
                        foreach ($cmpTCA_DB['matching'] as $tableName => $conf) {
                            $this->message($tLabel, $tableName, $this->displayFieldComp($conf['fields'], $FDdb[$tableName]['fields']), 1);
                        }
                    }
                    break;
                case 'import':
                    $mode123Imported = 0;
                    $tblFileContent = '';
                    if (preg_match('/^CURRENT_/', $actionParts[1])) {
                        if (!strcmp($actionParts[1], 'CURRENT_TABLES') || !strcmp($actionParts[1], 'CURRENT_TABLES+STATIC')) {
                            $tblFileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl(PATH_t3lib . 'stddb/tables.sql');
                            foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $loadedExtConf) {
                                if (is_array($loadedExtConf) && $loadedExtConf['ext_tables.sql']) {
                                    $tblFileContent .= LF . LF . LF . LF . \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($loadedExtConf['ext_tables.sql']);
                                }
                            }
                        }
                        if (!strcmp($actionParts[1], 'CURRENT_STATIC') || !strcmp($actionParts[1], 'CURRENT_TABLES+STATIC')) {
                            foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $loadedExtConf) {
                                if (is_array($loadedExtConf) && $loadedExtConf['ext_tables_static+adt.sql']) {
                                    $tblFileContent .= LF . LF . LF . LF . \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($loadedExtConf['ext_tables_static+adt.sql']);
                                }
                            }
                        }
                        $tblFileContent .= LF . LF . LF . LF . \TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions();
                    } elseif (@is_file($actionParts[1])) {
                        $tblFileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($actionParts[1]);
                    }
                    if ($tblFileContent) {
                        $tLabel = 'Import SQL dump';
                        // Getting statement array from
                        $statements = $this->sqlHandler->getStatementArray($tblFileContent, 1);
                        list($statements_table, $insertCount) = $this->sqlHandler->getCreateTables($statements, 1);
                        // Updating database...
                        if ($this->INSTALL['database_import_all']) {
                            $r = 0;
                            foreach ($statements as $k => $v) {
                                $res = $GLOBALS['TYPO3_DB']->admin_query($v);
                                $r++;
                            }
                            // Make a database comparison because some tables that are defined twice have
                            // not been created at this point. This applies to the "pages.*"
                            // fields defined in sysext/cms/ext_tables.sql for example.
                            $fileContent = implode(LF, $this->sqlHandler->getStatementArray($tblFileContent, 1, '^CREATE TABLE '));
                            $FDfile = $this->sqlHandler->getFieldDefinitions_fileContent($fileContent);
                            $FDdb = $this->sqlHandler->getFieldDefinitions_database();
                            $diff = $this->sqlHandler->getDatabaseExtra($FDfile, $FDdb);
                            $update_statements = $this->sqlHandler->getUpdateSuggestions($diff);
                            if (is_array($update_statements['add'])) {
                                foreach ($update_statements['add'] as $statement) {
                                    $res = $GLOBALS['TYPO3_DB']->admin_query($statement);
                                }
                            }
                            if ($this->mode == '123') {
                                // Create default be_user admin/password
                                $username = '******';
                                $pass = '******';
                                $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid', 'be_users', 'username='******'TYPO3_DB']->fullQuoteStr($username, 'be_users'));
                                if (!$count) {
                                    $insertFields = array('username' => $username, 'password' => md5($pass), 'admin' => 1, 'uc' => '', 'fileoper_perms' => 0, 'tstamp' => $GLOBALS['EXEC_TIME'], 'crdate' => $GLOBALS['EXEC_TIME']);
                                    $GLOBALS['TYPO3_DB']->exec_INSERTquery('be_users', $insertFields);
                                }
                            }
                            $this->message($tLabel, 'Imported ALL', '
								<p>
									Queries: ' . $r . '
								</p>
							', 1, 1);
                            if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('goto_step')) {
                                $this->action .= '&step=' . \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('goto_step');
                                \TYPO3\CMS\Core\Utility\HttpUtility::redirect($this->action);
                            }
                        } elseif (is_array($this->INSTALL['database_import'])) {
                            // Traverse the tables
                            foreach ($this->INSTALL['database_import'] as $table => $md5str) {
                                if ($md5str == md5($statements_table[$table])) {
                                    $res = $GLOBALS['TYPO3_DB']->admin_query('DROP TABLE IF EXISTS ' . $table);
                                    $res = $GLOBALS['TYPO3_DB']->admin_query($statements_table[$table]);
                                    if ($insertCount[$table]) {
                                        $statements_insert = $this->sqlHandler->getTableInsertStatements($statements, $table);
                                        foreach ($statements_insert as $k => $v) {
                                            $res = $GLOBALS['TYPO3_DB']->admin_query($v);
                                        }
                                    }
                                    $this->message($tLabel, 'Imported \'' . $table . '\'', '
										<p>
											Rows: ' . $insertCount[$table] . '
										</p>
									', 1, 1);
                                }
                            }
                        }
                        $mode123Imported = $this->isBasicComplete($tLabel);
                        if (!$mode123Imported) {
                            // Re-Getting current tables - may have been changed during import
                            $whichTables = $this->sqlHandler->getListOfTables();
                            if (count($statements_table)) {
                                reset($statements_table);
                                $out = '';
                                // Get the template file
                                $templateFile = @file_get_contents(PATH_site . $this->templateFilePath . 'CheckTheDatabaseImport.html');
                                // Get the template part from the file
                                $content = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($templateFile, '###IMPORT###');
                                if ($this->mode != '123') {
                                    $tables = array();
                                    // Get the subpart for regular mode
                                    $regularModeSubpart = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($content, '###REGULARMODE###');
                                    foreach ($statements_table as $table => $definition) {
                                        // Get the subpart for rows
                                        $tableSubpart = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($content, '###ROWS###');
                                        // Fill the 'table exists' part when it exists
                                        $exist = isset($whichTables[$table]);
                                        if ($exist) {
                                            // Get the subpart for table exists
                                            $existSubpart = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($tableSubpart, '###EXIST###');
                                            // Define the markers content
                                            $existMarkers = array('tableExists' => 'Table exists!', 'backPath' => $this->backPath);
                                            // Fill the markers in the subpart
                                            $existSubpart = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($existSubpart, $existMarkers, '###|###', TRUE, FALSE);
                                        }
                                        // Substitute the subpart for table exists
                                        $tableHtml = \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpart($tableSubpart, '###EXIST###', $existSubpart);
                                        // Define the markers content
                                        $tableMarkers = array('table' => $table, 'definition' => md5($definition), 'count' => $insertCount[$table] ? $insertCount[$table] : '', 'rowLabel' => $insertCount[$table] ? 'Rows: ' : '', 'tableExists' => 'Table exists!', 'backPath' => $this->backPath);
                                        // Fill the markers
                                        $tables[] = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($tableHtml, $tableMarkers, '###|###', TRUE, FALSE);
                                    }
                                    // Substitute the subpart for the rows
                                    $regularModeSubpart = \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpart($regularModeSubpart, '###ROWS###', implode(LF, $tables));
                                }
                                // Substitute the subpart for the regular mode
                                $content = \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpart($content, '###REGULARMODE###', $regularModeSubpart);
                                // Define the markers content
                                $contentMarkers = array('checked' => $this->mode == '123' || \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('presetWholeTable') ? 'checked="checked"' : '', 'label' => 'Import the whole file \'' . basename($actionParts[1]) . '\' directly (ignores selections above)');
                                // Fill the markers
                                $content = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($content, $contentMarkers, '###|###', TRUE, FALSE);
                                $form = $this->getUpdateDbFormWrap($action_type, $content);
                                $this->message($tLabel, 'Select tables to import', '
									<p>
										This is an overview of the CREATE TABLE
										definitions in the SQL file.
										<br />
										Select which tables you want to dump to
										the database.
										<br />
										Any table you choose dump to the
										database is dropped from the database
										first, so you\'ll lose all data in
										existing tables.
									</p>
								' . $form, 1, 1);
                            } else {
                                $this->message($tLabel, 'No tables', '
									<p>
										There seems to be no CREATE TABLE
										definitions in the SQL file.
										<br />
										This tool is intelligently creating one
										table at a time and not just dumping the
										whole content of the file uncritically.
										That\'s why there must be defined tables
										in the SQL file.
									</p>
								', 3, 1);
                            }
                        }
                    }
                    break;
                case 'view':
                    if (@is_file($actionParts[1])) {
                        $tLabel = 'Import SQL dump';
                        // Getting statement array from
                        $fileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($actionParts[1]);
                        $statements = $this->sqlHandler->getStatementArray($fileContent, 1);
                        $maxL = 1000;
                        $strLen = strlen($fileContent);
                        $maxlen = 200 + ($maxL - \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(($strLen - 20000) / 100, 0, $maxL));
                        if (count($statements)) {
                            $out = '';
                            foreach ($statements as $statement) {
                                $out .= '<p>' . nl2br(htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($statement, $maxlen))) . '</p>';
                            }
                        }
                        $this->message($tLabel, 'Content of ' . basename($actionParts[1]), $out, 1);
                    }
                    break;
                case 'adminUser':
                    if ($whichTables['be_users']) {
                        if (is_array($this->INSTALL['database_adminUser'])) {
                            $username = preg_replace('/[^\\da-z._-]/i', '', trim($this->INSTALL['database_adminUser']['username']));
                            $pass = trim($this->INSTALL['database_adminUser']['password']);
                            $pass2 = trim($this->INSTALL['database_adminUser']['password2']);
                            if ($username && $pass && $pass2) {
                                if ($pass != $pass2) {
                                    $this->message($headCode, 'Passwords are not equal!', '
										<p>
											The passwords entered twice are not
											equal.
										</p>
									', 2, 1);
                                } else {
                                    $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'be_users', 'username='******'TYPO3_DB']->fullQuoteStr($username, 'be_users'));
                                    if (!$GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
                                        $insertFields = array('username' => $username, 'password' => md5($pass), 'admin' => 1, 'uc' => '', 'fileoper_perms' => 0, 'tstamp' => $GLOBALS['EXEC_TIME'], 'crdate' => $GLOBALS['EXEC_TIME']);
                                        $result = $GLOBALS['TYPO3_DB']->exec_INSERTquery('be_users', $insertFields);
                                        $this->isBasicComplete($headCode);
                                        if ($result) {
                                            $this->message($headCode, 'User created', '
												<p>
													Username:
													<strong>' . htmlspecialchars($username) . '
													</strong>
												</p>
											', 1, 1);
                                        } else {
                                            $this->message($headCode, 'User not created', '
												<p>
													Error:
													<strong>' . htmlspecialchars($GLOBALS['TYPO3_DB']->sql_error()) . '
													</strong>
												</p>
											', 3, 1);
                                        }
                                    } else {
                                        $this->message($headCode, 'Username not unique!', '
											<p>
												The username,
												<strong>' . htmlspecialchars($username) . '
												</strong>
												, was not unique.
											</p>
										', 2, 1);
                                    }
                                }
                            } else {
                                $this->message($headCode, 'Missing data!', '
									<p>
										Not all required form fields have been
										filled.
									</p>
								', 2, 1);
                            }
                        }
                        // Get the template file
                        $templateFile = @file_get_contents(PATH_site . $this->templateFilePath . 'CheckTheDatabaseAdminUser.html');
                        // Get the template part from the file
                        $content = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($templateFile, '###TEMPLATE###');
                        // Define the markers content
                        $contentMarkers = array('userName' => 'username - unique, no space, lowercase', 'password' => 'password', 'repeatPassword' => 'password (repeated)');
                        // Fill the markers
                        $content = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($content, $contentMarkers, '###|###', TRUE, FALSE);
                        $form = $this->getUpdateDbFormWrap($action_type, $content);
                        $this->message($headCode, 'Create admin user', '
							<p>
								Enter username and password for a new admin
								user.
								<br />
								You should use this function only if there are
								no admin users in the database, for instance if
								this is a blank database.
								<br />
								After you\'ve created the user, log in and add
								the rest of the user information, like email and
								real name.
							</p>
						' . $form, 0, 1);
                    } else {
                        $this->message($headCode, 'Required table not in database', '
							<p>
								\'be_users\' must be a table in the database!
							</p>
						', 3, 1);
                    }
                    break;
                case 'UC':
                    if ($whichTables['be_users']) {
                        if (!strcmp($this->INSTALL['database_UC'], 1)) {
                            $GLOBALS['TYPO3_DB']->exec_UPDATEquery('be_users', '', array('uc' => ''));
                            $this->message($headCode, 'Clearing be_users.uc', '
								<p>
									Done.
								</p>
							', 1);
                        }
                        // Get the template file
                        $templateFile = @file_get_contents(PATH_site . $this->templateFilePath . 'CheckTheDatabaseUc.html');
                        // Get the template part from the file
                        $content = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($templateFile, '###TEMPLATE###');
                        // Define the markers content
                        $contentMarkers = array('clearBeUsers' => 'Clear be_users preferences ("uc" field)');
                        // Fill the markers
                        $content = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($content, $contentMarkers, '###|###', TRUE, FALSE);
                        $form = $this->getUpdateDbFormWrap($action_type, $content);
                        $this->message($headCode, 'Clear user preferences', '
							<p>
								If you press this button all backend users from
								the tables be_users will have their user
								preferences cleared (field \'uc\' set to an
								empty string).
								<br />
								This may come in handy in rare cases where that
								configuration may be corrupt.
								<br />
								Clearing this will clear all user settings from
								the \'Setup\' module.
							</p>
						' . $form);
                    } else {
                        $this->message($headCode, 'Required table not in database', '
							<p>
								\'be_users\' must be a table in the database!
							</p>
						', 3);
                    }
                    break;
                case 'cache':
                    $tableListArr = explode(',', 'cache_pages,cache_pagesection,cache_hash,cache_imagesizes,--div--,sys_log,sys_history,--div--,be_sessions,fe_sessions,fe_session_data' . (\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded('indexed_search') ? ',--div--,index_words,index_rel,index_phash,index_grlist,index_section,index_fulltext' : '') . (\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded('tt_products') ? ',--div--,sys_products_orders,sys_products_orders_mm_tt_products' : '') . (\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded('direct_mail') ? ',--div--,sys_dmail_maillog' : ''));
                    if (is_array($this->INSTALL['database_clearcache'])) {
                        $qList = array();
                        // Get the template file
                        $templateFile = @file_get_contents(PATH_site . $this->templateFilePath . 'CheckTheDatabaseCache.html');
                        // Get the subpart for emptied tables
                        $emptiedTablesSubpart = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($templateFile, '###EMPTIEDTABLES###');
                        // Get the subpart for table
                        $tableSubpart = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($emptiedTablesSubpart, '###TABLE###');
                        foreach ($tableListArr as $table) {
                            if ($table != '--div--') {
                                $table_c = TYPO3_OS == 'WIN' ? strtolower($table) : $table;
                                if ($this->INSTALL['database_clearcache'][$table] && $whichTables[$table_c]) {
                                    $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery($table);
                                    // Define the markers content
                                    $emptiedTablesMarkers = array('tableName' => $table);
                                    // Fill the markers in the subpart
                                    $qList[] = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($tableSubpart, $emptiedTablesMarkers, '###|###', TRUE, FALSE);
                                }
                            }
                        }
                        // Substitute the subpart for table
                        $emptiedTablesSubpart = \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpart($emptiedTablesSubpart, '###TABLE###', implode(LF, $qList));
                        if (count($qList)) {
                            $this->message($headCode, 'Clearing cache', '
								<p>
									The following tables were emptied:
								</p>
							' . $emptiedTablesSubpart, 1);
                        }
                    }
                    // Count entries and make checkboxes
                    $labelArr = array('cache_pages' => 'Pages', 'cache_pagesection' => 'TS template related information', 'cache_hash' => 'Multipurpose md5-hash cache', 'cache_imagesizes' => 'Cached image sizes', 'sys_log' => 'Backend action logging', 'sys_history' => 'Addendum to the sys_log which tracks ALL changes to content through TCE. May become huge by time. Is used for rollback (undo) and the WorkFlow engine.', 'be_sessions' => 'Backend User sessions', 'fe_sessions' => 'Frontend User sessions', 'fe_session_data' => 'Frontend User sessions data', 'sys_dmail_maillog' => 'Direct Mail log', 'sys_products_orders' => 'tt_product orders', 'sys_products_orders_mm_tt_products' => 'relations between tt_products and sys_products_orders');
                    $countEntries = array();
                    reset($tableListArr);
                    // Get the template file
                    $templateFile = @file_get_contents(PATH_site . $this->templateFilePath . 'CheckTheDatabaseCache.html');
                    // Get the subpart for table list
                    $tableListSubpart = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($templateFile, '###TABLELIST###');
                    // Get the subpart for the group separator
                    $groupSubpart = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($tableListSubpart, '###GROUP###');
                    // Get the subpart for a single table
                    $singleTableSubpart = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($tableListSubpart, '###SINGLETABLE###');
                    $checkBoxes = array();
                    foreach ($tableListArr as $table) {
                        if ($table != '--div--') {
                            $table_c = TYPO3_OS == 'WIN' ? strtolower($table) : $table;
                            if ($whichTables[$table_c]) {
                                $countEntries[$table] = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', $table);
                                // Checkboxes:
                                if ($this->INSTALL['database_clearcache'][$table] || $_GET['PRESET']['database_clearcache'][$table]) {
                                    $checked = 'checked="checked"';
                                } else {
                                    $checked = '';
                                }
                                // Define the markers content
                                $singleTableMarkers = array('table' => $table, 'checked' => $checked, 'count' => '(' . $countEntries[$table] . ' rows)', 'label' => $labelArr[$table]);
                                // Fill the markers in the subpart
                                $checkBoxes[] = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($singleTableSubpart, $singleTableMarkers, '###|###', TRUE, FALSE);
                            }
                        } else {
                            $checkBoxes[] = $groupSubpart;
                        }
                    }
                    // Substitute the subpart for the single tables
                    $content = \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpart($tableListSubpart, '###SINGLETABLE###', implode(LF, $checkBoxes));
                    // Substitute the subpart for the group separator
                    $content = \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpart($content, '###GROUP###', '');
                    $form = $this->getUpdateDbFormWrap($action_type, $content);
                    $this->message($headCode, 'Clear out selected tables', '
						<p>
							Pressing this button will delete all records from
							the selected tables.
						</p>
					' . $form);
                    break;
            }
        }
        $this->output($this->outputWrapper($this->printAll()));
    }
示例#21
0
 /**
  * @return array
  */
 protected static function getAvailableMigrations($extKey)
 {
     $basePath = ExtensionManagementUtility::extPath($extKey) . '/Classes/Migration';
     $files = GeneralUtility::getFilesInDir($basePath);
     $classes = array();
     foreach ($files as $file) {
         $ts = self::getTimestampFromMigration($file);
         if (!$ts) {
             continue;
         }
         $classes[$ts] = self::getMigrationNameFromFileName($file);
     }
     ksort($classes);
     return $classes;
 }
示例#22
0
 /**
  * Function getFolder traverses the target directory,
  * locates all iconFiles and collects them into an array
  *
  * @param string $directoryPath Path to an folder which contains images
  * @return array Returns an array with all files key: iconname, value: fileName
  */
 protected function getFolder($directoryPath)
 {
     $subFolders = \TYPO3\CMS\Core\Utility\GeneralUtility::get_dirs(PATH_site . $directoryPath);
     if (!$this->ommitSpriteNameInIconName) {
         $subFolders[] = '';
     }
     $resultArray = array();
     foreach ($subFolders as $folder) {
         if ($folder !== '.svn') {
             $icons = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir(PATH_site . $directoryPath . $folder . '/', 'gif,png,jpg');
             if (!in_array($folder, $this->spriteBases) && count($icons) && $folder !== '') {
                 $this->spriteBases[] = $folder;
             }
             foreach ($icons as $icon) {
                 $fileInfo = pathinfo($icon);
                 $iconName = ($folder ? $folder . '-' : '') . $fileInfo['filename'];
                 if (!$this->ommitSpriteNameInIconName) {
                     $iconName = $this->spriteName . '-' . $iconName;
                 }
                 $resultArray[$iconName] = $directoryPath . $folder . '/' . $icon;
             }
         }
     }
     return $resultArray;
 }
示例#23
0
 /**
  * Loads the css and javascript files of all registered navigation widgets
  *
  * @return void
  */
 protected function loadResourcesForRegisteredNavigationComponents()
 {
     if (!is_array($GLOBALS['TBE_MODULES']['_navigationComponents'])) {
         return;
     }
     $loadedComponents = array();
     foreach ($GLOBALS['TBE_MODULES']['_navigationComponents'] as $module => $info) {
         if (in_array($info['componentId'], $loadedComponents)) {
             continue;
         }
         $loadedComponents[] = $info['componentId'];
         $component = strtolower(substr($info['componentId'], strrpos($info['componentId'], '-') + 1));
         $componentDirectory = 'components/' . $component . '/';
         if ($info['isCoreComponent']) {
             $absoluteComponentPath = PATH_site . 'typo3/sysext/backend/Resources/Public/JavaScript/extjs/' . $componentDirectory;
             $relativeComponentPath = '../' . str_replace(PATH_site, '', $absoluteComponentPath);
         } else {
             $absoluteComponentPath = ExtensionManagementUtility::extPath($info['extKey']) . $componentDirectory;
             $relativeComponentPath = ExtensionManagementUtility::extRelPath($info['extKey']) . $componentDirectory;
         }
         $cssFiles = GeneralUtility::getFilesInDir($absoluteComponentPath . 'css/', 'css');
         if (file_exists($absoluteComponentPath . 'css/loadorder.txt')) {
             // Don't allow inclusion outside directory
             $loadOrder = str_replace('../', '', GeneralUtility::getUrl($absoluteComponentPath . 'css/loadorder.txt'));
             $cssFilesOrdered = GeneralUtility::trimExplode(LF, $loadOrder, true);
             $cssFiles = array_merge($cssFilesOrdered, $cssFiles);
         }
         foreach ($cssFiles as $cssFile) {
             $this->pageRenderer->addCssFile($relativeComponentPath . 'css/' . $cssFile);
         }
         $jsFiles = GeneralUtility::getFilesInDir($absoluteComponentPath . 'javascript/', 'js');
         if (file_exists($absoluteComponentPath . 'javascript/loadorder.txt')) {
             // Don't allow inclusion outside directory
             $loadOrder = str_replace('../', '', GeneralUtility::getUrl($absoluteComponentPath . 'javascript/loadorder.txt'));
             $jsFilesOrdered = GeneralUtility::trimExplode(LF, $loadOrder, true);
             $jsFiles = array_merge($jsFilesOrdered, $jsFiles);
         }
         foreach ($jsFiles as $jsFile) {
             $this->pageRenderer->addJsFile($relativeComponentPath . 'javascript/' . $jsFile);
         }
         $this->pageRenderer->addInlineSetting('RecordHistory', 'moduleUrl', BackendUtility::getModuleUrl('record_history'));
         $this->pageRenderer->addInlineSetting('NewRecord', 'moduleUrl', BackendUtility::getModuleUrl('db_new'));
         $this->pageRenderer->addInlineSetting('FormEngine', 'moduleUrl', BackendUtility::getModuleUrl('record_edit'));
     }
 }
示例#24
0
    /**
     * Rich Text Editor (RTE) user element selector
     *
     * @param array $openKeys
     * @return string
     */
    public function main_user($openKeys)
    {
        // Starting content:
        $content = $this->doc->startPage(htmlspecialchars($GLOBALS['LANG']->getLL('Insert Custom Element')));
        $RTEtsConfigParts = explode(':', \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('RTEtsConfigParams'));
        $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
        $thisConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
        if (is_array($thisConfig['userElements.'])) {
            $categories = [];
            foreach ($thisConfig['userElements.'] as $k => $value) {
                $ki = (int) $k;
                $v = $thisConfig['userElements.'][$ki . '.'];
                if (substr($k, -1) == '.' && is_array($v)) {
                    $subcats = [];
                    $openK = $ki;
                    if ($openKeys[$openK]) {
                        $mArray = '';
                        if ($v['load'] === 'images_from_folder') {
                            $mArray = [];
                            if ($v['path'] && @is_dir(PATH_site . $v['path'])) {
                                $files = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir(PATH_site . $v['path'], 'gif,jpg,jpeg,png', 0, '');
                                if (is_array($files)) {
                                    $c = 0;
                                    foreach ($files as $filename) {
                                        $iInfo = @getimagesize(PATH_site . $v['path'] . $filename);
                                        $iInfo = $this->calcWH($iInfo, 50, 100);
                                        $ks = (string) (100 + $c);
                                        $mArray[$ks] = $filename;
                                        $mArray[$ks . '.'] = ['content' => '<img src="' . $this->siteUrl . $v['path'] . $filename . '" />', '_icon' => '<img src="' . $this->siteUrl . $v['path'] . $filename . '" ' . $iInfo[3] . ' />', 'description' => $GLOBALS['LANG']->getLL('filesize') . ': ' . str_replace('&nbsp;', ' ', \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize(@filesize(PATH_site . $v['path'] . $filename))) . ', ' . htmlspecialchars($GLOBALS['LANG']->getLL('pixels')) . ': ' . $iInfo[0] . 'x' . $iInfo[1]];
                                        $c++;
                                    }
                                }
                            }
                        }
                        if (is_array($mArray)) {
                            if ($v['merge']) {
                                \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($mArray, $v);
                                $v = $mArray;
                            } else {
                                $v = $mArray;
                            }
                        }
                        foreach ($v as $k2 => $dummyValue) {
                            $k2i = (int) $k2;
                            if (substr($k2, -1) == '.' && is_array($v[$k2i . '.'])) {
                                $title = trim($v[$k2i]);
                                if (!$title) {
                                    $title = '[' . htmlspecialchars($GLOBALS['LANG']->getLL('noTitle')) . ']';
                                } else {
                                    $title = htmlspecialchars($GLOBALS['LANG']->sL($title));
                                }
                                $description = htmlspecialchars($GLOBALS['LANG']->sL($v[$k2i . '.']['description'])) . '<br />';
                                if (!$v[$k2i . '.']['dontInsertSiteUrl']) {
                                    $v[$k2i . '.']['content'] = str_replace('###_URL###', $this->siteUrl, $v[$k2i . '.']['content']);
                                }
                                $logo = $v[$k2i . '.']['_icon'] ?: '';
                                $onClickEvent = '';
                                switch ((string) $v[$k2i . '.']['mode']) {
                                    case 'wrap':
                                        $wrap = explode('|', $v[$k2i . '.']['content']);
                                        $onClickEvent = 'wrapHTML(' . GeneralUtility::quoteJSvalue($wrap[0]) . ',' . GeneralUtility::quoteJSvalue($wrap[1]) . ',false);';
                                        break;
                                    case 'processor':
                                        $script = trim($v[$k2i . '.']['submitToScript']);
                                        if (substr($script, 0, 4) != 'http') {
                                            $script = $this->siteUrl . $script;
                                        }
                                        if ($script) {
                                            $onClickEvent = 'processSelection(' . GeneralUtility::quoteJSvalue($script) . ');';
                                        }
                                        break;
                                    case 'insert':
                                    default:
                                        $onClickEvent = 'insertHTML(' . GeneralUtility::quoteJSvalue($v[$k2i . '.']['content']) . ');';
                                }
                                $A = ['<a href="#" onClick="' . $onClickEvent . 'return false;">', '</a>'];
                                $subcats[$k2i] = '<tr>
									<td></td>
									<td>' . $A[0] . $logo . $A[1] . '</td>
									<td>' . $A[0] . '<strong>' . $title . '</strong><br />' . $description . $A[1] . '</td>
								</tr>';
                            }
                        }
                        ksort($subcats);
                    }
                    $categories[$ki] = implode('', $subcats);
                }
            }
            ksort($categories);
            // Render menu of the items:
            $lines = [];
            foreach ($categories as $k => $v) {
                $title = trim($thisConfig['userElements.'][$k]);
                $openK = $k;
                if (!$title) {
                    $title = '[' . htmlspecialchars($GLOBALS['LANG']->getLL('noTitle')) . ']';
                } else {
                    $title = htmlspecialchars($GLOBALS['LANG']->sL($title));
                }
                $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
                $url = (string) $uriBuilder->buildUriFromRoute('rtehtmlarea_wizard_user_elements', ['OC_key' => ($openKeys[$openK] ? 'C|' : 'O|') . $openK]);
                $lines[] = '<tr><td colspan="3"><a href="#" title="' . htmlspecialchars($GLOBALS['LANG']->getLL('expand')) . '" onClick="jumpToUrl(' . GeneralUtility::quoteJSvalue($url) . ');return false;"><i class="fa fa-caret-square-o-' . ($openKeys[$openK] ? 'left' : 'right') . '" title="' . htmlspecialchars($GLOBALS['LANG']->getLL('expand')) . '"></i><strong>' . $title . '</strong></a></td></tr>';
                $lines[] = $v;
            }
            $content .= '<table class="table table-striped table-hover">' . implode('', $lines) . '</table>';
        }
        $content .= $this->doc->endPage();
        return $content;
    }
示例#25
0
 /**
  * Dotfiles; current directory: '.' and parent directory: '..' must not be
  * present.
  *
  * @test
  */
 public function getFilesInDirDoesNotFindDotfiles()
 {
     $vfsStreamUrl = $this->getFilesInDirCreateTestDirectory();
     $files = GeneralUtility::getFilesInDir($vfsStreamUrl);
     $this->assertNotContains('..', $files);
     $this->assertNotContains('.', $files);
 }
    /**
     * Import part of module
     *
     * @param array $inData Content of POST VAR tx_impexp[]..
     * @return void Setting content in $this->content
     * @todo Define visibility
     */
    public function importData($inData)
    {
        global $LANG;
        $access = is_array($this->pageinfo) ? 1 : 0;
        if ($this->id && $access || $GLOBALS['BE_USER']->user['admin'] && !$this->id) {
            if ($GLOBALS['BE_USER']->user['admin'] && !$this->id) {
                $this->pageinfo = array('title' => '[root-level]', 'uid' => 0, 'pid' => 0);
            }
            if ($inData['new_import']) {
                unset($inData['import_mode']);
            }
            /** @var $import \TYPO3\CMS\Impexp\ImportExport */
            $import = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Impexp\\ImportExport');
            $import->init(0, 'import');
            $import->update = $inData['do_update'];
            $import->import_mode = $inData['import_mode'];
            $import->enableLogging = $inData['enableLogging'];
            $import->global_ignore_pid = $inData['global_ignore_pid'];
            $import->force_all_UIDS = $inData['force_all_UIDS'];
            $import->showDiff = !$inData['notShowDiff'];
            $import->allowPHPScripts = $inData['allowPHPScripts'];
            $import->softrefInputValues = $inData['softrefInputValues'];
            // OUTPUT creation:
            $menuItems = array();
            // Make input selector:
            // must have trailing slash.
            $path = $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'];
            $filesInDir = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir(PATH_site . $path, 't3d,xml', 1, 1);
            $userPath = $this->userSaveFolder();
            //Files from User-Dir
            $filesInUserDir = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($userPath, 't3d,xml', 1, 1);
            $filesInDir = array_merge($filesInUserDir, $filesInDir);
            if (is_dir(PATH_site . $path . 'export/')) {
                $filesInDir = array_merge($filesInDir, \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir(PATH_site . $path . 'export/', 't3d,xml', 1, 1));
            }
            $tempFolder = $this->userTempFolder();
            if ($tempFolder) {
                $temp_filesInDir = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($tempFolder, 't3d,xml', 1, 1);
                $filesInDir = array_merge($filesInDir, $temp_filesInDir);
            }
            // Configuration
            $row = array();
            $opt = array('');
            foreach ($filesInDir as $file) {
                $opt[$file] = substr($file, strlen(PATH_site));
            }
            $row[] = '<tr class="bgColor5">
					<td colspan="2"><strong>' . $LANG->getLL('importdata_selectFileToImport', 1) . '</strong></td>
				</tr>';
            $row[] = '<tr class="bgColor4">
				<td><strong>' . $LANG->getLL('importdata_file', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'importFile', $GLOBALS['BACK_PATH'], '') . '</td>
				<td>' . $this->renderSelectBox('tx_impexp[file]', $inData['file'], $opt) . '<br />' . sprintf($LANG->getLL('importdata_fromPathS', 1), $path) . (!$import->compress ? '<br /><span class="typo3-red">' . $LANG->getLL('importdata_noteNoDecompressorAvailable', 1) . '</span>' : '') . '</td>
				</tr>';
            $row[] = '<tr class="bgColor5">
					<td colspan="2"><strong>' . $LANG->getLL('importdata_importOptions', 1) . '</strong></td>
				</tr>';
            $row[] = '<tr class="bgColor4">
				<td><strong>' . $LANG->getLL('importdata_update', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'update', $GLOBALS['BACK_PATH'], '') . '</td>
				<td>
					<input type="checkbox" name="tx_impexp[do_update]" id="checkDo_update" value="1"' . ($inData['do_update'] ? ' checked="checked"' : '') . ' />
					<label for="checkDo_update">' . $LANG->getLL('importdata_updateRecords', 1) . '</label><br/>
				<em>(' . $LANG->getLL('importdata_thisOptionRequiresThat', 1) . ')</em>' . ($inData['do_update'] ? '	<hr/>
					<input type="checkbox" name="tx_impexp[global_ignore_pid]" id="checkGlobal_ignore_pid" value="1"' . ($inData['global_ignore_pid'] ? ' checked="checked"' : '') . ' />
					<label for="checkGlobal_ignore_pid">' . $LANG->getLL('importdata_ignorePidDifferencesGlobally', 1) . '</label><br/>
					<em>(' . $LANG->getLL('importdata_ifYouSetThis', 1) . ')</em>
					' : '') . '</td>
				</tr>';
            $row[] = '<tr class="bgColor4">
				<td><strong>' . $LANG->getLL('importdata_options', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'options', $GLOBALS['BACK_PATH'], '') . '</td>
				<td>
					<input type="checkbox" name="tx_impexp[notShowDiff]" id="checkNotShowDiff" value="1"' . ($inData['notShowDiff'] ? ' checked="checked"' : '') . ' />
					<label for="checkNotShowDiff">' . $LANG->getLL('importdata_doNotShowDifferences', 1) . '</label><br/>
					<em>(' . $LANG->getLL('importdata_greenValuesAreFrom', 1) . ')</em>
					<br/><br/>

					' . ($GLOBALS['BE_USER']->isAdmin() ? '
					<input type="checkbox" name="tx_impexp[allowPHPScripts]" id="checkAllowPHPScripts" value="1"' . ($inData['allowPHPScripts'] ? ' checked="checked"' : '') . ' />
					<label for="checkAllowPHPScripts">' . $LANG->getLL('importdata_allowToWriteBanned', 1) . '</label><br/>' : '') . (!$inData['do_update'] && $GLOBALS['BE_USER']->isAdmin() ? '
					<br/>
					<input type="checkbox" name="tx_impexp[force_all_UIDS]" id="checkForce_all_UIDS" value="1"' . ($inData['force_all_UIDS'] ? ' checked="checked"' : '') . ' />
					<label for="checkForce_all_UIDS"><span class="typo3-red">' . $LANG->getLL('importdata_force_all_UIDS', 1) . '</span></label><br/>
					<em>(' . $LANG->getLL('importdata_force_all_UIDS_descr', 1) . ')</em>' : '') . '
				</td>
				</tr>';
            $row[] = '<tr class="bgColor4">
				<td><strong>' . $LANG->getLL('importdata_action', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'action', $GLOBALS['BACK_PATH'], '') . '</td>
				<td>' . (!$inData['import_file'] ? '<input type="submit" value="' . $LANG->getLL('importdata_preview', 1) . '" />' . ($inData['file'] ? ' - <input type="submit" value="' . ($inData['do_update'] ? $LANG->getLL('importdata_update_299e', 1) : $LANG->getLL('importdata_import', 1)) . '" name="tx_impexp[import_file]" onclick="return confirm(\'' . $LANG->getLL('importdata_areYouSure', 1) . '\');" />' : '') : '<input type="submit" name="tx_impexp[new_import]" value="' . $LANG->getLL('importdata_newImport', 1) . '" />') . '
					<input type="hidden" name="tx_impexp[action]" value="import" /></td>
				</tr>';
            $row[] = '<tr class="bgColor4">
				<td><strong>' . $LANG->getLL('importdata_enableLogging', 1) . '</strong>' . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'enableLogging', $GLOBALS['BACK_PATH'], '') . '</td>
				<td>
					<input type="checkbox" name="tx_impexp[enableLogging]" id="checkEnableLogging" value="1"' . ($inData['enableLogging'] ? ' checked="checked"' : '') . ' />
					<label for="checkEnableLogging">' . $LANG->getLL('importdata_writeIndividualDbActions', 1) . '</label><br/>
					<em>(' . $LANG->getLL('importdata_thisIsDisabledBy', 1) . ')</em>
				</td>
				</tr>';
            $menuItems[] = array('label' => $LANG->getLL('importdata_import', 1), 'content' => '
					<table border="0" cellpadding="1" cellspacing="1">
						' . implode('
						', $row) . '
					</table>
				');
            // Upload file:
            $tempFolder = $this->userTempFolder();
            if ($tempFolder) {
                $row = array();
                $row[] = '<tr class="bgColor5">
						<td colspan="2"><strong>' . $LANG->getLL('importdata_uploadFileFromLocal', 1) . '</strong></td>
					</tr>';
                $row[] = '<tr class="bgColor4">
						<td>' . $LANG->getLL('importdata_browse', 1) . \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_tx_impexp', 'upload', $GLOBALS['BACK_PATH'], '') . '</td>
						<td>

								<input type="file" name="upload_1"' . $this->doc->formWidth(35) . ' size="40" />
								<input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($tempFolder) . '" />
								<input type="hidden" name="file[upload][1][data]" value="1" /><br />

								<input type="submit" name="_upload" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit', 1) . '" />
								<input type="checkbox" name="overwriteExistingFiles" id="checkOverwriteExistingFiles" value="1" checked="checked" /> <label for="checkOverwriteExistingFiles">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.php:overwriteExistingFiles', 1) . '</label>
						</td>
					</tr>';
                if (\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('_upload')) {
                    $row[] = '<tr class="bgColor4">
							<td>' . $LANG->getLL('importdata_uploadStatus', 1) . '</td>
							<td>' . ($this->fileProcessor->internalUploadMap[1] ? $LANG->getLL('importdata_success', 1) . ' ' . substr($this->fileProcessor->internalUploadMap[1], strlen(PATH_site)) : '<span class="typo3-red">' . $LANG->getLL('importdata_failureNoFileUploaded', 1) . '</span>') . '</td>
						</tr>';
                }
                $menuItems[] = array('label' => $LANG->getLL('importdata_upload'), 'content' => '
						<table border="0" cellpadding="1" cellspacing="1">
							' . implode('
							', $row) . '
						</table>
					');
            }
            // Perform import or preview depending:
            $overviewContent = '';
            $extensionInstallationMessage = '';
            $emURL = '';
            $inFile = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($inData['file']);
            if ($inFile && @is_file($inFile)) {
                $trow = array();
                if ($import->loadFile($inFile, 1)) {
                    // Check extension dependencies:
                    $extKeysToInstall = array();
                    if (is_array($import->dat['header']['extensionDependencies'])) {
                        foreach ($import->dat['header']['extensionDependencies'] as $extKey) {
                            if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extKey)) {
                                $extKeysToInstall[] = $extKey;
                            }
                        }
                    }
                    if (count($extKeysToInstall)) {
                        $passParams = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('tx_impexp');
                        unset($passParams['import_mode']);
                        unset($passParams['import_file']);
                        $thisScriptUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI') . '?M=xMOD_tximpexp&id=' . $this->id . \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('tx_impexp', $passParams);
                        $emURL = $this->doc->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('em') . 'classes/index.php?CMD[requestInstallExtensions]=' . implode(',', $extKeysToInstall) . '&returnUrl=' . rawurlencode($thisScriptUrl);
                        $extensionInstallationMessage = 'Before you can install this T3D file you need to install the extensions "' . implode('", "', $extKeysToInstall) . '". Clicking Import will first take you to the Extension Manager so these dependencies can be resolved.';
                    }
                    if ($inData['import_file']) {
                        if (!count($extKeysToInstall)) {
                            $import->importData($this->id);
                            \TYPO3\CMS\Backend\Utility\BackendUtility::setUpdateSignal('updatePageTree');
                        } else {
                            \TYPO3\CMS\Core\Utility\HttpUtility::redirect($emURL);
                        }
                    }
                    $import->display_import_pid_record = $this->pageinfo;
                    $overviewContent = $import->displayContentOverview();
                }
                // Meta data output:
                $trow[] = '<tr class="bgColor5">
						<td colspan="2"><strong>' . $LANG->getLL('importdata_metaData', 1) . '</strong></td>
					</tr>';
                $opt = array('');
                foreach ($filesInDir as $file) {
                    $opt[$file] = substr($file, strlen(PATH_site));
                }
                $trow[] = '<tr class="bgColor4">
					<td><strong>' . $LANG->getLL('importdata_title', 1) . '</strong></td>
					<td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['title'])) . '</td>
					</tr>';
                $trow[] = '<tr class="bgColor4">
					<td><strong>' . $LANG->getLL('importdata_description', 1) . '</strong></td>
					<td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['description'])) . '</td>
					</tr>';
                $trow[] = '<tr class="bgColor4">
					<td><strong>' . $LANG->getLL('importdata_notes', 1) . '</strong></td>
					<td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['notes'])) . '</td>
					</tr>';
                $trow[] = '<tr class="bgColor4">
					<td><strong>' . $LANG->getLL('importdata_packager', 1) . '</strong></td>
					<td width="95%">' . nl2br(htmlspecialchars($import->dat['header']['meta']['packager_name'] . ' (' . $import->dat['header']['meta']['packager_username'] . ')')) . '<br/>
						' . $LANG->getLL('importdata_email', 1) . ' ' . $import->dat['header']['meta']['packager_email'] . '</td>
					</tr>';
                // Thumbnail icon:
                if (is_array($import->dat['header']['thumbnail'])) {
                    $pI = pathinfo($import->dat['header']['thumbnail']['filename']);
                    if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('gif,jpg,png,jpeg', strtolower($pI['extension']))) {
                        // Construct filename and write it:
                        $fileName = PATH_site . 'typo3temp/importthumb.' . $pI['extension'];
                        \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile($fileName, $import->dat['header']['thumbnail']['content']);
                        // Check that the image really is an image and not a malicious PHP script...
                        if (getimagesize($fileName)) {
                            // Create icon tag:
                            $iconTag = '<img src="' . $this->doc->backPath . '../' . substr($fileName, strlen(PATH_site)) . '" ' . $import->dat['header']['thumbnail']['imgInfo'][3] . ' vspace="5" style="border: solid black 1px;" alt="" />';
                            $trow[] = '<tr class="bgColor4">
								<td><strong>' . $LANG->getLL('importdata_icon', 1) . '</strong></td>
								<td>' . $iconTag . '</td>
								</tr>';
                        } else {
                            \TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($fileName);
                        }
                    }
                }
                $menuItems[] = array('label' => $LANG->getLL('importdata_metaData_1387'), 'content' => '
						<table border="0" cellpadding="1" cellspacing="1">
							' . implode('
							', $trow) . '
						</table>
					');
            }
            // Print errors that might be:
            $errors = $import->printErrorLog();
            $menuItems[] = array('label' => $LANG->getLL('importdata_messages'), 'content' => $errors, 'stateIcon' => $errors ? 2 : 0);
            // Output tabs:
            $content = $this->doc->getDynTabMenu($menuItems, 'tx_impexp_import', -1);
            if ($extensionInstallationMessage) {
                $content = '<div style="border: 1px black solid; margin: 10px 10px 10px 10px; padding: 10px 10px 10px 10px;">' . $this->doc->icons(1) . htmlspecialchars($extensionInstallationMessage) . '</div>' . $content;
            }
            $this->content .= $this->doc->section('', $content, 0, 1);
            // Print overview:
            if ($overviewContent) {
                $this->content .= $this->doc->section($inData['import_file'] ? $LANG->getLL('importdata_structureHasBeenImported', 1) : $LANG->getLL('filterpage_structureToBeImported', 1), $overviewContent, 0, 1);
            }
        }
    }
示例#27
0
    /**
     * Rich Text Editor (RTE) user element selector
     *
     * @param 	[type]		$openKeys: ...
     * @return 	[type]		...
     * @todo Define visibility
     */
    public function main_user($openKeys)
    {
        // Starting content:
        $content = $this->doc->startPage($GLOBALS['LANG']->getLL('Insert Custom Element', 1));
        $RTEtsConfigParts = explode(':', \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('RTEtsConfigParams'));
        $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
        $thisConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
        if (is_array($thisConfig['userElements.'])) {
            $categories = array();
            foreach ($thisConfig['userElements.'] as $k => $value) {
                $ki = intval($k);
                $v = $thisConfig['userElements.'][$ki . '.'];
                if (substr($k, -1) == '.' && is_array($v)) {
                    $subcats = array();
                    $openK = $ki;
                    if ($openKeys[$openK]) {
                        $mArray = '';
                        switch ((string) $v['load']) {
                            case 'images_from_folder':
                                $mArray = array();
                                if ($v['path'] && @is_dir(PATH_site . $v['path'])) {
                                    $files = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir(PATH_site . $v['path'], 'gif,jpg,jpeg,png', 0, '');
                                    if (is_array($files)) {
                                        $c = 0;
                                        foreach ($files as $filename) {
                                            $iInfo = @getimagesize(PATH_site . $v['path'] . $filename);
                                            $iInfo = $this->calcWH($iInfo, 50, 100);
                                            $ks = (string) (100 + $c);
                                            $mArray[$ks] = $filename;
                                            $mArray[$ks . '.'] = array('content' => '<img src="' . $this->siteUrl . $v['path'] . $filename . '" />', '_icon' => '<img src="' . $this->siteUrl . $v['path'] . $filename . '" ' . $iInfo[3] . ' />', 'description' => $GLOBALS['LANG']->getLL('filesize') . ': ' . str_replace('&nbsp;', ' ', \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize(@filesize(PATH_site . $v['path'] . $filename))) . ', ' . $GLOBALS['LANG']->getLL('pixels', 1) . ': ' . $iInfo[0] . 'x' . $iInfo[1]);
                                            $c++;
                                        }
                                    }
                                }
                                break;
                        }
                        if (is_array($mArray)) {
                            if ($v['merge']) {
                                $v = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($mArray, $v);
                            } else {
                                $v = $mArray;
                            }
                        }
                        foreach ($v as $k2 => $dummyValue) {
                            $k2i = intval($k2);
                            if (substr($k2, -1) == '.' && is_array($v[$k2i . '.'])) {
                                $title = trim($v[$k2i]);
                                if (!$title) {
                                    $title = '[' . $GLOBALS['LANG']->getLL('noTitle', 1) . ']';
                                } else {
                                    $title = $GLOBALS['LANG']->sL($title, 1);
                                }
                                $description = $GLOBALS['LANG']->sL($v[$k2i . '.']['description'], 1) . '<br />';
                                if (!$v[$k2i . '.']['dontInsertSiteUrl']) {
                                    $v[$k2i . '.']['content'] = str_replace('###_URL###', $this->siteUrl, $v[$k2i . '.']['content']);
                                }
                                $logo = $v[$k2i . '.']['_icon'] ? $v[$k2i . '.']['_icon'] : '';
                                $onClickEvent = '';
                                switch ((string) $v[$k2i . '.']['mode']) {
                                    case 'wrap':
                                        $wrap = explode('|', $v[$k2i . '.']['content']);
                                        $onClickEvent = 'wrapHTML(' . $GLOBALS['LANG']->JScharCode($wrap[0]) . ',' . $GLOBALS['LANG']->JScharCode($wrap[1]) . ',false);';
                                        break;
                                    case 'processor':
                                        $script = trim($v[$k2i . '.']['submitToScript']);
                                        if (substr($script, 0, 4) != 'http') {
                                            $script = $this->siteUrl . $script;
                                        }
                                        if ($script) {
                                            $onClickEvent = 'processSelection(' . $GLOBALS['LANG']->JScharCode($script) . ');';
                                        }
                                        break;
                                    case 'insert':
                                    default:
                                        $onClickEvent = 'insertHTML(' . $GLOBALS['LANG']->JScharCode($v[$k2i . '.']['content']) . ');';
                                        break;
                                }
                                $A = array('<a href="#" onClick="' . $onClickEvent . 'return false;">', '</a>');
                                $subcats[$k2i] = '<tr>
									<td><img src="clear.gif" width="18" height="1" /></td>
									<td class="bgColor4" valign="top">' . $A[0] . $logo . $A[1] . '</td>
									<td class="bgColor4" valign="top">' . $A[0] . '<strong>' . $title . '</strong><br />' . $description . $A[1] . '</td>
								</tr>';
                            }
                        }
                        ksort($subcats);
                    }
                    $categories[$ki] = implode('', $subcats);
                }
            }
            ksort($categories);
            // Render menu of the items:
            $lines = array();
            foreach ($categories as $k => $v) {
                $title = trim($thisConfig['userElements.'][$k]);
                $openK = $k;
                if (!$title) {
                    $title = '[' . $GLOBALS['LANG']->getLL('noTitle', 1) . ']';
                } else {
                    $title = $GLOBALS['LANG']->sL($title, 1);
                }
                $lines[] = '<tr><td colspan="3" class="bgColor5"><a href="#" title="' . $GLOBALS['LANG']->getLL('expand', 1) . '" onClick="jumpToUrl(\'?OC_key=' . ($openKeys[$openK] ? 'C|' : 'O|') . $openK . '\');return false;"><img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/ol/' . ($openKeys[$openK] ? 'minus' : 'plus') . 'bullet.gif', 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('expand', 1) . '" /><strong>' . $title . '</strong></a></td></tr>';
                $lines[] = $v;
            }
            $content .= '<table border="0" cellpadding="1" cellspacing="1">' . implode('', $lines) . '</table>';
        }
        $content .= $this->doc->endPage();
        return $content;
    }
示例#28
0
 /**
  * Remove old Backups
  *
  * @param string $backupPath Path to the Backup
  * @param int $backupsToKeep Backups to keep
  *
  * @return bool return
  */
 public static function removeOldBackups($backupPath, $backupsToKeep)
 {
     $oldBackupFiles = GeneralUtility::getFilesInDir($backupPath, '', false, '', 'backup.log');
     while (count($oldBackupFiles) > $backupsToKeep) {
         unlink($backupPath . array_shift($oldBackupFiles));
     }
     return true;
 }
示例#29
0
    /**
     * Main Task center module
     *
     * @return string HTML content.
     */
    public function main()
    {
        $content = '';
        $id = intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('display'));
        // If a preset is found, it is rendered using an iframe
        if ($id > 0) {
            $url = $GLOBALS['BACK_PATH'] . \TYPO3\CMS\Core\Extension\ExtensionManager::extRelPath('impexp') . 'app/index.php?tx_impexp[action]=export&preset[load]=1&preset[select]=' . $id;
            return $this->taskObject->urlInIframe($url, 1);
        } else {
            // Header
            $content .= $this->taskObject->description($GLOBALS['LANG']->getLL('.alttitle'), $GLOBALS['LANG']->getLL('.description'));
            $thumbnails = $lines = array();
            // Thumbnail folder and files:
            $tempDir = $this->userTempFolder();
            if ($tempDir) {
                $thumbnails = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($tempDir, 'png,gif,jpg', 1);
            }
            $clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
            $usernames = \TYPO3\CMS\Backend\Utility\BackendUtility::getUserNames();
            // Create preset links:
            $presets = $this->getPresets();
            // If any presets found
            if (is_array($presets)) {
                foreach ($presets as $key => $presetCfg) {
                    $configuration = unserialize($presetCfg['preset_data']);
                    $thumbnailFile = $thumbnails[$configuration['meta']['thumbnail']];
                    $title = strlen($presetCfg['title']) ? $presetCfg['title'] : '[' . $presetCfg['uid'] . ']';
                    $icon = 'EXT:impexp/export.gif';
                    $description = array();
                    // Is public?
                    if ($presetCfg['public']) {
                        $description[] = $GLOBALS['LANG']->getLL('task.public') . ': ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
                    }
                    // Owner
                    $description[] = $GLOBALS['LANG']->getLL('task.owner') . ': ' . ($presetCfg['user_uid'] === $GLOBALS['BE_USER']->user['uid'] ? $GLOBALS['LANG']->getLL('task.own') : '[' . htmlspecialchars($usernames[$presetCfg['user_uid']]['username']) . ']');
                    // Page & path
                    if ($configuration['pagetree']['id']) {
                        $description[] = $GLOBALS['LANG']->getLL('task.page') . ': ' . $configuration['pagetree']['id'];
                        $description[] = $GLOBALS['LANG']->getLL('task.path') . ': ' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::getRecordPath($configuration['pagetree']['id'], $clause, 20));
                    } else {
                        $description[] = $GLOBALS['LANG']->getLL('single-record');
                    }
                    // Meta information
                    if ($configuration['meta']['title'] || $configuration['meta']['description'] || $configuration['meta']['notes']) {
                        $metaInformation = '';
                        if ($configuration['meta']['title']) {
                            $metaInformation .= '<strong>' . htmlspecialchars($configuration['meta']['title']) . '</strong><br />';
                        }
                        if ($configuration['meta']['description']) {
                            $metaInformation .= htmlspecialchars($configuration['meta']['description']);
                        }
                        if ($configuration['meta']['notes']) {
                            $metaInformation .= '<br /><br />
												<strong>' . $GLOBALS['LANG']->getLL('notes') . ': </strong>
												<em>' . htmlspecialchars($configuration['meta']['notes']) . '</em>';
                        }
                        $description[] = '<br />' . $metaInformation;
                    }
                    // Collect all preset information
                    $lines[$key] = array('icon' => $icon, 'title' => $title, 'descriptionHtml' => implode('<br />', $description), 'link' => 'mod.php?M=user_task&SET[function]=impexp.tx_impexp_task&display=' . $presetCfg['uid']);
                }
                // Render preset list
                $content .= $this->taskObject->renderListMenu($lines);
            } else {
                // No presets found
                $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('no-presets'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE);
                $content .= $flashMessage->render();
            }
        }
        return $content;
    }
 /**
  * Add all *.css files of the directory $path to the stylesheets
  *
  * @param string $path directory to add
  * @return void
  */
 public function addStyleSheetDirectory($path)
 {
     $path = GeneralUtility::getFileAbsFileName($path);
     // Read all files in directory and sort them alphabetically
     $cssFiles = GeneralUtility::getFilesInDir($path, 'css');
     foreach ($cssFiles as $cssFile) {
         $this->pageRenderer->addCssFile(PathUtility::getRelativePathTo($path) . $cssFile);
     }
 }