aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README8
-rw-r--r--archives.php8
-rw-r--r--dopost.php1
-rw-r--r--functions.php14
-rw-r--r--htaccess.sample3
-rw-r--r--index.php9
-rw-r--r--nginx.sample4
-rw-r--r--post.php10
-rw-r--r--rss.php46
-rw-r--r--settings.sample7
-rw-r--r--styles.css16
-rw-r--r--title.php11
-rw-r--r--viewpost.php31
-rw-r--r--widget.php1
14 files changed, 129 insertions, 40 deletions
diff --git a/README b/README
index f2969fc..e9daa11 100644
--- a/README
+++ b/README
@@ -6,18 +6,16 @@ I wanted an exceptionally small piece of blogging software, where each post was
This is that piece of software.
-Installation (Apache):
+Installation (Common):
* Clone the repo
* Create a posts directory
* Move settings.sample to settings.php and configure it
* Create a .htpasswd file for posting users
+
+Installation (Apache):
* Create an Apache virtual host or .htaccess file based on htaccess.sample
* (Optional) delete .sample files
Instructions (nginx):
-* Clone the repo
-* Create a posts directory
-* Move settings.sample to settings.php and configure it
-* Create a .htpasswd file for posting users
* Create an nginx server based on nginx.sample
* (Optional) delete .sample files
diff --git a/archives.php b/archives.php
index 4a41f18..fbb76c7 100644
--- a/archives.php
+++ b/archives.php
@@ -1,5 +1,6 @@
<?php
require("settings.php");
+ require("functions.php");
?>
<!DOCTYPE html>
<html>
@@ -11,12 +12,7 @@
<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>
+<?php title(); ?>
<?php
$ls = explode("\n", `ls -1t {$blogPosts}/`);
diff --git a/dopost.php b/dopost.php
index f4f43e5..2ba4bbe 100644
--- a/dopost.php
+++ b/dopost.php
@@ -1,5 +1,6 @@
<?php
require("settings.php");
+ require("functions.php");
if (!isset($_POST['title']) || !isset($_POST['content'])) {
header("location: {$blogRoot}post.php");
diff --git a/functions.php b/functions.php
new file mode 100644
index 0000000..ec1ef28
--- /dev/null
+++ b/functions.php
@@ -0,0 +1,14 @@
+<?php
+
+function summarise($post) {
+ $post = preg_replace('/(\r?\n|\t)/', " ", $post);
+ $post = preg_replace('/"/', "&quot;", $post);
+ $post = preg_replace('/<.*?>/', " ", $post);
+ return substr($post, 0, 196) . "...";
+}
+
+function title() {
+ require("title.php");
+}
+
+?>
diff --git a/htaccess.sample b/htaccess.sample
index 043a3e5..42b34d4 100644
--- a/htaccess.sample
+++ b/htaccess.sample
@@ -1,12 +1,11 @@
RewriteEngine on
+RewriteRule ^feed$ /rss.php
RewriteRule ^post/(.*)$ /viewpost.php?post=$1
-#RewriteRule ^post/(.*)$ /blog/viewpost.php?post=$1
<Files "dopost.php">
AuthType Basic
AuthName "Secure"
AuthUserFile /var/www/.htpasswd
-# AuthUserFile /var/www/blog/.htpasswd
Require Valid-User
</Files>
diff --git a/index.php b/index.php
index 1eac730..a04cb39 100644
--- a/index.php
+++ b/index.php
@@ -1,5 +1,6 @@
<?php
require("settings.php");
+ require("functions.php");
?>
<!DOCTYPE html>
<html>
@@ -7,16 +8,12 @@
<head>
<title><?php echo $blogTitle; ?></title>
<link rel="stylesheet" type="text/css" href="<?php echo $blogRoot; ?>styles.css" />
+ <link href="feed" type="applictaion/atom+xml" rel=alternate" title="Atom Feed" />
</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>
+<?php title(); ?>
<?php
$start = 0;
diff --git a/nginx.sample b/nginx.sample
index ad5fa4f..f225b35 100644
--- a/nginx.sample
+++ b/nginx.sample
@@ -7,7 +7,9 @@ server {
root /var/www;
- rewrite \/post\/(.*)$ /viewpost.php?post=$1;
+ rewrite \/blog\/feed$ /blog/rss.php;
+ rewrite \/blog\/post\/(.*)$ /blog/viewpost.php?post=$1;
+
location /dopost.php {
auth_basic "Login to post";
auth_basic_user_file /var/www/.htpasswd;
diff --git a/post.php b/post.php
index 2ea452f..8636034 100644
--- a/post.php
+++ b/post.php
@@ -1,5 +1,6 @@
<?php
- require("settings.php");
+ require("settings.php");
+ require("functions.php");
?>
<!DOCTYPE html>
<html>
@@ -11,12 +12,7 @@
<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>
+<?php title(); ?>
<div>
<form method="post" action="<?php echo $blogRoot; ?>dopost.php">
diff --git a/rss.php b/rss.php
new file mode 100644
index 0000000..25fb3b8
--- /dev/null
+++ b/rss.php
@@ -0,0 +1,46 @@
+<?php
+ require("settings.php");
+ require("functions.php");
+ header("Content-Type: application/atom+xml");
+
+ echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n\n";
+ echo "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n";
+ echo "\t<title>$blogTitle</title>\n";
+ echo "\t<subtitle>$blogSubTitle</subtitle>\n";
+ echo "\t<link href=\"http://{$_SERVER['SERVER_NAME']}{$blogRoot}feed\" rel=\"self\"/>\n";
+ echo "\t<link href=\"http://{$_SERVER['SERVER_NAME']}{$blogRoot}\"/>\n";
+ echo "\t<id>tag:{$_SERVER['SERVER_NAME']}," . date("Y-m-d") . ":$blogRoot</id>\n";
+ echo "\t<updated>" . date(DATE_ATOM) . "</updated>\n\n";
+
+ $ls = explode("\n", `ls -1t {$blogPosts}/`);
+ foreach($ls as $file) {
+ if (preg_match('/^\./', $file)) continue;
+ if ($file === "") continue;
+
+ $plusfile = preg_replace('/ /', '+', $file);
+ $dashfile = preg_replace('/ /', '-', $file);
+ $stat = stat("{$blogPosts}$file");
+ $date = date(DATE_ATOM, $stat['mtime']);
+ $post = file_get_contents("{$blogPosts}$file");
+ $post = preg_replace('/\r?\n/', "<br>\n", $post);
+
+ echo "\t<entry>\n";
+ echo "\t\t<title>$file</title>\n";
+ echo "\t\t<link href=\"http://{$_SERVER['SERVER_NAME']}{$blogRoot}post/{$plusfile}\" />\n";
+ echo "\t\t<id>tag:{$_SERVER['SERVER_NAME']}," . date("Y-m-d") . ":{$blogRoot}{$dashfile}</id>\n";
+ echo "\t\t<updated>$date</updated>\n";
+ echo "\t\t<summary type=\"html\"><![CDATA[";
+ echo summarise($post);
+ echo "]]></summary>\n";
+ echo "\t\t<content type=\"html\"><![CDATA[";
+ echo $post;
+ echo "]]></content>\n";
+ echo "\t\t<author>\n";
+ echo "\t\t\t<name>$rssAuthorName</name>\n";
+ if (isset($rssAuthorEmail)) echo "\t\t\t<email>$rssAuthorEmail</email>\n";
+ echo "\t\t</author>\n";
+ echo "\t</entry>\n";
+ }
+
+ echo "</feed>";
+?>
diff --git a/settings.sample b/settings.sample
index 59f63b2..0a8abe6 100644
--- a/settings.sample
+++ b/settings.sample
@@ -7,9 +7,10 @@ $blogPosts = "/var/www/posts/";
//Page title
$blogTitle = "My Clog Blog";
-//Header title
-$blogHead = $blogTitle;
+$blogSubTitle = "It's awesome";
-//Twitter Creator
+//Author Information
$twitterCreator = "Example";
+$rssAuthorName = "A. N. Other";
+//$rssAuthorEmail = ""; //optional
?>
diff --git a/styles.css b/styles.css
index 3fa9294..194c7d0 100644
--- a/styles.css
+++ b/styles.css
@@ -32,6 +32,7 @@ a.toplink {
font-family: monospace;
float: bottom;
color: #000000;
+ padding: 0px 7px;
}
a.toplink:hover {
@@ -62,14 +63,27 @@ div {
padding: 5px;
}
+div>div {
+ width: 730px;
+ border: none;
+}
+
#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;
}
+
+#title>h1 {
+ font-size: 60px;
+}
+
+#title>h2 {
+ font-size: 20px;
+ font-family: monospace;
+}
diff --git a/title.php b/title.php
new file mode 100644
index 0000000..edee86b
--- /dev/null
+++ b/title.php
@@ -0,0 +1,11 @@
+<?php
+ require("settings.php");
+?>
+<div id="title">
+<h1><?php echo $blogTitle; ?></h1>
+<h2><?php echo $blogSubTitle; ?></h2>
+<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; ?>feed">Feed</a>
+<a class="toplink" href="<?php echo $blogRoot; ?>post.php">Post</a>
+</div>
diff --git a/viewpost.php b/viewpost.php
index aec9b00..8c70f64 100644
--- a/viewpost.php
+++ b/viewpost.php
@@ -1,9 +1,12 @@
<?php
require("settings.php");
+ require("functions.php");
+
if (!isset($_GET['post'])) {
header("location: $blogRoot");
exit(0);
}
+
$getpost = preg_replace('/\+/', ' ', $_GET['post']);
$post = file_get_contents("{$blogPosts}$getpost");
$post = preg_replace('/\n/', "<br>\n", $post);
@@ -19,24 +22,19 @@
<meta name="twitter:url" content="<?php echo "http://{$_SERVER['SERVER_NAME']}{$blogRoot}".$_GET['post']; ?>">
<meta name="twitter:creator" content="<?php echo $twitterCreator; ?>">
<meta name="twitter:title" content="<?php echo $getpost; ?>">
- <meta name="twitter:description" content="<?php echo preg_replace('/"/', '&quot;', substr($post, 0, 196)) . "..."; ?>">
+ <meta name="twitter:description" content="<?php echo summarise($post); ?>">
</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>
+<?php title(); ?>
<?php
- echo "<div>\n";
+ echo "<div>\n";
echo "<a class=\"title\" href=\"{$blogRoot}post/" . urlencode($getpost) . "\">$getpost <span id=\"perma\">[Permalink]</span></a> ";
?>
<a href="https://twitter.com/share" class="twitter-share-button" data-text="<?php echo "$blogTitle: {$getpost}"; ?>" data-url="http://<?php echo "{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}"; ?>">[Tweet]</a>
-<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
+<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<?php
$stat = stat("{$blogPosts}$getpost");
@@ -48,6 +46,21 @@
echo "</div>\n</a>\n\n";
?>
+<div id="disqus_thread">
+ <script type="text/javascript">
+ var disqus_shortname = 'user4574';
+
+ (function() {
+ var dsq = document.createElement('script');
+ dsq.type = 'text/javascript';
+ dsq.async = true;
+ dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
+ (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
+ })();
+ </script>
+ <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
+</div>
+
</body>
</html>
diff --git a/widget.php b/widget.php
index 89ec7c4..962cb3b 100644
--- a/widget.php
+++ b/widget.php
@@ -1,5 +1,6 @@
<?php
require("settings.php");
+ require("functions.php");
?>
<!DOCTYPE html>
<html>