############################################################################## # # Copyright (c) 2005 CMFonFive Contributors. All rights reserved. # # This software is distributed under the terms of the Zope Public # License (ZPL) v2.1. See COPYING.txt for more information. # ########################################################################### """ Five actions tool. $Id$ """ from AccessControl import ClassSecurityInfo from Acquisition import aq_base from Globals import InitializeClass from OFS.SimpleItem import SimpleItem from Products.CMFCore.ActionInformation import ActionInformation from Products.CMFCore.ActionProviderBase import ActionProviderBase from Products.CMFCore.Expression import Expression from Products.CMFCore.utils import UniqueObject from zope.app.publisher.browser.globalbrowsermenuservice import \ globalBrowserMenuService from globalbrowsermenuservice import getMenu from Products.Five import security import zope.thread class FiveActionsTool( UniqueObject, SimpleItem, ActionProviderBase ): """ Links content to discussions. """ __implements__ = (ActionProviderBase.__implements__) id = 'portal_fiveactions' meta_type = 'Five Actions Tool' security = ClassSecurityInfo() def getReqestURL(self): return self.REQUEST.URL security.declarePrivate('listActions') def listActions(self, info=None, object=None): """ List all the actions defined by a provider. """ # Necessary to make the Request look like a Zope3 request self.REQUEST.getURL = self.getReqestURL if object is None: object = info.content actions = [] for mid in globalBrowserMenuService._registry.keys(): menu = getMenu(mid, object, self.REQUEST) for entry in menu: # The action needs a unique name, so I'll build one # from the object_id and the action url. That is sure # to be unique. action = str(entry['action']) if object is None: act_id = 'action_%s' % action else: act_id = 'action_%s_%s' % (object.getId(), action) if entry['filter'] is None: filter = None else: filter = Expression(text=str(entry['filter'])) act = ActionInformation(id=act_id, title=str(entry['title']), action=Expression(text='string:%s' % action), condition=filter, category=str(mid), visible=1) actions.append(act) return actions or () InitializeClass( FiveActionsTool )