source: products/quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/adapters.py @ 2111

Last change on this file since 2111 was 1794, checked in by liebster, 14 years ago

more clean up

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