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

Last change on this file since 1782 was 1781, checked in by liebster, 14 years ago

Kill accessors usage in 'metatags order' property

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1import re, commands
2
3from zope.component import adapts
4from zope.interface import implements
5from zope.component import queryMultiAdapter
6
7from Acquisition import aq_inner
8from Products.CMFCore.utils import getToolByName
9
10from quintagroup.seoptimizer.util import SortedDict
11from quintagroup.seoptimizer.interfaces import IMetaKeywords, IMappingMetaTags
12
13METADATA_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")])
30
31class MetaKeywordsAdapter(object):
32    implements(IMetaKeywords)
33
34    def __init__(self, context):
35        self.context = context
36
37    def getMetaKeywords(self):
38        """ See interface.
39        """
40        request = self.context.REQUEST
41        meta_keywords = ''
42        filtered_keywords = []
43        portal_props = getToolByName(self.context, 'portal_properties')
44        seo_props = getToolByName(portal_props, 'seo_properties', None)
45        seo_context = queryMultiAdapter((self.context, request), name='seo_context')
46        if seo_context:
47            meta_keywords = list(seo_context.meta_keywords())
48        return ', '.join(meta_keywords)
49
50
51class 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):
60        """ See interface.
61        """
62        metadata_name = SortedDict()
63        if self.seo_props:
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]
68        return metadata_name
69
70
71class 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
82        # Calculate canonical path from qSEO_canonical property
83        prop = aq_inner(self.context).getProperty('qSEO_canonical', None)
84        if prop is not None:
85            return prop[len(purl()):]
86       
87        # Fallback for canonical path calculation
88        return '/'+'/'.join(purl.getRelativeContentPath(self.context))
Note: See TracBrowser for help on using the repository browser.