Skip to content

Commit efdb6bc

Browse files
committed
Changed module to match module parameter from get to avoid mismatch with route parameter
1 parent 9dbd5c0 commit efdb6bc

File tree

6 files changed

+50
-27
lines changed

6 files changed

+50
-27
lines changed

app/component/breadcrumb.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ function cacheKey() {
4242
}
4343

4444
function results() {
45-
$request = Request::getInstance();
46-
$route = $request->get['route'] ?? '';
47-
$slug = $request->get['slug'] ?? '';
48-
$name = $request->get['name'] ?? '';
49-
$homeText = __('Home');
50-
$shopText = __('Shop');
51-
$blogText = __('Blog');
52-
$urlOptions = [];
45+
$request = Request::getInstance();
46+
$module = $request->get['module'] ?? '';
47+
$slug = $request->get['slug'] ?? '';
48+
$name = $request->get['name'] ?? '';
49+
$homeText = __('Home');
50+
$shopText = __('Shop');
51+
$blogText = __('Blog');
52+
$urlOptions = [];
5353

5454
if ($this->options['absoluteURL']) {
5555
$urlOptions= ['host' => SITE_URL, 'scheme' => $_SERVER['REQUEST_SCHEME'] ?? 'http'];
@@ -59,7 +59,7 @@ function results() {
5959
['text' => $homeText, 'url' => url('index/index', $urlOptions)],
6060
];
6161

62-
switch ($route) {
62+
switch ($module) {
6363
//product page
6464
case 'product/product/index':
6565
$product_id = $request->get['product_id'] ?? false;

app/component/language.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function results() {
109109
//$url = getCurrentUrl();
110110
if (true/* && $options['default'] != $code*/) {
111111
$params = $lang + $content + $get + ['host' => $_SERVER['HTTP_HOST'] ?? '', 'scheme' => $scheme];
112-
$url = url($request->get['route'] ?? '', $params, false); //"/$shortcode" . getCurrentUrl();
112+
$url = url($request->get['module'] ?? '', $params, false); //"/$shortcode" . getCurrentUrl();
113113
$hreflang[$shortcode] = $url;
114114
}
115115

app/controller/cart/cart.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Vvveb\Controller\Base;
2626
use Vvveb\System\Cart\Cart as ShoppingCart;
2727
use Vvveb\System\Core\View;
28+
use Vvveb\System\Event;
2829
use Vvveb\System\Payment;
2930
use Vvveb\System\Shipping;
3031

@@ -50,7 +51,7 @@ function index() {
5051
$this->view->shipping = $shipping->getMethods([]);
5152

5253
if (isset($this->request->post['product_id']) &&
53-
(isset($this->request->get['route']) && $this->request->get['route'] == 'cart/cart/add')) {
54+
(isset($this->request->get['module']) && $this->request->get['module'] == 'cart/cart/add')) {
5455
$this->cart->add($this->request->post['product_id']);
5556
}
5657

@@ -77,6 +78,9 @@ private function action($action, $productId = null, $quantity = 1) {
7778
$option = $this->request->request['option'] ?? [];
7879
$subscriptionPlanId = $this->request->request['subscription_plan_id'] ?? false;
7980

81+
list($action, $productId, $key, $quantity, $option, $subscriptionPlanId) =
82+
Event :: trigger(__CLASS__,__FUNCTION__, $action, $productId, $key, $quantity, $option, $subscriptionPlanId);
83+
8084
if ($key || $productId) {
8185
//$this->view->success = false;
8286
switch ($action) {

app/template/pagination.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ $page_stop = $pagecount;
2828
$url = '@@__data-v-url__@@';
2929
3030
if (empty($url)) {
31-
$url = Vvveb\System\Core\FrontController :: getRoute();
31+
$url = Vvveb\System\Core\FrontController :: getModule();
3232
if (is_array($parameters)) {
3333
$parameters += Vvveb\System\Core\Request :: getInstance()->get;
3434
} else {

system/core/frontcontroller.php

+20-8
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@ static function notFound($service = false, $message = false, $statusCode = 404)
122122

123123
//$view = View :: getInstance();
124124
$response = Response::getInstance();
125-
$view = new View();
125+
126+
if ($service) {
127+
$view = View::getInstance();
128+
} else {
129+
$view = new View();
130+
}
131+
126132
$view->setTheme();
127133

128134
if (is_string($message)) {
@@ -343,6 +349,10 @@ static public function getRoute() {
343349
return $_GET['route'] ?? '';
344350
}
345351

352+
static public function getModule() {
353+
return $_GET['module'] ?? '';
354+
}
355+
346356
static public function dispatch() {
347357
$module = $_GET['module'] ?? $_POST['module'] ?? null;
348358
$action = $_GET['action'] ?? $_POST['action'] ?? null;
@@ -361,21 +371,23 @@ static public function dispatch() {
361371
if (V_SUBDIR_INSTALL) {
362372
$uri = str_replace(V_SUBDIR_INSTALL, '', $uri);
363373
}
364-
$uri = preg_replace('/\?.*$/', '', $uri);
365374

366-
if (! $module && (APP != 'admin' && APP != 'install' && (Routes::init(APP) && $parameters = Routes::match($uri)))) {
367-
$_GET = array_merge($parameters, $_GET);
375+
$uri = preg_replace('/\?.*$/', '', $uri);
376+
$route = false;
377+
378+
if (! $module && (APP != 'admin' && APP != 'install' && (Routes::init(APP) && $route = Routes::match($uri)))) {
379+
$_GET = array_merge($route, $_GET);
368380
} else {
369-
$module = $module ?? ((APP == 'app') ? 'error404' : 'index');
381+
$module = $module ?? ((APP == 'install' || APP == 'admin') ? 'index' : 'error404');
370382
self :: $status = 404;
371383
}
372384

373-
if (isset($_GET['route'])) {
374-
if (preg_match('@(^.+?)/(\w+$)@', $_GET['route'], $routeMatch)) {
385+
if ($route) {
386+
if (preg_match('@(^.+?)/(\w+$)@', $_GET['module'], $routeMatch)) {
375387
$module = $routeMatch[1];
376388
$action = $action ?? $routeMatch[2];
377389
} else {
378-
$module = trim($_GET['route'], '/');
390+
$module = trim($_GET['module'], '/');
379391
}
380392
}
381393

system/routes.php

+14-7
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ private static function processRoute($url, $data) {
6161
return $b['count'] <=> $a['count'];
6262
});
6363

64+
$route = $url;
6465
//escape / for regex
6566
$url = str_replace('/', '\/', $url);
6667
//numeric limit
@@ -74,7 +75,9 @@ private static function processRoute($url, $data) {
7475
//wildcard
7576
$url = preg_replace('/' . self :: wildcardRegex . '/', '.*?', $url);
7677

77-
self :: $urls[$url] = $module;
78+
self :: $urls[$route] = [$url, $module];
79+
80+
return $url;
7881
}
7982

8083
public static function addRoute($url, $data) {
@@ -119,15 +122,18 @@ public static function match($url) {
119122
if (! self :: $init) {
120123
self :: init();
121124
}
122-
123125
//remove get parameters
124-
$url = preg_replace('/\?.+$/', '', $url);
126+
$url = preg_replace('/\?.*$/', '', str_replace('//', '/', $url));
127+
128+
foreach (self :: $urls as $route => $data) {
129+
list($pattern, $module) = $data;
125130

126-
foreach (self :: $urls as $pattern => $route) {
127131
if ($url == $pattern || preg_match('/^' . $pattern . '$/', $url, $matches)) {
128132
$parameters = array_filter($matches, 'is_string', ARRAY_FILTER_USE_KEY);
129133

130-
$parameters['route'] = $route;
134+
$parameters['route'] = $route;
135+
$parameters['module'] = $module;
136+
$parameters['pattern'] = $pattern;
131137

132138
return $parameters;
133139
}
@@ -171,10 +177,11 @@ public static function getUrlData($url = false) {
171177
}
172178

173179
$parameters = self :: match($url);
180+
$route = stripslashes($parameters['route'] ?? '');
174181

175182
if ($parameters) {
176-
$parameters['pattern'] = self :: $modules[$parameters['route']][0]['url'];
177-
$parameters = $parameters + self :: $routes[$parameters['pattern']];
183+
//$parameters['pattern'] = self :: $modules[$parameters['route']][0]['url'];
184+
$parameters = $parameters + self :: $routes[$route];
178185

179186
if (isset($parameters['edit'])) {
180187
$parameters['edit'] = self :: varReplace($parameters['edit'], $parameters);

0 commit comments

Comments
 (0)