aboutsummaryrefslogtreecommitdiff
path: root/_site/includes
diff options
context:
space:
mode:
authorMinteck <46352972+Minteck@users.noreply.github.com>2021-07-01 00:54:32 +0200
committerMinteck <46352972+Minteck@users.noreply.github.com>2021-07-01 00:54:32 +0200
commit1d62401c897a5ba82d0def92d97d09195a6d676f (patch)
treed26f11765a4eee20ac4867d5b77794fcdcaac641 /_site/includes
parent1f23d65f32e37d0c6d703951d6735c9926f8521c (diff)
downloadunchainedtech-1d62401c897a5ba82d0def92d97d09195a6d676f.tar.gz
unchainedtech-1d62401c897a5ba82d0def92d97d09195a6d676f.tar.bz2
unchainedtech-1d62401c897a5ba82d0def92d97d09195a6d676f.zip
Fixed stuff + official logo
Diffstat (limited to '_site/includes')
-rw-r--r--_site/includes/admin/authorized.json4
-rw-r--r--_site/includes/admin/credentials.default.json5
-rw-r--r--_site/includes/articles/getlist.php93
-rw-r--r--_site/includes/dom/footer.php3
-rw-r--r--_site/includes/dom/header.php84
5 files changed, 183 insertions, 6 deletions
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 @@
-<p style="margin-top:20px;text-align:center;"><a href="/feed.xml" style="text-decoration: underline;">View RSS feed</a></p>
+
+<p style="margin-top:20px;text-align:center;"><a href="/feed.xml" style="text-decoration: underline;">View RSS feed</a><?= $admin ? "<span class='admin-text'> (doesn't include unreleased articles)</span>" : "" ?></p>
<hr>
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() {
<!DOCTYPE html>
<html>
<head>
- <title>Something went wrong - Blogchain</title>
+ <title>Something went wrong on Blogchain 🌙</title>
<style>
@font-face {
@@ -117,7 +152,7 @@ function customError($errno, $errstr, $errfile = "&lt;unknown file&gt;", $errlin
<!DOCTYPE html>
<html>
<head>
- <title>Something went wrong - Blogchain</title>
+ <title>Something went wrong on Blogchain 🌙</title>
<style>
@font-face {
@@ -187,12 +222,15 @@ set_error_handler("customError", E_ALL);
register_shutdown_function("customShutdown");
?>
+
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
- <title><?= isset($_TITLE) ? $_TITLE . " - Blogchain" : "Blogchain" ?></title>
+ <meta name="description" content="<?= $_DESCRIPTION ?? "A page from Blogchain, a blog made by technology enthusiasts that talks about all sorts of stuff." ?>">
+ <title><?= isset($_TITLE) ? $_TITLE . " on Blogchain 🌙" : "Blogchain" ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="icon" href="/logo.svg">
<link rel="stylesheet" href="/css/bootstrap.min.css">
<style>
@@ -299,11 +337,44 @@ register_shutdown_function("customShutdown");
background-position: center;
}
+ .badge-secondary {
+ background: black;
+ border: 1px solid #ffff00;
+ color: #ffff00 !important;
+ font-weight: normal;
+ }
+
+ .nav-admin {
+ color: #ffff00 !important;
+ outline-color: #ffff00 !important;
+ }
+
+ a.list-group-item.list-group-item-action.list-group-item-admin {
+ border-color: #ffff00;
+ color: #ffff00 !important;
+ }
+
+ a.list-group-item.list-group-item-action.list-group-item-admin:hover {
+ background-color: #ffff00 !important;
+ }
+
+ .card-admin {
+ filter: hue-rotate(-45deg);
+ }
+
+ .admin-text {
+ color: #ffff00 !important;
+ }
+
+ .list-admin-warning, .list-admin-warning * {
+ color: #ff0000 !important;
+ }
+
</style>
</head>
<body>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
- <a class="navbar-brand" href="/"># blogchain_</a>
+ <a class="navbar-brand" href="/"><img id="siteicon" src="/logo-alt.svg" width="32px"> <span style="vertical-align: middle;"># blogchain_ <?= $admin ? '<span class="badge badge-secondary">admin</span>' : '' ?></span></a>
<ul class="navbar-nav">
<li class="nav-item">
@@ -315,6 +386,11 @@ register_shutdown_function("customShutdown");
<li class="nav-item">
<a class="nav-link" href="/about">About</a>
</li>
+ <?php if ($admin): ?>
+ <li class="nav-item">
+ <a class="nav-link nav-admin" href="/admin">Administration</a>
+ </li>
+ <?php endif; ?>
</ul>
</nav> \ No newline at end of file