[1] | 1 | ## Script (Python) "prefs_seo_config" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters= portalTypes=[], exposeDCMetaTags=None, additionalKeywords=[], default_custom_metatags=[] |
---|
| 8 | ##title=add action tab for selected portal types |
---|
| 9 | ## |
---|
| 10 | from Products.CMFCore.utils import getToolByName |
---|
| 11 | |
---|
| 12 | portal_props = getToolByName(context, 'portal_properties') |
---|
| 13 | site_props = getToolByName(portal_props, 'site_properties') |
---|
| 14 | seo_props = getToolByName(portal_props, 'seo_properties') |
---|
| 15 | site_props.manage_changeProperties(exposeDCMetaTags=exposeDCMetaTags) |
---|
| 16 | seo_props.manage_changeProperties(additional_keywords=additionalKeywords) |
---|
| 17 | seo_props.manage_changeProperties(default_custom_metatags=default_custom_metatags) |
---|
| 18 | |
---|
| 19 | pt = getToolByName(context, 'portal_types') |
---|
| 20 | for ptype in pt.objectValues(): |
---|
| 21 | try: |
---|
| 22 | #for Plone-2.5 and higher |
---|
| 23 | acts = filter(lambda x: x.id == 'seo_properties', ptype.listActions()) |
---|
| 24 | action = acts and acts[0] or None |
---|
| 25 | except AttributeError: |
---|
| 26 | action = ptype.getActionById('seo_properties', default=None ) |
---|
| 27 | |
---|
| 28 | if ptype.getId() in portalTypes: |
---|
| 29 | if action is None: |
---|
| 30 | ptype.addAction('seo_properties', |
---|
| 31 | 'SEO Properties', |
---|
| 32 | 'string:${object_url}/qseo_properties_edit_form', |
---|
| 33 | '', |
---|
| 34 | 'Modify portal content', |
---|
| 35 | 'object', |
---|
| 36 | visible=1) |
---|
| 37 | else: |
---|
| 38 | if action !=None: |
---|
| 39 | actions = list(ptype.listActions()) |
---|
| 40 | ptype.deleteActions([actions.index(a) for a in actions if a.getId()=='seo_properties']) |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | msg = "Search Engine Optimizer configuration updated." |
---|
| 44 | try: |
---|
| 45 | context.plone_utils.addPortalMessage(msg) |
---|
| 46 | return state |
---|
| 47 | except AttributeError: |
---|
| 48 | return state.set(context=context, portal_status_message=msg) |
---|