Code cleanup:
* Removed some regexp * Using String Formatting Operation to fill 1byte string with '0'
This commit is contained in:
parent
e2b597fc1b
commit
31b7b41d65
42
blogthon.cgi
42
blogthon.cgi
@ -125,8 +125,8 @@ if static_display: static_display = re.sub('/', '', static_display)
|
|||||||
|
|
||||||
post_display = action.getvalue('p')
|
post_display = action.getvalue('p')
|
||||||
if post_display:
|
if post_display:
|
||||||
post_display = re.sub(' ', '-', post_display)
|
post_display = post_display.replace(' ', '-') \
|
||||||
post_display = re.sub('/', '', post_display)
|
.replace('/', '')
|
||||||
|
|
||||||
allentries_display = action.getvalue('a')
|
allentries_display = action.getvalue('a')
|
||||||
feed_display = action.getvalue('feed')
|
feed_display = action.getvalue('feed')
|
||||||
@ -151,12 +151,12 @@ if not cquizv: cquizv = ""
|
|||||||
# Comment to commit?
|
# Comment to commit?
|
||||||
if cname and ctext and ctitle:
|
if cname and ctext and ctitle:
|
||||||
# Prevent XSS hacks
|
# Prevent XSS hacks
|
||||||
cname = cname.replace("<", "<") \
|
cname = cname.replace('<', '<') \
|
||||||
.replace(">", ">") \
|
.replace('>', '>') \
|
||||||
.replace("\"", """)
|
.replace('\'', '"')
|
||||||
ctext = ctext.replace("<", "<") \
|
ctext = ctext.replace('<', '<') \
|
||||||
.replace(">", ">") \
|
.replace('>', '>') \
|
||||||
.replace("\"", """)
|
.replace('\'', '"')
|
||||||
|
|
||||||
# Add comment
|
# Add comment
|
||||||
if not cquiz == cquizv:
|
if not cquiz == cquizv:
|
||||||
@ -169,7 +169,6 @@ if cname and ctext and ctitle:
|
|||||||
content.close()
|
content.close()
|
||||||
except:
|
except:
|
||||||
errorpage(entries_dir, 'isn\'t writable!')
|
errorpage(entries_dir, 'isn\'t writable!')
|
||||||
comments_file = glob.glob(entries_dir + ctitle + '.comments')
|
|
||||||
try:
|
try:
|
||||||
content = open(comments_file[0], "a+")
|
content = open(comments_file[0], "a+")
|
||||||
content.write("-." + cname + "\n")
|
content.write("-." + cname + "\n")
|
||||||
@ -209,17 +208,12 @@ if feed_display == "atom":
|
|||||||
blog_title_md5sum = generate_uuid(blog_title)
|
blog_title_md5sum = generate_uuid(blog_title)
|
||||||
title_md5sum = generate_uuid(title)
|
title_md5sum = generate_uuid(title)
|
||||||
|
|
||||||
# Atom needs a 2byte string
|
# Append 0 to the beginning if len of integer is 1 (value<10)
|
||||||
month = str(date[1])
|
month = '%(#)02d' % {'#': int(date[1])}
|
||||||
day = str(date[2])
|
day = '%(#)02d' % {'#': int(date[2])}
|
||||||
hour = str(date[3])
|
hour = '%(#)02d' % {'#':int(date[3])}
|
||||||
min = str(date[4])
|
min = '%(#)02d' % {'#': int(date[4])}
|
||||||
sec = str(date[5])
|
sec = '%(#)02d' % {'#': int(date[5])}
|
||||||
if len(str(date[1])) == 1: month = '0' + str(date[1])
|
|
||||||
if len(str(date[2])) == 1: day = '0' + str(date[2])
|
|
||||||
if len(str(date[3])) == 1: hour = '0' + str(date[3])
|
|
||||||
if len(str(date[4])) == 1: min = '0' + str(date[4])
|
|
||||||
if len(str(date[5])) == 1: sec = '0' + str(date[5])
|
|
||||||
|
|
||||||
document_header("atom")
|
document_header("atom")
|
||||||
print '<link href="' + blog_url + '/?feed=atom" rel="self" type="application/atom+xml"/>'
|
print '<link href="' + blog_url + '/?feed=atom" rel="self" type="application/atom+xml"/>'
|
||||||
@ -260,11 +254,11 @@ elif feed_display == "rss":
|
|||||||
print ' </item>'
|
print ' </item>'
|
||||||
print ' </channel>'
|
print ' </channel>'
|
||||||
print '</rss>'
|
print '</rss>'
|
||||||
|
print date
|
||||||
|
|
||||||
# Generate regular page
|
# Generate regular page
|
||||||
else:
|
else:
|
||||||
document_header("xhtml-strict")
|
document_header("xhtml-strict")
|
||||||
# XHTML Header
|
|
||||||
print ' <head>'
|
print ' <head>'
|
||||||
print ' <title>' + blog_title + '</title>'
|
print ' <title>' + blog_title + '</title>'
|
||||||
print ' <meta http-equiv="content-type" content="text/html; charset=utf-8" />'
|
print ' <meta http-equiv="content-type" content="text/html; charset=utf-8" />'
|
||||||
@ -403,7 +397,7 @@ else:
|
|||||||
title = title.replace('.' + entries_suffix, '')
|
title = title.replace('.' + entries_suffix, '')
|
||||||
|
|
||||||
if month_display == date_to_compare or not month_display:
|
if month_display == date_to_compare or not month_display:
|
||||||
if post_display == re.sub(' ', '-', title) or not post_display:
|
if post_display == post_display.replace(' ', '-') or not post_display:
|
||||||
if allentries_display == "1" or entry_counter < entries_per_page:
|
if allentries_display == "1" or entry_counter < entries_per_page:
|
||||||
content = open(entry, "r")
|
content = open(entry, "r")
|
||||||
print ' <div class="entry">'
|
print ' <div class="entry">'
|
||||||
@ -492,7 +486,7 @@ else:
|
|||||||
comments_file = glob.glob(entries_dir + title + '.comments')
|
comments_file = glob.glob(entries_dir + title + '.comments')
|
||||||
if not comments_file and not post_display:
|
if not comments_file and not post_display:
|
||||||
print ' <div class="entry_comment">'
|
print ' <div class="entry_comment">'
|
||||||
print ' <a href="?p=' + re.sub(' ','-', title) + '" class="entry_comment">no comments</a>'
|
print ' <a href="?p=' + title.replace(' ','-') + '" class="entry_comment">no comments</a>'
|
||||||
print ' </div>'
|
print ' </div>'
|
||||||
print ' </div>'
|
print ' </div>'
|
||||||
print ''
|
print ''
|
||||||
@ -502,7 +496,7 @@ else:
|
|||||||
for line in comments_content:
|
for line in comments_content:
|
||||||
if line.split(".", 1)[0] == "-": comments_counter += 1
|
if line.split(".", 1)[0] == "-": comments_counter += 1
|
||||||
print ' <div class="entry_comment">'
|
print ' <div class="entry_comment">'
|
||||||
print ' <a href="?p=' + re.sub(' ', '-', title) + '" class="entry_comment">comments (' + str(comments_counter) + ')</a>'
|
print ' <a href="?p=' + title.replace(' ', '-') + '" class="entry_comment">comments (' + str(comments_counter) + ')</a>'
|
||||||
print ' </div>'
|
print ' </div>'
|
||||||
print ' </div>'
|
print ' </div>'
|
||||||
print ''
|
print ''
|
||||||
|
Loading…
Reference in New Issue
Block a user