def _updateMessages(self,supportmessages,usermessage,
                     lastMsgFrom,userName,userID,files):
     """
     """
     
     messagesElem = self.core.getHtmlIdSelector("jabberHelpdeskMessages")
     lastMsg = self.core.getHtmlIdSelector("lastMsg")
     if supportmessages or files:
         msgElem = ''
         
         for message in supportmessages:
             message = message.encode('utf-8')
             message = convertHtmlToWebIntelligentPlainText(message)
             message = convertWebIntelligentPlainTextToHtml(message)
             message = message.replace("<a href",'<a target="_blank" href')
             message = replaceEmoticons(message)
             message = message.decode('utf-8')
             msgElem =msgElem+ '<dd><span>%s</span></dd>'%(message)
         for (path,name,descr) in files:
             b64 = base64.encodestring(path)
             href = "%s/@@fileDownload?file=%s"%(self.context.absolute_url(),b64)
             msgElem = msgElem + '<dd>You received a file:<a href=%s target="_blank">%s</a> %s</dd>'%(href,name,descr)
         
         if (lastMsgFrom!='support') and (not usermessage):
             msgHead = '<dl id="lastMsg" class="msgCont"><dt class="msgHead"><span class="msgTL"></span>'
             msgHead = msgHead+'<span class="tile">%s</span><span class="msgTR"></span></dt>'%('support')
             
             self.core.setAttribute(lastMsg,'id','')
             self.core.insertHTMLAsLastChild(messagesElem, msgHead+msgElem+msgFoot)
             self.core.setStateVar('helpdesk-lastMsgFrom','support')
             lastMsgFrom='support'
         else:
             self.core.replaceHTML("#lastMsg .msgFoot",msgElem+msgFoot)
         self.plonekss.issuePortalMessage('','info')
     
     if usermessage:
         usermessage = convertHtmlToWebIntelligentPlainText(usermessage)
         usermessage = convertWebIntelligentPlainTextToHtml(usermessage)
         usermessage = usermessage.replace("<a href",'<a target="_blank" href')
         usermessage = replaceEmoticons(usermessage)
         usermessage = usermessage.decode('utf-8')
         msgElem = '<dd><span>%s</span></dd>'%(usermessage)
         
         if lastMsgFrom !='user':
             msgHead = '<dl id="lastMsg" class="msgCont"><dt class="msgHead"><span class="msgTL"></span>'
             msgHead = msgHead +'<span class="tile">%s</span><span class="msgTR"></span></dt>'%(userName)
             self.core.setAttribute(lastMsg,'id','')
             self.core.insertHTMLAsLastChild(messagesElem, msgHead+msgElem+msgFoot)
             self.core.setStateVar('helpdesk-lastMsgFrom','user')
         else:
             self.core.replaceHTML("#lastMsg .msgFoot",msgElem+msgFoot)
     
     if supportmessages or usermessage or files:
         self.jhkss.jh_resetScrollbar(messagesElem)
Example #2
0
def addDiscussion(portal,discussion,tags,context,discussionTitle=''):
    from ubify.coretypes import generateDiscussionTitle
    if discussion == '':
        return None
    objDiscussion = None
    new_id = context.generateUniqueId('Discussion')
    try:
        objDiscussion = getOrCreateType(portal,context,new_id,'Discussion')
    except:
        objDiscussion = None

    if objDiscussion <> None:
        if objDiscussion.title == '':
            if discussionTitle == '':
                objDiscussion.title = generateDiscussionTitle(convertHtmlToWebIntelligentPlainText(discussion))
            else:
                objDiscussion.title = discussionTitle
            objDiscussion.setDescription(discussion)
            objDiscussion._renameAfterCreation()

        if tags != '':
            try:
                values = tags.split(",")
                values = [val.strip().lower() for val in values]
                values = [k.lower() for k in list(unique(values)) if k]
            except AttributeError:
                values = []
            objDiscussion.setSubject(values)

        objDiscussion.reindexObject()
        notify(ObjectInitializedEvent(objDiscussion))

    return objDiscussion
    def transform(self, data, options=None):
        if self._validate(data) is None:
            return None

        html = u''.join(data).encode('utf-8')
        html = convertHtmlToWebIntelligentPlainText(html)
        return TransformResult(StringIter(unicode(html, 'utf-8')))
    def _to_text(self, body):
        # Because plone.intelligenttext uses htmlentitydefs to convert entities
        # to text and because htmlentitydefs returns entities in latin-1, we
        # take care of entity conversion by ourselves.
        body = self._expand_entities(body)

        # Expand links to reveal their hrefs.  When link tags are stripped out
        # the user still will see the target URL.
        body = self._expand_links(body)

        return convertHtmlToWebIntelligentPlainText(body.encode('utf-8')).\
            decode('utf-8')
Example #5
0
 def test_adapters(self):
     """Creates an IATContentType and tests the adaptation to IClassifiable
     """
     self.folder.invokeFactory('Document', 'test',
                               text="This is a test",
                               subject="A Subject")
     adapted = IClassifiable(self.folder['test'])
     self.failUnless(adapted.UID)
     self.failUnless(adapted.text==
         convertHtmlToWebIntelligentPlainText(
         self.folder['test'].SearchableText()))
     self.failUnless(adapted.categories==['A Subject'])
     self.failUnless(adapted.language=='en')
    def retrain_termextractor_action(self, action, data):
        storage = getUtility(INounPhraseStorage)
        storage.clear()

        catalog = getToolByName(self.context, "portal_catalog")
        types_to_search = storage.friendlyTypes or self._friendlyContentTypes()
        trainContent = catalog.searchResults(portal_type=types_to_search)
        for item in trainContent:
            # NOTE: Why can't I obtain item.SearchableText?
            # Is it too big to be returned in catalog brains?
            obj = item.getObject()
            uid = obj.UID()
            text = convertHtmlToWebIntelligentPlainText(obj.SearchableText())
            storage.addDocument(uid, text)
        self.status = _(
            u"Term extractor trained and NP storage updated." " You will need to re-train the classifier as well."
        )
 def __iter__(self):
     for item in self.previous:
         text = item['_transmogrify.zine.html']
         images = text.split('<img')[1:]
         for image in images:
             image = image.split('>')[0]
             if 'src="/' in image:
                 text = text.replace(image,
                     image.replace('src="/',
                     'src="%s' %(self.image_base))
                                    )
         parasplit = text.split('<p>')
         if len(parasplit) > 1:
             first_para = '<p>%s' %(parasplit[1])
             item['description'] = convertHtmlToWebIntelligentPlainText(
                 first_para)
         item['text'] = text
         yield item
    def __iter__(self):
        for item in self.previous:
            pathkey = self.pathkey(*item.keys())[0]
            # item doesn't exist or the type of comment cannot be
            # created
            if not self.enabled or not pathkey:
                yield item
                continue

            path = item[pathkey]
            obj = self.context.unrestrictedTraverse(path.lstrip('/'), None)
            # path doesn't exist
            if obj is None:
                yield item
                continue

            # TODO: check to see if the object supports commenting...
            comments = item.get('_comments', [])
            for comment in comments:
                title = comment.get('title', '')
                text = comment.get('text', '')
                creator = comment.get('author.name', '')
                creation_date = comment.get('published', '')
                modification_date = comment.get('updated', '')
                if self.comment_type == "plone.app.discussion":
                    conversation = IConversation(obj)
                    # create a reply object
                    comment = CommentFactory()
                    comment.title = title
                    comment.text = convertHtmlToWebIntelligentPlainText(text)
                    comment.creator = creator
                    # TODO: check if the date is a datetime instance
                    comment.creation_date = creation_date or\
                            datetime.datetime.now()
                    comment.modification_date = modification_date or\
                            datetime.datetime.now()
                    conversation.addComment(comment)
                    # TODO: fire events
                if self.comment_type == "plone":
                    # TODO: create default plone content
                    pass
            yield item
def updateClassifier(obj,event):

    try:
        termstorage = getUtility(INounPhraseStorage)    
        classifier = getUtility(IContentClassifier)
    except ComponentLookupError:
        return
    if not termstorage.friendlyTypes or \
        obj.portal_type in termstorage.friendlyTypes:
        uid = obj.UID()
        text = convertHtmlToWebIntelligentPlainText(
            obj.SearchableText())
        termstorage.addDocument(uid,text)
        subjects = obj.Subject()
    
        if subjects:
            classifier = getUtility(IContentClassifier)
            classifier.addTrainingDocument(uid,subjects)
            if classifier.trainAfterUpdate:
                classifier.train()
 def convert(self, orig, data, **kwargs):
     text = convertHtmlToWebIntelligentPlainText(orig)
     data.setData(text)
     return data
 def getText(self):
     """
     """
     return convertHtmlToWebIntelligentPlainText(self.context.SearchableText())
Example #12
0
 def getText(self):
     """
     """
     return convertHtmlToWebIntelligentPlainText(
         self.context.SearchableText())