2009-06-01 03:36:30 +02:00
|
|
|
#!/usr/bin/python
|
2009-11-01 15:41:17 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2009-06-01 03:36:30 +02:00
|
|
|
|
2009-07-29 20:17:16 +02:00
|
|
|
# This program is free software. It comes without any warranty, to
|
2009-02-28 18:02:23 +01:00
|
|
|
# the extent permitted by applicable law. You can redistribute it
|
|
|
|
# and/or modify it under the terms of the Do What The Fuck You Want
|
|
|
|
# To Public License, Version 2, as published by Sam Hocevar. See
|
|
|
|
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
|
|
|
|
2009-05-17 23:19:07 +02:00
|
|
|
# Authors: Stefan Ritter <xeno@thehappy.de>
|
|
|
|
# Adrian Vondendriesch <disco-stu@disco-stu.de>
|
2009-12-03 22:19:56 +01:00
|
|
|
# Pascal Turbing <pascal@turbing.de>
|
2010-12-14 09:42:38 +01:00
|
|
|
#
|
2009-03-01 13:55:09 +01:00
|
|
|
# Description: A simple blogging software
|
|
|
|
|
2010-02-17 11:16:00 +01:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import locale
|
|
|
|
import re
|
2010-11-20 20:01:08 +01:00
|
|
|
from ConfigParser import ConfigParser
|
|
|
|
from cgi import FieldStorage
|
2010-11-16 08:45:21 +01:00
|
|
|
from smtplib import SMTP
|
|
|
|
from md5 import new as newmd5
|
|
|
|
from glob import glob
|
|
|
|
from random import randint
|
2009-02-28 18:02:23 +01:00
|
|
|
|
2009-12-06 21:50:12 +01:00
|
|
|
# A wonderful place for doing some regexp ;)
|
2010-12-14 09:42:38 +01:00
|
|
|
no_break = re.compile("^\s*(<ul|</ul>|<li|</li>|<ol|</ol>|<table|</table>|<tr|</tr>|<td|</td>|<th|</th>|<p|</p>).*$")
|
|
|
|
line_start_hyphen = re.compile("^-.*$")
|
|
|
|
line_start_plus = re.compile("^\+.*$")
|
2009-12-06 21:50:12 +01:00
|
|
|
|
2010-11-15 17:50:11 +01:00
|
|
|
tab = "\t"
|
|
|
|
|
2009-03-28 14:30:02 +01:00
|
|
|
def generate_uuid(string):
|
2010-11-16 08:45:21 +01:00
|
|
|
string_md5sum = newmd5(string).hexdigest()
|
2010-12-14 09:42:38 +01:00
|
|
|
string = str.join("-", (string_md5sum[0:8], string_md5sum[8:12], string_md5sum[12:16], string_md5sum[16:20], string_md5sum[20:32]))
|
2009-03-28 14:30:02 +01:00
|
|
|
return string
|
|
|
|
|
2009-04-10 12:05:01 +02:00
|
|
|
def errorpage(string):
|
2010-12-14 09:42:38 +01:00
|
|
|
document_header("xhtml-strict")
|
|
|
|
print "<head><title>Error!</title></head>"
|
|
|
|
print "<body>"
|
2010-11-15 17:50:11 +01:00
|
|
|
print tab + string
|
2010-12-14 09:42:38 +01:00
|
|
|
print "</body>"
|
|
|
|
print "</html>"
|
2009-04-10 12:05:01 +02:00
|
|
|
sys.exit()
|
2009-03-28 14:30:02 +01:00
|
|
|
|
2009-04-30 10:26:56 +02:00
|
|
|
def document_header(string):
|
|
|
|
if string == "xhtml-transitional":
|
2010-12-14 09:42:38 +01:00
|
|
|
print "Content-type: text/html\n"
|
|
|
|
print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\""
|
|
|
|
print " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
|
|
|
|
print "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">"
|
2009-04-30 10:26:56 +02:00
|
|
|
if string == "xhtml-strict":
|
2010-12-14 09:42:38 +01:00
|
|
|
print "Content-type: text/html\n"
|
|
|
|
print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""
|
|
|
|
print " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
|
|
|
|
print "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">"
|
2009-04-30 10:26:56 +02:00
|
|
|
if string == "atom":
|
2010-12-14 09:42:38 +01:00
|
|
|
print "Content-type: application/atom+xml\n"
|
|
|
|
print "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
|
|
|
print "<feed xmlns=\"http://www.w3.org/2005/Atom\">"
|
2009-06-05 10:56:00 +02:00
|
|
|
if string == "rss":
|
2010-12-14 09:42:38 +01:00
|
|
|
print "Content-type: application/rss+xml\n"
|
|
|
|
print "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
|
|
|
print "<rss version=\"2.0\">"
|
|
|
|
|
2009-04-30 10:26:56 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
# Parse configuration
|
2010-11-16 08:45:21 +01:00
|
|
|
configuration = ConfigParser()
|
2009-12-06 17:03:28 +01:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
for config in ["../blogthonrc", "../.blogthonrc", "configuration"]:
|
|
|
|
if os.path.exists(config):
|
|
|
|
configuration.read(config)
|
|
|
|
config = True
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
config = False
|
|
|
|
|
|
|
|
if not config:
|
|
|
|
errorpage("No suitable configuration found!")
|
2009-02-28 18:02:23 +01:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: blog_title = configuration.get("personal", "blog_title")
|
|
|
|
except: errorpage("\"blog_title\" is missing in configuration!")
|
2009-05-22 10:18:04 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: blog_subtitle = configuration.get("personal", "blog_subtitle")
|
|
|
|
except: errorpage("\"blog_subtitle\" is missing in configuration!")
|
2009-05-22 10:18:04 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: blog_url = configuration.get("personal", "blog_url")
|
|
|
|
except: errorpage("\"blog_url\" is missing in configuration!")
|
2009-05-22 10:18:04 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: keywords = configuration.get("personal", "keywords")
|
|
|
|
except: errorpage("\"keywords\" is missing in configuration!")
|
2009-05-22 10:18:04 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: entries_dir = configuration.get("personal", "entries_dir")
|
|
|
|
except: errorpage("\"entries_dir\" is missing in configuration!")
|
2009-05-22 10:18:04 +02:00
|
|
|
if not os.path.exists(entries_dir):
|
2010-12-14 09:42:38 +01:00
|
|
|
errorpage("\"entries_dir\" does not exist!")
|
2009-05-22 10:18:04 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: entries_suffix = configuration.get("personal", "entries_suffix")
|
|
|
|
except: errorpage("\"entries_suffix\" is missing in configuration!")
|
2009-05-22 10:18:04 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: staticpages_dir = configuration.get("personal", "staticpages_dir")
|
|
|
|
except: errorpage("\"staticpages_dir\" is missing in configuration!")
|
2009-05-22 10:18:04 +02:00
|
|
|
if not os.path.exists(staticpages_dir):
|
2010-12-14 09:42:38 +01:00
|
|
|
errorpage("\"staticpages_dir\" does not exist!")
|
2009-05-22 10:18:04 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: plugins_dir = configuration.get("personal", "plugins_dir")
|
|
|
|
except: errorpage("\"plugins_dir\" is missing in configuration!")
|
2009-12-07 00:32:35 +01:00
|
|
|
if not os.path.exists(plugins_dir):
|
2010-12-14 09:42:38 +01:00
|
|
|
errorpage("\"plugins_dir\" does not exist!")
|
2009-12-07 00:32:35 +01:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: style = configuration.get("look", "style")
|
|
|
|
except: errorpage("\"style\" is missing in configuration!")
|
2009-05-22 10:18:04 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: language = configuration.get("look", "language")
|
|
|
|
except: errorpage("\"language\" is missing in configuration!")
|
2010-02-17 11:16:00 +01:00
|
|
|
if language == "de":
|
|
|
|
blog_locale = ("Seiten", "Monate", "Links", "Keine Kommentare", "Kommentare", "Alle Einträge anzeigen...", "Name", "Text", "Absenden")
|
|
|
|
locales_de = ("de_DE.UTF-8", "de_DE.@euro", "de_DE")
|
|
|
|
for i in locales_de:
|
|
|
|
try:
|
|
|
|
locale.setlocale(locale.LC_TIME, i)
|
|
|
|
break
|
|
|
|
except: continue
|
|
|
|
else: locale.setlocale(locale.LC_TIME, None)
|
|
|
|
|
2010-02-17 09:26:59 +01:00
|
|
|
else:
|
2010-02-17 11:16:00 +01:00
|
|
|
blog_locale = ("pages", "months", "links", "no comments", "comments", "View all entries...", "name", "text", "commit")
|
|
|
|
locales_en = ("en_US.UTF-8", "en_US.ISO-8859-15", "en_US")
|
|
|
|
for i in locales_en:
|
|
|
|
try:
|
|
|
|
locale.setlocale(locale.LC_TIME, i)
|
|
|
|
break
|
|
|
|
except: continue
|
|
|
|
else: locale.setlocale(locale.LC_TIME, None)
|
2010-02-17 09:26:59 +01:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: entries_per_page = configuration.getint("look", "entries_per_page")
|
|
|
|
except: errorpage("\"entries_per_page\" is missing in configuration!")
|
2009-05-22 10:18:04 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: monthlist = configuration.get("look", "monthlist")
|
|
|
|
except: errorpage("\"monthlist\" is missing in configuration!")
|
2009-05-22 10:18:04 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: staticpages = configuration.get("look", "staticpages")
|
|
|
|
except: errorpage("\"staticpages\" is missing in configuration!")
|
2009-05-22 10:18:04 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: linklist = configuration.get("look", "linklist")
|
|
|
|
except: errorpage("\"linklist\" is missing in configuration!")
|
2009-05-22 10:18:04 +02:00
|
|
|
if not os.path.exists("linklist"):
|
2010-12-14 09:42:38 +01:00
|
|
|
errorpage("\"linklist\" does not exist!")
|
2009-05-22 10:18:04 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: permalinks = configuration.get("look", "permalinks")
|
|
|
|
except: errorpage("\"permalinks\" is missing in configuration!")
|
2009-05-22 10:18:04 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: comments = configuration.get("look", "comments")
|
|
|
|
except: errorpage("\"comments\" is missing in configuration!")
|
2009-05-22 10:18:04 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: newest_first = configuration.get("look", "newest_first")
|
|
|
|
except: errorpage("\"newest_first\" is missing in configuration!")
|
2009-02-28 18:02:23 +01:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: new_comment_mail = configuration.get("smtp", "new_comment_mail")
|
|
|
|
except: errorpage("\"new_comment_mail\" is missing in configuration!")
|
2009-07-24 11:53:09 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: mail_to = configuration.get("smtp", "mail_to")
|
|
|
|
except: errorpage("\"mail_to\" is missing in configuration!")
|
2009-07-24 11:53:09 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: smtp_host = configuration.get("smtp", "smtp_host")
|
|
|
|
except: errorpage("\"smtp_host\" is missing in configuration!")
|
2009-07-24 11:53:09 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
try: feed_preview = configuration.get("feed", "feed_preview")
|
|
|
|
except: errorpage("\"feed_preview\" is missing or empty in configuration!")
|
2009-12-03 22:19:56 +01:00
|
|
|
|
2009-03-28 14:30:02 +01:00
|
|
|
# Read POST Variables
|
2010-11-20 20:01:08 +01:00
|
|
|
action = FieldStorage()
|
2010-12-14 09:42:38 +01:00
|
|
|
month_display = action.getvalue("m")
|
2009-07-21 17:27:23 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
static_display = action.getvalue("s")
|
|
|
|
if static_display: static_display = static_display.replace("/", "")
|
2009-07-21 17:27:23 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
post_display = action.getvalue("p")
|
|
|
|
if post_display: post_display = post_display.replace(" ", "-").replace("/", "")
|
2009-07-21 17:27:23 +02:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
allentries_display = action.getvalue("a")
|
|
|
|
feed_display = action.getvalue("feed")
|
2009-02-28 18:02:23 +01:00
|
|
|
if not month_display: month_display = ""
|
|
|
|
if not post_display: post_display = ""
|
|
|
|
if not static_display: static_display = ""
|
2009-03-02 01:50:14 +01:00
|
|
|
if not allentries_display: allentries_display = ""
|
2009-03-24 20:37:21 +01:00
|
|
|
if not feed_display: feed_display = ""
|
2009-02-28 18:02:23 +01:00
|
|
|
|
2009-03-08 19:17:59 +01:00
|
|
|
# Commentstuff
|
2010-12-14 09:42:38 +01:00
|
|
|
ctitle = action.getvalue("ctitle")
|
|
|
|
cname = action.getvalue("cname")
|
|
|
|
ctext = action.getvalue("ctext")
|
|
|
|
cquiz = action.getvalue("cquiz")
|
|
|
|
cquizv = action.getvalue("cquizv")
|
2009-03-08 19:17:59 +01:00
|
|
|
if not ctitle: ctitle = ""
|
|
|
|
if not cname: cname = ""
|
|
|
|
if not ctext: ctext = ""
|
2009-04-30 01:25:14 +02:00
|
|
|
if not cquiz: cquiz = ""
|
|
|
|
if not cquizv: cquizv = ""
|
2009-03-08 19:17:59 +01:00
|
|
|
|
|
|
|
# Comment to commit?
|
|
|
|
if cname and ctext and ctitle:
|
|
|
|
# Prevent XSS hacks
|
2010-12-14 09:42:38 +01:00
|
|
|
cname = cname.replace("<", "<").replace(">", ">").replace("\'", """)
|
|
|
|
ctext = ctext.replace("<", "<").replace(">", ">").replace("\'", """)
|
2009-11-16 08:00:41 +01:00
|
|
|
|
2009-03-08 19:17:59 +01:00
|
|
|
# Add comment
|
2009-04-30 01:25:14 +02:00
|
|
|
if not cquiz == cquizv:
|
|
|
|
errorpage("Brainmode")
|
|
|
|
else:
|
2010-12-14 09:42:38 +01:00
|
|
|
comments_file = os.path.join(entries_dir, ctitle + ".comments")
|
|
|
|
if not os.path.exists(comments_file):
|
2009-06-01 03:45:21 +02:00
|
|
|
try:
|
2010-12-14 09:42:38 +01:00
|
|
|
content = open(comments_file, "w")
|
2009-06-01 03:45:21 +02:00
|
|
|
content.close()
|
|
|
|
except:
|
2010-12-14 09:42:38 +01:00
|
|
|
errorpage("\"" + entries_dir + "\" isn\'t writable!")
|
|
|
|
|
2009-07-24 16:21:56 +02:00
|
|
|
try:
|
2010-12-14 09:42:38 +01:00
|
|
|
content = open(comments_file, "a")
|
2009-07-24 16:21:56 +02:00
|
|
|
content.write("-." + cname + "\n")
|
2010-02-17 11:16:00 +01:00
|
|
|
content.write("+." + time.strftime("%c", time.localtime()) + "\n")
|
2009-07-24 16:21:56 +02:00
|
|
|
ctext = ctext.split("\n")
|
|
|
|
for line in ctext:
|
|
|
|
content.write("." + line + "\n")
|
|
|
|
content.close()
|
2010-12-14 09:42:38 +01:00
|
|
|
|
2009-07-24 16:21:56 +02:00
|
|
|
# Send mail?
|
2010-12-14 09:42:38 +01:00
|
|
|
if not new_comment_mail == "False":
|
|
|
|
msg = "From: Blogthon\nTo: " + mail_to + "\nSubject: New comment on " + blog_title + "\n\nSomeone wrote a comment to this entry: " + blog_url + "?p=" + ctitle.replace(" ", "-")
|
2010-11-16 08:45:21 +01:00
|
|
|
smtp = SMTP(smtp_host)
|
2010-12-14 09:42:38 +01:00
|
|
|
smtp.starttls()
|
2009-07-24 16:21:56 +02:00
|
|
|
smtp.sendmail(blog_title, mail_to, msg)
|
|
|
|
smtp.quit()
|
|
|
|
except:
|
2010-12-14 09:42:38 +01:00
|
|
|
errorpage("Comment cannot be written!")
|
2009-03-08 19:17:59 +01:00
|
|
|
|
2009-03-24 20:37:21 +01:00
|
|
|
# Read entries and store their title and timestamp
|
2009-02-28 18:02:23 +01:00
|
|
|
entries = []
|
2010-12-14 09:42:38 +01:00
|
|
|
entries_list = glob(entries_dir + "*." + entries_suffix)
|
2009-02-28 18:02:23 +01:00
|
|
|
|
|
|
|
for entry in entries_list:
|
2010-12-14 09:42:38 +01:00
|
|
|
title = entry.replace(entries_dir, "", 1)
|
|
|
|
title = title.replace("." + entries_suffix, "")
|
2010-12-09 09:27:01 +01:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
stampfile = os.path.join(entries_dir, title + ".stamp")
|
2010-12-09 09:27:01 +01:00
|
|
|
if os.path.exists(stampfile):
|
|
|
|
timestamp = os.stat(stampfile)
|
|
|
|
else:
|
|
|
|
timestamp = os.stat(entry)
|
2010-12-14 09:42:38 +01:00
|
|
|
stampfile = os.path.join(entries_dir, title + ".stamp")
|
|
|
|
stamp = open(stampfile, "w")
|
2010-12-09 11:14:45 +01:00
|
|
|
stamp.close()
|
|
|
|
utime = os.utime(stampfile, (os.stat(entry)[8], os.stat(entry)[8]))
|
2010-12-09 09:27:01 +01:00
|
|
|
|
2009-02-28 18:02:23 +01:00
|
|
|
timestamp = time.localtime(timestamp[8])
|
|
|
|
entry = timestamp, entry
|
|
|
|
entries.append(entry)
|
|
|
|
|
|
|
|
if newest_first:
|
|
|
|
entries.sort(reverse=True)
|
|
|
|
else:
|
|
|
|
entries.sort()
|
|
|
|
|
2009-03-24 20:37:21 +01:00
|
|
|
# Generate atom feed
|
|
|
|
if feed_display == "atom":
|
|
|
|
date = entries[0][0]
|
2009-03-28 14:30:02 +01:00
|
|
|
blog_title_md5sum = generate_uuid(blog_title)
|
2009-03-24 20:37:21 +01:00
|
|
|
|
2009-12-02 12:19:30 +01:00
|
|
|
# Append 0 to the beginning if len of integer is 1 (value<10)
|
2010-12-14 09:42:38 +01:00
|
|
|
month = "%(#)02d" % {"#": int(date[1])}
|
|
|
|
day = "%(#)02d" % {"#": int(date[2])}
|
|
|
|
hour = "%(#)02d" % {"#":int(date[3])}
|
|
|
|
min = "%(#)02d" % {"#": int(date[4])}
|
|
|
|
sec = "%(#)02d" % {"#": int(date[5])}
|
2009-04-30 13:40:39 +02:00
|
|
|
|
2009-11-16 08:00:41 +01:00
|
|
|
document_header("atom")
|
2010-12-14 09:42:38 +01:00
|
|
|
print "<link href=\"" + blog_url + "/?feed=atom\" rel=\"self\" type=\"application/atom+xml\"/>"
|
|
|
|
print tab + "<author>"
|
|
|
|
print tab*2 + "<name>" + blog_title + "</name>"
|
|
|
|
print tab + "</author>"
|
|
|
|
print tab + "<title>" + blog_title + "</title>"
|
|
|
|
print tab + "<id>urn:uuid:" + blog_title_md5sum + "</id>"
|
|
|
|
print tab + "<updated>" + str(date[0]) + "-" + month + "-" + day + "T" + hour + ":" + min + ":" + sec + "Z</updated>"
|
|
|
|
print ""
|
2009-12-03 22:19:56 +01:00
|
|
|
j = len(entries)
|
|
|
|
if j > 10: j = 10
|
|
|
|
for i in xrange(0, j):
|
2010-12-14 09:42:38 +01:00
|
|
|
title = str(entries[i][1]).replace(entries_dir, "", 1).replace("." + entries_suffix, "")
|
2009-12-03 22:53:37 +01:00
|
|
|
date = entries[i][0]
|
2009-12-03 22:19:56 +01:00
|
|
|
title_md5sum = generate_uuid(title)
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*2 + "<entry>"
|
|
|
|
print tab*3 + "<title>" + title + "</title>"
|
|
|
|
print tab*3 + "<link href=\"" + blog_url + "?p=" + title + "\"/>"
|
|
|
|
print tab*3 + "<id>urn:uuid:" + title_md5sum + "</id>"
|
|
|
|
print tab*3 + "<updated>" + str(date[0]) + "-" + month + "-" + day + "T" + hour + ":" + min + ":" + sec + "Z</updated>"
|
|
|
|
print tab*3 + "<summary>"
|
|
|
|
content = open(str(entries[i][1]), "r")
|
2009-12-03 22:19:56 +01:00
|
|
|
for h in xrange(0, int(feed_preview)):
|
|
|
|
rss_line = content.readline().strip()
|
2010-12-14 09:42:38 +01:00
|
|
|
if rss_line != "":
|
|
|
|
print tab*4 + rss_line
|
2009-12-03 22:19:56 +01:00
|
|
|
content.close()
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*3 + "</summary>"
|
|
|
|
print tab*2 + "</entry>"
|
|
|
|
print "</feed>"
|
2009-03-24 20:37:21 +01:00
|
|
|
|
2009-06-05 10:56:00 +02:00
|
|
|
# Generate rss 2.0 feed
|
2009-06-05 20:36:39 +02:00
|
|
|
elif feed_display == "rss":
|
2009-06-05 10:56:00 +02:00
|
|
|
document_header("rss")
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab + "<channel>"
|
|
|
|
print tab*2 + "<title>" + blog_title + "</title>"
|
|
|
|
print tab*2 + "<link>" + blog_url + "</link>"
|
|
|
|
print tab*2 + "<description>" + blog_subtitle + "</description>"
|
2009-12-03 14:48:20 +01:00
|
|
|
date = time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime(time.mktime(entries[0][0])))
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*2 + "<pubDate>" + date + "</pubDate>"
|
|
|
|
print ""
|
2009-12-03 14:48:20 +01:00
|
|
|
j = len(entries)
|
|
|
|
if j > 10: j = 10
|
2009-12-03 14:53:21 +01:00
|
|
|
for i in xrange(0, j):
|
2010-12-14 09:42:38 +01:00
|
|
|
title = str(entries[i][1]).replace(entries_dir, "", 1).replace("." + entries_suffix, "")
|
2009-12-03 14:48:20 +01:00
|
|
|
date = time.strftime("%a, %d %b %Y %H:%M:%S %z", time.gmtime(time.mktime(entries[i][0])))
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*2 + "<item>"
|
|
|
|
print tab*3 + "<title>" + title + "</title>"
|
|
|
|
print tab*3 + "<link>" + blog_url + "?p=" + title + "</link>"
|
|
|
|
print tab*3 + "<guid>" + blog_url + "?p=" + title + "</guid>"
|
|
|
|
print tab*3 + "<pubDate>" + date + "</pubDate>"
|
|
|
|
content = open(str(entries[i][1]), "r")
|
|
|
|
rss_description= ""
|
2009-12-03 22:19:56 +01:00
|
|
|
for h in xrange(0, int(feed_preview)):
|
2009-12-04 00:29:05 +01:00
|
|
|
line = content.readline().strip()
|
|
|
|
if line:
|
2010-12-14 09:42:38 +01:00
|
|
|
rss_description = rss_description + line + "<br />"
|
2009-12-03 22:19:56 +01:00
|
|
|
content.close()
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*3 + "<description><![CDATA[" + rss_description + "]]></description>"
|
|
|
|
print tab*2 + "</item>"
|
|
|
|
print tab + "</channel>"
|
|
|
|
print "</rss>"
|
2009-06-05 10:56:00 +02:00
|
|
|
|
2009-03-24 20:37:21 +01:00
|
|
|
# Generate regular page
|
|
|
|
else:
|
2009-07-29 20:17:16 +02:00
|
|
|
document_header("xhtml-strict")
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab + "<head>"
|
|
|
|
print tab*2 + "<title>" + blog_title + "</title>"
|
|
|
|
print tab*2 + "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />"
|
|
|
|
print tab*2 + "<meta name=\"keywords\" content=\"" + keywords + "\" />"
|
|
|
|
print tab*2 + "<meta name=\"description\" content=\"" + blog_title + "\" />"
|
|
|
|
print tab*2 + "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles/" + style + "/" + style + ".css\" />"
|
|
|
|
print tab + "</head>"
|
|
|
|
print tab + "<body>"
|
|
|
|
print ""
|
2009-12-07 00:32:35 +01:00
|
|
|
|
|
|
|
# Plugins
|
|
|
|
sys.path.append(plugins_dir)
|
2010-12-14 09:42:38 +01:00
|
|
|
for plugin in glob(plugins_dir + "*.py"):
|
|
|
|
__import__ (plugin.split("/")[1].replace(".py", ""))
|
2009-12-07 00:32:35 +01:00
|
|
|
|
2009-05-17 23:19:07 +02:00
|
|
|
# Site header
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*2 + "<div class=\"header\">"
|
|
|
|
print tab*3 + "<div class=\"header_title\">"
|
|
|
|
print tab*4 + "<a href=\"?\" class=\"header_link\">" + blog_title + "</a>"
|
|
|
|
print tab*3 + "</div>"
|
|
|
|
print tab*3 + "<div class=\"header_subtitle\">"
|
|
|
|
print tab*4 + "<span class=\"header_subtitle\">" + blog_subtitle + "</span>"
|
|
|
|
print tab*3 + "</div>"
|
|
|
|
print tab*2 + "</div>"
|
|
|
|
print ""
|
2009-12-07 00:32:35 +01:00
|
|
|
|
2009-05-17 23:19:07 +02:00
|
|
|
# RSS feed
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*2 + "<div class=\"rss\">"
|
|
|
|
print tab*3 + "<a href=\"?feed=rss\" class=\"rss_link\">rss</a>"
|
|
|
|
print tab*2 + "</div>"
|
|
|
|
print ""
|
2009-12-07 00:32:35 +01:00
|
|
|
|
2009-05-17 23:19:07 +02:00
|
|
|
# Atom feed
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*2 + "<div class=\"atom\">"
|
|
|
|
print tab*3 + "<a href=\"?feed=atom\" class=\"atom_link\">atom</a>"
|
|
|
|
print tab*2 + "</div>"
|
|
|
|
print ""
|
2009-03-24 20:37:21 +01:00
|
|
|
|
2009-05-17 23:19:07 +02:00
|
|
|
# Staticpages
|
2009-03-24 20:37:21 +01:00
|
|
|
if staticpages == "True":
|
|
|
|
staticpages = []
|
2010-12-14 09:42:38 +01:00
|
|
|
staticpages_list = glob(staticpages_dir + "*")
|
2009-03-24 20:37:21 +01:00
|
|
|
staticpages_list.sort()
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*2 + "<div class=\"pages\">"
|
|
|
|
print tab*3 + "<div class=\"pages_title\">" + blog_locale[0] + "</div>"
|
|
|
|
print tab*3 + "<div class=\"pages_list\">"
|
|
|
|
print tab*4 + "<ul class=\"pages_list\">"
|
2009-03-24 20:37:21 +01:00
|
|
|
for staticpage in staticpages_list:
|
2010-12-14 09:42:38 +01:00
|
|
|
file = open(staticpage, "r")
|
2009-10-30 15:18:58 +01:00
|
|
|
header = file.readline()
|
2010-12-14 09:42:38 +01:00
|
|
|
if header.split(":", 1)[0] == "extern_link":
|
|
|
|
link = header.split(":", 1)[1].strip()
|
2009-10-30 15:00:06 +01:00
|
|
|
else:
|
2010-12-14 09:42:38 +01:00
|
|
|
link = re.sub("\w+?\/", "", staticpage)
|
|
|
|
link = "?s=" + link
|
2009-10-30 15:18:58 +01:00
|
|
|
file.close()
|
2010-12-14 09:42:38 +01:00
|
|
|
title = re.sub("\w+?\/\d+?-", "", staticpage)
|
|
|
|
print tab*5 + "<li class=\"pages_list_entry\"><a href=\"" + link + "\" class=\"pages_list_entry\">" + title + "</a></li>"
|
|
|
|
print tab*4 + "</ul>"
|
|
|
|
print tab*3 + "</div>"
|
|
|
|
print tab*3 + "<div class=\"pages_footer\"></div>"
|
|
|
|
print tab*2 + "</div>"
|
|
|
|
print ""
|
2009-03-24 20:37:21 +01:00
|
|
|
|
2009-05-17 23:19:07 +02:00
|
|
|
# Monthlist
|
2009-03-24 20:37:21 +01:00
|
|
|
if monthlist == "True":
|
|
|
|
olddate = ""
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*2 + "<div class=\"months\">"
|
|
|
|
print tab*3 + "<div class=\"months_title\">" + blog_locale[1] + "</div>"
|
|
|
|
print tab*3 + "<div class=\"months_list\">"
|
|
|
|
print tab*4 + "<ul class=\"months_list\">"
|
2009-03-24 20:37:21 +01:00
|
|
|
for entry in entries:
|
2009-12-10 15:19:31 +01:00
|
|
|
date = time.strftime("%m%Y", entry[0])
|
2009-03-24 20:37:21 +01:00
|
|
|
date_display = time.strftime("%h %Y", entry[0])
|
|
|
|
if not olddate == date:
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*5 + "<li class=\"months_list_entry\"><a href=\"?m=" + date + "\" class=\"months_list_entry\">" + date_display + "</a></li>"
|
2009-03-24 20:37:21 +01:00
|
|
|
olddate = date
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*4 + "</ul>"
|
|
|
|
print tab*3 + "</div>"
|
|
|
|
print tab*3 + "<div class=\"months_footer\"></div>"
|
|
|
|
print tab*2 + "</div>"
|
|
|
|
print ""
|
2009-03-24 20:37:21 +01:00
|
|
|
|
2009-05-17 23:19:07 +02:00
|
|
|
# Linklist
|
2009-03-24 20:37:21 +01:00
|
|
|
if linklist == "True":
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*2 + "<div class=\"linklist\">"
|
|
|
|
print tab*3 + "<div class=\"linklist_title\">" + blog_locale[2] + "</div>"
|
|
|
|
print tab*3 + "<div class=\"linklist_list\">"
|
|
|
|
print tab*4 + "<ul class=\"linklist_list\">"
|
2009-05-14 10:23:42 +02:00
|
|
|
try:
|
|
|
|
content = open("linklist", "r")
|
|
|
|
for line in content:
|
|
|
|
if line.strip() is "":
|
2010-12-14 09:42:38 +01:00
|
|
|
print "<br />"
|
2009-05-14 10:23:42 +02:00
|
|
|
else:
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*5 + "<li class=\"linklist_list_entry\"><a href=\"" + line.split(" ")[0] + "\" class=\"months_list_entry\">" + line.split(" ", 1)[1].strip() + "</a></li>"
|
2009-05-14 10:23:42 +02:00
|
|
|
content.close()
|
|
|
|
except:
|
2010-12-14 09:42:38 +01:00
|
|
|
print ""
|
|
|
|
print tab*4 + "</ul>"
|
|
|
|
print tab*3 + "</div>"
|
|
|
|
print tab*3 + "<div class=\"linklist_footer\"></div>"
|
|
|
|
print tab*2 + "</div>"
|
|
|
|
print ""
|
2009-03-24 20:37:21 +01:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*2 + "<div class=\"entries\">"
|
|
|
|
print ""
|
2009-12-10 15:19:31 +01:00
|
|
|
|
2009-05-18 17:27:03 +02:00
|
|
|
# Staticpage
|
|
|
|
if static_display != "":
|
2009-03-24 20:37:21 +01:00
|
|
|
content = open(staticpages_dir + static_display, "r")
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*3 + "<div class=\"entry\">"
|
|
|
|
print tab*4 + "<div class=\"entry_title\">" + re.sub("^\.", "", re.sub("\d+?-", "", static_display)) + "</div>"
|
|
|
|
print tab*4 + "<div class=\"entry_content\">"
|
|
|
|
print tab*5 + "<p>"
|
2009-03-24 20:37:21 +01:00
|
|
|
for line in content:
|
2009-12-10 15:19:31 +01:00
|
|
|
if no_break.match(line):
|
2010-11-16 08:33:29 +01:00
|
|
|
print tab*5 + line.strip()
|
2009-09-30 10:18:07 +02:00
|
|
|
else:
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*5 + line.strip() + "<br />"
|
|
|
|
print tab*5 + "</p>"
|
|
|
|
print tab*4 + "</div>"
|
|
|
|
print tab*4 + "<div class=\"entry_footer\"></div>"
|
|
|
|
print tab*4 + "<div class=\"entry_border_left\"></div>"
|
|
|
|
print tab*4 + "<div class=\"entry_border_right\"></div>"
|
|
|
|
print tab*4 + "<div class=\"entry_border_top\"></div>"
|
|
|
|
print tab*4 + "<div class=\"entry_border_bottom\"></div>"
|
|
|
|
print tab*3 + "</div>"
|
|
|
|
print ""
|
2009-03-24 20:37:21 +01:00
|
|
|
content.close()
|
2009-12-10 15:19:31 +01:00
|
|
|
|
2009-05-18 17:27:03 +02:00
|
|
|
# Entry
|
|
|
|
else:
|
2009-03-24 20:37:21 +01:00
|
|
|
entry_counter = 0
|
|
|
|
for entry in entries:
|
|
|
|
date = time.strftime("%c", entry[0])
|
|
|
|
date_to_compare = time.strftime("%m%Y", entry[0]) # Needed for permalinks
|
|
|
|
entry = entry[1]
|
2010-12-14 09:42:38 +01:00
|
|
|
title = entry.replace(entries_dir, "", 1)
|
|
|
|
title = title.replace("." + entries_suffix, "")
|
2009-03-24 20:37:21 +01:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
stampfile = os.path.join(entries_dir, title + ".stamp")
|
2010-12-09 11:14:45 +01:00
|
|
|
if os.path.exists(stampfile):
|
2010-12-09 09:27:01 +01:00
|
|
|
date = time.localtime(os.stat(stampfile)[8])
|
|
|
|
date = time.strftime("%c", date)
|
|
|
|
|
2009-03-24 20:37:21 +01:00
|
|
|
if month_display == date_to_compare or not month_display:
|
2010-12-14 09:42:38 +01:00
|
|
|
if post_display == title.replace(" ", "-") or not post_display:
|
2009-03-24 20:37:21 +01:00
|
|
|
if allentries_display == "1" or entry_counter < entries_per_page:
|
|
|
|
content = open(entry, "r")
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*3 + "<div class=\"entry\">"
|
2009-04-30 01:25:14 +02:00
|
|
|
if permalinks:
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*4 + "<div class=\"entry_title\"><a href=\"?p=" + title.replace(" ", "-") + "\" class=\"entry_title\">" + title + "</a></div>"
|
2009-04-30 01:25:14 +02:00
|
|
|
else:
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*4 + "<div class=\"entry_title\">" + title + "</div>"
|
|
|
|
print tab*4 + "<div class=\"entry_date\">" + date + "</div>"
|
|
|
|
print tab*4 + "<div class=\"entry_content\">"
|
2009-03-24 20:37:21 +01:00
|
|
|
for line in content:
|
2009-12-10 15:19:31 +01:00
|
|
|
if no_break.match(line):
|
2010-11-16 08:33:29 +01:00
|
|
|
print tab*5 + line.strip()
|
2009-09-27 17:19:22 +02:00
|
|
|
else:
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*5 + line.strip() + "<br />"
|
|
|
|
print tab*4 + "</div>"
|
|
|
|
print tab*4 + "<div class=\"entry_footer\"></div>"
|
|
|
|
print tab*4 + "<div class=\"entry_border_left\"></div>"
|
|
|
|
print tab*4 + "<div class=\"entry_border_right\"></div>"
|
|
|
|
print tab*4 + "<div class=\"entry_border_top\"></div>"
|
|
|
|
print tab*4 + "<div class=\"entry_border_bottom\"></div>"
|
2009-05-18 17:27:03 +02:00
|
|
|
|
|
|
|
# Comments...
|
|
|
|
# ... are shown when post_display and comments_file isn't false
|
2010-12-14 09:42:38 +01:00
|
|
|
comments_file = glob(entries_dir + title + ".comments")
|
2009-03-24 20:37:21 +01:00
|
|
|
if post_display:
|
|
|
|
if comments_file:
|
2010-12-14 09:42:38 +01:00
|
|
|
comments_file = glob(entries_dir + title + ".comments")
|
2009-03-24 20:37:21 +01:00
|
|
|
comments_content = open(comments_file[0], "r")
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*3 + "</div>"
|
|
|
|
print tab*2 + "</div>"
|
|
|
|
print ""
|
|
|
|
print tab*2 + "<div class=\"comments\">"
|
2009-07-10 00:50:26 +02:00
|
|
|
|
|
|
|
notfirstline = 0 # Ugly fix for closing comment containers
|
2009-11-02 14:14:21 +01:00
|
|
|
label_count = 0
|
2009-07-10 00:50:26 +02:00
|
|
|
|
2009-03-24 20:37:21 +01:00
|
|
|
for line in comments_content:
|
2009-12-10 15:19:31 +01:00
|
|
|
if line_start_hyphen.match(line):
|
2009-07-10 00:50:26 +02:00
|
|
|
if notfirstline == 1:
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*4 + "</div>"
|
|
|
|
print tab*3 + "</div>"
|
|
|
|
notfirstline = 0
|
|
|
|
print tab*3 + "<div class=\"comment\">"
|
2009-11-02 14:14:21 +01:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
# Label for each comment
|
2009-11-02 14:14:21 +01:00
|
|
|
label_count += 1
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*4 + "<a name=\"" + str(label_count) + "\"></a>"
|
2009-11-02 14:14:21 +01:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*4 + "<div class=\"comment_author\">" + line.split(".", 1)[1].strip() + "</div>"
|
2009-12-10 15:19:31 +01:00
|
|
|
elif line_start_plus.match(line):
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*4 + "<div class=\"comment_date\">" + line.split(".", 1)[1].strip() + "</div>"
|
|
|
|
print tab*4 + "<div class=\"comment_content\">"
|
2009-03-24 20:37:21 +01:00
|
|
|
else:
|
2010-12-14 09:42:38 +01:00
|
|
|
notfirstline = 1
|
2009-03-24 20:37:21 +01:00
|
|
|
line = line.split(".", 1)[1]
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*5 + line.strip() + "<br />"
|
|
|
|
print ""
|
|
|
|
print tab*4 + "</div>"
|
|
|
|
print tab*3 + "</div>"
|
2009-03-24 20:37:21 +01:00
|
|
|
comments_content.close()
|
2009-05-18 21:46:32 +02:00
|
|
|
else:
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*3 + "</div>"
|
|
|
|
print tab*2 + "</div>"
|
|
|
|
print tab*2 + "<div class=\"comments\">"
|
2009-03-24 20:37:21 +01:00
|
|
|
|
|
|
|
# Form for adding comments
|
2009-10-31 00:33:19 +01:00
|
|
|
if comments == "True":
|
2010-11-16 08:45:21 +01:00
|
|
|
random_int_a = randint(1,9)
|
|
|
|
random_int_b = randint(1,9)
|
2009-10-31 00:33:19 +01:00
|
|
|
cquizv = random_int_a + random_int_b
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*3 + "<div class=\"submit_comment\">"
|
|
|
|
print tab*4 + "<form action=\"\" method=\"post\">"
|
|
|
|
print tab*5 + "<input type=\"hidden\" name=\"ctitle\" value=\"" + title + "\" />"
|
|
|
|
print tab*5 + "<input type=\"hidden\" name=\"cquizv\" value=\"" + str(cquizv) + "\" />"
|
|
|
|
print tab*5 + "<label class=\"submit_comment_name\">" + blog_locale[6] + ":</label><input class=\"submit_comment_name_input\" type=\"text\" id=\"cname\" name=\"cname\" />"
|
|
|
|
print tab*5 + "<br /><label class=\"submit_comment_text\">" + blog_locale[7] + ":</label><textarea class=\"submit_comment_textarea\" id=\"ctext\" name=\"ctext\"></textarea>"
|
|
|
|
print tab*5 + "<br /><label class=\"submit_comment_quiz\">" + str(random_int_a) + "+" + str(random_int_b) + "=</label><input class=\"submit_comment_quiz_input\" type=\"text\" id=\"cquiz\" name=\"cquiz\" />"
|
|
|
|
print tab*5 + "<br /><input class=\"submit_comment_button\" type=\"submit\" id=\"submit\" value=\"" + blog_locale[8] + "\" />"
|
|
|
|
print tab*4 + "</form>"
|
|
|
|
print tab*3 + "</div>"
|
2009-10-31 00:33:19 +01:00
|
|
|
else:
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*3 + "<div class=\"submit_border_bottom\"></div>"
|
|
|
|
print ""
|
2009-03-24 20:37:21 +01:00
|
|
|
|
|
|
|
if comments == "True":
|
2010-12-14 09:42:38 +01:00
|
|
|
comments_file = glob(entries_dir + title + ".comments")
|
2009-03-24 20:37:21 +01:00
|
|
|
if not comments_file and not post_display:
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*4 + "<div class=\"entry_comment\">"
|
|
|
|
print tab*5 + "<a href=\"?p=" + title.replace(" " ,"-") + "\" class=\"entry_comment\">" + blog_locale[3] + "</a>"
|
|
|
|
print tab*4 + "</div>"
|
|
|
|
print tab*3 + "</div>"
|
|
|
|
print ""
|
2009-03-24 20:37:21 +01:00
|
|
|
elif comments_file and not post_display:
|
|
|
|
comments_content = open(comments_file[0], "r")
|
|
|
|
comments_counter = 0
|
|
|
|
for line in comments_content:
|
|
|
|
if line.split(".", 1)[0] == "-": comments_counter += 1
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*4 + "<div class=\"entry_comment\">"
|
|
|
|
print tab*5 + "<a href=\"?p=" + title.replace(" ", "-") + "\" class=\"entry_comment\">" + blog_locale[4] + " (" + str(comments_counter) + ")</a>"
|
|
|
|
print tab*4 + "</div>"
|
|
|
|
print tab*3 + "</div>"
|
|
|
|
print ""
|
2009-03-24 20:37:21 +01:00
|
|
|
comments_content.close()
|
2009-09-22 13:15:26 +02:00
|
|
|
else:
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*3 + "</div>"
|
|
|
|
print ""
|
2009-05-18 17:27:03 +02:00
|
|
|
|
2009-03-24 20:37:21 +01:00
|
|
|
content.close()
|
|
|
|
entry_counter += 1
|
|
|
|
|
2009-06-01 03:31:08 +02:00
|
|
|
if not month_display and not post_display and not allentries_display and entry_counter == entries_per_page: # Display pagelist
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*3 + "<div class=\"entry\"><a href=\"?a=1\">" + blog_locale[5] + "</a></div>"
|
2009-03-24 20:37:21 +01:00
|
|
|
|
2010-12-14 09:42:38 +01:00
|
|
|
print tab*2 + "</div>"
|
|
|
|
print ""
|
|
|
|
print tab + "</body>"
|
|
|
|
print "</html>"
|
2009-02-28 18:02:23 +01:00
|
|
|
|
|
|
|
# vim: set tw=0 ts=4:
|