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 viewCommentManager(self, ident): ns = { 'ident': ident, 'template': self.template, 'comments': BlogCommentModel.getAllByIdent(ident) } return render("site_plugins/blog/view/comment_manager.tmpl", ns)
def renderPost(post, edit_mode, is_permanent=False): page_obj = CMSModel.Pages.getPageById(post.getHostPage()) def cmsRender(text): return getFormatManager().htmlFormat(text, edit_mode, False, page_obj) #Buttons if edit_mode: btn_del = html_helpers.createActionLink("Delete post", "static_core/images/trash.png", "return Blog.del(this, '%s');" % post.getIdent(), tooltip_inner=True, confirm='Are you sure you want to delete?') btn_edit = html_helpers.createActionLink("Edit post", "static_core/images/edit.png", "return Blog.viewEdit('%s', this);" % post.getIdent(), tooltip_inner=True) btn_published = html_helpers.createActionLink("Published", "static_core/images/%(image)s", "return Blog.publish(this, '%s');" % post.getIdent(), tooltip_inner=True) d = post.published and {'image': 'on.png'} or {'image': 'off.png'} btn_published = btn_published % d else: btn_del = '' btn_edit = '' btn_published = '' ns = { 'post': post, 'btn_delete': btn_del, 'btn_edit': btn_edit, 'btn_published': btn_published, 'cmsRender': cmsRender, 'comments': BlogCommentModel.getAll(post.id), 'edit_mode': edit_mode, 'is_permanent': is_permanent, 'post_comment_div': renderPostComment(post.id), 'GENERIC_POST_LINK': GENERIC_POST_LINK, 'GENERIC_LABEL_LINK': GENERIC_LABEL_LINK, 'renderComment': renderComment } if post.published or edit_mode: #Check and see if the template has a inject method site_obj = getRootController().root_obj if getattr(site_obj.template, 'plugin_blog_renderPost', False): return site_obj.template.plugin_blog_renderPost(ns) else: return render("site_plugins/blog/view/item.tmpl", ns) else: return 'No post found.'
def updateComment(self, id, content): BlogCommentModel.update(id, content) self._expireCommentCache(id) return getFormatManager().noPluginFormat(content, True)
def getCommentContent(self, id): comment = BlogCommentModel.getById(id) return comment.content
def fetchMore(self, last_id, ident=''): last_id = long(last_id) list = BlogCommentModel.getAllByIdent(ident, after_id=last_id) jsons = [ i.toJSON() for i in list ] return '[%s]' % (','.join(jsons))
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)