[TASK] Remove superfluous parenthesis in sysexts
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Utility / ExtensionUtility.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Utility;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Utilities to manage plugins and modules of an extension. Also useful to auto-generate the autoloader registry
28 * file ext_autoload.php.
29 *
30 * @package Extbase
31 * @subpackage Utility
32 */
33 class ExtensionUtility {
34
35 const PLUGIN_TYPE_PLUGIN = 'list_type';
36 const PLUGIN_TYPE_CONTENT_ELEMENT = 'CType';
37 /**
38 * @var \TYPO3\CMS\Extbase\Service\ExtensionService
39 */
40 static protected $extensionService = NULL;
41
42 /**
43 * @return string
44 */
45 static protected function getExtensionService() {
46 if (self::$extensionService === NULL) {
47 require_once \TYPO3\CMS\Core\Extension\ExtensionManager::extPath('extbase', 'Classes/Service/ExtensionService.php');
48 $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
49 self::$extensionService = $objectManager->get('TYPO3\\CMS\\Extbase\\Service\\ExtensionService');
50 }
51 return self::$extensionService;
52 }
53
54 /**
55 * Add auto-generated TypoScript to configure the Extbase Dispatcher.
56 *
57 * When adding a frontend plugin you will have to add both an entry to the TCA definition
58 * of tt_content table AND to the TypoScript template which must initiate the rendering.
59 * Since the static template with uid 43 is the "content.default" and practically always
60 * used for rendering the content elements it's very useful to have this function automatically
61 * adding the necessary TypoScript for calling the appropriate controller and action of your plugin.
62 * It will also work for the extension "css_styled_content"
63 * FOR USE IN ext_localconf.php FILES
64 * Usage: 2
65 *
66 * @param string $extensionName The extension name (in UpperCamelCase) or the extension key (in lower_underscore)
67 * @param string $pluginName must be a unique id for your plugin in UpperCamelCase (the string length of the extension key added to the length of the plugin name should be less than 32!)
68 * @param array $controllerActions is an array of allowed combinations of controller and action stored in an array (controller name as key and a comma separated list of action names as value, the first controller and its first action is chosen as default)
69 * @param array $nonCacheableControllerActions is an optional array of controller name and action names which should not be cached (array as defined in $controllerActions)
70 * @param string $pluginType either Tx_Extbase_Utility_Extension::TYPE_PLUGIN (default) or Tx_Extbase_Utility_Extension::TYPE_CONTENT_ELEMENT
71 * @throws \InvalidArgumentException
72 * @return void
73 */
74 static public function configurePlugin($extensionName, $pluginName, array $controllerActions, array $nonCacheableControllerActions = array(), $pluginType = self::PLUGIN_TYPE_PLUGIN) {
75 if (empty($pluginName)) {
76 throw new \InvalidArgumentException('The plugin name must not be empty', 1239891987);
77 }
78 if (empty($extensionName)) {
79 throw new \InvalidArgumentException('The extension name was invalid (must not be empty and must match /[A-Za-z][_A-Za-z0-9]/)', 1239891989);
80 }
81 // Check if vendor name is prepended to extensionName in the format {vendorName}.{extensionName}
82 $vendorName = NULL;
83 if (FALSE !== $delimiterPosition = strrpos($extensionName, '.')) {
84 $vendorName = str_replace('.', '\\', substr($extensionName, 0, $delimiterPosition));
85 $extensionName = substr($extensionName, $delimiterPosition + 1);
86 }
87 $extensionName = str_replace(' ', '', ucwords(str_replace('_', ' ', $extensionName)));
88 $pluginSignature = strtolower($extensionName) . '_' . strtolower($pluginName);
89 if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName])) {
90 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName] = array();
91 }
92 foreach ($controllerActions as $controllerName => $actionsList) {
93 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'][$controllerName] = array('actions' => \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $actionsList));
94 if (!empty($nonCacheableControllerActions[$controllerName])) {
95 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'][$controllerName]['nonCacheableActions'] = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $nonCacheableControllerActions[$controllerName]);
96 }
97 }
98 $pluginTemplate = 'plugin.tx_' . strtolower($extensionName) . ' {
99 settings {
100 }
101 persistence {
102 storagePid =
103 classes {
104 }
105 }
106 view {
107 templateRootPath =
108 layoutRootPath =
109 partialRootPath =
110 # with defaultPid you can specify the default page uid of this plugin. If you set this to the string "auto" the target page will be determined automatically. Defaults to an empty string that expects the target page to be the current page.
111 defaultPid =
112 }
113 }';
114 \TYPO3\CMS\Core\Extension\ExtensionManager::addTypoScript($extensionName, 'setup', '
115 # Setting ' . $extensionName . ' plugin TypoScript
116 ' . $pluginTemplate);
117 switch ($pluginType) {
118 case self::PLUGIN_TYPE_PLUGIN:
119 $pluginContent = trim('
120 tt_content.list.20.' . $pluginSignature . ' = USER
121 tt_content.list.20.' . $pluginSignature . ' {
122 userFunc = TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run
123 extensionName = ' . $extensionName . '
124 pluginName = ' . $pluginName . (NULL !== $vendorName ? ("\n\t" . 'vendorName = ' . $vendorName) : '') . '
125 }');
126 break;
127 case self::PLUGIN_TYPE_CONTENT_ELEMENT:
128 $pluginContent = trim('
129 tt_content.' . $pluginSignature . ' = COA
130 tt_content.' . $pluginSignature . ' {
131 10 = < lib.stdheader
132 20 = USER
133 20 {
134 userFunc = TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run
135 extensionName = ' . $extensionName . '
136 pluginName = ' . $pluginName . (NULL !== $vendorName ? ("\n\t\t" . 'vendorName = ' . $vendorName) : '') . '
137 }
138 }');
139 break;
140 default:
141 throw new \InvalidArgumentException('The pluginType "' . $pluginType . '" is not suported', 1289858856);
142 }
143 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['pluginType'] = $pluginType;
144 \TYPO3\CMS\Core\Extension\ExtensionManager::addTypoScript($extensionName, 'setup', '
145 # Setting ' . $extensionName . ' plugin TypoScript
146 ' . $pluginContent, 43);
147 }
148
149 /**
150 * Register an Extbase PlugIn into backend's list of plugins
151 * FOR USE IN ext_tables.php FILES
152 *
153 * @param string $extensionName The extension name (in UpperCamelCase) or the extension key (in lower_underscore)
154 * @param string $pluginName must be a unique id for your plugin in UpperCamelCase (the string length of the extension key added to the length of the plugin name should be less than 32!)
155 * @param string $pluginTitle is a speaking title of the plugin that will be displayed in the drop down menu in the backend
156 * @param string $pluginIconPathAndFilename is a path to an icon file (relative to TYPO3_mainDir), that will be displayed in the drop down menu in the backend (optional)
157 * @throws \InvalidArgumentException
158 * @return void
159 */
160 static public function registerPlugin($extensionName, $pluginName, $pluginTitle, $pluginIconPathAndFilename = NULL) {
161 if (empty($pluginName)) {
162 throw new \InvalidArgumentException('The plugin name must not be empty', 1239891987);
163 }
164 if (empty($extensionName)) {
165 throw new \InvalidArgumentException('The extension name was invalid (must not be empty and must match /[A-Za-z][_A-Za-z0-9]/)', 1239891989);
166 }
167 $extensionName = str_replace(' ', '', ucwords(str_replace('_', ' ', $extensionName)));
168 $pluginSignature = strtolower($extensionName) . '_' . strtolower($pluginName);
169 \TYPO3\CMS\Core\Extension\ExtensionManager::addPlugin(array($pluginTitle, $pluginSignature, $pluginIconPathAndFilename), $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['pluginType']);
170 }
171
172 /**
173 * This method is called from t3lib_loadModules::checkMod and it replaces old conf.php.
174 *
175 * @param string $moduleSignature The module name
176 * @param string $modulePath Absolute path to module (not used by Extbase currently)
177 * @return array Configuration of the module
178 */
179 static public function configureModule($moduleSignature, $modulePath) {
180 $moduleConfiguration = $GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature];
181 $iconPathAndFilename = $moduleConfiguration['icon'];
182 if (substr($iconPathAndFilename, 0, 4) === 'EXT:') {
183 list($extensionKey, $relativePath) = explode('/', substr($iconPathAndFilename, 4), 2);
184 $iconPathAndFilename = \TYPO3\CMS\Core\Extension\ExtensionManager::extPath($extensionKey) . $relativePath;
185 }
186 // TODO: skin support
187 $moduleLabels = array(
188 'tabs_images' => array(
189 'tab' => $iconPathAndFilename
190 ),
191 'labels' => array(
192 'tablabel' => $GLOBALS['LANG']->sL($moduleConfiguration['labels'] . ':mlang_labels_tablabel'),
193 'tabdescr' => $GLOBALS['LANG']->sL($moduleConfiguration['labels'] . ':mlang_labels_tabdescr')
194 ),
195 'tabs' => array(
196 'tab' => $GLOBALS['LANG']->sL($moduleConfiguration['labels'] . ':mlang_tabs_tab')
197 )
198 );
199 $GLOBALS['LANG']->addModuleLabels($moduleLabels, $moduleSignature . '_');
200 return $moduleConfiguration;
201 }
202
203 /**
204 * Registers an Extbase module (main or sub) to the backend interface.
205 * FOR USE IN ext_tables.php FILES
206 *
207 * @param string $extensionName The extension name (in UpperCamelCase) or the extension key (in lower_underscore)
208 * @param string $mainModuleName The main module key, $sub is the submodule key. So $main would be an index in the $TBE_MODULES array and $sub could be an element in the lists there. If $main is not set a blank $extensionName module is created
209 * @param string $subModuleName The submodule key. If $sub is not set a blank $main module is created
210 * @param string $position This can be used to set the position of the $sub module within the list of existing submodules for the main module. $position has this syntax: [cmd]:[submodule-key]. cmd can be "after", "before" or "top" (or blank which is default). If "after"/"before" then submodule will be inserted after/before the existing submodule with [submodule-key] if found. If not found, the bottom of list. If "top" the module is inserted in the top of the submodule list.
211 * @param array $controllerActions is an array of allowed combinations of controller and action stored in an array (controller name as key and a comma separated list of action names as value, the first controller and its first action is chosen as default)
212 * @param array $moduleConfiguration The configuration options of the module (icon, locallang.xml file)
213 * @throws \InvalidArgumentException
214 * @return void
215 */
216 static public function registerModule($extensionName, $mainModuleName = '', $subModuleName = '', $position = '', array $controllerActions, array $moduleConfiguration = array()) {
217 if (empty($extensionName)) {
218 throw new \InvalidArgumentException('The extension name must not be empty', 1239891989);
219 }
220 // Check if vendor name is prepended to extensionName in the format {vendorName}.{extensionName}
221 $vendorName = NULL;
222 if (FALSE !== $delimiterPosition = strrpos($extensionName, '.')) {
223 $vendorName = str_replace('.', '\\', substr($extensionName, 0, $delimiterPosition));
224 $extensionName = substr($extensionName, $delimiterPosition + 1);
225 }
226 $extensionKey = \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName);
227 $extensionName = str_replace(' ', '', ucwords(str_replace('_', ' ', $extensionName)));
228 $defaultModuleConfiguration = array(
229 'access' => 'admin',
230 'icon' => 'EXT:extbase/ext_icon.gif',
231 'labels' => '',
232 'extRelPath' => \TYPO3\CMS\Core\Extension\ExtensionManager::extRelPath($extensionKey) . 'Classes/'
233 );
234 if (strlen($mainModuleName) > 0 && !array_key_exists($mainModuleName, $GLOBALS['TBE_MODULES'])) {
235 $mainModuleName = $extensionName . \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($mainModuleName);
236 } else {
237 $mainModuleName = strlen($mainModuleName) > 0 ? $mainModuleName : 'web';
238 }
239 // add mandatory parameter to use new pagetree
240 if ($mainModuleName === 'web') {
241 $defaultModuleConfiguration['navigationComponentId'] = 'typo3-pagetree';
242 }
243 $moduleConfiguration = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($defaultModuleConfiguration, $moduleConfiguration);
244 $moduleSignature = $mainModuleName;
245 if (strlen($subModuleName) > 0) {
246 $subModuleName = $extensionName . \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($subModuleName);
247 $moduleSignature .= '_' . $subModuleName;
248 }
249 $moduleConfiguration['name'] = $moduleSignature;
250 $moduleConfiguration['script'] = 'mod.php?M=' . rawurlencode($moduleSignature);
251 if (NULL !== $vendorName) {
252 $moduleConfiguration['vendorName'] = $vendorName;
253 }
254 $moduleConfiguration['extensionName'] = $extensionName;
255 $moduleConfiguration['configureModuleFunction'] = array('TYPO3\\CMS\\Extbase\\Utility\\ExtensionUtility', 'configureModule');
256 $GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature] = $moduleConfiguration;
257 if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['modules'][$moduleSignature])) {
258 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['modules'][$moduleSignature] = array();
259 }
260 foreach ($controllerActions as $controllerName => $actions) {
261 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['modules'][$moduleSignature]['controllers'][$controllerName] = array(
262 'actions' => \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $actions)
263 );
264 }
265 \TYPO3\CMS\Core\Extension\ExtensionManager::addModule($mainModuleName, $subModuleName, $position);
266 }
267
268 /**
269 * Register a type converter by class name.
270 *
271 * @param string $typeConverterClassName
272 * @return void
273 * @api
274 */
275 static public function registerTypeConverter($typeConverterClassName) {
276 if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['typeConverters'])) {
277 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['typeConverters'] = array();
278 }
279 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['typeConverters'][] = $typeConverterClassName;
280 }
281
282 /**
283 * Build the autoload registry for a given extension and place it ext_autoload.php.
284 *
285 * @param string $extensionKey Key of the extension
286 * @param string $extensionPath full path of the extension
287 * @param array $additionalAutoloadClasses additional classes to be added to the autoloader. The key must be the classname all-lowercase, the value must be the entry to be inserted
288 * @return string HTML string which should be outputted
289 * @deprecated since Extbase 1.4.0; will be removed in Extbase 6.0
290 */
291 static public function createAutoloadRegistryForExtension($extensionKey, $extensionPath, $additionalAutoloadClasses = array()) {
292 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
293 $classNameToFileMapping = array();
294 $extensionName = str_replace(' ', '', ucwords(str_replace('_', ' ', $extensionKey)));
295 $errors = self::buildAutoloadRegistryForSinglePath($classNameToFileMapping, $extensionPath . 'Classes/', '.*tslib.*', '$extensionClassesPath . \'|\'');
296 if ($errors) {
297 return $errors;
298 }
299 $globalPrefix = '$extensionClassesPath = TYPO3\\CMS\\Core\\Extension\\ExtensionManager::extPath(\'' . $extensionKey . '\') . \'Classes/\';';
300 $errors = array();
301 foreach ($classNameToFileMapping as $className => $fileName) {
302 if (!(strpos($className, 'tx_' . strtolower($extensionName)) === 0)) {
303 $errors[] = $className . ' does not start with Tx_' . $extensionName . ' and was not added to the autoloader registry.';
304 unset($classNameToFileMapping[$className]);
305 }
306 }
307 $classNameToFileMapping = array_merge($classNameToFileMapping, $additionalAutoloadClasses);
308 $autoloadFileString = self::generateAutoloadPhpFileData($classNameToFileMapping, $globalPrefix);
309 if (!@file_put_contents(($extensionPath . 'ext_autoload.php'), $autoloadFileString)) {
310 $errors[] = '<b>' . $extensionPath . 'ext_autoload.php could not be written!</b>';
311 }
312 $errors[] = 'Wrote the following data: <pre>' . htmlspecialchars($autoloadFileString) . '</pre>';
313 return implode('<br />', $errors);
314 }
315
316 /**
317 * Generate autoload PHP file data. Takes an associative array with class name to file mapping, and outputs it as PHP.
318 * Does NOT escape the values in the associative array. Includes the <?php ... ?> syntax and an optional global prefix.
319 *
320 * @param array $classNameToFileMapping class name to file mapping
321 * @param string $globalPrefix Global prefix which is prepended to all code.
322 * @return string The full PHP string
323 * @deprecated since Extbase 1.4.0; will be removed in Extbase 6.0
324 */
325 protected function generateAutoloadPhpFileData($classNameToFileMapping, $globalPrefix = '') {
326 $output = '<?php' . PHP_EOL;
327 $output .= '// DO NOT CHANGE THIS FILE! It is automatically generated by TYPO3\\CMS\\Extbase\\Utility\\ExtensionUtility::createAutoloadRegistryForExtension.' . PHP_EOL;
328 $output .= '// This file was generated on ' . date('Y-m-d H:i') . PHP_EOL;
329 $output .= PHP_EOL;
330 $output .= $globalPrefix . PHP_EOL;
331 $output .= 'return array(' . PHP_EOL;
332 foreach ($classNameToFileMapping as $className => $quotedFileName) {
333 $output .= ' \'' . $className . '\' => ' . $quotedFileName . ',' . PHP_EOL;
334 }
335 $output .= ');' . PHP_EOL;
336 $output .= '?>';
337 return $output;
338 }
339
340 /**
341 * Generate the $classNameToFileMapping for a given filePath.
342 *
343 * @param array $classNameToFileMapping (Reference to array) All values are appended to this array.
344 * @param string $path Path which should be crawled
345 * @param string $excludeRegularExpression Exclude regular expression, to exclude certain files from being processed
346 * @param string $valueWrap Wrap for the file name
347 * @return void
348 * @deprecated since Extbase 1.4.0; will be removed in Extbase 6.0
349 */
350 static protected function buildAutoloadRegistryForSinglePath(&$classNameToFileMapping, $path, $excludeRegularExpression = '', $valueWrap = '\'|\'') {
351 $extensionFileNames = \TYPO3\CMS\Core\Utility\GeneralUtility::removePrefixPathFromList(\TYPO3\CMS\Core\Utility\GeneralUtility::getAllFilesAndFoldersInPath(array(), $path, 'php', FALSE, 99, $excludeRegularExpression), $path);
352 foreach ($extensionFileNames as $extensionFileName) {
353 $classNamesInFile = self::extractClassNames($path . $extensionFileName);
354 if (!count($classNamesInFile)) {
355 continue;
356 }
357 foreach ($classNamesInFile as $className) {
358 $classNameToFileMapping[strtolower($className)] = str_replace('|', $extensionFileName, $valueWrap);
359 }
360 }
361 }
362
363 /**
364 * Extracts class names from the given file.
365 *
366 * @param string $filePath file path (absolute)
367 * @return array class names
368 * @deprecated since Extbase 1.4.0; will be removed in Extbase 6.0
369 */
370 static protected function extractClassNames($filePath) {
371 $fileContent = php_strip_whitespace($filePath);
372 $classNames = array();
373 if (FALSE) {
374 $tokens = token_get_all($fileContent);
375 while (1) {
376 // look for "class" or "interface"
377 $token = self::findToken($tokens, array(T_ABSTRACT, T_CLASS, T_INTERFACE));
378 // fetch "class" token if "abstract" was found
379 if ($token === 'abstract') {
380 $token = self::findToken($tokens, array(T_CLASS));
381 }
382 if ($token === false) {
383 // end of file
384 break;
385 }
386 // look for the name (a string) skipping only whitespace and comments
387 $token = self::findToken($tokens, array(T_STRING), array(T_WHITESPACE, T_COMMENT, T_DOC_COMMENT));
388 if ($token === false) {
389 // unexpected end of file or token: remove found names because of parse error
390 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog('Parse error in "' . $filePath . '".', 'Core', 2);
391 $classNames = array();
392 break;
393 }
394 $token = \TYPO3\CMS\Core\Utility\GeneralUtility::strtolower($token);
395 // exclude XLASS classes
396 if (strncmp($token, 'ux_', 3)) {
397 $classNames[] = $token;
398 }
399 }
400 } else {
401 // TODO: parse PHP - skip coments and strings, apply regexp only on the remaining PHP code
402 $matches = array();
403 preg_match_all('/^[ \\t]*(?:(?:abstract|final)?[ \\t]*(?:class|interface))[ \\t\\n\\r]+([a-zA-Z][a-zA-Z_0-9]*)/mS', $fileContent, $matches);
404 $classNames = array_map('TYPO3\\CMS\\Core\\Utility\\GeneralUtility::strtolower', $matches[1]);
405 }
406 return $classNames;
407 }
408
409 /**
410 * Find tokens in the tokenList
411 *
412 * @param array &$tokenList list of tokens as returned by token_get_all()
413 * @param array $wantedTokens
414 * @param array $intermediateTokens optional: list of tokens that are allowed to skip when looking for the wanted token
415 * @return mixed
416 * @deprecated since Extbase 1.4.0; will be removed in Extbase 6.0
417 */
418 static protected function findToken(array &$tokenList, array $wantedTokens, array $intermediateTokens = array()) {
419 $skipAllTokens = count($intermediateTokens) ? false : true;
420 $returnValue = false;
421 // Iterate with while since we need the current array position:
422 foreach ($tokenList as $token) {
423 // parse token (see http://www.php.net/manual/en/function.token-get-all.php for format of token list)
424 if (is_array($token)) {
425 list($id, $text) = $token;
426 } else {
427 $id = ($text = $token);
428 }
429 if (in_array($id, $wantedTokens)) {
430 $returnValue = $text;
431 break;
432 }
433 // look for another token
434 if ($skipAllTokens || in_array($id, $intermediateTokens)) {
435 continue;
436 }
437 break;
438 }
439 return $returnValue;
440 }
441
442 /**
443 * Determines the plugin namespace of the specified plugin (defaults to "tx_[extensionname]_[pluginname]")
444 * If plugin.tx_$pluginSignature.view.pluginNamespace is set, this value is returned
445 * If pluginNamespace is not specified "tx_[extensionname]_[pluginname]" is returned.
446 *
447 * @param string $extensionName name of the extension to retrieve the namespace for
448 * @param string $pluginName name of the plugin to retrieve the namespace for
449 * @return string plugin namespace
450 * @deprecated since Extbase 1.4.0; will be removed in Extbase 6.0 - Use Tx_Extbase_Service_ExtensionService instead
451 */
452 static public function getPluginNamespace($extensionName, $pluginName) {
453 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
454 $extensionService = self::getExtensionService();
455 return $extensionService->getPluginNamespace($extensionName, $pluginName);
456 }
457
458 /**
459 * Iterates through the global TypoScript configuration and returns the name of the plugin
460 * that matches specified extensionName, controllerName and actionName.
461 * If no matching plugin was found, NULL is returned.
462 * If more than one plugin matches and the current plugin is not configured to handle the action,
463 * an Exception will be thrown
464 *
465 * @param string $extensionName name of the target extension (UpperCamelCase)
466 * @param string $controllerName name of the target controller (UpperCamelCase)
467 * @param string $actionName name of the target action (lowerCamelCase)
468 * @return string name of the target plugin (UpperCamelCase) or NULL if no matching plugin configuration was found
469 * @deprecated since Extbase 1.4.0; will be removed in Extbase 6.0 - Use Tx_Extbase_Service_ExtensionService instead
470 */
471 static public function getPluginNameByAction($extensionName, $controllerName, $actionName) {
472 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
473 $extensionService = self::getExtensionService();
474 return $extensionService->getPluginNameByAction($extensionName, $controllerName, $actionName);
475 }
476
477 /**
478 * Checks if the given action is cacheable or not.
479 *
480 * @param string $extensionName Name of the target extension, without underscores
481 * @param string $pluginName Name of the target plugin
482 * @param string $controllerName Name of the target controller
483 * @param string $actionName Name of the action to be called
484 * @return boolean TRUE if the specified plugin action is cacheable, otherwise FALSE
485 * @deprecated since Extbase 1.4.0; will be removed in Extbase 6.0 - Use Tx_Extbase_Service_ExtensionService instead
486 */
487 static public function isActionCacheable($extensionName, $pluginName, $controllerName, $actionName) {
488 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
489 $extensionService = self::getExtensionService();
490 return $extensionService->isActionCacheable($extensionName, $pluginName, $controllerName, $actionName);
491 }
492
493 /**
494 * Determines the target page of the specified plugin.
495 * If plugin.tx_$pluginSignature.view.defaultPid is set, this value is used as target page id
496 * If defaultPid is set to "auto", a the target pid is determined by loading the tt_content record that contains this plugin
497 * If the page could not be determined, NULL is returned
498 * If defaultPid is "auto" and more than one page contains the specified plugin, an Exception is thrown
499 *
500 * @param string $extensionName name of the extension to retrieve the target PID for
501 * @param string $pluginName name of the plugin to retrieve the target PID for
502 * @return integer uid of the target page or NULL if target page could not be determined
503 * @deprecated since Extbase 1.4.0; will be removed in Extbase 6.0 - Use Tx_Extbase_Service_ExtensionService instead
504 */
505 static public function getTargetPidByPlugin($extensionName, $pluginName) {
506 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
507 $extensionService = self::getExtensionService();
508 return $extensionService->getTargetPidByPlugin($extensionName, $pluginName);
509 }
510
511 }
512
513
514 ?>