Skip to content

Commit

Permalink
Merge 10cf2a2 into 67cb86b
Browse files Browse the repository at this point in the history
  • Loading branch information
claytonc authored Sep 25, 2017
2 parents 67cb86b + 10cf2a2 commit 0352c55
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ There's a frood who really knows where his towel is.
- Update Basque translation.
[erral]

- Implement prefetch for Facebook.
[claytonc]


2.12b1 (2017-09-15)
^^^^^^^^^^^^^^^^^^^
Expand Down
11 changes: 11 additions & 0 deletions sc/social/like/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class ISocialLikeSettings(model.Schema):
'facebook_app_id',
'fbbuttons',
'fbshowlikes',
'facebook_prefetch_enable'
],
)

Expand Down Expand Up @@ -200,6 +201,16 @@ class ISocialLikeSettings(model.Schema):
default=True,
)

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,
)

model.fieldset(
'twitter', label=u'Twitter', fields=['twitter_username'])

Expand Down
9 changes: 9 additions & 0 deletions sc/social/like/locales/pt_BR/LC_MESSAGES/sc.social.like.po
Original file line number Diff line number Diff line change
Expand Up @@ -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."
8 changes: 8 additions & 0 deletions sc/social/like/locales/sc.social.like.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
2 changes: 1 addition & 1 deletion sc/social/like/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<metadata>
<version>3047</version>
<version>3048</version>
</metadata>
23 changes: 23 additions & 0 deletions sc/social/like/subscribers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from zope.component import getUtility
from zope.schema.interfaces import WrongType

import requests
import traceback


Expand Down Expand Up @@ -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=5,
verify=False)

if r.status_code == '200':
logger.info(u'Prefetching: ' + url)
else:
logger.warn(u'Prefetching fail')
5 changes: 5 additions & 0 deletions sc/social/like/tests/test_controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def test_twitter_username_record_in_registry(self):
self.assertTrue(hasattr(self.settings, 'twitter_username'))
self.assertEqual(self.settings.twitter_username, '')

def test_facebook_prefetch_enable_record_in_registry(self):
self.assertTrue(hasattr(self.settings, 'facebook_prefetch_enable'))
self.assertEqual(self.settings.facebook_prefetch_enable, False)

def test_records_removed_on_uninstall(self):
qi = self.portal['portal_quickinstaller']

Expand All @@ -126,6 +130,7 @@ def test_records_removed_on_uninstall(self):
ISocialLikeSettings.__identifier__ + '.fbbuttons',
ISocialLikeSettings.__identifier__ + '.fbshowlikes',
ISocialLikeSettings.__identifier__ + '.twitter_username',
ISocialLikeSettings.__identifier__ + '.facebook_prefetch_enable',
]

for r in records:
Expand Down
Empty file.
18 changes: 18 additions & 0 deletions sc/social/like/upgrades/v3048/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup">

<genericsetup:upgradeSteps
source="3047"
destination="3048"
profile="sc.social.like:default">

<genericsetup:upgradeDepends
title="Enable prefetch for Facebook"
description="Adds new field to the control panel configlet."
import_steps="plone.app.registry"
/>

</genericsetup:upgradeSteps>

</configure>
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
'Products.CMFPlone >=4.3',
'Products.CMFQuickInstallerTool',
'Products.GenericSetup',
'requests',
'setuptools',
'zope.component',
'zope.i18nmessageid',
Expand Down

0 comments on commit 0352c55

Please sign in to comment.