[1625] | 1 | import urllib |
---|
| 2 | try: |
---|
| 3 | import hashlib as md5 |
---|
| 4 | except ImportError: |
---|
| 5 | import md5 |
---|
[822] | 6 | |
---|
| 7 | from Acquisition import aq_inner |
---|
| 8 | from AccessControl import getSecurityManager |
---|
[1201] | 9 | |
---|
| 10 | from Products.CMFPlone.utils import IndexIterator |
---|
[822] | 11 | from Products.CMFPlone.utils import getToolByName |
---|
[1201] | 12 | from Products.CMFFormController.ControllerState import ControllerState |
---|
| 13 | from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
---|
| 14 | from quintagroup.plonecomments.utils import manage_mails |
---|
[822] | 15 | |
---|
| 16 | from plone.app.layout.viewlets import comments |
---|
[1201] | 17 | from plone.app.kss.plonekssview import PloneKSSView |
---|
[822] | 18 | |
---|
| 19 | class CommentsViewlet(comments.CommentsViewlet): |
---|
| 20 | """A custom version of the comments viewlet |
---|
| 21 | """ |
---|
| 22 | render = ViewPageTemplateFile('comments.pt') |
---|
| 23 | |
---|
| 24 | def is_moderation_enabled(self): |
---|
| 25 | """ Returns a boolean indicating whether the user has enabled moderation |
---|
| 26 | in the qPloneComments configlet |
---|
| 27 | """ |
---|
| 28 | portal_properties = getToolByName(self.context, 'portal_properties') |
---|
| 29 | try: |
---|
| 30 | return portal_properties.qPloneComments.getProperty('enable_moderation', None) |
---|
| 31 | except AttributeError: |
---|
| 32 | return False |
---|
| 33 | |
---|
| 34 | def can_moderate(self): |
---|
| 35 | """ Returns a boolean indicating whether the user has the 'Moderate Discussion' |
---|
| 36 | permission |
---|
| 37 | """ |
---|
| 38 | return getSecurityManager().checkPermission('Moderate Discussion', aq_inner(self.context)) |
---|
| 39 | |
---|
| 40 | def getGravatar(self, reply): |
---|
| 41 | purl = getToolByName(self.context, 'portal_url') |
---|
[1560] | 42 | mtool = getToolByName(self.context, 'portal_membership') |
---|
| 43 | portrait_url = purl() + '/defaultUser.gif' |
---|
[822] | 44 | email = '' |
---|
| 45 | |
---|
| 46 | creator = reply.Creator() |
---|
| 47 | if creator and not creator=='Anonymous User': |
---|
| 48 | mtool = getToolByName(self.context, "portal_membership") |
---|
| 49 | member = mtool.getMemberById(creator) |
---|
| 50 | email = member and member.getProperty('email','') or '' |
---|
[1560] | 51 | mem_id = getattr(member,'getId',lambda:'Anonymous User')() |
---|
| 52 | portrait = mtool.getPersonalPortrait(mem_id) |
---|
| 53 | portrait_url = portrait.absolute_url() |
---|
[822] | 54 | else: |
---|
| 55 | email = reply.getProperty('email',d='') |
---|
| 56 | |
---|
[1560] | 57 | if not email or not 'defaultUser.gif' in portrait_url: |
---|
| 58 | return portrait_url |
---|
| 59 | |
---|
[822] | 60 | size = 40 |
---|
| 61 | gravatar_url = "http://www.gravatar.com/avatar.php?" |
---|
| 62 | # construct the url |
---|
[1560] | 63 | gravatar_url += urllib.urlencode({'gravatar_id':md5.md5(email).hexdigest(), |
---|
| 64 | 'default':portrait_url, 'size':str(size)}) |
---|
[1201] | 65 | return gravatar_url |
---|
[1560] | 66 | |
---|
[1201] | 67 | |
---|
| 68 | def authenticated_report_abuse_enabled(self): |
---|
| 69 | """ """ |
---|
| 70 | portal_properties = getToolByName(self.context, 'portal_properties') |
---|
| 71 | prop_sheet = portal_properties['qPloneComments'] |
---|
| 72 | value = prop_sheet.getProperty('enable_authenticated_report_abuse', False) |
---|
| 73 | return value |
---|
| 74 | |
---|
| 75 | def anonymous_report_abuse_enabled(self): |
---|
| 76 | """ """ |
---|
| 77 | portal_properties = getToolByName(self.context, 'portal_properties') |
---|
| 78 | prop_sheet = portal_properties['qPloneComments'] |
---|
| 79 | value = prop_sheet.getProperty('enable_anonymous_report_abuse', False) |
---|
| 80 | return value |
---|
| 81 | |
---|
| 82 | def ajax_report_abuse_enabled(self): |
---|
| 83 | """ """ |
---|
| 84 | portal_properties = getToolByName(self.context, 'portal_properties') |
---|
| 85 | prop_sheet = portal_properties['qPloneComments'] |
---|
| 86 | value = prop_sheet.getProperty('enable_ajax_report_abuse', False) |
---|
| 87 | return value |
---|
| 88 | |
---|
| 89 | def email_from_address(self): |
---|
| 90 | """ """ |
---|
| 91 | portal_url = getToolByName(self.context, 'portal_url') |
---|
| 92 | portal = portal_url.getPortalObject() |
---|
| 93 | return portal.email_from_address |
---|
| 94 | |
---|
| 95 | def member(self): |
---|
| 96 | """ """ |
---|
| 97 | pm = getToolByName(self.context, 'portal_membership') |
---|
| 98 | return pm.getAuthenticatedMember() |
---|
| 99 | |
---|
| 100 | def tabindex(self): |
---|
| 101 | """ Needed for BBB, tabindex has been deprecated. |
---|
| 102 | """ |
---|
| 103 | return IndexIterator() |
---|
| 104 | |
---|
| 105 | def portal_url(self): |
---|
| 106 | """ """ |
---|
| 107 | return getToolByName(self.context, 'portal_url') |
---|