diff options
author | Gunnar Wrobel <wrobel@gentoo.org> | 2006-05-28 21:17:28 +0000 |
---|---|---|
committer | Gunnar Wrobel <wrobel@gentoo.org> | 2006-05-28 21:17:28 +0000 |
commit | 0793a462e5b24aac5952eda03e0450ed3b23390c (patch) | |
tree | 5ab533c3f1d95553512d9d18a6684519d70db344 /www-apps | |
parent | Added pycalendar and pyarchives to the ebuild. (diff) | |
download | overlay-0793a462e5b24aac5952eda03e0450ed3b23390c.tar.gz overlay-0793a462e5b24aac5952eda03e0450ed3b23390c.tar.bz2 overlay-0793a462e5b24aac5952eda03e0450ed3b23390c.zip |
Added trackback stuff
svn path=/stable/; revision=715
Diffstat (limited to 'www-apps')
-rw-r--r-- | www-apps/pyblosxom-plugins/Manifest | 5 | ||||
-rw-r--r-- | www-apps/pyblosxom-plugins/files/commentAPI.py | 138 | ||||
-rw-r--r-- | www-apps/pyblosxom-plugins/files/trackback.py | 127 | ||||
-rw-r--r-- | www-apps/pyblosxom-plugins/files/xmlrpc_pingback.py | 164 | ||||
-rw-r--r-- | www-apps/pyblosxom-plugins/pyblosxom-plugins-1.3.2.ebuild | 3 |
5 files changed, 436 insertions, 1 deletions
diff --git a/www-apps/pyblosxom-plugins/Manifest b/www-apps/pyblosxom-plugins/Manifest index 79192bf..ae71a13 100644 --- a/www-apps/pyblosxom-plugins/Manifest +++ b/www-apps/pyblosxom-plugins/Manifest @@ -1,4 +1,5 @@ MD5 f67ef44f565d2cfa49ce8e728267081b files/blocks.py 6567 +MD5 d4a9d94b9c5eff48ee20510177e22730 files/commentAPI.py 5425 MD5 3d89ed013ed90e7afff11e8e3a57ebf4 files/comments.py 25302 MD5 53cf6af3d39e1d47a4d26d20dbe4338b files/contact.py 11517 MD5 d41d8cd98f00b204e9800998ecf8427e files/digest-pyblosxom-plugins-1.3.2 0 @@ -13,6 +14,8 @@ MD5 dad8289c1e561ffec042f661873e4ed4 files/pyguest.py 10951 MD5 b0462630303ce00d3356062868299bce files/rss2renderer.py 8779 MD5 551595972432681869214de6b21dc0aa files/rss2renderer.py.html 41245 MD5 9d08ee37ee648e2e1541b51333db0fe6 files/session.py 11214 +MD5 d39794b25ac69bcced9f27be23cea81c files/trackback.py 4603 MD5 2fcbddb5246ec1f79ec0557cbe56bdad files/wbglast10summary.py 1094 MD5 1bd704ad5a8e5fd621b84a6ab2ec9d32 files/wbglast10summary.py.html 4862 -MD5 99bf8f8959ffc6e079cf39fd0a9d2d93 pyblosxom-plugins-1.3.2.ebuild 1043 +MD5 9d1afb745bb12ea8b1ab7a2ab2be7e6a files/xmlrpc_pingback.py 5696 +MD5 3a1cd48b2ee5f5175cf74f8ad606ad13 pyblosxom-plugins-1.3.2.ebuild 1128 diff --git a/www-apps/pyblosxom-plugins/files/commentAPI.py b/www-apps/pyblosxom-plugins/files/commentAPI.py new file mode 100644 index 0000000..494f3e9 --- /dev/null +++ b/www-apps/pyblosxom-plugins/files/commentAPI.py @@ -0,0 +1,138 @@ +""" +Copyright (c) 2003-2005 Ted Leung + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +CommentAPI provides support for Joe Gregario's CommentAPI +<http://wellformedweb.org/story/9>. To use it, place it your plugins +directory and make sure that you define py['commentAPI_urltrigger'], which +is the URI to be used for talking to the commentAPI. Be sure that +you have comments.py installed + +You must also add the commentAPI tags to your RSS 2.0 feed. The best way to +do this is to add an XML namespace declaration to the rss element: + xmlns:wfw="http://wellformedweb.org/CommentAPI" + +Then inside your RSS items you need to add a wfw:comment element: + + <wfw:comment>$base_url/###commentAPI###/$file_path</wfw:comment> + + where ###commentAPI### is the value of commentAPI_urltrigger + +%<--------------------------------------------------------- +py['commentAPI_urltrigger'] = "/commentAPI" +%<--------------------------------------------------------- + +""" +import os, os.path +from Pyblosxom import tools + +def cb_start(args): + request = args["request"] + config = request.getConfiguration() + +def verify_installation(request): + config = request.getConfiguration() + retval = 1 + + # all config properties are optional + if not config.has_key('commentAPI_urltrigger'): + print("missing optional property: 'commentAPI_urltrigger'") + + return retval + +def cb_handle(args): + """ + + @param args: a dict of plugin arguments + @type args: dict + """ + request = args['request'] + pyhttp = request.getHttp() + config = request.getConfiguration() + + urltrigger = config.get('commentAPI_urltrigger','/commentAPI') + + path_info = pyhttp['PATH_INFO'] + if path_info.startswith(urltrigger): + try: + from Pyblosxom.entries.fileentry import FileEntry + import os, sys + pi = path_info.replace(urltrigger,'') + if pi == '': + sys.exit("<html><body>CommentAPI.cgi expects to receive an RSS item on standard input</body></html>") + + datadir = config['datadir'] + path = os.path.join(datadir, pi[1:]) + data = request.getData() + filename = '' + ext = tools.what_ext(data['extensions'].keys(),path) + filename = os.path.normpath('%s.%s' % (path, ext)) + entry = FileEntry(request, filename, datadir ) + data = {} + data['entry_list'] = [ entry ] + + commentString = sys.stdin.read() + if commentString == None: + sys.exit("<html><body>CommentAPI expects to receive an RSS item on standard input</body></html>") + try: + from xml.dom.minidom import parseString + from xml.parsers.expat import ExpatError + commentDOM = parseString(commentString) + except ExpatError, ee: + sys.exit("<html><body>The RSS Item you supplied could not be parsed.\nThe error occured at line %d, column %d</body></html>" % (ee.lineno,ee.offset)) + + def dictFromDOM(dom, data, field, default=''): + """ + Fill in a field in dict with the content of a element in the dom + + TODO: epydoc + """ + value = dom.getElementsByTagName(field) + if len(value) == 1: + data[field] = value[0].firstChild.data + else: + data[field] = default + + # use dictFromDOM to fill in a dict with the stuff in the comment + cdict = {} + dictFromDOM(commentDOM, cdict, 'title') + dictFromDOM(commentDOM, cdict, 'author') + dictFromDOM(commentDOM, cdict, 'link') + dictFromDOM(commentDOM, cdict, 'source') + # force an integer data stamp -- not in keeping with RFC 822, + # but neither is RSS + import time + cdict['pubDate'] = str(time.time()) + dictFromDOM(commentDOM, cdict, 'description') + + # must be done after plugin initialization + from comments import writeComment + # write the comment (in the dict) + writeComment(request, config, data, cdict, config['blog_encoding']) + + print "Content-Type: text/plain\n" + print "OK" + except OSError: + print "Content-Type: text/plain\n" + print "An Error Occurred" + return 1 + else: + return 0 diff --git a/www-apps/pyblosxom-plugins/files/trackback.py b/www-apps/pyblosxom-plugins/files/trackback.py new file mode 100644 index 0000000..35541c8 --- /dev/null +++ b/www-apps/pyblosxom-plugins/files/trackback.py @@ -0,0 +1,127 @@ +""" +This plugin allows pyblosxom to process trackback +<http://www.sixapart.com/pronet/docs/trackback_spec> pings. You must have the +comments plugin installed as well, although you don't need to enable comments +on your blog in order for trackbacks to work + +%<--------------------------------------------------------- +py['trackback_urltrigger'] = "/trackback" +%<--------------------------------------------------------- + +For more detailed installation, read the README file that comes with +the comments plugins. + + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Copyright (c) 2003-2005 Ted Leung +""" +import cgi, os, os.path +from Pyblosxom import tools + +tb_good_response = """<?xml version="1.0" encoding="iso-8859-1"?> +<response> +<error>0</error> +</response>""" + +tb_bad_response = """<?xml version="1.0" encoding="iso-8859-1"?> +<response> +<error>1</error> +<message>%s</message> +</response>""" + +def cb_start(args): + request = args["request"] + config = request.getConfiguration() + logdir = config.get("logdir", "/tmp") + logfile = os.path.normpath(logdir + os.sep + "trackback.log") + +def verify_installation(request): + config = request.getConfiguration() + retval = 1 + + # all config properties are optional + if not config.has_key('trackback_urltrigger'): + print("missing optional property: 'trackback_urltrigger'") + + return retval + +def cb_handle(args): + """ + + @param args: a dict of plugin arguments + @type args: dict + """ + request = args['request'] + pyhttp = request.getHttp() + config = request.getConfiguration() + + urltrigger = config.get('trackback_urltrigger','/trackback') + + logger = tools.getLogger() + + path_info = pyhttp['PATH_INFO'] + if path_info.startswith(urltrigger): + response = request.getResponse() + response.addHeader("Content-type", "text/xml") + + form = request.getForm() + + message = "A trackback must have at least a URL field (see http://www.sixapart.com/pronet/docs/trackback_spec )" + + if form.has_key("url"): + import time + cdict = { 'title': form.getvalue('title', ''), \ + 'author': 'Trackback from %s' % form.getvalue('blog_name', ''), \ + 'pubDate' : str(time.time()), \ + 'link' : form['url'].value, \ + 'source' : form.getvalue('blog_name', ''), \ + 'description' : form.getvalue('excerpt', '') } + from Pyblosxom.entries.fileentry import FileEntry + from Pyblosxom.pyblosxom import Request + from Pyblosxom.pyblosxom import PyBlosxom + + datadir = config['datadir'] + + from comments import writeComment + try: + import os + pi = path_info.replace(urltrigger,'') + path = os.path.join(datadir, pi[1:]) + data = request.getData() + ext = tools.what_ext(data['extensions'].keys(), path) + entry = FileEntry(request, '%s.%s' % (path, ext), datadir ) + data = {} + data['entry_list'] = [ entry ] + writeComment(request, config, data, cdict, config['blog_encoding']) + print >> response, tb_good_response + except OSError: + message = 'URI '+path_info+" doesn't exist" + logger.error(message) + print >> response, tb_bad_response % message + + else: + logger.error(message) + print >> response, tb_bad_response % message + + # no further handling is needed + return 1 + else: + return 0 diff --git a/www-apps/pyblosxom-plugins/files/xmlrpc_pingback.py b/www-apps/pyblosxom-plugins/files/xmlrpc_pingback.py new file mode 100644 index 0000000..a3d18db --- /dev/null +++ b/www-apps/pyblosxom-plugins/files/xmlrpc_pingback.py @@ -0,0 +1,164 @@ +""" +Copyright (c) 2003-2005 Ted Leung + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +This module contains an XML-RPC extension to support pingback +<http://www.hixie.ch/specs/pingback/pingback> pings. You must have the +comments plugin installed as well, although you don't need to enable comments +on your blog in order for trackbacks to work + +""" + +from config import py +from Pyblosxom.pyblosxom import PyBlosxom +from Pyblosxom import tools +from xmlrpclib import Fault + +import os, re, sgmllib, time, urllib, urlparse + +def verify_installation(request): + # no config parameters + return 1 + +class parser(sgmllib.SGMLParser): + """ Shamelessly grabbed from Sam Ruby + from http://www.intertwingly.net/code/mombo/pingback.py + """ + """ extract title and hrefs from a web page""" + intitle=0 + title = "" + hrefs = [] + + def do_a(self, attrs): + attrs=dict(attrs) + if attrs.has_key('href'): self.hrefs.append(attrs['href']) + + def do_title(self, attrs): + if self.title=="": self.intitle=1 + def unknown_starttag(self, tag, attrs): + self.intitle=0 + def unknown_endtag(self,tag): + self.intitle=0 + def handle_charref(self, ref): + if self.intitle: self.title = self.title + ("&#%s;" % ref) + def handle_data(self,text): + if self.intitle: self.title = self.title + text + +def fileFor(req, uri): + config = req.getConfiguration() + data = req.getData() + urldata = urlparse.urlsplit(uri) + + # Reconstruct uri to something sane + uri = "%s://%s%s" % (urldata[0], urldata[1], urldata[2]) + fragment = urldata[4] + + # We get our path here + path = uri.replace(config['base_url'], '') + req.addHttp({'PATH_INFO': path, "form": {}}) + from Pyblosxom.pyblosxom import blosxom_process_path_info + blosxom_process_path_info({'request': req}) + + args = { 'request': req } + from Pyblosxom.pyblosxom import blosxom_file_list_handler + es = blosxom_file_list_handler(args) + + # We're almost there + if len(es) == 1 and path.find(es[0]['file_path']) >= 0: + return es[0] + + # Could be a fragment link + for i in es: + if i['fn'] == fragment: + return i + + # Point of no return + if len(es) >= 1: + raise Fault(0x0021, "%s cannot be used as a target" % uri) + else: + raise Fault(0x0020, "%s does not exist") + + +def pingback(request, source, target): + logger = tools.getLogger() + logger.info("pingback started") + source_file = urllib.urlopen(source.split('#')[0]) + if source_file.headers.get('error', '') == '404': + raise Fault(0x0010, "Target %s not exists" % target) + source_page = parser() + source_page.feed(source_file.read()) + source_file.close() + + if source_page.title == "": source_page.title = source + + if target in source_page.hrefs: + target_entry = fileFor(request, target) + + body = '' + try: + from rssfinder import getFeeds + from rssparser import parse + + baseurl=source.split("#")[0] + for feed in getFeeds(baseurl): + for item in parse(feed)['items']: + if item['link']==source: + if 'title' in item: source_page.title = item['title'] + if 'content_encoded' in item: body = item['content_encoded'].strip() + if 'description' in item: body = item['description'].strip() or body + body=re.compile('<.*?>',re.S).sub('',body) + body=re.sub('\s+',' ',body) + body=body[:body.rfind(' ',0,250)][:250] + " ...<br />" + except: + pass + + cmt = {'title':source_page.title, \ + 'author':'Pingback from %s' % source_page.title, + 'pubDate' : str(time.time()), \ + 'link': source, + 'source' : '', + 'description' : body} + + from comments import writeComment + config = request.getConfiguration() + data = request.getData() + data['entry_list'] = [ target_entry ] + + # TODO: Check if comment from the URL exists + writeComment(request, config, data, cmt, config['blog_encoding']) + + return "success pinging %s from %s\n" % (source, target) + else: + raise Fault(0x0011, "%s does not point to %s" % (target, source)) + +def cb_xmlrpc_register(args): + """ + Register as a pyblosxom XML-RPC plugin + """ + args['methods'].update({'pingback.ping': pingback }) + return args + +def cb_start(args): + request = args["request"] + config = request.getConfiguration() + + logger = tools.getLogger() + logger.info("finished config") diff --git a/www-apps/pyblosxom-plugins/pyblosxom-plugins-1.3.2.ebuild b/www-apps/pyblosxom-plugins/pyblosxom-plugins-1.3.2.ebuild index 5955d6b..44026b9 100644 --- a/www-apps/pyblosxom-plugins/pyblosxom-plugins-1.3.2.ebuild +++ b/www-apps/pyblosxom-plugins/pyblosxom-plugins-1.3.2.ebuild @@ -38,6 +38,9 @@ src_install() { logrequest.py pyguest.py blocks.py + trackback.py + commentAPI.py + xmlrpc_pingback.py wbglast10summary.py" for plg in ${PLUGINS} |