Improved strip function; minor changes

This commit is contained in:
pezcurrel 2022-12-29 19:40:05 +01:00
parent 60b6ce1f78
commit 25dc018f69

View file

@ -1,7 +1,5 @@
<?php
define('RN',"\r\n");
$bt=microtime(true);
$dlanguc=strtoupper($dlang);
@ -205,22 +203,18 @@ function nullyp($str) {
}
function strip($str,$uri) {
if (nullemp($str)) return(null);
while (preg_match('#^\s*<br\s*[\\\/]?>#i',$str)===1) $str=preg_replace('#^\s*<br\s*[\\\/]?>#i','',$str);
while (preg_match('#<br\s*[\\\/]?>\s*$#i',$str)===1) $str=preg_replace('#<br\s*[\\\/]?>\s*$#i','',$str);
while (preg_match('#<br\s*[\\\/]?>\s*<br\s*[\\\/]?>#si',$str)===1) $str=preg_replace('#<br\s*[\\\/]?>\s*<br\s*[\\\/]?>#si','<br>',$str);
$str=preg_replace('#<style( [^>]*)?>.*</style>#si','',$str);
$str=preg_replace('#<style( [^>]*)?>.*</style>#is','',$str);
$str=preg_replace('#<a href="(?![a-zA-Z]+://)([^"]+)#i','<a href="https://'.$uri.'$1>',$str);
$str=preg_replace('#<h[1-9][^>]*>#i','<p class="exh">',$str);
$str=preg_replace('#</h[1-9]>#i','</p>',$str);
$str=preg_replace(['#<h[1-9][^>]*>#i','#</h[1-9]>#i'],['<p class="exh">','</p>'],$str);
$str=preg_replace(['#</p><br>#i','#</li><br>#i','#</ul><br>#i','#<ul><br>#i'],['</p>','</li>','</ul>','<ul>'],$str);
$str=preg_replace('#<b>#i','<strong>',$str);
$str=preg_replace('#</b>#i','</strong>',$str);
$str=preg_replace('#<p></p>#i','',$str);
$str=preg_replace(['#<b>#i','#</b>#i'],['<strong>','</strong>'],$str);
$str=preg_replace('#<p>\s*</p>#is','',$str);
$str=strip_tags($str,'<a><br><ol><ul><li><p><div><i><b><strong><em><small><img>');
/*$str=preg_replace('#[\r\n]#m','',$str);
$str=preg_replace('#(<p[^>]*>|<ol[^>]*>|<ul[^>]*>|<div[^>]*>)#i',N.'$1',$str);
$str=preg_replace('#^\s*#m','',$str);
$str=preg_replace('#[\r\n]#',' ',$str);
$str=preg_replace('#(</p>|</ol>|</ul>|</div>)#i','$1'.N,$str);
$str=preg_replace(['#<p[^>]*>(.*)</p>$#i', '#<ol[^>]*>(.*)</ol>$#i', '#<ul[^>]*>(.*)</ul>$#i', '#<div[^>]*>(.*)</div>$#i'],['<p class="nobott">$1</p>', '<ol class="nobott">$1</ol>', '<ul class="nobott">$1</ul>', '<div class="nobott">$1</div>'],$str);*/
$str=rtrim($str);
$str=preg_replace(['#<p[^>]*>(.*)</p>$#i', '#<ol[^>]*>(.*)</ol>$#i', '#<ul[^>]*>(.*)</ul>$#i', '#<div[^>]*>(.*)</div>$#i'],['<p class="nobott">$1</p>', '<ol class="nobott">$1</ol>', '<ul class="nobott">$1</ul>', '<div class="nobott">$1</div>'],$str);
return($str);
}
@ -578,18 +572,18 @@ while ($if<$il && $row=mysqli_fetch_assoc($res)) {
$out.='</div>'.N;
if ($row['Noxious']) {
$out.='<div><div class="noxlab">'._('Why we consider this instance noxious').'</div><div class="noxreas">'.nully(strip(nl2br(trim(n2es($row['NoxReason'])),false),$row['URI'])).'</div></div>'.N;
$out.='<div><div class="noxlab">'._('Why we consider this instance noxious').'</div><div class="noxreas">'.nully(strip($row['NoxReason'],$row['URI'])).'</div></div>'.N;
}
$out.='<div><div class="idlab">'._('Short description').'</div><div class="idesc">'.nully(strip(nl2br(trim(n2es($row['ShortDesc'])),false),$row['URI'])).'</div></div>'.N;
$out.='<div><div class="idlab">'._('Long description').'</div><div class="idesc">'.nully(strip(trim(n2es($row['LongDesc'])),$row['URI'])).'</div></div>'.N;
$out.='<div><div class="idlab">'._('Short description').'</div><div class="idesc">'.nully(strip($row['ShortDesc'],$row['URI'])).'</div></div>'.N;
$out.='<div><div class="idlab">'._('Long description').'</div><div class="idesc">'.nully(strip($row['LongDesc'],$row['URI'])).'</div></div>'.N;
$out.='<div><div class="idlab">'._('Server rules').'</div><div class="idesc">';
$rres=tquery('SELECT Text FROM InstRules WHERE InstID='.$row['ID'],__LINE__);
if (mysqli_num_rows($rres)>0) {
$out.='<ol class="nobott">'.N;
while ($rrow=mysqli_fetch_assoc($rres))
$out.='<li>'.hspech($rrow['Text']).'</li>'.N;// no strip, do hspech, because it doesnt support html nor markdown in mastodon
$out.='<li>'.hspech($rrow['Text']).'</li>'.N;// no strip, do hspech, because server rules dont support html nor markdown in mastodon
$out.='</ol>'.N;
} else {
$out.='<span class="null">'._('Not available{plural}').'</span>';
@ -603,7 +597,7 @@ while ($if<$il && $row=mysqli_fetch_assoc($res)) {
$out.='<ul class="nobott">'.N;
while ($rrow=mysqli_fetch_assoc($rres)) {
$out.='<li><strong>'.hspech($rrow['Domain']).'</strong>: '.$sevmap[$rrow['Severity']];
if (!is_null($rrow['Comment'])) $out.=' - '.hspech($rrow['Comment']);// no strip, do hspech, because it doesnt support html nor markdown in mastodon
if (!is_null($rrow['Comment'])) $out.=' - '.hspech($rrow['Comment']);// no strip, do hspech, because moredated server comments dont support html nor markdown in mastodon
$out.='</li>'.N;
}
$out.='</ul>'.N;
@ -620,7 +614,7 @@ while ($if<$il && $row=mysqli_fetch_assoc($res)) {
} elseif ($row['AdmAccount']=='OPTED OUT') {
$admacc='<span class="null">'._('Opted out of search engines indexing').'</span>';
}
$out.='<div class="abox"><img class="aimg" src="'.$thumb.'"><div><span class="ilab">'._('Admin account').'</span> '.$admacc.'</div><div><span class="ilab">'._('Date of creation').'</span> '.nully(ldate($row['AdmCreatedAt'],true)).'</div><div><span class="ilab">'._('Admin name').'</span> '.nully(hspech($row['AdmDisplayName'])).'</div><div><div class="idlab">'._('Admin notes').'</div><div class="inote">'.nullyp(strip(trim(n2es($row['AdmNote'])),$row['URI'])).'</div>'.N;
$out.='<div class="abox"><img class="aimg" src="'.$thumb.'"><div><span class="ilab">'._('Admin account').'</span> '.$admacc.'</div><div><span class="ilab">'._('Date of creation').'</span> '.nully(ldate($row['AdmCreatedAt'],true)).'</div><div><span class="ilab">'._('Display name').'</span> '.nully(hspech($row['AdmDisplayName'])).'</div><div><div class="idlab">'._('Bio').'</div><div class="inote">'.nully(strip($row['AdmNote'],$row['URI'])).'</div>'.N;
$out.='</div></div>';
$out.='<div class="ghost"><div class="idlab">'._('Stats').'</div><div class="istat">';