Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0277.py @ 1648:2b8a975ff712
plugin XEP-0277: fixed unsecure blog feed
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 23 Nov 2015 14:58:18 +0100 |
parents | 94901070478e |
children | b58c8b4715c6 |
comparison
equal
deleted
inserted
replaced
1647:31b96ac3eec2 | 1648:2b8a975ff712 |
---|---|
15 # GNU Affero General Public License for more details. | 15 # GNU Affero General Public License for more details. |
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _, D_ |
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from sat.core.log import getLogger | 22 from sat.core.log import getLogger |
23 log = getLogger(__name__) | 23 log = getLogger(__name__) |
24 from twisted.words.protocols.jabber import jid, error | 24 from twisted.words.protocols.jabber import jid, error |
25 from twisted.words.xish import domish | 25 from twisted.words.xish import domish |
857 """ | 857 """ |
858 if node is None: | 858 if node is None: |
859 node = NS_MICROBLOG | 859 node = NS_MICROBLOG |
860 items, metadata = yield self._p.getItems(service_jid, node, max_items=max_items, item_ids=item_ids, rsm_request=rsm_request, extra=extra, profile_key=profile_key) | 860 items, metadata = yield self._p.getItems(service_jid, node, max_items=max_items, item_ids=item_ids, rsm_request=rsm_request, extra=extra, profile_key=profile_key) |
861 | 861 |
862 feed = """<?xml version="1.0" encoding="utf-8"?> | 862 feed_elt = domish.Element((NS_ATOM, 'feed')) |
863 <feed xmlns="http://www.w3.org/2005/Atom"> | 863 title = D_(u"{user}'s blogposts").format(user=service_jid.user) |
864 <title>%(user)s's blogposts</title> | 864 feed_elt.addElement('title', content=title) |
865 <link href="%(feed)s" rel="self" /> | 865 link_feed_elt = feed_elt.addElement('link') |
866 <link href="%(blog)s" /> | 866 link_feed_elt['href'] = 'http://{host}/blog/{user}/atom.xml'.format( |
867 <id>%(id)s</id> | 867 host=urllib.quote(service_jid.host,''), |
868 <updated>%(date)s</updated>\n""" % {'user': service_jid.user, | 868 user=urllib.quote(service_jid.user,'')) |
869 'feed': 'http://%s/blog/%s/atom.xml' % (service_jid.host, service_jid.user), | 869 link_feed_elt['rel'] = 'self' |
870 'blog': 'http://%s/blog/%s' % (service_jid.host, service_jid.user), | 870 link_blog_elt = feed_elt.addElement('link') |
871 'id': node, | 871 link_blog_elt['href'] = 'http://{host}/blog/{user}'.format( |
872 'date': rfc3339.timestamp_from_tf(rfc3339.tf_utc())} | 872 host=urllib.quote(service_jid.host,''), |
873 | 873 user=urllib.quote(service_jid.user,'')) |
874 def removeAllURIs(element): | 874 feed_elt.addElement('id', content=node) |
875 """Recursively remove the URIs of the element and its children. | 875 feed_elt.addElement('updated', rfc3339.timestamp_from_tf(rfc3339.tf_utc())) |
876 Without that, the entry would still be valid but not displayed | 876 |
877 by Firefox nor Thunderbird (and probably more readers)""" | 877 defer.returnValue(u'<?xml version="1.0" encoding="utf-8"?>'+feed_elt.toXml()) |
878 element.uri = element.defaultUri = None | |
879 for child in element.children: | |
880 if isinstance(child, domish.Element): | |
881 removeAllURIs(child) | |
882 | |
883 for item in items: | |
884 entry = item.firstChildElement() | |
885 removeAllURIs(entry) | |
886 feed += " " + entry.toXml() + "\n" | |
887 defer.returnValue(feed + "</feed>") | |
888 |