var decodeText = function(text) {
  if (text === undefined) {
    return '';
  }  
  text = encoder.htmlDecode(text);
  text = text.replace(/<br\/>/g, '\r\n')
  return text;
};
Example #2
0
 sayTitle : function (client, channel, message) {
   // If the title is a URL itself, we'll use the lower level IRC client
   // to send the message to avoid getting stuck in an infinite lookup loop
   var Encoder = require('node-html-encoder').Encoder;
   var e = new Encoder('entity');
   message = e.htmlDecode(message);
   if (message.match(plugins.url.config.urlRegExp)) {
     client.say(channel, message);
   } else {
     say(client, channel, message);
   }
 },
function decodeHTMLEntities(str) {
    if (str && typeof str === 'string') {
        // strip script/html tags
        str = str.replace("\r\n","                   \r\n");
        str = str.replace(/<br\s*\/?>/mg, "");

        str = str.replace(/<script[^>]*>([\S\s]*?)<\/script>/gmi, '');
        str = str.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gmi, '');
        str = encoder.htmlDecode(str);
    }

    return str;
}
Example #4
0
             }, function(err, feed) {
                 if (err) {
                     res.send('Error caught: ' + err);
                     return;
                 }

                 // retrieve paging urls from feed
                 req.session.nextPage = feed.nextPageUrl;

                 // adjust language if requested
                 req.session.fromLang = req.query.from || req.session.fromLang;
                 req.session.toLang = req.query.to || req.session.toLang;
                 
                 // extract texts from chatter posts and comments, and format dates for humans
                 var texts = [];
                 for (var i = 0; i < feed.items.length; i++) {
                     texts.push(encoder.htmlDecode(feed.items[i].body.text));
                     feed.items[i].createdDate = dateFormat(new Date(feed.items[i].createdDate));
                     for (var j = 0; j < feed.items[i].comments.comments.length; j++) {
                         texts.push(encoder.htmlDecode(feed.items[i].comments.comments[j].body.text));
                         feed.items[i].comments.comments[j].createdDate = dateFormat(new Date(feed.items[i].comments.comments[j].createdDate));
                     }
                 }
                 
                 // Calculate possible from-to pairs to display
                 var from = [], to = [];
                 for (var i = 0; i < langs.length; i++) {
                     if (langs[i].from === req.session.fromLang) {
                         to.push(langs[i].to);
                     }
                     if (from.indexOf(langs[i].from) === -1) {
                         from.push(langs[i].from);
                     }
                 }
                 
                 // if changed `from`, adjust `to` if existing impossible
                 if (to.indexOf(req.session.toLang) === -1) {
                     req.session.toLang = to[0];
                 }

                 // translate the texts
                 Translation.translate(texts, req.session.fromLang, req.session.toLang, function(err, texts) {

                     // insert translated text into chatter object
                     for (var i = 0; i < feed.items.length; i++) {
                         feed.items[i].body.text2 = texts.shift();
                         for (var j = 0; j < feed.items[i].comments.comments.length; j++) {
                             feed.items[i].comments.comments[j].body.text2 = texts.shift();
                         }
                     }
                                  
                     // render the view    
                     res.render('index.ejs', {
                           layout: false,
                           chatter: feed,
                           fromLang: req.session.fromLang,
                           toLang: req.session.toLang,
                           fromLangs: from,
                           toLangs: to
                     });

                 });

             });
Example #5
0
 'nodeHtmlEncoder(numerical).htmlDecode': function () { nodeHtmlEncoderNumerical.htmlDecode(emptyTextToDecode); },
Example #6
0
 'nodeHtmlEncoder(entities).htmlDecode': function () { nodeHtmlEncoderEntities.htmlDecode(emptyTextToDecode); },
Example #7
0
			socket.on('startTest', function (data) {
				var encoder = new Encoder('entity');
				var params = JSON.parse(encoder.htmlDecode(data))
				tests.sio_start(params, true);
			});
  mailparser.on("end", function(mail_object) {
    changes.document_type = "email";
    changes.metadata.to = [];
    (mail_object.to || []).forEach(function(item) {
      changes.metadata.to.push(item);
    });
    changes.metadata.cc = [];
    (mail_object.cc || []).forEach(function(item) {
      changes.metadata.cc.push(item);
    });
    changes.metadata.bcc = [];
    (mail_object.bcc || []).forEach(function(item) {
      changes.metadata.bcc.push(item);
    });
    changes.metadata.from = exists(mail_object.from);
    changes.metadata.subject = exists(mail_object.subject);

    if(mail_object.html && mail_object.html.trim() !== '') {
      changes.data.html = encoder.htmlDecode(mail_object.html).trim();
    }

    if(mail_object.headers && mail_object.headers.date) {
      changes.creation_date = new Date(mail_object.headers.date);
      changes.metadata.date = new Date(mail_object.headers.date);
    }
    else if(mail_object.date) {
      changes.creation_date = new Date(mail_object.date);
      changes.metadata.date = new Date(mail_object.date);
    }
    if(mail_object.text) {
      changes.metadata.text = mail_object.text;
    }
    else if(changes.data.html) {
      changes.metadata.text = changes.data.html.replace(reg, " ");
      changes.metadata.text = changes.metadata.text.replace("  ", " ");
    }
    else {
      // Special case, with empty HTML section.
      changes.metadata.text = '';
    }

    // Format text
    changes.metadata.text = changes.metadata.text.trim();
    changes.metadata.text = changes.metadata.text.replace(/</g, '&lt;').replace(/>/g, '&gt;');

    changes.related = [];

    // Delete doc without name and extension
    var attachments = mail_object.attachments || [];
    if(changes.data.html) {
      changes.data.html = cid(changes.data.html, attachments);
    }

    var filtered_attachments = [];
    attachments.forEach(function(attachment){
      if(!attachment.applied && (attachment.fileName || attachment.generatedFileName.lastIndexOf(".") !== -1)) {
        attachment.fileName = attachment.generatedFileName;
        filtered_attachments.push(attachment);
      }
    });

    async.each(filtered_attachments, function(attachment, cb) {
      var anyfetch = new Anyfetch(document.access_token);
      anyfetch.setApiUrl(finalCb.apiUrl);

      var docAttachment = {};
      docAttachment.metadata = {};
      docAttachment.metadata.subject = exists(mail_object.subject);
      docAttachment.identifier = document.identifier + "/" + attachment.fileName;
      docAttachment.document_type = "file";
      docAttachment.metadata = {};
      docAttachment.metadata.path = "/" + attachment.fileName;
      docAttachment.user_access = document.user_access;
      docAttachment.creation_date = changes.creation_date;
      docAttachment.related = [document.identifier,];
      changes.related.push(docAttachment.identifier);
      // File to send
      var fileConfigAttachment = {
        file: attachment.content,
        filename: attachment.fileName,
        knownLength: attachment.length
      };

      anyfetch.sendDocumentAndFile(docAttachment, fileConfigAttachment, cb);
    },
    rarity.carry([changes], cb));
  });