3 # Copyright (c) 2008, 2009, Simon Morgan <sjm@spamcop.net>
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #import cgitb; cgitb.enable()
27 def displaypost(date
, title
, body
):
28 """Formats and prints a post"""
29 print '<div class="blogpost">'
30 print '<h1>%s</h1>' % title
31 print '<h3>%s</h3>' % date
32 print markdown2
.markdown(body
)
35 starttime
= time
.time()
37 form
= cgi
.FieldStorage()
39 print "Content-type: text/html; charset=UTF-8\n"
41 print '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
44 common
.printheaders(config
.TITLE
)
46 conn
= common
.connect()
48 numposts
= common
.getnumposts(conn
)
50 print '<p>Nothing here yet. How about you <a href="post.cgi">post</a> something interesting?</p>'
52 if form
.has_key("id"):
53 if common
.getnumposts(conn
, form
.getvalue("id")) > 0:
54 (date
, title
, text
) = conn
.execute("SELECT date, title, text FROM entries WHERE id = ?", (form
.getvalue("id"),)).fetchone()
55 displaypost(date
, title
, text
)
57 print "<p>No such post.</p>"
60 if form
.has_key("offset"):
61 offset
= int(form
.getvalue("offset"))
62 for row
in conn
.execute("SELECT * FROM entries ORDER BY date DESC LIMIT ? OFFSET ?", (config
.NUMPOSTS
, offset
)):
63 displaypost(row
[1], '<a href="index.cgi?id=%s">%s</a>' % (row
[0], row
[2]), row
[3])
64 print '<div id="navigation">'
66 newoffset
= offset
- config
.NUMPOSTS
69 print '<a href="index.cgi?offset=%s">Prev</a>' % newoffset
70 if offset
+ config
.NUMPOSTS
< numposts
:
71 newoffset
= offset
+ config
.NUMPOSTS
72 print '<a href="index.cgi?offset=%s">Next</a>' % newoffset
77 print '<!-- Page generated in %s seconds. -->' % (time
.time() - starttime
)