/** * Main function, returning the HTML content * * @return string HTML */ function main() { $content = ''; $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); $this->installTool = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility'); $databaseUpdateUtility = $this->objectManager->get('SJBR\\StaticInfoTables\\Utility\\DatabaseUpdateUtility'); // Clear the class cache $classCacheManager = $this->objectManager->get('SJBR\\StaticInfoTables\\Cache\\ClassCacheManager'); $classCacheManager->reBuild(); // Process the database updates of this base extension (we want to re-process these updates every time the update script is invoked) $extensionSitePath = ExtensionManagementUtility::extPath(GeneralUtility::camelCaseToLowerCaseUnderscored($this->extensionName)); $content .= '<p>' . nl2br(LocalizationUtility::translate('updateTables', $this->extensionName)) . '</p>'; $this->importStaticSqlFile($extensionSitePath); // Get the extensions which want to extend static_info_tables $loadedExtensions = array_unique(ExtensionManagementUtility::getLoadedExtensionListArray()); foreach ($loadedExtensions as $extensionKey) { $extensionInfoFile = ExtensionManagementUtility::extPath($extensionKey) . 'Configuration/DomainModelExtension/StaticInfoTables.txt'; if (file_exists($extensionInfoFile)) { // We need to reprocess the database structure update sql statements (ext_tables) $this->processDatabaseUpdates($extensionKey); // Now we process the static data updates (ext_tables_static+adt) // Note: The Install Tool Utility does not handle sql update statements $databaseUpdateUtility->doUpdate($extensionKey); $content .= '<p>' . nl2br(LocalizationUtility::translate('updateLanguageLabels', $this->extensionName)) . ' ' . $extensionKey . '</p>'; } } if (!$content) { // Nothing to do $content .= '<p>' . nl2br(LocalizationUtility::translate('nothingToDo', $this->extensionName)) . '</p>'; } // Notice for old language packs $content .= '<p>' . nl2br(LocalizationUtility::translate('update.oldLanguagePacks', $this->extensionName)) . '</p>'; return $content; }
/** * @param string $queueName * @return QueueInterface * @throws JobQueueException */ public function getQueue($queueName) { if (!isset($this->queues[$queueName])) { $settings = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['jobqueue']; $className = $this->extensionConfiguration->get('defaultQueue'); $options = []; if (isset($settings[$queueName])) { $className = isset($settings[$queueName]['className']) ? $settings[$queueName]['className'] : null; $options = isset($settings[$queueName]['options']) ? (array) $settings[$queueName]['options'] : []; } if (empty($options)) { $options = isset($settings[$className]['options']) ? (array) $settings[$className]['options'] : []; } if (!isset($options['timeout'])) { $defaultTimeout = (int) $this->extensionConfiguration->get('defaultTimeout'); $options['timeout'] = $defaultTimeout > 0 ? $defaultTimeout : null; } if (empty($className)) { throw new JobQueueException('No jobqueue class name configuration found.', 1448488276); } $classNameParts = ClassNamingUtility::explode($className); ExtensionManagementUtility::isLoaded(GeneralUtility::camelCaseToLowerCaseUnderscored($classNameParts['extensionName']), true); $queue = $this->objectManager->get($className, $queueName, $options); if (!$queue instanceof QueueInterface) { throw new JobQueueException("Queue '{$queueName}' is not a queue.", 1446318455); } $this->queues[$queueName] = $queue; } return $this->queues[$queueName]; }
/** * Get all the complex data for the loader. * This return value will be cached and stored in the database * There is no file monitoring for this cache * * @param Loader $autoLoader * @param int $type * * @return array */ public function prepareLoader(Loader $autoLoader, $type) { $languageOverride = []; if ($type === LoaderInterface::EXT_TABLES) { return $languageOverride; } $languageOverridePath = ExtensionManagementUtility::extPath($autoLoader->getExtensionKey()) . 'Resources/Private/Language/Overrides/'; if (!is_dir($languageOverridePath)) { return $languageOverride; } $files = GeneralUtility::getAllFilesAndFoldersInPath([], $languageOverridePath, 'xlf,php,xml', false, 99); foreach ($files as $file) { $file = str_replace($languageOverridePath, '', $file); $parts = GeneralUtility::trimExplode('/', $file, true); $extension = GeneralUtility::camelCaseToLowerCaseUnderscored($parts[0]); unset($parts[0]); $parts = array_values($parts); // language $language = 'default'; $fileParts = GeneralUtility::trimExplode('.', PathUtility::basename($file), true); if (strlen($fileParts[0]) === 2) { $language = $fileParts[0]; unset($fileParts[0]); $parts[sizeof($parts) - 1] = implode('.', $fileParts); } $languageOverride[] = ['language' => $language, 'original' => 'EXT:' . $extension . '/' . implode('/', $parts), 'override' => 'EXT:' . $autoLoader->getExtensionKey() . '/Resources/Private/Language/Overrides/' . $file]; } return $languageOverride; }
/** * This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers * to adjust functionality. * * @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for * flexiblity in overriding this method. * @return bool */ protected static function evaluateCondition($arguments = null) { $extensionName = $arguments['extensionName']; $extensionKey = GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName); $isLoaded = ExtensionManagementUtility::isLoaded($extensionKey); return true === $isLoaded; }
/** * Find the translation subkey based on the class name of the exception */ protected function findTranslationSubKeyByExceptionClassName() { preg_match("/_([^_]*)Exception\$/", get_class($this), $subKey); if (!empty($subKey[1])) { $this->subKey = \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($subKey[1]); } }
/** * Resolves path e.g. EXT:media/Resources/Public/foo.png or ../../foo and returns an absolute path to the given resource. * * @param string $resource * @return string */ public static function resolvePath($resource) { $resource = self::canonicalPath($resource); if (!is_file(PATH_site . $resource)) { $resource = 'EXT:' . GeneralUtility::camelCaseToLowerCaseUnderscored(self::$extensionName) . '/Resources/Public/' . $resource; } return GeneralUtility::getFileAbsFileName($resource); }
/** * * @param string $word * * @return bool */ public static function isReservedTYPO3Word($word) { if (in_array(\TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($word), self::$reservedTYPO3ColumnNames)) { return true; } else { return false; } }
/** * @return string */ protected function getExtensionKeyFromSettings() { $extensionKey = $this->configuration['extensionKey']; if (FALSE !== strpos($extensionKey, '.')) { $extensionKey = array_pop(explode('.', $extensionKey)); } return GeneralUtility::camelCaseToLowerCaseUnderscored($extensionKey); }
/** * Get the extension key by the given model name * * @param string|object $modelClassName * * @return string */ public static function getExtensionKeyByModel($modelClassName) { if (is_object($modelClassName)) { $modelClassName = get_class($modelClassName); } $matches = self::explodeObjectModelName($modelClassName); return GeneralUtility::camelCaseToLowerCaseUnderscored($matches['extensionName']); }
/** * CacheUtility constructor. */ public function __construct() { parent::__construct(); $this->_extKey = GeneralUtility::camelCaseToLowerCaseUnderscored($this->extensionName); $this->_request = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Mvc\\Request'); $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); $this->_configurationManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager'); }
/** * Render * * Renders a valid CSS class/id name * * @return string */ public function render() { $name = $this->renderChildren(); $name = trim($name); $name = \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($name); $name = strtolower($name); $name = str_replace(array(' ', '_'), '-', $name); return $name; }
/** * @param $params * @param $ref */ public function flexformSelection(&$params, &$ref) { $providers = self::getProviders(); $params['items'] = array(); foreach ($providers as $provider) { $extensionName = self::getExtensionNameByClassName($provider); $params['items'][] = array($provider, $provider, 'EXT:' . GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName) . '/ext_icon.gif'); } }
/** * Initializes the controller before invoking an action method. * * Override this method to solve tasks which all actions have in * common. * * @return void */ protected function initializeAction() { parent::initializeAction(); $this->dateTime = new \DateTime('now', new \DateTimeZone('Europe/Berlin')); $this->extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][GeneralUtility::camelCaseToLowerCaseUnderscored($this->extensionName)]); $this->controllerSettings = $this->settings['controllers'][$this->request->getControllerName()]; $this->actionSettings = $this->controllerSettings['actions'][$this->request->getControllerActionName()]; $this->currentPageUid = $GLOBALS['TSFE']->id; }
/** * Render method * * @return string */ public function render() { $extensionName = $this->arguments['extensionName']; $extensionKey = GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName); $isLoaded = ExtensionManagementUtility::isLoaded($extensionKey); if (TRUE === $isLoaded) { return $this->renderThenChild(); } else { return $this->renderElseChild(); } }
/** * @param string $qualifiedExtensionName * @return array */ public static function getVendorNameAndExtensionKey($qualifiedExtensionName) { if (TRUE === self::hasVendorName($qualifiedExtensionName)) { list($vendorName, $extensionKey) = GeneralUtility::trimExplode('.', $qualifiedExtensionName); } else { $vendorName = NULL; $extensionKey = $qualifiedExtensionName; } $extensionKey = GeneralUtility::camelCaseToLowerCaseUnderscored($extensionKey); return array($vendorName, $extensionKey); }
/** * Get class names within namespace * * @param string $namespace * @return array */ protected function getClassNamesInNamespace($namespace) { $namespaceParts = explode('\\', $namespace); if ($namespaceParts[count($namespaceParts) - 1] == '') { } $classFilePathAndName = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(\TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($namespaceParts[2])) . 'Classes/'; $classFilePathAndName .= implode(array_slice($namespaceParts, 3, -1), '/') . '/'; $classNames = array(); $this->recursiveClassNameSearch($namespace, $classFilePathAndName, $classNames); sort($classNames); return $classNames; }
/** * Get the absolute table icon for the given model name * * @param string $modelClassName * @param boolean $extSyntax Get the EXT: Syntax instead of a rel Path * * @return string */ public static function getByModelName($modelClassName, $extSyntax = false) { $modelInformation = ClassNamingUtility::explodeObjectModelName($modelClassName); $extensionKey = GeneralUtility::camelCaseToLowerCaseUnderscored($modelInformation['extensionName']); $modelName = str_replace('\\', '/', $modelInformation['modelName']); $tableIconPath = ExtensionManagementUtility::extPath($extensionKey) . 'Resources/Public/Icons/' . $modelName . '.'; $fileExtension = self::getIconFileExtension($tableIconPath); if ($fileExtension) { return self::returnRelativeIconPath($extensionKey, 'Resources/Public/Icons/' . $modelName . '.' . $fileExtension, $extSyntax); } return self::getByExtensionKey($extensionKey, $extSyntax); }
/** * @return array */ public function getExtensionKeyAndActionFromUrl() { if (NULL !== $this->extensionKeyAndAction) { return $this->extensionKeyAndAction; } list($module, $identifier) = explode('_', GeneralUtility::_GET('M')); list($signature) = explode('_', $identifier); $signature = GeneralUtility::camelCaseToLowerCaseUnderscored($signature); list($parent, $extensionKeyAndAction) = explode('_tx_', $signature); unset($module, $parent); $this->extensionKeyAndAction = explode('_', $extensionKeyAndAction); return $this->extensionKeyAndAction; }
/** * Fetch the files given an object assuming * * @param $propertyName * @param Content $object * @return File[] */ protected function findByFileReference($propertyName, Content $object) { $fileField = 'uid_local'; $tableName = 'sys_file_reference'; $clause = sprintf('tablenames = "%s" %s AND fieldname = "%s" AND uid_foreign = %s', $object->getDataType(), $this->getWhereClauseForEnabledFields($tableName), GeneralUtility::camelCaseToLowerCaseUnderscored($propertyName), $object->getUid()); $rows = $this->getDatabaseConnection()->exec_SELECTgetRows($fileField, $tableName, $clause); // Build array of Files $files = array(); foreach ($rows as $row) { $files[] = ResourceFactory::getInstance()->getFileObject($row[$fileField]); } return $files; }
/** * Find table and model information for the given extension key * * @param string $extensionKey * * @return array */ protected function findTableAndModelInformationForExtension($extensionKey) { $information = []; $register = SmartObjectRegister::getRegister(); foreach ($register as $class) { $parts = ClassNamingUtility::explodeObjectModelName($class); if (GeneralUtility::camelCaseToLowerCaseUnderscored($parts['extensionName']) === $extensionKey) { if (ModelUtility::getTableNameByModelReflectionAnnotation($class) === '') { $information[] = ['table' => ModelUtility::getTableNameByModelName($class), 'class' => $class]; } } } return $information; }
/** * Find table and model information for the given extension key * * @param string $extensionKey * * @return array */ protected function findTableAndModelInformationForExtension($extensionKey) { $information = []; $register = SmartObjectRegister::getRegister(); foreach ($register as $class) { $parts = ClassNamingUtility::explodeObjectModelName($class); if (GeneralUtility::camelCaseToLowerCaseUnderscored($parts['extensionName']) === $extensionKey) { if (ModelUtility::getTableNameByModelReflectionAnnotation($class) === '') { $modelInformation = SmartObjectInformationService::getInstance()->getCustomModelFieldTca($class); $information[] = ['table' => ModelUtility::getTableNameByModelName($class), 'properties' => array_keys($modelInformation)]; } } } return $information; }
/** * Fill the model based on the database record * * @param array $record The database record */ public function fill(array $record) { $reflection = GeneralUtility::makeInstance(Reflection::class, get_class($this)); $properties = $reflection->getProperties(\ReflectionProperty::IS_PROTECTED); foreach ($properties as $property) { $databaseField = GeneralUtility::camelCaseToLowerCaseUnderscored($property->name); $type = $reflection->getPropertyTag($property, 'var'); if (substr($type, -2) === '[]') { $type = 'array'; } if (isset($record[$databaseField]) && $type !== 'array') { settype($record[$databaseField], $type); $this->{$property->name} = $record[$databaseField]; } } }
/** * @param string $name * @param string $extensionKey * @return string */ public function render($name, $extensionKey = NULL) { if (NULL === $extensionKey) { $extensionName = $this->controllerContext->getRequest()->getControllerExtensionName(); $extensionKey = GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName); } if (FALSE === array_key_exists($extensionKey, $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'])) { return NULL; } $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey]); if (TRUE === array_key_exists($name, $extConf)) { return $extConf[$name]; } else { return NULL; } }
/** * Render the URI to the resource. The filename is used from child content. * * @param string $path The path and filename of the resource (relative to Public resource directory of the extension). * @param string $extensionName Target extension name. If not set, the current extension name will be used * @param boolean $absolute If set, an absolute URI is rendered * @return string The URI to the resource * @api */ public function render($path, $extensionName = NULL, $absolute = FALSE) { if ($extensionName === NULL) { $extensionName = $this->controllerContext->getRequest()->getControllerExtensionName(); } $uri = 'EXT:' . \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName) . '/Resources/Public/' . $path; $uri = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($uri); $uri = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($uri); if (TYPO3_MODE === 'BE' && $absolute === FALSE && $uri !== FALSE) { $uri = '../' . $uri; } if ($absolute === TRUE) { $uri = $this->controllerContext->getRequest()->getBaseURI() . $uri; } return $uri; }
/** * Constructor * * @param string $controllerClassName Class name of the controller providing the command * @param string $controllerCommandName Command name, i.e. the method name of the command, without the "Command" suffix * @throws \InvalidArgumentException */ public function __construct($controllerClassName, $controllerCommandName) { $this->controllerClassName = $controllerClassName; $this->controllerCommandName = $controllerCommandName; $delimiter = strpos($controllerClassName, '\\') !== FALSE ? '\\' : '_'; $classNameParts = explode($delimiter, $controllerClassName); if (isset($classNameParts[0]) && $classNameParts[0] === 'TYPO3' && isset($classNameParts[1]) && $classNameParts[1] === 'CMS') { $classNameParts[0] .= '\\' . $classNameParts[1]; unset($classNameParts[1]); $classNameParts = array_values($classNameParts); } if (count($classNameParts) !== 4 || strpos($classNameParts[3], 'CommandController') === FALSE) { throw new \InvalidArgumentException('Invalid controller class name "' . $controllerClassName . '". Class name must end with "CommandController".', 1305100019); } $this->extensionName = $classNameParts[1]; $extensionKey = \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($this->extensionName); $this->commandIdentifier = strtolower($extensionKey . ':' . substr($classNameParts[3], 0, -17) . ':' . $controllerCommandName); }
/** * @param array $arguments * @param callable $renderChildrenClosure * @param RenderingContextInterface $renderingContext * @return string */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { $path = $arguments['path']; $extensionName = $arguments['extensionName']; $absolute = $arguments['absolute']; if ($extensionName === NULL) { $extensionName = $renderingContext->getControllerContext()->getRequest()->getControllerExtensionName(); } $uri = 'EXT:' . GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName) . '/Resources/Public/' . $path; $uri = GeneralUtility::getFileAbsFileName($uri); $uri = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($uri); if (TYPO3_MODE === 'BE' && $absolute === FALSE && $uri !== FALSE) { $uri = '../' . $uri; } if ($absolute === TRUE) { $uri = $renderingContext->getControllerContext()->getRequest()->getBaseUri() . $uri; } return $uri; }
/** * Get all the complex data for the loader. * This return value will be cached and stored in the database * There is no file monitoring for this cache * * @param Loader $loader * @param int $type * * @return array */ public function prepareLoader(Loader $loader, $type) { $flexForms = []; $flexFormPath = ExtensionManagementUtility::extPath($loader->getExtensionKey()) . 'Configuration/FlexForms/'; // Plugins $extensionName = GeneralUtility::underscoredToUpperCamelCase($loader->getExtensionKey()); $flexFormsFiles = FileUtility::getBaseFilesInDir($flexFormPath, 'xml'); foreach ($flexFormsFiles as $fileKey) { $pluginSignature = strtolower($extensionName . '_' . $fileKey); $flexForms[] = ['pluginSignature' => $pluginSignature, 'path' => 'FILE:EXT:' . $loader->getExtensionKey() . '/Configuration/FlexForms/' . $fileKey . '.xml']; } // Content $flexFormsFiles = FileUtility::getBaseFilesInDir($flexFormPath . 'Content/', 'xml'); foreach ($flexFormsFiles as $fileKey) { $contentSignature = strtolower($loader->getExtensionKey() . '_' . GeneralUtility::camelCaseToLowerCaseUnderscored($fileKey)); $flexForms[] = ['contentSignature' => $contentSignature, 'path' => 'FILE:EXT:' . $loader->getExtensionKey() . '/Configuration/FlexForms/Content/' . $fileKey . '.xml']; } return $flexForms; }
/** * @param array $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext * @return mixed */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { $extensionKey = $arguments['extensionKey']; $path = $arguments['path']; if (null === $extensionKey) { $extensionName = $renderingContext->getControllerContext()->getRequest()->getControllerExtensionName(); $extensionKey = GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName); } if (!array_key_exists($extensionKey, $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'])) { return null; } elseif (!array_key_exists($extensionKey, static::$configurations)) { $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey]); static::$configurations[$extensionKey] = GeneralUtility::removeDotsFromTS($extConf); } if (!$path) { return static::$configurations[$extensionKey]; } return ObjectAccess::getPropertyPath(static::$configurations[$extensionKey], $path); }
/** * @param string $string * @param string $case * @return string */ public function render($string = null, $case = null) { if (null === $string) { $string = $this->renderChildren(); } if ('BE' === TYPO3_MODE) { $tsfeBackup = FrontendSimulationUtility::simulateFrontendEnvironment(); } $charset = $GLOBALS['TSFE']->renderCharset; switch ($case) { case self::CASE_LOWER: $string = $GLOBALS['TSFE']->csConvObj->conv_case($charset, $string, 'toLower'); break; case self::CASE_UPPER: $string = $GLOBALS['TSFE']->csConvObj->conv_case($charset, $string, 'toUpper'); break; case self::CASE_UCWORDS: $string = ucwords($string); break; case self::CASE_UCFIRST: $string = $GLOBALS['TSFE']->csConvObj->convCaseFirst($charset, $string, 'toUpper'); break; case self::CASE_LCFIRST: $string = $GLOBALS['TSFE']->csConvObj->convCaseFirst($charset, $string, 'toLower'); break; case self::CASE_CAMELCASE: $string = GeneralUtility::underscoredToUpperCamelCase($string); break; case self::CASE_LOWERCAMELCASE: $string = GeneralUtility::underscoredToLowerCamelCase($string); break; case self::CASE_UNDERSCORED: $string = GeneralUtility::camelCaseToLowerCaseUnderscored($string); break; default: break; } if ('BE' === TYPO3_MODE) { FrontendSimulationUtility::resetFrontendEnvironment($tsfeBackup); } return $string; }
/** * @param string $path * @param string $extensionKey * @param string $name (deprecated, just use $path instead) * @return string * @throws Exception */ public function render($path = NULL, $extensionKey = NULL, $name = NULL) { if (NULL !== $path) { $pathToExtract = $path; } elseif (NULL !== $name) { $pathToExtract = $name; GeneralUtility::deprecationLog('v:variable.extensionConfiguration was called with parameter "name" which is deprecated. Use "path" instead.'); } else { throw new Exception('v:variable.extensionConfiguration requires the "path" attribute to be filled.', 1446998437); } if (NULL === $extensionKey) { $extensionName = $this->controllerContext->getRequest()->getControllerExtensionName(); $extensionKey = GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName); } if (FALSE === array_key_exists($extensionKey, $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'])) { return NULL; } $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey]); return $this->extractFromArrayByPath($extConf, $path); }