source: products/qSEOptimizer/tags/1.0.0/__init__.py @ 1

Last change on this file since 1 was 1, checked in by myroslav, 18 years ago

Building directory structure

File size: 1.8 KB
Line 
1import Globals
2from Products.CMFCore.DirectoryView import registerDirectory
3from AccessControl import allow_module
4from Products.CMFCore.utils import getToolByName
5from util import SortedDict
6from os import path
7import config
8
9
10allow_module('Products.qSEOptimizer.util')
11qSEO_globals = globals()
12registerDirectory('skins', qSEO_globals)
13
14
15try:
16    # for Plone-2.1 and higher
17    from Products.CMFPlone.PloneTool import PloneTool
18    _present = hasattr(PloneTool, "listMetaTags")
19except ImportError:
20    _present = False
21
22if _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
Note: See TracBrowser for help on using the repository browser.