def add_as_tinymce_linkable(setup_tool): """Add Embedder to TinyMCE's list of linkable content types.""" tinymce_tool = api.portal.get_tool('portal_tinymce') linkable = tinymce_tool.linkable.split('\n') linkable.append('sc.embedder') tinymce_tool.linkable = '\n'.join(linkable) assert 'sc.embedder' in tinymce_tool.linkable.split('\n') logger.info("sc.embedder added to TinyMCE's list of linkable content types.")
def remove_videojs_resources(setup_tool): """Remove Video.js from resource registries.""" css_tool = api.portal.get_tool('portal_css') css_tool.unregisterResource(REMOVE_CSS) logger.info('Video.js was removed from portal_css.') js_tool = api.portal.get_tool('portal_javascripts') js_tool.unregisterResource(REMOVE_JS) logger.info('Video.js was removed from portal_javascripts.')
def add_relateditems_behavior(setup_tool): """Add Related Items behavior to Embedder content type.""" from plone.app.relationfield.behavior import IRelatedItems from plone.dexterity.interfaces import IDexterityFTI from zope.component import getUtility fti = getUtility(IDexterityFTI, name='sc.embedder') if IRelatedItems.__identifier__ not in fti.behaviors: fti.behaviors += (IRelatedItems.__identifier__,) logger.info('IRelatedItems behavior added to content type')
def remove_dexteritytextindexer_behavior(setup_tool): """Remove IDexterityTextIndexer behavior to Embedder content type.""" from plone.dexterity.interfaces import IDexterityFTI from zope.component import getUtility fti = getUtility(IDexterityFTI, name='sc.embedder') behaviors = list(fti.behaviors) if BEHAVIOR in behaviors: behaviors.remove(BEHAVIOR) fti.behaviors = tuple(behaviors) logger.info('IDexterityTextIndexer behavior removed from content type')
def sanitize_iframe_tags(setup_tool): """Remove invalid attributes from iframes.""" logger.info('Sanitizing iframes from embedded code') catalog = api.portal.get_tool('portal_catalog') query = dict(object_provides=IEmbedder.__identifier__) results = catalog.unrestrictedSearchResults(**query) for brain in results: obj = brain.getObject() obj.embed_html = sanitize_iframe_tag(obj.embed_html) logger.info('{0} objects were processed'.format(len(results)))
def sanitize_iframe_tags(setup_tool): """Remove invalid attributes from iframes.""" logger.info('Sanitizing iframes from embedded code') catalog = api.portal.get_tool('portal_catalog') query = dict(object_provides=IEmbedder.__identifier__) results = catalog.unrestrictedSearchResults(**query) for brain in results: obj = brain.getObject() try: obj.embed_html = sanitize_iframe_tag(obj.embed_html) except TypeError: # pragma: no cover msg = 'An error ocurred sanitizing object: {0}; skipping' logger.error(msg.format(obj.absolute_url())) logger.info('{0} objects were processed'.format(len(results)))
def get_data(self, url, maxwidth=None, maxheight=None, format='json'): """Return the data provided by the endpoint.""" self.initialize_consumer() request = {} if maxwidth is not None: request['maxwidth'] = maxwidth if maxheight is not None: request['maxheight'] = maxheight request['format'] = format try: response = self.consumer.embed(url, **request) return response.getData() except oembed.OEmbedNoEndpoint, e: logger.info(e)
def setup_portal_transforms(context): if not context.readDataFile('sc.embedder-default.txt'): return logger.info('Updating portal_transform safe_html settings') tid = 'safe_html' pt = api.portal.get_tool('portal_transforms') if tid not in pt.objectIds(): return trans = pt[tid] tconfig = trans._config tconfig['valid_tags']['iframe'] = '1' make_config_persistent(tconfig) trans._p_changed = True trans.reload()
def reindex_searchable_text(setup_tool): """Reindex embedders to fix SearchableText.""" logger.info('Reindexing the catalog') catalog = api.portal.get_tool('portal_catalog') results = catalog(portal_type='sc.embedder') logger.info(u'Found {0} embedders'.format(len(results))) for n, obj in enumerate(get_valid_objects(results), start=1): catalog.catalog_object(obj, idxs=['SearchableText']) if n % 1000 == 0: transaction.commit() logger.info('{0} items processed.'.format(n)) transaction.commit() logger.info('Done.')
class Consumer(object): """oEmbed consumer utility.""" def __init__(self): self.consumer = None def get_data(self, url, maxwidth=None, maxheight=None, format='json'): """Return the data provided by the endpoint.""" self.initialize_consumer() request = {} if maxwidth is not None: request['maxwidth'] = maxwidth if maxheight is not None: request['maxheight'] = maxheight request['format'] = format try: response = self.consumer.embed(url, **request) return response.getData() except oembed.OEmbedNoEndpoint, e: logger.info(e) except oembed.OEmbedError, e: # often a mimetype error logger.info(e)
def cook_css_resources(context): """Cook css resources.""" css_tool = api.portal.get_tool('portal_css') css_tool.cookResources() logger.info('CSS resources were cooked')
def add_tile(setup_tool): """Update control panel options.""" profile = 'profile-{0}:default'.format(PROJECTNAME) setup_tool.runImportStepFromProfile(profile, 'plone.app.registry') logger.info('Added collective.cover tile for sc.embedder content type.')
def cook_javascript_resources(context): """Cook javascript resources.""" js_tool = api.portal.get_tool('portal_javascripts') js_tool.cookResources() logger.info('Javascript resources were cooked')
def cook_css_resources(context): # pragma: no cover """Cook CSS resources.""" css_tool = api.portal.get_tool('portal_css') css_tool.cookResources() logger.info('CSS resources were cooked')
def cook_javascript_resources(context): # pragma: no cover """Cook JavaScript resources.""" js_tool = api.portal.get_tool('portal_javascripts') js_tool.cookResources() logger.info('Javascript resources were cooked')