[552] | 1 | import urllib, md5 #hashlib |
---|
| 2 | |
---|
[1] | 3 | from Acquisition import aq_inner |
---|
| 4 | from AccessControl import getSecurityManager |
---|
[909] | 5 | |
---|
[1355] | 6 | from Products.CMFPlone.MembershipTool import default_portrait |
---|
[909] | 7 | from Products.CMFPlone.utils import IndexIterator |
---|
[1] | 8 | from Products.CMFPlone.utils import getToolByName |
---|
[920] | 9 | from Products.CMFFormController.ControllerState import ControllerState |
---|
[909] | 10 | from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
---|
[920] | 11 | from Products.qPloneComments.utils import manage_mails |
---|
[1] | 12 | |
---|
| 13 | from plone.app.layout.viewlets import comments |
---|
[920] | 14 | from plone.app.kss.plonekssview import PloneKSSView |
---|
[1] | 15 | |
---|
| 16 | class CommentsViewlet(comments.CommentsViewlet): |
---|
[89] | 17 | """A custom version of the comments viewlet |
---|
[1] | 18 | """ |
---|
| 19 | render = ViewPageTemplateFile('comments.pt') |
---|
[89] | 20 | |
---|
[1] | 21 | def is_moderation_enabled(self): |
---|
| 22 | """ Returns a boolean indicating whether the user has enabled moderation |
---|
| 23 | in the qPloneComments configlet |
---|
| 24 | """ |
---|
| 25 | portal_properties = getToolByName(self.context, 'portal_properties') |
---|
| 26 | try: |
---|
| 27 | return portal_properties.qPloneComments.getProperty('enable_moderation', None) |
---|
| 28 | except AttributeError: |
---|
| 29 | return False |
---|
[89] | 30 | |
---|
[1] | 31 | def can_moderate(self): |
---|
| 32 | """ Returns a boolean indicating whether the user has the 'Moderate Discussion' |
---|
| 33 | permission |
---|
| 34 | """ |
---|
| 35 | return getSecurityManager().checkPermission('Moderate Discussion', aq_inner(self.context)) |
---|
[552] | 36 | |
---|
[553] | 37 | def getGravatar(self, reply): |
---|
[552] | 38 | purl = getToolByName(self.context, 'portal_url') |
---|
| 39 | default = purl() + '/defaultUser.gif' |
---|
| 40 | email = '' |
---|
| 41 | |
---|
[553] | 42 | creator = reply.Creator() |
---|
| 43 | if creator and not creator=='Anonymous User': |
---|
[552] | 44 | mtool = getToolByName(self.context, "portal_membership") |
---|
| 45 | member = mtool.getMemberById(creator) |
---|
| 46 | email = member and member.getProperty('email','') or '' |
---|
[1355] | 47 | portrait = mtool.getPersonalPortrait(creator) |
---|
| 48 | if portrait.getId() != default_portrait: |
---|
| 49 | return portrait.absolute_url() |
---|
[553] | 50 | else: |
---|
| 51 | email = reply.getProperty('email',d='') |
---|
[552] | 52 | if not email: |
---|
| 53 | return default |
---|
| 54 | |
---|
| 55 | size = 40 |
---|
| 56 | gravatar_url = "http://www.gravatar.com/avatar.php?" |
---|
| 57 | # construct the url |
---|
| 58 | gravatar_url += urllib.urlencode({'gravatar_id':md5.md5(email).hexdigest(), |
---|
| 59 | 'default':default, 'size':str(size)}) |
---|
| 60 | |
---|
[909] | 61 | return gravatar_url |
---|
| 62 | |
---|
[939] | 63 | def authenticated_report_abuse_enabled(self): |
---|
[909] | 64 | """ """ |
---|
| 65 | portal_properties = getToolByName(self.context, 'portal_properties') |
---|
| 66 | prop_sheet = portal_properties['qPloneComments'] |
---|
[939] | 67 | value = prop_sheet.getProperty('enable_authenticated_report_abuse', False) |
---|
[909] | 68 | return value |
---|
| 69 | |
---|
[939] | 70 | def anonymous_report_abuse_enabled(self): |
---|
| 71 | """ """ |
---|
| 72 | portal_properties = getToolByName(self.context, 'portal_properties') |
---|
| 73 | prop_sheet = portal_properties['qPloneComments'] |
---|
| 74 | value = prop_sheet.getProperty('enable_anonymous_report_abuse', False) |
---|
| 75 | return value |
---|
| 76 | |
---|
| 77 | def ajax_report_abuse_enabled(self): |
---|
| 78 | """ """ |
---|
| 79 | portal_properties = getToolByName(self.context, 'portal_properties') |
---|
| 80 | prop_sheet = portal_properties['qPloneComments'] |
---|
| 81 | value = prop_sheet.getProperty('enable_ajax_report_abuse', False) |
---|
| 82 | return value |
---|
| 83 | |
---|
[909] | 84 | def email_from_address(self): |
---|
| 85 | """ """ |
---|
| 86 | portal_url = getToolByName(self.context, 'portal_url') |
---|
| 87 | portal = portal_url.getPortalObject() |
---|
| 88 | return portal.email_from_address |
---|
| 89 | |
---|
| 90 | def member(self): |
---|
| 91 | """ """ |
---|
| 92 | pm = getToolByName(self.context, 'portal_membership') |
---|
| 93 | return pm.getAuthenticatedMember() |
---|
| 94 | |
---|
| 95 | def tabindex(self): |
---|
| 96 | """ Needed for BBB, tabindex has been deprecated. |
---|
| 97 | """ |
---|
| 98 | return IndexIterator() |
---|
| 99 | |
---|
| 100 | def portal_url(self): |
---|
| 101 | """ """ |
---|
| 102 | return getToolByName(self.context, 'portal_url') |
---|
| 103 | |
---|
| 104 | |
---|
[920] | 105 | |
---|
| 106 | class CommentsKSS(PloneKSSView): |
---|
| 107 | """ Operations on the report abuse form using KSS. |
---|
| 108 | """ |
---|
| 109 | |
---|
| 110 | def submit_abuse_report(self): |
---|
[939] | 111 | """ Send an email with the abuse report message and hide abuse report form. |
---|
| 112 | """ |
---|
[920] | 113 | errors = {} |
---|
| 114 | context = aq_inner(self.context) |
---|
| 115 | request = context.REQUEST |
---|
| 116 | portal = getToolByName(self.context, 'portal_url').getPortalObject() |
---|
| 117 | if hasattr(context, 'captcha_validator'): |
---|
| 118 | dummy_controller_state = ControllerState( |
---|
| 119 | id='comments.pt', |
---|
| 120 | context=context, |
---|
| 121 | button='submit', |
---|
| 122 | status='success', |
---|
| 123 | errors={}, |
---|
| 124 | next_action=None,) |
---|
| 125 | # get the form controller |
---|
| 126 | controller = portal.portal_form_controller |
---|
| 127 | # send the validate script to the form controller with the dummy state object |
---|
| 128 | controller_state = controller.validate(dummy_controller_state, request, ['captcha_validator',]) |
---|
| 129 | errors.update(controller_state.errors) |
---|
| 130 | |
---|
| 131 | message = request.get('message') |
---|
| 132 | if not message: |
---|
| 133 | errors.update({'message': 'Please provide a message'}) |
---|
| 134 | |
---|
| 135 | mtool = getToolByName(self.context, "portal_membership") |
---|
| 136 | member = mtool.getAuthenticatedMember() |
---|
| 137 | comment_id = self.context.request.get('comment_id') |
---|
| 138 | ksscore = self.getCommandSet('core') |
---|
| 139 | if errors: |
---|
[939] | 140 | html = self.macroContent('context/report_abuse_form/macros/form', |
---|
[920] | 141 | errors=errors, |
---|
| 142 | show_form=True, |
---|
| 143 | tabindex=IndexIterator(), |
---|
| 144 | member=member, |
---|
| 145 | **request.form) |
---|
[953] | 146 | node = ksscore.getHtmlIdSelector('span-reply-form-holder-%s' % comment_id) |
---|
[946] | 147 | ksscore.replaceInnerHTML(node, html) |
---|
[920] | 148 | return self.render() |
---|
| 149 | |
---|
| 150 | # report_abuse(context, context, message, comment) |
---|
| 151 | manage_mails(context, self.context, 'report_abuse') |
---|
[946] | 152 | |
---|
[939] | 153 | html = self.macroContent('context/report_abuse_form/macros/form', |
---|
[920] | 154 | tabindex=IndexIterator(), |
---|
| 155 | member=member, |
---|
| 156 | **request.form) |
---|
| 157 | node = ksscore.getHtmlIdSelector('span-reply-form-holder-%s' % comment_id) |
---|
[939] | 158 | html = '<br/><span style="color:red">You have reported this comment for abuse.</span>' |
---|
| 159 | self.commands.addCommand('remove_abuse_report_form', |
---|
| 160 | node, |
---|
| 161 | comment_id=comment_id, |
---|
| 162 | html=html) |
---|
[946] | 163 | |
---|
| 164 | node = ksscore.getHtmlIdSelector('div-captcha-%s' % comment_id) |
---|
| 165 | html = self.macroContent('context/report_abuse_form/macros/captcha', |
---|
| 166 | **request.form) |
---|
| 167 | ksscore.replaceInnerHTML(node, html) |
---|
[920] | 168 | return self.render() |
---|
| 169 | |
---|