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