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