[387] | 1 | import re, commands |
---|
[1671] | 2 | |
---|
| 3 | from zope.component import adapts |
---|
[387] | 4 | from zope.interface import implements |
---|
[408] | 5 | from zope.component import queryMultiAdapter |
---|
[1671] | 6 | |
---|
| 7 | from Acquisition import aq_inner |
---|
[387] | 8 | from Products.CMFCore.utils import getToolByName |
---|
| 9 | |
---|
[1671] | 10 | from quintagroup.seoptimizer.util import SortedDict |
---|
[1624] | 11 | from quintagroup.seoptimizer.interfaces import IMetaKeywords, IMappingMetaTags |
---|
[387] | 12 | |
---|
[1781] | 13 | METADATA_MAPS = dict([ |
---|
| 14 | ("DC.publisher", "Publisher"), |
---|
| 15 | ("DC.description", "Description"), |
---|
| 16 | ("DC.contributors", "Contributors"), |
---|
| 17 | ("DC.creator", "Creator"), |
---|
| 18 | ("DC.format", "Format"), |
---|
| 19 | ("DC.rights", "Rights"), |
---|
| 20 | ("DC.language", "Language"), |
---|
| 21 | ("DC.date.modified", "ModificationDate"), |
---|
| 22 | ("DC.date.created", "CreationDate"), |
---|
| 23 | ("DC.type", "Type"), |
---|
| 24 | ("DC.subject", "Subject"), |
---|
| 25 | ("DC.distribution", "seo_distribution"), |
---|
| 26 | ("description", "seo_description"), |
---|
| 27 | ("keywords", "meta_keywords"), |
---|
| 28 | ("robots", "seo_robots"), |
---|
| 29 | ("distribution", "seo_distribution")]) |
---|
[1313] | 30 | |
---|
[1624] | 31 | class MetaKeywordsAdapter(object): |
---|
| 32 | implements(IMetaKeywords) |
---|
[387] | 33 | |
---|
| 34 | def __init__(self, context): |
---|
| 35 | self.context = context |
---|
| 36 | |
---|
[1624] | 37 | def getMetaKeywords(self): |
---|
[1509] | 38 | """ See interface. |
---|
| 39 | """ |
---|
[1624] | 40 | request = self.context.REQUEST |
---|
| 41 | meta_keywords = '' |
---|
| 42 | filtered_keywords = [] |
---|
[387] | 43 | portal_props = getToolByName(self.context, 'portal_properties') |
---|
[1313] | 44 | seo_props = getToolByName(portal_props, 'seo_properties', None) |
---|
[408] | 45 | seo_context = queryMultiAdapter((self.context, request), name='seo_context') |
---|
[1313] | 46 | if seo_context: |
---|
[1624] | 47 | meta_keywords = list(seo_context.meta_keywords()) |
---|
| 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 |
---|
| 56 | self.portal_props = getToolByName(self.context, 'portal_properties') |
---|
| 57 | self.seo_props = getToolByName(self.portal_props, 'seo_properties', None) |
---|
| 58 | |
---|
| 59 | def getMappingMetaTags(self): |
---|
[1509] | 60 | """ See interface. |
---|
| 61 | """ |
---|
[1313] | 62 | metadata_name = SortedDict() |
---|
| 63 | if self.seo_props: |
---|
[1781] | 64 | pmn = self.seo_props.getProperty('metatags_order', ()) |
---|
| 65 | for mt in pmn: |
---|
| 66 | if METADATA_MAPS.has_key(mt): |
---|
| 67 | metadata_name[mt] = METADATA_MAPS[mt] |
---|
[1313] | 68 | return metadata_name |
---|
[1671] | 69 | |
---|
| 70 | |
---|
| 71 | class canonicalPathAdapter(object): |
---|
| 72 | """Adapts base content to canonical path, with taking into consideration |
---|
| 73 | SEO canonical path value. |
---|
| 74 | """ |
---|
| 75 | |
---|
| 76 | def __init__(self, context): |
---|
| 77 | self.context = context |
---|
| 78 | |
---|
| 79 | def canonical_path(self): |
---|
| 80 | purl = getToolByName(self.context,'portal_url') |
---|
| 81 | |
---|
[1720] | 82 | # Calculate canonical path from qSEO_canonical property |
---|
[1671] | 83 | prop = aq_inner(self.context).getProperty('qSEO_canonical', None) |
---|
| 84 | if prop is not None: |
---|
| 85 | return prop[len(purl()):] |
---|
| 86 | |
---|
[1720] | 87 | # Fallback for canonical path calculation |
---|
[1671] | 88 | return '/'+'/'.join(purl.getRelativeContentPath(self.context)) |
---|