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