diff --git a/sc/social/like/interfaces.py b/sc/social/like/interfaces.py index 2f84d086..bf13a313 100644 --- a/sc/social/like/interfaces.py +++ b/sc/social/like/interfaces.py @@ -212,3 +212,16 @@ class ISocialLikeSettings(model.Schema): required=False, default='', ) + + model.fieldset( + 'open_graph', label=u'Open Graph', fields=['facebook_prefetch_enable']) + + facebook_prefetch_enable = schema.Bool( + title=_(u'Enable Prefetching Facebook?'), + description=_( + u'help_facebook_prefetch_enable', + default=u'If enabled, an event is triggered so that Facebook ' + u'downloads mobile content before someone clicks on a link.' + ), + default=False, + ) diff --git a/sc/social/like/locales/pt_BR/LC_MESSAGES/sc.social.like.po b/sc/social/like/locales/pt_BR/LC_MESSAGES/sc.social.like.po index bb449ca6..cefb2c06 100644 --- a/sc/social/like/locales/pt_BR/LC_MESSAGES/sc.social.like.po +++ b/sc/social/like/locales/pt_BR/LC_MESSAGES/sc.social.like.po @@ -422,3 +422,12 @@ msgstr "Cancelar" #: sc/social/like/vocabularies.py:36 msgid "vertical" msgstr "vertical" + + +#: ./sc/social/like/interfaces.py:220 +msgid "Enable Prefetching Facebook?" +msgstr "" + +#: ./sc/social/like/interfaces.py:222 +msgid "help_facebook_prefetch_enable" +msgstr "Se ativado, um evento é acionado para que o Facebook faça o download de conteúdo móvel antes de alguém clicar em um link." \ No newline at end of file diff --git a/sc/social/like/locales/sc.social.like.pot b/sc/social/like/locales/sc.social.like.pot index 4dcc3c92..052cbb02 100644 --- a/sc/social/like/locales/sc.social.like.pot +++ b/sc/social/like/locales/sc.social.like.pot @@ -422,3 +422,11 @@ msgstr "" #: ./sc/social/like/vocabularies.py:36 msgid "vertical" msgstr "" + +#: ./sc/social/like/interfaces.py:220 +msgid "Enable Prefetching Facebook?" +msgstr "" + +#: ./sc/social/like/interfaces.py:222 +msgid "help_facebook_prefetch_enable" +msgstr "" diff --git a/sc/social/like/subscribers.py b/sc/social/like/subscribers.py index 9e860ed1..52d09fd8 100644 --- a/sc/social/like/subscribers.py +++ b/sc/social/like/subscribers.py @@ -26,6 +26,7 @@ from zope.component import getUtility from zope.schema.interfaces import WrongType +import requests import traceback @@ -148,9 +149,31 @@ def check_sharing_best_practices_on_editing(obj, event): state = api.content.get_state(obj) if state in ('published', ): check_sharing_best_practices(obj) + prefetch_facebook(obj) def check_sharing_best_practices_on_publishing(obj, event): """Event subscriber for content being published.""" if event.status['review_state'] in ('published', ): check_sharing_best_practices(obj) + prefetch_facebook(obj) + + +def prefetch_facebook(obj): + """Prefetching in object if enable.""" + + record = ISocialLikeSettings.__identifier__ + '.facebook_prefetch_enable' + prefetch_enable = api.portal.get_registry_record(record, default=False) + + if not prefetch_enable: + return + + url = obj.absolute_url() + r = requests.post('https://graph.facebook.com/?id=' + url + '&scrape=true', + timeout=10, + verify=False) + + if r.status_code == '200': + logger.info(u'Prefetching: ' + url) + else: + logger.warn(u'Prefetching fail') diff --git a/setup.py b/setup.py index 65d1eed9..9f8d1fdf 100644 --- a/setup.py +++ b/setup.py @@ -52,6 +52,7 @@ 'Products.CMFPlone >=4.3', 'Products.CMFQuickInstallerTool', 'Products.GenericSetup', + 'requests', 'setuptools', 'zope.component', 'zope.i18nmessageid',