From 1d62401c897a5ba82d0def92d97d09195a6d676f Mon Sep 17 00:00:00 2001 From: Minteck <46352972+Minteck@users.noreply.github.com> Date: Thu, 1 Jul 2021 00:54:32 +0200 Subject: Fixed stuff + official logo --- _site/includes/admin/authorized.json | 4 ++ _site/includes/admin/credentials.default.json | 5 ++ _site/includes/articles/getlist.php | 93 ++++++++++++++++++++++++++- _site/includes/dom/footer.php | 3 +- _site/includes/dom/header.php | 84 ++++++++++++++++++++++-- 5 files changed, 183 insertions(+), 6 deletions(-) create mode 100644 _site/includes/admin/authorized.json create mode 100644 _site/includes/admin/credentials.default.json (limited to '_site/includes') diff --git a/_site/includes/admin/authorized.json b/_site/includes/admin/authorized.json new file mode 100644 index 0000000..72784f0 --- /dev/null +++ b/_site/includes/admin/authorized.json @@ -0,0 +1,4 @@ +[ + "antoine62", + "Minteck" +] \ No newline at end of file diff --git a/_site/includes/admin/credentials.default.json b/_site/includes/admin/credentials.default.json new file mode 100644 index 0000000..83b9e5b --- /dev/null +++ b/_site/includes/admin/credentials.default.json @@ -0,0 +1,5 @@ +{ + "id": "your client id", + "secret": "your client secret", + "token": "the personnal access token of a user that has access to the repository" +} \ No newline at end of file diff --git a/_site/includes/articles/getlist.php b/_site/includes/articles/getlist.php index e82a192..8018472 100644 --- a/_site/includes/articles/getlist.php +++ b/_site/includes/articles/getlist.php @@ -22,7 +22,8 @@ function getArticlesList($ordered = true) { "title" => $id, "author" => "Blogchain", "cover" => null, - "extract" => "" + "extract" => "", + "admin" => false ]; $list[$id]["id"] = $id; @@ -84,6 +85,96 @@ function getArticlesList($ordered = true) { } else { $list[$id]["content"]["mini"] = $list[$id]["content"]["clean"]; } + if (strlen($list[$id]["content"]["clean"]) > 500) { + $list[$id]["content"]["little"] = substr($list[$id]["content"]["clean"], 0, 500) . "…"; + } else { + $list[$id]["content"]["little"] = $list[$id]["content"]["clean"]; + } + } + } + + $files = scandir($_SERVER['DOCUMENT_ROOT'] . "/../_posts/_drafts"); + + foreach ($files as $file) { + if (is_file($_SERVER['DOCUMENT_ROOT'] . "/../_posts/_drafts/" . $file) && $file !== "_template.md" && $file !== ".gitkeep") { + $content = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/../_posts/_drafts/" . $file); + $lines = explode("\n", $content); + $unlined = []; + + $id = substr($file, 0, -3); + $list[$id] = [ + "date" => date("Ymd"), + "title" => $id, + "author" => [ "Blogchain Authors" ], + "cover" => null, + "extract" => "", + "admin" => true + ]; + $list[$id]["id"] = $id; + + $propertiesMode = false; + $propertiesDone = false; + $cline = 0; + $upline = 0; + foreach ($lines as $line) { + if (!$propertiesDone) { + if (trim($line) === "---") { + if ($propertiesMode) { + $propertiesDone = true; + $propertiesMode = false; + $upline = $cline + 1; + } else { + $propertiesMode = true; + } + } else if ($propertiesMode) { + $parts = explode(":", $line); + $p_ins = trim($parts[0]); + array_shift($parts); + $p_data = trim(implode(":", $parts)); + + switch ($p_ins) { + case "date": + $pp_dt = DateTime::createFromFormat('Y-m-d', $p_data); + $list[$id]["date"] = $pp_dt->format("Ymd"); + break; + + case "title": + $list[$id]["title"] = $p_data; + break; + + case "author": + $list[$id]["author"] = explode("|", $p_data); + break; + + case "cover": + $list[$id]["cover"] = $p_data; + break; + } + } + } + $cline++; + } + + $i = 0; + while ($i++ < $upline) { + array_shift($lines); + } + + $text = implode("\n", $lines); + + $list[$id]["content"] = []; + $list[$id]["content"]["full"] = $Parsedown->text($text); + $list[$id]["content"]["clean"] = strip_tags($list[$id]["content"]["full"]); + if (strlen($list[$id]["content"]["clean"]) > 100) { + $list[$id]["content"]["mini"] = substr($list[$id]["content"]["clean"], 0, 100) . "…"; + } else { + $list[$id]["content"]["mini"] = $list[$id]["content"]["clean"]; + } + if (strlen($list[$id]["content"]["clean"]) > 500) { + $list[$id]["content"]["little"] = substr($list[$id]["content"]["clean"], 0, 500) . "…"; + } else { + $list[$id]["content"]["little"] = $list[$id]["content"]["clean"]; + } } } diff --git a/_site/includes/dom/footer.php b/_site/includes/dom/footer.php index 1d0fb97..2b0a1f2 100644 --- a/_site/includes/dom/footer.php +++ b/_site/includes/dom/footer.php @@ -1,4 +1,5 @@ -

View RSS feed

+ +

View RSS feed (doesn't include unreleased articles)" : "" ?>


diff --git a/_site/includes/dom/header.php b/_site/includes/dom/header.php index db37bab..7f4bcf5 100644 --- a/_site/includes/dom/header.php +++ b/_site/includes/dom/header.php @@ -3,9 +3,44 @@ $listGetTimeout = 0; ob_start(); +$admin = true; +if (!isset($_COOKIE["ADMIN_TOKEN"])) { + $admin = false; + if (isset($__ADMIN)) header("Location: /admin/offline") and die(); +} else { + if (!(strpos("/", $_COOKIE['ADMIN_TOKEN']) === false && strpos(".", $_COOKIE['ADMIN_TOKEN']) === false && file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/admin/tokens/" . $_COOKIE['ADMIN_TOKEN']))) { + $admin = false; + if (isset($__ADMIN)) header("Location: /admin/offline") and die(); + } else { + $_USER = trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/admin/tokens/" . $_COOKIE['ADMIN_TOKEN'])); + } +} + require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/markdown.php"; $Parsedown = new Parsedown(); +function gh_api($api) { + $crl = curl_init("https://api.github.com/" . $api); + curl_setopt($crl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($crl, CURLINFO_HEADER_OUT, true); + curl_setopt($crl, CURLOPT_POST, false); + + curl_setopt($crl, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json', + "Accept: application/json", + "Authorization: token " . json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/admin/credentials.json"), true)["token"], + "User-Agent: Blogchain-Admin/0.0.0 (nekostarfan@gmail.com)" + )); + + $result = curl_exec($crl); + + if ($result === false) { + throw new ErrorException("GitHub API unexpectedly interrupted", 214, E_ERROR); + } + + return $result; +} + require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/articles/getlist.php"; function customShutdown() { @@ -16,7 +51,7 @@ function customShutdown() { - Something went wrong - Blogchain + Something went wrong on Blogchain 🌙 \ No newline at end of file -- cgit