From c85e14577460026f0268de263b18fea1ae57ca1d Mon Sep 17 00:00:00 2001 From: ro Date: Wed, 4 Sep 2024 14:32:36 -0600 Subject: [PATCH] added getbyIndex for pages, urlencode page titles the theme controller was grabbing the index by its page name, which was bad because that might change. that was replaced with a getById function since the index id will always be 0 since it's the first page. this is a seperate function from getByUuid which is a unique indentifier for each page which was being used interchangably before the fix. all of those references have been cleaned up to reference which type of id is needed there was also a bug that happened on rendering when there were special characters in the title. this was solved by saving the title as a urlencoded string and then just decodded when it was needed for display on the front end --- app/Http/Controllers/DashController.php | 2 +- app/Http/Controllers/ThemeController.php | 8 ++++---- app/Interfaces/PageRepositoryInterface.php | 4 +++- app/Repositories/PageRepository.php | 11 ++++++++++- app/Services/Data/SortingService.php | 6 +++--- app/Services/Upkeep/InitService.php | 2 +- resources/views/back/page.blade.php | 4 ++-- resources/views/includes/recent-meta.blade.php | 5 ++++- 8 files changed, 28 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/DashController.php b/app/Http/Controllers/DashController.php index 9f652b2..e6a0925 100644 --- a/app/Http/Controllers/DashController.php +++ b/app/Http/Controllers/DashController.php @@ -88,7 +88,7 @@ class DashController extends Controller $title; $page = []; $views = []; - $mode == 'edit' ? $page = $this->pages->getById($uuid) : $page = []; + $mode == 'edit' ? $page = $this->pages->getByUuid($uuid) : $page = []; $mode == 'edit' ? $title = $page['title'] : $title = 'Add New'; $mode == 'edit' ? $views = $this->themes->getCustomViews($page['layout']) : $views[] = 'page'; diff --git a/app/Http/Controllers/ThemeController.php b/app/Http/Controllers/ThemeController.php index 18edc37..4dd59e5 100644 --- a/app/Http/Controllers/ThemeController.php +++ b/app/Http/Controllers/ThemeController.php @@ -56,14 +56,14 @@ class ThemeController extends Controller $page; if ($view == 'index') { $template = $currentTheme . '.index'; - $page = $this->pages->getBySlug('first'); + $page = $this->pages->getById(0); } else { $template = $currentTheme . '.page'; //if coming from theme page, grabs id of latest page if ($id == null) { - $id = $this->getPageID(); + $uuid = $this->getPageUUID(); } - $page = $this->pages->getById($id); + $page = $this->pages->getByUuid($uuid); } $pageData = $this->sort->page($page); break; @@ -88,7 +88,7 @@ class ThemeController extends Controller } } - private function getPageID() + private function getPageUUID() { $book = $this->pages->getAll(); $page = $book->where('layout', 'page')->first(); diff --git a/app/Interfaces/PageRepositoryInterface.php b/app/Interfaces/PageRepositoryInterface.php index 47b4163..5454897 100644 --- a/app/Interfaces/PageRepositoryInterface.php +++ b/app/Interfaces/PageRepositoryInterface.php @@ -6,7 +6,9 @@ interface PageRepositoryInterface { public function getAll(); - public function getByID($uuid); + public function getById($id); + + public function getByUuid($uuid); public function getBySlug($slug); diff --git a/app/Repositories/PageRepository.php b/app/Repositories/PageRepository.php index fb6cc81..df04577 100644 --- a/app/Repositories/PageRepository.php +++ b/app/Repositories/PageRepository.php @@ -45,7 +45,15 @@ class PageRepository implements PageRepositoryInterface return $this->pages; } - public function getById($uuid) + public function getById($id) + { + $page = $this->pages->where('id', $id)->first(); + //quick check to see if layout is set + $page['layout'] == '' ? $page['layout'] = 'page' : $page['layout'] = $page['layout']; + return $page; + } + + public function getByUuid($uuid) { $page = $this->pages->where('uuid', $uuid)->first(); //quick check to see if layout is set @@ -121,6 +129,7 @@ class PageRepository implements PageRepositoryInterface $id = $task != 'create' ? $body->id : $this->settings->getSettings()['library_stats']['current_index']; $uuid = $task != 'create' ? $body->uuid : createUUID(); //set variables post body for saving + $body->title = urlencode($body->title); $body->id = $id; $body->uuid = $uuid; $body->path = $path; diff --git a/app/Services/Data/SortingService.php b/app/Services/Data/SortingService.php index 094c3f6..fd701e3 100644 --- a/app/Services/Data/SortingService.php +++ b/app/Services/Data/SortingService.php @@ -216,7 +216,7 @@ class SortingService array_push($recent, [ 'path' => $item['path'], 'slug' => $item['slug'], - 'title' => $item['title'], + 'title' => urldecode($item['title']), 'feature' => $item['feature'], ]); } @@ -226,7 +226,7 @@ class SortingService array_push($featured, [ 'path' => $item['path'], 'slug' => $item['slug'], - 'title' => $item['title'], + 'title' => urldecode($item['title']), 'feature' => $item['feature'], ]); } @@ -237,7 +237,7 @@ class SortingService "debug" => $debug, "theme" => $this->info['theme'], "status" => session('member') != null ? true : false, - "title" => $page['title'], + "title" => urldecode($page['title']), "meta" => $meta, "menu" => $this->settings->getMenu(), "info" => $this->info, diff --git a/app/Services/Upkeep/InitService.php b/app/Services/Upkeep/InitService.php index 41cde58..17a6e09 100644 --- a/app/Services/Upkeep/InitService.php +++ b/app/Services/Upkeep/InitService.php @@ -88,7 +88,7 @@ class InitService //create index file //TODO: upate path attribute to use env variable $index = [ - 'id' => 1, + 'id' => 0, 'uuid' => createUUID(), 'title' => 'FIRST!', 'imageList' => '/assets/images/global/default-bg.jpg', diff --git a/resources/views/back/page.blade.php b/resources/views/back/page.blade.php index 7e0ae69..db7454c 100644 --- a/resources/views/back/page.blade.php +++ b/resources/views/back/page.blade.php @@ -1,8 +1,7 @@ @extends('frame') -@section('title', 'The Dash | Editing '. $title) - @php + $title = urldecode($title); if($mode == 'edit') { $id = $page['id']; @@ -30,6 +29,7 @@ $files = ""; } @endphp + @section('title', 'The Dash | Editing '. $title) @section('main-content')
diff --git a/resources/views/includes/recent-meta.blade.php b/resources/views/includes/recent-meta.blade.php index f60fad2..8bd1a81 100644 --- a/resources/views/includes/recent-meta.blade.php +++ b/resources/views/includes/recent-meta.blade.php @@ -29,7 +29,10 @@ if($page['featured'] == 'true')
- {{ $page['title'] }} + @php + $title = urldecode($page['title']); + @endphp + {{ $title }}