2024-03-14 19:39:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
2024-03-19 20:19:27 +01:00
|
|
|
use Carbon\Carbon;
|
|
|
|
|
2024-03-14 19:39:43 +01:00
|
|
|
use function _\find;
|
|
|
|
use function _\filter;
|
|
|
|
|
|
|
|
class SortingService
|
|
|
|
{
|
|
|
|
private $p_tags = [];
|
|
|
|
private $p_archive = [];
|
|
|
|
private $settings;
|
|
|
|
private $contents;
|
2024-03-19 20:19:27 +01:00
|
|
|
private $themes;
|
2024-03-28 23:42:37 +01:00
|
|
|
private $info = [];
|
2024-03-14 19:39:43 +01:00
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
SettingsService $settingsService,
|
|
|
|
ContentService $contentService,
|
2024-03-19 20:19:27 +01:00
|
|
|
ThemeService $themeService,
|
2024-03-14 19:39:43 +01:00
|
|
|
) {
|
|
|
|
$this->settings = $settingsService;
|
|
|
|
$this->contents = $contentService;
|
2024-03-19 20:19:27 +01:00
|
|
|
$this->themes = $themeService;
|
2024-03-28 23:42:37 +01:00
|
|
|
$global = $this->settings->getGlobal();
|
|
|
|
$this->info = [
|
|
|
|
'keywords' => isset($global['keywords'])
|
|
|
|
? $global['keywords']
|
|
|
|
: 'fipamo, blog, jamstack, php, markdown, js',
|
|
|
|
'menu' => $this->settings->getMenu(),
|
|
|
|
'tags' => $this->settings->getTags(),
|
|
|
|
'description' => $global['descriptions'],
|
|
|
|
'image' => $global['base_url'] . $global['background'],
|
|
|
|
'baseURL' => $global['base_url'],
|
|
|
|
'dynamicRender' => $global['dynamicRender'],
|
|
|
|
'theme' => $global['theme'],
|
|
|
|
];
|
2024-03-14 19:39:43 +01:00
|
|
|
}
|
|
|
|
|
2024-03-28 23:42:37 +01:00
|
|
|
public function tags($debug = true)
|
2024-03-14 19:39:43 +01:00
|
|
|
{
|
|
|
|
$pages = $this->contents->loadAllPages();
|
|
|
|
foreach ($pages as $page) {
|
|
|
|
$temp = [];
|
|
|
|
if (isset($page['tags'])) {
|
|
|
|
$temp = explode(',', $page['tags']);
|
|
|
|
foreach ($temp as $tag) {
|
|
|
|
$label = trim($tag);
|
|
|
|
if (!find($this->p_tags, ['tag_name' => $label])) {
|
|
|
|
array_push($this->p_tags, [
|
|
|
|
'tag_name' => $label,
|
2024-03-28 22:13:13 +01:00
|
|
|
'slug' => safeString($label),
|
2024-03-14 19:39:43 +01:00
|
|
|
'pages' => $this->tagPages($label, $pages),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-03-15 21:28:26 +01:00
|
|
|
$tagData = [];
|
|
|
|
|
2024-04-22 23:19:06 +02:00
|
|
|
//dd($this->settings->getTags()['pages']);
|
2024-03-15 21:28:26 +01:00
|
|
|
$tagData = [
|
2024-03-28 23:42:37 +01:00
|
|
|
'debug' => $debug, // for theme kit
|
|
|
|
'tags' => $this->p_tags,
|
|
|
|
'theme' => $this->info['theme'], // for theme kit
|
|
|
|
'title' => 'Pages Tagged as Tag',
|
|
|
|
'dynamicRender' => $this->info['dynamicRender'],
|
2024-04-22 23:19:06 +02:00
|
|
|
'pages' => $this->settings->getTags()['pages'],
|
2024-03-28 23:42:37 +01:00
|
|
|
'info' => $this->info,
|
|
|
|
'menu' => $this->settings->getMenu(),
|
|
|
|
'media' => [
|
|
|
|
['file' => $this->info['image'],
|
|
|
|
'type' => trim(pathinfo($this->info['image'], PATHINFO_EXTENSION))]
|
|
|
|
]
|
2024-03-15 21:28:26 +01:00
|
|
|
];
|
2024-03-28 23:42:37 +01:00
|
|
|
|
2024-03-15 21:28:26 +01:00
|
|
|
return $tagData;
|
2024-03-14 19:39:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function tagPages($tag, $pages)
|
|
|
|
{
|
|
|
|
$tagged = [];
|
|
|
|
foreach ($pages as $page) {
|
|
|
|
if (isset($page['tags'])) {
|
|
|
|
if (strpos($page['tags'], $tag) !== false) {
|
|
|
|
array_push($tagged, [
|
|
|
|
'title' => $page['title'],
|
|
|
|
'slug' => $page['slug'],
|
|
|
|
'path' => $page['path'],
|
|
|
|
'feature' => $page['feature'],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $tagged;
|
|
|
|
}
|
|
|
|
|
2024-03-28 23:42:37 +01:00
|
|
|
public function archive($debug = true)
|
2024-03-14 19:39:43 +01:00
|
|
|
{
|
|
|
|
$pages = $this->contents->loadAllPages();
|
|
|
|
$years = [];
|
|
|
|
$archive = [];
|
|
|
|
foreach ($pages as $page) {
|
|
|
|
$date = explode('/', $page['path']);
|
|
|
|
if (!find($years, ['year' => trim($date[0])])) {
|
|
|
|
$findPages = filter($pages, ['createdYear' => trim($date[0])]);
|
|
|
|
array_push(
|
|
|
|
$years,
|
|
|
|
[
|
|
|
|
'year' => trim($date[0]),
|
|
|
|
'count' => count($findPages),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($years as $year) {
|
|
|
|
$sorted = [];
|
|
|
|
$filtered = filter($pages, ['createdYear' => $year['year']]);
|
|
|
|
foreach ($filtered as $obj) {
|
|
|
|
$month = date('m', date($obj['rawCreated']));
|
|
|
|
if (!find($sorted, ['month' => $month])) {
|
|
|
|
$perMonth = filter(
|
|
|
|
$pages,
|
|
|
|
[
|
|
|
|
'path' => $year['year'] . '/' . $month,
|
|
|
|
'deleted' => false,
|
|
|
|
'published' => true,
|
|
|
|
'layout' => 'page',
|
|
|
|
]
|
|
|
|
);
|
|
|
|
array_push($sorted, [
|
|
|
|
'month' => $month,
|
|
|
|
'full_month' => date('F', date($obj['rawCreated'])),
|
|
|
|
'count' => count($perMonth),
|
|
|
|
'pages' => $perMonth,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
array_push($this->p_archive, [
|
|
|
|
'year' => $year['year'],
|
|
|
|
'year_data' => $sorted,
|
|
|
|
]);
|
|
|
|
}
|
2024-03-15 21:28:26 +01:00
|
|
|
$archive_data = [];
|
2024-03-28 23:42:37 +01:00
|
|
|
|
2024-03-15 21:28:26 +01:00
|
|
|
$archiveData = [
|
2024-03-28 23:42:37 +01:00
|
|
|
'debug' => $debug, // for theme kit
|
|
|
|
'theme' => $this->info['theme'], // for theme kit
|
|
|
|
'title' => 'Archives',
|
|
|
|
'dynamicRender' => $this->info['dynamicRender'],
|
|
|
|
'archive' => $this->p_archive,
|
|
|
|
'info' => $this->info,
|
|
|
|
'menu' => $this->settings->getMenu(),
|
|
|
|
'media' => [
|
|
|
|
['file' => $this->info['image'],
|
|
|
|
'type' => trim(pathinfo($this->info['image'], PATHINFO_EXTENSION))]
|
|
|
|
],
|
2024-03-15 21:28:26 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
return $archiveData;
|
2024-03-14 19:39:43 +01:00
|
|
|
}
|
|
|
|
|
2024-03-28 23:42:37 +01:00
|
|
|
public function page($page, $debug = true)
|
2024-03-14 19:39:43 +01:00
|
|
|
{
|
|
|
|
$pageOptions = [];
|
2024-03-28 23:42:37 +01:00
|
|
|
$tags = [];
|
2024-03-14 19:39:43 +01:00
|
|
|
if (isset($page['tags'])) {
|
|
|
|
$taglist = explode(',', $page['tags']);
|
|
|
|
foreach ($taglist as $tag) {
|
|
|
|
$label = trim($tag);
|
|
|
|
array_push($tags, [
|
|
|
|
'label' => $label . ' ',
|
2024-03-28 22:13:13 +01:00
|
|
|
'slug' => safeString($label),
|
2024-03-14 19:39:43 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$meta = [
|
|
|
|
'who' => $page['author'],
|
|
|
|
'when' => $page['created'],
|
|
|
|
'tags' => $tags,
|
|
|
|
];
|
|
|
|
// if page feature isn't empty, find image from list and set it as background image
|
|
|
|
// if it is empty, just use global background
|
|
|
|
if ($page['feature'] != '' || $page['feature'] != null) {
|
|
|
|
$media = explode(',', $page['feature']);
|
|
|
|
$set = false;
|
|
|
|
foreach ($media as $file) {
|
|
|
|
$item = trim($file);
|
|
|
|
$ext = pathinfo($item, PATHINFO_EXTENSION);
|
|
|
|
|
|
|
|
if ($ext != 'mp4' && !$set) {
|
2024-03-28 23:42:37 +01:00
|
|
|
$this->info['image'] = $this->info['baseURL'] . $item;
|
|
|
|
$set = true;
|
2024-03-14 19:39:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-03-15 21:28:26 +01:00
|
|
|
$recent = [];
|
|
|
|
$featured = [];
|
|
|
|
$limit = 4;
|
|
|
|
$pages = $this->contents->loadAllPages();
|
|
|
|
foreach ($pages as $item) {
|
|
|
|
if (
|
|
|
|
!$item['deleted'] &&
|
|
|
|
$item['published'] &&
|
|
|
|
$item['menu'] != 'true'
|
|
|
|
) {
|
|
|
|
if (count($recent) < $limit) {
|
|
|
|
array_push($recent, [
|
|
|
|
'path' => $item['path'],
|
|
|
|
'slug' => $item['slug'],
|
|
|
|
'title' => $item['title'],
|
|
|
|
'feature' => $item['feature'],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item['featured'] == true) {
|
|
|
|
if (count($featured) < $limit) {
|
|
|
|
array_push($featured, [
|
2024-03-14 19:39:43 +01:00
|
|
|
'path' => $item['path'],
|
|
|
|
'slug' => $item['slug'],
|
|
|
|
'title' => $item['title'],
|
|
|
|
'feature' => $item['feature'],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-03-15 21:28:26 +01:00
|
|
|
|
2024-03-28 23:42:37 +01:00
|
|
|
$pageData = [
|
|
|
|
"debug" => $debug,
|
|
|
|
"theme" => $this->info['theme'],
|
|
|
|
"status" => session('member') != null ? true : false,
|
|
|
|
"title" => $page['title'],
|
|
|
|
"meta" => $meta,
|
|
|
|
"menu" => $this->settings->getMenu(),
|
|
|
|
"info" => $this->info,
|
|
|
|
"media" => $page['media'],
|
|
|
|
"files" => $page['docs'],
|
|
|
|
"content" => $page['html'],
|
|
|
|
"recent" => $recent,
|
|
|
|
"feature" => $featured,
|
|
|
|
"tags" => $meta['tags'],
|
|
|
|
"dynamicRender" => $this->info['dynamicRender'],
|
2024-03-15 21:28:26 +01:00
|
|
|
];
|
2024-03-28 23:42:37 +01:00
|
|
|
return $pageData;
|
2024-03-14 19:39:43 +01:00
|
|
|
}
|
2024-03-19 20:19:27 +01:00
|
|
|
|
2024-03-22 21:35:44 +01:00
|
|
|
public function navigation()
|
|
|
|
{
|
|
|
|
$pageOptions = [
|
|
|
|
'title' => 'Edit Navigation',
|
|
|
|
'status' => session('member') != '' ? true : false,
|
|
|
|
'menu' => $this->settings->getMenu(),
|
|
|
|
];
|
|
|
|
|
|
|
|
return $pageOptions;
|
|
|
|
}
|
|
|
|
|
2024-03-19 20:19:27 +01:00
|
|
|
public function settings()
|
|
|
|
{
|
|
|
|
$global = $this->settings->getGlobal();
|
|
|
|
$email = $this->settings->getEmail();
|
|
|
|
$updated = new Carbon($global['last_backup']);
|
|
|
|
$status = session('member') != '' ? true : false;
|
|
|
|
$pageOptions = [
|
|
|
|
'title' => 'Settings',
|
|
|
|
'private' => $global['private'],
|
|
|
|
'renderOnSave' => $global['renderOnSave'],
|
|
|
|
'background' => $global['background'],
|
|
|
|
'member' => session('member'),
|
|
|
|
'ftoken' => session('form_token'),
|
|
|
|
'siteTitle' => $global['title'],
|
|
|
|
'baseUrl' => $global['base_url'],
|
|
|
|
'desc' => $global['descriptions'],
|
2024-04-22 21:11:51 +02:00
|
|
|
'lastBackup' => $updated->format('Y F d H i s'),
|
2024-03-19 20:19:27 +01:00
|
|
|
'currentTheme' => $global['theme'],
|
|
|
|
'themes' => $this->themes->getThemes(),
|
|
|
|
'apiStatus' => isset($global['externalAPI']) ? $global['externalAPI'] : 'false',
|
|
|
|
'dynamicRenderStatus' => isset($global['dynamicRender']) ? $global['dynamicRender'] : 'false',
|
|
|
|
'mailOption' => $email['active'],
|
|
|
|
'mailConfig' => $email,
|
|
|
|
'status' => $status,
|
|
|
|
];
|
|
|
|
return $pageOptions;
|
|
|
|
}
|
2024-03-14 19:39:43 +01:00
|
|
|
}
|