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