1 | from zope.interface import implements |
---|
2 | from zope.component import queryAdapter |
---|
3 | from zope.component import queryMultiAdapter |
---|
4 | |
---|
5 | from quintagroup.seoptimizer.util import SortedDict |
---|
6 | from quintagroup.seoptimizer.interfaces import IMetaKeywords, IMappingMetaTags |
---|
7 | from quintagroup.seoptimizer.browser.seo_configlet import ISEOConfigletSchema |
---|
8 | |
---|
9 | METADATA_MAPS = dict([ |
---|
10 | ("DC.publisher", "Publisher"), |
---|
11 | ("DC.description", "Description"), |
---|
12 | ("DC.contributors", "Contributors"), |
---|
13 | ("DC.creator", "Creator"), |
---|
14 | ("DC.format", "Format"), |
---|
15 | ("DC.rights", "Rights"), |
---|
16 | ("DC.language", "Language"), |
---|
17 | ("DC.date.modified", "ModificationDate"), |
---|
18 | ("DC.date.created", "CreationDate"), |
---|
19 | ("DC.type", "Type"), |
---|
20 | ("DC.subject", "Subject"), |
---|
21 | ("DC.distribution", "seo_distribution"), |
---|
22 | ("description", "seo_description"), |
---|
23 | ("keywords", "meta_keywords"), |
---|
24 | ("robots", "seo_robots"), |
---|
25 | ("distribution", "seo_distribution")]) |
---|
26 | |
---|
27 | |
---|
28 | class MetaKeywordsAdapter(object): |
---|
29 | implements(IMetaKeywords) |
---|
30 | |
---|
31 | def __init__(self, context): |
---|
32 | self.context = context |
---|
33 | |
---|
34 | def getMetaKeywords(self): |
---|
35 | """ See interface. |
---|
36 | """ |
---|
37 | meta_keywords = [] |
---|
38 | seo_context = queryMultiAdapter((self.context, self.context.REQUEST), |
---|
39 | name='seo_context') |
---|
40 | if seo_context: |
---|
41 | meta_keywords = list(seo_context['meta_keywords']) |
---|
42 | return ', '.join(meta_keywords) |
---|
43 | |
---|
44 | |
---|
45 | class MappingMetaTags(object): |
---|
46 | implements(IMappingMetaTags) |
---|
47 | |
---|
48 | def __init__(self, context): |
---|
49 | self.context = context |
---|
50 | pps = queryMultiAdapter((self.context, self.context.REQUEST), |
---|
51 | name="plone_portal_state") |
---|
52 | self.gseo = queryAdapter(pps.portal(), ISEOConfigletSchema) |
---|
53 | |
---|
54 | def getMappingMetaTags(self): |
---|
55 | """ See interface. |
---|
56 | """ |
---|
57 | metadata_name = SortedDict() |
---|
58 | if self.gseo: |
---|
59 | for mt in self.gseo.metatags_order: |
---|
60 | if mt in METADATA_MAPS: |
---|
61 | metadata_name[mt] = METADATA_MAPS[mt] |
---|
62 | return metadata_name |
---|