def addComment(self, author, email, website, content, post_id): #Check captcha m = md5.new() m.update(content) hash_val = m.hexdigest() if hash_val != session().get('captcha_ok_for'): raise Exception('Wrong captcha check') else: del session()['captcha_ok_for'] if website != '' and website.find("http://") != 0: website = "http://%s" % (website) #Strip scripts, style and meta content = re.sub('<(script|meta|style)(.|\s)*?>(.|\s)*?</(script|meta|style)>', '', content) #Check for same URL's posted try: self.checkURLSpam(author, content) except SpamComment: return '<p><b style="background-color: #ffffcc; color: red">Your comment was marked as spam.</b>, but will be readded if it isn\'t.</p>' self._expireCache(post_id) id = BlogCommentModel.add(author, email, website, content, post_id) email_data = { 'title': 'An comment has been posted', 'author': author, 'email': email, 'website': website, 'content': content, 'delete_link': self._getDeleteURL(id), 'post_id': self._getCommentURL(post_id, id) } #Send a notification email if hasattr(getConfig(), 'DEFAULT_EMAIL'): text = """%(title)s Author: %(author)s Email: %(email)s Website: %(website)s Post link: %(post_id)s Content: %(content)s Delete link: %(delete_link)s """ % email_data mail = getConfig().DEFAULT_EMAIL getMailManager().sendEmail(mail, [mail], '[Skeletonz] %s' % email_data['title'], text) if id: return renderComment(BlogCommentModel.getById(id), True, False) else: return '<p><b style="background-color: #ffffcc; color: red">Your comment was marked as spam.</b>, but will be readded if it isn\'t.</p>'
def deleteComments(self, ids, ident=""): ids = json.read(ids) if len(ids) > 0: first_id = ids[0] c = BlogCommentModel.getById(first_id) self._expireCommentCache(first_id) for id in ids: BlogCommentModel.delete(id) return 'ok'
def getCommentContent(self, id): comment = BlogCommentModel.getById(id) return comment.content
def deleteComment(self, id, ident=""): c = BlogCommentModel.getById(id) self._expireCommentCache(id) #BlogCommentModel.delete(id) return c.post_id
def viewComment(self, id): comment = BlogCommentModel.getById(id) post = comment.getPost() url = self._getCommentURL(post.id, id) raise amiweb.HTTPFound(url)
def _expireCommentCache(self, id): comment = BlogCommentModel.getById(id) self._expireCache(comment.post_id)