/[theodore]/bunnyblog/index.cgi


UCC Code Repository

Contents of /bunnyblog/index.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 13 - (show annotations) (download)
Fri Feb 1 02:19:08 2008 UTC (12 years, 8 months ago) by theodore
File size: 5008 byte(s)
Updates regarding creating a new CMS Page with an existing CMS Page filename.
Its bad, and not allowed anymore.


1 #!/usr/bin/python
2 import cgi
3 import cgitb; cgitb.enable()
4 import blog
5
6 """
7 Here we set up all the variables for generating the page
8 """
9 main = ""
10 title = "<@[email protected]> - "
11 header = ""
12
13 """
14 Here we retrieve the blog and any arguments
15 Defaults are assigned here
16 """
17 form = cgi.FieldStorage()
18 myblog = blog.Blog(True)
19 numarticles = len(myblog.articles)
20 perpage = 10
21 pagenum = 1
22 httpstatuscode = "200"
23
24
25 def listarticles(pagenum = 0, perpage = 10):
26 main = ""
27 start = numarticles - pagenum * perpage - 1
28 finish = start - perpage
29 if finish < 1:
30 articles = myblog.articles[start::-1]
31 else:
32 articles = myblog.articles[start:finish:-1]
33 for article in articles:
34 main += article.htmlize()
35 return main
36
37 def linkto(page,text="",classname=""):
38 if text == "prev":
39 page = page-1
40 text = "&lt;"*3 + " Prev"
41 classname = "class = 'prev'"
42 elif text == "next":
43 page = page+1
44 text = "Next " + 3*"&gt;"
45 classname = "class = 'next'"
46 elif text != "":
47 text = text
48 else:
49 text = str(page)
50 link = " <a href='index.cgi?pagenum=%d&amp;perpage=%d' %s>%s</a> " % (page,perpage,classname,text)
51 return link
52
53 def generatetoc(currentpage = 1):
54 toc = "<div class='toc'>"
55 if currentpage > 1:
56 toc += linkto(currentpage,"prev")
57 toc += "Page:"
58 for i in range(1,pages + 1):
59 if i == currentpage:
60 toc += "<a> %d </a>" % i
61 else:
62 toc += linkto(i)
63
64 if currentpage <= numarticles // perpage:
65 toc += linkto(currentpage,"next")
66 toc += "</div>"
67 return toc
68
69 if form.has_key('pagenum'):
70 if form.has_key('perpage'):
71 try:
72 perpage = int(form['perpage'].value)
73 except:
74 perpage = 10
75 if perpage < 1 or perpage > 100:
76 perpage = 10
77 pages = (numarticles + 1) // perpage
78 try:
79 pagenum = int(form['pagenum'].value)
80 except:
81 pagenum = 1
82 if pagenum < 1 or pagenum > pages:
83 pagenum = 1
84 toc = numarticles > perpage and generatetoc(pagenum) or ""
85 main += toc + "<hr />" + listarticles(pagenum-1, perpage) + "<hr />" + toc
86 header += "Archives - Page %d" % pagenum
87 title += header
88 elif form.has_key('action') and form.has_key('index'):
89 action = form['action'].value
90 articleindex = int(form['index'].value)
91 article = myblog.findbyindex(articleindex)
92 if article:
93 comment = form['comment'].value
94 author = form['author'].value
95 if action == 'addcomment' and comment and author:
96 if form.has_key('comment') and form.has_key('author'):
97 if action == 'addcomment' and comment and author:
98 article.addcomment(author,comment)
99 myblog.saveblog()
100 main += "Successfully saved"
101 main += article.htmlize()
102 main += article.showcomments()
103 else:
104 main += blog.error('invalid comment or author')
105 else:
106 main += blog.error('nosuchindex: ' + str(articleindex))
107 elif form.has_key('article'):
108 try:
109 index = int(form['article'].value)
110 article = myblog.findbyindex(index)
111 if article:
112 main += article.htmlize()
113 main += article.showcomments()
114 title = article.title
115 else:
116 main += blog.error('indexoutrange')
117 except:
118 main += blog.error('indexoutrange')
119 elif form.has_key('title'):
120 articletitle = form['title'].value
121 article = myblog.findbytitle(articletitle)
122 if article:
123 main += article.htmlize()
124 main += article.showcomments()
125 header = article.title
126 title += header
127 else:
128 main += blog.error('nosuchtitle: ' + articletitle)
129 elif form.has_key('page'):
130 pagetodisplay = form['page'].value
131 if pagetodisplay == 'home':
132 pages = (numarticles +1) // 5
133 (cmspage,header) = blog.getcmspage("home")
134 main += cmspage + "<br /><hr />"
135 title = "Welcome to <@[email protected]>"
136 if len(myblog.articles):
137 main += "<h2>Latest Rant:</h2>" + myblog.articles[-1].htmlize() + "For more reading material, please continue to the " + linkto(1,"Archives")
138 elif pagetodisplay == 'archive':
139 perpage = 10
140 pages = (numarticles + 1) // perpage
141 pagenum = 1
142 if numarticles > perpage:
143 toc = generatetoc(pagenum)
144 main += toc + "<hr />" + listarticles(pagenum-1, perpage) + "<hr />" + toc
145 header += "Archives - Page %d" % pagenum
146 else:
147 main += listarticles(pagenum-1, perpage)
148 header += "Archives - Page %d" % pagenum
149 title += header
150 else:
151 (cmspage,header) = blog.getcmspage(pagetodisplay)
152 if cmspage.find("404") != -1:
153 myblog.httpcode = "404"
154 main += cmspage
155 if blog.admin :
156 main += "<br />This page doesn't appear to exist. <a href='admin.cgi?page=newcontent'>Click here to create a new page</a>"
157 title = "<@[email protected]> - %s" % header
158 else:
159 pages = (numarticles + 1) // 5
160 (cmspage,header) = blog.getcmspage("home")
161 main += cmspage
162 if len(myblog.articles):
163 main += "<h2>Latest Rant:</h2>" + myblog.articles[-1].htmlize() + "For more reading material, please continue to the " + linkto(1,"Archives")
164 else:
165 main += "Login to the <a href='admin.cgi'>admin page</a> to begin your new blog"
166 title = "Welcome to <@[email protected]>"
167
168
169 sidebar = blog.gettemplate("shoutbox",'data')
170 if blog.isadmin():
171 sidebar += "<hr />" + blog.gettemplate("admin/toolbar")
172 myblog.display(title,header,main, sidebar)

Properties

Name Value
svn:executable

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26