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 (is_array($arguments)) {
54 foreach ($arguments as $argumentKey => $argumentValue) {
55 if ($argumentValue instanceof Tx_Extbase_DomainObject_AbstractEntity) {
56 $arguments[$argumentKey] = array('uid' => $argumentValue->getUid());
57 }
58 }
59 }
60 if ($actionName !== NULL) {
61 $arguments['action'] = $actionName;
62 }
63 if ($controllerName !== NULL) {
64 $arguments['controller'] = $controllerName;
65 }
66 if ($extensionName === NULL) {
67 $extensionName = $this->request->getControllerExtensionName();
68 }
69 if ($pluginName === NULL) {
70 $pluginName = $this->request->getPluginName();
71 }
72 $argumentPrefix = strtolower('tx_' . $extensionName . '_' . $pluginName);
73 $prefixedArguments = (count($arguments) > 0) ? array($argumentPrefix => $arguments) : array();
74
75 return $this->typolinkURI($pageUid, $prefixedArguments, $options, $pageType);
76 }
77
78 /**
79 * Get an URI from typolink_URL
80 *
81 * @param integer $pageUid uid of the target page. If not set, the current page uid is used
82 * @param array $arguments query parameters
83 * @param array $options Further options (usually options of the typolink configuration)
84 * @param integer $pageType type of the target page. See typolink.parameter
85 * @return The URI
86 */
87 public function typolinkURI($pageUid, array $arguments = array(), array $options = array(), $pageType = 0) {
88 $typolinkConfiguration = array();
89 $typolinkConfiguration['parameter'] = $pageUid;
90 if ($pageType !== 0) {
91 $typolinkConfiguration['parameter'] .= ',' . $pageType;
92 }
93 $typolinkConfiguration['additionalParams'] = '';
94 if (count($arguments) > 0) {
95 $typolinkConfiguration['additionalParams'] .= '&' . http_build_query($arguments, NULL, '&');
96 if (!isset($options['no_cache'])) {
97 $typolinkConfiguration['useCacheHash'] = 1;
98 }
99 }
100 if (isset($options['additionalParams'])) {
101 $typolinkConfiguration['additionalParams'] .= $this->contentObject->stdWrap($options['additionalParams'], isset($options['additionalParams.']) ? $options['additionalParams.'] : array());
102 unset($options['additionalParams']);
103 unset($options['additionalParams.']);
104 }
105 $typolinkConfiguration = t3lib_div::array_merge_recursive_overrule($typolinkConfiguration, $options);
106
107 return $this->contentObject->typoLink_URL($typolinkConfiguration);
108 }
109 }
110 ?>
111