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

Last change on this file since 1752 was 1742, checked in by chervol, 14 years ago

removed the keywords filtering check and global keywords dependency

  • Property svn:eol-style set to native
File size: 2.3 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        portal_props = getToolByName(self.context, 'portal_properties')
27        seo_props = getToolByName(portal_props, 'seo_properties', None)
28        seo_context = queryMultiAdapter((self.context, request), name='seo_context')
29        if seo_context:
30            meta_keywords = list(seo_context.meta_keywords())
31        return ', '.join(meta_keywords)
32
33
34class 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):
43        """ See interface.
44        """
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
52
53
54class 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
65        # Calculate canonical path from qSEO_canonical property
66        prop = aq_inner(self.context).getProperty('qSEO_canonical', None)
67        if prop is not None:
68            return prop[len(purl()):]
69       
70        # Fallback for canonical path calculation
71        return '/'+'/'.join(purl.getRelativeContentPath(self.context))
Note: See TracBrowser for help on using the repository browser.