[1] | 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 | import config |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | allow_module('Products.qSEOptimizer.util') |
---|
| 11 | qSEO_globals = globals() |
---|
| 12 | registerDirectory('skins', qSEO_globals) |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | try: |
---|
| 16 | # for Plone-2.1 and higher |
---|
| 17 | from Products.CMFPlone.PloneTool import PloneTool |
---|
| 18 | _present = hasattr(PloneTool, "listMetaTags") |
---|
| 19 | except ImportError: |
---|
| 20 | _present = False |
---|
| 21 | |
---|
| 22 | if _present: |
---|
| 23 | old_lmt = PloneTool.listMetaTags |
---|
| 24 | |
---|
| 25 | def listMetaTags(self, context): |
---|
| 26 | site_props = getToolByName(context, 'portal_properties').site_properties |
---|
| 27 | exposeDCMetaTags = site_props.exposeDCMetaTags |
---|
| 28 | |
---|
| 29 | metaTags = SortedDict() |
---|
| 30 | metaTags.update(old_lmt(self, context)) |
---|
| 31 | metadataList = [ |
---|
| 32 | ('qSEO_Description', 'description'), |
---|
| 33 | ('qSEO_Keywords', 'keywords'), |
---|
| 34 | ('qSEO_Robots', 'robots'), |
---|
| 35 | ('qSEO_Distribution','distribution')] |
---|
| 36 | |
---|
| 37 | if exposeDCMetaTags: |
---|
| 38 | metadataList.append(('qSEO_Distribution', 'DC.distribution')) |
---|
| 39 | for accessor, key in metadataList: |
---|
| 40 | method = getattr(context, accessor, None) |
---|
| 41 | if not callable(method): |
---|
| 42 | # ups |
---|
| 43 | continue |
---|
| 44 | # Catch AttributeErrors raised by some AT applications |
---|
| 45 | try: |
---|
| 46 | value = method() |
---|
| 47 | except AttributeError: |
---|
| 48 | value = None |
---|
| 49 | |
---|
| 50 | if not value: |
---|
| 51 | # no data |
---|
| 52 | continue |
---|
| 53 | if ( type(value) == tuple ) or ( type(value) == list ): |
---|
| 54 | # convert a list to a string |
---|
| 55 | value = ', '.join(value) |
---|
| 56 | metaTags[key] = value |
---|
| 57 | |
---|
| 58 | return metaTags |
---|
| 59 | |
---|
| 60 | PloneTool.listMetaTags = listMetaTags |
---|