2024-03-05 20:27:27 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
|
|
|
use App\Interfaces\PageRepositoryInterface;
|
|
|
|
use App\Services\SettingsService;
|
|
|
|
use App\Services\ContentService;
|
|
|
|
use App\Services\PaginateService;
|
2024-03-08 21:09:43 +01:00
|
|
|
use App\Services\DocService;
|
2024-03-14 19:39:43 +01:00
|
|
|
use App\Services\SortingService;
|
2024-03-18 23:14:17 +01:00
|
|
|
use App\Services\RenderService;
|
2024-03-08 21:09:43 +01:00
|
|
|
use Carbon\Carbon;
|
2024-03-05 20:27:27 +01:00
|
|
|
|
|
|
|
class PageRepository implements PageRepositoryInterface
|
|
|
|
{
|
|
|
|
protected $content;
|
|
|
|
protected $setttings;
|
|
|
|
protected $paginate;
|
|
|
|
protected $pages;
|
2024-03-08 21:09:43 +01:00
|
|
|
protected $docs;
|
2024-03-14 19:39:43 +01:00
|
|
|
protected $sort;
|
2024-03-18 23:14:17 +01:00
|
|
|
protected $render;
|
2024-03-05 20:27:27 +01:00
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
ContentService $contentService,
|
|
|
|
SettingsService $settingsService,
|
2024-03-08 21:09:43 +01:00
|
|
|
PaginateService $paginateService,
|
|
|
|
DocService $docService,
|
2024-03-14 19:39:43 +01:00
|
|
|
SortingService $sortingService,
|
2024-03-18 23:14:17 +01:00
|
|
|
RenderService $renderService
|
2024-03-05 20:27:27 +01:00
|
|
|
) {
|
|
|
|
$this->content = $contentService;
|
|
|
|
$this->settings = $settingsService;
|
|
|
|
$this->paginate = $paginateService;
|
2024-03-08 21:09:43 +01:00
|
|
|
$this->docs = $docService;
|
2024-03-14 19:39:43 +01:00
|
|
|
$this->sort = $sortingService;
|
2024-03-18 23:14:17 +01:00
|
|
|
$this->render = $renderService;
|
2024-03-05 20:27:27 +01:00
|
|
|
$this->pages = $this->content->loadAllPages();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAll()
|
|
|
|
{
|
|
|
|
return $this->pages;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getById($uuid)
|
|
|
|
{
|
2024-03-15 22:18:10 +01:00
|
|
|
$page = $this->pages->where('uuid', $uuid)->first();
|
|
|
|
//quick check to see if layout is set
|
|
|
|
$page['layout'] == '' ? $page['layout'] = 'page' : $page['layout'] = $page['layout'];
|
|
|
|
return $page;
|
2024-03-05 20:27:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function delete($uuid)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-03-08 21:09:43 +01:00
|
|
|
public function create($page)
|
2024-03-05 20:27:27 +01:00
|
|
|
{
|
2024-03-12 23:16:36 +01:00
|
|
|
return $this->editPage($page, null, 'create');
|
2024-03-05 20:27:27 +01:00
|
|
|
}
|
|
|
|
|
2024-03-08 21:09:43 +01:00
|
|
|
public function update($page)
|
2024-03-05 20:27:27 +01:00
|
|
|
{
|
2024-03-08 21:09:43 +01:00
|
|
|
return $this->editPage($page, $this->pages->where('uuid', $page->uuid)->first(), 'update');
|
2024-03-05 20:27:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getGroup($num, $limit, $sort = "all")
|
|
|
|
{
|
|
|
|
return $this->paginate->getPage($num, $limit, $sort);
|
|
|
|
}
|
2024-03-08 21:09:43 +01:00
|
|
|
|
|
|
|
private function editPage($body, $page, $task)
|
|
|
|
{
|
|
|
|
$path;
|
|
|
|
$file;
|
|
|
|
$writePath;
|
|
|
|
$message;
|
2024-03-15 22:18:10 +01:00
|
|
|
$deleted;
|
2024-03-08 21:09:43 +01:00
|
|
|
if ($task != 'create') {
|
|
|
|
$path = date('Y', date($page['rawCreated'])) .
|
|
|
|
'/' .
|
|
|
|
date('m', date($page['rawCreated']));
|
|
|
|
} else {
|
|
|
|
$path = date('Y') . '/' . date('m');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($task == 'delete') {
|
|
|
|
$deleted = 'true';
|
|
|
|
$body->menu = 'false';
|
|
|
|
$body->published = 'false';
|
|
|
|
$body->featured = 'false';
|
|
|
|
} else {
|
|
|
|
$deleted = isset($page['deleted']) ? $page['deleted'] : 'false';
|
|
|
|
}
|
|
|
|
|
|
|
|
$created = $task != 'create' ? new Carbon($page['rawCreated']) : Carbon::now();
|
|
|
|
$updated = Carbon::now();
|
|
|
|
|
|
|
|
// grab current index from settings and update
|
2024-03-12 23:16:36 +01:00
|
|
|
$id = $task != 'create' ? $body->id : $this->settings->getSettings()['library_stats']['current_index'];
|
2024-03-28 23:42:37 +01:00
|
|
|
$uuid = $task != 'create' ? $body->uuid : createUUID();
|
2024-03-08 21:09:43 +01:00
|
|
|
//set variables post body for saving
|
|
|
|
$body->id = $id;
|
|
|
|
$body->uuid = $uuid;
|
|
|
|
$body->path = $path;
|
|
|
|
$body->author = session('member')['handle'];
|
|
|
|
$body->created = $created->format("Y-m-d\TH:i:sP");
|
|
|
|
$body->updated = $updated->format("Y-m-d\TH:i:sP");
|
|
|
|
$body->deleted = $deleted;
|
|
|
|
//set path to save file
|
|
|
|
if ($body->layout == 'index') {
|
|
|
|
$writePath = '../content/pages/start/index.md';
|
|
|
|
} else {
|
|
|
|
$writePath = '../content/pages/' . $path . '/' . $body->slug . '.md';
|
|
|
|
}
|
|
|
|
//write file to path
|
|
|
|
$saved = $this->docs::writePages($task, $path, $writePath, $this->docs::objectToMD($body));
|
|
|
|
//handle post save result
|
|
|
|
if ($saved) {
|
|
|
|
if (
|
|
|
|
$this->settings->getGlobal()['renderOnSave'] == 'true' &&
|
|
|
|
$this->settings->getGlobal()['dynamicRender'] == 'false'
|
|
|
|
) {
|
2024-03-18 23:14:17 +01:00
|
|
|
$this->render->tags();
|
|
|
|
$this->render->archive();
|
|
|
|
$this->render->pages();
|
2024-03-08 21:09:43 +01:00
|
|
|
$message = 'Filed edited and rendered. NOICE.';
|
|
|
|
} else {
|
|
|
|
$message = 'File edited. Nice work';
|
|
|
|
}
|
|
|
|
|
|
|
|
//upadte settings if needed
|
|
|
|
$body->path = $path;
|
2024-03-22 21:35:44 +01:00
|
|
|
$this->settings->updateMenu($body);
|
2024-04-22 23:19:06 +02:00
|
|
|
$this->settings->updateTags($this->sort->tags());
|
2024-03-08 21:09:43 +01:00
|
|
|
// if new page added, update current index in Settings file
|
|
|
|
if ($task == 'create') {
|
2024-03-12 23:16:36 +01:00
|
|
|
$this->settings->updatePageIndex();
|
2024-03-08 21:09:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'message' => $message,
|
|
|
|
'type' => $task == 'update' ? 'postUpdated' : 'postAdded',
|
|
|
|
'id' => $uuid,
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
return $response = [
|
|
|
|
'message' => "Uh oh. File save problem. Don't panic",
|
|
|
|
'type' => 'postError',
|
|
|
|
'id' => $uuid,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
2024-03-05 20:27:27 +01:00
|
|
|
}
|