Improve link filter

This commit is contained in:
calzoneman 2013-09-27 10:28:48 -05:00
parent ba66aadf66
commit 8ba5743bc2
2 changed files with 19 additions and 4 deletions

View File

@ -1,3 +1,9 @@
Fri Sep 27 10:27 2013 CDT
* lib/channel.js: Change the link regex, change the way 'affects links'
works. The default link filter will only transform a link of no
previous filters transform it (and filters will only transform a link
if 'affects links' is ticked).
Thu Sep 26 23:40 2013 CDT Thu Sep 26 23:40 2013 CDT
* lib/config.js: Add config keys for statistics interval & max age, * lib/config.js: Add config keys for statistics interval & max age,
alias purge interval & max age. alias purge interval & max age.

View File

@ -21,6 +21,7 @@ var Filter = require("./filter.js").Filter;
var Playlist = require("./playlist"); var Playlist = require("./playlist");
var sanitize = require("validator").sanitize; var sanitize = require("validator").sanitize;
var $util = require("./utilities"); var $util = require("./utilities");
var url = require("url");
var Channel = function(name, Server) { var Channel = function(name, Server) {
var self = this; var self = this;
@ -2101,17 +2102,25 @@ Channel.prototype.chainMessage = function(user, msg, data) {
} }
Channel.prototype.filterMessage = function(msg) { Channel.prototype.filterMessage = function(msg) {
const link = /((?:(?:https?)|(?:ftp))(?::\/\/[0-9a-zA-Z\.]+(?::[0-9]+)?[^\s'"$]+))/g; const link = /(\w+:\/\/(?:[^:\/\[\]\s]+|\[[0-9a-f:]+\])(?::\d+)?(?:\/[^\/\s]*)*)/ig;
var subs = msg.split(link); var subs = msg.split(link);
// Apply other filters // Apply other filters
for(var j = 0; j < subs.length; j++) { for(var j = 0; j < subs.length; j++) {
if(this.opts.enable_link_regex && subs[j].match(link)) { if(this.opts.enable_link_regex && subs[j].match(link)) {
subs[j] = subs[j].replace(link, "<a href=\"$1\" target=\"_blank\">$1</a>"); var orig = subs[j];
for(var i = 0; i < this.filters.length; i++) { for(var i = 0; i < this.filters.length; i++) {
if(!this.filters[i].filterlinks || !this.filters[i].active) if(!this.filters[i].filterlinks || !this.filters[i].active)
continue; continue;
subs[j] = this.filters[i].filter(subs[j]); subs[j] = this.filters[i].filter(subs[j]);
} }
// only apply link filter if another filter hasn't changed
// the link
if (subs[j] === orig) {
subs[j] = url.format(url.parse(subs[j]));
subs[j] = subs[j].replace(link,
"<a href=\"$1\" target=\"_blank\">$1</a>");
}
continue; continue;
} }
for(var i = 0; i < this.filters.length; i++) { for(var i = 0; i < this.filters.length; i++) {