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