5459b5116047275e5a2d551b27d7c8b758578ef4
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / MVC / Web / URIHelper.php
1 <?php
2
3 /* *
4 * This script is part of the TYPO3 project - inspiring people to share! *
5 * *
6 * TYPO3 is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU General Public License version 2 as published by *
8 * the Free Software Foundation. *
9 * *
10 * This script is distributed in the hope that it will be useful, but *
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
12 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
13 * Public License for more details. *
14 * */
15
16 require_once(PATH_t3lib . 'interfaces/interface.t3lib_singleton.php');
17 require_once(PATH_tslib . 'class.tslib_content.php');
18
19 /**
20 * @package
21 * @subpackage
22 * @version $Id:$
23 */
24 class Tx_ExtBase_MVC_Web_URIHelper implements t3lib_Singleton {
25 /**
26 * An instance of tslib_cObj
27 *
28 * @var tslib_cObj
29 */
30 protected $contentObject;
31
32 public function __construct(array $arguments = array()) {
33 $this->contentObject = t3lib_div::makeInstance('tslib_cObj');
34 }
35
36 /**
37 * Get an URI for a controller / action / extension on a specific page within the scope
38 * of the current request.
39 * @return The URI
40 */
41 public function URIFor($request, $actionName = '', $arguments = array(), $controllerName = '', $page = '', $extensionKey = '', $anchor = '', $useCacheHash = TRUE) {
42 $prefixedExtensionKey = 'tx_' . strtolower($request->getExtensionName()) . '_' . strtolower($request->getPluginKey());
43
44 $arguments['action'] = $actionName;
45 $arguments['controller'] = ($controllerName !== '') ? $controllerName : $request->getControllerName();
46 $prefixedArguments = array();
47 foreach ($arguments as $argumentName => $argumentValue) {
48 $key = $prefixedExtensionKey . '[' . $argumentName . ']';
49 $prefixedArguments[$key] = $argumentValue;
50 }
51
52 return $this->typolinkURI($page, $anchor, $useCacheHash, $prefixedArguments);
53 }
54
55 /**
56 * Get an URI from typolink
57 * @return The URI
58 */
59 public function typolinkURI($page = '', $anchor = '', $useCacheHash = TRUE, $arguments = array()) {
60 if ($page === '') {
61 $page = $GLOBALS['TSFE']->id;
62 }
63
64 $typolinkConfiguration = array(
65 'parameter' => $page
66 );
67
68 if (count($arguments) > 0) {
69 foreach ($arguments as $argumentNameSpace => $argument) {
70 $typolinkConfiguration['additionalParams'] .= '&' . $argumentNameSpace . '=' . rawurlencode($argument);
71 }
72 }
73 if ($anchor) {
74 $typolinkConfiguration['section'] = $anchor;
75 }
76 if ($useCacheHash) {
77 $typolinkConfiguration['useCacheHash'] = 1;
78 } else {
79 $typolinkConfiguration['useCacheHash'] = 0;
80 }
81
82 return $this->contentObject->typoLink_URL($typolinkConfiguration);
83 }
84 }
85 ?>