[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 | |
---|
[1313] | 13 | |
---|
[1624] | 14 | class MetaKeywordsAdapter(object): |
---|
| 15 | implements(IMetaKeywords) |
---|
[387] | 16 | |
---|
| 17 | def __init__(self, context): |
---|
| 18 | self.context = context |
---|
| 19 | |
---|
[1624] | 20 | def getMetaKeywords(self): |
---|
[1509] | 21 | """ See interface. |
---|
| 22 | """ |
---|
[1624] | 23 | request = self.context.REQUEST |
---|
| 24 | meta_keywords = '' |
---|
| 25 | filtered_keywords = [] |
---|
[387] | 26 | portal_props = getToolByName(self.context, 'portal_properties') |
---|
[1313] | 27 | seo_props = getToolByName(portal_props, 'seo_properties', None) |
---|
[408] | 28 | seo_context = queryMultiAdapter((self.context, request), name='seo_context') |
---|
[1313] | 29 | if seo_context: |
---|
[1624] | 30 | meta_keywords = list(seo_context.meta_keywords()) |
---|
| 31 | return ', '.join(meta_keywords) |
---|
[387] | 32 | |
---|
[1313] | 33 | |
---|
| 34 | class MappingMetaTags(object): |
---|
| 35 | implements(IMappingMetaTags) |
---|
| 36 | |
---|
| 37 | def __init__(self, context): |
---|
| 38 | self.context = context |
---|
| 39 | self.portal_props = getToolByName(self.context, 'portal_properties') |
---|
| 40 | self.seo_props = getToolByName(self.portal_props, 'seo_properties', None) |
---|
| 41 | |
---|
| 42 | def getMappingMetaTags(self): |
---|
[1509] | 43 | """ See interface. |
---|
| 44 | """ |
---|
[1313] | 45 | metadata_name = SortedDict() |
---|
| 46 | if self.seo_props: |
---|
| 47 | pmn = self.seo_props.getProperty('metatags_order') |
---|
| 48 | pmn = pmn and pmn or '' |
---|
| 49 | for mt in [mt.split(' ') for mt in pmn if len(mt.split(' '))==2]: |
---|
| 50 | metadata_name[mt[0]] = mt[1] |
---|
| 51 | return metadata_name |
---|
[1671] | 52 | |
---|
| 53 | |
---|
| 54 | class canonicalPathAdapter(object): |
---|
| 55 | """Adapts base content to canonical path, with taking into consideration |
---|
| 56 | SEO canonical path value. |
---|
| 57 | """ |
---|
| 58 | |
---|
| 59 | def __init__(self, context): |
---|
| 60 | self.context = context |
---|
| 61 | |
---|
| 62 | def canonical_path(self): |
---|
| 63 | purl = getToolByName(self.context,'portal_url') |
---|
| 64 | |
---|
[1720] | 65 | # Calculate canonical path from qSEO_canonical property |
---|
[1671] | 66 | prop = aq_inner(self.context).getProperty('qSEO_canonical', None) |
---|
| 67 | if prop is not None: |
---|
| 68 | return prop[len(purl()):] |
---|
| 69 | |
---|
[1720] | 70 | # Fallback for canonical path calculation |
---|
[1671] | 71 | return '/'+'/'.join(purl.getRelativeContentPath(self.context)) |
---|