[1] | 1 | import string |
---|
| 2 | from App.Common import package_home |
---|
| 3 | from os.path import exists as path_exists, join as path_join |
---|
| 4 | from cStringIO import StringIO |
---|
| 5 | from Products.CMFCore.utils import getToolByName |
---|
| 6 | from Products.CMFCore.DirectoryView import addDirectoryViews |
---|
| 7 | from Products.qSEOptimizer import qSEO_globals |
---|
| 8 | from Products.CMFCore.CMFCorePermissions import ManagePortal |
---|
| 9 | |
---|
| 10 | configlets = ({'id':'qSEOptimizer', |
---|
| 11 | 'name':'Search Engine Optimizer', |
---|
| 12 | 'action':'string:${portal_url}/prefs_seo_setup', |
---|
| 13 | 'condition':'', |
---|
| 14 | 'category':'Products', |
---|
| 15 | 'visible':1, |
---|
| 16 | 'appId':'qSEOptimizer', |
---|
| 17 | 'permission':ManagePortal},) |
---|
| 18 | |
---|
| 19 | qSEO_CONTENT = ['File','Document','News Item','BlogEntry'] |
---|
| 20 | qSEO_FOLDER = [] |
---|
| 21 | qSEO_TYPES = qSEO_CONTENT + qSEO_FOLDER |
---|
| 22 | try: |
---|
| 23 | True |
---|
| 24 | except: |
---|
| 25 | True = 1 |
---|
| 26 | False = 0 |
---|
| 27 | |
---|
| 28 | def setupSkin(self, out, layers): |
---|
| 29 | """Setup skins""" |
---|
| 30 | skinstool=getToolByName(self, 'portal_skins') |
---|
| 31 | addDirectoryViews(skinstool, 'skins', qSEO_globals) |
---|
| 32 | |
---|
| 33 | for skin in skinstool.getSkinSelections(): |
---|
| 34 | modified = False |
---|
| 35 | path = skinstool.getSkinPath(skin) |
---|
| 36 | path = map( string.strip, string.split( path,',' ) ) |
---|
| 37 | for layer in layers: |
---|
| 38 | if not layer in path: |
---|
| 39 | try: |
---|
| 40 | path.insert(path.index('custom')+1, layer ) |
---|
| 41 | except ValueError: |
---|
| 42 | path.append(layer) |
---|
| 43 | modified = True |
---|
| 44 | out.write(' Layer %s sucessfully installed into skin %s.\n' % (layer,skin)) |
---|
| 45 | else: |
---|
| 46 | out.write(' Layer %s was already installed into skin %s.\n' % (layer,skin)) |
---|
| 47 | if modified: |
---|
| 48 | path = string.join( path, ', ' ) |
---|
| 49 | skinstool.addSkinSelection( skin, path ) |
---|
| 50 | |
---|
| 51 | def removeSkin(self, layer): |
---|
| 52 | """Remove layers""" |
---|
| 53 | skinstool = getToolByName(self, 'portal_skins') |
---|
| 54 | for skinName in skinstool.getSkinSelections(): |
---|
| 55 | original_path = skinstool.getSkinPath(skinName) |
---|
| 56 | original_path = [l.strip() for l in original_path.split(',')] |
---|
| 57 | new_path= [] |
---|
| 58 | for l in original_path: |
---|
| 59 | if (l == layer) or (l.startswith(layer+'/')): |
---|
| 60 | continue |
---|
| 61 | new_path.append(l) |
---|
| 62 | skinstool.addSkinSelection(skinName, ','.join(new_path)) |
---|
| 63 | |
---|
| 64 | def setupActions(self, out): |
---|
| 65 | # And now update the relevant portal_type actions |
---|
| 66 | out.write("Inspecting portal_types\n") |
---|
| 67 | tool = getToolByName(self, 'portal_types') |
---|
| 68 | for ptype in tool.objectValues(): |
---|
| 69 | if ptype.getId() in qSEO_TYPES: |
---|
| 70 | #add the action for viewing versioning |
---|
| 71 | action = ptype.getActionById( 'seo_properties', default=None ) |
---|
| 72 | if action is None: |
---|
| 73 | out.write( ' Added SEO Properties tab for %s\n' % ptype.getId() ) |
---|
| 74 | ptype.addAction( 'seo_properties' |
---|
| 75 | , 'SEO Properties' |
---|
| 76 | , 'string:${object_url}/qseo_properties_edit_form' |
---|
| 77 | , '' |
---|
| 78 | , 'Modify portal content' |
---|
| 79 | , 'object' |
---|
| 80 | , visible=1 |
---|
| 81 | ) |
---|
| 82 | def removeActions(self): |
---|
| 83 | # And now update the relevant portal_type actions |
---|
| 84 | tool = getToolByName(self, 'portal_types') |
---|
| 85 | for ptype in tool.objectValues(): |
---|
| 86 | if ptype.getId() in qSEO_TYPES: |
---|
| 87 | #delet the action for viewing versioning |
---|
| 88 | action = ptype.getActionById( 'seo_properties', default=None ) |
---|
| 89 | if action != None: |
---|
| 90 | acts = list(ptype.listActions()) |
---|
| 91 | ptype.deleteActions([acts.index(a) for a in acts if a.getId()=='seo_properties']) |
---|
| 92 | |
---|
| 93 | def install(self): |
---|
| 94 | """Install product""" |
---|
| 95 | out = StringIO() |
---|
| 96 | Layers =[] |
---|
| 97 | mtool = getToolByName(self, 'portal_migration') |
---|
| 98 | plone_version = mtool.getFileSystemVersion() |
---|
| 99 | product_path = package_home(qSEO_globals) |
---|
| 100 | versioned_skin = path_join(product_path, 'skins','qSEOptimizer', plone_version) |
---|
| 101 | |
---|
| 102 | Layers.append('qSEOptimizer') |
---|
| 103 | out.write(' Searching for %s... ' % versioned_skin) |
---|
| 104 | if path_exists(versioned_skin): |
---|
| 105 | out.write('found.\n') |
---|
| 106 | Layers.append('qSEOptimizer/%s' % plone_version) |
---|
| 107 | else: |
---|
| 108 | out.write("""not found.\nLimited functionality mode. Upgrade qSEOptimizer product or report to support@quintagroup.com if uprade not available.\n\n""") |
---|
| 109 | out.write('Call setupSkin... \n') |
---|
| 110 | setupSkin(self, out, Layers) |
---|
| 111 | |
---|
| 112 | out.write('Call setupActions... \n') |
---|
| 113 | setupActions(self, out) |
---|
| 114 | |
---|
| 115 | configTool = getToolByName(self, 'portal_controlpanel', None) |
---|
| 116 | if configTool: |
---|
| 117 | for conf in configlets: |
---|
| 118 | configTool.registerConfiglet(**conf) |
---|
| 119 | out.write('Added configlet %s\n' % conf['id']) |
---|
| 120 | |
---|
| 121 | return out.getvalue() |
---|
| 122 | |
---|
| 123 | def uninstall(self): |
---|
| 124 | """ Uninstall Products """ |
---|
| 125 | out = StringIO() |
---|
| 126 | removeSkin(self, 'qSEOptimizer') |
---|
| 127 | removeActions(self) |
---|
| 128 | |
---|
| 129 | configTool = getToolByName(self, 'portal_controlpanel', None) |
---|
| 130 | if configTool: |
---|
| 131 | for conf in configlets: |
---|
| 132 | try: |
---|
| 133 | configTool.unregisterConfiglet(conf['id']) |
---|
| 134 | except BadRequestException,KeyError: |
---|
| 135 | portal_icons = getToolByName(self,'portal_actionicons') |
---|
| 136 | portal_icons.manage_removeActionIcon(conf['category'],conf['id']) |
---|
| 137 | out.write('Removed configlet %s\n' % conf['id']) |
---|
| 138 | |
---|
| 139 | return 'qSEOptimizer succesfully removed' |
---|