Extbase:
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / MVC / View / Helper / UriHelperRenamed.php
1 <?php
2 /* *
3 * This script is part of the TYPO3 project - inspiring people to share! *
4 * *
5 * TYPO3 is free software; you can redistribute it and/or modify it under *
6 * the terms of the GNU General Public License version 2 as published by *
7 * the Free Software Foundation. *
8 * *
9 * This script is distributed in the hope that it will be useful, but *
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
11 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
12 * Public License for more details. *
13 * */
14
15 require_once(PATH_t3lib . 'interfaces/interface.t3lib_singleton.php');
16 require_once(PATH_tslib . 'class.tslib_content.php');
17
18 /**
19 * @package
20 * @subpackage
21 * @version $Id:$
22 */
23 // TODO Rename file name URIHelper to UriHelper
24 class Tx_Extbase_MVC_View_Helper_UriHelper extends Tx_Extbase_MVC_View_Helper_AbstractHelper implements t3lib_Singleton {
25
26 /**
27 * An instance of tslib_cObj
28 *
29 * @var tslib_cObj
30 */
31 protected $contentObject;
32
33 /**
34 * Constructs this URI Helper
35 */
36 public function __construct(array $arguments = array()) {
37 $this->contentObject = t3lib_div::makeInstance('tslib_cObj');
38 }
39
40 /**
41 * Creates an URI by making use of the typolink mechanism.
42 *
43 * @param string $actionName Name of the action to be called
44 * @param array $arguments Additional arguments
45 * @param string $controllerName Name of the target controller. If not set, current controller is used
46 * @param string $pageUid
47 * @param array $options Further options
48 * @return string the HTML code for the generated link
49 * @author Bastian Waidelich <bastian@typo3.org>
50 */
51 public function uriFor($actionName, $arguments = array(), $controllerName = '', $parameter = 0, $anchor = '', $useCacheHash = TRUE) {
52 $prefixedExtensionKey = 'tx_' . strtolower($this->request->getControllerExtensionKey()) . '_' . strtolower($this->request->getPluginKey());
53
54 $arguments['action'] = $actionName;
55 $arguments['controller'] = ($controllerName !== '') ? $controllerName : $this->request->getControllerName();
56 $prefixedArguments = array();
57 foreach ($arguments as $argumentName => $argumentValue) {
58 $key = $prefixedExtensionKey . '[' . $argumentName . ']';
59 $prefixedArguments[$key] = $argumentValue;
60 }
61
62 return $this->typolinkUri($pageUid, $anchor, $useCacheHash, $prefixedArguments);
63 }
64
65 /**
66 * Get an URI from typolink
67 * @return The URI
68 */
69 public function typolinkUri($pageUid = 0, $anchor = '', $useCacheHash = TRUE, $arguments = array()) {
70 if ($pageUid === 0) {
71 $pageUid = $GLOBALS['TSFE']->id;
72 }
73
74 $typolinkConfiguration = array(
75 'parameter' => $pageUid
76 );
77
78 if (count($arguments) > 0) {
79 foreach ($arguments as $argumentNameSpace => $argument) {
80 $typolinkConfiguration['additionalParams'] .= '&' . $argumentNameSpace . '=' . rawurlencode($argument);
81 }
82 }
83 if (!empty($anchor)) {
84 $typolinkConfiguration['section'] = $anchor;
85 }
86 if ($useCacheHash === TRUE) {
87 $typolinkConfiguration['useCacheHash'] = 1;
88 } else {
89 $typolinkConfiguration['useCacheHash'] = 0;
90 }
91
92 return $this->contentObject->typoLink_URL($typolinkConfiguration);
93 }
94 }
95 ?>