Skip to content

Commit 73c86d3

Browse files
authored
Merge pull request #11 from opencorero/dev
Dev
2 parents d5e0d61 + fc4a2a0 commit 73c86d3

File tree

8 files changed

+53
-32
lines changed

8 files changed

+53
-32
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818
"nwidart/laravel-modules": "^4.1",
1919
"rachidlaasri/laravel-installer": "^4.0",
2020
"symfony/yaml": "^3.0",
21-
"laravelcollective/html": "~5.0"
21+
"laravelcollective/html": "~5.0",
22+
"arcanedev/log-viewer": "^4.7",
23+
"studio/laravel-totem": "^5.3"
2224
},
2325
"require-dev": {
24-
"arcanedev/log-viewer": "^4.7",
2526
"barryvdh/laravel-debugbar": "^3.2",
2627
"beyondcode/laravel-dump-server": "^1.0",
2728
"facade/ignition": "^1.0",
2829
"filp/whoops": "^2.0",
2930
"fzaninotto/faker": "^1.4",
3031
"mockery/mockery": "^1.0",
3132
"nunomaduro/collision": "^3.0",
32-
"phpunit/phpunit": "^7.5",
33-
"studio/laravel-totem": "^5.3"
33+
"phpunit/phpunit": "^7.5"
3434
},
3535
"config": {
3636
"platform": {

config/app.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
|
8181
*/
8282

83-
'locale' => 'en',
83+
'locale' => env('APP_LOCALE', 'en'),
8484

8585
/*
8686
|--------------------------------------------------------------------------
@@ -93,7 +93,7 @@
9393
|
9494
*/
9595

96-
'fallback_locale' => 'en',
96+
'fallback_locale' => env('APP_LOCALE_FALLBACK', 'en'),
9797

9898
/*
9999
|--------------------------------------------------------------------------
121 Bytes
Binary file not shown.

opencart-module/2.x/upload/admin/controller/startup/opencore.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@ public function before_view($route, &$data)
6767
$data['permissions'][] = 'core/*';
6868

6969
//get modules
70-
$modules = app('modules')->all();
71-
foreach ($modules as $module) {
72-
if ($module->enabled()) {
73-
$data['permissions'][] = strtolower($module->getName()) . '/*';
70+
if (is_dir(realpath(DIR_APPLICATION . '../core/modules'))) {
71+
foreach (glob(realpath(DIR_APPLICATION . '../core/modules') . '/*/module.json') as $path) {
72+
$moduleManifest = json_decode(file_get_contents($path));
73+
if (!json_last_error() && !empty($moduleManifest->active)) {
74+
$moduleName = strtolower(basename(str_replace('/module.json', '', $path)));
75+
$data['permissions'][] = $moduleName . '/*';
76+
}
7477
}
7578
}
7679
break;
107 Bytes
Binary file not shown.

opencart-module/3.x/upload/admin/controller/startup/opencore.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@ public function before_view($route, &$data)
6767
$data['permissions'][] = 'core/*';
6868

6969
//get modules
70-
$modules = app('modules')->all();
71-
foreach ($modules as $module) {
72-
if ($module->enabled()) {
73-
$data['permissions'][] = strtolower($module->getName()) . '/*';
70+
if (is_dir(realpath(DIR_APPLICATION . '../core/modules'))) {
71+
foreach (glob(realpath(DIR_APPLICATION . '../core/modules') . '/*/module.json') as $path) {
72+
$moduleManifest = json_decode(file_get_contents($path));
73+
if (!json_last_error() && !empty($moduleManifest->active)) {
74+
$moduleName = strtolower(basename(str_replace('/module.json', '', $path)));
75+
$data['permissions'][] = $moduleName . '/*';
76+
}
7477
}
7578
}
7679
break;

support/Helper.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,20 @@ function token_field()
5757
}
5858
}
5959

60-
if (! function_exists('module_version')) {
60+
if (!function_exists('module_version')) {
6161
function module_version(\Nwidart\Modules\Laravel\Module $module)
6262
{
6363
return $module->version;
6464
}
6565
}
66+
67+
if (!function_exists('module_asset')) {
68+
function module_asset($asset)
69+
{
70+
$url = Module::asset($asset);
71+
72+
$url = substr_replace($url, 'https://', 0, 2);
73+
74+
return $url;
75+
}
76+
}

support/Opencart/Startup.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@
1414
}
1515

1616
if (!defined('OPENCORE_VERSION')) {
17-
define('OPENCORE_VERSION', '1.2.3');
17+
define('OPENCORE_VERSION', '1.2.2');
1818
}
1919

2020
require_once __DIR__ . '/../../Framework.php';
2121

22+
use Exception;
2223
use Opencore\Framework;
24+
use Symfony\Component\Routing\Matcher\UrlMatcher;
25+
use Symfony\Component\Routing\RequestContext;
26+
use Symfony\Component\Routing\Route;
27+
use Symfony\Component\Routing\RouteCollection;
2328

2429
class Startup extends \Controller
2530
{
@@ -130,13 +135,14 @@ public function checkOpenCoreRoute()
130135
$allowed_routes = [];
131136

132137
if (!$allowed_routes = $this->cache->get('opencore_routes')) {
133-
$query = $this->db->query("SELECT method, uri FROM `" . DB_PREFIX . "opencore_routes` WHERE `status` = '1' ORDER BY uri");
138+
$query = $this->db->query("SELECT method, name, uri FROM `opencore_routes` WHERE `status` = '1' ORDER BY uri");
134139

135140
if (!$query->num_rows)
136141
return false;
137142

138143
foreach ($query->rows as $route) {
139-
$allowed_routes[$route['method']][] = $route['uri'];
144+
$name = $route['name'] ?? $route['uri'];
145+
$allowed_routes[$route['method']][$name] = $route['uri'];
140146
}
141147

142148
/**
@@ -147,22 +153,20 @@ public function checkOpenCoreRoute()
147153

148154
$requestMethod = $_SERVER['REQUEST_METHOD'];
149155
if (!empty($allowed_routes[$requestMethod])) {
150-
if (in_array($this->route, $allowed_routes[$requestMethod])) {
151-
return true;
156+
$routes = new RouteCollection();
157+
$context = new RequestContext('/');
158+
159+
foreach ($allowed_routes[$requestMethod] as $name => $routeUri) {
160+
$routeInstance = new Route($routeUri);
161+
$routes->add($name, $routeInstance);
152162
}
153163

154-
foreach ($allowed_routes[$requestMethod] as $route) {
155-
if (preg_match_all('/\{(.*?)\??\}/', $route, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
156-
foreach ($matches[0] as $match) {
157-
$remainingUri = substr($this->route, $match[1], strlen($this->route));
158-
$getSamePartFromRoute = strtok($remainingUri, '/');
159-
$route = substr_replace($route, $getSamePartFromRoute, $match[1], strlen($match[0]));
160-
}
161-
162-
if ($route === $this->route) {
163-
return true;
164-
}
165-
}
164+
$matcher = new UrlMatcher($routes, $context);
165+
166+
try {
167+
return $matcher->match('/'.$this->route);
168+
} catch(Exception $e) {
169+
return false;
166170
}
167171
}
168172

0 commit comments

Comments
 (0)