// forward
if (empty($this->url)) {
- $this->url = LinkHandler::getInstance()->getLink('', array('controller' => 'Index'));
+ $this->url = LinkHandler::getInstance()->getLink('Index');
}
HeaderUtil::redirect($this->url, false);
exit;
$this->saved();
// open queue
- $url = LinkHandler::getInstance()->getLink('action=openQueue&processNo='.$processNo, array('controller' => 'Package'));
+ $url = LinkHandler::getInstance()->getLink('Package', array(), 'action=openQueue&processNo='.$processNo);
HeaderUtil::redirect($url);
exit;
}
$this->saved();
// open queue
- $url = LinkHandler::getInstance()->getLink('action=openQueue&processNo='.$processNo, array('controller' => 'Package'));
+ $url = LinkHandler::getInstance()->getLink('Package', array(), 'action=openQueue&processNo='.$processNo);
HeaderUtil::redirect($url);
exit;
}
$this->saved();
// forward
- $url = LinkHandler::getInstance()->getLink('', array(
- 'controller' => 'PackageUpdateSearchResult',
- 'id' => $search->searchID
- ));
+ $url = LinkHandler::getInstance()->getLink('PackageUpdateSearchResult', array('id' => $search->searchID));
HeaderUtil::redirect($url);
exit;
}
$this->saved();
// forward to result page
- $url = LinkHandler::getInstance()->getLink('sortField='.rawurlencode($this->sortField).'&sortOrder='.rawurlencode($this->sortOrder), array(
- 'controller' => 'UserList',
- 'id' => $this->searchID
- ));
+ $url = LinkHandler::getInstance()->getLink('UserList', array('id' => $this->searchID), 'sortField='.rawurlencode($this->sortField).'&sortOrder='.rawurlencode($this->sortOrder));
HeaderUtil::redirect($url);
exit;
}
WCF::getSession()->register('userMailData', $userMailData);
$this->saved();
- $url = LinkHandler::getInstance()->getLink('', array(
- 'controller' => 'UserMail',
- 'id' => $mailID
- ));
+ $url = LinkHandler::getInstance()->getLink('UserMail', array('id' => $mailID));
// show worker template
WCF::getTPL()->assign(array(
* @see wcf\system\menu\ITreeMenuItem::getLink()
*/
public function getLink() {
- return LinkHandler::getInstance()->getLink($this->menuItemLink);
+ return LinkHandler::getInstance()->getLink(null, array(), $this->menuItemLink);
}
}
* @see wcf\system\menu\ITreeMenuItem::getLink()
*/
public function getLink() {
- return LinkHandler::getInstance()->getLink($this->menuItemLink);
+ return LinkHandler::getInstance()->getLink(null, array(), $this->menuItemLink);
}
}
$packageInstallation = $statement->fetchArray();
if (!isset($packageInstallation['queueID'])) {
- $url = LinkHandler::getInstance()->getLink('', array('controller' => 'PackageList'));
+ $url = LinkHandler::getInstance()->getLink('PackageList');
HeaderUtil::redirect($url);
exit;
}
else {
- $url = LinkHandler::getInstance()->getLink('action='.$packageInstallation['action'].'&queueID='.$packageInstallation['queueID'], array('controller' => 'Package'));
+ $url = LinkHandler::getInstance()->getLink('Package', array(), 'action='.$packageInstallation['action'].'&queueID='.$packageInstallation['queueID']);
HeaderUtil::redirect($url);
exit;
}
));
}
- $url = LinkHandler::getInstance()->getLink('action=openQueue&processNo='.$processNo, array('controller' => 'Package'));
+ $url = LinkHandler::getInstance()->getLink('Package', array(), 'action=openQueue&processNo='.$processNo);
HeaderUtil::redirect($url);
exit;
}
/**
* Returns a relative link.
*
- * @param string $url
+ * @param string $controller
* @param array $parameters
+ * @param string $url
* @return string
*/
- public function getLink($url, array $parameters = array()) {
+ public function getLink($controller = null, array $parameters = array(), $url = '') {
$abbreviation = 'wcf';
$isRaw = false;
if (isset($parameters['application'])) {
}
// build route
- if (isset($parameters['controller'])) {
+ if ($controller !== null) {
+ $parameters['controller'] = $controller;
$routeURL = RouteHandler::getInstance()->buildRoute($parameters);
- if (!$isRaw) {
+ if (!$isRaw && !empty($url)) {
$routeURL .= (strpos($routeURL, '?') === false) ? '?' : '&';
}
$url = $routeURL . $url;
* @return string
*/
public function buildLink(array $components) {
- $link = 'index.php/';
- foreach ($this->routeSchema as $component) {
- if (!isset($components[$component])) {
- continue;
+ $link = '';
+
+ // handle default values for controller
+ $buildRoute = true;
+ if (count($components) == 1) {
+ if (isset($this->parameterOptions['controller']) && strcasecmp($this->parameterOptions['controller']['default'], $components['controller']) == 0) {
+ // only the controller was given and matches default, omit routing
+ $buildRoute = false;
}
+ }
+
+ if ($buildRoute) {
+ foreach ($this->routeSchema as $component) {
+ if (!isset($components[$component])) {
+ continue;
+ }
- $link .= $components[$component] . '/';
- unset($components[$component]);
+ $link .= $components[$component] . '/';
+ unset($components[$component]);
+ }
}
+ $link = 'index.php' . (!empty($link) ? '/' : '');
+
if (!empty($components)) {
$link .= '?' . html_build_query($components, '', '&');
}
<?php
namespace wcf\system\template\plugin;
+use wcf\system\exception\SystemException;
use wcf\system\request\LinkHandler;
use wcf\system\template\TemplateEngine;
use wcf\util\StringUtil;
* @see wcf\system\template\IBlockTemplatePlugin::execute()
*/
public function execute($tagArgs, $blockContent, TemplateEngine $tplObj) {
+ if (!isset($tagArgs['controller'])) throw new SystemException("missing 'controller' argument in pages tag");
if (!isset($tagArgs['application']) || empty($tagArgs['application'])) {
$tagArgs['application'] = 'wcf';
}
if (isset($tagArgs['encode']) && !$tagArgs['encode']) {
- return LinkHandler::getInstance()->getLink($blockContent, $tagArgs);
+ return LinkHandler::getInstance()->getLink($tagArgs['controller'], $tagArgs, $blockContent);
}
- return StringUtil::encodeHTML(LinkHandler::getInstance()->getLink($blockContent, $tagArgs));
+ return StringUtil::encodeHTML(LinkHandler::getInstance()->getLink($tagArgs['controller'], $tagArgs, $blockContent));
}
/**
// create and encode route link
$routeComponents = array('controller' => $tagArgs['controller']);
if (isset($tagArgs['id'])) $routeComponents['id'] = $tagArgs['id'];
- $routeURL = RouteHandler::getInstance()->buildRoute($routeComponents);
+ $routeURL = RouteHandler::getInstance()->buildRoute($tagArgs['controller'], $routeComponents);
$tagArgs['link'] = StringUtil::encodeHTML($routeURL . $tagArgs['link']);
if (!isset($tagArgs['page'])) {