-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
398 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
session_start(); | ||
|
||
function getTitle($string) { | ||
$pattern = "/<h1>(.*?)<\/h1>/"; | ||
preg_match_all($pattern, $string, $matches); | ||
return ($matches[1]); | ||
} | ||
|
||
function stringifyTitle($str, $delimiter = '-') { | ||
$slug = strtolower(trim(preg_replace('/[\s-]+/', $delimiter, preg_replace('/[^A-Za-z0-9-]+/', $delimiter, preg_replace('/[&]/', 'and', preg_replace('/[\']/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $str))))), $delimiter)); | ||
return $slug; | ||
} | ||
|
||
if (isset($_SESSION["in"]) && $_SESSION["in"] === 1) { | ||
|
||
include("data.php"); | ||
include("bones/function.php"); | ||
|
||
|
||
if (isset($_POST["writearea"]) && $_POST["writearea"] !== "") { | ||
|
||
include("parsedown/Parsedown.php"); | ||
$Parsedown = new Parsedown(); | ||
|
||
// parse all content to html | ||
$content = $Parsedown->text($_POST["writearea"]); | ||
|
||
// get title and slug before cutting it from the content | ||
$title = getTitle($content); | ||
$slug = stringifyTitle(implode($title)); | ||
|
||
// crop the title and make perex | ||
$content = substr($content, strpos($content, '</h1>') + 5); | ||
$perex = mb_strimwidth(strip_tags($content), 0, 180, "..."); | ||
|
||
|
||
mkdir("../".$slug); | ||
|
||
// create markdown backup for future edits | ||
$file = fopen("../".$slug."/article.md","w"); | ||
fwrite($file, $_POST["writearea"]); | ||
fclose($file); | ||
|
||
// create title file for navigation | ||
$file = fopen("../".$slug."/name","w"); | ||
fwrite($file, implode($title)); | ||
fclose($file); | ||
|
||
// create actual permalink file | ||
$file = fopen("../".$slug."/index.php","w"); | ||
|
||
// pre-created html filled with new content | ||
$fileString = makePageDOM(implode($title),$perex,$siteDescription,$siteName,$content,$slug); | ||
|
||
fwrite($file, $fileString); | ||
fclose($file); | ||
|
||
header("Location: index.php"); | ||
|
||
} | ||
|
||
?> | ||
|
||
<!doctype html> | ||
<html lang="cs"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title><?=$siteName;?></title> | ||
<link rel="stylesheet" type="text/css" href="pretty/neon.css"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1"> | ||
<meta name="description" content="<?=$siteDescription;?>"> | ||
<link rel="preconnect" href="https://fonts.gstatic.com"> | ||
<link href="https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,700;1,400&display=swap" rel="stylesheet"> | ||
<link rel="icon" type="image/png" href="pretty/i/favicon.png"> | ||
</head> | ||
<body> | ||
<main> | ||
<form action="addpage.php" method="post" class="write"> | ||
<nav class="clean"> | ||
<a class="graylink" href="../admin/">Discard</a> | ||
<input type="submit" value="Publish"> | ||
</nav> | ||
<textarea name="writearea" spellcheck="false" placeholder="# Start with a title" autofocus></textarea> | ||
</form> | ||
</main> | ||
</body> | ||
</html> | ||
<?php } else { | ||
header("Location: ../admin/"); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
session_start(); | ||
include("../admin/data.php"); | ||
|
||
function makeArticleDOM($title,$perex,$siteName,$content) { | ||
|
||
$date = date("Y-m-d"); | ||
$DOM = <<<LOL | ||
<?php include("../../admin/data.php"); ?> | ||
<!doctype html> | ||
<html lang="cs"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>$title</title> | ||
<link rel="stylesheet" type="text/css" href="../../admin/pretty/neon.css"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1"> | ||
<meta name="description" content="$perex"> | ||
<link rel="preconnect" href="https://fonts.gstatic.com"> | ||
<link href="https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,700;1,400&display=swap" rel="stylesheet"> | ||
<link rel="icon" type="image/png" href="../../admin/pretty/i/favicon.png"> | ||
</head> | ||
<body> | ||
<main> | ||
<header class="blogpost"> | ||
<h2><a href="../../">$siteName</a></h2> | ||
</header> | ||
<section><h1>$title</h1><span>$date</span><div>$content</div></section> | ||
</main> | ||
</body> | ||
</html> | ||
LOL; | ||
return $DOM; | ||
} | ||
|
||
function makePageDOM($title,$perex,$siteDescription,$siteName,$content,$slug) { | ||
|
||
|
||
$DOM = <<<LOL | ||
<!doctype html> | ||
<html lang="cs"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>$title</title> | ||
<link rel="stylesheet" type="text/css" href="../admin/pretty/neon.css"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1"> | ||
<meta name="description" content="$siteDescription"> | ||
<link rel="preconnect" href="https://fonts.gstatic.com"> | ||
<link href="https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,700;1,400&display=swap" rel="stylesheet"> | ||
<link rel="icon" type="image/png" href="../admin/pretty/i/favicon.png"> | ||
</head> | ||
<body> | ||
<main> | ||
<header> | ||
<h2><a href="../">$siteName</a></h2> | ||
<p>$siteDescription</p> | ||
</header> | ||
<?php include("../admin/bones/nav.php"); ?> | ||
<?php include("../admin/bones/pageadminnav.php"); ?> | ||
<section><div>$content</div></section> | ||
</main> | ||
<script src="../admin/pretty/do.js"></script> | ||
</body> | ||
</html> | ||
LOL; | ||
return $DOM; | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
include("../admin/data.php"); | ||
|
||
if ($siteExtraEnabledPages === "1") { | ||
$pagePath = "../*"; | ||
$pageArray = glob($pagePath, GLOB_ONLYDIR); | ||
|
||
$nav = "<nav class='pages'>"; | ||
$nav.= "<a href='../'>Blog</a>"; | ||
|
||
foreach ($pageArray as $page) { | ||
if ($page !== "../admin" && $page !== "../".$siteBlogPageSlug) { | ||
$name = file_get_contents($page."/name",true); | ||
$nav .= "<a href='".$page."'>".$name."</a>"; | ||
} | ||
} | ||
|
||
$nav .= "</nav>"; | ||
echo $nav; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
session_start(); | ||
include("../admin/data.php"); | ||
|
||
if ($siteExtraEnabledPages === "1" && isset($_SESSION["in"]) && $_SESSION["in"] === 1) { | ||
|
||
|
||
$nav = <<<LOL | ||
<nav class="adminnav"> | ||
<a href="../admin/" class="graylink">Return back</a> | ||
<a href="../admin/editpage.php" id="editpage" class="graylink">Edit this page</a> | ||
<a href="#" id="deletepage" class="graylink">Delete this page</a> | ||
</nav> | ||
LOL; | ||
echo $nav; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<?php $siteName = "Blog title";$siteDescription = "Lengthy blog description"; $sitePassword = "pencil"; $siteBlogPageSlug = "blog"; ?> | ||
<?php $siteName = "Blog title";$siteDescription = "Lengthy blog description"; $sitePassword = "pencil"; $siteBlogPageSlug = "blog"; $siteExtraEnabledPages = "0"; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
session_start(); | ||
|
||
if (isset($_SESSION["in"]) && $_SESSION["in"] === 1 && isset($_GET["id"])) { | ||
include("data.php"); | ||
$dirname = $_GET["id"]; | ||
array_map('unlink', glob("../".$dirname."/*")); | ||
rmdir("../".$dirname); | ||
header("Location: ../admin/"); | ||
} else { | ||
header("Location: ../admin/"); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
session_start(); | ||
|
||
function getTitle($string) { | ||
$pattern = "/<h1>(.*?)<\/h1>/"; | ||
preg_match_all($pattern, $string, $matches); | ||
return ($matches[1]); | ||
} | ||
|
||
function stringifyTitle($str, $delimiter = '-') { | ||
$slug = strtolower(trim(preg_replace('/[\s-]+/', $delimiter, preg_replace('/[^A-Za-z0-9-]+/', $delimiter, preg_replace('/[&]/', 'and', preg_replace('/[\']/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $str))))), $delimiter)); | ||
return $slug; | ||
} | ||
|
||
if (isset($_SESSION["in"]) && $_SESSION["in"] === 1) { | ||
|
||
include("data.php"); | ||
include("bones/function.php"); | ||
$id = $_GET["id"]; | ||
|
||
|
||
if (isset($_POST["writearea"]) && $_POST["writearea"] !== "") { | ||
|
||
include("parsedown/Parsedown.php"); | ||
$Parsedown = new Parsedown(); | ||
|
||
// parse all content to html | ||
$content = $Parsedown->text($_POST["writearea"]); | ||
|
||
// get title and slug before cutting it from the content | ||
$title = getTitle($content); | ||
$slug = stringifyTitle(implode($title)); | ||
|
||
// crop the title and make perex | ||
$content = substr($content, strpos($content, '</h1>') + 5); | ||
$perex = mb_strimwidth(strip_tags($content), 0, 180, "..."); | ||
|
||
// delete original page if slug differs | ||
if ($slug !== $id) { | ||
array_map('unlink', glob("../".$id."/*")); | ||
rmdir("../".$id); | ||
mkdir("../".$slug); | ||
} | ||
|
||
// create markdown backup for future edits | ||
$file = fopen("../".$slug."/article.md","w"); | ||
fwrite($file, $_POST["writearea"]); | ||
fclose($file); | ||
|
||
// create title file for navigation | ||
$file = fopen("../".$slug."/name","w"); | ||
fwrite($file, implode($title)); | ||
fclose($file); | ||
|
||
// create actual permalink file | ||
$file = fopen("../".$slug."/index.php","w"); | ||
|
||
// pre-created html filled with new content | ||
$fileString = makePageDOM(implode($title),$perex,$siteDescription,$siteName,$content,$slug); | ||
|
||
fwrite($file, $fileString); | ||
fclose($file); | ||
|
||
header("Location: ../".$id); | ||
|
||
} | ||
|
||
?> | ||
|
||
<!doctype html> | ||
<html lang="cs"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title><?=$siteName;?></title> | ||
<link rel="stylesheet" type="text/css" href="pretty/neon.css"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1"> | ||
<meta name="description" content="<?=$siteDescription;?>"> | ||
<link rel="preconnect" href="https://fonts.gstatic.com"> | ||
<link href="https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,700;1,400&display=swap" rel="stylesheet"> | ||
<link rel="icon" type="image/png" href="pretty/i/favicon.png"> | ||
</head> | ||
<body> | ||
<main> | ||
<form action="addpage.php" method="post" class="write"> | ||
<nav class="clean"> | ||
<a class="graylink" href="../admin/">Discard</a> | ||
<input type="submit" value="Publish"> | ||
</nav> | ||
<textarea name="writearea" spellcheck="false" placeholder="# Start with a title" autofocus><?php | ||
$originalFile = fopen("../".$id."/article.md", "r") or die("php file reading error."); | ||
echo fread($originalFile,filesize("../".$id."/article.md")); | ||
fclose($originalFile); | ||
?></textarea> | ||
</form> | ||
</main> | ||
</body> | ||
</html> | ||
<?php } else { | ||
header("Location: ../admin/"); | ||
} | ||
?> |
Oops, something went wrong.