summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGunnar Wrobel <wrobel@gentoo.org>2005-09-04 15:21:26 +0000
committerGunnar Wrobel <wrobel@gentoo.org>2005-09-04 15:21:26 +0000
commit9348b6945817b1755b5e2fb9f571e4ecc09c5b21 (patch)
tree327438a9819a45cfe2bf4e978ca25d4af72170ae /www-apps/pyblosxom-plugins/files
parentFixed digests (diff)
downloadoverlay-9348b6945817b1755b5e2fb9f571e4ecc09c5b21.tar.gz
overlay-9348b6945817b1755b5e2fb9f571e4ecc09c5b21.tar.bz2
overlay-9348b6945817b1755b5e2fb9f571e4ecc09c5b21.zip
Fixed comments plugin
svn path=/; revision=353
Diffstat (limited to 'www-apps/pyblosxom-plugins/files')
-rw-r--r--www-apps/pyblosxom-plugins/files/comments.py137
1 files changed, 100 insertions, 37 deletions
diff --git a/www-apps/pyblosxom-plugins/files/comments.py b/www-apps/pyblosxom-plugins/files/comments.py
index f843ef9..43e0cef 100644
--- a/www-apps/pyblosxom-plugins/files/comments.py
+++ b/www-apps/pyblosxom-plugins/files/comments.py
@@ -3,18 +3,19 @@ This module contains an extension to Blosxom file entries to support
comments.
Contributors:
-Ted Leung
-Will Guaraldi
-Wari Wahab
-Robert Wall
-Bill Mill
-Roberto De Almeida
+ Ted Leung
+ Will Guaraldi
+ Wari Wahab
+ Robert Wall
+ Bill Mill
+ Roberto De Almeida
+ David Geller
If you make any changes to this plugin, please a send a patch with your
changes to twl+pyblosxom@sauria.com so that we can incorporate your changes.
Thanks!
-This plugin requires the pyXML module.
+This plugin requires the PyXML module.
This module supports the following config parameters (they are not
required):
@@ -33,9 +34,6 @@ required):
If you omit this, the from address will be the
e-mail address as input in the comment form
comment_smtp_to - the person to send comment notifications to.
- comment_rejected_words - the list of words that will cause automatic
- rejection of the comment--this is a very
- poor man's spam reducer.
comment_nofollow - set this to 1 to add rel="nofollow" attributes to
links in the description -- these attributes are embedded
in the stored representation.
@@ -84,7 +82,34 @@ If you would like comment previews, you need to do 2 things.
This plugin implements Google's nofollow support for links in the body of the
comment. If you display the link of the comment poster in your HTML template
then you must add the rel="nofollow" attribute to your template as well
+
+
+
+Copyright (c) 2003-2005 Ted Leung
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
"""
+__author__ = "Ted Leung"
+__version__ = "$Id: comments.py,v 1.41.4.7 2005/06/10 13:58:29 willhelm Exp $"
+
import cgi, glob, os.path, re, time, cPickle, os, codecs
from xml.sax.saxutils import escape
from Pyblosxom import tools
@@ -95,8 +120,8 @@ def cb_start(args):
config = request.getConfiguration()
logdir = config.get("logdir", "/tmp/")
- logfile = os.path.normpath(logdir + os.sep + "comments.log")
- tools.make_logger(logfile)
+ # logfile = os.path.normpath(logdir + os.sep + "comments.log")
+ # tools.make_logger(logfile)
if not config.has_key('comment_dir'):
config['comment_dir'] = os.path.join(config['datadir'],'comments')
@@ -258,7 +283,8 @@ def readComment(filename, encoding):
cmt['cmt_pubDate'] = time.ctime(float(cmt['cmt_pubDate'])) #pretty time
return cmt
except: #don't error out on a bad comment
- tools.log('bad comment file: %s' % filename)
+ # tools.log('bad comment file: %s' % filename)
+ pass
def writeComment(request, config, data, comment, encoding):
"""
@@ -281,7 +307,8 @@ def writeComment(request, config, data, comment, encoding):
cdir = os.path.normpath(cdir)
if not os.path.isdir(cdir):
os.makedirs(cdir)
- cfn = os.path.join(cdir,entry['fn']+"-"+comment['pubDate']+"."+config['comment_ext'])
+
+ cfn = os.path.join(cdir,entry['fn']+"-"+comment['pubDate']+"."+config['comment_draft_ext'])
argdict = { "request": request, "comment": comment }
reject = tools.run_callback("comment_reject",
@@ -289,25 +316,28 @@ def writeComment(request, config, data, comment, encoding):
donefunc=lambda x:x)
if reject == 1:
return "Comment rejected."
+
+ def makeXMLField(name, field):
+ return "<"+name+">" + cgi.escape(field.get(name, "")) + "</"+name+">\n";
+
+ filedata = '<?xml version="1.0" encoding="%s"?>\n' % encoding
+ filedata += "<item>\n"
+ filedata += makeXMLField('title', comment)
+ filedata += makeXMLField('author', comment)
+ filedata += makeXMLField('link', comment)
+ filedata += makeXMLField('email', comment)
+ filedata += makeXMLField('source', comment)
+ filedata += makeXMLField('pubDate', comment)
+ filedata += makeXMLField('description', comment)
+ filedata += "</item>\n"
try :
cfile = codecs.open(cfn, "w", encoding)
except IOError:
- tools.log("Couldn't open comment file %s for writing" % cfn)
- return
-
- def makeXMLField(name, field):
- return "<"+name+">"+cgi.escape(field[name])+"</"+name+">\n";
-
- cfile.write('<?xml version="1.0" encoding="%s"?>\n' % encoding)
- cfile.write("<item>\n")
- cfile.write(makeXMLField('title',comment))
- cfile.write(makeXMLField('author',comment))
- cfile.write(makeXMLField('link',comment))
- cfile.write(makeXMLField('source',comment))
- cfile.write(makeXMLField('pubDate',comment))
- cfile.write(makeXMLField('description',comment))
- cfile.write("</item>\n")
+ # tools.log("Couldn't open comment file %s for writing" % cfn)
+ return "Internal error: Your comment could not be saved."
+
+ cfile.write(filedata)
cfile.close()
#write latest pickle
@@ -316,8 +346,8 @@ def writeComment(request, config, data, comment, encoding):
try:
latest = open(latestFilename,"w")
except IOError:
- tools.log("Couldn't open latest comment pickle for writing")
- return
+ # tools.log("Couldn't open latest comment pickle for writing")
+ return "Couldn't open latest comment pickle for writing."
else:
modTime = float(comment['pubDate'])
@@ -328,12 +358,20 @@ def writeComment(request, config, data, comment, encoding):
# should log or e-mail
if latest:
latest.close()
- return
-
+ return "Internal error: Your comment may not have been saved."
+
if config.has_key('comment_smtp_server') and \
config.has_key('comment_smtp_to'):
+ # FIXME - removed grabbing send_email's return error message
+ # so there's no way to know if email is getting sent or not.
send_email(config, entry, comment, cdir, cfn)
+ # figure out if the comment was submitted as a draft
+ if config["comment_ext"] != config["comment_draft_ext"]:
+ return "Comment was submitted for approval. Thanks!"
+
+ return "Comment submitted. Thanks!"
+
def send_email(config, entry, comment, comment_dir, comment_filename):
"""Send an email to the blog owner on a new comment
@@ -366,11 +404,11 @@ def send_email(config, entry, comment, comment_dir, comment_filename):
email = comment['email']
else:
email = config['comment_smtp_from']
+
try:
server = smtplib.SMTP(config['comment_smtp_server'])
curl = config['base_url']+'/'+entry['file_path']
comment_dir = os.path.join(config['comment_dir'], entry['absolute_path'])
- comment_filename = os.path.join(comment_dir,entry['fn']+"-"+comment['pubDate']+"."+config['comment_draft_ext'])
message = []
message.append("From: %s" % email)
@@ -384,7 +422,9 @@ def send_email(config, entry, comment, comment_dir, comment_filename):
msg="\n".join(message))
server.quit()
except Exception, e:
- tools.log("Error sending mail: %s" % e)
+ # tools.log("Error sending mail: %s" % e)
+ # FIXME - if we error out, no one will know.
+ pass
def clean_author(s):
"""
@@ -543,6 +583,7 @@ def cb_prepare(args):
data["comment_message"] = writeComment(request, config, data, \
cdict, encoding)
+
def escape_link(linkstring):
"""Don't allow html in the link string"""
for c in "<>'\"":
@@ -553,6 +594,24 @@ def decode_form(d, encoding):
for key in d:
d[key].value = d[key].value.decode(encoding)
+def cb_pathinfo(args):
+ request = args['request']
+ data = request.getData()
+ pyhttp = request.getHttp()
+ qstr = pyhttp.get('QUERY_STRING', None)
+
+ data['display_comment_default'] = 0
+
+ if qstr == None:
+ return None
+
+ parsed_qs = cgi.parse_qs(qstr)
+ if parsed_qs.has_key('showcomments'):
+ if parsed_qs['showcomments'][0] == 'yes':
+ data['display_comment_default'] = 1
+
+ return None
+
def cb_head(args):
renderer = args['renderer']
@@ -575,10 +634,12 @@ def cb_story(args):
entry = args['entry']
template = args['template']
request = args["request"]
+ data = request.getData()
config = request.getConfiguration()
if len(renderer.getContent()) == 1 \
and renderer.flavour.has_key('comment-story') \
- and not entry.has_key("nocomments"):
+ and not entry.has_key("nocomments") \
+ and data['display_comment_default'] == 1:
template = renderer.flavour.get('comment-story','')
args['template'] = args['template'] + template
@@ -620,11 +681,13 @@ def cb_story_end(args):
entry = args['entry']
template = args['template']
request = args["request"]
+ data = request.getData()
form = request.getHttp()['form']
config = request.getConfiguration()
if len(renderer.getContent()) == 1 \
and renderer.flavour.has_key('comment-story') \
- and not entry.has_key("nocomments"):
+ and not entry.has_key("nocomments") \
+ and data['display_comment_default'] == 1:
output = []
entry['comments'] = readComments(entry, config)
if entry.has_key('comments'):