[387] | 1 | import re, commands |
---|
[1671] | 2 | |
---|
| 3 | from zope.component import adapts |
---|
[387] | 4 | from zope.interface import implements |
---|
[1900] | 5 | from zope.component import queryAdapter |
---|
[408] | 6 | from zope.component import queryMultiAdapter |
---|
[1671] | 7 | |
---|
| 8 | from Acquisition import aq_inner |
---|
[1855] | 9 | from OFS.interfaces import IPropertyManager |
---|
[387] | 10 | from Products.CMFCore.utils import getToolByName |
---|
| 11 | |
---|
[1671] | 12 | from quintagroup.seoptimizer.util import SortedDict |
---|
[1624] | 13 | from quintagroup.seoptimizer.interfaces import IMetaKeywords, IMappingMetaTags |
---|
[1900] | 14 | from quintagroup.seoptimizer.browser.seo_configlet import ISEOConfigletSchema |
---|
[387] | 15 | |
---|
[1781] | 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")]) |
---|
[1313] | 33 | |
---|
[1624] | 34 | class MetaKeywordsAdapter(object): |
---|
| 35 | implements(IMetaKeywords) |
---|
[387] | 36 | |
---|
| 37 | def __init__(self, context): |
---|
| 38 | self.context = context |
---|
| 39 | |
---|
[1624] | 40 | def getMetaKeywords(self): |
---|
[1509] | 41 | """ See interface. |
---|
| 42 | """ |
---|
[1624] | 43 | request = self.context.REQUEST |
---|
[1816] | 44 | meta_keywords = [] |
---|
[1624] | 45 | filtered_keywords = [] |
---|
[408] | 46 | seo_context = queryMultiAdapter((self.context, request), name='seo_context') |
---|
[1313] | 47 | if seo_context: |
---|
[1816] | 48 | meta_keywords = list(seo_context['meta_keywords']) |
---|
[1624] | 49 | return ', '.join(meta_keywords) |
---|
[387] | 50 | |
---|
[1313] | 51 | |
---|
| 52 | class MappingMetaTags(object): |
---|
| 53 | implements(IMappingMetaTags) |
---|
| 54 | |
---|
| 55 | def __init__(self, context): |
---|
| 56 | self.context = context |
---|
[1900] | 57 | pps = queryMultiAdapter((self.context, self.context.REQUEST), |
---|
| 58 | name="plone_portal_state") |
---|
| 59 | self.gseo = queryAdapter(pps.portal(), ISEOConfigletSchema) |
---|
[1313] | 60 | |
---|
| 61 | def getMappingMetaTags(self): |
---|
[1509] | 62 | """ See interface. |
---|
| 63 | """ |
---|
[1313] | 64 | metadata_name = SortedDict() |
---|
[1900] | 65 | if self.gseo: |
---|
| 66 | for mt in self.gseo.metatags_order: |
---|
[1781] | 67 | if METADATA_MAPS.has_key(mt): |
---|
| 68 | metadata_name[mt] = METADATA_MAPS[mt] |
---|
[1313] | 69 | return metadata_name |
---|
[1671] | 70 | |
---|
| 71 | |
---|
| 72 | class canonicalPathAdapter(object): |
---|
| 73 | """Adapts base content to canonical path, with taking into consideration |
---|
| 74 | SEO canonical path value. |
---|
| 75 | """ |
---|
| 76 | |
---|
| 77 | def __init__(self, context): |
---|
[1855] | 78 | self.context = aq_inner(context) |
---|
[1671] | 79 | |
---|
| 80 | def canonical_path(self): |
---|
| 81 | purl = getToolByName(self.context,'portal_url') |
---|
| 82 | |
---|
[1720] | 83 | # Calculate canonical path from qSEO_canonical property |
---|
[1855] | 84 | if IPropertyManager.providedBy(self.context): |
---|
| 85 | prop = self.context.getProperty('qSEO_canonical', None) |
---|
| 86 | if prop is not None: |
---|
| 87 | return prop[len(purl()):] |
---|
| 88 | |
---|
[1720] | 89 | # Fallback for canonical path calculation |
---|
[1671] | 90 | return '/'+'/'.join(purl.getRelativeContentPath(self.context)) |
---|