source: products/quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/adapters.py @ 1896

Last change on this file since 1896 was 1855, checked in by mylan, 14 years ago

#156: Refuse from stright depending from IPropertyManager interface and leave only ITraversable one, update adapter registration

  • Property svn:eol-style set to native
File size: 2.9 KB
RevLine 
[387]1import re, commands
[1671]2
3from zope.component import adapts
[387]4from zope.interface import implements
[408]5from zope.component import queryMultiAdapter
[1671]6
7from Acquisition import aq_inner
[1855]8from OFS.interfaces import IPropertyManager
[387]9from Products.CMFCore.utils import getToolByName
10
[1671]11from quintagroup.seoptimizer.util import SortedDict
[1624]12from quintagroup.seoptimizer.interfaces import IMetaKeywords, IMappingMetaTags
[387]13
[1781]14METADATA_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]32class 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
52class 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
72class 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))
Note: See TracBrowser for help on using the repository browser.