comparison src/plugins/plugin_misc_groupblog.py @ 832:c4b22aedb7d7

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)
author souliane <souliane@mailoo.org>
date Wed, 05 Feb 2014 16:36:51 +0100
parents d7f9cd8a08cd
children 071524bfcc7d
comparison
equal deleted inserted replaced
831:d7f9cd8a08cd 832:c4b22aedb7d7
274 - allow_comments: True to accept comments, False else (default: False) 274 - allow_comments: True to accept comments, False else (default: False)
275 - rich: if present, contain rich text in currently selected syntax 275 - rich: if present, contain rich text in currently selected syntax
276 """ 276 """
277 node_name = self.getNodeName(client.jid) 277 node_name = self.getNodeName(client.jid)
278 mblog_data = {'content': message} 278 mblog_data = {'content': message}
279 if 'rich' in extra: 279
280 mblog_data['rich'] = extra['rich'] 280 for attr in ['content_rich', 'title', 'title_rich']:
281 if attr in extra and extra[attr]:
282 mblog_data[attr] = extra[attr]
281 P = self.host.plugins["XEP-0060"] 283 P = self.host.plugins["XEP-0060"]
282 access_model_value = ACCESS_TYPE_MAP[access_type] 284 access_model_value = ACCESS_TYPE_MAP[access_type]
283 285
284 if extra.get('allow_comments', 'False').lower() == 'true': 286 if extra.get('allow_comments', 'False').lower() == 'true':
285 # XXX: use the item identifier? http://bugs.goffi.org/show_bug.cgi?id=63 287 # XXX: use the item identifier? http://bugs.goffi.org/show_bug.cgi?id=63
286 comments_node = "%s_%s__%s" % (NS_COMMENT_PREFIX, str(uuid.uuid4()), node_name) 288 comments_node = "%s_%s__%s" % (NS_COMMENT_PREFIX, str(uuid.uuid4()), node_name)
287 mblog_data['comments'] = "xmpp:%(service)s?%(query)s" % {'service': service.userhost(), 289 mblog_data['comments'] = "xmpp:%(service)s?%(query)s" % {'service': service.userhost(),
288 'query': urllib.urlencode([('node',comments_node.encode('utf-8'))])} 290 'query': urllib.urlencode([('node', comments_node.encode('utf-8'))])}
289 _options = {P.OPT_ACCESS_MODEL: access_model_value, 291 _options = {P.OPT_ACCESS_MODEL: access_model_value,
290 P.OPT_PERSIST_ITEMS: 1, 292 P.OPT_PERSIST_ITEMS: 1,
291 P.OPT_MAX_ITEMS: -1, 293 P.OPT_MAX_ITEMS: -1,
292 P.OPT_DELIVER_PAYLOADS: 1, 294 P.OPT_DELIVER_PAYLOADS: 1,
293 P.OPT_SEND_ITEM_SUBSCRIBE: 1, 295 P.OPT_SEND_ITEM_SUBSCRIBE: 1,
294 P.OPT_PUBLISH_MODEL: "subscribers", #TODO: should be open if *both* node and item access_model are open (public node and item) 296 P.OPT_PUBLISH_MODEL: "subscribers", # TODO: should be open if *both* node and item access_model are open (public node and item)
295 } 297 }
296 if access_model_value == 'roster': 298 if access_model_value == 'roster':
297 _options[P.OPT_ROSTER_GROUPS_ALLOWED] = list(access_list) 299 _options[P.OPT_ROSTER_GROUPS_ALLOWED] = list(access_list)
298 300
299 # FIXME: check comments node creation success, at the moment this is a potential security risk (if the node 301 # FIXME: check comments node creation success, at the moment this is a potential security risk (if the node
323 325
324 defer_blog = self.host.plugins["XEP-0060"].publish(service, node_name, items=[mblog_item], profile_key=client.profile) 326 defer_blog = self.host.plugins["XEP-0060"].publish(service, node_name, items=[mblog_item], profile_key=client.profile)
325 defer_blog.addErrback(self._mblogPublicationFailed) 327 defer_blog.addErrback(self._mblogPublicationFailed)
326 return defer_blog 328 return defer_blog
327 329
328 entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, client.profile) 330 entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, client.profile)
329 entry_d.addCallback(itemCreated) 331 entry_d.addCallback(itemCreated)
330 return entry_d 332 return entry_d
331 333
332 def _mblogPublicationFailed(self, failure): 334 def _mblogPublicationFailed(self, failure):
333 #TODO 335 #TODO
410 """ 412 """
411 413
412 def initialised(result): 414 def initialised(result):
413 profile, client = result 415 profile, client = result
414 mblog_data = {'content': message} 416 mblog_data = {'content': message}
415 if 'rich' in extra: 417 for attr in ['content_rich', 'title', 'title_rich']:
416 mblog_data['rich'] = extra['rich'] 418 if attr in extra and extra[attr]:
419 mblog_data[attr] = extra[attr]
417 service, node, item_id = pub_data 420 service, node, item_id = pub_data
418 if comments: 421 if comments:
419 node = self.getNodeName(client.jid) 422 node = self.getNodeName(client.jid)
420 mblog_data['id'] = str(item_id) 423 mblog_data['id'] = str(item_id)
421 if 'published' in extra: 424 if 'published' in extra:
446 """ 449 """
447 def initialised(result): 450 def initialised(result):
448 profile, client = result 451 profile, client = result
449 service, node = self.host.plugins["XEP-0277"].parseCommentUrl(node_url) 452 service, node = self.host.plugins["XEP-0277"].parseCommentUrl(node_url)
450 mblog_data = {'content': message} 453 mblog_data = {'content': message}
451 if 'rich' in extra: 454 for attr in ['content_rich', 'title', 'title_rich']:
452 mblog_data['rich'] = extra['rich'] 455 if attr in extra and extra[attr]:
456 mblog_data[attr] = extra[attr]
453 if 'allow_comments' in extra: 457 if 'allow_comments' in extra:
454 raise NotImplementedError # TODO 458 raise NotImplementedError # TODO
455 entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, profile) 459 entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, profile)
456 entry_d.addCallback(lambda mblog_item: self.host.plugins["XEP-0060"].publish(service, node, items=[mblog_item], profile_key=profile)) 460 entry_d.addCallback(lambda mblog_item: self.host.plugins["XEP-0060"].publish(service, node, items=[mblog_item], profile_key=profile))
457 return entry_d 461 return entry_d