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