1 | # from Globals import InitializeClass |
---|
2 | from Products.CMFCore.ActionProviderBase import ActionProviderBase |
---|
3 | from Products.CMFPlone.PloneFolder import PloneFolder |
---|
4 | from config import TOOL_ID, PROJECTNAME |
---|
5 | from Products.Archetypes.public import * |
---|
6 | from Products.CMFPlone.interfaces.OrderedContainer import IOrderedContainer |
---|
7 | from Products.CMFCore.ActionInformation import ActionInformation |
---|
8 | from Products.CMFCore.Expression import Expression |
---|
9 | from Products.CMFCore.CMFCorePermissions import ManageProperties |
---|
10 | from Acquisition import aq_base |
---|
11 | |
---|
12 | from Products.XMLRPCMethod.XMLRPCMethod import RPCThread, XMLRPCMethod |
---|
13 | from Products.CMFCore.utils import getToolByName |
---|
14 | from zLOG import LOG |
---|
15 | |
---|
16 | _marker = [] |
---|
17 | def modify_fti(fti): |
---|
18 | fti['title'] = 'Portal Ping Tool' |
---|
19 | fti['allowed_content_types'] = ('PingInfo',) |
---|
20 | fti['filter_content_types'] = 1 |
---|
21 | fti['icon'] = 'tool.gif' |
---|
22 | actions = ( |
---|
23 | { 'id': 'view', |
---|
24 | 'name': 'View', |
---|
25 | 'action': 'string:folder_contents', |
---|
26 | 'permissions': ('Manage portal',), |
---|
27 | 'category':'object', |
---|
28 | }, ) |
---|
29 | fti['actions']=tuple(actions) |
---|
30 | |
---|
31 | |
---|
32 | class PingTool(BaseFolder, PloneFolder, ActionProviderBase): #, BaseFolder): |
---|
33 | """This tool serve for operation with ActionInfo objects |
---|
34 | """ |
---|
35 | |
---|
36 | schema = BaseSchema |
---|
37 | filter_content_types = 1 |
---|
38 | allowed_content_types = ['PingInfo'] |
---|
39 | global_allowed = 0 |
---|
40 | |
---|
41 | meta_type = archetype_name = portal_type = 'PingTool' |
---|
42 | |
---|
43 | |
---|
44 | __implements__ = (IOrderedContainer,) |
---|
45 | _actions = ( ActionInformation( |
---|
46 | id='ping' |
---|
47 | , title='Ping setup' |
---|
48 | , action=Expression( |
---|
49 | text='string:${folder_url}/ping_setup') |
---|
50 | , condition=Expression( |
---|
51 | text='python: folder==object and portal.portal_syndication.isSyndicationAllowed(object)') |
---|
52 | , permissions=(ManageProperties,) |
---|
53 | , category='folder' |
---|
54 | , visible=1 |
---|
55 | ) |
---|
56 | , |
---|
57 | ) |
---|
58 | |
---|
59 | |
---|
60 | def pingFeedReader(self,context): |
---|
61 | """ ping """ |
---|
62 | status = 'success' |
---|
63 | message = 'The servers are pinged' |
---|
64 | blog = context.simpleblog_tool.getFrontPage(context) |
---|
65 | title = blog.Title() |
---|
66 | portal = context.portal_url.getPortalObject() |
---|
67 | canonical_url = portal.getProperty('canonical_url', None) |
---|
68 | if canonical_url: |
---|
69 | #return "failure", "Please setup 'canonical_url' property for your Plone site" |
---|
70 | url = context.portal_url.getRelativeContentURL(blog) |
---|
71 | url = canonical_url + url |
---|
72 | else: |
---|
73 | url = blog.absolute_url() |
---|
74 | ps = getToolByName(context,'portal_syndication') |
---|
75 | rss_templates = {'Blog':'','RSS1':'/RSS','RSS2':'/RSS2'} |
---|
76 | pingProp = self.getPingProperties(blog) |
---|
77 | result = 'ok' |
---|
78 | if not pingProp['enable_ping']: |
---|
79 | message = 'Ping is dissabled' |
---|
80 | return status, message |
---|
81 | if ps.isSyndicationAllowed(blog): |
---|
82 | sites = pingProp['ping_sites'] |
---|
83 | if sites: |
---|
84 | for site in sites: |
---|
85 | site_obj = getattr(self,site) |
---|
86 | site_rss_version = rss_templates[site_obj.getRss_version()] |
---|
87 | site_method = site_obj.getMethod_name() |
---|
88 | site_url = site_obj.getUrl() |
---|
89 | |
---|
90 | PingMethod = XMLRPCMethod('myid',"",site_url,site_method,25) |
---|
91 | blog_url = url + site_rss_version |
---|
92 | try: |
---|
93 | #LOG('qPing', 0, title, blog_url, site_url) |
---|
94 | result = PingMethod(title,blog_url) |
---|
95 | except: |
---|
96 | LOG('qPingTool', 100,"The site "+ site_url+" generated error for "+ blog_url, result) |
---|
97 | message += '\n'+ str(result) |
---|
98 | return status, message |
---|
99 | |
---|
100 | |
---|
101 | def setupPing(self,context, |
---|
102 | enable_ping=0, |
---|
103 | ping_sites=(), |
---|
104 | REQUEST=None): |
---|
105 | """ """ |
---|
106 | obj=aq_base(context) |
---|
107 | status = 'success' |
---|
108 | message = 'Your changes have been saved' |
---|
109 | |
---|
110 | syInfo = getattr(obj, 'syndication_information', None) |
---|
111 | |
---|
112 | if syInfo is None: |
---|
113 | message = 'Syndication is Disabled' |
---|
114 | status = 'failed' |
---|
115 | syInfo.ping_sites = list(ping_sites) |
---|
116 | syInfo.enable_ping = enable_ping |
---|
117 | return status, message |
---|
118 | |
---|
119 | def getPingProperties(self, context): |
---|
120 | """ """ |
---|
121 | obj=aq_base(context) |
---|
122 | |
---|
123 | syInfo = getattr(obj, 'syndication_information', None) |
---|
124 | pingPropeties={} |
---|
125 | pingPropeties['ping_sites'] = getattr(syInfo,'ping_sites',[]) |
---|
126 | pingPropeties['enable_ping'] = getattr(syInfo,'enable_ping',0) |
---|
127 | return pingPropeties |
---|
128 | |
---|
129 | registerType(PingTool) |
---|