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 | |
---|
8 | from Products.qSEOptimizer import qSEO_globals |
---|
9 | |
---|
10 | qSEO_CONTENT = ['File','Document','News Item','BlogEntry'] |
---|
11 | qSEO_FOLDER = [] |
---|
12 | qSEO_TYPES = qSEO_CONTENT + qSEO_FOLDER |
---|
13 | |
---|
14 | def setupSkin(self, out, skinFolder): |
---|
15 | skinstool=getToolByName(self, 'portal_skins') |
---|
16 | |
---|
17 | addDirectoryViews(skinstool, 'skins', qSEO_globals) |
---|
18 | |
---|
19 | for skin in skinstool.getSkinSelections(): |
---|
20 | path = skinstool.getSkinPath(skin) |
---|
21 | path = map( string.strip, string.split( path,',' ) ) |
---|
22 | |
---|
23 | if not skinFolder in path: |
---|
24 | try: |
---|
25 | path.insert( path.index( 'custom')+1, skinFolder ) |
---|
26 | except ValueError: |
---|
27 | path.append(skinFolder) |
---|
28 | path = string.join( path, ', ' ) |
---|
29 | skinstool.addSkinSelection( skin, path ) |
---|
30 | out.write(' Subskin sucessfully installed into skin %s.\n' % skin) |
---|
31 | else: |
---|
32 | out.write(' Subskin was already installed into skin %s.\n' % skin) |
---|
33 | |
---|
34 | def removeSkin(self, skins = []): |
---|
35 | if skins: |
---|
36 | skinstool = getToolByName(self, 'portal_skins') |
---|
37 | for skinName in skinstool.getSkinSelections(): |
---|
38 | path = skinstool.getSkinPath(skinName) |
---|
39 | path = [i.strip() for i in path.split(',')] |
---|
40 | for s in skins: |
---|
41 | if s in path: |
---|
42 | path.remove(s) |
---|
43 | s += '/' |
---|
44 | for layer in path: |
---|
45 | if layer.startswith(s): |
---|
46 | path.remove(layer) |
---|
47 | path = ','.join(path) |
---|
48 | skinstool.addSkinSelection(skinName, path) |
---|
49 | |
---|
50 | def setupActions(self, out): |
---|
51 | # And now update the relevant portal_type actions |
---|
52 | out.write("Inspecting portal_types\n") |
---|
53 | tool = getToolByName(self, 'portal_types') |
---|
54 | for ptype in tool.objectValues(): |
---|
55 | if ptype.getId() in qSEO_TYPES: |
---|
56 | #add the action for viewing versioning |
---|
57 | action = ptype.getActionById( 'seo_properties', default=None ) |
---|
58 | if action is None: |
---|
59 | out.write( ' Added SEO Properties tab for %s\n' % ptype.getId() ) |
---|
60 | ptype.addAction( 'seo_properties' |
---|
61 | , 'SEO Properties' |
---|
62 | , 'string:${object_url}/qseo_properties_edit_form' |
---|
63 | , '' |
---|
64 | , 'Modify portal content' |
---|
65 | , 'object' |
---|
66 | , visible=1 |
---|
67 | ) |
---|
68 | |
---|
69 | |
---|
70 | def install(self): |
---|
71 | out = StringIO() |
---|
72 | |
---|
73 | out.write('Call setupSkin... \n') |
---|
74 | |
---|
75 | mtool = getToolByName(self, 'portal_migration') |
---|
76 | plone_version = mtool.getFileSystemVersion() |
---|
77 | product_path = package_home(qSEO_globals) |
---|
78 | |
---|
79 | skin = 'qSEOptimizer' |
---|
80 | versioned_skin = path_join(product_path, 'skins', skin, plone_version) |
---|
81 | out.write(' Searching for %s... ' % versioned_skin) |
---|
82 | |
---|
83 | if path_exists(versioned_skin): |
---|
84 | out.write('found.\n') |
---|
85 | skin = 'qSEOptimizer/%s' % plone_version |
---|
86 | else: |
---|
87 | out.write("""not found.\n |
---|
88 | Limited functionality mode. |
---|
89 | Upgrade qSEOptimizer product or report to support@quintagroup.com if uprade not available.\n\n""") |
---|
90 | setupSkin(self, out, skin) |
---|
91 | |
---|
92 | out.write('Call setupActions... \n') |
---|
93 | setupActions(self, out) |
---|
94 | |
---|
95 | return out.getvalue() |
---|
96 | |
---|
97 | def uninstall(self): |
---|
98 | removeSkin(self, ('qSEOptimizer',)) |
---|
99 | return 'qSEOptimizer uninstalled successfully.' |
---|