/* assign language variables */
self::getTPL()->assign(array(
"isReseller" => User::isReseller(),
- "isAdmin" => User::isAdmin()
+ "isAdmin" => User::isAdmin(),
+ 'baseurl' => RequestHandler::getInstance()->getBaseUrl()
));
/*self::getTPL()->assign("version", mb_substr(sha1(DNS_VERSION), 0, 8));*/
$routes = [];
foreach ($controllers as $name => $data) {
- $routes[$name] = Segment::factory([ 'route' => $name.'[/][/:id[-:title]]', 'constraints' => [ 'id' => '[0-9]+', 'title' => '[a-zA-Z0-9_.-/]+' ], 'defaults' => [ 'controller' => $data ] ]);
+ $routes[$name] = Segment::factory([ 'route' => '[/]' . $name . '[/][/:id[-:title]]', 'constraints' => [ 'id' => '[0-9]+', 'title' => '[a-zA-Z0-9_.-/]+' ], 'defaults' => [ 'controller' => $data ] ]);
}
$this->router->setRoutes($routes);
$_REQUEST[$key] = $value;
}
}
+
+ public function getBaseUrl () {
+ $protocol = 'http://';
+
+ if ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443 || (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) {
+ $protocol = 'https://';
+ }
+
+ return $protocol . $_SERVER['HTTP_HOST'] . '/';
+ }
+
+ public function getLink (array $params = [], $query = '') {
+ $path_info = true; // TODO: add config constant for that
+
+ $url = $this->getBaseUrl() . 'index.php';
+ if ($path_info) {
+ $url .= '/';
+ }
+ else {
+ $url .= '?';
+ }
+
+ if (!empty($params['controller'])) {
+ $url .= $params['controller'];
+ }
+ else {
+ // TODO: InvalidArgumentException?
+ }
+
+ if (!empty($params['id'])) {
+ if (!empty($params['title'])) {
+ $url .= '/'.$params['id'].'-'.$params['title'];
+ }
+ else {
+ $url .= '/'.$params['id'];
+ }
+ }
+
+ if (!empty($query)) {
+ if ($path_info) {
+ if (strpos($query, '&') === 0) {
+ $query = '/' . substr($query, 1);
+ }
+ else if (strpos($query, '/') !== 0) {
+ $query = '/' . $query;
+ }
+ }
+ else {
+ if (strpos($query, '/') === 0) {
+ $query = '&' . substr($query, 1);
+ }
+ else if (strpos($query, '&') !== 0) {
+ $query = '&' . $query;
+ }
+ }
+
+ $url .= $query;
+ }
+
+ return $url;
+ }
}
class Request extends BaseRequest {
public function getPath() {
- $queryString = $_SERVER['QUERY_STRING'];
-
- if (strpos($queryString, '&') !== false) {
- $pos = strpos($queryString, '&');
- $queryString = substr($queryString, 0, $pos);
+ if (isset($_SERVER['PATH_INFO']) && !empty($_SERVER['PATH_INFO'])) {
+ $queryString = $_SERVER['PATH_INFO'];
+ }
+ else {
+ $queryString = $_SERVER['QUERY_STRING'];
+
+ if (strpos($queryString, '&') !== false) {
+ $pos = strpos($queryString, '&');
+ $queryString = substr($queryString, 0, $pos);
+ }
}
-
return $queryString;
}
}
<?php
+use dns\system\RequestHandler;
function smarty_block_link($params, $content, $template, &$repeat) {
if ($repeat) {
$params['title'] = null;
}
- $url = 'index.php?'.$params['controller'];
-
- if (!empty($params['id'])) {
- if (!empty($params['title'])) {
- $url .= '/'.$params['id'].'-'.$params['title'];
- }
- else {
- $url .= '/'.$params['id'];
- }
- }
-
- if (!empty($content)) {
- if (strpos($content, '&') !== 0) {
- $url .= '&';
- }
-
- $url .= $content;
- }
-
- return @htmlspecialchars($url, ENT_COMPAT, 'UTF-8');
+ return RequestHandler::getInstance()->getLink($params, $content);
}
<!DOCTYPE html>
<html>
<head>
+ <base href="{$baseurl}" />
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">