Skip to content

Commit

Permalink
COM_buildURL now builds a URL based on $_CONF['url_routing']
Browse files Browse the repository at this point in the history
  • Loading branch information
mystralkk committed Jan 20, 2016
1 parent 7abfb8c commit 7239b33
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 144 deletions.
3 changes: 1 addition & 2 deletions public_html/index.php
Expand Up @@ -84,8 +84,7 @@ function fixTopic(&$A, $tid_list)
}

// If URL routing is enabled, then let the router handle the request
if (isset($_CONF['url_routing']) && !empty($_CONF['url_routing'])) {
require_once $_CONF['path_system'] . 'classes/router.class.php';
if ($_CONF['url_rewrite'] && isset($_CONF['url_routing']) && !empty($_CONF['url_routing'])) {
Router::dispatch();
}

Expand Down
5 changes: 3 additions & 2 deletions public_html/lib-common.php
Expand Up @@ -199,8 +199,9 @@
* This provides optional URL rewriting functionality.
*/

require_once( $_CONF['path_system'] . 'classes/url.class.php' );
$_URL = new url( $_CONF['url_rewrite'] );
require_once $_CONF['path_system'] . 'classes/router.class.php';
require_once $_CONF['path_system'] . 'classes/url.class.php';
$_URL = new Url($_CONF['url_rewrite'], $_CONF['url_routing']);

/**
* This is our HTML template class. It is the same one found in PHPLib and is
Expand Down
32 changes: 25 additions & 7 deletions system/classes/router.class.php
Expand Up @@ -44,6 +44,11 @@ public static function dispatch()
{
global $_CONF, $_TABLES;

// URL rewrite is disabled
if (!$_CONF['url_rewrite']) {
return false;
}

// URL routing is not supported
if (!isset($_CONF['url_routing'])) {
return false;
Expand Down Expand Up @@ -184,6 +189,11 @@ public static function convertUrl($url, $requestMethod = self::HTTP_REQUEST_GET)
{
global $_CONF, $_TABLES;

// URL rewrite is disabled
if (!$_CONF['url_rewrite']) {
return $url;
}

// URL routing is not supported
if (!isset($_CONF['url_routing'])) {
return $url;
Expand Down Expand Up @@ -231,22 +241,26 @@ public static function convertUrl($url, $requestMethod = self::HTTP_REQUEST_GET)

// Try simple comparison without placeholders
if (strcasecmp($route, $url) === 0) {
$retval = $rule;

if ($routingType === self::ROUTING_WITH_INDEX_PHP) {
$rule = $_CONF['site_url'] . $rule;
$retval = '/index.php' . $retval;
}

$retval = $_CONF['site_url'] . $retval;

if (self::$debug) {
COM_errorLog(__METHOD__ . ': matched with simple comparison rule "' . $A['route'] . '"');
COM_errorLog(__METHOD__ . ': matched with simple comparison route "' . $A['route'] . '"');
}

return $rule;
return $retval;
}

// Try comparison with placeholders
if (preg_match_all(self::PATTERN_PLACEHOLDER, $route, $matches, PREG_SET_ORDER)) {
$placeHolders = array();

// Replace placeholders in a rule with ones for regular expressions
// Replace placeholders in a route with ones for regular expressions
foreach ($matches as $match) {
$placeHolders[] = $match[1];
$route = str_ireplace($match[1], '([^/]+)', $route);
Expand All @@ -269,18 +283,22 @@ public static function convertUrl($url, $requestMethod = self::HTTP_REQUEST_GET)
foreach ($matches as $match) {
$match = urlencode($match);
$placeHolder = array_shift($placeHolders);
$url = str_ireplace($placeHolder, $match, $url);
$rule = str_ireplace($placeHolder, $match, $rule);
}

$retval = $rule;

if ($routingType === self::ROUTING_WITH_INDEX_PHP) {
$url = $_CONF['site_url'] . $url;
$retval = '/index.php' . $retval;
}

$retval = $_CONF['site_url'] . $retval;

if (self::$debug) {
COM_errorLog(__METHOD__ . ': matched with regular expression rule "' . $A['route'] . '"');
}

return $url;
return $retval;
}
}

Expand Down

0 comments on commit 7239b33

Please sign in to comment.