diff --git a/CHANGES.rst b/CHANGES.rst
index 0ea47fc9..cb9955db 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -6,7 +6,8 @@ There's a frood who really knows where his towel is.
2.4.2 (unreleased)
^^^^^^^^^^^^^^^^^^
-- Nothing changed yet.
+- Use Plone's registry instead of the ``portal_properties`` tool to store package configuration (closes `#1`_).
+ [hvelarde]
2.4.1 (2015-12-10)
@@ -276,6 +277,7 @@ There's a frood who really knows where his towel is.
* Initial release [cleberjsantos]
+.. _`#1`: https://github.com/collective/sc.social.like/issues/1
.. _`#15`: https://github.com/collective/sc.social.like/pull/15
.. _`#36`: https://github.com/collective/sc.social.like/issues/36
.. _`#38`: https://github.com/collective/sc.social.like/issues/38
diff --git a/sc/social/like/Extensions/Install.py b/sc/social/like/Extensions/Install.py
index 45523398..cd1db2b4 100644
--- a/sc/social/like/Extensions/Install.py
+++ b/sc/social/like/Extensions/Install.py
@@ -3,17 +3,8 @@
from plone import api
-def remove_properties(portal):
- portal_properties = api.portal.get_tool(name='portal_properties')
- try:
- portal_properties.manage_delObjects(ids='sc_social_likes_properties')
- except KeyError:
- pass
-
-
def uninstall(portal, reinstall=False):
if not reinstall:
- remove_properties(portal)
profile = 'profile-%s:uninstall' % PROJECTNAME
setup_tool = api.portal.get_tool(name='portal_setup')
setup_tool.runAllImportStepsFromProfile(profile)
diff --git a/sc/social/like/browser/configure.zcml b/sc/social/like/browser/configure.zcml
index 36bc5760..9e5d9d4b 100644
--- a/sc/social/like/browser/configure.zcml
+++ b/sc/social/like/browser/configure.zcml
@@ -61,4 +61,11 @@
permission="zope.Public"
/>
+
+
diff --git a/sc/social/like/browser/helper.py b/sc/social/like/browser/helper.py
index cc3feaf4..5dd69bd7 100644
--- a/sc/social/like/browser/helper.py
+++ b/sc/social/like/browser/helper.py
@@ -1,15 +1,16 @@
# -*- coding: utf-8 -*-
-
from Acquisition import aq_inner
-from Products.Five import BrowserView
from plone.app.layout.globals.interfaces import IViewView
from plone.memoize.view import memoize
from plone.memoize.view import memoize_contextless
-from sc.social.like.controlpanel.likes import LikeControlPanelAdapter
+from plone.registry.interfaces import IRegistry
+from Products.Five import BrowserView
+from sc.social.like.interfaces import ISocialLikeSettings
from sc.social.like.interfaces import IHelperView
from sc.social.like.plugins import IPlugin
from zope.component import getMultiAdapter
from zope.component import getUtilitiesFor
+from zope.component import getUtility
from zope.interface import implements
@@ -30,8 +31,9 @@ def __init__(self, context, request, *args, **kwargs):
@memoize_contextless
def configs(self):
- adapter = LikeControlPanelAdapter(self.portal)
- return adapter
+ registry = getUtility(IRegistry)
+ settings = registry.forInterface(ISocialLikeSettings)
+ return settings
@memoize_contextless
def enabled_portal_types(self):
diff --git a/sc/social/like/browser/socialikes.py b/sc/social/like/browser/socialikes.py
index 1cea0023..93518652 100644
--- a/sc/social/like/browser/socialikes.py
+++ b/sc/social/like/browser/socialikes.py
@@ -1,38 +1,27 @@
# -*- coding: utf-8 -*-
-from Acquisition import aq_inner
+from plone import api
+from plone.api.exc import InvalidParameterError
from Products.Five import BrowserView
-from Products.CMFCore.utils import getToolByName
-
-from zope.interface import implements
-from zope.i18nmessageid import MessageFactory
-
+from sc.social.like.interfaces import ISocialLikeSettings
from sc.social.like.interfaces import ISocialLikes
-
-_ = MessageFactory('sc.social.like')
+from zope.interface import implements
class SocialLikes(BrowserView):
- """
- """
- implements(ISocialLikes)
- enabled_portal_types = []
+ implements(ISocialLikes)
- def __init__(self, context, request, *args, **kwargs):
- super(SocialLikes, self).__init__(context, request, *args, **kwargs)
- context = aq_inner(context)
+ def __init__(self, context, request):
self.context = context
- pp = getToolByName(context, 'portal_properties')
- self.sheet = getattr(pp, 'sc_social_likes_properties', None)
- if self.sheet:
- self.enabled_portal_types = self.sheet.getProperty(
- 'enabled_portal_types'
- )
+ self.request = request
@property
def enabled(self):
- """Validates if social bookmarks should be enabled
- for this context"""
- context = self.context
- enabled_portal_types = self.enabled_portal_types
- return context.portal_type in enabled_portal_types
+ """Validates if social bookmarks should be enabled in this context."""
+ record = ISocialLikeSettings.__identifier__ + '.enabled_portal_types'
+ try:
+ enabled_portal_types = api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ enabled_portal_types = []
+
+ return self.context.portal_type in enabled_portal_types
diff --git a/sc/social/like/browser/viewlets.py b/sc/social/like/browser/viewlets.py
index bfc1e346..19f21a34 100644
--- a/sc/social/like/browser/viewlets.py
+++ b/sc/social/like/browser/viewlets.py
@@ -1,8 +1,11 @@
# -*- coding:utf-8 -*-
+from plone import api
+from plone.api.exc import InvalidParameterError
from plone.app.layout.viewlets import ViewletBase
+from plone.memoize.view import memoize
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
+from sc.social.like.interfaces import ISocialLikeSettings
from zope.component import getMultiAdapter
-from plone.memoize.view import memoize
class BaseLikeViewlet(ViewletBase):
@@ -74,17 +77,19 @@ class SocialLikesViewlet(BaseLikeViewlet):
@property
def render_method(self):
- tools = getMultiAdapter((self.context, self.request),
- name=u'plone_tools')
- site_properties = tools.properties()
# global cookie settings for privacy level
if self.request.cookies.get('social-optout', None) == 'true' or \
self.request.get_header('HTTP_DNT') == '1':
return 'link'
+
# site specific privacy level check
- if getattr(site_properties, 'sc_social_likes_properties', None) \
- and getattr(site_properties.sc_social_likes_properties,
- 'do_not_track', None) and \
- site_properties.sc_social_likes_properties.do_not_track:
+ record = ISocialLikeSettings.__identifier__ + '.do_not_track'
+ try:
+ do_not_track = api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ do_not_track = False
+
+ if do_not_track:
return 'link'
+
return 'plugin'
diff --git a/sc/social/like/config.py b/sc/social/like/config.py
index e22edcf4..c5465115 100644
--- a/sc/social/like/config.py
+++ b/sc/social/like/config.py
@@ -5,3 +5,6 @@
__docformat__ = 'plaintext'
PROJECTNAME = 'sc.social.like'
+
+DEFAULT_ENABLED_CONTENT_TYPES = ('Document', 'Event', 'News Item')
+DEFAULT_PLUGINS_ENABLED = ('Facebook', 'Twitter')
diff --git a/sc/social/like/configure.zcml b/sc/social/like/configure.zcml
index c7c8ee1c..9620fc5e 100644
--- a/sc/social/like/configure.zcml
+++ b/sc/social/like/configure.zcml
@@ -7,11 +7,10 @@
-
+
-
diff --git a/sc/social/like/controlpanel.py b/sc/social/like/controlpanel.py
new file mode 100644
index 00000000..82c77fd5
--- /dev/null
+++ b/sc/social/like/controlpanel.py
@@ -0,0 +1,20 @@
+# -*- coding:utf-8 -*-
+from plone.app.registry.browser import controlpanel
+from sc.social.like import LikeMessageFactory as _
+from sc.social.like.interfaces import ISocialLikeSettings
+
+
+class SocialLikeSettingsEditForm(controlpanel.RegistryEditForm):
+
+ """Control panel edit form."""
+
+ schema = ISocialLikeSettings
+ label = _(u'Social Like')
+ description = _(u'Settings for the sc.social.like package')
+
+
+class SocialLikeSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
+
+ """Control panel form wrapper."""
+
+ form = SocialLikeSettingsEditForm
diff --git a/sc/social/like/controlpanel/__init__.py b/sc/social/like/controlpanel/__init__.py
deleted file mode 100644
index 40a96afc..00000000
--- a/sc/social/like/controlpanel/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-# -*- coding: utf-8 -*-
diff --git a/sc/social/like/controlpanel/configure.zcml b/sc/social/like/controlpanel/configure.zcml
deleted file mode 100644
index 2630d71f..00000000
--- a/sc/social/like/controlpanel/configure.zcml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
diff --git a/sc/social/like/controlpanel/likes.pt b/sc/social/like/controlpanel/likes.pt
deleted file mode 100644
index 426e7657..00000000
--- a/sc/social/like/controlpanel/likes.pt
+++ /dev/null
@@ -1,171 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
- Info
-
-
-
-
-
-
- Site Setup
-
-
-
- Do something
-
-
-
- Description
-
-
-
-
-
-
-
-
-
-
-
diff --git a/sc/social/like/controlpanel/likes.py b/sc/social/like/controlpanel/likes.py
deleted file mode 100644
index 9581ee0c..00000000
--- a/sc/social/like/controlpanel/likes.py
+++ /dev/null
@@ -1,134 +0,0 @@
-# -*- coding:utf-8 -*-
-
-from Acquisition import aq_inner
-from Products.CMFDefault.formlib.schema import ProxyFieldProperty as PFP
-from Products.CMFDefault.formlib.schema import SchemaAdapterBase
-from Products.CMFPlone.interfaces import IPloneSiteRoot
-from Products.CMFPlone.utils import getToolByName
-from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
-from plone.app.controlpanel.form import ControlPanelForm
-from sc.social.like import LikeMessageFactory as _
-from sc.social.like.plugins import IPlugin
-from zope import schema
-from zope.app.form.browser import itemswidgets
-from zope.component import adapts
-from zope.component import getUtilitiesFor
-from zope.formlib.form import FormFields
-from zope.interface import Interface
-from zope.interface import implements
-from zope.schema.vocabulary import SimpleTerm
-from zope.schema.vocabulary import SimpleVocabulary
-
-CONTENT_TYPES = 'plone.app.vocabularies.ReallyUserFriendlyTypes'
-
-
-class MultiSelectWidget(itemswidgets.MultiSelectWidget):
- """ """
- def __init__(self, field, request):
- """Initialize the widget."""
- super(MultiSelectWidget, self).__init__(field,
- field.value_type.vocabulary,
- request)
-
-
-styles = SimpleVocabulary([
- SimpleTerm(value=u'horizontal', title=_(u'horizontal')),
- SimpleTerm(value=u'vertical', title=_(u'vertical')),
-])
-
-
-class IProvidersSchema(Interface):
- """ General Configurations """
-
- enabled_portal_types = schema.Tuple(
- title=_(u'Content types'),
- description=_(
- u'help_portal_types',
- default=u'Please select content types in which the '
- u'viewlet will be applied.',
- ),
- required=True,
- value_type=schema.Choice(vocabulary=CONTENT_TYPES)
- )
-
- plugins_enabled = schema.Tuple(
- title=_(u'Plugins'),
- description=_(
- u'help_enabled_plugins',
- default=u'Please select which plugins will be used',
- ),
- required=False,
- value_type=schema.Choice(vocabulary='sc.social.likes.plugins')
- )
-
- typebutton = schema.Choice(
- title=_(u'Button style'),
- description=_(
- u'help_selected_buttons',
- default=u'Choose your button style.',
- ),
- required=True,
- default=_(u'horizontal'),
- vocabulary=styles,
- )
-
- do_not_track = schema.Bool(
- title=_(u'Do not track users'),
- description=_(
- u'help_do_not_track',
- default=u'If enabled, the site will not provide advanced sharing '
- u'widgets , instead simple links will be used.\n'
- u'This will limits user experience and features '
- u'(like the share count) but will enhance users privacy: '
- u'no 3rd party cookies will be sent to users.'
- ),
- default=False,
- )
-
-
-class BaseControlPanelAdapter(SchemaAdapterBase):
- """ Base control panel adapter """
-
- def __init__(self, context):
- super(BaseControlPanelAdapter, self).__init__(context)
- portal_properties = getToolByName(context, 'portal_properties')
- self.context = portal_properties.get('sc_social_likes_properties', None)
-
-
-class LikeControlPanelAdapter(BaseControlPanelAdapter):
- """ Like control panel adapter """
- adapts(IPloneSiteRoot)
- implements(IProvidersSchema)
-
- enabled_portal_types = PFP(IProvidersSchema['enabled_portal_types'])
- typebutton = PFP(IProvidersSchema['typebutton'])
- plugins_enabled = PFP(IProvidersSchema['plugins_enabled'])
- do_not_track = PFP(IProvidersSchema['do_not_track'])
-
-
-class ProvidersControlPanel(ControlPanelForm):
- """ """
- template = ViewPageTemplateFile('likes.pt')
- form_fields = FormFields(IProvidersSchema)
-
- form_fields['enabled_portal_types'].custom_widget = MultiSelectWidget
- form_fields['plugins_enabled'].custom_widget = MultiSelectWidget
-
- label = _('Social: Like Actions settings')
- description = _('Configure settings for social like actions.')
- form_name = _('Social: Like Actions')
-
- def plugins_configs(self):
- """ Return Plugins and their configuration pages """
- context = aq_inner(self.context)
- portal_url = getToolByName(context, 'portal_url')()
- registered = dict(getUtilitiesFor(IPlugin))
- plugins = []
- for name in registered:
- plugin = registered[name]
- config_view = plugin.config_view()
- if config_view:
- url = '%s/%s' % (portal_url, config_view)
- plugins.append({'name': name,
- 'url': url})
- return plugins
diff --git a/sc/social/like/docs/__init__.py b/sc/social/like/docs/__init__.py
deleted file mode 100644
index 792d6005..00000000
--- a/sc/social/like/docs/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-#
diff --git a/sc/social/like/docs/browser.txt b/sc/social/like/docs/browser.txt
deleted file mode 100644
index bd12ee63..00000000
--- a/sc/social/like/docs/browser.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-Accessing as portal owner
--------------------------
-
- >>> from Products.Five.testbrowser import Browser
- >>> from Testing.ZopeTestCase import user_password
- >>> browser = Browser()
- >>> browser.addHeader('Authorization',
- ... 'Basic %s:%s' % ('portal_owner', user_password))
diff --git a/sc/social/like/interfaces.py b/sc/social/like/interfaces.py
new file mode 100644
index 00000000..0ba8b84c
--- /dev/null
+++ b/sc/social/like/interfaces.py
@@ -0,0 +1,169 @@
+# -*- coding:utf-8 -*-
+from plone.supermodel import model
+from sc.social.like import LikeMessageFactory as _
+from sc.social.like.config import DEFAULT_ENABLED_CONTENT_TYPES
+from sc.social.like.config import DEFAULT_PLUGINS_ENABLED
+from sc.social.like.vocabularies import FacebookButtonsVocabulary
+from sc.social.like.vocabularies import FacebookVerbsVocabulary
+from sc.social.like.vocabularies import TypeButtonVocabulary
+from zope import schema
+from zope.interface import Interface
+
+
+class ISocialLikeLayer(Interface):
+ """
+ """
+
+
+class ISocialLikes(Interface):
+ """
+ """
+
+
+class IHelperView(Interface):
+ """
+ """
+ def configs():
+ """ Social Like configuration """
+
+ def enabled_portal_types():
+ """ Portal Types that will display our viewlet """
+
+ def plugins_enabled():
+ """ List of plugins enabled """
+
+ def typebutton():
+ """ Button to be used """
+
+ def enabled(view):
+ """
+ Social Like is enabled for this context and provided view
+ (when provided)
+ """
+
+ def available_plugins():
+ """ Return available plugins """
+
+ def plugins():
+ """ Return enabled plugins """
+
+ def view_template_id():
+ """ View or template id for this context """
+
+
+class ISocialLikeSettings(model.Schema):
+
+ """Schema for the control panel form."""
+
+ enabled_portal_types = schema.Tuple(
+ title=_(u'Content types'),
+ description=_(
+ u'help_portal_types',
+ default=u'Please select content types in which the '
+ u'viewlet will be applied.',
+ ),
+ required=True,
+ default=DEFAULT_ENABLED_CONTENT_TYPES,
+ value_type=schema.Choice(
+ vocabulary='plone.app.vocabularies.ReallyUserFriendlyTypes')
+ )
+
+ plugins_enabled = schema.Tuple(
+ title=_(u'Plugins'),
+ description=_(
+ u'help_enabled_plugins',
+ default=u'Please select which plugins will be used',
+ ),
+ required=False,
+ default=DEFAULT_PLUGINS_ENABLED,
+ value_type=schema.Choice(vocabulary='sc.social.likes.plugins')
+ )
+
+ typebutton = schema.Choice(
+ title=_(u'Button style'),
+ description=_(
+ u'help_selected_buttons',
+ default=u'Choose your button style.',
+ ),
+ required=True,
+ default=u'horizontal',
+ vocabulary=TypeButtonVocabulary,
+ )
+
+ do_not_track = schema.Bool(
+ title=_(u'Do not track users'),
+ description=_(
+ u'help_do_not_track',
+ default=u'If enabled, the site will not provide advanced sharing '
+ u'widgets , instead simple links will be used.\n'
+ u'This will limits user experience and features '
+ u'(like the share count) but will enhance users privacy: '
+ u'no 3rd party cookies will be sent to users.'
+ ),
+ default=False,
+ )
+
+ model.fieldset(
+ 'facebook',
+ label=u'Facebook',
+ fields=['fbaction', 'facebook_username', 'facebook_app_id', 'fbbuttons'],
+ )
+
+ fbaction = schema.Choice(
+ title=_(u'Verb to display'),
+ description=_(
+ u'help_verb_display',
+ default=u'The verb to display in the facebook button. '
+ u'Currently only "like" and "recommend" are '
+ u'supported.',
+ ),
+ required=True,
+ default=u'like',
+ vocabulary=FacebookVerbsVocabulary,
+ )
+
+ facebook_username = schema.ASCIILine(
+ title=_(u'Admins'),
+ description=_(
+ u'help_admins',
+ default=u'A comma-separated list of either the '
+ u'Facebook IDs of page administrators.',
+ ),
+ required=False,
+ default='',
+ )
+
+ facebook_app_id = schema.ASCIILine(
+ title=_(u'Application ID'),
+ description=_(
+ u'help_appid',
+ default=u'A Facebook Platform application ID.\n'
+ u'This is required when \"Do not track users\" option is enabled.',
+ ),
+ required=False,
+ default='',
+ )
+
+ fbbuttons = schema.Tuple(
+ title=_(u'Facebook buttons'),
+ description=_(
+ u'help_fbbuttons',
+ default=u'Select buttons to be shown',
+ ),
+ value_type=schema.Choice(vocabulary=FacebookButtonsVocabulary),
+ required=True,
+ default=(u'Like', ),
+ )
+
+ model.fieldset(
+ 'twitter', label=u'Twitter', fields=['twitter_username'])
+
+ twitter_username = schema.ASCIILine(
+ title=_(u'Twitter nick'),
+ description=_(
+ u'help_your_twitter_nick',
+ default=u'Enter your twitter nick. eg. simplesconsultoria',
+ ),
+ required=False,
+ default='',
+ )
diff --git a/sc/social/like/interfaces/__init__.py b/sc/social/like/interfaces/__init__.py
deleted file mode 100644
index 02662a9a..00000000
--- a/sc/social/like/interfaces/__init__.py
+++ /dev/null
@@ -1,5 +0,0 @@
-# flake8: noqa
-
-from socialikes import IHelperView
-from socialikes import ISocialLikeLayer
-from socialikes import ISocialLikes
diff --git a/sc/social/like/interfaces/socialikes.py b/sc/social/like/interfaces/socialikes.py
deleted file mode 100644
index 207ac79b..00000000
--- a/sc/social/like/interfaces/socialikes.py
+++ /dev/null
@@ -1,45 +0,0 @@
-# -*- coding:utf-8 -*-
-from zope.interface import Interface
-from zope.i18nmessageid import MessageFactory
-_ = MessageFactory('sc.social.like')
-
-
-class ISocialLikeLayer(Interface):
- """
- """
-
-
-class ISocialLikes(Interface):
- """
- """
-
-
-class IHelperView(Interface):
- """
- """
- def configs():
- """ Social Like configuration """
-
- def enabled_portal_types():
- """ Portal Types that will display our viewlet """
-
- def plugins_enabled():
- """ List of plugins enabled """
-
- def typebutton():
- """ Button to be used """
-
- def enabled(view):
- """
- Social Like is enabled for this context and provided view
- (when provided)
- """
-
- def available_plugins():
- """ Return available plugins """
-
- def plugins():
- """ Return enabled plugins """
-
- def view_template_id():
- """ View or template id for this context """
diff --git a/sc/social/like/logger.py b/sc/social/like/logger.py
new file mode 100644
index 00000000..8d4c9a3c
--- /dev/null
+++ b/sc/social/like/logger.py
@@ -0,0 +1,6 @@
+# -*- coding: utf-8 -*-
+from sc.social.like.config import PROJECTNAME
+
+import logging
+
+logger = logging.getLogger(PROJECTNAME)
diff --git a/sc/social/like/plugins/facebook/browser.py b/sc/social/like/plugins/facebook/browser.py
index 74ebefe1..90b9fead 100644
--- a/sc/social/like/plugins/facebook/browser.py
+++ b/sc/social/like/plugins/facebook/browser.py
@@ -1,9 +1,12 @@
# -*- coding:utf-8 -*-
from Acquisition import aq_parent, aq_inner
+from plone import api
+from plone.api.exc import InvalidParameterError
from Products.CMFCore.interfaces import ISiteRoot
from Products.CMFCore.utils import getToolByName
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
+from sc.social.like.interfaces import ISocialLikeSettings
from sc.social.like.plugins.facebook.utils import facebook_language
from sc.social.like.utils import get_content_image
from sc.social.like.utils import get_language
@@ -16,27 +19,21 @@
class PluginView(BrowserView):
- enabled_portal_types = []
- typebutton = ''
fb_enabled = False
- fbaction = ''
- fbadmins = ''
language = 'en_US'
- fbshow_like = True
- fbshow_share = False
metadata = ViewPageTemplateFile('templates/metadata.pt')
plugin = ViewPageTemplateFile('templates/plugin.pt')
link = ViewPageTemplateFile('templates/link.pt')
def __init__(self, context, request):
- super(PluginView, self).__init__(context, request)
- pp = getToolByName(context, 'portal_properties')
-
self.context = context
+ self.request = request
+ # FIXME: the following could rise unexpected exceptions
+ # move it to a new setup() method
+ # see: http://docs.plone.org/develop/plone/views/browserviews.html#creating-a-view
self.title = context.title
self.description = context.Description()
- self.request = request
self.portal_state = getMultiAdapter((self.context, self.request),
name=u'plone_portal_state')
self.portal = self.portal_state.portal()
@@ -44,15 +41,8 @@ def __init__(self, context, request):
self.portal_title = self.portal_state.portal_title()
self.url = context.absolute_url()
self.language = facebook_language(get_language(context), self.language)
- self.sheet = getattr(pp, 'sc_social_likes_properties', None)
self.image = get_content_image(context, width=1200, height=630)
- if self.sheet:
- self.fbaction = self.sheet.getProperty('fbaction', '')
- self.fbapp_id = self.sheet.getProperty('fbapp_id', '')
- self.fbadmins = self.sheet.getProperty('fbadmins', '')
- self.fbshow_like = 'Like' in self.sheet.getProperty('fbbuttons', [])
- self.fbshow_share = 'Share' in self.sheet.getProperty('fbbuttons', [])
- self.button = self.typebutton
+ self.typebutton # XXX: needed to initialize self.width
def fbjs(self):
js_source = """
@@ -99,7 +89,12 @@ def image_url(self):
@property
def typebutton(self):
- typebutton = self.sheet.getProperty('typebutton', '')
+ record = ISocialLikeSettings.__identifier__ + '.typebutton'
+ try:
+ typebutton = api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ typebutton = ''
+
if typebutton == 'horizontal':
typebutton = 'button_count'
self.width = '90px'
@@ -108,6 +103,46 @@ def typebutton(self):
self.width = '55px'
return typebutton
+ @property
+ def fbaction(self):
+ record = ISocialLikeSettings.__identifier__ + '.fbaction'
+ try:
+ return api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ return ''
+
+ @property
+ def app_id(self):
+ record = ISocialLikeSettings.__identifier__ + '.facebook_app_id'
+ try:
+ return api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ return ''
+
+ @property
+ def admins(self):
+ record = ISocialLikeSettings.__identifier__ + '.facebook_username'
+ try:
+ return api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ return ''
+
+ @property
+ def fbshow_like(self):
+ record = ISocialLikeSettings.__identifier__ + '.fbbuttons'
+ try:
+ return 'Like' in api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ return False
+
+ @property
+ def fbshow_share(self):
+ record = ISocialLikeSettings.__identifier__ + '.fbbuttons'
+ try:
+ return 'Share' in api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ return False
+
def _isPortalDefaultView(self):
context = self.context
if ISiteRoot.providedBy(aq_parent(aq_inner(context))):
@@ -129,7 +164,7 @@ def type(self):
def share_link(self):
absolute_url = self.context.absolute_url()
params = dict(
- app_id=self.fbapp_id,
+ app_id=self.app_id,
display='popup',
href=absolute_url,
redirect_uri=absolute_url,
diff --git a/sc/social/like/plugins/facebook/configure.zcml b/sc/social/like/plugins/facebook/configure.zcml
index 50e3923c..b8ed70c7 100644
--- a/sc/social/like/plugins/facebook/configure.zcml
+++ b/sc/social/like/plugins/facebook/configure.zcml
@@ -8,17 +8,6 @@
factory="sc.social.like.plugins.facebook.Facebook"
name="Facebook" />
-
-
-
-
-
Simple link sharing will not work is no FB APPID is configured
-
+
-
-
+
+
-
\ No newline at end of file
+
diff --git a/sc/social/like/plugins/gplus/browser.py b/sc/social/like/plugins/gplus/browser.py
index f79bceb3..853144b8 100644
--- a/sc/social/like/plugins/gplus/browser.py
+++ b/sc/social/like/plugins/gplus/browser.py
@@ -1,7 +1,9 @@
# -*- coding:utf-8 -*-
-from Products.CMFCore.utils import getToolByName
+from plone import api
+from plone.api.exc import InvalidParameterError
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
+from sc.social.like.interfaces import ISocialLikeSettings
from sc.social.like.utils import get_language
from urllib import urlencode
from zope.component import getMultiAdapter
@@ -9,7 +11,6 @@
class PluginView(BrowserView):
- typebutton = ''
gp_enabled = True
language = 'en'
@@ -18,11 +19,11 @@ class PluginView(BrowserView):
link = ViewPageTemplateFile('templates/link.pt')
def __init__(self, context, request):
- super(PluginView, self).__init__(context, request)
- pp = getToolByName(context, 'portal_properties')
-
self.context = context
self.request = request
+ # FIXME: the following could rise unexpected exceptions
+ # move it to a new setup() method
+ # see: http://docs.plone.org/develop/plone/views/browserviews.html#creating-a-view
self.portal_state = getMultiAdapter((self.context, self.request),
name=u'plone_portal_state')
self.portal = self.portal_state.portal()
@@ -30,11 +31,15 @@ def __init__(self, context, request):
self.portal_title = self.portal_state.portal_title()
self.url = context.absolute_url()
self.language = get_language(context)
- self.sheet = getattr(pp, 'sc_social_likes_properties', None)
@property
def typebutton(self):
- typebutton = self.sheet.getProperty('typebutton', '')
+ record = ISocialLikeSettings.__identifier__ + '.typebutton'
+ try:
+ typebutton = api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ typebutton = ''
+
if typebutton == 'horizontal':
typebutton = 'medium'
else:
diff --git a/sc/social/like/plugins/linkedin/browser.py b/sc/social/like/plugins/linkedin/browser.py
index c1138c15..e7a3fb8a 100644
--- a/sc/social/like/plugins/linkedin/browser.py
+++ b/sc/social/like/plugins/linkedin/browser.py
@@ -1,7 +1,9 @@
# -*- coding:utf-8 -*-
-from Products.CMFCore.utils import getToolByName
+from plone import api
+from plone.api.exc import InvalidParameterError
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
+from sc.social.like.interfaces import ISocialLikeSettings
from sc.social.like.utils import get_language
from urllib import urlencode
from zope.component import getMultiAdapter
@@ -9,7 +11,6 @@
class PluginView(BrowserView):
- typebutton = ''
linkedin_enabled = True
language = 'en'
@@ -18,11 +19,11 @@ class PluginView(BrowserView):
link = ViewPageTemplateFile('templates/link.pt')
def __init__(self, context, request):
- super(PluginView, self).__init__(context, request)
- pp = getToolByName(context, 'portal_properties')
-
self.context = context
self.request = request
+ # FIXME: the following could rise unexpected exceptions
+ # move it to a new setup() method
+ # see: http://docs.plone.org/develop/plone/views/browserviews.html#creating-a-view
self.portal_state = getMultiAdapter((self.context, self.request),
name=u'plone_portal_state')
self.portal = self.portal_state.portal()
@@ -30,11 +31,15 @@ def __init__(self, context, request):
self.portal_title = self.portal_state.portal_title()
self.url = context.absolute_url()
self.language = get_language(context)
- self.sheet = getattr(pp, 'sc_social_likes_properties', None)
@property
def typebutton(self):
- typebutton = self.sheet.getProperty('typebutton', '')
+ record = ISocialLikeSettings.__identifier__ + '.typebutton'
+ try:
+ typebutton = api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ typebutton = ''
+
if typebutton == 'horizontal':
typebutton = 'right'
else:
diff --git a/sc/social/like/plugins/pinterest/browser.py b/sc/social/like/plugins/pinterest/browser.py
index 43131fd4..c34973fc 100644
--- a/sc/social/like/plugins/pinterest/browser.py
+++ b/sc/social/like/plugins/pinterest/browser.py
@@ -1,7 +1,9 @@
# -*- coding:utf-8 -*-
-from Products.CMFCore.utils import getToolByName
+from plone import api
+from plone.api.exc import InvalidParameterError
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
+from sc.social.like.interfaces import ISocialLikeSettings
from sc.social.like.utils import get_content_image
from sc.social.like.utils import get_language
from urllib import urlencode
@@ -13,7 +15,6 @@
class PluginView(BrowserView):
- typebutton = ''
pinterest_enabled = False
language = 'en'
@@ -22,11 +23,11 @@ class PluginView(BrowserView):
link = ViewPageTemplateFile('templates/link.pt')
def __init__(self, context, request):
- super(PluginView, self).__init__(context, request)
- pp = getToolByName(context, 'portal_properties')
-
self.context = context
self.request = request
+ # FIXME: the following could rise unexpected exceptions
+ # move it to a new setup() method
+ # see: http://docs.plone.org/develop/plone/views/browserviews.html#creating-a-view
self.portal_state = getMultiAdapter((self.context, self.request),
name=u'plone_portal_state')
self.portal = self.portal_state.portal()
@@ -35,7 +36,6 @@ def __init__(self, context, request):
self.url = context.absolute_url()
self.image = get_content_image(context, scale='large')
self.language = get_language(context)
- self.sheet = getattr(pp, 'sc_social_likes_properties', None)
def share_url(self):
template = BASE_URL + PARAMS
@@ -56,7 +56,12 @@ def image_url(self):
@property
def typebutton(self):
- typebutton = self.sheet.getProperty('typebutton', '')
+ record = ISocialLikeSettings.__identifier__ + '.typebutton'
+ try:
+ typebutton = api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ typebutton = ''
+
if typebutton == 'horizontal':
typebutton = 'beside'
else:
diff --git a/sc/social/like/plugins/twitter/browser.py b/sc/social/like/plugins/twitter/browser.py
index 2c31f476..65b24fab 100644
--- a/sc/social/like/plugins/twitter/browser.py
+++ b/sc/social/like/plugins/twitter/browser.py
@@ -1,9 +1,11 @@
# -*- coding:utf-8 -*-
-from Products.CMFCore.utils import getToolByName
+from plone import api
+from plone.api.exc import InvalidParameterError
from Products.CMFPlone.utils import safe_unicode
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.PythonScripts.standard import url_quote
+from sc.social.like.interfaces import ISocialLikeSettings
from sc.social.like.utils import get_language
from urllib import urlencode
from zope.component import getMultiAdapter
@@ -11,10 +13,7 @@
class PluginView(BrowserView):
- enabled_portal_types = []
- typebutton = ''
- twitter_enabled = ''
- twittvia = ''
+ twitter_enabled = False
language = 'en'
metadata = ViewPageTemplateFile('templates/metadata.pt')
@@ -22,11 +21,11 @@ class PluginView(BrowserView):
link = ViewPageTemplateFile('templates/link.pt')
def __init__(self, context, request):
- super(PluginView, self).__init__(context, request)
- pp = getToolByName(context, 'portal_properties')
-
self.context = context
self.request = request
+ # FIXME: the following could rise unexpected exceptions
+ # move it to a new setup() method
+ # see: http://docs.plone.org/develop/plone/views/browserviews.html#creating-a-view
self.portal_state = getMultiAdapter((self.context, self.request),
name=u'plone_portal_state')
self.portal = self.portal_state.portal()
@@ -34,26 +33,38 @@ def __init__(self, context, request):
self.portal_title = self.portal_state.portal_title()
self.url = context.absolute_url()
self.language = get_language(context)
- self.sheet = getattr(pp, 'sc_social_likes_properties', None)
- if self.sheet:
- self.typebutton = self.sheet.getProperty('typebutton', '')
- self.twittvia = self.sheet.getProperty('twittvia', '')
self.urlnoscript = (
u'http://twitter.com/home?status=' +
url_quote(u'{0} - {1} via {2}'.format(
safe_unicode(self.context.title),
self.context.absolute_url(),
- self.twittvia)
+ self.via)
)
)
+ @property
+ def typebutton(self):
+ record = ISocialLikeSettings.__identifier__ + '.typebutton'
+ try:
+ return api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ return ''
+
+ @property
+ def via(self):
+ record = ISocialLikeSettings.__identifier__ + '.twitter_username'
+ try:
+ return api.portal.get_registry_record(record)
+ except InvalidParameterError:
+ return ''
+
def share_link(self):
params = dict(
text=self.context.Title(),
url=self.context.absolute_url(),
)
- if self.twittvia:
- params['via'] = self.twittvia
+ if self.via:
+ params['via'] = self.via
url = 'https://twitter.com/intent/tweet?' + urlencode(params)
return url
diff --git a/sc/social/like/plugins/twitter/configure.zcml b/sc/social/like/plugins/twitter/configure.zcml
index 654c60fd..b209e973 100644
--- a/sc/social/like/plugins/twitter/configure.zcml
+++ b/sc/social/like/plugins/twitter/configure.zcml
@@ -8,17 +8,6 @@
factory="sc.social.like.plugins.twitter.Twitter"
name="Twitter" />
-
-
-
-
-