| 1 | import string |
|---|
| 2 | from cStringIO import StringIO |
|---|
| 3 | from Products.CMFCore.utils import getToolByName |
|---|
| 4 | from Products.CMFCore.DirectoryView import addDirectoryViews |
|---|
| 5 | from Products.qPloneGoogleSitemaps import qPGS_globals |
|---|
| 6 | from Products.CMFCore.CMFCorePermissions import ManagePortal |
|---|
| 7 | from OFS.ObjectManager import BadRequestException |
|---|
| 8 | |
|---|
| 9 | configlets = ({'id':'qPloneGoogleSitemaps', |
|---|
| 10 | 'name':'Google Sitemaps', |
|---|
| 11 | 'action':'string:${portal_url}/prefs_gsm_overview', |
|---|
| 12 | 'condition':'', |
|---|
| 13 | 'category':'Products', |
|---|
| 14 | 'visible':1, |
|---|
| 15 | 'appId':'qPloneGoogleSitemaps', |
|---|
| 16 | 'permission':ManagePortal, |
|---|
| 17 | 'imageUrl':'qplonegooglesitemaps.gif'},) |
|---|
| 18 | |
|---|
| 19 | def setupSkin(self, out, skinFolder): |
|---|
| 20 | skinstool=getToolByName(self, 'portal_skins') |
|---|
| 21 | |
|---|
| 22 | addDirectoryViews(skinstool, 'skins', qPGS_globals) |
|---|
| 23 | |
|---|
| 24 | for skin in skinstool.getSkinSelections(): |
|---|
| 25 | path = skinstool.getSkinPath(skin) |
|---|
| 26 | path = map( string.strip, string.split( path,',' ) ) |
|---|
| 27 | |
|---|
| 28 | if not skinFolder in path: |
|---|
| 29 | try: |
|---|
| 30 | path.insert( path.index( 'custom')+1, skinFolder ) |
|---|
| 31 | except ValueError: |
|---|
| 32 | path.append(skinFolder) |
|---|
| 33 | path = string.join( path, ', ' ) |
|---|
| 34 | skinstool.addSkinSelection( skin, path ) |
|---|
| 35 | out.write(' %s layer sucessfully installed into skin %s.\n' % (skinFolder, skin)) |
|---|
| 36 | else: |
|---|
| 37 | out.write(' %s layer was already installed into skin %s.\n' % (skinFolder, skin)) |
|---|
| 38 | |
|---|
| 39 | def install(self): |
|---|
| 40 | """ Install qPloneGoogleSitemaps """ |
|---|
| 41 | out = StringIO() |
|---|
| 42 | if not hasattr(self.portal_properties, 'googlesitemap_properties'): |
|---|
| 43 | self.portal_properties.addPropertySheet('googlesitemap_properties', 'Google SiteMap properties') |
|---|
| 44 | |
|---|
| 45 | props = self.portal_properties.googlesitemap_properties |
|---|
| 46 | portalTypes = ('Plone Folder', 'ATFolder') |
|---|
| 47 | new_portalTypes = ['Document', ] |
|---|
| 48 | sitemap_properties = ( |
|---|
| 49 | ('portalTypes', 'lines', new_portalTypes), |
|---|
| 50 | ('states', 'lines', ['published', ]), |
|---|
| 51 | ('blackout_list', 'lines',[]), |
|---|
| 52 | ('reg_exp', 'lines',[]), |
|---|
| 53 | ('urls', 'lines',[]), |
|---|
| 54 | ('verification_filename','string','') |
|---|
| 55 | ) |
|---|
| 56 | |
|---|
| 57 | types = self.portal_types.listContentTypes( by_metatype=1 ) |
|---|
| 58 | for prop_id, prop_type, prop_value in sitemap_properties: |
|---|
| 59 | if not hasattr(props, prop_id): |
|---|
| 60 | props._setProperty(prop_id, prop_value, prop_type) |
|---|
| 61 | |
|---|
| 62 | configTool = getToolByName(self, 'portal_controlpanel', None) |
|---|
| 63 | if configTool: |
|---|
| 64 | for conf in configlets: |
|---|
| 65 | configTool.registerConfiglet(**conf) |
|---|
| 66 | out.write('Added configlet %s\n' % conf['id']) |
|---|
| 67 | |
|---|
| 68 | out.write('Call setupSkin... \n') |
|---|
| 69 | setupSkin(self, out, 'qPloneGoogleSitemaps') |
|---|
| 70 | |
|---|
| 71 | return out.getvalue() |
|---|
| 72 | |
|---|
| 73 | def uninstall(self): |
|---|
| 74 | """ Uninstall qPloneGoogleSitemaps """ |
|---|
| 75 | out = StringIO() |
|---|
| 76 | |
|---|
| 77 | props = getToolByName(self,'portal_properties') |
|---|
| 78 | try: |
|---|
| 79 | props.manage_delObjects(['googlesitemap_properties',]) |
|---|
| 80 | except BadRequestException: pass |
|---|
| 81 | |
|---|
| 82 | configTool = getToolByName(self, 'portal_controlpanel', None) |
|---|
| 83 | if configTool: |
|---|
| 84 | for conf in configlets: |
|---|
| 85 | try: |
|---|
| 86 | configTool.unregisterConfiglet(conf['id']) |
|---|
| 87 | except BadRequestException,KeyError: |
|---|
| 88 | portal_icons = getToolByName(self,'portal_actionicons') |
|---|
| 89 | portal_icons.manage_removeActionIcon(conf['category'],conf['id']) |
|---|
| 90 | out.write('Removed configlet %s\n' % conf['id']) |
|---|
| 91 | |
|---|
| 92 | return out.getvalue() |
|---|