コード例 #1
0
ファイル: trackback.py プロジェクト: aklapcin/gae_blog
    def post(self, post_slug):

        # this is probably the best resource for more info about trackback: http://www.sixapart.com/labs/trackback/

        ip_address = self.request.remote_addr
        blog = self.blog
        error = ""

        if not blog:
            error = "There is no blog at this URL."
        elif not blog.enable_linkbacks or ip_address in blog.blocklist:
            error = "This blog does not have trackbacks enabled."
        elif not post_slug:
            error = "Missing post ID."
        else:
            post = model.BlogPost.get_by_id(post_slug, parent=blog.key)
            # only allow trackbacking to a post if it's actually published
            if not post or not post.published:
                error = "There is no post with ID " + post_slug
            else:
                form_data, errors, valid_data = self.validate()

                if errors:
                    error = "Invalid request."
                else:
                    excerpt = valid_data["excerpt"]
                    if excerpt:
                        # strip out all HTML to be on the safe side
                        excerpt = model.stripHTML(excerpt)

                        if excerpt:
                            # turn URL's into links
                            excerpt = model.linkURLs(excerpt)
                            # finally, replace linebreaks with HTML linebreaks
                            excerpt = excerpt.replace("\r\n", "<br/>")

                    url = valid_data["url"]
                    if url:
                        # look for a comment from this URL address on this blog already (redundancy check)
                        exists = post.comments.filter(model.BlogComment.url == url).filter(
                            model.BlogComment.trackback == True
                        )
                        if exists.count():
                            error = "This trackback already exists."

                if not error:
                    comment = model.BlogComment(url=url, trackback=True, ip_address=ip_address, parent=post.key)

                    if valid_data["title"]:
                        comment.name = valid_data["title"]
                    if excerpt:
                        comment.body = excerpt
                    if valid_data["blog_name"]:
                        comment.blog_name = valid_data["blog_name"]

                    comment.put()

                    self.linkbackEmail(post, comment)

        self.renderTemplate("trackback.xml", error=error)
コード例 #2
0
ファイル: trackback.py プロジェクト: loveinlastnight/gae_blog
    def post(self, post_slug):

        # this is probably the best resource for more info about trackback: http://www.sixapart.com/labs/trackback/

        ip_address = self.request.remote_addr
        blog = self.blog
        error = ''

        if not blog:
            error = 'There is no blog at this URL.'
        elif not blog.enable_linkbacks or ip_address in blog.blocklist:
            error = 'This blog does not have trackbacks enabled.'
        elif not post_slug:
            error = 'Missing post ID.'
        else:
            post = model.BlogPost.get_by_id(post_slug, parent=blog.key)
            # only allow trackbacking to a post if it's actually published
            if not post or not post.published:
                error = 'There is no post with ID ' + post_slug
            else:
                form_data, errors, valid_data = self.validate()

                if errors:
                    error = 'Invalid request.'
                else:
                    excerpt = valid_data["excerpt"]
                    if excerpt:
                        # strip out all HTML to be on the safe side
                        excerpt = model.stripHTML(excerpt)

                        if excerpt:
                            # turn URL's into links
                            excerpt = model.linkURLs(excerpt)
                            # finally, replace linebreaks with HTML linebreaks
                            excerpt = excerpt.replace("\r\n", "<br/>")

                    url = valid_data["url"]
                    if url:
                        # look for a comment from this URL address on this blog already (redundancy check)
                        exists = post.comments.filter(
                            model.BlogComment.url == url).filter(
                                model.BlogComment.trackback == True)
                        if exists.count():
                            error = 'This trackback already exists.'

                if not error:
                    comment = model.BlogComment(url=url,
                                                trackback=True,
                                                ip_address=ip_address,
                                                parent=post.key)

                    if valid_data["title"]:
                        comment.name = valid_data["title"]
                    if excerpt:
                        comment.body = excerpt
                    if valid_data["blog_name"]:
                        comment.blog_name = valid_data["blog_name"]

                    comment.put()

                    self.linkbackEmail(post, comment)

        self.renderTemplate('trackback.xml', error=error)
コード例 #3
0
ファイル: post.py プロジェクト: aklapcin/gae_blog
    def post(self, post_slug):

        ip_address = self.request.remote_addr
        blog = self.blog
        if blog and blog.enable_comments and ip_address not in blog.blocklist:
            # only allow comment posting if comments are enabled
            if post_slug:
                post = model.BlogPost.get_by_id(post_slug, parent=blog.key)
                if post and post.published:
                    # only allow commenting to a post if it's actually published

                    bot = self.botProtection('/post/' + post_slug)
                    if bot: return

                    form_data, errors, valid_data = self.validate()

                    valid_linkback = valid_data["trackback"] or valid_data["pingback"] or valid_data["webmention"]

                    if "body" not in errors:
                        # strip out all HTML to be on the safe side
                        body = model.stripHTML(valid_data["body"])

                        if body:
                            # turn URL's into links
                            body = model.linkURLs(body)
                            # finally, replace linebreaks with HTML linebreaks
                            body = body.replace("\r\n", "<br/>")
                        elif not valid_linkback:
                            errors["body"] = True

                    if valid_data["author_choice"] == "author":
                        # validate that if they want to comment as an author that it's valid and they're approved
                        if not self.user_is_admin:
                            return self.renderError(403)

                        author = model.BlogAuthor.get_by_id(valid_data["author"], parent=blog.key)
                        if not author:
                            errors["author"] = True

                        if not errors:
                            comment = model.BlogComment(body=body, approved=True, author=author.key, parent=post.key)
                            memcache.delete(self.request.path)
                    else:
                        # trackbacks require URLs, normal comments require emails if not from an author
                        if valid_linkback:
                            # must be admin to set linkbacks here and not through the normal paths
                            if not self.user_is_admin:
                                return self.renderError(403)

                            if not valid_data["url"]:
                                errors["url"] = True
                        elif not valid_data["email"]:
                            errors["email"] = True

                    if errors:
                        return self.redisplay(form_data, errors, self.blog_url + '/post/' + post_slug + '#comment-link')
                    elif valid_data["author_choice"] != "author":
                        # look for a previously approved comment from this email address on this blog
                        email = valid_data["email"]
                        approved = blog.comments.filter(model.BlogComment.email == email).filter(model.BlogComment.approved == True)

                        comment = model.BlogComment(email=email, body=body, ip_address=ip_address, parent=post.key)

                        if valid_data["name"]:
                            comment.name = valid_data["name"]
                        if valid_data["url"]:
                            comment.url = valid_data["url"]
                        if valid_data["trackback"]:
                            comment.trackback = True
                        if valid_data["blog_name"]:
                            comment.blog_name = valid_data["blog_name"]
                        if valid_data["pingback"]:
                            comment.pingback = True
                        if valid_data["webmention"]:
                            comment.webmention = True

                        if approved.count():
                            comment.approved = True
                            memcache.delete(self.request.path)
                        else:
                            self.linkbackEmail(post, comment)

                    comment.put()

                    return self.redirect(self.blog_url + '/post/' + post_slug + '#comments')

        return self.renderError(404)
コード例 #4
0
    def post(self, post_slug):

        ip_address = self.request.remote_addr
        blog = self.blog
        if blog and blog.enable_comments and ip_address not in blog.blocklist:
            # only allow comment posting if comments are enabled
            if post_slug:
                post = model.BlogPost.get_by_id(post_slug, parent=blog.key)
                if post and post.published:
                    # only allow commenting to a post if it's actually published

                    bot = self.botProtection('/post/' + post_slug)
                    if bot: return

                    form_data, errors, valid_data = self.validate()

                    valid_linkback = valid_data["trackback"] or valid_data[
                        "pingback"] or valid_data["webmention"]

                    if "body" not in errors:
                        # strip out all HTML to be on the safe side
                        body = model.stripHTML(valid_data["body"])

                        if body:
                            # turn URL's into links
                            body = model.linkURLs(body)
                            # finally, replace linebreaks with HTML linebreaks
                            body = body.replace("\r\n", "<br/>")
                        elif not valid_linkback:
                            errors["body"] = True

                    if valid_data["author_choice"] == "author":
                        # validate that if they want to comment as an author that it's valid and they're approved
                        if not self.user_is_admin:
                            return self.renderError(403)

                        author = model.BlogAuthor.get_by_id(
                            valid_data["author"], parent=blog.key)
                        if not author:
                            errors["author"] = True

                        if not errors:
                            comment = model.BlogComment(body=body,
                                                        approved=True,
                                                        author=author.key,
                                                        parent=post.key)
                            memcache.delete(self.request.path)
                    else:
                        # trackbacks require URLs, normal comments require emails if not from an author
                        if valid_linkback:
                            # must be admin to set linkbacks here and not through the normal paths
                            if not self.user_is_admin:
                                return self.renderError(403)

                            if not valid_data["url"]:
                                errors["url"] = True
                        elif not valid_data["email"]:
                            errors["email"] = True

                    if errors:
                        return self.redisplay(
                            form_data, errors, self.blog_url + '/post/' +
                            post_slug + '#comment-link')
                    elif valid_data["author_choice"] != "author":
                        # look for a previously approved comment from this email address on this blog
                        email = valid_data["email"]
                        approved = blog.comments.filter(
                            model.BlogComment.email == email).filter(
                                model.BlogComment.approved == True)

                        comment = model.BlogComment(email=email,
                                                    body=body,
                                                    ip_address=ip_address,
                                                    parent=post.key)

                        if valid_data["name"]:
                            comment.name = valid_data["name"]
                        if valid_data["url"]:
                            comment.url = valid_data["url"]
                        if valid_data["trackback"]:
                            comment.trackback = True
                        if valid_data["blog_name"]:
                            comment.blog_name = valid_data["blog_name"]
                        if valid_data["pingback"]:
                            comment.pingback = True
                        if valid_data["webmention"]:
                            comment.webmention = True

                        if approved.count():
                            comment.approved = True
                            memcache.delete(self.request.path)
                        else:
                            self.linkbackEmail(post, comment)

                    comment.put()

                    return self.redirect(self.blog_url + '/post/' + post_slug +
                                         '#comments')

        return self.renderError(404)