|
<?php |
|
|
|
namespace Kanboard\Helper; |
|
|
|
use Kanboard\Core\Base; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UrlHelper extends Base |
|
{ |
|
private $base = ''; |
|
private $directory = ''; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function doc($label, $file = '') |
|
{ |
|
$url = sprintf(DOCUMENTATION_URL_PATTERN, $file); |
|
return sprintf('<a href="%s" target="_blank">%s</a>', $url, $label); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function button($icon, $label, $controller, $action, array $params = array(), $class = '') |
|
{ |
|
$html = '<i class="fa fa-'.$icon.' fa-fw"></i> '.$label; |
|
$class = 'btn '.$class; |
|
return $this->link($html, $controller, $action, $params, false, $class); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function icon($icon, $label, $controller, $action, array $params = array(), $csrf = false, $class = '', $title = '', $newTab = false, $anchor = '', $absolute = false) |
|
{ |
|
$html = '<i class="fa fa-fw fa-'.$icon.'" aria-hidden="true"></i>'.$label; |
|
return $this->helper->url->link($html, $controller, $action, $params, $csrf, $class, $title, $newTab, $anchor, $absolute); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function link($label, $controller, $action, array $params = array(), $csrf = false, $class = '', $title = '', $newTab = false, $anchor = '', $absolute = false) |
|
{ |
|
return '<a href="'.$this->href($controller, $action, $params, $csrf, $anchor, $absolute).'" class="'.$class.'" title=\''.$title.'\' '.($newTab ? 'target="_blank"' : '').'>'.$label.'</a>'; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function absoluteLink($label, $controller, $action, array $params = array()) |
|
{ |
|
return $this->link($label, $controller, $action, $params, false, '', '', true, '', true); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function href($controller, $action, array $params = array(), $csrf = false, $anchor = '', $absolute = false) |
|
{ |
|
return $this->build('&', $controller, $action, $params, $csrf, $anchor, $absolute); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function to($controller, $action, array $params = array(), $anchor = '', $absolute = false) |
|
{ |
|
return $this->build('&', $controller, $action, $params, false, $anchor, $absolute); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function base() |
|
{ |
|
if (empty($this->base)) { |
|
$this->base = $this->configModel->get('application_url') ?: $this->server(); |
|
} |
|
|
|
return $this->base; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function dir() |
|
{ |
|
if ($this->directory === '' && $this->request->getMethod() !== '') { |
|
if (defined('KANBOARD_URL') && strlen(KANBOARD_URL) > 0) { |
|
$this->directory = parse_url(KANBOARD_URL, PHP_URL_PATH); |
|
} else { |
|
$this->directory = str_replace('\\', '/', dirname($this->request->getServerVariable('PHP_SELF'))); |
|
$this->directory = $this->directory !== '/' ? $this->directory.'/' : '/'; |
|
$this->directory = str_replace('//', '/', $this->directory); |
|
} |
|
} |
|
|
|
return $this->directory; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function server() |
|
{ |
|
if ($this->request->getServerVariable('SERVER_NAME') === '') { |
|
return 'http://localhost/'; |
|
} |
|
|
|
$url = $this->request->isHTTPS() ? 'https://' : 'http://'; |
|
$url .= $this->request->getServerVariable('SERVER_NAME'); |
|
$url .= $this->request->getServerVariable('SERVER_PORT') == 80 || $this->request->getServerVariable('SERVER_PORT') == 443 ? '' : ':'.$this->request->getServerVariable('SERVER_PORT'); |
|
$url .= $this->dir() ?: '/'; |
|
|
|
return $url; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function build($separator, $controller, $action, array $params = array(), $csrf = false, $anchor = '', $absolute = false) |
|
{ |
|
$path = $this->route->findUrl($controller, $action, $params); |
|
$qs = array(); |
|
|
|
if (empty($path)) { |
|
$qs['controller'] = $controller; |
|
$qs['action'] = $action; |
|
$qs += $params; |
|
} else { |
|
unset($params['plugin']); |
|
} |
|
|
|
if ($csrf) { |
|
$qs['csrf_token'] = $this->token->getCSRFToken(); |
|
} |
|
|
|
if (! empty($qs)) { |
|
$path .= '?'.http_build_query($qs, '', $separator); |
|
} |
|
|
|
return ($absolute ? $this->base() : $this->dir()).$path.(empty($anchor) ? '' : '#'.$anchor); |
|
} |
|
} |
|
|