Skip to content

Commit 50c2091

Browse files
author
Paul Nicholas Bersch
committed
Added new files from recent changes
1 parent f1b27a7 commit 50c2091

22 files changed

+3362
-0
lines changed

blog_class.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import post_class, comment_class
2+
import re, os, cherrypy
3+
4+
class Blog(object):
5+
def __init__(self, author = "Anonymous", url = "http://127.0.0.1"):
6+
self.posts = []
7+
self.author = author
8+
self.url = url
9+
self.getPosts()
10+
11+
def getPosts(self):
12+
self.posts = []
13+
expression = re.compile('\d*')
14+
for file in os.listdir(os.getcwd() + '/posts/'):
15+
if expression.match(file) != None:
16+
currentPost = post_class.Post()
17+
filehandle = open('posts/' + file, 'r')
18+
currentPost = post_class.Post(file, (filehandle.readline())[0:-1], filehandle.read())
19+
filehandle.close()
20+
currentPost.markupbody()
21+
self.posts.append(currentPost)
22+
23+
def index(self):
24+
page = []
25+
header = open('theme/header.php', 'r')
26+
page.append(header.read())
27+
header.close()
28+
29+
for post in self.posts:
30+
page.append(post.createPost())
31+
32+
footer = open('theme/footer.php', 'r')
33+
page.append(footer.read())
34+
footer.close()
35+
page = '\n\n'.join(page)
36+
return page
37+
index.exposed = True
38+
39+
def post(self, id):
40+
header = open('theme/header.php', 'r')
41+
yield header.read()
42+
header.close()
43+
44+
for post in self.posts:
45+
if post.date == id:
46+
yield post.createPost(True)
47+
break
48+
49+
footer = open('theme/footer.php', 'r')
50+
yield footer.read()
51+
footer.close()
52+
post.exposed = True
53+
54+
def ajaxedit(self, id, width, height):
55+
for post in self.posts:
56+
if post.date == id:
57+
return post.createEditor(width, height)
58+
ajaxedit.exposed = True
59+
60+
@cherrypy.tools.staticdir(root=os.getcwd(), dir='files')
61+
def files(self):
62+
yield '<h2>Browsing directory /files</h2>\n'
63+
for dirpath, dirnames, filenames in os.walk(os.getcwd()+'/files'):
64+
filenames.sort()
65+
for filename in filenames:
66+
yield '<a href="/files/%s">%s</a>\n' % (filename, filename)
67+
files.exposed = True
68+
69+
def edit(self, post_title, post_body, post_date):
70+
for post in self.posts:
71+
if post.date == post_date:
72+
post.editPost(post_title, post_body)
73+
return 'Updated.'
74+
edit.exposed = True
75+
76+
def ajaxget(self, id):
77+
for post in self.posts:
78+
if post.date == id:
79+
return post.createPost(False)
80+
ajaxget.exposed = True

blog_class.pyc

3.58 KB
Binary file not shown.

comment_class.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import post_class
2+
from datetime import datetime
3+
4+
class Comment(post_class.Post):
5+
def __init__(self, date = datetime.today(), title = "", body = "", commenterName = "Anonymous"):
6+
super(Comment, self).__init__(date, title, body)
7+
self.commenterName = commenterName

comment_class.pyc

748 Bytes
Binary file not shown.

files

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/paul/images/photos/20080720/MSP_road_trip/

files-real/photos

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/paul/images/photos/

files-real/ponies.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<title>Page about ponies.</title>
4+
</head>
5+
<body>
6+
Herrow wrld.
7+
</body>
8+
</html>

old_php/ajaxedit.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
require_once('postfunctions.php');
4+
$postID = $_POST["id"];
5+
$width = $_POST["width"];
6+
$width = $width - 10;
7+
$height = $_POST["height"];
8+
9+
$postTitle = getPostSubject($postID);
10+
$rawText = getRawPost($postID);
11+
12+
$filledTextarea = '<input type="text" name="input_title" id="input_title" value="'.$postTitle.'"> <br />'.'<textarea id="input_body" style = "width:'.$width.'px; height:'.$height.'px;">'.$rawText.'</textarea>'.
13+
' <br /> <form action="edit.php" method="post" name="postForm" id="postForm"> <input type="hidden" name="post_title" id="post_title">'.
14+
' <input type="hidden" name="post_body" id="post_body">'.
15+
' <input type="hidden" name="post_date" id="post_date" value="'.$postID.'">'.
16+
' <input type="button" value="Submit Post" onclick="fill_form_and_escape('.$postID.')">'.
17+
' <input type="button" value = "Cancel" onclick = "cancelEditing()"> </form>';
18+
19+
echo $filledTextarea;
20+
21+
?>
22+

old_php/ajaxget.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
require_once('postfunctions.php');
4+
$postID = $_POST["id"];
5+
6+
$postTitle = getPostSubject($postID);
7+
$rawText = getMarkupPost($postID);
8+
9+
$filledPost =
10+
'<h2 id = "' . $postID . '_title" class="thesubject">' .
11+
$postTitle . '</h2>' .
12+
$rawText;
13+
14+
echo $filledPost;
15+
16+
?>
17+

old_php/ajaxnewpost.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<input type="text" name="input_title" id="input_title">
2+
<br />
3+
<textarea name="input_body" rows="10" cols="80" id="input_body"></textarea>
4+
<br />
5+
<form action="submit.php" method="post" name="postForm">
6+
<input type="hidden" name="input_title" id="post_title">
7+
<input type="hidden" name="input_body" id="post_body">
8+
<input type="button" value="Submit Post" onclick="
9+
function() {
10+
var postID = <?php echo date(YmdHis); ?>;
11+
$('.hidden').attr('id', postid);
12+
fill_form_and_escape(postID);
13+
setClickable();
14+
};">
15+
<input type="button" value="Cancel" onclick="$('.hidden').remove(); cancelEditing();">
16+
</form>

old_php/edit.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
require_once('postfunctions.php');
4+
$title = urldecode($_POST["post_title"]);
5+
$body = urldecode($_POST["post_body"]);
6+
$postedtime = $_POST["post_date"];
7+
8+
$out = fopen('posts/'.$postedtime, "w");
9+
if (!$out)
10+
{
11+
echo false;
12+
exit;
13+
}
14+
fwrite($out, $title."\n");
15+
fwrite($out, "\n".$body."\n");
16+
fclose($out);
17+
createIndexFile();
18+
//echo "header('Location: index.html');";
19+
//echo '<script type="text/javascript"> cancelEditing(); </script>';
20+
echo 'Post Saved';
21+
?>

old_php/index.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
$indexpage = null;
4+
5+
require_once('./postfunctions.php');
6+
7+
createIndexFile();
8+
9+
header('Location: index.html');
10+
?>

old_php/newpost.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4+
5+
<head>
6+
<title>New Post Maker</title>
7+
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
8+
<meta name="generator" content="Geany 0.10.2" />
9+
<script type="text/javascript" src="js/jquery-1.2.1.js"></script>
10+
<script type="text/javascript" src="js/functions.js"></script>
11+
</head>
12+
13+
<body>
14+
15+
<input type="text" name="input_title" id="input_title">
16+
<br />
17+
<textarea name="input_body" rows="10" cols="80" id="input_body"></textarea>
18+
<br />
19+
<form action="submit.php" method="post" name="postForm">
20+
<input type="hidden" name="input_title" id="post_title">
21+
<input type="hidden" name="input_body" id="post_body">
22+
<input type="button" value="Submit Post" onclick="fill_form_and_escape('<?php echo date(YmdHis); ?>'); setTimeout('location.href=\'newpost.php\'',1250);">
23+
</form>
24+
25+
</body>
26+
</html>

old_php/postfunctions.php

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
3+
function getPostFilenames() {
4+
5+
if ($handle = opendir('posts/')) {
6+
while (false !== ($file = readdir($handle))) {
7+
//run through each file in the directory
8+
if (substr($file, 0, 1) != '.') { //don't include hidden files
9+
//create an array of filenames
10+
$filearray[] = trim($file);
11+
}
12+
}
13+
closedir($handle);
14+
if (count($filearray) < 1) {
15+
return false;
16+
}
17+
natcasesort($filearray); //sort filenames
18+
return $filearray;
19+
}
20+
}
21+
22+
function getRawPost($postid) {
23+
$fh = fopen('posts/'.$postid, 'r');
24+
fgets($fh);
25+
fgets($fh);
26+
$rawtext = fread($fh, filesize('posts/'.$postid));
27+
return $rawtext;
28+
}
29+
30+
function getMarkupPost($postid) {
31+
require_once('./textile/classTextile.php');
32+
$fh = fopen('posts/'.$postid, 'r');
33+
fgets($fh);
34+
fgets($fh);
35+
$post = fread($fh, filesize('posts/'.$postid));
36+
//cause the body of the post to be textile-ified
37+
$textile = new Textile();
38+
$post = $textile->TextileThis($post);
39+
//make the date (more) human-readable
40+
$prettydate = substr($postid,4,2).'/'.substr($postid,6,2).'/'.substr($postid,0,4).' at '.
41+
substr($postid,-6,2).':'.substr($postid,-4,2).':'.substr($postid,-2);
42+
$posts = "\n".'<h3 class="time">'.$prettydate.'</h3>'."\n".'<div id="'.$postid.'_body" class="thebody">'.
43+
"\n".$post."\n".'</div>'."\n".'</div>'."\n";
44+
fclose($fh);
45+
return $posts;
46+
}
47+
48+
49+
function getPostSubject($postid) {
50+
$fh = fopen('posts/'.$postid, 'r');
51+
$title = fgets($fh);
52+
$title = substr($title, 0, -1);
53+
fclose($fh);
54+
return $title;
55+
}
56+
57+
58+
function markupPosts() {
59+
60+
$filearray = getPostFilenames();
61+
if (!($filearray)) { return '<div id="content"><h3>Nothing to see here.</h3></div>'; }
62+
foreach ($filearray as $file){
63+
//add markup to posts and put them together with the newest post on top
64+
$posts= getMarkupPost($file) . $posts;
65+
$posts = '<div class="post" id="'.$file.'">'."\n".'<h2 id = "'.$file.'_title" class="thesubject">'. getPostSubject($file) .'</h2>'.$posts;
66+
}
67+
$posts = '<span class="createnew"> + </span>'.$posts;
68+
$posts = '<div id="content">'."\n".$posts;
69+
$posts.="\n".'</div>';
70+
return $posts;
71+
}
72+
73+
function createIndexFile() {
74+
75+
$indexpage = getHeader();
76+
$indexpage .= markupPosts();
77+
$indexpage .= getFooter();
78+
79+
$out = fopen('index.html', "w");
80+
if (!$out)
81+
{
82+
print("OMG");
83+
exit;
84+
}
85+
fwrite($out, $indexpage);
86+
fclose($out);
87+
}
88+
89+
function getHeader() {
90+
$fh = fopen('./theme/'.'header.php', 'r');
91+
$headertext = fread($fh, filesize('./theme/'.'header.php'));
92+
return $headertext;
93+
}
94+
95+
function getFooter() {
96+
$fh = fopen('./theme/'.'footer.php', 'r');
97+
$footertext = fread($fh, filesize('./theme/'.'footer.php'));
98+
return $footertext;
99+
}
100+
101+
function markupRSS() {
102+
103+
require_once('./textile/classTextile.php');
104+
105+
$filearray = getPostFilenames();
106+
107+
foreach ($filearray as $file){
108+
//add markup to posts and put them together with the newest post on top
109+
$fh = fopen('posts/'.$file, 'r');
110+
$title = fgets($fh);
111+
$title = substr($title, 0, -1);
112+
$post = fread($fh, filesize('posts/'.$file));
113+
$post = substr($post, 1);
114+
115+
//cause the body of the post to be textile-ified
116+
$textile = new Textile();
117+
$post = $textile->TextileThis($post);
118+
119+
//make the date (more) human-readable
120+
$prettydate = substr($file,4,2).'/'.substr($file,6,2).'/'.substr($file,0,4).' at '.
121+
substr($file,-6,2).':'.substr($file,-4,2).':'.substr($file,-2);
122+
123+
$posts = "\n".'<description>'."\n".$post."\n".'</div>'."\n".'</div>'."\n".$posts;
124+
$posts = '<item><title>'."\n".$prettydate.' - '.$title.'</title>'.'<link>http://paulbersch.com/</link>'.$posts;
125+
}
126+
$posts = '<?xml version="1.0" ?>'."\n"."<rss version=\"2.0\">"."\n"."<channel>"."\n".
127+
"<title>Blog Title Goes Here</title>"."\n"."<link>http://paulbersch.com</link>"."\n"."<description>I describe this feed very well.</description>".$posts;
128+
$posts.="\n".'</rss>';
129+
return $posts;
130+
}
131+
132+
133+
134+
?>

old_php/settings.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
$title = "overcomplicated.org"
3+
$subtitle = "the temporary home of paul bersch"
4+
5+
$author_name = "paul bersch"
6+
$max_posts = 100
7+
?>

0 commit comments

Comments
 (0)