1 | import re, commands |
---|
2 | from zope.interface import implements |
---|
3 | from zope.component import queryMultiAdapter |
---|
4 | from Products.CMFCore.utils import getToolByName |
---|
5 | |
---|
6 | from quintagroup.seoptimizer.interfaces import IMetaKeywords, IMappingMetaTags |
---|
7 | from quintagroup.seoptimizer.util import SortedDict |
---|
8 | |
---|
9 | |
---|
10 | class MetaKeywordsAdapter(object): |
---|
11 | implements(IMetaKeywords) |
---|
12 | |
---|
13 | def __init__(self, context): |
---|
14 | self.context = context |
---|
15 | |
---|
16 | def getMetaKeywords(self): |
---|
17 | """ See interface. |
---|
18 | """ |
---|
19 | request = self.context.REQUEST |
---|
20 | meta_keywords = '' |
---|
21 | seo_context = queryMultiAdapter((self.context, request), name='seo_context') |
---|
22 | if seo_context: |
---|
23 | meta_keywords = list(seo_context.meta_keywords()) |
---|
24 | return ', '.join(meta_keywords) |
---|
25 | |
---|
26 | |
---|
27 | class MappingMetaTags(object): |
---|
28 | implements(IMappingMetaTags) |
---|
29 | |
---|
30 | def __init__(self, context): |
---|
31 | self.context = context |
---|
32 | self.portal_props = getToolByName(self.context, 'portal_properties') |
---|
33 | self.seo_props = getToolByName(self.portal_props, 'seo_properties', None) |
---|
34 | |
---|
35 | def getMappingMetaTags(self): |
---|
36 | """ See interface. |
---|
37 | """ |
---|
38 | metadata_name = SortedDict() |
---|
39 | if self.seo_props: |
---|
40 | pmn = self.seo_props.getProperty('metatags_order') |
---|
41 | pmn = pmn and pmn or '' |
---|
42 | for mt in [mt.split(' ') for mt in pmn if len(mt.split(' '))==2]: |
---|
43 | metadata_name[mt[0]] = mt[1] |
---|
44 | return metadata_name |
---|