################################################################################## ## ## MOD Title: derefer.me MOD ## MOD Author: N/A < info[at]derefer.me > (Martin Janecke) http://derefer.me/ ## MOD Description: ## This MOD derefers all user posted external hyperlinks. ## MOD Version: 1.2.1 ## ## Installation Level: Easy ## Installation Time: 12 Minutes ## Files To Edit: ## groupcp.php ## includes/bbcode.php ## includes/functions.php ## includes/usercp_viewprofile.php ## memberlist.php ## privmsg.php ## viewtopic.php ## Included Files: N/A ## ################################################################################## ## Author Notes: ## ## This MOD derefers all user posted external hyperlinks with or without ## url-tags, including the user's website from the user profile. It doesn't ## derefer links to messengers such as ICQ. ## Neither does it derefer external images using the img-tag. Derefering ## img-tags requires another technology, such as an image proxy. ## ## This MOD is tested for phpbb-2.0.23. Please update your forum software ## to this phpbb-2 version prior to installing this mod. ## ## Please download the newest version of this mod from: ## http://derefer.me/download/derefer-me-mod-phpbb-2.txt ## ################################################################################## ## MOD History: ## ## 2008-07-24 - Version 1.0.0 ## - Initial Release ## ## 2008-11-23 - Version 1.1.0 ## - Use a function for dereferring. ## ## 2009-04-25 - Version 1.2.0 ## - Only derefer external links. ## ## 2010-03-16 - Version 1.2.1 ## - Fixed an error with URLs including the ampersand. ## ################################################################################## ## ## Before adding this MOD to your forum, you should back up all files ## related to this MOD. ## ################################################################################## # #-----[ OPEN ]----- # groupcp.php # #-----[ FIND ]----- # $www_img = ( $row['user_website'] ) ? '' . $lang['Visit_website'] . '' : ''; $www = ( $row['user_website'] ) ? '' . $lang['Visit_website'] . '' : ''; # #-----[ REPLACE WITH ]----- # $www_img = ( $row['user_website'] ) ? '' . $lang['Visit_website'] . '' : ''; $www = ( $row['user_website'] ) ? '' . $lang['Visit_website'] . '' : ''; # #-----[ OPEN ]----- # includes/bbcode.php # #-----[ FIND ]----- # // We do URLs in several different ways.. $bbcode_tpl['url1'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']); $bbcode_tpl['url1'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url1']); $bbcode_tpl['url2'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']); $bbcode_tpl['url2'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url2']); $bbcode_tpl['url3'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']); $bbcode_tpl['url3'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['url3']); $bbcode_tpl['url4'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']); $bbcode_tpl['url4'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url4']); # #-----[ REPLACE WITH ]----- # // We do URLs in several different ways... $bbcode_tpl['url1'] = ' global $bbcode_tpl; $url1 = str_replace("{URL}", derefer ($match[1]), $bbcode_tpl["url"]); return str_replace("{DESCRIPTION}", $match[1], $url1); '; $bbcode_tpl['url2'] = ' global $bbcode_tpl; $url2 = str_replace("{URL}", derefer ("http://{$match[1]}"), $bbcode_tpl["url"]); return str_replace("{DESCRIPTION}", $match[1], $url2); '; $bbcode_tpl['url3'] = ' global $bbcode_tpl; $url3 = str_replace("{URL}", derefer ($match[1]), $bbcode_tpl["url"]); return str_replace("{DESCRIPTION}", $match[2], $url3); '; $bbcode_tpl['url4'] = ' global $bbcode_tpl; $url4 = str_replace("{URL}", derefer ("http://{$match[1]}"), $bbcode_tpl["url"]); return str_replace("{DESCRIPTION}", $match[3], $url4); '; # #-----[ FIND ]----- # // Patterns and replacements for URL and email tags.. $patterns = array(); $replacements = array(); # #-----[ AFTER, ADD ]----- # $callback_patterns = array(); $callback_replacements = array(); # #-----[ FIND ]----- # // matches a [url]xxxx://www.phpbb.com[/url] code.. $patterns[] = "#\[url\]([\w]+?://([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is"; $replacements[] = $bbcode_tpl['url1']; // [url]www.phpbb.com[/url] code.. (no xxxx:// prefix). $patterns[] = "#\[url\]((www|ftp)\.([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is"; $replacements[] = $bbcode_tpl['url2']; // [url=xxxx://www.phpbb.com]phpBB[/url] code.. $patterns[] = "#\[url=([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is"; $replacements[] = $bbcode_tpl['url3']; // [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix). $patterns[] = "#\[url=((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is"; $replacements[] = $bbcode_tpl['url4']; # #-----[ REPLACE WITH ]----- # // matches a [url]xxxx://www.phpbb.com[/url] code.. $callback_patterns[] = "#\[url\]([\w]+?://([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is"; $callback_replacements[] = $bbcode_tpl['url1']; // [url]www.phpbb.com[/url] code.. (no xxxx:// prefix). $callback_patterns[] = "#\[url\]((www|ftp)\.([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is"; $callback_replacements[] = $bbcode_tpl['url2']; // [url=xxxx://www.phpbb.com]phpBB[/url] code.. $callback_patterns[] = "#\[url=([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is"; $callback_replacements[] = $bbcode_tpl['url3']; // [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix). $callback_patterns[] = "#\[url=((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is"; $callback_replacements[] = $bbcode_tpl['url4']; # #-----[ FIND ]----- # $text = preg_replace($patterns, $replacements, $text); # #-----[ AFTER, ADD ]----- # foreach ($callback_patterns as $key => $pattern) { $text = preg_replace_callback($pattern, create_function ('$match', $callback_replacements[$key]), $text); } # #-----[ FIND ]----- # $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1\\2", $ret); # #-----[ REPLACE WITH ]----- # $ret = preg_replace_callback ( "#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", create_function ( '$match', 'return "{$match[1]}{$match[2]}";' ), $ret ); # #-----[ FIND ]----- # $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1\\2", $ret); # #-----[ REPLACE WITH ]----- # $ret = preg_replace_callback ( "#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", create_function ( '$match', 'return "{$match[1]}{$match[2]}";' ), $ret ); # #-----[ OPEN ]----- # includes/functions.php # #-----[ FIND ]----- # function get_db_stat($mode) # #-----[ BEFORE, ADD ]----- # // dereferring function function derefer ($url) { global $board_config; // return the unaltered URL for local links if (($components = @parse_url ($url)) && isset ($components['host']) && isset ($board_config['server_name'])) { if (strtolower ($components['host']) == strtolower ($board_config['server_name'])) { return $url; } } // return the dereferred URL for external links return 'http://derefer.me/?' . urlencode (str_replace ('&', '&', $url)); } # #-----[ OPEN ]----- # includes/usercp_viewprofile.php # #-----[ FIND ]----- # $www_img = ( $profiledata['user_website'] ) ? '' . $lang['Visit_website'] . '' : ' '; $www = ( $profiledata['user_website'] ) ? '' . $profiledata['user_website'] . '' : ' '; # #-----[ REPLACE WITH ]----- # $www_img = ( $profiledata['user_website'] ) ? '' . $lang['Visit_website'] . '' : ' '; $www = ( $profiledata['user_website'] ) ? '' . $profiledata['user_website'] . '' : ' '; # #-----[ OPEN ]----- # memberlist.php # #-----[ FIND ]----- # $www_img = ( $row['user_website'] ) ? '' . $lang['Visit_website'] . '' : ''; $www = ( $row['user_website'] ) ? '' . $lang['Visit_website'] . '' : ''; # #-----[ REPLACE WITH ]----- # $www_img = ( $row['user_website'] ) ? '' . $lang['Visit_website'] . '' : ''; $www = ( $row['user_website'] ) ? '' . $lang['Visit_website'] . '' : ''; # #-----[ OPEN ]----- # privmsg.php # #-----[ FIND ]----- # $www_img = ( $privmsg['user_website'] ) ? '' . $lang['Visit_website'] . '' : ''; $www = ( $privmsg['user_website'] ) ? '' . $lang['Visit_website'] . '' : ''; # #-----[ REPLACE WITH ]----- # $www_img = ( $privmsg['user_website'] ) ? '' . $lang['Visit_website'] . '' : ''; $www = ( $privmsg['user_website'] ) ? '' . $lang['Visit_website'] . '' : ''; # #-----[ OPEN ]----- # viewtopic.php # #-----[ FIND ]----- # $www_img = ( $postrow[$i]['user_website'] ) ? '' . $lang['Visit_website'] . '' : ''; $www = ( $postrow[$i]['user_website'] ) ? '' . $lang['Visit_website'] . '' : ''; # #-----[ REPLACE WITH ]----- # $www_img = ( $postrow[$i]['user_website'] ) ? '' . $lang['Visit_website'] . '' : ''; $www = ( $postrow[$i]['user_website'] ) ? '' . $lang['Visit_website'] . '' : ''; # #-----[ SAVE/CLOSE ALL FILES ]----- # # EoM