Extbase:
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / MVC / View / Helper / URIHelper.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 class Tx_Extbase_MVC_View_Helper_URIHelper extends Tx_Extbase_MVC_View_Helper_AbstractHelper implements t3lib_Singleton {
24
25 /**
26 * An instance of tslib_cObj
27 *
28 * @var tslib_cObj
29 */
30 protected $contentObject;
31
32 /**
33 * Constructs this URI Helper
34 */
35 public function __construct() {
36 $this->contentObject = t3lib_div::makeInstance('tslib_cObj');
37 }
38
39 /**
40 * Creates an URI by making use of the typolink mechanism.
41 *
42 * @param integer $pageUid uid of the target page
43 * @param string $actionName Name of the action to be called
44 * @param array $arguments Additional query parameters, will be "namespaced"
45 * @param string $controllerName Name of the target controller
46 * @param string $extensionName Name of the target extension, without underscores. If NULL current ExtensionName is used.
47 * @param string $pluginName Name of the target plugin. If NULL current PluginName is used.
48 * @param array $options Further options (usually options of the typolink configuration)
49 * @param integer $pageType type of the target page. See typolink.parameter
50 * @return string the typolink URI
51 */
52 public function URIFor($pageUid, $actionName = NULL, $arguments = array(), $controllerName = NULL, $extensionName = NULL, $pluginName = NULL, array $options = array(), $pageType = 0) {
53 if ($actionName !== NULL) {
54 $arguments['action'] = $actionName;
55 }
56 if ($controllerName !== NULL) {
57 $arguments['controller'] = $controllerName;
58 }
59 if ($extensionName === NULL) {
60 $extensionName = $this->request->getControllerExtensionName();
61 }
62 if ($pluginName === NULL) {
63 $pluginName = $this->request->getPluginKey();
64 }
65 $argumentPrefix = strtolower('tx_' . $extensionName . '_' . $pluginName);
66 $prefixedArguments = (count($arguments) > 0) ? array($argumentPrefix => $arguments) : array();
67
68 return $this->typolinkURI($pageUid, $prefixedArguments, $options, $pageType);
69 }
70
71 /**
72 * Get an URI from typolink_URL
73 *
74 * @param integer $pageUid uid of the target page. If not set, the current page uid is used
75 * @param array $arguments query parameters
76 * @param array $options Further options (usually options of the typolink configuration)
77 * @param integer $pageType type of the target page. See typolink.parameter
78 * @return The URI
79 */
80 public function typolinkURI($pageUid, array $arguments = array(), array $options = array(), $pageType = 0) {
81 $typolinkConfiguration = array();
82 $typolinkConfiguration['parameter'] = $pageUid;
83 if ($pageType !== 0) {
84 $typolinkConfiguration['parameter'] .= ',' . $pageType;
85 }
86 $typolinkConfiguration['additionalParams'] = '';
87 if (count($arguments) > 0) {
88 $typolinkConfiguration['additionalParams'] .= '&' . http_build_query($arguments);
89 if (!isset($options['no_cache'])) {
90 $typolinkConfiguration['useCacheHash'] = 1;
91 }
92 }
93 if (isset($options['additionalParams'])) {
94 $typolinkConfiguration['additionalParams'] .= $this->contentObject->stdWrap($options['additionalParams'], isset($options['additionalParams.']) ? $options['additionalParams.'] : array());
95 unset($options['additionalParams']);
96 unset($options['additionalParams.']);
97 }
98 $typolinkConfiguration = t3lib_div::array_merge_recursive_overrule($typolinkConfiguration, $options);
99 return $this->contentObject->typoLink_URL($typolinkConfiguration);
100 }
101 }
102 ?>