/** * Constructor */ public function __construct() { // we check for existence of our targetDirectory if (!is_dir(PATH_site . $this->targetDirectory)) { GeneralUtility::mkdir(PATH_site . $this->targetDirectory); } // if enabled, we check whether we should auto-create the .htaccess file if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['generateApacheHtaccess']) { // check whether .htaccess exists $htaccessPath = PATH_site . $this->targetDirectory . '.htaccess'; if (!file_exists($htaccessPath)) { GeneralUtility::writeFile($htaccessPath, $this->htaccessTemplate); } } // decide whether we should create gzipped versions or not $compressionLevel = $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['compressionLevel']; // we need zlib for gzencode() if (extension_loaded('zlib') && $compressionLevel) { $this->createGzipped = TRUE; // $compressionLevel can also be TRUE if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($compressionLevel)) { $this->gzipCompressionLevel = (int) $compressionLevel; } } $this->setInitialPaths(); }
/** * Constructor: * initializes locking, check input parameters and set variables accordingly. * * @param string $id ID to identify this lock in the system * @param string $method Define which locking method to use. Defaults to "flock". * @throws \InvalidArgumentException * @throws \Exception */ public function __construct($id, $method = null) { // Force ID to be string $id = (string) $id; if (!$method) { $method = $GLOBALS['TYPO3_CONF_VARS']['SYS']['extbase_hijax']['lockingMode']; } $this->method = $method; switch ($this->method) { case 'flock': $genTempPath = PATH_site . 'typo3temp' . DIRECTORY_SEPARATOR . 'extbase_hijax' . DIRECTORY_SEPARATOR; if (!is_dir($genTempPath)) { \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($genTempPath); } $path = PATH_site . 'typo3temp' . DIRECTORY_SEPARATOR . 'extbase_hijax' . DIRECTORY_SEPARATOR . 'locks' . DIRECTORY_SEPARATOR; if (!is_dir($path)) { \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($path); } $this->id = md5($id); $this->resource = $path . $this->id; break; case 'semaphore': $this->id = abs(crc32($id)); if (($this->resource = sem_get($this->id, 1)) === FALSE) { throw new \Exception('Unable to get semaphore', 1313828196); } break; case 'disable': break; default: throw new \InvalidArgumentException('No such method "' . $method . '"', 1294586097); } }
/** * Flush all processed files to be used for debugging mainly. * * @return void */ public function flushProcessedFilesCommand() { foreach ($this->getStorageRepository()->findAll() as $storage) { // This only works for local driver if ($storage->getDriverType() === 'Local') { $this->outputLine(); $this->outputLine(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); $this->outputLine('--------------------------------------------'); $this->outputLine(); #$storage->getProcessingFolder()->delete(TRUE); // will not work // Well... not really FAL friendly but straightforward for Local drivers. $processedDirectoryPath = PATH_site . $storage->getProcessingFolder()->getPublicUrl(); $fileIterator = new FilesystemIterator($processedDirectoryPath, FilesystemIterator::SKIP_DOTS); $numberOfProcessedFiles = iterator_count($fileIterator); GeneralUtility::rmdir($processedDirectoryPath, TRUE); GeneralUtility::mkdir($processedDirectoryPath); // recreate the directory. $message = sprintf('Done! Removed %s processed file(s).', $numberOfProcessedFiles); $this->outputLine($message); // Remove the record as well. $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('count(*) AS numberOfProcessedFiles', 'sys_file_processedfile', 'storage = ' . $storage->getUid()); $this->getDatabaseConnection()->exec_DELETEquery('sys_file_processedfile', 'storage = ' . $storage->getUid()); $message = sprintf('Done! Removed %s records from "sys_file_processedfile".', $record['numberOfProcessedFiles']); $this->outputLine($message); } } // Remove possible remaining "sys_file_processedfile" $query = 'TRUNCATE sys_file_processedfile'; $this->getDatabaseConnection()->sql_query($query); }
/** * Checks for several directories being writable. * * @return Status Indicates status of the file system */ protected function getFileSystemStatus() { $languageService = $this->getLanguageService(); $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_writable'); $message = ''; $severity = Status::OK; // Requirement level // -1 = not required, but if it exists may be writable or not // 0 = not required, if it exists the dir should be writable // 1 = required, don't has to be writable // 2 = required, has to be writable $checkWritable = array('typo3temp/' => 2, 'typo3temp/assets/' => 2, 'typo3temp/assets/compressed/' => 2, 'typo3temp/assets/images/' => 0, 'typo3temp/assets/css/' => 2, 'typo3temp/assets/js/' => 2, 'typo3temp/assets/_processed_/' => 0, 'typo3temp/var/' => 2, 'typo3temp/var/transient/' => 2, 'typo3temp/var/charset/' => 2, 'typo3temp/var/locks/' => 2, 'typo3conf/' => 2, 'typo3conf/ext/' => 0, 'typo3conf/l10n/' => 0, 'uploads/' => 2, 'uploads/pics/' => 0, 'uploads/media/' => 0, $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] => -1, $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . '_temp_/' => 0); if ($GLOBALS['TYPO3_CONF_VARS']['EXT']['allowGlobalInstall']) { $checkWritable[TYPO3_mainDir . 'ext/'] = -1; } foreach ($checkWritable as $relPath => $requirementLevel) { if (!@is_dir(PATH_site . $relPath)) { // If the directory is missing, try to create it GeneralUtility::mkdir(PATH_site . $relPath); } if (!@is_dir(PATH_site . $relPath)) { if ($requirementLevel > 0) { // directory is required $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_missingDirectory'); $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExistCouldNotCreate'), $relPath) . '<br />'; $severity = Status::ERROR; } else { $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExist'), $relPath); if ($requirementLevel == 0) { $message .= ' ' . $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldAlsoBeWritable'); } $message .= '<br />'; if ($severity < Status::WARNING) { $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_nonExistingDirectory'); $severity = Status::WARNING; } } } else { if (!is_writable(PATH_site . $relPath)) { switch ($requirementLevel) { case 0: $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldBeWritable'), PATH_site . $relPath) . '<br />'; if ($severity < Status::WARNING) { $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_recommendedWritableDirectory'); $severity = Status::WARNING; } break; case 2: $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_requiredWritableDirectory'); $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryMustBeWritable'), PATH_site . $relPath) . '<br />'; $severity = Status::ERROR; break; default: } } } } return GeneralUtility::makeInstance(Status::class, $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_fileSystem'), $value, $message, $severity); }
/** * Render Link to Captcha Image * * @return string */ public function render() { $string = $this->getStringForCaptcha(); if (!is_dir(dirname($this->getCaptchaImage())) && !GeneralUtility::mkdir(GeneralUtility::getFileAbsFileName(dirname($this->getCaptchaImage())))) { return 'Error: Folder ' . dirname($this->getCaptchaImage()) . '/ don\'t exists'; } return $this->createImage($string); }
/** * Creates a fake extension inside typo3temp/. No configuration is created, * just the folder * * @return string The extension key */ protected function createFakeExtension() { $extKey = strtolower(uniqid('testing')); $absExtPath = PATH_site . 'typo3temp/' . $extKey . '/'; $relPath = 'typo3temp/' . $extKey . '/'; \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($absExtPath); $this->fakedExtensions[$extKey] = array('siteRelPath' => $relPath); return $extKey; }
/** * @return string */ protected function getLanguageDirectory() { // Create language file dynamically $languageDirectory = PATH_site . 'typo3temp/vidi'; if (!is_dir($languageDirectory)) { GeneralUtility::mkdir($languageDirectory); } return $languageDirectory; }
/** * Checks for several directories being writable. * * @return tx_reports_reports_status_Status An tx_reports_reports_status_Status object indicating the status of the file system */ protected function getFileSystemStatus() { $value = $GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_writable'); $message = ''; $severity = \TYPO3\CMS\Reports\Status::OK; // Requirement level // -1 = not required, but if it exists may be writable or not // 0 = not required, if it exists the dir should be writable // 1 = required, don't has to be writable // 2 = required, has to be writable $checkWritable = array('typo3temp/' => 2, 'typo3temp/pics/' => 2, 'typo3temp/temp/' => 2, 'typo3temp/llxml/' => 2, 'typo3temp/cs/' => 2, 'typo3temp/GB/' => 2, 'typo3temp/locks/' => 2, 'typo3conf/' => 2, 'typo3conf/ext/' => 0, 'typo3conf/l10n/' => 0, TYPO3_mainDir . 'ext/' => -1, 'uploads/' => 2, 'uploads/pics/' => 0, 'uploads/media/' => 0, $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] => -1, $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . '_temp_/' => 0); foreach ($checkWritable as $relPath => $requirementLevel) { if (!@is_dir(PATH_site . $relPath)) { // If the directory is missing, try to create it \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir(PATH_site . $relPath); } if (!@is_dir(PATH_site . $relPath)) { if ($requirementLevel > 0) { // directory is required $value = $GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_missingDirectory'); $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_directoryDoesNotExistCouldNotCreate'), $relPath) . '<br />'; $severity = \TYPO3\CMS\Reports\Status::ERROR; } else { $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_directoryDoesNotExist'), $relPath); if ($requirementLevel == 0) { $message .= ' ' . $GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_directoryShouldAlsoBeWritable'); } $message .= '<br />'; if ($severity < \TYPO3\CMS\Reports\Status::WARNING) { $value = $GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_nonExistingDirectory'); $severity = \TYPO3\CMS\Reports\Status::WARNING; } } } else { if (!is_writable(PATH_site . $relPath)) { switch ($requirementLevel) { case 0: $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_directoryShouldBeWritable'), PATH_site . $relPath) . '<br />'; if ($severity < \TYPO3\CMS\Reports\Status::WARNING) { $value = $GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_recommendedWritableDirectory'); $severity = \TYPO3\CMS\Reports\Status::WARNING; } break; case 2: $value = $GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_requiredWritableDirectory'); $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_directoryMustBeWritable'), PATH_site . $relPath) . '<br />'; $severity = \TYPO3\CMS\Reports\Status::ERROR; break; } } } } return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->sL('LLL:EXT:install/report/locallang.xml:status_fileSystem'), $value, $message, $severity); }
/** * Creates a fake extension inside typo3temp/. No configuration is created, * just the folder * * @param bool $extkeyOnly * @return string The extension key */ protected function createFakeExtension($extkeyOnly = FALSE) { $extKey = strtolower(uniqid('testing')); $absExtPath = PATH_site . 'typo3conf/ext/' . $extKey . '/'; $relPath = 'typo3conf/ext/' . $extKey . '/'; $this->fakedExtensions[$extKey] = array('siteRelPath' => $relPath, 'siteAbsPath' => $absExtPath); if ($extkeyOnly === TRUE) { return $extKey; } \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($absExtPath); return $extKey; }
/** * Initialize some properties * * @param array $objects * @return void */ protected function initializeEnvironment(array $objects) { /** @var \Fab\Vidi\Domain\Model\Content $object */ $object = reset($objects); $this->temporaryDirectory = PATH_site . 'typo3temp/' . uniqid() . '/'; GeneralUtility::mkdir($this->temporaryDirectory); // Compute file name and path variable $this->exportFileNameAndPath = $this->temporaryDirectory . $object->getDataType() . '-' . date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']); // Compute file name and path variable for zip $zipFileName = $object->getDataType() . '-' . date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']) . '.zip'; $this->zipFileNameAndPath = $this->temporaryDirectory . $zipFileName; }
/** * Creates a fake extension inside typo3temp/. No configuration is created, * just the folder * * @param bool $extkeyOnly * @return string The extension key */ protected function createFakeExtension($extkeyOnly = false) { $extKey = strtolower($this->getUniqueId('testing')); $absExtPath = PATH_site . 'typo3temp/ext-' . $extKey . '/'; $relPath = 'typo3temp/ext-' . $extKey . '/'; $this->fakedExtensions[$extKey] = array('siteRelPath' => $relPath, 'siteAbsPath' => $absExtPath); if ($extkeyOnly === true) { return $extKey; } \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($absExtPath); $this->testFilesToDelete[] = PATH_site . 'typo3temp/ext-' . $extKey; return $extKey; }
/** * Cleanup sitemap directory */ protected function _cleanupDirectory() { if (empty($this->_sitemapDir)) { throw new \Exception('Basedir not set'); } $fullPath = PATH_site . '/' . $this->_sitemapDir; if (!is_dir($fullPath)) { \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($fullPath); } foreach (new \DirectoryIterator($fullPath) as $file) { if ($file->isFile() && !$file->isDot()) { $fileName = $file->getFilename(); unlink($fullPath . '/' . $fileName); } } }
public function setUp() { parent::setUp(); $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class); if (!class_exists('PhpParser\\Parser')) { throw new UnknownClassException('PhpParser not found!!'); } $this->fixturesPath = __DIR__ . '/Fixtures/'; $testTargetDir = 'testDir'; vfsStream::setup($testTargetDir); $dummyExtensionDir = vfsStream::url($testTargetDir) . '/'; $yamlParser = new \EBT\ExtensionBuilder\Utility\SpycYAMLParser(); $settings = $yamlParser->YAMLLoadString(file_get_contents($this->fixturesPath . 'Settings/settings1.yaml')); $this->extension = $this->getMock(\EBT\ExtensionBuilder\Domain\Model\Extension::class, array('getExtensionDir')); $this->extension->setVendorName('EBT'); $this->extension->setExtensionKey('dummy'); $this->extension->expects($this->any())->method('getExtensionDir')->will($this->returnValue($dummyExtensionDir)); if (is_dir($dummyExtensionDir)) { GeneralUtility::mkdir($dummyExtensionDir, TRUE); } $this->extension->setSettings($settings); // get instances to inject in Mocks $configurationManager = $this->objectManager->get(\EBT\ExtensionBuilder\Configuration\ConfigurationManager::class); $this->parserService = new \EBT\ExtensionBuilder\Service\Parser(new \PhpParser\Lexer()); $this->printerService = $this->objectManager->get(\EBT\ExtensionBuilder\Service\Printer::class); $localizationService = $this->objectManager->get(\EBT\ExtensionBuilder\Service\LocalizationService::class); $this->classBuilder = $this->objectManager->get(\EBT\ExtensionBuilder\Service\ClassBuilder::class); $this->classBuilder->initialize($this->extension); $this->roundTripService = $this->getAccessibleMock(\EBT\ExtensionBuilder\Service\RoundTrip::class, array('dummy')); $this->inject($this->roundTripService, 'configurationManager', $configurationManager); $this->inject($this->roundTripService, 'parserService', $this->parserService); $this->roundTripService->initialize($this->extension); $this->fileGenerator = $this->getAccessibleMock(\EBT\ExtensionBuilder\Service\FileGenerator::class, array('dummy')); $this->inject($this->fileGenerator, 'objectManager', $this->objectManager); $this->inject($this->fileGenerator, 'printerService', $this->printerService); $this->inject($this->fileGenerator, 'localizationService', $localizationService); $this->inject($this->fileGenerator, 'classBuilder', $this->classBuilder); $this->inject($this->fileGenerator, 'roundTripService', $this->roundTripService); $this->codeTemplateRootPath = PATH_typo3conf . 'ext/extension_builder/Resources/Private/CodeTemplates/Extbase/'; $this->modelClassTemplatePath = $this->codeTemplateRootPath . 'Classes/Domain/Model/Model.phpt'; $this->fileGenerator->setSettings(array('codeTemplateRootPath' => $this->codeTemplateRootPath, 'extConf' => array('enableRoundtrip' => '1'))); $this->fileGenerator->_set('codeTemplateRootPath', __DIR__ . '/../Resources/Private/CodeTemplates/Extbase/'); $this->fileGenerator->_set('enableRoundtrip', true); $this->fileGenerator->_set('extension', $this->extension); }
/** * Initializes a poll repository. * * @return PollRepository */ public static function initializePollRepository() { $settings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['doodle']); /** @var \Causal\DoodleClient\Client $doodleClient */ $doodleClient = GeneralUtility::makeInstance('Causal\\DoodleClient\\Client', $settings['username'], $settings['password']); $cookiePath = PATH_site . 'typo3temp/tx_doodle/'; if (!is_dir($cookiePath)) { GeneralUtility::mkdir($cookiePath); } if (!is_file($cookiePath . '/.htaccess')) { GeneralUtility::writeFile($cookiePath . '/.htaccess', 'Deny from all'); } $doodleClient->setCookiePath($cookiePath)->connect(); /** @var \Causal\Doodle\Domain\Repository\PollRepository $pollRepository */ $pollRepository = GeneralUtility::makeInstance('Causal\\Doodle\\Domain\\Repository\\PollRepository'); $pollRepository->setDoodleClient($doodleClient); return $pollRepository; }
/** * @param string $subject ID to identify this lock in the system * @throws LockCreateException if the lock could not be created */ public function __construct($subject) { // Tests if the directory for simple locks is available. // If not, the directory will be created. The lock path is usually // below typo3temp, typo3temp itself should exist already $path = PATH_site . self::FILE_LOCK_FOLDER; if (!is_dir($path)) { // Not using mkdir_deep on purpose here, if typo3temp itself // does not exist, this issue should be solved on a different // level of the application. if (!GeneralUtility::mkdir($path)) { throw new LockCreateException('Cannot create directory ' . $path, 1395140007); } } if (!is_writable($path)) { throw new LockCreateException('Cannot write to directory ' . $path, 1396278700); } $this->filePath = $path . 'simple_' . md5((string) $subject); }
protected function setUp() { parent::setUp(); $this->fixturesPath = __DIR__ . '/Fixtures/'; $testTargetDir = 'testDir'; vfsStream::setup($testTargetDir); $dummyExtensionDir = vfsStream::url($testTargetDir) . '/'; $settings = \EBT\ExtensionBuilder\Utility\SpycYAMLParser::YAMLLoadString(file_get_contents($this->fixturesPath . 'Settings/settings1.yaml')); $this->extension = $this->getMock(\EBT\ExtensionBuilder\Domain\Model\Extension::class, array('getExtensionDir')); $this->extension->setVendorName('EBT'); $this->extension->setExtensionKey('dummy'); $this->extension->expects(self::any())->method('getExtensionDir')->will(self::returnValue($dummyExtensionDir)); if (is_dir($dummyExtensionDir)) { GeneralUtility::mkdir($dummyExtensionDir, true); } $this->extension->setSettings($settings); $this->codeTemplateRootPath = PATH_typo3conf . 'ext/extension_builder/Resources/Private/CodeTemplates/Extbase/'; $this->modelClassTemplatePath = $this->codeTemplateRootPath . 'Classes/Domain/Model/Model.phpt'; }
/** * @param string $subject ID to identify this lock in the system * @throws LockCreateException */ public function __construct($subject) { $path = PATH_site . self::FILE_LOCK_FOLDER; if (!is_dir($path)) { // Not using mkdir_deep on purpose here, if typo3temp/var itself // does not exist, this issue should be solved on a different // level of the application. if (!GeneralUtility::mkdir($path)) { throw new LockCreateException('Cannot create directory ' . $path, 1460976250); } } if (!is_writable($path)) { throw new LockCreateException('Cannot write to directory ' . $path, 1460976320); } $this->filePath = $path . 'sem_' . md5((string) $subject); touch($this->filePath); $this->id = ftok($this->filePath, 'A'); if ($this->id === false) { throw new LockCreateException('Cannot create key for semaphore using path ' . $this->filePath, 1396278734); } }
/** * Set up sprite icon data and create cache entry calling the registered generator. * * Stuff the compiled $GLOBALS['TBE_STYLES']['spriteIconApi']['iconsAvailable'] * global into php code cache. * * @throws \RuntimeException * @return void */ protected static function buildSpriteDataAndCreateCacheEntry() { $handlerClass = $GLOBALS['TYPO3_CONF_VARS']['BE']['spriteIconGenerator_handler']; /** @var $handler \TYPO3\CMS\Backend\Sprite\SpriteIconGeneratorInterface */ $handler = GeneralUtility::makeInstance($handlerClass); // Throw exception if handler class does not implement required interface if (!$handler instanceof \TYPO3\CMS\Backend\Sprite\SpriteIconGeneratorInterface) { throw new \RuntimeException('Class ' . $handlerClass . ' in $TYPO3_CONF_VARS[BE][spriteIconGenerator_handler] ' . ' does not implement ' . \TYPO3\CMS\Backend\Sprite\SpriteIconGeneratorInterface::class, 1294586333); } // Create temp directory if missing if (!is_dir(PATH_site . self::$tempPath)) { GeneralUtility::mkdir(PATH_site . self::$tempPath); } // Generate CSS and TCA files, build icon set register $handler->generate(); // Get all icons registered from skins, merge with core icon list $availableSkinIcons = (array) $GLOBALS['TBE_STYLES']['spriteIconApi']['coreSpriteImageNames']; if (isset($GLOBALS['TBE_STYLES']['skins']) && is_array($GLOBALS['TBE_STYLES']['skins'])) { foreach ($GLOBALS['TBE_STYLES']['skins'] as $skinData) { $availableSkinIcons = array_merge($availableSkinIcons, (array) $skinData['availableSpriteIcons']); } } // Merge icon names provided by the skin, with // registered "complete sprites" and the handler class $iconNames = array_merge($availableSkinIcons, (array) $GLOBALS['TBE_STYLES']['spritemanager']['spriteIconsAvailable'], $handler->getAvailableIconNames()); $GLOBALS['TBE_STYLES']['spriteIconApi']['iconsAvailable'] = $iconNames; $cacheFileContent = '$GLOBALS[\'TBE_STYLES\'][\'spriteIconApi\'][\'iconsAvailable\'] = '; $cacheFileContent .= var_export($iconNames, TRUE) . ';'; /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */ GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('cache_core')->set(static::getCacheIdentifier(), $cacheFileContent); }
$original_images = array(); foreach ($product_original as $arr_key => $arr_val) { if (strpos($arr_key, 'products_image') !== false && !empty($arr_val)) { $original_file = $arr_val; $original_images[$arr_key] = $arr_val; $tmp_filename = explode('.', $original_file); $count_filename = count($tmp_filename); $ext = $tmp_filename[$count_filename - 1]; unset($tmp_filename[$count_filename - 1]); $new_filename = implode('', $tmp_filename) . '-CL' . $image_tstamp . '.' . $ext; // copy original product image $original_path = $this->DOCUMENT_ROOT . mslib_befe::getImagePath($original_file, 'products', 'original'); // $folder = mslib_befe::getImagePrefixFolder($new_filename); if (!is_dir($this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder)) { \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder); } $folder .= '/'; $target = $this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder . $new_filename; if (copy($original_path, $target)) { mslib_befe::resizeProductImage($target, $new_filename, $this->DOCUMENT_ROOT . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey), 1); } // $updateArray[$arr_key] = $new_filename; } } if ($update_product_images) { foreach ($update_product_images as $key => $value) { if ($original_images[$key] != $value) { $updateArray[$key] = $value; }
/** * Creates the icon file for the function getIcon() * * @param string $iconfile Original unprocessed Icon file, relative path to PATH_typo3 * @param string $mode Mode string, eg. "deleted" or "futuretiming" determining how the icon will look * @param int $user The number of the fe_group record uid if applicable * @param bool $protectSection Flag determines if the protected-section icon should be applied. * @param string $absFile Absolute path to file from which to create the icon. * @param string $iconFileName_stateTagged The filename that this icon should have had, basically [icon base name]_[flags].[extension] - used for part of temporary filename * @return string Filename relative to PATH_typo3 * @access private */ public static function makeIcon($iconfile, $mode, $user, $protectSection, $absFile, $iconFileName_stateTagged) { $iconFileName = GeneralUtility::shortMD5($iconfile . '|' . $mode . '|-' . $user . '|' . $protectSection) . '_' . $iconFileName_stateTagged . '.' . ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'] ? 'png' : 'gif'); $mainpath = '../typo3temp/Icons/' . $iconFileName; $path = PATH_site . 'typo3temp/Icons/' . $iconFileName; if (file_exists($path)) { // Returns if found in ../typo3temp/Icons/ return $mainpath; } else { // Makes icon: if (file_exists($absFile)) { if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) { // Create image pointer, if possible $im = self::imagecreatefrom($absFile); if ($im < 0) { return $iconfile; } // Converting to gray scale, dimming the icon: if ($mode == 'disabled' or $mode != 'futuretiming' && $mode != 'no_icon_found' && !(!$mode && $user)) { $totalImageColors = ImageColorsTotal($im); for ($c = 0; $c < $totalImageColors; $c++) { $cols = ImageColorsForIndex($im, $c); $newcol = round(($cols['red'] + $cols['green'] + $cols['blue']) / 3); $lighten = $mode == 'disabled' ? 2.5 : 2; $newcol = round(255 - (255 - $newcol) / $lighten); ImageColorSet($im, $c, $newcol, $newcol, $newcol); } } // Applying user icon, if there are access control on the item: if ($user) { if ($user < 100) { // Apply user number only if lower than 100 $black = ImageColorAllocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, $user > 10 ? 9 : 5, 8, $black); $white = ImageColorAllocate($im, 255, 255, 255); imagestring($im, 1, 1, 1, $user, $white); } $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_group.gif'); if ($ol_im < 0) { return $iconfile; } self::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im)); } // Applying overlay based on mode: if ($mode) { unset($ol_im); switch ($mode) { case 'deleted': $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_deleted.gif'); break; case 'futuretiming': $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_timing.gif'); break; case 'timing': $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_timing.gif'); break; case 'hiddentiming': $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_hidden_timing.gif'); break; case 'no_icon_found': $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_no_icon_found.gif'); break; case 'disabled': // is already greyed - nothing more $ol_im = 0; break; case 'hidden': default: $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_hidden.gif'); } if ($ol_im < 0) { return $iconfile; } if ($ol_im) { self::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im)); } } // Protect-section icon: if ($protectSection) { $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_sub5.gif'); if ($ol_im < 0) { return $iconfile; } self::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im)); } // Create the image as file, destroy GD image and return: $targetDirectory = dirname($path); if (!@is_dir($targetDirectory)) { GeneralUtility::mkdir($targetDirectory); } @self::imagemake($im, $path); GraphicalFunctions::gifCompress($path, 'IM'); ImageDestroy($im); return $mainpath; } else { return $iconfile; } } else { return $GLOBALS['BACK_PATH'] . 'typo3/sysext/backend/Resources/Public/Images/Overlay/default.gif'; } } }
/** * @test */ public function loadBaseTcaCreatesCacheFileWithContentOfAnExtensionsConfigurationTcaPhpFile() { $extensionName = $this->getUniqueId('test_baseTca_'); $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName); $packagePath = $packageManager->getPackage($extensionName)->getPackagePath(); GeneralUtility::mkdir($packagePath); GeneralUtility::mkdir($packagePath . 'Configuration/'); GeneralUtility::mkdir($packagePath . 'Configuration/TCA/'); $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($packageManager); ExtensionManagementUtility::setPackageManager($packageManager); $uniqueTableName = $this->getUniqueId('table_name_'); $uniqueStringInTableConfiguration = $this->getUniqueId('table_configuration_'); $tableConfiguration = '<?php return array(\'foo\' => \'' . $uniqueStringInTableConfiguration . '\'); ?>'; file_put_contents($packagePath . 'Configuration/TCA/' . $uniqueTableName . '.php', $tableConfiguration); $mockCache = $this->getMock(AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE); /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */ $mockCacheManager = $this->getMock(CacheManager::class, array('getCache')); $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache)); ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager); $mockCache->expects($this->once())->method('has')->will($this->returnValue(FALSE)); $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTableConfiguration), $this->anything()); ExtensionManagementUtility::loadBaseTca(TRUE); }
/** * Create a user directory if defined * * @param int $uid Id of the user record * @return void */ protected function action_createDir($uid) { $path = $this->action_getUserMainDir(); if ($path) { GeneralUtility::mkdir($path . $uid); GeneralUtility::mkdir($path . $uid . '/_temp_/'); } }
/** * Create a zip file from an extension * * @param array $extension * @return string Name and path of create zip file */ public function createZipFileFromExtension($extension) { $extensionPath = $this->getAbsoluteExtensionPath($extension); // Add trailing slash to the extension path, getAllFilesAndFoldersInPath explicitly requires that. $extensionPath = PathUtility::sanitizeTrailingSeparator($extensionPath); $version = $this->getExtensionVersion($extension); if (empty($version)) { $version = '0.0.0'; } if (!@is_dir(PATH_site . 'typo3temp/ExtensionManager/')) { GeneralUtility::mkdir(PATH_site . 'typo3temp/ExtensionManager/'); } $fileName = $this->getAbsolutePath('typo3temp/ExtensionManager/' . $extension . '_' . $version . '_' . date('YmdHi', $GLOBALS['EXEC_TIME']) . '.zip'); $zip = new \ZipArchive(); $zip->open($fileName, \ZipArchive::CREATE); $excludePattern = $GLOBALS['TYPO3_CONF_VARS']['EXT']['excludeForPackaging']; // Get all the files of the extension, but exclude the ones specified in the excludePattern $files = GeneralUtility::getAllFilesAndFoldersInPath(array(), $extensionPath, '', true, PHP_INT_MAX, $excludePattern); // Make paths relative to extension root directory. $files = GeneralUtility::removePrefixPathFromList($files, $extensionPath); // Remove the one empty path that is the extension dir itself. $files = array_filter($files); foreach ($files as $file) { $fullPath = $extensionPath . $file; // Distinguish between files and directories, as creation of the archive // fails on Windows when trying to add a directory with "addFile". if (is_dir($fullPath)) { $zip->addEmptyDir($file); } else { $zip->addFile($fullPath, $file); } } $zip->close(); return $fileName; }
/** * Add specified directory * * @param string $extDirPath * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException * @return void */ protected function addDirectory($extDirPath) { GeneralUtility::mkdir($extDirPath); if (!is_dir($extDirPath)) { throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(sprintf($GLOBALS['LANG']->getLL('clearMakeExtDir_could_not_create_dir'), $this->getRelativePath($extDirPath)), 1337280416); } }
/** * * @param string $fileName * @param string $registryNameReturnsFalse * @param string $registryNameReturnsTrue * @test * @dataProvider importT3DFileDoesNotImportFileIfAlreadyImportedDataProvider */ public function importT3DFileDoesNotImportFileIfAlreadyImported($fileName, $registryNameReturnsFalse, $registryNameReturnsTrue) { $extKey = $this->createFakeExtension(); $absPath = PATH_site . $this->fakedExtensions[$extKey]['siteRelPath']; \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($absPath . 'Initialisation'); file_put_contents($absPath . 'Initialisation/' . $fileName, 'DUMMY'); $registryMock = $this->getMock('\\TYPO3\\CMS\\Core\\Registry', array('get', 'set')); $registryMock->expects($this->any())->method('get')->will($this->returnValueMap(array(array('extensionDataImport', $this->fakedExtensions[$extKey]['siteRelPath'] . 'Initialisation/' . $registryNameReturnsFalse, NULL, FALSE), array('extensionDataImport', $this->fakedExtensions[$extKey]['siteRelPath'] . 'Initialisation/' . $registryNameReturnsTrue, NULL, TRUE)))); $installMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('getRegistry', 'getImportExportUtility'), array(), '', FALSE); $dependencyUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility'); $installMock->_set('dependencyUtility', $dependencyUtility); $installMock->_set('registry', $registryMock); $installMock->expects($this->never())->method('getImportExportUtility'); $installMock->_call('importT3DFile', $this->fakedExtensions[$extKey]['siteRelPath']); }
/** * Imports files from Initialisation/Files to fileadmin * via lowlevel copy directory method * * @param string $extensionSiteRelPath relative path to extension dir * @param string $extensionKey */ protected function importInitialFiles($extensionSiteRelPath, $extensionKey) { $importRelFolder = $extensionSiteRelPath . 'Initialisation/Files'; if (!$this->registry->get('extensionDataImport', $importRelFolder)) { $importFolder = PATH_site . $importRelFolder; if (file_exists($importFolder)) { $destinationRelPath = $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . $extensionKey; $destinationAbsolutePath = PATH_site . $destinationRelPath; if (!file_exists($destinationAbsolutePath) && \TYPO3\CMS\Core\Utility\GeneralUtility::isAllowedAbsPath($destinationAbsolutePath)) { \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($destinationAbsolutePath); } \TYPO3\CMS\Core\Utility\GeneralUtility::copyDirectory($importRelFolder, $destinationRelPath); $this->registry->set('extensionDataImport', $importRelFolder, 1); $this->emitAfterExtensionFileImportSignal($destinationAbsolutePath); } } }
/** * @test */ public function copyDirectoryCopiesFilesAndDirectoriesWithAbsolutePaths() { $sourceDirectory = 'typo3temp/' . $this->getUniqueId('test_') . '/'; $absoluteSourceDirectory = PATH_site . $sourceDirectory; $this->testFilesToDelete[] = $absoluteSourceDirectory; GeneralUtility::mkdir($absoluteSourceDirectory); $targetDirectory = 'typo3temp/' . $this->getUniqueId('test_') . '/'; $absoluteTargetDirectory = PATH_site . $targetDirectory; $this->testFilesToDelete[] = $absoluteTargetDirectory; GeneralUtility::mkdir($absoluteTargetDirectory); GeneralUtility::writeFileToTypo3tempDir($absoluteSourceDirectory . 'file', '42'); GeneralUtility::mkdir($absoluteSourceDirectory . 'foo'); GeneralUtility::writeFileToTypo3tempDir($absoluteSourceDirectory . 'foo/file', '42'); GeneralUtility::copyDirectory($absoluteSourceDirectory, $absoluteTargetDirectory); $this->assertFileExists($absoluteTargetDirectory . 'file'); $this->assertFileExists($absoluteTargetDirectory . 'foo/file'); }
/** * @test */ public function mkdirSetsGroupOwnershipOfCreatedDirectory() { if (!function_exists('posix_getegid')) { $this->markTestSkipped('Function posix_getegid() not available, mkdirSetsGroupOwnershipOfCreatedDirectory() tests skipped'); } if (posix_getegid() === -1) { $this->markTestSkipped('The mkdirSetsGroupOwnershipOfCreatedDirectory() is not available on Mac OS because posix_getegid() always returns -1 on Mac OS.'); } $swapGroup = $this->checkGroups(__FUNCTION__); if ($swapGroup !== FALSE) { $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = $swapGroup; $directory = uniqid('mkdirtest_'); Utility\GeneralUtility::mkdir(PATH_site . 'typo3temp/' . $directory); clearstatcache(); $resultDirectoryGroupInfo = posix_getgrgid(filegroup(PATH_site . 'typo3temp/' . $directory)); $resultDirectoryGroup = $resultDirectoryGroupInfo['name']; @rmdir(PATH_site . 'typo3temp/' . $directory); $this->assertEquals($resultDirectoryGroup, $swapGroup); } }
/** * Returns TRUE if directory exists and if it doesn't it will create directory and return TRUE if that succeeded. * * @param string $dirPrefix Directory to create. Having a trailing slash. Must be in fileadmin/. Relative to PATH_site * @return bool TRUE, if directory exists (was created) */ public function checkOrCreateDir($dirPrefix) { // Split dir path and remove first directory (which should be "fileadmin") $filePathParts = explode('/', $dirPrefix); $firstDir = array_shift($filePathParts); if ($firstDir === $this->fileadminFolderName && GeneralUtility::getFileAbsFileName($dirPrefix)) { $pathAcc = ''; foreach ($filePathParts as $dirname) { $pathAcc .= '/' . $dirname; if (strlen($dirname)) { if (!@is_dir(PATH_site . $this->fileadminFolderName . $pathAcc)) { if (!GeneralUtility::mkdir(PATH_site . $this->fileadminFolderName . $pathAcc)) { $this->error('ERROR: Directory could not be created....B'); return false; } } } elseif ($dirPrefix === $this->fileadminFolderName . $pathAcc) { return true; } else { $this->error('ERROR: Directory could not be created....A'); } } } return false; }
/** * * @return string */ protected function getTemporaryFolderName() { $temporaryPath = PATH_site . 'typo3temp/var/transient/'; do { $temporaryFolderName = $temporaryPath . 'export_temp_files_' . mt_rand(1, PHP_INT_MAX); } while (is_dir($temporaryFolderName)); GeneralUtility::mkdir($temporaryFolderName); return $temporaryFolderName; }