1 | import urllib |
---|
2 | try: |
---|
3 | import hashlib as md5 |
---|
4 | md5.md5 |
---|
5 | except ImportError: |
---|
6 | import md5 |
---|
7 | |
---|
8 | from Acquisition import aq_inner |
---|
9 | from AccessControl import getSecurityManager |
---|
10 | from Products.CMFPlone.utils import getToolByName |
---|
11 | from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
---|
12 | from plone.app.layout.viewlets import comments |
---|
13 | |
---|
14 | |
---|
15 | class CommentsViewlet(comments.CommentsViewlet): |
---|
16 | """A custom version of the comments viewlet |
---|
17 | """ |
---|
18 | render = ViewPageTemplateFile('comments.pt') |
---|
19 | |
---|
20 | def is_moderation_enabled(self): |
---|
21 | """ Returns a boolean indicating whether the user has enabled |
---|
22 | moderation in the qPloneComments configlet |
---|
23 | """ |
---|
24 | portal_properties = getToolByName(self.context, 'portal_properties') |
---|
25 | try: |
---|
26 | return portal_properties.qPloneComments.getProperty( |
---|
27 | 'enable_moderation', None) |
---|
28 | except AttributeError: |
---|
29 | return False |
---|
30 | |
---|
31 | def can_moderate(self): |
---|
32 | """ Returns a boolean indicating whether the user has the |
---|
33 | 'Moderate Discussion' permission |
---|
34 | """ |
---|
35 | return getSecurityManager().checkPermission('Moderate Discussion', |
---|
36 | aq_inner(self.context)) |
---|
37 | |
---|
38 | def getGravatar(self, reply): |
---|
39 | purl = getToolByName(self.context, 'portal_url') |
---|
40 | mtool = getToolByName(self.context, 'portal_membership') |
---|
41 | portrait_url = purl() + '/defaultUser.gif' |
---|
42 | email = reply.getProperty('email', d='') |
---|
43 | |
---|
44 | creator = reply.Creator() |
---|
45 | if creator and not creator == 'Anonymous User' and not email: |
---|
46 | mtool = getToolByName(self.context, "portal_membership") |
---|
47 | member = mtool.getMemberById(creator) |
---|
48 | email = member and member.getProperty('email', '') or '' |
---|
49 | mem_id = getattr(member, 'getId', lambda: 'Anonymous User')() |
---|
50 | portrait = mtool.getPersonalPortrait(mem_id) |
---|
51 | portrait_url = portrait.absolute_url() |
---|
52 | |
---|
53 | if not email or not 'defaultUser.gif' in portrait_url: |
---|
54 | return portrait_url |
---|
55 | |
---|
56 | size = 40 |
---|
57 | gravatar_url = "http://www.gravatar.com/avatar.php?" |
---|
58 | # construct the url |
---|
59 | gravatar_url += urllib.urlencode({ |
---|
60 | 'gravatar_id': md5.md5(email.lower()).hexdigest(), |
---|
61 | 'default': portrait_url, |
---|
62 | 'size': str(size)}) |
---|
63 | return gravatar_url |
---|
64 | |
---|
65 | def authenticated_report_abuse_enabled(self): |
---|
66 | """ authenticated_report_abuse_enabled """ |
---|
67 | portal_properties = getToolByName(self.context, 'portal_properties') |
---|
68 | prop_sheet = portal_properties['qPloneComments'] |
---|
69 | value = prop_sheet.getProperty('enable_authenticated_report_abuse', |
---|
70 | False) |
---|
71 | return value |
---|
72 | |
---|
73 | def anonymous_report_abuse_enabled(self): |
---|
74 | """ anonymous_report_abuse_enabled """ |
---|
75 | portal_properties = getToolByName(self.context, 'portal_properties') |
---|
76 | prop_sheet = portal_properties['qPloneComments'] |
---|
77 | value = prop_sheet.getProperty('enable_anonymous_report_abuse', False) |
---|
78 | return value |
---|
79 | |
---|
80 | def visual_effects_level(self): |
---|
81 | """ visual_effects_level """ |
---|
82 | portal_properties = getToolByName(self.context, 'portal_properties') |
---|
83 | prop_sheet = portal_properties['qPloneComments'] |
---|
84 | value = prop_sheet.getProperty('visual_effects', 0) |
---|
85 | return value |
---|
86 | |
---|
87 | def email_from_address(self): |
---|
88 | """ email_from_address """ |
---|
89 | portal_url = getToolByName(self.context, 'portal_url') |
---|
90 | portal = portal_url.getPortalObject() |
---|
91 | return portal.email_from_address |
---|
92 | |
---|
93 | |
---|
94 | from zope.interface import Interface |
---|
95 | from Products.Five.browser import BrowserView |
---|
96 | |
---|
97 | |
---|
98 | class IQCommentsView(Interface): |
---|
99 | """ QComments View Interface |
---|
100 | """ |
---|
101 | |
---|
102 | def js3(): |
---|
103 | """ visual_effects = 1 |
---|
104 | """ |
---|
105 | |
---|
106 | def js4(): |
---|
107 | """ visual_effects = 0 and popupenabled or visual_effects == 2 |
---|
108 | """ |
---|
109 | |
---|
110 | |
---|
111 | class QCommentsView(BrowserView): |
---|
112 | """ QComments View |
---|
113 | """ |
---|
114 | |
---|
115 | def js3(self): |
---|
116 | """ visual_effects = 1 |
---|
117 | """ |
---|
118 | portal_properties = getToolByName(self.context, 'portal_properties') |
---|
119 | prop_sheet = portal_properties['qPloneComments'] |
---|
120 | value = prop_sheet.getProperty('visual_effects', -1) |
---|
121 | return value == 1 |
---|
122 | |
---|
123 | def js4(self): |
---|
124 | """ visual_effects = 0 and popupenabled or visual_effects == 2 |
---|
125 | """ |
---|
126 | portal_properties = getToolByName(self.context, 'portal_properties') |
---|
127 | prop_sheet = portal_properties['qPloneComments'] |
---|
128 | value = prop_sheet.getProperty('visual_effects', -1) |
---|
129 | jstool = aq_inner(self.context).portal_javascripts |
---|
130 | popupenabled = jstool.getResource('popupforms.js').getEnabled() |
---|
131 | return value == 0 and popupenabled or value == 2 |
---|