diff options
author | Mickaël Rémond <mickael.remond@process-one.net> | 2007-02-19 10:49:23 +0000 |
---|---|---|
committer | Mickaël Rémond <mickael.remond@process-one.net> | 2007-02-19 10:49:23 +0000 |
commit | 5882e29fb63767c9173844332ae1e32ca4069ec2 (patch) | |
tree | 46a11ffeb4e71920283169e2eb61bd47f883abbd /src | |
parent | * src/mod_muc/mod_muc_room.erl: API improvement: Implementation of an (diff) |
* src/mod_muc/mod_muc_log.erl: Spam prevention: The default behaviour
is now to use the nofollow rel attributes for links that are submitted
by users (EJAB-185).
* doc/guide.tex: Likewise.
SVN Revision: 728
Diffstat (limited to 'src')
-rw-r--r-- | src/mod_muc/mod_muc_log.erl | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/src/mod_muc/mod_muc_log.erl b/src/mod_muc/mod_muc_log.erl index 58fce60be..4fcb2b712 100644 --- a/src/mod_muc/mod_muc_log.erl +++ b/src/mod_muc/mod_muc_log.erl @@ -38,6 +38,7 @@ access, lang, timezone, + spam_prevention, top_link}). %%==================================================================== @@ -98,6 +99,7 @@ init([Host, Opts]) -> AccessLog = gen_mod:get_opt(access_log, Opts, muc_admin), Timezone = gen_mod:get_opt(timezone, Opts, local), Top_link = gen_mod:get_opt(top_link, Opts, {"/", "Home"}), + NoFollow = gen_mod:get_opt(spam_prevention, Opts, true), Lang = case ejabberd_config:get_local_option({language, Host}) of undefined -> ""; @@ -111,6 +113,7 @@ init([Host, Opts]) -> access = AccessLog, lang = Lang, timezone = Timezone, + spam_prevention = NoFollow, top_link = Top_link}}. %%-------------------------------------------------------------------- @@ -261,6 +264,7 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, State) -> css_file = CSSFile, lang = Lang, timezone = Timezone, + spam_prevention = NoFollow, top_link = TopLink} = State, Room = get_room_info(RoomJID, Opts), @@ -319,7 +323,7 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, State) -> [Nick, ?T("leaves the room")]); {leave, Reason} -> io_lib:format("<font class=\"ml\">~s ~s: ~s</font><br/>", - [Nick, ?T("leaves the room"), htmlize(Reason)]); + [Nick, ?T("leaves the room"), htmlize(Reason,NoFollow)]); {kickban, "307", ""} -> io_lib:format("<font class=\"mk\">~s ~s</font><br/>", [Nick, ?T("has been kicked")]); @@ -337,7 +341,7 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, State) -> [OldNick, ?T("is now known as"), Nick]); {subject, T} -> io_lib:format("<font class=\"msc\">~s~s~s</font><br/>", - [Nick, ?T(" has set the subject to: "), htmlize(T)]); + [Nick, ?T(" has set the subject to: "), htmlize(T,NoFollow)]); {body, T} -> case regexp:first_match(T, "^/me\s") of {match, _, _} -> @@ -345,7 +349,7 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, State) -> [Nick, string:substr(htmlize(T), 5)]); nomatch -> io_lib:format("<font class=\"mn\"><~s></font> ~s<br/>", - [Nick, htmlize(T)]) + [Nick, htmlize(T,NoFollow)]) end end, {Hour, Minute, Second} = Time, @@ -640,11 +644,19 @@ put_room_config(F, RoomConfig, Lang) -> fw(F, "<div class=\"rcos\" id=\"a~p\" style=\"display: none;\" ><br/>~s</div>", [Now2, RoomConfig]), fw(F, "</div>"). +%% htmlize +%% The default behaviour is to ignore the nofollow spam prevention on links +%% (NoFollow=false) htmlize(S1) -> + htmlize(S1, false). + +%% The NoFollow parameter tell if the spam prevention should be applied to the link found +%% true means 'apply nofollow on links'. +htmlize(S1, NoFollow) -> S2_list = string:tokens(S1, "\n"), lists:foldl( fun(Si, Res) -> - Si2 = htmlize2(Si), + Si2 = htmlize2(Si, NoFollow), case Res of "" -> Si2; _ -> Res ++ "<br/>" ++ Si2 @@ -653,14 +665,21 @@ htmlize(S1) -> "", S2_list). -htmlize2(S1) -> +htmlize2(S1, NoFollow) -> S2 = element(2, regexp:gsub(S1, "\\&", "\\&")), S3 = element(2, regexp:gsub(S2, "<", "\\<")), S4 = element(2, regexp:gsub(S3, ">", "\\>")), - S5 = element(2, regexp:gsub(S4, "(http|ftp)://.[^ ]*", "<a href=\"&\">&</a>")), + S5 = element(2, regexp:gsub(S4, "(http|ftp)://.[^ ]*", link_regexp(NoFollow))), %% Remove 'right-to-left override' unicode character 0x202e element(2, regexp:gsub(S5, [226,128,174], "[RLO]")). +%% Regexp link +%% Add the nofollow rel attribute when required +link_regexp(false) -> + "<a href=\"&\">&</a>"; +link_regexp(true) -> + "<a href=\"&\" rel=\"nofollow\">&</a>". + get_room_info(RoomJID, Opts) -> Title = case lists:keysearch(title, 1, Opts) of |