[1822] | 1 | import re |
---|
[1788] | 2 | from zope.interface import Interface |
---|
| 3 | from zope.interface import implements |
---|
| 4 | from zope.component import adapts |
---|
| 5 | from zope.schema.vocabulary import SimpleTerm |
---|
| 6 | from zope.schema.vocabulary import SimpleVocabulary |
---|
[1822] | 7 | from zope.schema import Bool, Text, Choice, Tuple, List |
---|
[1788] | 8 | from zope.app.form.browser import RadioWidget |
---|
| 9 | |
---|
| 10 | from zope.formlib.form import FormFields |
---|
| 11 | from zope.app.component.hooks import getSite |
---|
| 12 | from zope.app.form.browser import TextAreaWidget |
---|
| 13 | |
---|
| 14 | from plone.app.controlpanel.form import ControlPanelForm |
---|
| 15 | from plone.app.controlpanel.widgets import MultiCheckBoxThreeColumnWidget |
---|
| 16 | |
---|
| 17 | from Products.CMFCore.utils import getToolByName |
---|
| 18 | from Products.CMFDefault.formlib.schema import ProxyFieldProperty |
---|
| 19 | from Products.CMFDefault.formlib.schema import SchemaAdapterBase |
---|
| 20 | from Products.CMFPlone.interfaces import IPloneSiteRoot |
---|
| 21 | |
---|
| 22 | from quintagroup.seoptimizer import SeoptimizerMessageFactory as _ |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | # Configlet schema |
---|
| 26 | class ISEOConfigletSchema(Interface): |
---|
| 27 | |
---|
| 28 | exposeDCMetaTags = Bool( |
---|
| 29 | title=_("label_exposeDCMetaTags", |
---|
| 30 | default='Expose <abbr title="Dublin Core">DC</abbr> meta tags'), |
---|
| 31 | description=_("description_seo_dc_metatags", |
---|
| 32 | default='Controls if <abbr title="Dublin Core">DC</abbr> ' |
---|
| 33 | 'metatags are exposed to page header. They include ' |
---|
| 34 | 'DC.description, DC.type, DC.format, DC.creator and ' |
---|
| 35 | 'others.'), |
---|
| 36 | default=True, |
---|
| 37 | required=False) |
---|
| 38 | |
---|
[1822] | 39 | default_custom_metatags = List( |
---|
[1788] | 40 | title=_("label_default_custom_metatags", default='Default custom metatags.'), |
---|
| 41 | description=_("help_default_custom_metatags", |
---|
| 42 | default='Fill in custom metatag names (one per line) which will' |
---|
| 43 | 'appear on qseo_properties edit tab. Example: ' |
---|
| 44 | '"metaname|metacontent" or "metaname".'), |
---|
| 45 | required=False) |
---|
| 46 | |
---|
[1822] | 47 | metatags_order = List( |
---|
[1788] | 48 | title=_("label_metatags_order", |
---|
| 49 | default='Meta tags order in the page.'), |
---|
| 50 | description=_("help_metatags_order", |
---|
| 51 | default='Fill in meta tags (one per line) in the order in which' |
---|
| 52 | ' they will appear on site source pages. Example: ' |
---|
| 53 | '"metaname accessor".'), |
---|
| 54 | required=False) |
---|
| 55 | |
---|
| 56 | types_seo_enabled = Tuple( |
---|
| 57 | title=_("label_content_type_title", default='Content Types'), |
---|
| 58 | description=_("description_seo_content_types", |
---|
| 59 | default='Select content types that will have SEO properties ' |
---|
| 60 | 'enabled.'), |
---|
| 61 | required=False, |
---|
| 62 | missing_value=tuple(), |
---|
| 63 | value_type=Choice( |
---|
| 64 | vocabulary="plone.app.vocabularies.ReallyUserFriendlyTypes")) |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | class SEOConfigletAdapter(SchemaAdapterBase): |
---|
| 69 | |
---|
| 70 | adapts(IPloneSiteRoot) |
---|
| 71 | implements(ISEOConfigletSchema) |
---|
| 72 | |
---|
| 73 | def __init__(self, context): |
---|
| 74 | super(SEOConfigletAdapter, self).__init__(context) |
---|
| 75 | self.portal = getSite() |
---|
| 76 | pprop = getToolByName(self.portal, 'portal_properties') |
---|
| 77 | self.context = pprop.seo_properties |
---|
| 78 | self.siteprops = pprop.site_properties |
---|
| 79 | self.ttool = getToolByName(context, 'portal_types') |
---|
| 80 | |
---|
| 81 | def getExposeDC(self): |
---|
| 82 | return self.siteprops.getProperty('exposeDCMetaTags') |
---|
| 83 | |
---|
| 84 | def setExposeDC(self, value): |
---|
| 85 | return self.siteprops._updateProperty('exposeDCMetaTags', bool(value)) |
---|
| 86 | |
---|
| 87 | def getTypesSEOEnabled(self): |
---|
| 88 | ct_with_seo = self.context.content_types_with_seoproperties |
---|
| 89 | return [t for t in self.ttool.listContentTypes() if t in ct_with_seo] |
---|
| 90 | |
---|
| 91 | def setTypesSEOEnabled(self, value): |
---|
| 92 | value = [t for t in self.ttool.listContentTypes() if t in value] |
---|
| 93 | self.context._updateProperty('content_types_with_seoproperties', value) |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | exposeDCMetaTags = property(getExposeDC, setExposeDC) |
---|
[1823] | 97 | default_custom_metatags = ProxyFieldProperty(ISEOConfigletSchema['default_custom_metatags']) |
---|
| 98 | metatags_order = ProxyFieldProperty(ISEOConfigletSchema['metatags_order']) |
---|
[1788] | 99 | types_seo_enabled = property(getTypesSEOEnabled, setTypesSEOEnabled) |
---|
[1822] | 100 | |
---|
[1788] | 101 | |
---|
| 102 | class SmallTextAreaWidget(TextAreaWidget): |
---|
| 103 | height = 5 |
---|
[1822] | 104 | splitter = re.compile(u'\\r?\\n', re.S|re.U) |
---|
[1788] | 105 | |
---|
[1822] | 106 | def _toFieldValue(self, value): |
---|
| 107 | return filter(None, self.splitter.split(value)) |
---|
[1788] | 108 | |
---|
[1822] | 109 | def _toFormValue(self, value): |
---|
| 110 | return u'\r\n'.join(list(value)) |
---|
| 111 | |
---|
| 112 | |
---|
[1788] | 113 | class SEOConfiglet(ControlPanelForm): |
---|
| 114 | |
---|
| 115 | form_fields = FormFields(ISEOConfigletSchema) |
---|
| 116 | form_fields['default_custom_metatags'].custom_widget = SmallTextAreaWidget |
---|
[1822] | 117 | form_fields['metatags_order'].custom_widget = SmallTextAreaWidget |
---|
[1788] | 118 | form_fields['types_seo_enabled'].custom_widget = MultiCheckBoxThreeColumnWidget |
---|
| 119 | form_fields['types_seo_enabled'].custom_widget.cssClass='label' |
---|
| 120 | |
---|
| 121 | label = _("Search Engine Optimizer configuration") |
---|
| 122 | description = _("seo_configlet_description", default="You can select what " |
---|
| 123 | "content types are qSEOptimizer-enabled, and control if " |
---|
| 124 | "Dublin Core metatags are exposed in the header of content " |
---|
| 125 | "pages.") |
---|
| 126 | form_name = _("") |
---|