Extbase:
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / MVC / View / Helper / 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_View_Helper_URIHelper implements t3lib_Singleton {
25
26 /**
27 * An instance of tslib_cObj
28 *
29 * @var tslib_cObj
30 */
31 protected $contentObject;
32
33 public function __construct(array $arguments = array()) {
34 $this->contentObject = t3lib_div::makeInstance('tslib_cObj');
35 }
36
37 /**
38 * Get an URI for a controller / action / extension on a specific page within the scope
39 * of the current request.
40 * @return The URI
41 */
42 public function URIFor($request, $actionName = '', $arguments = array(), $controllerName = '', $page = '', $extensionKey = '', $anchor = '', $useCacheHash = TRUE) {
43 $prefixedExtensionKey = 'tx_' . strtolower($request->getExtensionName()) . '_' . strtolower($request->getPluginKey());
44
45 $arguments['action'] = $actionName;
46 $arguments['controller'] = ($controllerName !== '') ? $controllerName : $request->getControllerName();
47 $prefixedArguments = array();
48 foreach ($arguments as $argumentName => $argumentValue) {
49 $key = $prefixedExtensionKey . '[' . $argumentName . ']';
50 $prefixedArguments[$key] = $argumentValue;
51 }
52
53 return $this->typolinkURI($page, $anchor, $useCacheHash, $prefixedArguments);
54 }
55
56 /**
57 * Get an URI from typolink
58 * @return The URI
59 */
60 public function typolinkURI($page = '', $anchor = '', $useCacheHash = TRUE, $arguments = array()) {
61 if ($page === '') {
62 $page = $GLOBALS['TSFE']->id;
63 }
64
65 $typolinkConfiguration = array(
66 'parameter' => $page
67 );
68
69 if (count($arguments) > 0) {
70 foreach ($arguments as $argumentNameSpace => $argument) {
71 $typolinkConfiguration['additionalParams'] .= '&' . $argumentNameSpace . '=' . rawurlencode($argument);
72 }
73 }
74 if ($anchor) {
75 $typolinkConfiguration['section'] = $anchor;
76 }
77 if ($useCacheHash) {
78 $typolinkConfiguration['useCacheHash'] = 1;
79 } else {
80 $typolinkConfiguration['useCacheHash'] = 0;
81 }
82
83 return $this->contentObject->typoLink_URL($typolinkConfiguration);
84 }
85 }
86 ?>