diff --git a/app/Http/Controllers/Front/StartController.php b/app/Http/Controllers/Front/StartController.php index 9f95a7e..64ce46d 100644 --- a/app/Http/Controllers/Front/StartController.php +++ b/app/Http/Controllers/Front/StartController.php @@ -5,29 +5,63 @@ namespace App\Http\Controllers\Front; use App\Services\SettingsService; use App\Http\Controllers\Controller; use App\Services\AuthService; +use App\Interfaces\PageRepositoryInterface; +use App\Services\SortingService; +use App\Services\AssetService; + +use function _\find; class StartController extends Controller { protected $settings; protected $auth; + protected PageRepositoryInterface $pages; + protected AssetService $assets; + protected SortingService $sort; - public function __construct(SettingsService $settingsService, AuthService $authService) - { + public function __construct( + PageRepositoryInterface $pageRepository, + SettingsService $settingsService, + AuthService $authService, + AssetService $assetService, + SortingService $sortService, + ) { + $this->pages = $pageRepository; $this->settings = $settingsService; $this->auth = $authService; + $this->assets = $assetService; + $this->sort = $sortService; } public function index($first = 00, $second = 00, $third = 00) { - $global = $this->settings->getGlobal(); + $global = $this->settings->getGlobal(); + $currentTheme = $this->assets->getCurrentTheme(); + $template; + $pageData = []; + $pages = $this->pages->getAll(); //check if configs are present if (file_exists(env('FOLKS_PATH')) && file_exists(env('SETTINGS_PATH'))) { if ($global['dynamicRender'] == 'true') { if (is_numeric($first)) { - dd('index'); + if ($first == 00 || !isset($first)) { + $page = $pages->where('id', 1)->first(); + $pageData = $this->sort->page($page); + $template = $currentTheme . '.index'; + } else { + $page = $this->pages->getBySlug($third); + $pageData = $this->sort->page($page); + $template = $currentTheme . '.' . $page['layout']; + } } else { - dd('pages'); + if ($first == null || $first == '') { + $page = $pages->where('id', 1)->first(); + $pageData = $this->sort->page($page); + $template = $currentTheme . '.index'; + } else { + } } + return view($template, $pageData); } else { return response()->file('../public/index.html'); } @@ -35,4 +69,31 @@ class StartController extends Controller return view('back.init', ["status" => false, "title" => "Set Up"]); } } + + public function page($first = 00, $second = 00, $third = 00) + { + $currentTheme = $this->assets->getCurrentTheme(); + switch ($first) { + case 'archive': + case 'archives': + $template = $currentTheme . '.archive'; + $pageData = $this->sort->archive(); + break; + case 'tags': + $template = $currentTheme . '.tags'; + $tags = $this->sort->tags(false); + $tagData = find($tags['tags'], ['tag_name' => $second]); + $pageData = [ + 'theme' => $currentTheme, // for theme kit + 'title' => 'Pages Tagged as ' . $second, + 'dynamicRender' => $tags['dynamicRender'], + 'info' => $tags['info'], + 'menu' => $tags['menu'], + 'pages' => $tagData['pages'], + 'media' => $tags['media'], + ]; + break; + } + return view($template, $pageData); + } } diff --git a/app/Http/Controllers/RouteController.php b/app/Http/Controllers/RouteController.php index 94787ec..932018b 100644 --- a/app/Http/Controllers/RouteController.php +++ b/app/Http/Controllers/RouteController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use App\Http\Controllers\Dash\IndexController; use App\Http\Controllers\Dash\AuthController; +use App\Http\Controllers\Front\StartController; use App\Http\Controllers\Theming\ThemeController; use Illuminate\Http\Request; @@ -12,15 +13,18 @@ class RouteController extends Controller protected $dash; protected $auth; protected $theme; + protected $front; public function __construct( IndexController $indexController, AuthController $authController, ThemeController $themeController, + StartController $startContoller, ) { $this->dash = $indexController; $this->auth = $authController; $this->theme = $themeController; + $this->front = $startContoller; } public function get($first = null, $second = null, $third = null, $fourth = null) @@ -41,12 +45,13 @@ class RouteController extends Controller return $this->theme->start(); } break; - default: - dd('$first' . $first); + case 'tags': + case 'archives': + return $this->front->page($first, $second, $third); break; } } else { - dd('index'); + return $this->front->index($first, $second, $third); } } diff --git a/app/Http/Controllers/Theming/ThemeController.php b/app/Http/Controllers/Theming/ThemeController.php index 4bc0d9e..f354c64 100644 --- a/app/Http/Controllers/Theming/ThemeController.php +++ b/app/Http/Controllers/Theming/ThemeController.php @@ -40,7 +40,7 @@ class ThemeController extends Controller "pages" => $this->themes->getCustomViews('page') ]); } else { - return redirect('back.login'); + return redirect('dashboard'); } } diff --git a/app/Interfaces/PageRepositoryInterface.php b/app/Interfaces/PageRepositoryInterface.php index b9391fe..47b4163 100644 --- a/app/Interfaces/PageRepositoryInterface.php +++ b/app/Interfaces/PageRepositoryInterface.php @@ -8,6 +8,8 @@ interface PageRepositoryInterface public function getByID($uuid); + public function getBySlug($slug); + public function delete($uuid); public function create($page); diff --git a/app/Repositories/PageRepository.php b/app/Repositories/PageRepository.php index c7f1d1d..d2df3ec 100644 --- a/app/Repositories/PageRepository.php +++ b/app/Repositories/PageRepository.php @@ -51,6 +51,14 @@ class PageRepository implements PageRepositoryInterface return $page; } + public function getBySlug($slug) + { + $page = $this->pages->where('slug', $slug)->first(); + //quick check to see if layout is set + $page['layout'] == '' ? $page['layout'] = 'page' : $page['layout'] = $page['layout']; + return $page; + } + public function delete($uuid) { }