| 1 | ## Script (Python) "discussion_reply" |
|---|
| 2 | ##bind container=container |
|---|
| 3 | ##bind context=context |
|---|
| 4 | ##bind namespace= |
|---|
| 5 | ##bind script=script |
|---|
| 6 | ##bind state=state |
|---|
| 7 | ##bind subpath=traverse_subpath |
|---|
| 8 | ##parameters=subject,body_text,text_format='plain',username=None,password=None |
|---|
| 9 | ##title=Reply to content |
|---|
| 10 | |
|---|
| 11 | from Products.PythonScripts.standard import url_quote_plus |
|---|
| 12 | req = context.REQUEST |
|---|
| 13 | |
|---|
| 14 | if username or password: |
|---|
| 15 | # The user username/password inputs on on the comment form were used, |
|---|
| 16 | # which might happen when anonymous commenting is enabled. If they typed |
|---|
| 17 | # something in to either of the inputs, we send them to 'logged_in'. |
|---|
| 18 | # 'logged_in' will redirect them back to this script if authentication |
|---|
| 19 | # succeeds with a query string which will post the message appropriately |
|---|
| 20 | # and show them the result. if 'logged_in' fails, the user will be |
|---|
| 21 | # presented with the stock login failure page. This all depends |
|---|
| 22 | # heavily on cookiecrumbler, but I believe that is a Plone requirement. |
|---|
| 23 | came_from = '%s?subject=%s&body_text=%s' % (req['URL'], subject, body_text) |
|---|
| 24 | came_from = url_quote_plus(came_from) |
|---|
| 25 | portal_url = context.portal_url() |
|---|
| 26 | |
|---|
| 27 | return req.RESPONSE.redirect( |
|---|
| 28 | '%s/logged_in?__ac_name=%s' |
|---|
| 29 | '&__ac_password=%s' |
|---|
| 30 | '&came_from=%s' % (portal_url, |
|---|
| 31 | url_quote_plus(username), |
|---|
| 32 | url_quote_plus(password), |
|---|
| 33 | came_from, |
|---|
| 34 | ) |
|---|
| 35 | ) |
|---|
| 36 | |
|---|
| 37 | # if (the user is already logged in) or (if anonymous commenting is enabled and |
|---|
| 38 | # they posted without typing a username or password into the form), we do |
|---|
| 39 | # the following |
|---|
| 40 | |
|---|
| 41 | creator = context.portal_membership.getAuthenticatedMember().getUserName() |
|---|
| 42 | tb = context.talkback |
|---|
| 43 | id = tb.createReply(title=subject, text=body_text, Creator=creator) |
|---|
| 44 | reply = tb.getReply(id) |
|---|
| 45 | |
|---|
| 46 | #XXX THIS NEEDS TO GO AWAY! |
|---|
| 47 | portal_discussion=context.portal_discussion |
|---|
| 48 | if hasattr(portal_discussion.aq_explicit, 'cookReply'): |
|---|
| 49 | portal_discussion.cookReply(reply, text_format='plain') |
|---|
| 50 | |
|---|
| 51 | parent = tb.aq_parent |
|---|
| 52 | |
|---|
| 53 | from Products.CMFPlone import transaction_note |
|---|
| 54 | transaction_note('Added comment to %s at %s' % (parent.title_or_id(), reply.absolute_url())) |
|---|
| 55 | |
|---|
| 56 | target = '%s/%s' % (parent.absolute_url(), parent.getTypeInfo().getActionById('view')) |
|---|
| 57 | return req.RESPONSE.redirect(target) |
|---|