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