diff --git a/.htaccess b/.htaccess index 68cde7b..87d5f09 100644 --- a/.htaccess +++ b/.htaccess @@ -1,3 +1,7 @@ + + #For security reasons OpenCore needs mod_rewrite activated! + Deny from all + Options -MultiViews -Indexes @@ -9,16 +13,16 @@ RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d - RewriteRule ^(.*)/$ /$1 [L,R=301] + RewriteCond %{REQUEST_URI} (.+)/$ + RewriteRule ^ %1 [L,R=301] - RewriteCond %{REQUEST_URI} !(\.ico|\.gif|\.jpg|\.jpeg|\.png|\.js|\.css|\.svg|robots\.txt)$ [NC] - RewriteCond %{REQUEST_FILENAME} !-d - RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^ index.php [L] + RewriteCond %{REQUEST_URI} !^/public/ + RewriteRule ^(.*)$ public/$1 [L,NC] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !^/public/ - RewriteRule ^(.*)$ public/$1 [L,NC] + RewriteRule ^ public/index.php [L] diff --git a/Framework.php b/Framework.php index 1dd793e..5f2aba0 100644 --- a/Framework.php +++ b/Framework.php @@ -32,6 +32,7 @@ class Framework private $request; private $kernel; private $registry; + private $routes_checked = []; public function __construct() { @@ -116,14 +117,8 @@ public function handle($registry = null) * @param object $registry * @return bool */ - public function checkRoute($route) + public function checkRoute($route, &$output) { - //force admin route in case the request comes from admin side - if(defined('HTTPS_CATALOG')) { - $_SERVER['SCRIPT_NAME'] = str_replace(basename(DIR_APPLICATION) . '/', '', $_SERVER['SCRIPT_NAME']); - - $route = 'admin/' . $route; - } // Strip query string (?foo=bar) and decode URI if (false !== $pos = strpos($route, '?')) { @@ -131,8 +126,36 @@ public function checkRoute($route) } $route = rawurldecode($route); + /** + * Avoid multi chekings for the same controller + */ + if(isset($this->routes_checked[$route])) { + return null; + } else { + $this->routes_checked[$route] = true; + } + $this->request = \Illuminate\Http\Request::capture(); + /** + * force admin route in case the request comes from admin side + */ + if(defined('HTTPS_CATALOG')) { + $appBaseName = basename(DIR_APPLICATION) . '/'; + $route = $appBaseName . $route; + + $serverName = $this->request->server->get('SCRIPT_NAME'); + $this->request->server->set('SCRIPT_NAME', str_replace($appBaseName, '', $serverName)); + } + + /** + * Change URI for partial loaded controllers like common/header, common/footer etc... + * in order to be able to override them + */ + if($output !== false) { + $this->request->server->set('REQUEST_URI', $route); + } + return $this->app->router->has($route) || $this->request->is($route . '*'); } } diff --git a/README.md b/README.md index e2f00d1..94bf34c 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ MIT license. Please see the [license file](LICENSE) for more information. ## TODO -* remove routes from other initiated vendors to be accessible -> logs & totem! URGENT! + * display jobs & failed_jobs lists in developer module * admin user permission checked on modify | POST / PUT / DELETE * move occore user permission changes inside OpenCore project in a separate method diff --git a/config/log-viewer.php b/config/log-viewer.php new file mode 100644 index 0000000..a42ba9e --- /dev/null +++ b/config/log-viewer.php @@ -0,0 +1,148 @@ + storage_path('logs'), + + /* ----------------------------------------------------------------- + | Log files pattern + | ----------------------------------------------------------------- + */ + + 'pattern' => [ + 'prefix' => Filesystem::PATTERN_PREFIX, // 'laravel-' + 'date' => Filesystem::PATTERN_DATE, // '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]' + 'extension' => Filesystem::PATTERN_EXTENSION, // '.log' + ], + + /* ----------------------------------------------------------------- + | Locale + | ----------------------------------------------------------------- + | Supported locales : + | 'auto', 'ar', 'bg', 'de', 'en', 'es', 'et', 'fa', 'fr', 'hu', 'hy', 'id', 'it', 'ja', 'ko', 'nl', + | 'pl', 'pt-BR', 'ro', 'ru', 'sv', 'th', 'tr', 'zh-TW', 'zh' + */ + + 'locale' => 'auto', + + /* ----------------------------------------------------------------- + | Theme + | ----------------------------------------------------------------- + | Supported themes : + | 'bootstrap-3', 'bootstrap-4' + | Make your own theme by adding a folder to the views directory and specifying it here. + */ + + 'theme' => 'bootstrap-3', + + /* ----------------------------------------------------------------- + | Route settings + | ----------------------------------------------------------------- + */ + + 'route' => [ + 'enabled' => false, + + 'attributes' => [ + 'prefix' => 'admin/developer/log-viewer', + + 'middleware' => env('ARCANEDEV_LOGVIEWER_MIDDLEWARE') ? explode(',', env('ARCANEDEV_LOGVIEWER_MIDDLEWARE')) : 'App\Http\Middleware\AdminMiddleware', + ], + ], + + /* ----------------------------------------------------------------- + | Log entries per page + | ----------------------------------------------------------------- + | This defines how many logs & entries are displayed per page. + */ + + 'per-page' => 30, + + /* ----------------------------------------------------------------- + | LogViewer's Facade + | ----------------------------------------------------------------- + */ + + 'facade' => 'LogViewer', + + /* ----------------------------------------------------------------- + | Download settings + | ----------------------------------------------------------------- + */ + + 'download' => [ + 'prefix' => 'laravel-', + + 'extension' => 'log', + ], + + /* ----------------------------------------------------------------- + | Menu settings + | ----------------------------------------------------------------- + */ + + 'menu' => [ + 'filter-route' => 'developer::admin.logs.filter', + + 'icons-enabled' => true, + ], + + /* ----------------------------------------------------------------- + | Icons + | ----------------------------------------------------------------- + */ + + 'icons' => [ + /** + * Font awesome >= 4.3 + * http://fontawesome.io/icons/ + */ + 'all' => 'fa fa-fw fa-list', // http://fontawesome.io/icon/list/ + 'emergency' => 'fa fa-fw fa-bug', // http://fontawesome.io/icon/bug/ + 'alert' => 'fa fa-fw fa-bullhorn', // http://fontawesome.io/icon/bullhorn/ + 'critical' => 'fa fa-fw fa-heartbeat', // http://fontawesome.io/icon/heartbeat/ + 'error' => 'fa fa-fw fa-times-circle', // http://fontawesome.io/icon/times-circle/ + 'warning' => 'fa fa-fw fa-exclamation-triangle', // http://fontawesome.io/icon/exclamation-triangle/ + 'notice' => 'fa fa-fw fa-exclamation-circle', // http://fontawesome.io/icon/exclamation-circle/ + 'info' => 'fa fa-fw fa-info-circle', // http://fontawesome.io/icon/info-circle/ + 'debug' => 'fa fa-fw fa-life-ring', // http://fontawesome.io/icon/life-ring/ + ], + + /* ----------------------------------------------------------------- + | Colors + | ----------------------------------------------------------------- + */ + + 'colors' => [ + 'levels' => [ + 'empty' => '#D1D1D1', + 'all' => '#8A8A8A', + 'emergency' => '#B71C1C', + 'alert' => '#D32F2F', + 'critical' => '#F44336', + 'error' => '#FF5722', + 'warning' => '#FF9100', + 'notice' => '#4CAF50', + 'info' => '#1976D2', + 'debug' => '#90CAF9', + ], + ], + + /* ----------------------------------------------------------------- + | Strings to highlight in stack trace + | ----------------------------------------------------------------- + */ + + 'highlight' => [ + '^#\d+', + '^Stack trace:', + ], + +]; diff --git a/config/totem.php b/config/totem.php new file mode 100644 index 0000000..571f422 --- /dev/null +++ b/config/totem.php @@ -0,0 +1,236 @@ + [ + [ + 'label' => 'Every Minute', + 'interval' => 'everyMinute', + 'parameters' => false, + ], + [ + 'label' => 'Every Five Minutes', + 'interval' => 'everyFiveMinutes', + 'parameters' => false, + ], + [ + 'label' => 'Every Ten Minutes', + 'interval' => 'everyTenMinutes', + 'parameters' => false, + ], + [ + 'label' => 'Every Thirty Minutes', + 'interval' => 'everyThirtyMinutes', + 'parameters' => false, + ], + [ + 'label' => 'Hourly', + 'interval' => 'hourly', + 'parameters' => false, + ], + [ + 'label' => 'Hourly at', + 'interval' => 'hourlyAt', + 'parameters' => [ + [ + 'label' => 'At', + 'name' => 'at', + 'type' => 'number', + 'min' => '0', + 'max' => '59', + ], + ], + ], + [ + 'label' => 'Daily', + 'interval' => 'daily', + 'parameters' => false, + ], + [ + 'label' => 'Daily at', + 'interval' => 'dailyAt', + 'parameters' => [ + [ + 'label' => 'At', + 'name' => 'at', + 'type' => 'time', + ], + ], + ], + [ + 'label' => 'Twice Daily', + 'interval' => 'twiceDaily', + 'parameters' => [ + [ + 'label' => 'First', + 'name' => 'at', + 'type' => 'time', + ], + [ + 'label' => 'Second', + 'name' => 'second_at', + 'type' => 'time', + ], + ], + ], + [ + 'label' => 'Weekly', + 'interval' => 'weekly', + 'parameters' => false, + ], + [ + 'label' => 'Weekly On', + 'interval' => 'weeklyOn', + 'parameters' => [ + [ + 'label' => 'On', + 'name' => 'on', + 'type' => 'number', + 'min' => '1', + 'max' => '31', + ], + [ + 'label' => 'At', + 'name' => 'at', + 'type' => 'time', + ], + ], + ], + [ + 'label' => 'Monthly', + 'interval' => 'monthly', + 'parameters' => false, + ], + [ + 'label' => 'Monthly On', + 'interval' => 'monthlyOn', + 'parameters' => [ + [ + 'label' => 'On', + 'name' => 'on', + 'type' => 'number', + 'max' => '', + ], + [ + 'label' => 'At', + 'name' => 'at', + 'type' => 'time', + ], + ], + ], + [ + 'label' => 'Twice Monthly', + 'interval' => 'twiceMonthly', + 'parameters' => [ + [ + 'label' => 'First', + 'name' => 'on', + 'type' => 'number', + ], + [ + 'label' => 'Second', + 'name' => 'second_at', + 'type' => 'text', + ], + ], + ], + [ + 'label' => 'Quarterly', + 'interval' => 'quarterly', + 'parameters' => false, + ], + [ + 'label' => 'Yearly', + 'interval' => 'yearly', + 'parameters' => false, + ], + [ + 'label' => 'Weekdays', + 'interval' => 'weekdays', + 'parameters' => false, + ], + [ + 'label' => 'Every Sunday', + 'interval' => 'sundays', + 'parameters' => false, + ], + [ + 'label' => 'Every Monday', + 'interval' => 'mondays', + 'parameters' => false, + ], + [ + 'label' => 'Every Tuesday', + 'interval' => 'tuesdays', + 'parameters' => false, + ], + [ + 'label' => 'Every Wednesday', + 'interval' => 'wednesdays', + 'parameters' => false, + ], + [ + 'label' => 'Every Thursday', + 'interval' => 'thursdays', + 'parameters' => false, + ], + [ + 'label' => 'Every Friday', + 'interval' => 'fridays', + 'parameters' => false, + ], + [ + 'label' => 'Every Saturday', + 'interval' => 'saturdays', + 'parameters' => false, + ], + [ + 'label' => 'Between', + 'interval' => 'between', + 'parameters' => [ + [ + 'label' => 'Start', + 'name' => 'start', + 'type' => 'time', + ], + [ + 'label' => 'End', + 'name' => 'end', + 'type' => 'time', + ], + ], + ], + [ + 'label' => 'Unless Between', + 'interval' => 'unlessBetween', + 'parameters' => [ + [ + 'label' => 'Start', + 'name' => 'start', + 'type' => 'time', + ], + [ + 'label' => 'End', + 'name' => 'end', + 'type' => 'time', + ], + ], + ], + ], + 'web' => [ + 'middleware' => ['web', 'App\Http\Middleware\AdminMiddleware'], + ], + 'api' => [ + 'middleware' =>['api', 'App\Http\Middleware\AdminMiddleware'], + ], + 'table_prefix' => env('TOTEM_TABLE_PREFIX', 'opencore_'), + 'artisan' => [ + 'command_filter' => [], + 'whitelist' => true, + ], + 'database_connection' => env('TOTEM_DATABASE_CONNECTION'), + + 'broadcasting' => [ + 'enabled' => env('TOTEM_BROADCASTING_ENABLED', true), + 'channel' => env('TOTEM_BROADCASTING_CHANNEL', 'task.events'), + ], +]; diff --git a/modules/Developer/Config/log-viewer.php b/modules/Developer/Config/log-viewer.php index 48f3a39..a42ba9e 100644 --- a/modules/Developer/Config/log-viewer.php +++ b/modules/Developer/Config/log-viewer.php @@ -48,7 +48,7 @@ */ 'route' => [ - 'enabled' => true, + 'enabled' => false, 'attributes' => [ 'prefix' => 'admin/developer/log-viewer', diff --git a/modules/Developer/Providers/DeveloperServiceProvider.php b/modules/Developer/Providers/DeveloperServiceProvider.php index 3126d65..9c80d4e 100644 --- a/modules/Developer/Providers/DeveloperServiceProvider.php +++ b/modules/Developer/Providers/DeveloperServiceProvider.php @@ -29,7 +29,7 @@ public function boot() $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); //avoid errors when working with local machine composer & remote server files - if(defined('TOTEM_DATABASE_CONNECTION') && class_exists('\Studio\Totem\Task')) { + if (defined('TOTEM_DATABASE_CONNECTION') && class_exists('\Studio\Totem\Task')) { \Studio\Totem\Task::observe(\Modules\Developer\Observers\TaskObserver::class); } } @@ -55,13 +55,22 @@ public function register() protected function registerConfig() { $this->publishes([ - __DIR__.'/../Config/config.php' => config_path('developer.php'), - __DIR__.'/../Config/log-viewer.php' => config_path('log-viewer.php'), - __DIR__.'/../Config/totem.php' => config_path('totem.php'), + __DIR__ . '/../Config/config.php' => config_path('developer.php'), + __DIR__ . '/../Config/log-viewer.php' => config_path('log-viewer.php'), + __DIR__ . '/../Config/totem.php' => config_path('totem.php'), ], 'config'); $this->mergeConfigFrom( - __DIR__.'/../Config/config.php', 'developer' + __DIR__ . '/../Config/config.php', + 'developer' + ); + $this->mergeConfigFrom( + __DIR__ . '/../Config/log-viewer.php', + 'log-viewer' + ); + $this->mergeConfigFrom( + __DIR__ . '/../Config/totem.php', + 'totem' ); } @@ -74,11 +83,11 @@ public function registerViews() { $viewPath = resource_path('views/modules/developer'); - $sourcePath = __DIR__.'/../Resources/views'; + $sourcePath = __DIR__ . '/../Resources/views'; $this->publishes([ $sourcePath => $viewPath - ],'views'); + ], 'views'); $this->loadViewsFrom(array_merge(array_map(function ($path) { return $path . '/modules/developer'; @@ -97,7 +106,7 @@ public function registerTranslations() if (is_dir($langPath)) { $this->loadTranslationsFrom($langPath, 'developer'); } else { - $this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', 'developer'); + $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'developer'); } } @@ -108,7 +117,7 @@ public function registerTranslations() */ public function registerFactories() { - if (! app()->environment('production')) { + if (!app()->environment('production')) { app(Factory::class)->load(__DIR__ . '/../Database/factories'); } } diff --git a/modules/Developer/changelog.yml b/modules/Developer/changelog.yml index bfa5567..d3fb6f8 100644 --- a/modules/Developer/changelog.yml +++ b/modules/Developer/changelog.yml @@ -1,5 +1,9 @@ url: https://github.com/opencorero/developer-module/releases/tag/ versions: + "1.0.1": + changed: + - changed routes of arcanedev/log-viewer + - changed routes for totem "1.0.0": added: - logs section dashboard diff --git a/modules/Example/Http/Controllers/Admin/ExampleController.php b/modules/Example/Http/Controllers/Admin/ExampleController.php index 748ece1..64194e1 100644 --- a/modules/Example/Http/Controllers/Admin/ExampleController.php +++ b/modules/Example/Http/Controllers/Admin/ExampleController.php @@ -52,4 +52,15 @@ public function destroy(Request $request, $id) return redirect(route('example::admin.index')); } + + /** + * Example method for replacing admin common/column_left partial controller/view + * You can rewrite any default route based on routes/admin.php + * If the route is already used by the system, that means you will override it + * + * @return Response object + */ + public function commonColumnLeftReplace() { + return response("COLUMN LEFT REPLACE EXAMPLE"); + } } diff --git a/modules/Example/Http/Controllers/Catalog/ExampleController.php b/modules/Example/Http/Controllers/Catalog/ExampleController.php index a3b61cf..0ec4442 100644 --- a/modules/Example/Http/Controllers/Catalog/ExampleController.php +++ b/modules/Example/Http/Controllers/Catalog/ExampleController.php @@ -20,4 +20,15 @@ function index() { function json() { return response()->json(['name' => 'OpenCore', 'by' => 'Aweb Design']); } + + /** + * Example method for replacing common/column_left or any other partia content + * You can rewrite any default route based on routes/catalog.php. + * If the route is already used by the system, that means you will override it + * + * @return Response object + */ + public function commonColumnLeftReplace() { + return response("COLUMN LEFT REPLACE EXAMPLE"); + } } diff --git a/modules/Example/Routes/admin.php b/modules/Example/Routes/admin.php index 4f3b647..3e9523a 100644 --- a/modules/Example/Routes/admin.php +++ b/modules/Example/Routes/admin.php @@ -14,3 +14,15 @@ $router->get('example', 'ExampleController@index')->name('index'); $router->post('example/store', 'ExampleController@store')->name('store'); $router->delete('example/{id}', 'ExampleController@destroy')->name('destroy'); + +/** + * Example overriding common/column_left controller + * Uncomment the following line if you whant to test it + */ +//$router->get('common/column_left', 'ExampleController@commonColumnLeftReplace')->name('common.column_left'); + +/** + * Example overriding catalog/category list section + * Uncomment the following line if you whant to test it + */ +//$router->get('catalog/category', 'ExampleController@index')->name('catalog.category'); diff --git a/modules/Example/Routes/catalog.php b/modules/Example/Routes/catalog.php index 1e5e124..74330ec 100644 --- a/modules/Example/Routes/catalog.php +++ b/modules/Example/Routes/catalog.php @@ -18,3 +18,11 @@ $router->get('example/json', [ 'as' => 'example.json', 'uses' => 'ExampleController@json' ]); + +/** + * Example overriding common/column_left controller + * Uncomment the following line if you whant to test it + */ +/*$router->get('common/column_left', [ + 'as' => 'common.column_left', 'uses' => 'ExampleController@commonColumnLeftReplace' +]);*/ diff --git a/modules/Example/changelog.yml b/modules/Example/changelog.yml index c6b2fc5..63ba639 100644 --- a/modules/Example/changelog.yml +++ b/modules/Example/changelog.yml @@ -1,9 +1,12 @@ url: https://github.com/opencorero/example-module/releases/tag/ versions: - "1.0.0": - added: - - Using new feature - changed: - - Updating the module structure - removed: - - Old home file + "1.0.1": + added: + - Example for overriding default opencart routes added + "1.0.0": + added: + - Using new feature + changed: + - Updating the module structure + removed: + - Old home file diff --git a/opencart-module/opencore.ocmod.zip b/opencart-module/opencore.ocmod.zip index 02d87b8..f2463e8 100644 Binary files a/opencart-module/opencore.ocmod.zip and b/opencart-module/opencore.ocmod.zip differ diff --git a/opencart-module/upload/admin/controller/extension/module/opencore.php b/opencart-module/upload/admin/controller/extension/module/opencore.php index 8f0ebb9..9350626 100644 --- a/opencart-module/upload/admin/controller/extension/module/opencore.php +++ b/opencart-module/upload/admin/controller/extension/module/opencore.php @@ -61,8 +61,8 @@ public function install() $this->refreshOcmod(); $this->installEvent('opencore_admin_menu', 'startup/opencore/before_view', 'admin/view/*/before'); - $this->installEvent('opencore_admin_before_controller', 'startup/opencore/before_controller', 'admin/controller/*/before'); - $this->installEvent('opencore_catalog_before_controller', 'startup/opencore/before_controller', 'catalog/controller/*/before'); + $this->installEvent('opencore_admin_before_c', 'startup/opencore/before_controller', 'admin/controller/*/before'); + $this->installEvent('opencore_catalog_before_c', 'startup/opencore/before_controller', 'catalog/controller/*/before'); $this->addPermissions('extension/module/opencore', ['access', 'modify']); $this->addPermissions('core/*', ['access', 'modify']); @@ -78,8 +78,8 @@ public function uninstall() $this->refreshOcmod(); $this->removeEvent('opencore_admin_menu'); - $this->removeEvent('opencore_admin_before_controller'); - $this->removeEvent('opencore_catalog_before_controller'); + $this->removeEvent('opencore_admin_before_c'); + $this->removeEvent('opencore_catalog_before_c'); $this->removePermissions('extension/module/opencore', ['access', 'modify']); $this->removePermissions('core/*', ['access', 'modify']); diff --git a/opencart-module/upload/admin/controller/startup/opencore.php b/opencart-module/upload/admin/controller/startup/opencore.php index e2f3df5..b01d755 100644 --- a/opencart-module/upload/admin/controller/startup/opencore.php +++ b/opencart-module/upload/admin/controller/startup/opencore.php @@ -25,18 +25,13 @@ class ControllerStartupOpencore extends Startup * @param array $data * @return string */ - function before_controller($route, &$data) + function before_controller($route, &$data, &$output = false) { /** - * we are using $this->request->get['route'] instead of $route because on $route some characters like dash ("-") are removed + * Check if a laravel route exists and if so execute it + * else return NULL */ - if (!empty($this->request->get['route']) && preg_replace('/[^a-zA-Z0-9_\/]/', '', (string) $this->request->get['route']) == $route) { - $route = $this->request->get['route']; - } - - if ($this->checkOpenCoreRoute($route, $data)) { - return $this->response(); - } + return $this->executeIfRouteExists($route, $data, $output); /** * in case the view\/*\/before event is not activated by default we can call @@ -56,7 +51,7 @@ public function before_view($route, &$data) return; } - switch($route) { + switch ($route) { case 'common/column_left': //adding entries into admin menu for OpenCore panel $data['menus'][] = [ @@ -66,7 +61,7 @@ public function before_view($route, &$data) 'href' => $this->url->link('core/home', $this->getTokenStr()), 'children' => [] ]; - break; + break; case 'user/user_group_form': //adding permissions into admin user/permissions page for OpenCore panel $data['permissions'][] = 'core/*'; @@ -74,17 +69,18 @@ public function before_view($route, &$data) //get modules $modules = app('modules')->all(); foreach ($modules as $module) { - if($module->enabled()) { + if ($module->enabled()) { $data['permissions'][] = strtolower($module->getName()) . '/*'; } } - break; + break; } $this->booted($route); } - private function booted($route) { + private function booted($route) + { $this->booted[$route] = true; } } diff --git a/opencart-module/upload/catalog/controller/startup/opencore.php b/opencart-module/upload/catalog/controller/startup/opencore.php index 7aab0a4..6f82042 100644 --- a/opencart-module/upload/catalog/controller/startup/opencore.php +++ b/opencart-module/upload/catalog/controller/startup/opencore.php @@ -25,22 +25,17 @@ class ControllerStartupOpencore extends Startup * @param array $data * @return string */ - function before_controller($route, &$data) + function before_controller($route, &$data, &$output = false) { /* if (self::$booted) { return false; } */ /** - * we are using $this->request->get['route'] instead of $route because on $route some characters like dash ("-") are removed + * Check if a laravel route exists and if so execute it + * else return NULL */ - if (!empty($this->request->get['route']) && preg_replace('/[^a-zA-Z0-9_\/]/', '', (string) $this->request->get['route']) == $route) { - $route = $this->request->get['route']; - } - - if ($this->checkOpenCoreRoute($route, $data)) { - return $this->response(); - } + return $this->executeIfRouteExists($route, $data, $output); /** * in case the view\/*\/before event is not activated by default we can call diff --git a/support/Opencart/OcCore.php b/support/Opencart/OcCore.php index 8425d72..8e68c55 100644 --- a/support/Opencart/OcCore.php +++ b/support/Opencart/OcCore.php @@ -32,7 +32,7 @@ public static function getInstance() return $this->registry; }*/ - public function routeUrl($url) + public function removeIndexAndRouteParam($url) { if (strstr($url, 'index.php?route=')) { $url = str_replace('index.php?route=common/home', '', $url); //replace home url for catalog @@ -48,15 +48,20 @@ public function routeUrl($url) public function routeCatalogSeoUrl() { - if (isset($this->request->get['_route_']) && $this->request->get['route'] == 'error/not_found') { - $newRoute = $this->request->get['_route_']; - $this->request->get['route'] = $newRoute; - $this->request->has_route[$newRoute] = true; - - return true; + /** + * Check for Ceo Mega Packe module + */ + if (!$this->config->get('smp_is_install')) { + + /** + * check if not found, maybe the page exists in Laravel system + */ + if (isset($this->request->get['_route_']) && isset($this->request->get['route']) && $this->request->get['route'] == 'error/not_found') { + $newRoute = $this->request->get['_route_']; + $this->request->get['route'] = $newRoute; + $this->request->has_route[$newRoute] = true; + } } - - return false; } public function isRouted($route) diff --git a/support/Opencart/Startup.php b/support/Opencart/Startup.php index 5fc0ee6..208bdfc 100644 --- a/support/Opencart/Startup.php +++ b/support/Opencart/Startup.php @@ -14,7 +14,7 @@ } if (!defined('OPENCORE_VERSION')) { - define('OPENCORE_VERSION', '1.0.0'); + define('OPENCORE_VERSION', '1.1.0'); } require_once __DIR__ . '/../../vendor/autoload.php'; @@ -36,13 +36,41 @@ function __construct($registry) } /** - * Run function + * Execute Laravel if route exists * - * @execute Framewrok + * @param string $route + * @param array &$data + * @param string &$output */ - public function run() + public function executeIfRouteExists($route, &$data, &$output = false) { - Framework::getInstance()->run(); + /** + * we are using $this->request->get['route'] instead of $route because on $route some characters like dash ("-") are removed + */ + if (!empty($this->request->get['route']) && preg_replace('/[^a-zA-Z0-9_\/]/', '', (string) $this->request->get['route']) == $route) { + $route = $this->request->get['route']; + } + + if ($this->checkOpenCoreRoute($route, $data, $output)) { + $response = $this->response(); + + if($output === false) { + /** + * means is a controller request which means we need to use default setOutput() + */ + $this->response->setOutput($response); + return true; + } else { + /** + * the request is done using the loader method and $output need to be populated + * Check system/engine/loader.php + */ + $output = $response; + return false; + } + } + + return null; } /** @@ -50,31 +78,35 @@ public function run() * * @param string $route */ - public function checkOpenCoreRoute($route, &$data) + public function checkOpenCoreRoute($route, &$data, &$output) { $this->route = $route; $this->data = $data; + /* We should add a dinamyc ignore list here */ - if (Framework::getInstance()->checkRoute($route)) { + if (Framework::getInstance()->checkRoute($route, $output)) { return Framework::getInstance()->handle(self::$_registry); } } + /** + * Run function + * + * @execute Framewrok + */ + public function run() + { + Framework::getInstance()->run(); + } + /** * Framework Response function */ public function response() { - $response = Framework::getInstance()->getResponse(); - - if ((isset($this->request->get['route']) && $this->request->get['route'] == $this->route) || (!isset($this->request->get['route']) && in_array($this->route, ['/', 'common/home']))) { - echo $response; - return false; - } else { - return $response; - } + return Framework::getInstance()->getResponse(); } /** diff --git a/support/Resources/opencore.ocmod.xml b/support/Resources/opencore.ocmod.xml index 24e82bd..2d162fd 100644 --- a/support/Resources/opencore.ocmod.xml +++ b/support/Resources/opencore.ocmod.xml @@ -22,7 +22,7 @@ use OpenCore\Support\OpenCart\OcCore; - routeUrl($url);]]> + removeIndexAndRouteParam($url);]]> @@ -37,10 +37,17 @@ use OpenCore\Support\OpenCart\OcCore; - - request->get['route'])) {]]> - routeCatalogSeoUrl();]]> + + + oldSeoUrlindex(); + + $this->routeCatalogSeoUrl(); + } + + public function oldSeoUrlindex() { + ]]> @@ -56,12 +63,9 @@ use OpenCore\Support\OpenCart\OcCore; - - - routeCatalogSeoUrl()) { - return true; //we have found a OpenCore match so we will ignore the rest of SeoPack - }]]> + + request->get['route'] == 'error/not_found' ) {]]> + routeCatalogSeoUrl();]]> request->get['route'] );]]>