2024-03-14 19:39:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
use function _\find;
|
|
|
|
use function _\filter;
|
|
|
|
|
|
|
|
class SortingService
|
|
|
|
{
|
|
|
|
private $p_tags = [];
|
|
|
|
private $p_archive = [];
|
|
|
|
private $settings;
|
|
|
|
private $contents;
|
|
|
|
private $strings;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
SettingsService $settingsService,
|
|
|
|
ContentService $contentService,
|
|
|
|
StringService $stringService
|
|
|
|
) {
|
|
|
|
$this->settings = $settingsService;
|
|
|
|
$this->contents = $contentService;
|
|
|
|
$this->strings = $stringService;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tags()
|
|
|
|
{
|
|
|
|
$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,
|
|
|
|
'slug' => $this->strings::safeString($label),
|
|
|
|
'pages' => $this->tagPages($label, $pages),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-03-15 21:28:26 +01:00
|
|
|
$global = $this->settings->getGlobal();
|
|
|
|
$tagData = [];
|
|
|
|
|
|
|
|
$pageInfo = [
|
|
|
|
'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'],
|
|
|
|
];
|
|
|
|
$tagData = [
|
|
|
|
'tags' => $this->p_tags,
|
|
|
|
'info' => $pageInfo,
|
|
|
|
];
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function archive()
|
|
|
|
{
|
|
|
|
$pages = $this->contents->loadAllPages();
|
|
|
|
$years = [];
|
|
|
|
$archive = [];
|
|
|
|
foreach ($pages as $page) {
|
|
|
|
// $year = date("Y", date($page["rawCreated"]));
|
|
|
|
$date = explode('/', $page['path']);
|
|
|
|
// echo $page["title"] . " : " . $year . "\n";
|
|
|
|
if (!find($years, ['year' => trim($date[0])])) {
|
|
|
|
$findPages = filter($pages, ['createdYear' => trim($date[0])]);
|
|
|
|
// var_dump($findPages);
|
|
|
|
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
|
|
|
$global = $this->settings->getGlobal();
|
|
|
|
$archive_data = [];
|
|
|
|
$pageInfo = [
|
|
|
|
'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'],
|
|
|
|
];
|
|
|
|
$archiveData = [
|
|
|
|
'archive' => $this->p_archive,
|
|
|
|
'info' => $pageInfo,
|
|
|
|
];
|
|
|
|
|
|
|
|
return $archiveData;
|
2024-03-14 19:39:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function page($page)
|
|
|
|
{
|
|
|
|
$global = $this->settings->getGlobal();
|
|
|
|
$pageOptions = [];
|
|
|
|
|
|
|
|
$pageInfo = [
|
|
|
|
'keywords' => isset($global['keywords'])
|
|
|
|
? $global['keywords']
|
|
|
|
: 'fipamo, blog, jamstack, php, markdown, js',
|
|
|
|
'description' => $global['descriptions'],
|
|
|
|
'image' => $global['base_url'] . $global['background'],
|
|
|
|
'baseURL' => $global['base_url'],
|
|
|
|
];
|
|
|
|
$tags = [];
|
|
|
|
if (isset($page['tags'])) {
|
|
|
|
$taglist = explode(',', $page['tags']);
|
|
|
|
foreach ($taglist as $tag) {
|
|
|
|
$label = trim($tag);
|
|
|
|
array_push($tags, [
|
|
|
|
'label' => $label . ' ',
|
|
|
|
'slug' => $this->strings->safeString($label),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$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) {
|
|
|
|
$pageInfo['image'] = $pageInfo['baseURL'] . $item;
|
|
|
|
$set = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-03-15 03:03:46 +01:00
|
|
|
//TODO: get rid of if statement and always return recent and featured
|
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
|
|
|
|
|
|
|
$pageOptions = [
|
|
|
|
'title' => $page['title'],
|
|
|
|
'background' => $page['feature'],
|
|
|
|
'content' => $page['html'],
|
|
|
|
'meta' => $meta,
|
|
|
|
'recent' => $recent,
|
|
|
|
'featured' => $featured,
|
|
|
|
'info' => $pageInfo,
|
|
|
|
'menu' => $this->settings->getMenu(),
|
|
|
|
'dynamicRender' => $global['dynamicRender'],
|
|
|
|
'media' => $page['media'],
|
|
|
|
'files' => $page['docs'],
|
|
|
|
'tags' => $meta['tags'],
|
|
|
|
];
|
2024-03-14 23:58:11 +01:00
|
|
|
return $pageOptions;
|
2024-03-14 19:39:43 +01:00
|
|
|
}
|
|
|
|
}
|