plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:

Implementation should follow the following formal specification:

"title" and "content" data can be passed in raw, xhtml or rich format.
When we receive from a frontend a new/updated microblog item:

- keys "title" or "content" have to be escaped (disable HTML tags)
- keys "title_rich" or "content_rich" have to be converted from the current syntax to XHTML
- keys "title_xhtml" or "content_xhtml" have to be cleaned from unwanted XHTML content

Rules to deal with concurrent keys:

- existence of both  "*_xhtml" and "*_rich" keys must raise an exception
- existence of both raw and ("*_xhtml" or "*_rich") is OK

As the storage always need raw data, if it is not given by the user it can be
extracted from the "*_rich" or "*_xhtml" data (remove the XHTML tags).

When a frontend wants to edit a blog post that contains XHTML title or content,
the conversion is made from XHTML to the current user-defined syntax.

- plugin text_syntaxes: added "text" syntax (using lxml)
This commit is contained in:
souliane 2014-02-05 16:36:51 +01:00
commit ff81f76184

View file

@ -276,8 +276,10 @@ class GroupBlog(object):
"""
node_name = self.getNodeName(client.jid)
mblog_data = {'content': message}
if 'rich' in extra:
mblog_data['rich'] = extra['rich']
for attr in ['content_rich', 'title', 'title_rich']:
if attr in extra and extra[attr]:
mblog_data[attr] = extra[attr]
P = self.host.plugins["XEP-0060"]
access_model_value = ACCESS_TYPE_MAP[access_type]
@ -285,13 +287,13 @@ class GroupBlog(object):
# XXX: use the item identifier? http://bugs.goffi.org/show_bug.cgi?id=63
comments_node = "%s_%s__%s" % (NS_COMMENT_PREFIX, str(uuid.uuid4()), node_name)
mblog_data['comments'] = "xmpp:%(service)s?%(query)s" % {'service': service.userhost(),
'query': urllib.urlencode([('node',comments_node.encode('utf-8'))])}
'query': urllib.urlencode([('node', comments_node.encode('utf-8'))])}
_options = {P.OPT_ACCESS_MODEL: access_model_value,
P.OPT_PERSIST_ITEMS: 1,
P.OPT_MAX_ITEMS: -1,
P.OPT_DELIVER_PAYLOADS: 1,
P.OPT_SEND_ITEM_SUBSCRIBE: 1,
P.OPT_PUBLISH_MODEL: "subscribers", #TODO: should be open if *both* node and item access_model are open (public node and item)
P.OPT_PUBLISH_MODEL: "subscribers", # TODO: should be open if *both* node and item access_model are open (public node and item)
}
if access_model_value == 'roster':
_options[P.OPT_ROSTER_GROUPS_ALLOWED] = list(access_list)
@ -325,7 +327,7 @@ class GroupBlog(object):
defer_blog.addErrback(self._mblogPublicationFailed)
return defer_blog
entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, client.profile)
entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, client.profile)
entry_d.addCallback(itemCreated)
return entry_d
@ -412,8 +414,9 @@ class GroupBlog(object):
def initialised(result):
profile, client = result
mblog_data = {'content': message}
if 'rich' in extra:
mblog_data['rich'] = extra['rich']
for attr in ['content_rich', 'title', 'title_rich']:
if attr in extra and extra[attr]:
mblog_data[attr] = extra[attr]
service, node, item_id = pub_data
if comments:
node = self.getNodeName(client.jid)
@ -448,8 +451,9 @@ class GroupBlog(object):
profile, client = result
service, node = self.host.plugins["XEP-0277"].parseCommentUrl(node_url)
mblog_data = {'content': message}
if 'rich' in extra:
mblog_data['rich'] = extra['rich']
for attr in ['content_rich', 'title', 'title_rich']:
if attr in extra and extra[attr]:
mblog_data[attr] = extra[attr]
if 'allow_comments' in extra:
raise NotImplementedError # TODO
entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, profile)