2024-03-01 20:34:36 +01:00
|
|
|
<?php
|
|
|
|
|
2024-05-13 06:14:53 +02:00
|
|
|
namespace App\Services\Data;
|
2024-03-01 20:34:36 +01:00
|
|
|
|
2024-03-22 21:35:44 +01:00
|
|
|
use Carbon\Carbon;
|
2024-05-13 06:14:53 +02:00
|
|
|
use App\Services\Assets\DocService;
|
2024-03-22 21:35:44 +01:00
|
|
|
|
|
|
|
use function _\find;
|
2024-06-26 01:01:10 +02:00
|
|
|
use function _\pull;
|
2024-03-22 21:35:44 +01:00
|
|
|
|
2024-03-01 20:34:36 +01:00
|
|
|
class SettingsService
|
|
|
|
{
|
2024-03-12 23:16:36 +01:00
|
|
|
protected $settings;
|
2024-03-01 20:34:36 +01:00
|
|
|
protected $tags;
|
2024-03-12 23:16:36 +01:00
|
|
|
protected $docs;
|
2024-03-22 21:35:44 +01:00
|
|
|
protected $contents;
|
2024-03-01 20:34:36 +01:00
|
|
|
|
2024-03-22 21:35:44 +01:00
|
|
|
public function __construct(DocService $docService, ContentService $contentService)
|
2024-03-01 20:34:36 +01:00
|
|
|
{
|
2024-05-08 23:55:27 +02:00
|
|
|
if (file_exists(env('TAGS_PATH'))) {
|
|
|
|
$this->tags = json_decode(file_get_contents(env('TAGS_PATH')), true);
|
|
|
|
} else {
|
|
|
|
$this->tags = [];
|
|
|
|
}
|
2024-05-13 21:36:06 +02:00
|
|
|
|
2024-07-26 20:43:45 +02:00
|
|
|
$this->docs = $docService;
|
|
|
|
$this->contents = $contentService;
|
2024-03-12 23:16:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function loadSettings()
|
|
|
|
{
|
2024-05-08 23:55:27 +02:00
|
|
|
$settings = [];
|
|
|
|
//if config files aren't avaiable, load templates
|
|
|
|
if (file_exists(env('SETTINGS_PATH'))) {
|
|
|
|
$settings = json_decode(file_get_contents(env('SETTINGS_PATH')), true);
|
|
|
|
} else {
|
|
|
|
$settings = json_decode(
|
|
|
|
file_get_contents('../content/init/settings-template.json'),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $settings;
|
2024-03-12 23:16:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getSettings()
|
|
|
|
{
|
|
|
|
return $this->loadSettings();
|
2024-03-01 20:34:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getGlobal()
|
|
|
|
{
|
2024-03-12 23:16:36 +01:00
|
|
|
$this->settings = $this->loadSettings();
|
|
|
|
return $this->settings['global'];
|
2024-03-01 20:34:36 +01:00
|
|
|
}
|
|
|
|
|
2024-03-19 20:19:27 +01:00
|
|
|
public function getEmail()
|
|
|
|
{
|
|
|
|
$this->settings = $this->loadSettings();
|
|
|
|
return $this->settings['email'];
|
|
|
|
}
|
|
|
|
|
2024-03-14 19:39:43 +01:00
|
|
|
public function getMenu()
|
|
|
|
{
|
|
|
|
$this->settings = $this->loadSettings();
|
|
|
|
return $this->settings['menu'];
|
|
|
|
}
|
|
|
|
|
2024-03-15 21:28:26 +01:00
|
|
|
public function getTags()
|
|
|
|
{
|
|
|
|
return $this->tags;
|
|
|
|
}
|
|
|
|
|
2024-03-12 23:16:36 +01:00
|
|
|
public function updatePageIndex()
|
|
|
|
{
|
|
|
|
$this->settings = $this->loadSettings();
|
|
|
|
$this->settings['library_stats']['current_index']++;
|
|
|
|
$this->docs->writeSettings($this->settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateGlobalData($key, $value)
|
|
|
|
{
|
|
|
|
$this->settings = $this->loadSettings();
|
2024-04-05 20:29:38 +02:00
|
|
|
$this->settings['global'][$key] = $value;
|
2024-03-12 23:16:36 +01:00
|
|
|
$this->docs->writeSettings($this->settings);
|
|
|
|
}
|
2024-03-19 23:35:02 +01:00
|
|
|
|
2024-03-22 21:35:44 +01:00
|
|
|
public function updateMenu($body)
|
|
|
|
{
|
|
|
|
$settings = $this->loadSettings();
|
|
|
|
//$menu = $settings["menu"];
|
|
|
|
$item = [
|
|
|
|
'title' => $body->title,
|
|
|
|
'id' => $body->id,
|
|
|
|
'uuid' => $body->uuid,
|
|
|
|
'slug' => $body->slug,
|
|
|
|
'path' => $body->path,
|
|
|
|
];
|
|
|
|
if ($body->menu == 'true') {
|
|
|
|
if (!find($settings['menu'], ['uuid' => $item['uuid']])) {
|
|
|
|
array_push($settings['menu'], $item);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (find($settings['menu'], ['uuid' => $item['uuid']])) {
|
|
|
|
pull($settings['menu'], $item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->docs->writeSettings($settings);
|
|
|
|
}
|
|
|
|
|
2024-04-22 23:19:06 +02:00
|
|
|
public function updateTags($update)
|
|
|
|
{
|
|
|
|
$this->docs->writeSettings($update, env('TAGS_PATH'));
|
|
|
|
}
|
|
|
|
|
2024-03-19 23:35:02 +01:00
|
|
|
public function sync($data)
|
|
|
|
{
|
|
|
|
$settings = $this->getSettings();
|
|
|
|
$settings['global']['base_url'] = $data->global->base_url;
|
|
|
|
$settings['global']['title'] = $data->global->title;
|
|
|
|
$settings['global']['descriptions'] = $data->global->descriptions;
|
|
|
|
$settings['global']['private'] = $data->global->private;
|
|
|
|
$settings['global']['renderOnSave'] = $data->global->renderOnSave;
|
|
|
|
$settings['global']['theme'] = $data->global->theme;
|
|
|
|
$settings['global']['externalAPI'] = $data->global->externalAPI;
|
|
|
|
$settings['global']['dynamicRender'] = $data->global->dynamicRender;
|
|
|
|
|
2024-06-25 23:33:42 +02:00
|
|
|
//$settings['email']['active'] = $data->email->active;
|
|
|
|
//$settings['email']['smtp'] = $data->email->smtp;
|
|
|
|
//$settings['email']['mailgun'] = $data->email->mailgun;
|
2024-03-19 23:35:02 +01:00
|
|
|
|
2024-05-13 21:36:06 +02:00
|
|
|
return $this->docs::writeSettings($settings);
|
2024-03-19 23:35:02 +01:00
|
|
|
}
|
2024-03-22 21:35:44 +01:00
|
|
|
|
|
|
|
public function navSync($data)
|
|
|
|
{
|
|
|
|
$settings = $this->loadSettings();
|
|
|
|
$pages = $this->contents->loadAllPages();
|
|
|
|
$remove = $data->remove;
|
|
|
|
$result = [];
|
|
|
|
//if remove contains id, find nav item page and set menu to false
|
|
|
|
if ($remove != null || $remove != '') {
|
|
|
|
$page = $pages->where('uuid', $remove)->first();
|
|
|
|
$page['menu'] = 'false';
|
|
|
|
$page['published']
|
|
|
|
? ($page['published'] = 'true')
|
|
|
|
: ($page['published'] = 'false');
|
|
|
|
$page['featured']
|
|
|
|
? ($page['featured'] = 'true')
|
|
|
|
: ($page['featured'] = 'false');
|
|
|
|
$page['deleted']
|
|
|
|
? ($page['deleted'] = 'true')
|
|
|
|
: ($page['deleted'] = 'false');
|
|
|
|
$updated = Carbon::now();
|
|
|
|
$created = new Carbon($page['rawCreated']);
|
|
|
|
$page['created'] = $created->format("Y-m-d\TH:i:sP");
|
|
|
|
$page['updated'] = $updated->format("Y-m-d\TH:i:sP");
|
|
|
|
|
|
|
|
if ($page['layout'] == 'index') {
|
|
|
|
$writePath = '../content/pages/start/index.md';
|
|
|
|
} else {
|
|
|
|
$writePath = '../content/pages/' . $page['path'] . '/' . $page['slug'] . '.md';
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$object = (object) $page;
|
|
|
|
$object->imageList = $page['feature'];
|
|
|
|
$object->fileList = $page['files'];
|
|
|
|
$this->docs::writePages('write', $page['path'], $writePath, $this->docs::objectToMD($object));
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$result = [
|
|
|
|
'message' => 'Page Was Not Updated. Be cool ',
|
|
|
|
'type' => 'pageUpdateError',
|
|
|
|
'error' => $e->getMessage(),
|
|
|
|
];
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$settings['menu'] = [];
|
|
|
|
$items = $data->menu;
|
|
|
|
foreach ($items as $item) {
|
|
|
|
array_push($settings['menu'], [
|
|
|
|
'title' => $item->title,
|
|
|
|
'id' => $item->id,
|
|
|
|
'uuid' => $item->uuid,
|
|
|
|
'slug' => $item->slug,
|
|
|
|
'path' => $item->path,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$this->docs->writeSettings($settings);
|
|
|
|
$result = [
|
|
|
|
'message' => 'Navigation updated. Very slick!',
|
|
|
|
'type' => 'menuUpdated',
|
|
|
|
];
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$result = [
|
|
|
|
'message' => 'Navigation Update Error. It\'ll be ok!',
|
|
|
|
'type' => 'menuUpdateError',
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2024-03-01 20:34:36 +01:00
|
|
|
}
|