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