1 | ## Script (Python) "listMetaTags" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters= |
---|
8 | ##title=List Dublin Core for '<meta>' tags |
---|
9 | ## |
---|
10 | from DateTime import DateTime |
---|
11 | from Products.CMFCore.utils import getToolByName |
---|
12 | |
---|
13 | site_props = getToolByName(context, 'portal_properties').site_properties |
---|
14 | exposeDCMetaTags = site_props.getProperty('exposeDCMetaTags',True) |
---|
15 | |
---|
16 | metadataList = [ |
---|
17 | # dublic core accessor name, metadata name |
---|
18 | ('qSEO_Description', 'description'), |
---|
19 | ('qSEO_Keywords', 'keywords'), |
---|
20 | ('qSEO_Robots', 'robots'), |
---|
21 | ('qSEO_Distribution','distribution'), |
---|
22 | ] |
---|
23 | |
---|
24 | returnList = [] |
---|
25 | if exposeDCMetaTags: |
---|
26 | metadataList.append(('qSEO_Distribution', 'DC.distribution')) |
---|
27 | metadataList.append(('Description', 'DC.description')) |
---|
28 | metadataList.append(('Subject', 'DC.subject')) |
---|
29 | metadataList.append(('Creator', 'DC.creator')) |
---|
30 | metadataList.append(('Contributors', 'DC.contributors')) |
---|
31 | metadataList.append(('Publisher', 'DC.publisher')) |
---|
32 | metadataList.append(('CreationDate', 'DC.date.created')) |
---|
33 | metadataList.append(('ModificationDate', 'DC.date.modified')) |
---|
34 | metadataList.append(('Type', 'DC.type')) |
---|
35 | metadataList.append(('Format', 'DC.format')) |
---|
36 | metadataList.append(('Language', 'DC.language')) |
---|
37 | metadataList.append(('Rights', 'DC.rights')) |
---|
38 | |
---|
39 | for accessor, key in metadataList: |
---|
40 | method = getattr(context, accessor, None) |
---|
41 | if not callable(method): |
---|
42 | # ups |
---|
43 | continue |
---|
44 | |
---|
45 | # Catch AttributeErrors raised by some AT applications |
---|
46 | try: |
---|
47 | value = method() |
---|
48 | except AttributeError: |
---|
49 | value = None |
---|
50 | |
---|
51 | if not value: |
---|
52 | # no data |
---|
53 | continue |
---|
54 | if accessor == 'Publisher' and value == 'No publisher': |
---|
55 | # No publisher is hardcoded (XXX: still?) |
---|
56 | continue |
---|
57 | if same_type(value, ()) or same_type(value, []): |
---|
58 | # convert a list to a string |
---|
59 | value = ', '.join(value) |
---|
60 | returnList.append( (key, value) ) |
---|
61 | |
---|
62 | # Portions of following code was copy/pasted from the listMetaTags script from |
---|
63 | # CMFDefault. This script is licensed under the ZPL 2.0 as stated here: |
---|
64 | # http://www.zope.org/Resources/ZPL |
---|
65 | # Zope Public License (ZPL) Version 2.0 |
---|
66 | # This software is Copyright (c) Zope Corporation (tm) and Contributors. All rights reserved. |
---|
67 | created = context.CreationDate() |
---|
68 | |
---|
69 | effective = context.EffectiveDate() |
---|
70 | if effective and effective != 'None': |
---|
71 | effective = DateTime(effective) |
---|
72 | else: |
---|
73 | effective = None |
---|
74 | |
---|
75 | expires = context.ExpirationDate() |
---|
76 | if expires and expires != 'None': |
---|
77 | expires = DateTime(expires) |
---|
78 | else: |
---|
79 | expires = None |
---|
80 | |
---|
81 | # Filter out DWIMish artifacts on effective / expiration dates |
---|
82 | eff_str = ( effective and effective.year() > 1000 |
---|
83 | and effective != created ) and effective.Date() or '' |
---|
84 | exp_str = ( expires and expires.year() < 9000 ) and expires.Date() or '' |
---|
85 | |
---|
86 | if exp_str or exp_str: |
---|
87 | returnList.append( ( 'DC.date.valid_range' |
---|
88 | , '%s - %s' % ( eff_str, exp_str ) ) ) |
---|
89 | |
---|
90 | return returnList |
---|