Exemple #1
0
    def canonical_path(self):
        purl = getToolByName(self.context,'portal_url')
        entry = IWeblogEntry(self.context).__of__(self.context.aq_inner.aq_parent)
        weblog_content = entry.getWeblogContentObject()
        weblog_path = '/'+'/'.join(purl.getRelativeContentPath(weblog_content))

        return '%s/%s' % (weblog_path,'/'.join(getArchivePathFor(entry, weblog_content)))
Exemple #2
0
 def canonical_path(self):
     purl = getToolByName(self.context,'portal_url')
     if not self.context.workflow_history['plone_workflow'][-1]['review_state'] == 'published':
         return '/' + purl.getRelativeContentURL(self.context)
     entry = IWeblogEntry(self.context).__of__(self.context.aq_inner.aq_parent)
     weblog_content = entry.getWeblogContentObject()
     weblog_path = '/' + purl.getRelativeContentURL(weblog_content)
     return '%s/%s' % (weblog_path,'/'.join(getArchivePathFor(entry, weblog_content)))
    def __call__(self, subject, body_text, text_format="plain", username=None, password=None):
        """This method is lifted almost directly from CMFPlone's
        discussion_reply.cpy skin script. Modifications start at the point where
        we try to adapt to IWeblogEntry.
        """
        req = self.request
        if username or password:
            # The user username/password inputs on on the comment form were used,
            # which might happen when anonymous commenting is enabled. If they typed
            # something in to either of the inputs, we send them to 'logged_in'.
            # 'logged_in' will redirect them back to this script if authentication
            # succeeds with a query string which will post the message appropriately
            # and show them the result.  if 'logged_in' fails, the user will be
            # presented with the stock login failure page.  This all depends
            # heavily on cookiecrumbler, but I believe that is a Plone requirement.
            came_from = "%s?subject=%s&body_text=%s" % (req["URL"], subject, body_text)
            came_from = url_quote_plus(came_from)
            portal_url = self.context.portal_url()
            return req.RESPONSE.redirect(
                "%s/logged_in?__ac_name=%s"
                "&__ac_password=%s"
                "&came_from=%s" % (portal_url, url_quote_plus(username), url_quote_plus(password), came_from)
            )
        # if (the user is already logged in) or (if anonymous commenting is enabled and
        # they posted without typing a username or password into the form), we do
        # the following
        mtool = getToolByName(self.context, "portal_membership")
        creator = mtool.getAuthenticatedMember().getId()
        dtool = getToolByName(self.context, "portal_discussion")
        tb = dtool.getDiscussionFor(self.context)
        id = tb.createReply(title=subject, text=body_text, Creator=creator)
        reply = tb.getReply(id)
        # TODO THIS NEEDS TO GO AWAY!
        if hasattr(dtool.aq_explicit, "cookReply"):
            dtool.cookReply(reply, text_format="plain")
        parent = tb.aq_parent
        # return to the discussable object.
        obj = self.context.plone_utils.getDiscussionThread(tb)[0]
        try:
            entry = IWeblogEntry(obj).__of__(self.context.aq_inner.aq_parent)
            # Check for the existence of a parent weblog to see if `obj' should
            # be treated as having an archive url.
            if IWeblog.providedBy(entry.getWeblog()):
                weview = getMultiAdapter((obj, self.request), name=u"weblogentry_view")
                base = weview.getArchiveURLFor(entry)
        except TypeError:
            base = obj.getTypeInfo().getActionInfo("object/view", obj)["url"]
        anchor = reply.getId()
        from Products.CMFPlone.utils import transaction_note

        transaction_note("Added comment to %s at %s" % (parent.title_or_id(), reply.absolute_url()))
        self.context.plone_utils.addPortalMessage(_(u"Comment added."))
        target = "%s#%s" % (base, anchor)
        return req.RESPONSE.redirect(target)
Exemple #4
0
 def isWeblogContent(self, obj=None):
     """See IBaseView.
     """
     if obj is None:
         obj = self.context
     if IWeblog.providedBy(obj):
         return True
     elif IWeblogArchive.providedBy(obj):
         return True
     elif IWeblogEntry.providedBy(obj):
         return True
     elif ITopic.providedBy(obj):
         return True
     return False
def getArchivePathForNoArchive(obj, weblog_content):
    """See IWeblogView.
    """
    weblog_path = weblog_content.getPhysicalPath()

    if IWeblogEntry.providedBy(obj):
        obj = obj.context

    obj_path = getattr(obj, 'getPath', None)
    if obj_path and callable(obj_path):
        obj_path = obj.getPath().split('/')
    else:
        obj_path = obj.getPhysicalPath()

    return obj_path[len(weblog_path):]
 def addEntry(self,
              title,
              excerpt,
              text,
              topics=[],
              id=None,
              pubdate=None,
              mimetype=None):
     """Add an entry from the provided arguments.  If id is None, normalize
     the title to create an id.  If pubdate is None, ignore it.
     Return the new entry.
     """
     config = IWeblogEnhancedConfiguration(self.context)
     if id is None:
         id = getUtility(IIDNormalizer).normalize(title)
     self.context.invokeFactory(id=id, type_name=config.default_type)
     obj = getattr(self.context, id)
     entry = IWeblogEntry(obj).__of__(obj)
     entry.setTitle(title)
     entry.setText(text, mimetype)
     entry.setExcerpt(excerpt)
     if topics:
         entry.setTopics(topics)
     if pubdate is not None:
         entry.setPublicationDate(pubdate)
     #obj.reindexObject()
     return entry
Exemple #7
0
    def __call__(self,
                 subject,
                 body_text,
                 text_format='plain',
                 username=None,
                 password=None):
        """This method is lifted almost directly from CMFPlone's
        discussion_reply.cpy skin script. Modifications start at the point where
        we try to adapt to IWeblogEntry.
        """
        req = self.request
        if username or password:
            # The user username/password inputs on on the comment form were used,
            # which might happen when anonymous commenting is enabled. If they typed
            # something in to either of the inputs, we send them to 'logged_in'.
            # 'logged_in' will redirect them back to this script if authentication
            # succeeds with a query string which will post the message appropriately
            # and show them the result.  if 'logged_in' fails, the user will be
            # presented with the stock login failure page.  This all depends
            # heavily on cookiecrumbler, but I believe that is a Plone requirement.
            came_from = '%s?subject=%s&body_text=%s' % (req['URL'], subject, body_text)
            came_from = url_quote_plus(came_from)
            portal_url = self.context.portal_url()
            return req.RESPONSE.redirect(
                '%s/logged_in?__ac_name=%s'
                '&__ac_password=%s'
                '&came_from=%s' % (portal_url,
                                       url_quote_plus(username),
                                       url_quote_plus(password),
                                       came_from,
                                       )
                )
        # if (the user is already logged in) or (if anonymous commenting is enabled and
        # they posted without typing a username or password into the form), we do
        # the following
        mtool = getToolByName(self.context, 'portal_membership')
        creator = mtool.getAuthenticatedMember().getId()
        # qPloneComments related code
        pp = getToolByName(self.context,'portal_properties')
        qPC = getattr(pp,'qPloneComments', None)
        requireEmail = False
        if qPC:
            requireEmail = qPC.getProperty('require_email', False)
            if requireEmail:
                if mtool.isAnonymousUser():
                    email = self.request.get('email', '')
                else:
                    email = mtool.getAuthenticatedMember().getProperty('email')

            isForAnonymous = pp['qPloneComments'].getProperty('enable_anonymous_commenting', False)
            comment_creator = req.get('Creator', None)
            if isForAnonymous and comment_creator:
                # Get entered anonymous name
                creator = comment_creator
                        
        dtool = getToolByName(self.context, 'portal_discussion')
        tb = dtool.getDiscussionFor(self.context)
        if requireEmail:
            id = tb.createReply(title=subject, text=body_text, Creator=creator, email=email)
        else:
            id = tb.createReply(title=subject, text=body_text, Creator=creator)
        reply = tb.getReply(id)

        # Add website property to reply
        website = req.get('website', '').strip()
        if website:
            if not website.startswith('http://'):
                website = 'http://' + website
            reply.manage_addProperty(id='website', value=website, type='string')

        # TODO THIS NEEDS TO GO AWAY!
        if hasattr(dtool.aq_explicit, 'cookReply'):
            dtool.cookReply(reply, text_format='plain')
        parent = tb.aq_parent
        # return to the discussable object.
        obj = self.context.plone_utils.getDiscussionThread(tb)[0]
        try:
            entry = IWeblogEntry(obj).__of__(self.context.aq_inner.aq_parent)
            # Check for the existence of a parent weblog to see if `obj' should
            # be treated as having an archive url.
            if IWeblog.providedBy(entry.getWeblog()):
                weview = getMultiAdapter((obj, self.request),
                                         name=u'weblogentry_view')
                base = weview.getArchiveURLFor(entry)
        except TypeError:
            base = obj.getTypeInfo().getActionInfo('object/view',
                                                               obj)['url']
        anchor = reply.getId()
        from Products.CMFPlone.utils import transaction_note
        transaction_note('Added comment to %s at %s' % (parent.title_or_id(),
                                                        reply.absolute_url()))
        self.context.plone_utils.addPortalMessage(_(u'Comment added.'))
        target = '%s#%s' % (base, anchor)
        return req.RESPONSE.redirect(target)