def backend(comment, content_object, request): """ Akismet spam checker backend for Zinnia. """ blog_url = '%s://%s/' % (PROTOCOL, Site.objects.get_current().domain) akismet = Akismet(key=AKISMET_API_KEY, blog_url=blog_url) if not akismet.verify_key(): raise APIKeyError('Your Akismet API key is invalid.') akismet_data = { 'user_ip': request.META.get('REMOTE_ADDR', ''), 'user_agent': request.META.get('HTTP_USER_AGENT', ''), 'referrer': request.META.get('HTTP_REFERER', 'unknown'), 'permalink': content_object.get_absolute_url(), 'comment_type': 'comment', 'comment_author': smart_str(comment.name), 'comment_author_email': smart_str(comment.email), 'comment_author_url': smart_str(comment.url), } is_spam = akismet.comment_check(smart_str(comment.comment), data=akismet_data, build_data=True) return is_spam
def moderate(self, comment, content_object, request): """Determine whether a given comment on a given object should be allowed to show up immediately, or should be marked non-public and await approval.""" if self.auto_moderate_comments: return True if not AKISMET_COMMENT or not AKISMET_API_KEY: return False try: from akismet import Akismet from akismet import APIKeyError except ImportError: return False akismet = Akismet(key=AKISMET_API_KEY, blog_url='%s://%s/' % (PROTOCOL, Site.objects.get_current().domain)) if akismet.verify_key(): akismet_data = { 'user_ip': request.META.get('REMOTE_ADDR', ''), 'user_agent': request.META.get('HTTP_USER_AGENT', ''), 'referrer': request.META.get('HTTP_REFERER', 'unknown'), 'permalink': content_object.get_absolute_url(), 'comment_type': 'comment', 'comment_author': smart_str(comment.userinfo.get('name', '')), 'comment_author_email': smart_str(comment.userinfo.get('email', '')), 'comment_author_url': smart_str(comment.userinfo.get('url', '')), } is_spam = akismet.comment_check(smart_str(comment.comment), data=akismet_data, build_data=True) if is_spam: comment.save() user = comment.content_object.authors.all()[0] comment.flags.create(user=user, flag='spam') return is_spam raise APIKeyError('Your Akismet API key is invalid.')
def backend(comment, content_object, request): """TypePad spam checker backend for Gstudio""" blog_url = '%s://%s/' % (PROTOCOL, Site.objects.get_current().domain) typepad = TypePad(key=TYPEPAD_API_KEY, blog_url=blog_url) if not typepad.verify_key(): raise APIKeyError('Your Typepad API key is invalid.') typepad_data = { 'user_ip': request.META.get('REMOTE_ADDR', ''), 'user_agent': request.META.get('HTTP_USER_AGENT', ''), 'referrer': request.META.get('HTTP_REFERER', 'unknown'), 'permalink': content_object.get_absolute_url(), 'comment_type': 'comment', 'comment_author': smart_str(comment.userinfo.get('name', '')), 'comment_author_email': smart_str(comment.userinfo.get('email', '')), 'comment_author_url': smart_str(comment.userinfo.get('url', '')), } is_spam = typepad.comment_check(smart_str(comment.comment), data=typepad_data, build_data=True) return is_spam