1 | #from Globals import InitializeClass |
---|
2 | import os |
---|
3 | from Products.CMFCore.ActionProviderBase import ActionProviderBase |
---|
4 | from Products.CMFPlone.PloneFolder import PloneFolder |
---|
5 | from config import TOOL_ID, PROJECTNAME |
---|
6 | from Products.Archetypes.public import * |
---|
7 | from Products.ATContentTypes.content.folder import ATFolder |
---|
8 | from Products.ATContentTypes.content.base import updateActions, updateAliases |
---|
9 | from Products.CMFPlone.interfaces.OrderedContainer import IOrderedContainer |
---|
10 | from Products.CMFCore.ActionInformation import ActionInformation |
---|
11 | from Products.CMFCore.Expression import Expression |
---|
12 | from Products.CMFCore.CMFCorePermissions import ManageProperties |
---|
13 | from Acquisition import aq_base |
---|
14 | from Products.CMFCore.utils import _getViewFor |
---|
15 | from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
---|
16 | from Products.XMLRPCMethod.XMLRPCMethod import RPCThread, XMLRPCMethod |
---|
17 | from Products.CMFCore.utils import getToolByName |
---|
18 | from util import getCanonicalURL |
---|
19 | from zLOG import LOG |
---|
20 | |
---|
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 | |
---|
32 | class PingTool(ATFolder, PloneFolder, ActionProviderBase): #(BaseFolder, PloneFolder, ActionProviderBase): |
---|
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 | content_icon = 'tool.gif' |
---|
45 | immediate_view = 'view' |
---|
46 | default_view = 'view' |
---|
47 | |
---|
48 | ######## |
---|
49 | __implements__ = (IOrderedContainer,) |
---|
50 | _actions = ( ActionInformation( |
---|
51 | id='ping' |
---|
52 | , title='Ping setup' |
---|
53 | , action=Expression( |
---|
54 | text='string:${folder_url}/ping_setup') |
---|
55 | , condition=Expression( |
---|
56 | text='python: folder is object and portal.portal_syndication.isSyndicationAllowed(object)') |
---|
57 | , permissions=(ManageProperties,) |
---|
58 | , category='folder' |
---|
59 | , visible=1 |
---|
60 | ), |
---|
61 | ) |
---|
62 | |
---|
63 | actions = updateActions(ATFolder, |
---|
64 | ({'id' : 'view' \ |
---|
65 | ,'name' : 'View' \ |
---|
66 | ,'action' : 'string:folder_contents' \ |
---|
67 | ,'permissions': ('Manage portal',) \ |
---|
68 | ,'category' :'object' \ |
---|
69 | }, |
---|
70 | ) |
---|
71 | ) |
---|
72 | |
---|
73 | aliases = updateAliases(ATFolder, |
---|
74 | {'(Default)' : 'folder_listing' \ |
---|
75 | ,'view' : 'folder_contents' \ |
---|
76 | }, |
---|
77 | ) |
---|
78 | |
---|
79 | manage_options = ( |
---|
80 | {'label' : 'Overview', 'action' : 'manage_overview'}, |
---|
81 | ) + ATFolder.manage_options |
---|
82 | |
---|
83 | manage_overview = PageTemplateFile(os.path.join('www', 'overview'), globals(), __name__='manage_overview') |
---|
84 | |
---|
85 | def pingFeedReader(self,context): |
---|
86 | """ ping """ |
---|
87 | status = 'success' |
---|
88 | message = 'The servers are pinged' |
---|
89 | if context.meta_type == 'BlogFolder': |
---|
90 | blog = context.simpleblog_tool.getFrontPage(context) |
---|
91 | else: |
---|
92 | blog = context |
---|
93 | |
---|
94 | title = blog.Title() |
---|
95 | portal = context.portal_url.getPortalObject() |
---|
96 | canonical_url = getCanonicalURL(context) |
---|
97 | if canonical_url: |
---|
98 | url = context.portal_url.getRelativeContentURL(blog) |
---|
99 | url = canonical_url + url |
---|
100 | else: |
---|
101 | status = 'failed' |
---|
102 | return status, 'Ping is impossible.See portal_pingtool.' |
---|
103 | |
---|
104 | ps = getToolByName(context,'portal_syndication') |
---|
105 | rss_templates = {'Blog':'','RSS1':'/RSS','RSS2':'/RSS2'} |
---|
106 | pingProp = self.getPingProperties(blog) |
---|
107 | result = 'ok' |
---|
108 | if not pingProp['enable_ping']: |
---|
109 | status = 'failed' |
---|
110 | message = 'Ping is dissabled' |
---|
111 | return status, message |
---|
112 | if ps.isSyndicationAllowed(blog): |
---|
113 | sites = pingProp['ping_sites'] |
---|
114 | if sites: |
---|
115 | for site in sites: |
---|
116 | site_obj = getattr(self,site) |
---|
117 | site_rss_version = rss_templates[site_obj.getRss_version()] |
---|
118 | site_method = site_obj.getMethod_name() |
---|
119 | site_url = site_obj.getUrl() |
---|
120 | |
---|
121 | PingMethod = XMLRPCMethod('myid',"",site_url,site_method,25) |
---|
122 | blog_url = url + site_rss_version |
---|
123 | try: |
---|
124 | #LOG('qPing', 0, title, blog_url, site_url) |
---|
125 | result = PingMethod(title,blog_url) |
---|
126 | except: |
---|
127 | LOG('qPingTool', 100,"The site "+ site_url+" generated error for "+ blog_url, result) |
---|
128 | message += '\n'+ str(result) |
---|
129 | return status, message |
---|
130 | |
---|
131 | |
---|
132 | def setupPing(self,context, |
---|
133 | enable_ping=0, |
---|
134 | ping_sites=(), |
---|
135 | REQUEST=None): |
---|
136 | """ """ |
---|
137 | obj=aq_base(context) |
---|
138 | status = 'success' |
---|
139 | message = 'Your changes have been saved' |
---|
140 | syInfo = getattr(obj, 'syndication_information', None) |
---|
141 | |
---|
142 | if syInfo is None: |
---|
143 | message = 'Syndication is Disabled' |
---|
144 | status = 'failed' |
---|
145 | else: |
---|
146 | syInfo.ping_sites = list(ping_sites) |
---|
147 | syInfo.enable_ping = enable_ping |
---|
148 | |
---|
149 | return status, message |
---|
150 | |
---|
151 | def getPingProperties(self, context): |
---|
152 | """ """ |
---|
153 | obj=aq_base(context) |
---|
154 | |
---|
155 | syInfo = getattr(obj, 'syndication_information', None) |
---|
156 | pingPropeties={} |
---|
157 | pingPropeties['ping_sites'] = getattr(syInfo,'ping_sites',[]) |
---|
158 | pingPropeties['enable_ping'] = getattr(syInfo,'enable_ping',0) |
---|
159 | return pingPropeties |
---|
160 | |
---|
161 | def om_icons(self): |
---|
162 | """ Checking on ZMI for canonical_url setting.""" |
---|
163 | icons = ({'path':'misc_/qPingTool/tool.gif' \ |
---|
164 | ,'alt':self.meta_type \ |
---|
165 | ,'title':self.meta_type \ |
---|
166 | },) |
---|
167 | if not getCanonicalURL(self): |
---|
168 | icons = icons + ({'path':'misc_/PageTemplates/exclamation.gif' \ |
---|
169 | ,'alt':'Error' \ |
---|
170 | ,'title':'PingTool needs setting canonical_url' \ |
---|
171 | },) |
---|
172 | return icons |
---|
173 | |
---|
174 | registerType(PingTool) |
---|