示例#1
0
class ICanonicalURLUpdater(model.Schema):
    """A form to update the canonical url of portal objects based on a date."""

    old_canonical_domain = schema.URI(
        title=_(u'Old canonical domain'),
        description=
        _(u'help_canonical_domain',
          default=
          u'The canonical domain will be used to construct the canonical URL (<code>og:url</code> property) of portal objects. '
          u'Use the domain name of your site (e.g. <strong>http://www.example.org</strong> or <strong>https://www.example.org</strong>). '
          u'Facebook will use the canonical URL to ensure that all actions such as likes and shares aggregate at the same URL rather than spreading across multiple versions of a page. '
          u'Check <a href="https://pypi.python.org/pypi/sc.social.like">package documentation</a> for more information on how to use this feature.'
          ),
        required=True,
        constraint=validate_canonical_domain,
    )

    published_before = schema.Date(
        title=_(u'Date'),
        description=
        _(u'help_published_before',
          default=
          u'Objects published before this date will be updated using the canonical domain defined in this form; '
          u'objects published on or after this date will be updated using the canonical domain defined in the control panel configlet.'
          ),
        required=True,
    )
示例#2
0
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
示例#3
0
class SocialLikeSettingsEditForm(controlpanel.RegistryEditForm):

    """Control panel edit form."""

    schema = ISocialLikeSettings
    label = _(u'Social Like')
    description = _(u'Settings for the sc.social.like package')
示例#4
0
class IFacebookTile(IPersistentCoverTile):
    """A tile that embeds a Facebook Page."""

    href = schema.URI(
        title=_(u'Facebook Page'),
        description=_(u'The URL of the Facebook Page.'),
        required=True,
    )

    width = schema.Int(
        title=_(u'Width'),
        description=_(
            u'Set the maximum width of the widget between 180 and 500 pixels. '
            u'Leave it empty to automatically adjust the widget to the width of the tile.'
        ),
        required=False,
        default=None,
        min=180,
        max=500,
    )

    height = schema.Int(
        title=_(u'Height'),
        description=_(
            u'Set the height of a displayed widget, overriding the value stored with the widget ID. '
            u'Must be greater than 70 pixels. '),
        required=True,
        default=500,
        min=70,
    )

    # form.widget('tabs', CheckBoxFieldWidget)
    # tabs = schema.Choice(
    #     title=_(u'Tabs to render'),
    #     required=False,
    #     default='timeline',
    #     vocabulary=TabsOptions,
    # )

    hide_cover = schema.Bool(
        title=_(u'Hide cover photo in the header'),
        default=True,
    )

    show_facepile = schema.Bool(
        title=_(u'Show profile photos when friends like this'),
        default=False,
    )

    hide_cta = schema.Bool(
        title=_(u'Hide the custom call to action button (if available)'),
        default=True,
    )

    small_header = schema.Bool(
        title=_(u'Show small header'),
        default=True,
    )
示例#5
0
class ProvidersControlPanel(ControlPanelForm):
    """ """
    form_fields = FormFieldsets(baseset, twitterset, fbset, gpset)

    form_fields['enabled_portal_types'].custom_widget = MultiSelectWidget

    label = _('Social: Like Actions settings')
    description = _('Configure settings for social like actions.')
    form_name = _('Social: Like Actions')
示例#6
0
class ITwitterTile(IPersistentCoverTile):

    """A tile that embeds a Twitter timeline."""

    widget_id = schema.ASCIILine(
        title=_(u'Widget ID'),
        required=False,
        default='',
    )

    width = schema.Int(
        title=_(u'Width'),
        description=_(
            u'Set the maximum width of the widget between 180 and 520 pixels. '
            u'Leave it empty to automatically adjust the widget to the width of the tile.'),
        required=False,
        default=None,
        min=180,
        max=520,
    )

    height = schema.Int(
        title=_(u'Height'),
        description=_(
            u'Set the height of a displayed widget, overriding the value stored with the widget ID. '
            u'Must be greater than 200 pixels. '
            u'Note: this parameter does not apply if a tweet limit has been specified.'),
        required=False,
        default=500,
        min=200,
    )

    # form.widget('chrome', CheckBoxFieldWidget)
    # chrome = schema.Choice(
    #     title=_(u'Chrome'),
    #     required=False,
    #     vocabulary=ChromeOptions,
    # )

    tweet_limit = schema.Int(
        title=_(u'Tweet limit'),
        description=_(
            u'Display an expanded timeline of between 1 and 20 tweets. '
            u'Leave it empty to use the default or to set the height of the widget.'),
        required=False,
        default=None,
        min=1,
        max=20,
    )

    aria_polite = schema.Choice(
        title=_(u'WAI-ARIA politeness'),
        description=_(
            u'A timeline widget is a live region of a page which may receive updates as new tweets become available. '
            u'When specified as polite, assistive technologies will notify users of updates but generally do not interrupt the current task, and updates take low priority. '
            u'When specified as assertive, assistive technologies will immediately notify the user, and could potentially clear the speech queue of previous updates.'),
        required=True,
        values=['polite', 'assertive'],
        default='polite',
    )
示例#7
0
class ITwitterSchema(Interface):
    """ Twitter configurations """

    twittvia = schema.TextLine(
        title=_(u'Twitter nick'),
        description=_(
            u'help_your_twitter_nick',
            default=u'Enter your twitter nick. eg. simplesconsultoria',
        ),
        required=False,
    )
示例#8
0
    def handle_update(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = _(u'Please correct the errors.')
            return

        self.update_canonical_url(data)
示例#9
0
    def handle_update(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = _(u'Please correct the errors.')
            return

        self.update_canonical_url(data)
示例#10
0
class ITwitterSchema(Interface):
    """ Twitter configurations """

    twitter_enabled = Bool(
        title=_(u"Enable Twitter button"),
        default=True,
        required=False,
    )

    twittvia = TextLine(
        title=_(u'Twitter nick'),
        description=_(
            u'help_your_twitter_nick',
            default=u"Enter your twitter nick. eg. simplesconsultoria",
        ),
        required=False,
    )
示例#11
0
class IGpSchema(Interface):
    """ Google+ configurations """

    gp_enabled = Bool(
        title=_(u"Enable Google+ action"),
        default=True,
        required=False,
    )
示例#12
0
    def update(self):
        super(CanonicalURLUpdater, self).update()
        # show error message if no canonical domain has been defined in the configlet
        if not self.canonical_domain:
            msg = _(u'Canonical domain has not been defined in the control panel configlet.')
            api.portal.show_message(message=msg, request=self.request, type='error')

        # disable the green bar and the portlet columns
        self.request.set('disable_border', 1)
        self.request.set('disable_plone.rightcolumn', 1)
        self.request.set('disable_plone.leftcolumn', 1)
示例#13
0
class IFacebookSchema(Interface):
    """ Facebook configurations """

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

    fbadmins = schema.TextLine(
        title=_(u'Admins'),
        description=_(
            u'help_admins',
            default=u"A comma-separated list of either the "
            u"Facebook IDs of page administrators.",
        ),
        required=False,
    )

    fbapp_id = schema.TextLine(
        title=_(u'Application ID'),
        description=_(
            u'help_appid',
            default=u"A Facebook Platform application ID.",
        ),
        required=False,
    )
示例#14
0
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,
    )
示例#15
0
    def update(self):
        super(CanonicalURLUpdater, self).update()
        # show error message if no canonical domain has been defined in the configlet
        if not self.canonical_domain:
            msg = _(
                u'Canonical domain has not been defined in the control panel configlet.'
            )
            api.portal.show_message(message=msg,
                                    request=self.request,
                                    type='error')

        # disable the green bar and the portlet columns
        self.request.set('disable_border', 1)
        self.request.set('disable_plone.rightcolumn', 1)
        self.request.set('disable_plone.leftcolumn', 1)
示例#16
0
class IFacebookSchema(Interface):
    """ Facebook configurations """

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

    fbadmins = schema.TextLine(
        title=_(u'Admins'),
        description=_(
            u'help_admins',
            default=u'A comma-separated list of either the '
            u'Facebook IDs of page administrators.',
        ),
        required=False,
    )

    fbapp_id = schema.TextLine(
        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,
    )

    fbbuttons = schema.Tuple(
        title=_(u'Facebook buttons'),
        description=_(
            u'help_fbbuttons',
            default=u'Select buttons to be shown',
        ),
        value_type=schema.Choice(vocabulary=buttons),
        default=(u'Like', ),
        required=True,
    )
示例#17
0
class IProvidersSchema(Interface):
    """ General Configurations """

    enabled_portal_types = 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=Choice(
            vocabulary="plone.app.vocabularies.ReallyUserFriendlyTypes"))

    typebutton = Choice(
        title=_(u'Button style'),
        description=_(
            u'help_selected_buttons',
            default=u"Choose your button style.",
        ),
        required=True,
        default=_(u'horizontal'),
        values=(_(u'horizontal'), _(u'vertical')),
    )
示例#18
0
class IFbSchema(Interface):
    """ Facebook configurations """

    fb_enabled = Bool(
        title=_(u"Enable Facebook button"),
        default=True,
        required=False,
    )

    fb_typebutton = Choice(
        title=_(u"Choose the type of button you want"),
        required=True,
        default=u'like',
        vocabulary=buttonTypes,
    )

    fbaction = 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."
            u"Only used for 'Like' button type.",
        ),
        required=True,
        default=u'like',
        vocabulary=verbs,
    )

    fbadmins = TextLine(
        title=_(u'Admins'),
        description=_(
            u'help_admins',
            default=u"A comma-separated list of either the "
            u"Facebook IDs of page administrators or a "
            u"Facebook Platform application ID.",
        ),
        required=False,
    )
示例#19
0
class ISocialLikeSettings(model.Schema):
    """Schema for the control panel form."""

    enabled_portal_types = schema.Tuple(
        title=_('Content types'),
        description=_(
            'help_portal_types',
            default='Please select content types in which the '
                    '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=_('Plugins'),
        description=_(
            'help_enabled_plugins',
            default='Please select which plugins will be used',
        ),
        required=False,
        default=DEFAULT_PLUGINS_ENABLED,
        value_type=schema.Choice(vocabulary='sc.social.likes.plugins'),
    )

    folderish_templates = schema.List(
        title=_('Folderish Templates'),
        description=_(
            'help_folderish_templates',
            default='If a folderish has one of these templates as default '
                    'view, the viewlet is showed even if the folderish type '
                    'is not selected in Content types.',
        ),
        required=False,
        value_type=schema.TextLine(),
    )

    validation_enabled = schema.Bool(
        title=_('Enable content validation?'),
        description=_(
            'help_validation_enabled',
            default='Enables validation to check if content follows social networks sharing best practices. '
                    'The validation includes title, description and lead image fields. '
                    'This feature is only available for Dexterity-based content types.'),
        default=True,
    )

    typebutton = schema.Choice(
        title=_('Button style'),
        description=_(
            'help_selected_buttons',
            default='Choose your button style.',
        ),
        required=True,
        default='horizontal',
        vocabulary=TypeButtonVocabulary,
    )

    do_not_track = schema.Bool(
        title=_('Do not track users'),
        description=_(
            'help_do_not_track',
            default='If enabled, the site will not provide advanced sharing '
                    'widgets; simple links will be used instead.\n'
                    'This will limit user experience and features '
                    u"(like the share count) but will enhance users' privacy: "
                    'no 3rd party cookies will be sent to users.'),
        default=False,
    )

    model.fieldset(
        'open_graph',
        label='Open Graph',
        fields=[
            'fallback_image',
        ],
    )

    # The former property canonical_domain is now removed since Plone 6 core
    # already generates and serves a canonical URL for every page.

    form.widget('fallback_image', NamedImageFieldWidget)
    fallback_image = schema.Bytes(
        title=_('Fallback image'),
        description=_(
            'help_fallback_image',
            default='Content without a lead image will use this image as fallback (<code>og:image</code> property). '
                    'There could be a delay of up to 2 minutes when replacing this image.'),
        required=False,
        constraint=validate_og_fallback_image,
    )

    model.fieldset(
        'facebook',
        label='Facebook',
        fields=[
            'fbaction',
            'facebook_username',
            'facebook_app_id',
            'fbbuttons',
            'fbshowlikes',
            'facebook_prefetch_enabled',
        ],
    )

    fbaction = schema.Choice(
        title=_('Verb to display'),
        description=_(
            'help_verb_display',
            default='The verb to display in the Facebook button. '
                    'Currently only "like" and "recommend" are '
                    'supported.'),
        required=True,
        default='like',
        vocabulary=FacebookVerbsVocabulary,
    )

    facebook_username = schema.ASCIILine(
        title=_('Admins'),
        description=_(
            'help_admins',
            default='A comma-separated list of either the '
                    'Facebook IDs of page administrators.'),
        required=False,
        default='',
    )

    facebook_app_id = schema.ASCIILine(
        title=_('Application ID'),
        description=_(
            'help_appid',
            default='A Facebook Platform application ID.\n'
                    'This is required when the \"Do not track users\" option is enabled and for the '
                    'Facebook share icon to be displayed. See https://developers.facebook.com/docs/apps#register'),
        required=False,
        default='',
    )

    fbbuttons = schema.Tuple(
        title=_('Facebook buttons'),
        description=_(
            'help_fbbuttons',
            default='Select buttons to be shown',
        ),
        value_type=schema.Choice(vocabulary=FacebookButtonsVocabulary),
        required=True,
        default=('Like',),
    )

    fbshowlikes = schema.Bool(
        title=_('Show number of likes'),
        description=_(
            'help_show_likes',
            default='If enabled, the Facebook button will show the number of '
                    'Facebook users who have already liked this page.'),
        default=True,
    )

    facebook_prefetch_enabled = schema.Bool(
        title=_('Enable Facebook prefetch?'),
        description=_(
            'help_facebook_prefetch_enabled',
            default='If enabled, an event is triggered to make Facebook '
                    'crawler scrape and cache metadata every time a new '
                    'piece content is published and every time published '
                    'content is edited. '
                    'This will keep the metadata updated on Facebook always.'),
        default=False,
    )

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

    twitter_username = schema.ASCIILine(
        title=_('Twitter nick'),
        description=_(
            'help_your_twitter_nick',
            default='Enter your twitter nick. eg. simplesconsultoria'),
        required=False,
        default='',
    )
示例#20
0
    def plugins(self):
        terms = []
        registered = dict(getUtilitiesFor(IPlugin))
        keys = list(registered.keys())
        keys.sort()
        for key in keys:
            terms.append(SimpleTerm(key, title=key))

        return SimpleVocabulary(terms)

    def __call__(self, context):
        return self.plugins()


PluginsVocabularyFactory = PluginsVocabulary()

TypeButtonVocabulary = SimpleVocabulary([
    SimpleTerm(value='horizontal', title=_('horizontal')),
    SimpleTerm(value='vertical', title=_('vertical')),
])

FacebookVerbsVocabulary = SimpleVocabulary([
    SimpleTerm(value='like', title=_('Like')),
    SimpleTerm(value='recommend', title=_('Recommend')),
])

FacebookButtonsVocabulary = SimpleVocabulary([
    SimpleTerm(value='Like', title=_('Like')),
    SimpleTerm(value='Share', title=_('Share')),
])
示例#21
0
    linkedin_enabled = Bool(
        title=_(u"Enable Linkedin button"),
        default=True,
        required=False,
        )

class LinkedinControlPanelAdapter(BaseControlPanelAdapter):
    """ Linkedin control panel adapter """
    adapts(IPloneSiteRoot)
    implements(ILinkedinSchema)

    linkedin_enabled = ProxyFieldProperty(ILinkedinSchema['linkedin_enabled'])

linkedinset = FormFieldsets(ILinkedinSchema)
linkedinset.id = 'linkedinset'
linkedinset.label = _(u'Linkedin settings')

class IPinterestSchema(Interface):
    """ Pinterest configurations """

    pinterest_enabled = Bool(
        title=_(u"Enable Pinterest button"),
        default=True,
        required=False,
        )

class PinterestControlPanelAdapter(BaseControlPanelAdapter):
    """ Pinterest control panel adapter """
    adapts(IPloneSiteRoot)
    implements(IPinterestSchema)
示例#22
0
from plone.app.controlpanel.form import ControlPanelForm
from Products.CMFDefault.formlib.schema import ProxyFieldProperty as PFP
from Products.CMFPlone.interfaces import IPloneSiteRoot
from sc.social.like import LikeMessageFactory as _
from sc.social.like.controlpanel.likes import BaseControlPanelAdapter
from zope import schema
from zope.component import adapts
from zope.formlib.form import FormFields
from zope.interface import implements
from zope.interface import Interface
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary

verbs = SimpleVocabulary([
    SimpleTerm(value=u'like', title=_(u'Like')),
    SimpleTerm(value=u'recommend', title=_(u'Recommend')),
])

buttons = SimpleVocabulary([
    SimpleTerm(value=u'Like', title=_(u'Like')),
    SimpleTerm(value=u'Share', title=_(u'Share')),
])


class IFacebookSchema(Interface):
    """ Facebook configurations """

    fbaction = schema.Choice(
        title=_(u'Verb to display'),
        description=_(
示例#23
0
from Products.CMFPlone.utils import getToolByName
from Products.CMFDefault.formlib.schema import ProxyFieldProperty
from Products.CMFDefault.formlib.schema import SchemaAdapterBase

from plone.app.controlpanel.form import ControlPanelForm

from plone.fieldsets.fieldsets import FormFieldsets

from zope.app.form.browser.itemswidgets import MultiSelectWidget as BaseMultiSelectWidget

from sc.social.like import LikeMessageFactory as _

from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm

buttonTypes = SimpleVocabulary(
    [SimpleTerm(value=u"like", title=_(u"Like")), SimpleTerm(value=u"share_this", title=_(u"Share this"))]
)

verbs = SimpleVocabulary(
    [SimpleTerm(value=u"like", title=_(u"Like")), SimpleTerm(value=u"recommend", title=_(u"Recommend"))]
)


class MultiSelectWidget(BaseMultiSelectWidget):
    """ """

    def __init__(self, field, request):
        """Initialize the widget."""
        super(MultiSelectWidget, self).__init__(field, field.value_type.vocabulary, request)

示例#24
0
from Products.CMFPlone.utils import getToolByName
from Products.CMFDefault.formlib.schema import ProxyFieldProperty
from Products.CMFDefault.formlib.schema import SchemaAdapterBase

from plone.app.controlpanel.form import ControlPanelForm

from plone.fieldsets.fieldsets import FormFieldsets

from zope.app.form.browser.itemswidgets import MultiSelectWidget as BaseMultiSelectWidget

from sc.social.like import LikeMessageFactory as _

from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm

verbs = SimpleVocabulary(
    [SimpleTerm(value=u'like', title=_(u'Like')),
     SimpleTerm(value=u'recommend', title=_(u'Recommend')), ]
    )


class MultiSelectWidget(BaseMultiSelectWidget):
    """ """
    def __init__(self, field, request):
        """Initialize the widget."""
        super(MultiSelectWidget, self).__init__(field,
            field.value_type.vocabulary, request)


class IProvidersSchema(Interface):
    """ General Configurations """
示例#25
0
from Products.CMFPlone.utils import getToolByName
from Products.CMFDefault.formlib.schema import ProxyFieldProperty
from Products.CMFDefault.formlib.schema import SchemaAdapterBase

from plone.app.controlpanel.form import ControlPanelForm

from plone.fieldsets.fieldsets import FormFieldsets

from zope.app.form.browser.itemswidgets import MultiSelectWidget as BaseMultiSelectWidget

from sc.social.like import LikeMessageFactory as _

from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm

buttonTypes = SimpleVocabulary([
    SimpleTerm(value=u'like', title=_(u'Like')),
    SimpleTerm(value=u'share_this', title=_(u'Share this')),
])

verbs = SimpleVocabulary([
    SimpleTerm(value=u'like', title=_(u'Like')),
    SimpleTerm(value=u'recommend', title=_(u'Recommend')),
])


class MultiSelectWidget(BaseMultiSelectWidget):
    """ """
    def __init__(self, field, request):
        """Initialize the widget."""
        super(MultiSelectWidget,
              self).__init__(field, field.value_type.vocabulary, request)
示例#26
0
    def plugins(self):
        terms = []
        registered = dict(getUtilitiesFor(IPlugin))
        keys = registered.keys()
        keys.sort()
        for key in keys:
            terms.append(SimpleTerm(key, title=key))

        return SimpleVocabulary(terms)

    def __call__(self, context):
        return self.plugins()


PluginsVocabularyFactory = PluginsVocabulary()

TypeButtonVocabulary = SimpleVocabulary([
    SimpleTerm(value=u'horizontal', title=_(u'horizontal')),
    SimpleTerm(value=u'vertical', title=_(u'vertical')),
])

FacebookVerbsVocabulary = SimpleVocabulary([
    SimpleTerm(value=u'like', title=_(u'Like')),
    SimpleTerm(value=u'recommend', title=_(u'Recommend')),
])

FacebookButtonsVocabulary = SimpleVocabulary([
    SimpleTerm(value=u'Like', title=_(u'Like')),
    SimpleTerm(value=u'Share', title=_(u'Share')),
])
示例#27
0
from collective.cover.tiles.base import PersistentCoverTile
from plone import api
# from plone.autoform import directives as form
from plone.memoize import view
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from sc.social.like import LikeMessageFactory as _
from sc.social.like.interfaces import ISocialLikeSettings
# from z3c.form.browser.checkbox import CheckBoxFieldWidget
from zope import schema
from zope.interface import implementer
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary


ChromeOptions = SimpleVocabulary([
    SimpleTerm(value='noheader', title=_(u'Hide the timeline header')),
    SimpleTerm(value='nofooter', title=_(u'Hide the timeline footer')),
    SimpleTerm(value='noborders', title=_(u'Remove all borders within the widget')),
    SimpleTerm(value='noscrollbar', title=_(u'Crop and hides the main timeline scrollbar')),
    SimpleTerm(value='transparent', title=_(u"Remove the widget's background color")),
])


class ITwitterTile(IPersistentCoverTile):

    """A tile that embeds a Twitter timeline."""

    widget_id = schema.ASCIILine(
        title=_(u'Widget ID'),
        required=False,
        default='',
示例#28
0
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,
示例#29
0
def get_valid_objects(brains):
    """Generate a list of objects associated with valid brains."""
    for b in brains:
        try:
            obj = b.getObject()
        except KeyError:
            obj = None

        if obj is None:  # warn on broken entries in the catalog
            msg = u'Skipping invalid reference in the catalog: {0}'
            logger.warn(msg.format(b.getPath()))
            continue
        yield obj


MSG_INVALID_OG_TITLE = _(
    u'Title of content should have less than 70 characters.')


def validate_og_title(title):
    """Check if title of content is set and has less than 70 characters.

    More information:
    * https://dev.twitter.com/cards/markup
    """
    if title and len(title) <= OG_TITLE_MAX_LENGTH:
        return True

    raise ValueError(MSG_INVALID_OG_TITLE)


MSG_INVALID_OG_DESCRIPTION = _(
示例#30
0
class ProviderControlPanel(ControlPanelForm):
    """ """
    form_fields = FormFields(IFacebookSchema)

    label = _('Social: Facebook settings')
    description = _('Configure settings for Facebook integration.')
示例#31
0
        terms = []
        registered = dict(getUtilitiesFor(IPlugin))
        keys = registered.keys()
        keys.sort()
        for key in keys:
            terms.append(SimpleTerm(key, title=key))

        return SimpleVocabulary(terms)

    def __call__(self, context):
        return self.plugins()

PluginsVocabularyFactory = PluginsVocabulary()


TypeButtonVocabulary = SimpleVocabulary([
    SimpleTerm(value=u'horizontal', title=_(u'horizontal')),
    SimpleTerm(value=u'vertical', title=_(u'vertical')),
])


FacebookVerbsVocabulary = SimpleVocabulary([
    SimpleTerm(value=u'like', title=_(u'Like')),
    SimpleTerm(value=u'recommend', title=_(u'Recommend')),
])

FacebookButtonsVocabulary = SimpleVocabulary([
    SimpleTerm(value=u'Like', title=_(u'Like')),
    SimpleTerm(value=u'Share', title=_(u'Share')),
])
示例#32
0
from plone.app.controlpanel.form import ControlPanelForm
from Products.CMFDefault.formlib.schema import ProxyFieldProperty as PFP
from Products.CMFPlone.interfaces import IPloneSiteRoot
from sc.social.like import LikeMessageFactory as _
from sc.social.like.controlpanel.likes import BaseControlPanelAdapter
from zope import schema
from zope.component import adapts
from zope.formlib.form import FormFields
from zope.interface import implements
from zope.interface import Interface
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary

verbs = SimpleVocabulary([
    SimpleTerm(value=u'like', title=_(u'Like')),
    SimpleTerm(value=u'recommend', title=_(u'Recommend')),
])


class IFacebookSchema(Interface):
    """ Facebook configurations """

    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.",
        ),
示例#33
0
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,
示例#34
0
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'),
    )

    validation_enabled = schema.Bool(
        title=_(u'Enable content validation?'),
        description=
        _(u'help_validation_enabled',
          default=
          u'Enables validation to check if content follows social networks sharing best practices. '
          u'The validation includes title, description and lead image fields. '
          u'This feature is only available for Dexterity-based content types.'
          ),
        default=True,
    )

    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(
        'open_graph',
        label=u'Open Graph',
        fields=[
            'canonical_domain',
            'fallback_image',
        ],
    )

    canonical_domain = schema.URI(
        title=_(u'Canonical domain'),
        description=
        _(u'help_canonical_domain',
          default=
          u'The canonical domain will be used to construct the canonical URL (<code>og:url</code> property) of portal objects. '
          u'Use the domain name of your site (e.g. <strong>http://www.example.org</strong> or <strong>https://www.example.org</strong>). '
          u'Facebook will use the canonical URL to ensure that all actions such as likes and shares aggregate at the same URL rather than spreading across multiple versions of a page. '
          u'Check <a href="https://pypi.python.org/pypi/sc.social.like">package documentation</a> for more information on how to use this feature.'
          ),
        required=True,
        constraint=validate_canonical_domain,
    )

    form.widget('fallback_image', NamedImageFieldWidget)
    fallback_image = schema.ASCII(
        title=_(u'Fallback image'),
        description=
        _(u'help_fallback_image',
          default=
          u'Content without a lead image will use this image as fallback (<code>og:image</code> property). '
          u'There could be a delay of up to 2 minutes when replacing this image.'
          ),
        required=False,
        constraint=validate_og_fallback_image,
    )

    model.fieldset(
        'facebook',
        label=u'Facebook',
        fields=[
            'fbaction',
            'facebook_username',
            'facebook_app_id',
            'fbbuttons',
            'fbshowlikes',
            'facebook_prefetch_enabled',
        ],
    )

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

    fbshowlikes = schema.Bool(
        title=_(u'Show number of likes'),
        description=_(
            u'help_show_likes',
            default=u'If enabled, the Facebook button will show the number of '
            u'Facebook users who have already liked this page.'),
        default=True,
    )

    facebook_prefetch_enabled = schema.Bool(
        title=_(u'Enable Facebook prefetch?'),
        description=_(
            u'help_facebook_prefetch_enabled',
            default=u'If enabled, an event is triggered to make Facebook '
            u'crawler scrape and cache metadata every time a new '
            u'piece content is published and every time published '
            u'content is edited. '
            u'This will keep the metadata updated on Facebook always.'),
        default=False,
    )

    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='',
    )
示例#35
0
class ProviderControlPanel(ControlPanelForm):
    """ """
    form_fields = FormFields(ITwitterSchema)

    label = _('Social: Twitter settings')
    description = _('Configure settings for Twitter integration.')
示例#36
0
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='',
    )
示例#37
0
from collective.cover.tiles.base import PersistentCoverTile
from plone import api
# from plone.autoform import directives as form
from plone.memoize import view
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from sc.social.like import LikeMessageFactory as _
from sc.social.like.interfaces import ISocialLikeSettings
from urllib import urlencode
# from z3c.form.browser.checkbox import CheckBoxFieldWidget
from zope import schema
from zope.interface import implementer
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary

TabsOptions = SimpleVocabulary([
    SimpleTerm(value='timeline', title=_(u'Timeline')),
    SimpleTerm(value='events', title=_(u'Events')),
    SimpleTerm(value='messages', title=_(u'Messages')),
])


class IFacebookTile(IPersistentCoverTile):
    """A tile that embeds a Facebook Page."""

    href = schema.URI(
        title=_(u'Facebook Page'),
        description=_(u'The URL of the Facebook Page.'),
        required=True,
    )

    width = schema.Int(
示例#38
0
class CanonicalURLUpdater(form.Form):
    """A form to update the canonical url of portal objects based on a date."""

    fields = field.Fields(ICanonicalURLUpdater)
    label = _(u'Canonical URL updater form')
    description = _(
        u'This form will update the canonical URL of all Dexterity-based '
        u'objects in the catalog providing the Social Media behavior.')
    ignoreContext = True

    @property
    def canonical_domain(self):
        return api.portal.get_registry_record(name='canonical_domain',
                                              interface=ISocialLikeSettings)

    def update(self):
        super(CanonicalURLUpdater, self).update()
        # show error message if no canonical domain has been defined in the configlet
        if not self.canonical_domain:
            msg = _(
                u'Canonical domain has not been defined in the control panel configlet.'
            )
            api.portal.show_message(message=msg,
                                    request=self.request,
                                    type='error')

        # disable the green bar and the portlet columns
        self.request.set('disable_border', 1)
        self.request.set('disable_plone.rightcolumn', 1)
        self.request.set('disable_plone.leftcolumn', 1)

    @property
    def update_button_enabled(self):
        """Condition to be used to display the "Update" button."""
        return self.canonical_domain is not None

    @button.buttonAndHandler(_('Update'),
                             name='update',
                             condition=lambda form: form.update_button_enabled)
    def handle_update(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = _(u'Please correct the errors.')
            return

        self.update_canonical_url(data)

    @button.buttonAndHandler(_(u'label_cancel', default=u'Cancel'),
                             name='cancel')
    def handle_cancel(self, action):
        self.request.response.redirect(self.context.absolute_url())

    def update_canonical_url(self, data):
        """Update the canonical URL of all objects in the catalog
        providing the ISocialMedia behavior.

        Objects published before the specified date will be updated
        using the canonical domain defined in this form; objects
        published on or after that date will be updated using the
        canonical domain defined in the control panel configlet.
        """
        old_canonical_domain = data['old_canonical_domain']
        new_canonical_domain = self.canonical_domain
        published_before = data['published_before'].isoformat()
        results = api.content.find(
            object_provides=ISocialMedia.__identifier__,
            review_state='published',
        )
        total = len(results)
        logger.info(
            u'{0} objects will have their canonical URL updated'.format(total))

        for obj in get_valid_objects(results):
            # FIXME: we're currently ignoring the Plone site id
            #        https://github.com/collective/sc.social.like/issues/119
            path = '/'.join(obj.getPhysicalPath()[2:])
            if obj.effective_date < DateTime(published_before):
                # use the canonical domain defined in this form
                obj.canonical_url = '{0}/{1}'.format(old_canonical_domain,
                                                     path)
            elif not obj.canonical_url:
                # use the canonical domain defined in the configlet
                obj.canonical_url = '{0}/{1}'.format(new_canonical_domain,
                                                     path)

        logger.info(u'Done.')
        self.status = u'Update complete; {0} items processed.'.format(total)
示例#39
0
def get_valid_objects(brains):
    """Generate a list of objects associated with valid brains."""
    for b in brains:
        try:
            obj = b.getObject()
        except KeyError:
            obj = None

        if obj is None:  # warn on broken entries in the catalog
            msg = u'Skipping invalid reference in the catalog: {0}'
            logger.warn(msg.format(b.getPath()))
            continue
        yield obj


MSG_INVALID_OG_TITLE = _(
    u'Title of content should have less than 70 characters.')


def validate_og_title(title):
    """Check if title of content is set and has less than 70 characters.

    More information:
    * https://dev.twitter.com/cards/markup
    """
    if title and len(title) <= OG_TITLE_MAX_LENGTH:
        return True

    raise ValueError(MSG_INVALID_OG_TITLE)


MSG_INVALID_OG_DESCRIPTION = _(
示例#40
0
from collective.cover.tiles.base import PersistentCoverTile
from plone import api
# from plone.autoform import directives as form
from plone.memoize import view
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from sc.social.like import LikeMessageFactory as _
from sc.social.like.interfaces import ISocialLikeSettings
# from z3c.form.browser.checkbox import CheckBoxFieldWidget
from zope import schema
from zope.interface import implementer
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary


TabsOptions = SimpleVocabulary([
    SimpleTerm(value='timeline', title=_(u'Timeline')),
    SimpleTerm(value='events', title=_(u'Events')),
    SimpleTerm(value='messages', title=_(u'Messages')),
])


class IFacebookTile(IPersistentCoverTile):

    """A tile that embeds a Facebook Page."""

    href = schema.URI(
        title=_(u'Facebook Page'),
        description=_(u'The URL of the Facebook Page.'),
        required=True,
    )