2024-03-08 21:09:43 +01:00
|
|
|
<?php
|
|
|
|
|
2024-05-13 06:14:53 +02:00
|
|
|
namespace App\Services\Assets;
|
2024-03-08 21:09:43 +01:00
|
|
|
|
|
|
|
class DocService
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function writePages($task, $path, $fileLocation, $fileContents)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if ($task == 'create') {
|
|
|
|
if (!is_dir('../content/pages/' . $path)) {
|
|
|
|
//Directory does not exist, so lets create it.
|
|
|
|
mkdir('../content/pages/' . $path, 0755, true);
|
|
|
|
}
|
|
|
|
file_put_contents($fileLocation, $fileContents);
|
|
|
|
} else {
|
|
|
|
($new = fopen($fileLocation, 'w')) or die('Unable to open file!');
|
|
|
|
fwrite($new, $fileContents);
|
|
|
|
fclose($new);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} catch (Error $error) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-12 23:16:36 +01:00
|
|
|
public static function updateMenu($body)
|
2024-03-08 21:09:43 +01:00
|
|
|
{
|
2024-03-12 23:16:36 +01:00
|
|
|
$settings = self::$settings;
|
|
|
|
//$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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DocTools::writeSettings('../config/settings.json', $settings);
|
|
|
|
}
|
|
|
|
|
2024-04-16 23:36:57 +02:00
|
|
|
public static function writeSettings($fileContents, $location = null)
|
2024-03-12 23:16:36 +01:00
|
|
|
{
|
2024-04-16 23:36:57 +02:00
|
|
|
if (is_null($location)) {
|
|
|
|
$fileLocation = env('SETTINGS_PATH');
|
|
|
|
} else {
|
|
|
|
$fileLocation = $location;
|
|
|
|
}
|
|
|
|
|
|
|
|
$message = [];
|
2024-03-19 23:35:02 +01:00
|
|
|
try {
|
|
|
|
if (!is_file($fileLocation)) {
|
|
|
|
file_put_contents($fileLocation, json_encode($fileContents));
|
|
|
|
} else {
|
|
|
|
($new = fopen($fileLocation, 'w')) or die('Unable to open file!');
|
|
|
|
fwrite($new, json_encode($fileContents));
|
|
|
|
fclose($new);
|
|
|
|
}$message = [
|
|
|
|
'message' => "Settings Synced. You're doing great!",
|
|
|
|
'type' => 'settingsUpdated',
|
|
|
|
];
|
|
|
|
} catch (Error $error) {
|
|
|
|
$message = [
|
|
|
|
'message' => "Settings Not Synced. We'll figure it out",
|
|
|
|
'type' => 'settingsUpdated',
|
|
|
|
];
|
2024-03-08 21:09:43 +01:00
|
|
|
}
|
2024-03-19 23:35:02 +01:00
|
|
|
|
|
|
|
return $message;
|
2024-03-08 21:09:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function writeHTML($location, $html, $path = null)
|
|
|
|
{
|
|
|
|
if ($path != null) {
|
|
|
|
if (!is_dir($path)) {
|
|
|
|
//Directory does not exist, so lets create it.
|
|
|
|
mkdir($path, 0755, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!is_file($location)) {
|
|
|
|
file_put_contents($location, $html);
|
|
|
|
} else {
|
|
|
|
($new = fopen($location, 'w')) or die('Unable to open file!');
|
|
|
|
fwrite($new, $html);
|
|
|
|
fclose($new);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function deleteFolder($path)
|
|
|
|
{
|
|
|
|
if (!empty($path) && is_dir($path)) {
|
|
|
|
$dir = new \RecursiveDirectoryIterator(
|
|
|
|
$path,
|
|
|
|
\RecursiveDirectoryIterator::SKIP_DOTS
|
|
|
|
); //upper dirs are not included,otherwise DISASTER HAPPENS :)
|
|
|
|
$files = new \RecursiveIteratorIterator(
|
|
|
|
$dir,
|
|
|
|
\RecursiveIteratorIterator::CHILD_FIRST
|
|
|
|
);
|
|
|
|
foreach ($files as $f) {
|
|
|
|
if (is_file($f)) {
|
|
|
|
unlink($f);
|
|
|
|
} else {
|
|
|
|
$empty_dirs[] = $f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty($empty_dirs)) {
|
|
|
|
foreach ($empty_dirs as $eachDir) {
|
|
|
|
rmdir($eachDir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rmdir($path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function objectToMD($object)
|
|
|
|
{
|
|
|
|
$markdown = "---\n" .
|
|
|
|
'id: ' .
|
|
|
|
$object->id .
|
|
|
|
"\n" .
|
|
|
|
'uuid: ' .
|
|
|
|
$object->uuid .
|
|
|
|
"\n" .
|
|
|
|
'title: ' .
|
|
|
|
"'" .
|
|
|
|
$object->title .
|
|
|
|
"'" .
|
|
|
|
"\n" .
|
|
|
|
'feature: ' .
|
|
|
|
$object->imageList .
|
|
|
|
"\n" .
|
|
|
|
'files: ' .
|
|
|
|
$object->fileList .
|
|
|
|
"\n" .
|
|
|
|
'path: ' .
|
|
|
|
$object->path .
|
|
|
|
"\n" .
|
|
|
|
'layout: ' .
|
|
|
|
$object->layout .
|
|
|
|
"\n" .
|
|
|
|
'tags: ' .
|
|
|
|
$object->tags .
|
|
|
|
"\n" .
|
|
|
|
'author: ' .
|
|
|
|
$object->author .
|
|
|
|
"\n" .
|
|
|
|
'created: ' .
|
|
|
|
$object->created .
|
|
|
|
"\n" .
|
|
|
|
'updated: ' .
|
|
|
|
$object->updated .
|
|
|
|
"\n" .
|
|
|
|
'deleted: ' .
|
|
|
|
$object->deleted .
|
|
|
|
"\n" .
|
|
|
|
'slug: ' .
|
|
|
|
$object->slug .
|
|
|
|
"\n" .
|
|
|
|
'menu: ' .
|
|
|
|
$object->menu .
|
|
|
|
"\n" .
|
|
|
|
'published: ' .
|
2024-03-15 22:18:10 +01:00
|
|
|
$object->published .
|
2024-03-08 21:09:43 +01:00
|
|
|
"\n" .
|
|
|
|
'featured: ' .
|
|
|
|
$object->featured .
|
|
|
|
"\n---\n" .
|
|
|
|
$object->content;
|
|
|
|
|
|
|
|
return $markdown;
|
|
|
|
}
|
|
|
|
}
|