Allow using html tags in linkfilter without breaking dereferrer or image embed

This commit is contained in:
Daniel Winzen
2016-03-06 07:52:08 +01:00
parent cbba4e5784
commit 8d2b10468f
2 changed files with 10 additions and 8 deletions

View File

@ -1,3 +1,5 @@
Version 1.15.3 - Mar. 6, 2016
Allow using html tags in linkfilter without breaking dereferrer or image embed
Added French translation Added French translation
Added 2 Spanish translations. Added 2 Spanish translations.

View File

@ -2647,7 +2647,7 @@ function apply_linkfilter(){
} }
} }
foreach($filters as $filter){ foreach($filters as $filter){
$U['message']=preg_replace_callback("/<a href=\"([^\"]+)\" target=\"_blank\">([^<]+)<\/a>/i", $U['message']=preg_replace_callback("/<a href=\"([^\"]+)\" target=\"_blank\">(.*?(?=<\/a>))<\/a>/i",
function ($matched) use(&$filter){ function ($matched) use(&$filter){
return "<a href=\"$matched[1]\" target=\"_blank\">".preg_replace("/$filter[match]/i", $filter['replace'], $matched[2]).'</a>'; return "<a href=\"$matched[1]\" target=\"_blank\">".preg_replace("/$filter[match]/i", $filter['replace'], $matched[2]).'</a>';
} }
@ -2655,7 +2655,7 @@ function apply_linkfilter(){
} }
$redirect=get_setting('redirect'); $redirect=get_setting('redirect');
if(get_setting('imgembed')){ if(get_setting('imgembed')){
$U['message']=preg_replace_callback('/\[img\]\s?<a href="([^"]+)" target="_blank">([^<]+)<\/a>/i', $U['message']=preg_replace_callback('/\[img\]\s?<a href="([^"]+)" target="_blank">(.*?(?=<\/a>))<\/a>/i',
function ($matched){ function ($matched){
return str_ireplace('[/img]', '', "<br><a href=\"$matched[1]\" target=\"_blank\"><img src=\"$matched[1]\"></a><br>"); return str_ireplace('[/img]', '', "<br><a href=\"$matched[1]\" target=\"_blank\"><img src=\"$matched[1]\"></a><br>");
} }
@ -2665,15 +2665,15 @@ function apply_linkfilter(){
$redirect="$_SERVER[SCRIPT_NAME]?action=redirect&url="; $redirect="$_SERVER[SCRIPT_NAME]?action=redirect&url=";
} }
if(get_setting('forceredirect')){ if(get_setting('forceredirect')){
$U['message']=preg_replace_callback('/<a href="([^"]+)" target="_blank">([^<]+)<\/a>/', $U['message']=preg_replace_callback('/<a href="([^"]+)" target="_blank">(.*?(?=<\/a>))<\/a>/',
function ($matched) use($redirect){ function ($matched) use($redirect){
return "<a href=\"$redirect".urlencode($matched[1])."\" target=\"_blank\">$matched[2]</a>"; return "<a href=\"$redirect".urlencode($matched[1])."\" target=\"_blank\">$matched[2]</a>";
} }
, $U['message']); , $U['message']);
}elseif(preg_match_all('/<a href="([^"]+)" target="_blank">([^<]+)<\/a>/', $U['message'], $matches)){ }elseif(preg_match_all('/<a href="([^"]+)" target="_blank">(.*?(?=<\/a>))<\/a>/', $U['message'], $matches)){
foreach($matches[1] as $match){ foreach($matches[1] as $match){
if(!preg_match('~^http(s)?://~', $match)){ if(!preg_match('~^http(s)?://~', $match)){
$U['message']=preg_replace_callback('/<a href="('.str_replace('/', '\/', $match).')\" target=\"_blank\">([^<]+)<\/a>/', $U['message']=preg_replace_callback('/<a href="('.str_replace('/', '\/', $match).')\" target=\"_blank\">(.*?(?=<\/a>))<\/a>/',
function ($matched) use($redirect){ function ($matched) use($redirect){
return "<a href=\"$redirect".urlencode($matched[1])."\" target=\"_blank\">$matched[2]</a>"; return "<a href=\"$redirect".urlencode($matched[1])."\" target=\"_blank\">$matched[2]</a>";
} }
@ -2837,7 +2837,7 @@ function print_messages($delstatus=''){
$message['text']=openssl_decrypt($message['text'], 'aes-256-cbc', $C['encryptkey'], 0, '1234567890123456'); $message['text']=openssl_decrypt($message['text'], 'aes-256-cbc', $C['encryptkey'], 0, '1234567890123456');
} }
if($injectRedirect){ if($injectRedirect){
$message['text']=preg_replace_callback('/<a href="([^"]+)" target="_blank">([^<]+)<\/a>/', $message['text']=preg_replace_callback('/<a href="([^"]+)" target="_blank">(.*?(?=<\/a>))<\/a>/',
function ($matched) use ($redirect){ function ($matched) use ($redirect){
return "<a href=\"$redirect".urlencode($matched[1])."\" target=\"_blank\">$matched[2]</a>"; return "<a href=\"$redirect".urlencode($matched[1])."\" target=\"_blank\">$matched[2]</a>";
} }
@ -2871,7 +2871,7 @@ function print_messages($delstatus=''){
$message['text']=openssl_decrypt($message['text'], 'aes-256-cbc', $C['encryptkey'], 0, '1234567890123456'); $message['text']=openssl_decrypt($message['text'], 'aes-256-cbc', $C['encryptkey'], 0, '1234567890123456');
} }
if($injectRedirect){ if($injectRedirect){
$message['text']=preg_replace_callback('/<a href="([^"]+)" target="_blank">([^<]+)<\/a>/', $message['text']=preg_replace_callback('/<a href="([^"]+)" target="_blank">(.*?(?=<\/a>))<\/a>/',
function ($matched) use($redirect) { function ($matched) use($redirect) {
return "<a href=\"$redirect".urlencode($matched[1])."\" target=\"_blank\">$matched[2]</a>"; return "<a href=\"$redirect".urlencode($matched[1])."\" target=\"_blank\">$matched[2]</a>";
} }
@ -3375,7 +3375,7 @@ function load_lang(){
function load_config(){ function load_config(){
global $C; global $C;
$C=array( $C=array(
'version' =>'1.15.2', // Script version 'version' =>'1.15.3', // Script version
'dbversion' =>14, // Database version 'dbversion' =>14, // Database version
'keeplimit' =>3, // Amount of messages to keep in the database (multiplied with max messages displayed) - increase if you have many private messages 'keeplimit' =>3, // Amount of messages to keep in the database (multiplied with max messages displayed) - increase if you have many private messages
'msgencrypted' =>false, // Store messages encrypted in the database to prevent other database users from reading them - true/false - visit the setup page after editing! 'msgencrypted' =>false, // Store messages encrypted in the database to prevent other database users from reading them - true/false - visit the setup page after editing!