fipamo/brain/utility/DocTools.inc.php

91 lines
1.8 KiB
PHP
Raw Normal View History

2021-04-14 21:48:57 +02:00
<?php
class DocTools
{
public function __construct()
{
}
public static function writePages($task, $path, $fileLocation, $fileContents)
2021-04-14 21:48:57 +02:00
{
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;
}
}
public static function writeSettings($fileLocation, $fileContents)
{
($new = fopen($fileLocation, "w")) or die("Unable to open file!");
fwrite($new, json_encode($fileContents));
fclose($new);
}
public static function objectToMD($object)
{
$markdown =
"---\n" .
"id: " .
$object["id"] .
"\n" .
"uuid: " .
$object["uuid"] .
"\n" .
"title: " .
$object["title"] .
"\n" .
"feature: " .
$object["feature"] .
"\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: " .
$object["published"] .
"\n" .
"featured: " .
$object["featured"] .
"\n---\n" .
$object["content"];
return $markdown;
}
2021-04-14 21:48:57 +02:00
}