[1] | 1 | import os |
---|
[198] | 2 | from Acquisition import aq_base |
---|
| 3 | from zLOG import LOG |
---|
| 4 | from zope.interface import implements |
---|
| 5 | from AccessControl import ClassSecurityInfo |
---|
| 6 | from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
---|
| 7 | from Products.Archetypes.public import * |
---|
[1] | 8 | from Products.CMFCore.ActionProviderBase import ActionProviderBase |
---|
[198] | 9 | from Products.CMFCore.permissions import ManagePortal |
---|
| 10 | from Products.CMFCore.utils import getToolByName |
---|
[1] | 11 | from Products.ATContentTypes.content.folder import ATFolder |
---|
| 12 | from Products.CMFPlone.interfaces.OrderedContainer import IOrderedContainer |
---|
[198] | 13 | from Products.CMFPlone.PloneFolder import PloneFolder |
---|
[1] | 14 | from Products.XMLRPCMethod.XMLRPCMethod import RPCThread, XMLRPCMethod |
---|
| 15 | |
---|
[225] | 16 | from Products.qPingTool import qPingToolMessageFactory as _ |
---|
[198] | 17 | from interfaces import IPingTool |
---|
| 18 | from adapter import ICanonicalURL |
---|
| 19 | from config import PROJECTNAME |
---|
| 20 | |
---|
[1] | 21 | _marker = [] |
---|
| 22 | |
---|
| 23 | def modify_fti(fti): |
---|
| 24 | fti['title'] = 'Portal Ping Tool' |
---|
| 25 | fti['allowed_content_types'] = ('PingInfo',) |
---|
| 26 | fti['filter_content_types'] = 1 |
---|
| 27 | #fti['icon'] = 'tool.gif' |
---|
| 28 | #fti['immediate_view'] = 'view' |
---|
| 29 | #fti['default_view'] = 'view' |
---|
| 30 | |
---|
| 31 | |
---|
[198] | 32 | class PingTool(ATFolder, PloneFolder): |
---|
[1] | 33 | """ |
---|
| 34 | |
---|
[198] | 35 | >>> IPingTool.implementedBy(PingTool) |
---|
| 36 | True |
---|
| 37 | """ |
---|
| 38 | security = ClassSecurityInfo() |
---|
[1] | 39 | |
---|
[198] | 40 | implements(IPingTool) |
---|
[1] | 41 | __implements__ = (IOrderedContainer,) |
---|
| 42 | |
---|
[198] | 43 | archetype_name = portal_type = 'PingTool' |
---|
[1] | 44 | manage_options = ( |
---|
| 45 | {'label' : 'Overview', 'action' : 'manage_overview'}, |
---|
| 46 | ) + ATFolder.manage_options |
---|
| 47 | |
---|
[208] | 48 | manage_overview = PageTemplateFile(os.path.join('www', 'overview'), globals(), __name__='manage_overview') |
---|
[1] | 49 | |
---|
[198] | 50 | def om_icons(self): |
---|
| 51 | """ Checking on ZMI for canonical_url setting.""" |
---|
| 52 | icons = ({'path':'misc_/qPingTool/tool.gif' \ |
---|
| 53 | ,'alt':self.meta_type \ |
---|
| 54 | ,'title':self.meta_type \ |
---|
| 55 | },) |
---|
| 56 | if not ICanonicalURL(self).getCanonicalURL(): |
---|
| 57 | icons = icons + ({'path':'misc_/PageTemplates/exclamation.gif' \ |
---|
| 58 | ,'alt':'Error' \ |
---|
| 59 | ,'title':'PingTool needs setting canonical_url' \ |
---|
| 60 | },) |
---|
| 61 | return icons |
---|
| 62 | |
---|
| 63 | security.declareProtected(ManagePortal, 'pingFeedReader') |
---|
[1] | 64 | def pingFeedReader(self,context): |
---|
| 65 | """ ping """ |
---|
[198] | 66 | status = 'failed' |
---|
[210] | 67 | pingProp = self.getPingProperties(context) |
---|
[198] | 68 | if not pingProp['enable_ping']: |
---|
[225] | 69 | message = _(u'Ping is dissabled.') |
---|
[198] | 70 | return status, message |
---|
[215] | 71 | canonical_url = ICanonicalURL(self).getCanonicalURL() |
---|
| 72 | if not canonical_url: |
---|
[225] | 73 | return status, _(u'Ping is impossible.Setup canonical_url.') |
---|
[1] | 74 | ps = getToolByName(context,'portal_syndication') |
---|
[210] | 75 | if ps.isSyndicationAllowed(context): |
---|
[1] | 76 | sites = pingProp['ping_sites'] |
---|
[225] | 77 | message = _(u'Select servers.') |
---|
[210] | 78 | for site in sites: |
---|
| 79 | status = 'success' |
---|
[225] | 80 | message = _(u'The servers are pinged.') |
---|
[215] | 81 | site_obj = getattr(self, site) |
---|
| 82 | site_method = site_obj.getMethod_name() |
---|
| 83 | site_url = site_obj.getUrl() |
---|
[210] | 84 | PingMethod = XMLRPCMethod('myid', "", site_url, site_method, 25) |
---|
| 85 | title = context.Title() |
---|
[215] | 86 | rss_version = site_obj.getRss_version() |
---|
| 87 | ping_url = pingProp['ping_'+rss_version] |
---|
[210] | 88 | try: |
---|
| 89 | result_ping = PingMethod(title, ping_url) |
---|
| 90 | result = result_ping['message'] |
---|
| 91 | except: |
---|
| 92 | result = 'The site %s generated error for %s.' % (site_url, ping_url) |
---|
| 93 | LOG('qPingTool', 100, result) |
---|
| 94 | message += '\nReturned message from %s: %s' % (site_url, str(result)) |
---|
[198] | 95 | else: |
---|
| 96 | message = 'The %s is not syndication allowed' % url |
---|
[1] | 97 | return status, message |
---|
| 98 | |
---|
[198] | 99 | security.declareProtected(ManagePortal, 'setupPing') |
---|
[1] | 100 | def setupPing(self,context, |
---|
| 101 | enable_ping=0, |
---|
| 102 | ping_sites=(), |
---|
[215] | 103 | ping_Weblog='', |
---|
| 104 | ping_RSS1='', |
---|
| 105 | ping_RSS2='', |
---|
[1] | 106 | REQUEST=None): |
---|
| 107 | """ """ |
---|
| 108 | obj=aq_base(context) |
---|
| 109 | status = 'success' |
---|
[225] | 110 | message = _(u'Changes saved.') |
---|
[1] | 111 | syInfo = getattr(obj, 'syndication_information', None) |
---|
| 112 | |
---|
| 113 | if syInfo is None: |
---|
[225] | 114 | message = _(u'Syndication is Disabled') |
---|
[1] | 115 | status = 'failed' |
---|
| 116 | else: |
---|
| 117 | syInfo.ping_sites = list(ping_sites) |
---|
| 118 | syInfo.enable_ping = enable_ping |
---|
[215] | 119 | syInfo.ping_Weblog = ping_Weblog |
---|
| 120 | syInfo.ping_RSS1 = ping_RSS1 |
---|
| 121 | syInfo.ping_RSS2 = ping_RSS2 |
---|
| 122 | |
---|
[1] | 123 | return status, message |
---|
| 124 | |
---|
[198] | 125 | security.declareProtected(ManagePortal, 'getPingProperties') |
---|
[1] | 126 | def getPingProperties(self, context): |
---|
| 127 | """ """ |
---|
| 128 | obj=aq_base(context) |
---|
| 129 | syInfo = getattr(obj, 'syndication_information', None) |
---|
[215] | 130 | pingProperties={} |
---|
| 131 | pingProperties['ping_sites'] = getattr(syInfo, 'ping_sites', []) |
---|
| 132 | pingProperties['enable_ping'] = getattr(syInfo, 'enable_ping', 0) |
---|
[1] | 133 | |
---|
[215] | 134 | pingProperties['ping_Weblog'] = getattr(syInfo, 'ping_Weblog', '') |
---|
| 135 | if not pingProperties['ping_Weblog']: |
---|
| 136 | pingProperties['ping_Weblog'] = self.getPingDefaultUrl(context, 'Weblog') |
---|
| 137 | |
---|
| 138 | pingProperties['ping_RSS1'] = getattr(syInfo, 'ping_RSS1', '') |
---|
| 139 | if not pingProperties['ping_RSS1']: |
---|
| 140 | pingProperties['ping_RSS1'] = self.getPingDefaultUrl(context, 'RSS1') |
---|
| 141 | |
---|
| 142 | pingProperties['ping_RSS2'] = getattr(syInfo, 'ping_RSS2', '') |
---|
| 143 | if not pingProperties['ping_RSS2']: |
---|
| 144 | pingProperties['ping_RSS2'] = self.getPingDefaultUrl(context, 'RSS2') |
---|
| 145 | |
---|
| 146 | return pingProperties |
---|
| 147 | |
---|
| 148 | security.declareProtected(ManagePortal, 'getPingDefaultUrl') |
---|
| 149 | def getPingDefaultUrl(self, context, rss_version='Weblog'): |
---|
[210] | 150 | rss_templates = {'Weblog':'','RSS1':'/RSS','RSS2':'/RSS2'} |
---|
| 151 | url = getToolByName(context, 'portal_url').getRelativeContentURL(context) |
---|
[215] | 152 | canonical_url = ICanonicalURL(self).getCanonicalURL() |
---|
[210] | 153 | ping_url = '' |
---|
[215] | 154 | if canonical_url: |
---|
| 155 | if not canonical_url[-1] == '/': |
---|
| 156 | canonical_url += '/' |
---|
| 157 | url = canonical_url + url |
---|
| 158 | site_rss_version = rss_templates[rss_version] |
---|
[210] | 159 | ping_url = url + site_rss_version |
---|
| 160 | return ping_url |
---|
| 161 | |
---|
[198] | 162 | registerType(PingTool, PROJECTNAME) |
---|