mirror of https://github.com/calzoneman/sync.git
Improve link filter
This commit is contained in:
parent
ba66aadf66
commit
8ba5743bc2
|
@ -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.
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -1125,7 +1126,7 @@ Channel.prototype.broadcastPoll = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var unhidden = this.poll.packUpdate(true);
|
var unhidden = this.poll.packUpdate(true);
|
||||||
var hidden = this.poll.packUpdate(false);
|
var hidden = this.poll.packUpdate(false);
|
||||||
|
|
||||||
this.users.forEach(function (u) {
|
this.users.forEach(function (u) {
|
||||||
if (self.hasPermission(u, "viewhiddenpoll"))
|
if (self.hasPermission(u, "viewhiddenpoll"))
|
||||||
u.socket.emit("newPoll", unhidden);
|
u.socket.emit("newPoll", unhidden);
|
||||||
|
@ -1138,7 +1139,7 @@ Channel.prototype.broadcastPollUpdate = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var unhidden = this.poll.packUpdate(true);
|
var unhidden = this.poll.packUpdate(true);
|
||||||
var hidden = this.poll.packUpdate(false);
|
var hidden = this.poll.packUpdate(false);
|
||||||
|
|
||||||
this.users.forEach(function (u) {
|
this.users.forEach(function (u) {
|
||||||
if (self.hasPermission(u, "viewhiddenpoll"))
|
if (self.hasPermission(u, "viewhiddenpoll"))
|
||||||
u.socket.emit("updatePoll", unhidden);
|
u.socket.emit("updatePoll", unhidden);
|
||||||
|
@ -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++) {
|
||||||
|
|
Loading…
Reference in New Issue