[387] | 1 | from zope.interface import implements |
---|
[2139] | 2 | from zope.component import queryAdapter |
---|
[408] | 3 | from zope.component import queryMultiAdapter |
---|
[1671] | 4 | |
---|
| 5 | from quintagroup.seoptimizer.util import SortedDict |
---|
[1624] | 6 | from quintagroup.seoptimizer.interfaces import IMetaKeywords, IMappingMetaTags |
---|
[2139] | 7 | from quintagroup.seoptimizer.browser.seo_configlet import ISEOConfigletSchema |
---|
[387] | 8 | |
---|
[2139] | 9 | METADATA_MAPS = dict([ |
---|
| 10 | ("DC.publisher", "Publisher"), |
---|
| 11 | ("DC.description", "Description"), |
---|
| 12 | ("DC.contributors", "Contributors"), |
---|
| 13 | ("DC.creator", "Creator"), |
---|
| 14 | ("DC.format", "Format"), |
---|
| 15 | ("DC.rights", "Rights"), |
---|
| 16 | ("DC.language", "Language"), |
---|
| 17 | ("DC.date.modified", "ModificationDate"), |
---|
| 18 | ("DC.date.created", "CreationDate"), |
---|
| 19 | ("DC.type", "Type"), |
---|
| 20 | ("DC.subject", "Subject"), |
---|
| 21 | ("DC.distribution", "seo_distribution"), |
---|
| 22 | ("description", "seo_description"), |
---|
| 23 | ("keywords", "meta_keywords"), |
---|
| 24 | ("robots", "seo_robots"), |
---|
| 25 | ("distribution", "seo_distribution")]) |
---|
[1313] | 26 | |
---|
[3134] | 27 | |
---|
[1624] | 28 | class MetaKeywordsAdapter(object): |
---|
| 29 | implements(IMetaKeywords) |
---|
[387] | 30 | |
---|
| 31 | def __init__(self, context): |
---|
| 32 | self.context = context |
---|
| 33 | |
---|
[1624] | 34 | def getMetaKeywords(self): |
---|
[1509] | 35 | """ See interface. |
---|
| 36 | """ |
---|
[2139] | 37 | meta_keywords = [] |
---|
| 38 | seo_context = queryMultiAdapter((self.context, self.context.REQUEST), |
---|
| 39 | name='seo_context') |
---|
[1313] | 40 | if seo_context: |
---|
[2139] | 41 | meta_keywords = list(seo_context['meta_keywords']) |
---|
[1624] | 42 | return ', '.join(meta_keywords) |
---|
[387] | 43 | |
---|
[1313] | 44 | |
---|
| 45 | class MappingMetaTags(object): |
---|
| 46 | implements(IMappingMetaTags) |
---|
| 47 | |
---|
| 48 | def __init__(self, context): |
---|
| 49 | self.context = context |
---|
[2139] | 50 | pps = queryMultiAdapter((self.context, self.context.REQUEST), |
---|
| 51 | name="plone_portal_state") |
---|
| 52 | self.gseo = queryAdapter(pps.portal(), ISEOConfigletSchema) |
---|
[1313] | 53 | |
---|
| 54 | def getMappingMetaTags(self): |
---|
[1509] | 55 | """ See interface. |
---|
| 56 | """ |
---|
[1313] | 57 | metadata_name = SortedDict() |
---|
[2139] | 58 | if self.gseo: |
---|
| 59 | for mt in self.gseo.metatags_order: |
---|
[3134] | 60 | if mt in METADATA_MAPS: |
---|
[2139] | 61 | metadata_name[mt] = METADATA_MAPS[mt] |
---|
[1313] | 62 | return metadata_name |
---|