forked from getpelican/pelican
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This system is based on email. Users have to send comment by mail : - By thereselve using right format (pretty difficult) - Using a html form "actioning" to a script sending the mail as necessary (far easier for them) You will have to setup the following config variable : - IMAP_HOSTNAME : The hostname where to read comments/emails. - IMAP_USERNAME : The username to use. - IMAP_PASSWORD : The password to use. - IMAP_READBOX : In wish directory read emails (INBOX, INBOX/validated) In samples/commentsystem : - send_comment.py : A python cgi script to send the mail where it need to be sent - comments.html A template to insert at the end of your article template: <div id="article"> ... {{ article.content }} ... {% include 'comments.html' %} ... </div> This code worked on my early tests. However it never has been push in production. It is published here cause somes want it to be shared. Feel free to use it as you need it but use it at your own risk. License is the same of pelican (AGPL) cause code is part of pelican. But I will not bother you if you take it in your project on another license. (Maybe write my name somewhere on your sources :P )
- Loading branch information
1 parent
8864b55
commit c590eca
Showing
8 changed files
with
275 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<div id="comments"> | ||
|
||
<h2>Commentaires:</h2> | ||
<div id="commentSection"> | ||
<ol id="commentsList"> | ||
{% for slug, _comments in comments %} | ||
{% if article.slug == slug %} | ||
{% for comment in _comments %} | ||
<li> | ||
Par | ||
{% if comment.website %} | ||
<a class="author" href="{{comment.website|e}}">{{ comment.author|e }}</a> | ||
{% else %} | ||
{{ comment.author|e }} | ||
{% endif %} | ||
le <span class="date">{{ comment.locale_date }}</span> | ||
<div class="commentContent"> | ||
{{ comment.content }} | ||
</div> | ||
</li> | ||
{% endfor %} | ||
{% endif %} | ||
{% endfor %} | ||
</ol> | ||
</div> | ||
|
||
<div class="answer"> | ||
<h3>Répondre :</h3> | ||
<form name='comment' method='POST' accept-charset="UTF-8" action='http://your.website/send_comment.py'> | ||
<input type='hidden' name='slug' value="{{ article.slug }}" /> | ||
<input type='hidden' name='lang' value="{{ article.lang }}" /> | ||
<table> | ||
<tr><td>Nom:</td><td><input type='text' name='realname' size='20'/>*</td></tr> | ||
<tr><td>Email:</td><td><input type='text' name='email' size='20'/>*</td></tr> | ||
<tr><td>Site web:</td><td><input type='text' name='website' size='20' value='http://'/></td></tr> | ||
<tr><td>Commentaire: *</td><td/></tr> | ||
</table> | ||
<textarea name='comment' cols='100' rows='10'></textarea><br/> | ||
<input type='submit' name='Submit' value="Poster un commentaire"/> | ||
</form> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
import cgi | ||
|
||
import cgitb | ||
cgitb.enable() | ||
|
||
import sys | ||
|
||
form = cgi.FieldStorage() | ||
|
||
|
||
if not ( form.has_key("slug") | ||
and form.has_key("lang") | ||
and form.has_key("realname") | ||
and form.has_key("email") | ||
and form.has_key("comment") | ||
): | ||
print 'Location: /pages/comment-error.html' | ||
|
||
sys.exit(0) | ||
|
||
from email.mime.multipart import MIMEMultipart | ||
from email.mime.text import MIMEText | ||
from email.header import Header | ||
from email import Charset | ||
from email.Utils import formataddr | ||
from subprocess import Popen, PIPE | ||
from hashlib import md5 | ||
|
||
|
||
slug = form.getvalue('slug').decode('utf8') | ||
lang = form.getvalue('lang').decode('utf8') | ||
realname = form.getvalue('realname').decode('utf8') | ||
email = form.getvalue('email').decode('utf8') | ||
website = form.getvalue('website','').decode('utf8') | ||
website = website.strip() | ||
# [TODO] handle https | ||
if website == u"http://": | ||
website = u"" | ||
if not website.startswith(u"http://"): | ||
website = u"http://" + website | ||
comment = form.getvalue('comment').decode('utf8') | ||
|
||
id_ = md5(comment.encode('utf8')).hexdigest() | ||
|
||
content = u"""slug: %(slug)s | ||
lang: %(lang)s | ||
author: %(realname)s | ||
email: %(email)s | ||
website: %(website)s | ||
id: %(id)s | ||
---------- | ||
%(comment)s | ||
""" % {'slug':slug, 'lang':lang, 'realname':realname, 'email':email, 'website':website, 'id':id_, 'comment':comment} | ||
content = content.encode('utf8') | ||
|
||
subject = u"[Comment] %(slug)s - %(name)s" % {'slug': slug, 'name' : realname} | ||
|
||
send_name = str(Header(realname, "utf8")) | ||
email = str(Header(email, "utf8")) | ||
|
||
|
||
To=u"comment-box@hostname.example" | ||
msg = MIMEText(content, "plain", "utf8") | ||
msg["From"] = formataddr((realname, email)) | ||
msg["To"] = Header(To, 'utf8') | ||
msg.add_header('reply-to', str(Header(To, 'utf8'))) | ||
|
||
msg["Subject"] = Header(subject, 'utf8') | ||
|
||
p = Popen(["/usr/lib/sendmail", "-t"], stdin=PIPE) | ||
p.communicate(msg.as_string()) | ||
|
||
print 'Location: /pages/comment-ok.html' | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters