| 1 |
import Globals |
|---|
| 2 |
from Products.CMFCore.DirectoryView import registerDirectory |
|---|
| 3 |
from AccessControl import allow_module |
|---|
| 4 |
from Products.CMFCore.utils import getToolByName |
|---|
| 5 |
from util import SortedDict |
|---|
| 6 |
from os import path |
|---|
| 7 |
|
|---|
| 8 |
from Products.qSEOptimizer import config |
|---|
| 9 |
|
|---|
| 10 |
try: |
|---|
| 11 |
from Products.qSEOptimizer.interfaces import IKeywords |
|---|
| 12 |
zope_interface_available = True |
|---|
| 13 |
except ImportError: |
|---|
| 14 |
zope_interface_available = False |
|---|
| 15 |
|
|---|
| 16 |
allow_module('Products.qSEOptimizer.util') |
|---|
| 17 |
qSEO_globals = globals() |
|---|
| 18 |
registerDirectory('skins', qSEO_globals) |
|---|
| 19 |
|
|---|
| 20 |
try: |
|---|
| 21 |
|
|---|
| 22 |
from Products.CMFPlone.PloneTool import PloneTool |
|---|
| 23 |
_present = hasattr(PloneTool, "listMetaTags") |
|---|
| 24 |
except ImportError: |
|---|
| 25 |
_present = False |
|---|
| 26 |
|
|---|
| 27 |
if _present: |
|---|
| 28 |
old_lmt = PloneTool.listMetaTags |
|---|
| 29 |
|
|---|
| 30 |
def listMetaTags(self, context): |
|---|
| 31 |
portal_props = getToolByName(context, 'portal_properties') |
|---|
| 32 |
seo_props = getToolByName(portal_props, 'seo_properties', None) |
|---|
| 33 |
if seo_props is None: |
|---|
| 34 |
return old_lmt(self, context) |
|---|
| 35 |
|
|---|
| 36 |
site_props = getToolByName(portal_props, 'site_properties') |
|---|
| 37 |
exposeDCMetaTags = site_props.exposeDCMetaTags |
|---|
| 38 |
|
|---|
| 39 |
metaTags = SortedDict() |
|---|
| 40 |
metaTags.update(old_lmt(self, context)) |
|---|
| 41 |
metadataList = [ |
|---|
| 42 |
('qSEO_Description', 'description'), |
|---|
| 43 |
('qSEO_Keywords', 'keywords'), |
|---|
| 44 |
('qSEO_Robots', 'robots'), |
|---|
| 45 |
('qSEO_Distribution','distribution')] |
|---|
| 46 |
|
|---|
| 47 |
if exposeDCMetaTags: |
|---|
| 48 |
metadataList.append(('qSEO_Distribution', 'DC.distribution')) |
|---|
| 49 |
|
|---|
| 50 |
for accessor, key in metadataList: |
|---|
| 51 |
method = getattr(context, accessor, None) |
|---|
| 52 |
if not callable(method): |
|---|
| 53 |
|
|---|
| 54 |
continue |
|---|
| 55 |
|
|---|
| 56 |
try: |
|---|
| 57 |
value = method() |
|---|
| 58 |
except AttributeError: |
|---|
| 59 |
value = None |
|---|
| 60 |
|
|---|
| 61 |
if not value: |
|---|
| 62 |
continue |
|---|
| 63 |
if isinstance(value, (tuple, list)): |
|---|
| 64 |
value = ', '.join(value) |
|---|
| 65 |
|
|---|
| 66 |
metaTags[key] = value |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
property_prefix = 'qSEO_custom_' |
|---|
| 70 |
for property, value in context.propertyItems(): |
|---|
| 71 |
idx = property.find(property_prefix) |
|---|
| 72 |
if idx == 0 and len(property) > len(property_prefix): |
|---|
| 73 |
metaTags[property[len(property_prefix):]] = value |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
if zope_interface_available: |
|---|
| 77 |
adapter = IKeywords(context, None) |
|---|
| 78 |
if adapter is not None: |
|---|
| 79 |
keywords = adapter.listKeywords() |
|---|
| 80 |
if keywords: |
|---|
| 81 |
metaTags['keywords'] = keywords |
|---|
| 82 |
|
|---|
| 83 |
return metaTags |
|---|
| 84 |
|
|---|
| 85 |
PloneTool.listMetaTags = listMetaTags |
|---|