diff options
author | Nathan Lasseter <nathan@4574.co.uk> | 2012-10-10 20:03:21 +0100 |
---|---|---|
committer | Nathan Lasseter <nathan@4574.co.uk> | 2012-10-10 20:03:21 +0100 |
commit | 94c589ed55b20a581810e126b20fdc2d67c68221 (patch) | |
tree | 7d3d84aa3cc291417f667ee48a3fc120b95b2e43 |
Initial commit
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | .htaccess | 11 | ||||
-rw-r--r-- | README | 12 | ||||
-rw-r--r-- | archives.php | 22 | ||||
-rw-r--r-- | dopost.php | 15 | ||||
-rw-r--r-- | index.php | 44 | ||||
-rw-r--r-- | post.php | 14 | ||||
-rw-r--r-- | settings.php | 14 | ||||
-rw-r--r-- | styles.css | 62 | ||||
-rw-r--r-- | top.php | 20 | ||||
-rw-r--r-- | viewpost.php | 26 |
11 files changed, 242 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c5103b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.htpasswd +posts/ diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..5c502fc --- /dev/null +++ b/.htaccess @@ -0,0 +1,11 @@ +RewriteEngine on + +RewriteRule ^post/(.*)$ /viewpost.php?post=$1 + +<Files "dopost.php"> + AuthType Basic + AuthName "Secure" + AuthUserFile /var/www/.htpasswd +# AuthUserFile /var/www/blog/.htpasswd + Require Valid-User +</Files> @@ -0,0 +1,12 @@ +Clog + +PHP blogging software + +Released unlicensed + +Installation: +* Clone the repo +* Create a posts directory +* Edit settings.php to your liking +* Create a .htpasswd file for posting users +* Edit .htaccess to point to .htpasswd diff --git a/archives.php b/archives.php new file mode 100644 index 0000000..3f29067 --- /dev/null +++ b/archives.php @@ -0,0 +1,22 @@ +<?php + require("top.php"); + + $ls = explode("\n", `ls -1t {$blogPosts}/`); + foreach($ls as $file) { + if (preg_match('/^\./', $file)) continue; + if ($file === "") continue; + + echo "<a id=\"$file\">"; + echo "<div>\n"; + echo "<a class=\"title\" href=\"{$blogRoot}post/" . urlencode($file) . "\">$file</a>\n"; + + $stat = stat("{$blogPosts}$file"); + $date = date('d-m-Y H:i T', $stat['mtime']); + echo "<span class=\"date\">$date</span>\n"; + echo "</div>\n</a>\n\n"; + } +?> + +</body> + +</html> diff --git a/dopost.php b/dopost.php new file mode 100644 index 0000000..f4f43e5 --- /dev/null +++ b/dopost.php @@ -0,0 +1,15 @@ +<?php + require("settings.php"); + + if (!isset($_POST['title']) || !isset($_POST['content'])) { + header("location: {$blogRoot}post.php"); + exit(0); + } + + $file = $_POST['title']; + $content = $_POST['content']; + + file_put_contents("{$blogPosts}$file", $content); + + header("location: {$blogRoot}"); +?> diff --git a/index.php b/index.php new file mode 100644 index 0000000..9541b14 --- /dev/null +++ b/index.php @@ -0,0 +1,44 @@ +<?php + require("top.php"); + + $start = 0; + $show = 5; + if(isset($_GET['start'])) $start = $_GET['start']; + if(isset($_GET['show'])) $show = $_GET['show']; + + $ls = explode("\n", `ls -1t {$blogPosts}`); + + function hide($var) { + return(!preg_match('/^\./', $var)); + } + array_filter($ls, "hide"); + + $limitedls = array_slice($ls, $start, $show); + foreach($limitedls as $file) { + if ($file === "") continue; + + echo "<a id=\"$file\">"; + echo "<div>\n"; + echo "<a class=\"title\" href=\"{$blogRoot}post/" . urlencode($file) . "\">$file <span id=\"perma\">[Permalink]</span></a>\n"; + + $stat = stat("{$blogPosts}$file"); + $date = date('d-m-Y H:i T', $stat['mtime']); + echo "<span class=\"date\">$date</span>\n"; + echo "<br><br>\n"; + + $post = file_get_contents("{$blogPosts}$file"); + $post = preg_replace('/\n/', "<br>\n", $post); + echo $post; + echo "</div>\n</a>\n\n"; + } + + echo "<div id=\"title\">\n"; + $older = $start + $show; + $newer = $start - $show; + if ($newer >= 0) echo "<a class=\"toplink\" href=\"{$blogRoot}?start=$newer&show=$show\">Newer</a>\n"; + if ($older <= (count($ls) - 2)) echo "<a class=\"toplink\" href=\"{$blogRoot}?start=$older&show=$show\">Older</a>\n"; + echo "</div>\n"; +?> +</body> + +</html> diff --git a/post.php b/post.php new file mode 100644 index 0000000..9bd9138 --- /dev/null +++ b/post.php @@ -0,0 +1,14 @@ +<?php + require("top.php"); +?> +<div> +<form method="post" action="<?php echo $blogRoot; ?>dopost.php"> +<input name="title" size="50"> +<input type="submit" value="Post" /> +<textarea rows="20" cols="93" name="content"></textarea> +</form> +</div> + +</body> + +</html> diff --git a/settings.php b/settings.php new file mode 100644 index 0000000..014f48b --- /dev/null +++ b/settings.php @@ -0,0 +1,14 @@ +<?php +//Blog root directory RELATIVE TO SERVER ROOT +$blogRoot = "/"; +//$blogRoot = "/blog/"; + +//Posts directory RELATIVE TO FILESYSTEM ROOT +$blogPosts = "/var/www/posts/"; +//$blogPosts = "/var/www/blog/posts/"; + +//Page title +$blogTitle = "My Clog Blog"; +//Header title +$blogHead = $blogTitle; +?> diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..335fa40 --- /dev/null +++ b/styles.css @@ -0,0 +1,62 @@ +body { + font-family: sans-serif; + font-size: 12pt; + background-color: #FEFEFE; + margin: 0 auto; + width: 800px; +} + +a.title { + font-weight: bold; + font-size: 20pt; + margin: 0px 0px 14px; + text-decoration: none; + color: black; +} + +#perma { + font-size: 8pt; + font-weight: normal; +} + +a.toplink { + font-size: 14pt; + letter-spacing: -1px; + font-family: monospace; + float: bottom; + color: #000000; +} + +a.toplink:hover { + color: #808080; +} + +span.date { + margin: 0px 0px 14px; + font-size: 12px; + float: right; +} + +div { + clear: both; + text-align: justify; + border-style: solid; + border-color: #E0E0E0; + border-width: 5px; + border-radius: 5px; + width: 770px; + margin: 10px auto; + padding: 5px; +} + +#title { + position: relative; + background-color: #E0E0E0; + text-align: center; + width: 750px; + margin: 10px 0px 5px; + font-size: 32px; + padding: 25px; + border: 0px; + border-radius: 10px; +} @@ -0,0 +1,20 @@ +<?php + require("settings.php"); +?> +<!DOCTYPE html> +<html> + +<head> + <title><?php echo $blogTitle; ?></title> + <link rel="stylesheet" type="text/css" href="<?php echo $blogRoot; ?>styles.css" /> +</head> + +<body> + +<div id="title"> +<h1><?php echo $blogHead; ?></h1> +<a class="toplink" href="<?php echo $blogRoot; ?>">Home</a> +<a class="toplink" href="<?php echo $blogRoot; ?>archives.php">Archives</a> +<a class="toplink" href="<?php echo $blogRoot; ?>post.php">Post</a> +</div> + diff --git a/viewpost.php b/viewpost.php new file mode 100644 index 0000000..e4c6cab --- /dev/null +++ b/viewpost.php @@ -0,0 +1,26 @@ +<?php + if (!isset($_GET['post'])) { + header("location: $blogRoot"); + exit(0); + } + + require("top.php"); + + $file = $_GET['post']; + echo "<div>\n"; + echo "<a class=\"title\" href=\"{$blogRoot}post/" . urlencode($file) . "\">$file <span id=\"perma\">[Permalink]</span></a>\n"; + + $stat = stat("{$blogPosts}$file"); + $date = date('d-m-Y H:i T', $stat['mtime']); + echo "<span class=\"date\">$date</span>\n"; + echo "<br><br>\n"; + + $post = file_get_contents("{$blogPosts}$file"); + $post = preg_replace('/\n/', "<br>\n", $post); + echo $post; + echo "</div>\n</a>\n\n"; +?> + +</body> + +</html> |