From 47f236cd514d4a448d8b7ebc0fed3c4606eb418f Mon Sep 17 00:00:00 2001 From: Timot Tarjani Date: Thu, 9 Jan 2025 19:39:50 +0100 Subject: [PATCH 1/4] Refactoring app structure --- app/Console/Commands/InstallCommand.php | 2 +- app/Controllers/InstallController.php | 2 +- app/Controllers/PageController.php | 4 +- app/Controllers/SearchController.php | 2 +- app/Controllers/ThemeController.php | 15 ++-- app/Controllers/WebsiteController.php | 10 +-- app/Http/Middleware/WebsiteMiddleware.php | 2 +- app/{Libs => Interfaces}/PluginInterface.php | 2 +- app/Libs/BladeThemeEngine.php | 80 ----------------- app/Libs/Controller.php | 52 ----------- app/Libs/ViewResolver.php | 61 ------------- app/Model/Plugin.php | 2 +- app/Providers/ThemeServiceProvider.php | 2 +- app/Services/BladeThemeEngine.php | 86 +++++++++++++++++++ app/{Libs => Services}/DotEnvGenerator.php | 2 +- app/{Libs => Services}/PluginManager.php | 4 +- app/{Libs => Services}/SearchEngine.php | 2 +- app/{Libs => Services}/ShortCode.php | 2 +- app/{Libs => Services}/Theme.php | 2 +- app/{Libs => Services}/ThemeEngine.php | 4 +- app/{Helpers => Services}/Website.php | 2 + config/app.php | 1 + resources/tests/unit/SearchEngineTest.php | 6 +- resources/tests/unit/WidgetResolverTest.php | 4 +- .../app/Controllers/StartController.php | 16 ++-- themes/TheWright/header.php | 2 +- 26 files changed, 132 insertions(+), 237 deletions(-) rename app/{Libs => Interfaces}/PluginInterface.php (95%) delete mode 100644 app/Libs/BladeThemeEngine.php delete mode 100644 app/Libs/Controller.php delete mode 100644 app/Libs/ViewResolver.php create mode 100644 app/Services/BladeThemeEngine.php rename app/{Libs => Services}/DotEnvGenerator.php (95%) rename app/{Libs => Services}/PluginManager.php (82%) rename app/{Libs => Services}/SearchEngine.php (98%) rename app/{Libs => Services}/ShortCode.php (97%) rename app/{Libs => Services}/Theme.php (99%) rename app/{Libs => Services}/ThemeEngine.php (96%) rename app/{Helpers => Services}/Website.php (99%) diff --git a/app/Console/Commands/InstallCommand.php b/app/Console/Commands/InstallCommand.php index ad0384193..e86d9b566 100644 --- a/app/Console/Commands/InstallCommand.php +++ b/app/Console/Commands/InstallCommand.php @@ -117,7 +117,7 @@ public function handle() $this->info("3. Generating .env file..."); - $dotenv = new \App\Libs\DotEnvGenerator(); + $dotenv = new \App\Services\DotEnvGenerator(); $dotenv->addEnvVar('DB_HOST', '127.0.0.1'); $dotenv->addEnvVar('DB_CONNECTION', $database['driver']); $dotenv->addEnvVar('DB_USERNAME', $database['username']); diff --git a/app/Controllers/InstallController.php b/app/Controllers/InstallController.php index bf372cbfe..15a104cf4 100644 --- a/app/Controllers/InstallController.php +++ b/app/Controllers/InstallController.php @@ -179,7 +179,7 @@ public function step4() { if (!Session::has('error')) { - $dotenv = new \App\Libs\DotEnvGenerator(); + $dotenv = new \App\Services\DotEnvGenerator(); //TODO Inject $dotenv->addEnvVar('DB_HOST', Session::get('step2.server')); $dotenv->addEnvVar('DB_CONNECTION', Session::get('step2.db_driver')); $dotenv->addEnvVar('DB_USERNAME', Session::get('step2.username')); diff --git a/app/Controllers/PageController.php b/app/Controllers/PageController.php index 66111f173..a1fe3de83 100644 --- a/app/Controllers/PageController.php +++ b/app/Controllers/PageController.php @@ -55,7 +55,7 @@ public function create(Request $request) return view('pages.form', [ 'all_page' => Page::all(), - 'page_templates' => (new \App\Libs\Theme($request->settings['theme']))->templates(), + 'page_templates' => (new \App\Services\Theme($request->settings['theme']))->templates(), ]); } @@ -112,7 +112,7 @@ public function edit(Request $request, Page $page) return view('pages.form', [ 'page' => $page, 'all_page' => Page::all(), - 'page_templates' => (new \App\Libs\Theme($request->settings['theme']))->templates(), + 'page_templates' => (new \App\Services\Theme($request->settings['theme']))->templates(), ]); } diff --git a/app/Controllers/SearchController.php b/app/Controllers/SearchController.php index 759208379..8820a2888 100644 --- a/app/Controllers/SearchController.php +++ b/app/Controllers/SearchController.php @@ -4,7 +4,7 @@ use Illuminate\Http\Request; use Illuminate\Routing\Controller; -use App\Libs\SearchEngine; +use App\Services\SearchEngine; class SearchController extends Controller { diff --git a/app/Controllers/ThemeController.php b/app/Controllers/ThemeController.php index 5b98a3501..5bbeaaaa2 100644 --- a/app/Controllers/ThemeController.php +++ b/app/Controllers/ThemeController.php @@ -5,6 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Routing\Controller; +use App\Services\Theme; use App\Model\Settings; class ThemeController extends Controller @@ -19,9 +20,9 @@ class ThemeController extends Controller public function index(Request $request) { return view("theme.index", [ - 'active_theme' => new \App\Libs\Theme($request->settings['theme']), + 'active_theme' => new Theme($request->settings['theme']), 'all_themes' => collect(array_slice(scandir("themes"), 2))->map(function ($theme) { - return new \App\Libs\Theme($theme); + return new Theme($theme); }) ]); } @@ -48,15 +49,15 @@ public function config($slug) $websiteController = new \App\Controllers\WebsiteController(request()); $websiteController->before(); - $theme_engine = new \App\Libs\ThemeEngine(request()); - $theme_engine->setTheme(new \App\Libs\Theme(request()->settings['theme'])); + $theme_engine = new \App\Services\ThemeEngine(request()); + $theme_engine->setTheme(new Theme(request()->settings['theme'])); $theme_engine->boot(); \Website::initalize($theme_engine); return view("theme.config", [ - 'active_theme' => new \App\Libs\Theme(request()->settings['theme']), + 'active_theme' => new Theme(request()->settings['theme']), 'website_content' => $websiteController->index(request()->input('page')), ]); } @@ -73,7 +74,7 @@ public function options($theme) $theme_css->save(); } - $theme = new \App\Libs\Theme($theme == null ? request()->settings['theme'] : $theme); + $theme = new Theme($theme == null ? request()->settings['theme'] : $theme); $translations = []; @@ -90,7 +91,7 @@ public function updateTranslations($theme) if (request()->isMethod('POST')) { try { - $theme = new \App\Libs\Theme($theme == null ? request()->settings['theme'] : $theme); + $theme = new Theme($theme == null ? request()->settings['theme'] : $theme); $translations = []; diff --git a/app/Controllers/WebsiteController.php b/app/Controllers/WebsiteController.php index c89107aef..0a520f0a3 100644 --- a/app/Controllers/WebsiteController.php +++ b/app/Controllers/WebsiteController.php @@ -12,14 +12,14 @@ class WebsiteController extends Controller private $request; private $engines = [ - 'hcms' => \App\Libs\ThemeEngine::class, - 'blade' => \App\Libs\BladeThemeEngine::class, - //'twig' => \App\Libs\TwigThemeEngine::class, + 'hcms' => \App\Services\ThemeEngine::class, + 'blade' => \App\Services\BladeThemeEngine::class, + //'twig' => \App\Services\TwigThemeEngine::class, ]; private $theme; - public function __construct(Request $request, \App\Libs\Theme $theme){ + public function __construct(Request $request, \App\Services\Theme $theme){ $this->request = $request; $this->theme = $theme; } @@ -140,7 +140,7 @@ public function search() } - $search_engine = new \App\Libs\SearchEngine(); + $search_engine = new \App\Services\SearchEngine(); $search_engine->registerModel(\App\Model\Blogpost::class); $search_engine->registerModel(\App\Model\Page::class); diff --git a/app/Http/Middleware/WebsiteMiddleware.php b/app/Http/Middleware/WebsiteMiddleware.php index 2dd98b710..b97fd94e1 100644 --- a/app/Http/Middleware/WebsiteMiddleware.php +++ b/app/Http/Middleware/WebsiteMiddleware.php @@ -11,7 +11,7 @@ class WebsiteMiddleware private $widgets; - public function __construct(\App\Libs\ShortCode $shortcode_engine){ + public function __construct(\App\Services\ShortCode $shortcode_engine){ $this->widgets = $shortcode_engine; } diff --git a/app/Libs/PluginInterface.php b/app/Interfaces/PluginInterface.php similarity index 95% rename from app/Libs/PluginInterface.php rename to app/Interfaces/PluginInterface.php index 839eab0f8..c892a5607 100644 --- a/app/Libs/PluginInterface.php +++ b/app/Interfaces/PluginInterface.php @@ -1,6 +1,6 @@ request = $request; - } - - public function getTheme(){ - return $this->theme; - } - - public function setTheme(\App\Libs\Theme $theme){ - $this->theme = $theme; - } - - public function pageTemplate($page_template){ - $this->page_template = $page_template; - } - - public function defaultTemplateExists($template){ - return file_exists($this->theme->getPath().$template.'.blade.php'); - } - - public function templateExists($template){ - return file_exists($this->theme->getPath()."page_templates".DIRECTORY_SEPARATOR.$template); - } - - - public function render(array $data){ - - $default_data = [ - '_THEME_PATH' => str_replace(DIRECTORY_SEPARATOR,'/',$this->theme->getPath()), - ]; - - - \View::addNamespace('theme', base_path($this->theme->getPath())); - - - return view('theme::'.str_replace('.blade.php','',$this->page_template),array_merge($default_data,$data)); - - } - - - public function runScript($script_name){ - if($this->theme->getConfig($script_name)){ - return call_user_func($this->theme->getConfig($script_name)); - } - - return NULL; - } - - - public function render404(){ - - if($this->theme->has404Template()){ - $this->page_template = "404"; - }else{ - $this->page_template = "default.404"; - } - - } - - public function renderWebsiteDown(){ - if($this->theme->hasWebsiteDownTemplate()){ - $this->page_template = "website_down"; - }else{ - $this->page_template = "default.website_down"; - } - } - - - -} \ No newline at end of file diff --git a/app/Libs/Controller.php b/app/Libs/Controller.php deleted file mode 100644 index ff26b9811..000000000 --- a/app/Libs/Controller.php +++ /dev/null @@ -1,52 +0,0 @@ -request = $request; - - $this->view = $viewResolver; - } - - /** - * @deprecated deprecated since version 1.0.0 - */ - public function redirect($location){ - return redirect($location); - } - - /** - * @deprecated deprecated since version 1.0.0 - */ - public function redirectToSelf(){ - return redirect()->back(); - } - -} diff --git a/app/Libs/ViewResolver.php b/app/Libs/ViewResolver.php deleted file mode 100644 index fe703fb97..000000000 --- a/app/Libs/ViewResolver.php +++ /dev/null @@ -1,61 +0,0 @@ -data['title'] = null; - $this->data['css'] = Config::get('horizontcms.css'); - $this->data['js'] = Config::get('horizontcms.js'); - } - - /** - * @deprecated deprecated since version 1.0.0 - */ - public function title($title) - { - $this->data['title'] = $title; - } - - /** - * @deprecated deprecated since version 1.0.0 - */ - public function render($view_file, array $data = []) - { - - return view($view_file, array_merge($this->data, $data)); - } - - /** - * @deprecated deprecated since version 1.0.0 - */ - public function css($file) - { - $this->data['css'][] = $file; - } - - /** - * @deprecated deprecated since version 1.0.0 - */ - public function js($file) - { - $this->data['js'][] = $file; - } - -} diff --git a/app/Model/Plugin.php b/app/Model/Plugin.php index 24efd0c2d..c469bd0ef 100644 --- a/app/Model/Plugin.php +++ b/app/Model/Plugin.php @@ -181,7 +181,7 @@ public function getRegister($register, $default = null) $instance = new $plugin_namespace(); - if ($instance instanceof \App\Libs\PluginInterface) { + if ($instance instanceof \App\Interfaces\PluginInterface) { return $instance->$register(); } } diff --git a/app/Providers/ThemeServiceProvider.php b/app/Providers/ThemeServiceProvider.php index 22d09b404..232b1ca31 100644 --- a/app/Providers/ThemeServiceProvider.php +++ b/app/Providers/ThemeServiceProvider.php @@ -4,7 +4,7 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\Route; -use \App\Libs\Theme; +use \App\Services\Theme; class ThemeServiceProvider extends ServiceProvider { diff --git a/app/Services/BladeThemeEngine.php b/app/Services/BladeThemeEngine.php new file mode 100644 index 000000000..2ad2516de --- /dev/null +++ b/app/Services/BladeThemeEngine.php @@ -0,0 +1,86 @@ +request = $request; + } + + public function getTheme() + { + return $this->theme; + } + + public function setTheme(\App\Services\Theme $theme) + { + $this->theme = $theme; + } + + public function pageTemplate($page_template) + { + $this->page_template = $page_template; + } + + public function defaultTemplateExists($template) + { + return file_exists($this->theme->getPath() . $template . '.blade.php'); + } + + public function templateExists($template) + { + return file_exists($this->theme->getPath() . "page_templates" . DIRECTORY_SEPARATOR . $template); + } + + + public function render(array $data) + { + + $default_data = [ + '_THEME_PATH' => str_replace(DIRECTORY_SEPARATOR, '/', $this->theme->getPath()), + ]; + + + \View::addNamespace('theme', base_path($this->theme->getPath())); + + + return view('theme::' . str_replace('.blade.php', '', $this->page_template), array_merge($default_data, $data)); + } + + + public function runScript($script_name) + { + if ($this->theme->getConfig($script_name)) { + return call_user_func($this->theme->getConfig($script_name)); + } + + return NULL; + } + + + public function render404() + { + + if ($this->theme->has404Template()) { + $this->page_template = "404"; + } else { + $this->page_template = "default.404"; + } + } + + public function renderWebsiteDown() + { + if ($this->theme->hasWebsiteDownTemplate()) { + $this->page_template = "website_down"; + } else { + $this->page_template = "default.website_down"; + } + } +} diff --git a/app/Libs/DotEnvGenerator.php b/app/Services/DotEnvGenerator.php similarity index 95% rename from app/Libs/DotEnvGenerator.php rename to app/Services/DotEnvGenerator.php index 6e7027a76..3e7e6b76f 100644 --- a/app/Libs/DotEnvGenerator.php +++ b/app/Services/DotEnvGenerator.php @@ -1,6 +1,6 @@ theme; } - public function setTheme(\App\Libs\Theme $theme){ + public function setTheme(\App\Services\Theme $theme){ $this->theme = $theme; } diff --git a/app/Helpers/Website.php b/app/Services/Website.php similarity index 99% rename from app/Helpers/Website.php rename to app/Services/Website.php index 6a0d4877e..c6405b010 100644 --- a/app/Helpers/Website.php +++ b/app/Services/Website.php @@ -1,5 +1,7 @@ Lavary\Menu\Facade::class, 'Settings' => \App\Model\Settings::class, + 'Website' => \App\Services\Website::class, 'Zipper' => Madnest\Madzipper\Madzipper::class, ], diff --git a/resources/tests/unit/SearchEngineTest.php b/resources/tests/unit/SearchEngineTest.php index 1ef388fff..df74146bf 100644 --- a/resources/tests/unit/SearchEngineTest.php +++ b/resources/tests/unit/SearchEngineTest.php @@ -13,7 +13,7 @@ class SearchEngineTest extends TestCase protected function setUp(): void { parent::setUp(); - $this->engine = new \App\Libs\SearchEngine(); + $this->engine = new \App\Services\SearchEngine(); } /** @@ -25,7 +25,7 @@ public function testSearchEngineInitiation() { - $this->assertInstanceOf(\App\Libs\SearchEngine::class, $this->engine); + $this->assertInstanceOf(\App\Services\SearchEngine::class, $this->engine); $this->assertObjectHasProperty('searchModels', $this->engine); $this->assertObjectHasProperty('searchKey', $this->engine); @@ -56,7 +56,7 @@ public function testGetterAndSetterModel() $this->engine->registerModel(\App\Model\Page::class); $this->assertEquals(1, count($this->engine->getRegisteredModels())); - $this->assertEquals(0, count($this->engine->getResultsFor(\App\Libs\Page::class))); + $this->assertEquals(0, count($this->engine->getResultsFor(\App\Model\Page::class))); } public function testExecuteSearch() diff --git a/resources/tests/unit/WidgetResolverTest.php b/resources/tests/unit/WidgetResolverTest.php index 879606283..92519dc5f 100644 --- a/resources/tests/unit/WidgetResolverTest.php +++ b/resources/tests/unit/WidgetResolverTest.php @@ -7,7 +7,7 @@ class WidgetResolverTest extends TestCase public function testSetterAndGetter() { - $widgetResolver = new \App\Libs\ShortCode(); + $widgetResolver = new \App\Services\ShortCode(); $widgetResolver->addWidget('{[TestingWidget]}', 'WidgetResolved'); @@ -20,7 +20,7 @@ public function testWidgetResolving() $content = "Some sample text for testing the {[TestingWidget1]} and {[TestingWidget2]} resolving"; - $widgetResolver = new \App\Libs\ShortCode(); + $widgetResolver = new \App\Services\ShortCode(); $widgetResolver->addWidget('{[TestingWidget1]}', 'WidgetResolved1'); diff --git a/themes/TheWright/app/Controllers/StartController.php b/themes/TheWright/app/Controllers/StartController.php index 8a4218a7d..277558710 100644 --- a/themes/TheWright/app/Controllers/StartController.php +++ b/themes/TheWright/app/Controllers/StartController.php @@ -3,15 +3,13 @@ namespace Theme\TheWright\App\Controllers; use Illuminate\Http\Request; -use App\Libs\Controller; +use Illuminate\Routing\Controller; -class StartController extends Controller{ +class StartController extends Controller +{ - public function index(){ - dd("It's a theme controller!"); + public function index() + { + dd("It's a theme controller!"); } - - - - -} \ No newline at end of file +} diff --git a/themes/TheWright/header.php b/themes/TheWright/header.php index c48322fc0..c9a19cef3 100644 --- a/themes/TheWright/header.php +++ b/themes/TheWright/header.php @@ -27,7 +27,7 @@ } ?> - + \ No newline at end of file From 1fc678fbb498b0170e53e7b0d470b5a26ced4b62 Mon Sep 17 00:00:00 2001 From: Timot Tarjani Date: Thu, 9 Jan 2025 21:29:25 +0100 Subject: [PATCH 2/4] Update readme --- README.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/README.md b/README.md index 412dbbb89..0f956ae7f 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,6 @@ This lightweight CMS platform is not just about functionality—it's about empow ### Latest version: [v1.2.0](https://github.com/ttimot24/HorizontCMS/releases/tag/v1.2.0) -### Try out - -Frontend: [http://horizontcms.herokuapp.com/](https://horizontcms.herokuapp.com/) - -Backend: [http://horizontcms.herokuapp.com/admin](https://horizontcms.herokuapp.com/admin) - -> Username & password: admin/admin ### Installation #### Browser From 8c22c674a4b3ae12a18c9caedd90bd449efe7efe Mon Sep 17 00:00:00 2001 From: Timot Tarjani Date: Thu, 9 Jan 2025 21:29:55 +0100 Subject: [PATCH 3/4] Update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0f956ae7f..7e9f750ca 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![VueJs 2.6](https://img.shields.io/badge/VueJs-2.6-green.svg)](http://vuejs.org) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/d645b6be9b6a42a8b6189cc32ea8f546)](https://www.codacy.com/app/ttimot24/HorizontCMS?utm_source=github.com&utm_medium=referral&utm_content=ttimot24/HorizontCMS&utm_campaign=Badge_Grade) -**HorizontCMS** is an open-source, responsive Content Management System (CMS) built on the powerful combination of Laravel 9, Vue.js 2.6, and Bootstrap 5.2. With its sleek design and robust features, HorizontCMS empowers developers like you to create stunning websites and blogs for the next generation. +**HorizontCMS** is an open-source, responsive Content Management System (CMS) built on the powerful combination of Laravel 10, Vue.js 2.6, and Bootstrap 5.2. With its sleek design and robust features, HorizontCMS empowers developers like you to create stunning websites and blogs for the next generation. This lightweight CMS platform is not just about functionality—it's about empowerment. Whether you're a seasoned developer or a novice user, HorizontCMS provides intuitive tools and a seamless interface to extend and build your online presence with ease. With just one click, you can unlock endless possibilities and unleash your creativity. From d9ff94eddb5512df38c76b71148d70b68e4116f4 Mon Sep 17 00:00:00 2001 From: Timot Tarjani Date: Fri, 17 Jan 2025 18:42:09 +0100 Subject: [PATCH 4/4] BlogpostCategory REST response --- app/Controllers/BlogpostCategoryController.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/Controllers/BlogpostCategoryController.php b/app/Controllers/BlogpostCategoryController.php index 82f41b02f..9d908b892 100644 --- a/app/Controllers/BlogpostCategoryController.php +++ b/app/Controllers/BlogpostCategoryController.php @@ -20,10 +20,17 @@ class BlogpostCategoryController extends Controller * * @return \Illuminate\Http\Response */ - public function index() + public function index(Request $request) { + + $all_categories = BlogpostCategory::all(); + + if ($request->wantsJson()) { + return response()->json($all_categories); + } + return view('blogposts.category.index', [ - 'all_category' => BlogpostCategory::all(), + 'all_category' => $all_categories, ]); }