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