“Advanced criteria” are always displayed; removed “reset advanced criteria to default”; restructured code
This commit is contained in:
parent
1d754f9588
commit
1f2165249d
1 changed files with 94 additions and 178 deletions
|
@ -28,7 +28,7 @@ $oldline=31*24*60*60;
|
|||
|
||||
// an instance is considered dead if the last time it responded is before the graceline (see code below)
|
||||
// $gracetime is defined in mustard/include/gracetime.php
|
||||
$graceline=time()-$gracetime;
|
||||
$graceline=$bt-$gracetime;
|
||||
|
||||
if (array_key_exists('id',$_GET) && preg_match('/^\d+$/',$_GET['id'])) {
|
||||
$_GET['id']+=0;
|
||||
|
@ -38,15 +38,9 @@ if (array_key_exists('id',$_GET) && preg_match('/^\d+$/',$_GET['id'])) {
|
|||
}
|
||||
|
||||
//$getc=count($_GET);
|
||||
//forzo $getc a 1 per non mostrare mai la spiega di come funziona il motore di ricerca
|
||||
//forcing $getc to 1 to never display the explanation of search engine workings
|
||||
$getc=1;
|
||||
|
||||
if (array_key_exists('advc',$_GET)) {
|
||||
($_GET['advc']=='1') ? $_GET['advc']=1 : $_GET['advc']=0;
|
||||
} else {
|
||||
$_GET['advc']=0;
|
||||
}
|
||||
|
||||
$minudef=10;
|
||||
$minumax=4294967295;
|
||||
$maxudef=30000;
|
||||
|
@ -70,45 +64,25 @@ echo('</nav>
|
|||
<img src="'.$prepath.'imgs/helpbutti.svg" id="helpbutt" class="helpb" onmouseover="swhelpi(true);" onmouseout="swhelpi(false);" onclick="swhelp();">
|
||||
<h3>'._('Instances').'</h3>
|
||||
<script language="JavaScript">
|
||||
let mctrlsh=false;
|
||||
function shmctrl() {
|
||||
let mctrl=document.getElementById("mctrl");
|
||||
let mctrlb=document.getElementById("mctrlb");
|
||||
let advc=document.getElementById("advc");
|
||||
if (mctrlsh) {
|
||||
//mctrl.style.display="none";
|
||||
mctrl.style.height="0px";
|
||||
//mctrlb.className="litbut";
|
||||
mctrlb.value="'._('Show advanced criteria').'";
|
||||
advc.value=0;
|
||||
mctrlsh=false;
|
||||
} else {
|
||||
//mctrl.style.display="block";
|
||||
mctrl.style.height=mctrl.scrollHeight+"px";
|
||||
//mctrlb.className="litbuta";
|
||||
mctrlb.value="'._('Hide advanced criteria').'";
|
||||
advc.value=1;
|
||||
mctrlsh=true;
|
||||
}
|
||||
}
|
||||
|
||||
let helpsh='.(($getc==0) ? 'false' : 'true').';
|
||||
|
||||
function swhelp() {
|
||||
let hdiv=document.getElementById("help");
|
||||
let himg=document.getElementById("helpbutt");
|
||||
if (helpsh) {
|
||||
//hdiv.style.display="none";
|
||||
hdiv.style.height="0px";
|
||||
himg.title="'._('Show introduction').'";
|
||||
himg.src="'.$prepath.'imgs/helpbutti.svg";
|
||||
helpsh=false;
|
||||
} else {
|
||||
//hdiv.style.display="block";
|
||||
hdiv.style.height=hdiv.scrollHeight+"px";
|
||||
himg.title="'._('Hide introduction').'";
|
||||
himg.src="'.$prepath.'imgs/helpbutta.svg";
|
||||
helpsh=true;
|
||||
}
|
||||
}
|
||||
|
||||
function swhelpi(over) {
|
||||
let himg=document.getElementById("helpbutt"), ia;
|
||||
if (helpsh) {
|
||||
|
@ -118,67 +92,17 @@ function swhelpi(over) {
|
|||
}
|
||||
himg.src="'.$prepath.'imgs/helpbutt"+ia+".svg";
|
||||
}
|
||||
|
||||
function swp(pn) {
|
||||
document.curvf.p.value=pn;
|
||||
document.curvf.submit();
|
||||
}
|
||||
|
||||
function sethid(obj) {
|
||||
if (document.getElementById("cb"+obj).checked)
|
||||
document.getElementById(obj).value=1;
|
||||
else
|
||||
document.getElementById(obj).value=0;
|
||||
ckadvcri();
|
||||
}
|
||||
|
||||
let advcri=true;
|
||||
|
||||
function ckadvcri() {
|
||||
if (document.getElementById("minu").value!='.$minudef.' ||
|
||||
document.getElementById("maxu").value!='.$maxudef.' ||
|
||||
document.getElementById("minau").value!='.$minaudef.' ||
|
||||
document.getElementById("minc").value!='.$mincdef.' ||
|
||||
document.getElementById("cbnoxious").checked==false ||
|
||||
document.getElementById("cbcreg").checked==false ||
|
||||
document.getElementById("cbappr").checked==true ||
|
||||
document.getElementById("cblcok").checked==true) {
|
||||
|
||||
document.getElementById("disadvcrib").value="'._('Reset all advanced criteria to default').'";
|
||||
advcri=false;
|
||||
} else {
|
||||
document.getElementById("disadvcrib").value="'._('Disable all advanced criteria').'";
|
||||
advcri=true;
|
||||
}
|
||||
}
|
||||
|
||||
function endisadvcri() {
|
||||
if (advcri) {
|
||||
document.getElementById("minu").value="";
|
||||
document.getElementById("maxu").value="";
|
||||
document.getElementById("minau").value="";
|
||||
document.getElementById("minc").value="";
|
||||
document.getElementById("cbnoxious").checked=false;
|
||||
document.getElementById("noxious").value=0;
|
||||
document.getElementById("cbcreg").checked=false;
|
||||
document.getElementById("creg").value=0;
|
||||
document.getElementById("cbappr").checked=false;
|
||||
document.getElementById("appr").value=0;
|
||||
document.getElementById("cblcok").checked=false;
|
||||
document.getElementById("lcok").value=0;
|
||||
} else {
|
||||
document.getElementById("minu").value='.$minudef.';
|
||||
document.getElementById("maxu").value='.$maxudef.';
|
||||
document.getElementById("minau").value='.$minaudef.';
|
||||
document.getElementById("minc").value='.$mincdef.';
|
||||
document.getElementById("cbnoxious").checked=true;
|
||||
document.getElementById("noxious").value=1;
|
||||
document.getElementById("cbcreg").checked=true;
|
||||
document.getElementById("creg").value=1;
|
||||
document.getElementById("cbappr").checked=false;
|
||||
document.getElementById("appr").value=0;
|
||||
document.getElementById("cblcok").checked=false;
|
||||
document.getElementById("lcok").value=0;
|
||||
}
|
||||
ckadvcri();
|
||||
}
|
||||
|
||||
function presub() {
|
||||
|
@ -192,60 +116,6 @@ function presub() {
|
|||
</script>
|
||||
'.N);
|
||||
|
||||
function nullemp($inp) {
|
||||
if (is_null($inp) || preg_match('/^\s*$/',$inp)===1) return(true);
|
||||
return(false);
|
||||
}
|
||||
function ldate($ts,$dateonly=false) {
|
||||
if (nullemp($ts)) return(null);
|
||||
$ts=round($ts);
|
||||
if (!$dateonly)
|
||||
return(gmdate('d/m/Y H:i:s e',$ts));
|
||||
else
|
||||
return(gmdate('d/m/Y e',$ts));
|
||||
}
|
||||
function hspech($str) {
|
||||
if (nullemp($str)) return(null);
|
||||
return(htmlspecialchars($str,ENT_QUOTES|ENT_HTML5,'UTF-8'));
|
||||
}
|
||||
function muorimeglio($msg,$close) {
|
||||
global $link;
|
||||
if ($close)
|
||||
mysqli_close($link);
|
||||
echo('<p>'.$msg.'</p>'.N.'</section>'.N.'</div>'.N.'</div>'.N.'</body>'.N);
|
||||
exit(2);
|
||||
}
|
||||
function nully($str) {
|
||||
// "Not available" in singular form - translators, please omit "{singular}" from translation,
|
||||
// it's there just to diversify this "Not available" from the next one
|
||||
if (nullemp($str)) return('<span class="null">'._('Not available{singular}').'</span>');
|
||||
return($str);
|
||||
}
|
||||
function nullyp($str) {
|
||||
// "Not available" in plural form - translators, please omit "{plural}" from translation,
|
||||
// it's there just to diversify this "Not available" from the previous one
|
||||
if (nullemp($str)) return('<span class="null">'._('Not available{plural}').'</span>');
|
||||
return($str);
|
||||
}
|
||||
function strip($str,$uri) {
|
||||
if (nullemp($str)) return(null);
|
||||
$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','#</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','#</b>#i','#<i>#i','#</i>#i'],['<strong>','</strong>','<em>','</em>'],$str);
|
||||
$str=preg_replace('#<p>\s*</p>#is','',$str);
|
||||
$str=strip_tags($str,'<a><br><ol><ul><li><p><div><strong><em><small><img>');
|
||||
// all this part below is to try and assign the css "nobott" css class to a possible closing <p>/<ol>/<ul>/<div>,
|
||||
// to avoid the useless and UGLY last bottom-margin :-))
|
||||
$str=preg_replace('#^\s*#m','',$str);// strip all spaces from empty lines
|
||||
$str=preg_replace('#[\r\n]#',' ',$str);// strip all "wrap chars"
|
||||
$str=preg_replace('#(</p>|</ol>|</ul>|</div>)#i','$1'.N,$str);// now add a newline after every </p> and so on
|
||||
$str=rtrim($str);// trim the newline at the end of the whole text block in order for the next preg_replace to match against $ as end of the whole text block
|
||||
$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);
|
||||
}
|
||||
|
||||
$link=mysqli_connect($conf['db_host'],$conf['db_user_name'],$conf['db_user_password'],$conf['db_name'],$conf['db_port'],$conf['db_socket']) or muorimeglio(_('Couldn’t connect to database: ').mysqli_connect_error().' ['.mysqli_connect_errno().']',false);
|
||||
mysqli_set_charset($link,'utf8mb4');
|
||||
|
||||
|
@ -254,10 +124,6 @@ $row=mysqli_fetch_assoc($res);
|
|||
echo(_('<div id="help" class="helpd"><p class="intro">This is our search engine for Mastodon instances. It works this way: data of already indexed instances gets updated every night, and a shuffling occurs for the “random ordering”; also, once a week, during the night between Tuesday and Wednesday, new instances get searched for and added to the database.</p><p class="intro">Advanced search criteria are customizable, but by default they reflect our fondness for a decentralized and egalitarian Fediverse, and we try to exclude instances accepting fascist, racist, sexist, ableist, sovereignist contents.</p></div>').N);
|
||||
printf(_('<p class="introe">We currently count <span class="statd">%s</span> Mastodon instances, with <span class="statd">%s</span> users (<span class="statd">%s</span> active during last month) and <span class="statd">%s</span> published statuses.</p>').N, fnum($row['tinsts'],0,$dlang), fnum($row['tusers'],0,$dlang), fnum($row['tactusers'],0,$dlang), fnum($row['tstatuses'],0,$dlang));
|
||||
|
||||
// <p class="intro">Nella prima versione stabile daremo a* admin delle istanze compatibili con questa politica la possibilità di descrivere ulteriormente la propria istanza con questi campi, tutti facoltativi: “Descrizione in inglese” (per le istanze la cui descrizione è in altre lingue), “Località” (se l’istanza è particolarmente legata a un territorio), “Lingue” (se le lingue utilizzate prevalentemente sull’istanza non corrispondono a quelle rilevate automaticamente dal nostro crawler), “Modalità di copertura dei costi” (per esempio “Autonoma”, “Sottoscrizioni volontarie degli utenti”, “Iniziative benefit”), “Regole sui contenuti” (per esempio “Tag NSFW per i nudi”, “No link a siti di partiti politici”, “No pubblicità”, “Content Warning prima degli spoiler”), e “Categorie” (per esempio “Generalista”, “Astronomia”, “Politica”, “Musica folk”).</p>
|
||||
// daremo la possibilità di segnalarci le istanze su cui sono accettati contenuti di questo tipo
|
||||
// Le istanze che non rispondono da più di due mesi vengono dichiarate “morte” nel database e non vengono più mostrate tra i risultati della ricerca, ma una volta all’anno, nella notte di Halloween (31 ottobre), vengono nuovamente controllate e, se rispondono, “resuscitate”
|
||||
|
||||
if ((array_key_exists('noxious',$_GET) && $_GET['noxious']=='1') || !array_key_exists('noxious',$_GET)) {
|
||||
$_GET['cbnoxious']=' checked';
|
||||
$_GET['noxious']=1;
|
||||
|
@ -265,7 +131,6 @@ if ((array_key_exists('noxious',$_GET) && $_GET['noxious']=='1') || !array_key_e
|
|||
$_GET['cbnoxious']='';
|
||||
$_GET['noxious']=0;
|
||||
}
|
||||
//echo('<p>noxious: '.$_GET['noxious'].'</p>');
|
||||
|
||||
if ((array_key_exists('creg',$_GET) && $_GET['creg']=='1') || !array_key_exists('creg',$_GET)) {
|
||||
$_GET['cbcreg']=' checked';
|
||||
|
@ -313,20 +178,6 @@ else
|
|||
$_GET['desc']='';
|
||||
if (mb_strlen($_GET['desc'])>64) $_GET['desc']='';
|
||||
|
||||
function ckgnum($key,$def,$max) {
|
||||
if (array_key_exists($key,$_GET)) {
|
||||
$_GET[$key]=trim($_GET[$key]);
|
||||
if (preg_match('#^\d+$#',$_GET[$key])===1) {
|
||||
$_GET[$key]=$_GET[$key]+0;
|
||||
if ($_GET[$key]>$max) $_GET[$key]=$max;
|
||||
} elseif ($_GET[$key]!='') {
|
||||
$_GET[$key]=$def;
|
||||
}
|
||||
} else {
|
||||
$_GET[$key]=$def;
|
||||
}
|
||||
}
|
||||
|
||||
ckgnum('minu',$minudef,$minumax);
|
||||
ckgnum('maxu',$maxudef,$maxumax);
|
||||
if (is_int($_GET['maxu']) && is_int($_GET['minu']) && $_GET['maxu']<$_GET['minu']) $_GET['maxu']=$_GET['minu'];
|
||||
|
@ -357,7 +208,6 @@ $p=1;
|
|||
if (array_key_exists('p',$_GET) && preg_match('#^[0-9]+$#',$_GET['p'])===1) $p=$_GET['p']+0;
|
||||
|
||||
echo('<form method="get" id="curvf" name="curvf">
|
||||
<input name="advc" type="hidden" value="'.$_GET['advc'].'">
|
||||
<input name="noxious" type="hidden" value="'.$_GET['noxious'].'">
|
||||
<input name="creg" type="hidden" value="'.$_GET['creg'].'">
|
||||
<input name="appr" type="hidden" value="'.$_GET['appr'].'">
|
||||
|
@ -371,7 +221,9 @@ echo('<form method="get" id="curvf" name="curvf">
|
|||
<input name="ord" type="hidden" value="'.$_GET['ord'].'">
|
||||
<input name="p" type="hidden" value="'.$p.'">
|
||||
</form>'.N);
|
||||
|
||||
($_GET['lang']==0) ? $selected=' selected' : $selected='';
|
||||
|
||||
echo('<form method="get" id="searchf" class="sdbox" onsubmit="presub();">
|
||||
<div class="sdtit">'._('Search criteria').'</div>
|
||||
<div class="sddesc">'._('Show instances where...').'</div>
|
||||
|
@ -380,12 +232,14 @@ echo('<form method="get" id="searchf" class="sdbox" onsubmit="presub();">
|
|||
<div class="sdinput">
|
||||
<select id="lang" name="lang" class="sselect">
|
||||
<option value="0"'.$selected.'>'._('Irrelevant').'</option>'.N);
|
||||
|
||||
$res=mysqli_query($link,'SELECT Languages.ID AS Lid, CONCAT(Name'.$dlanguc.', \' [\', Code, \'] (\', COUNT(Languages.ID), \')\') AS Txt FROM InstOurLangs LEFT JOIN Languages ON Languages.ID=OurLangID LEFT JOIN Instances ON Instances.ID=InstOurLangs.InstID WHERE Instances.LastOkCheckTS>='.$graceline.' AND Instances.IsMastodon=1 AND InstOurLangs.Pos=1 GROUP BY Languages.ID ORDER BY Name'.$dlanguc.' ASC') or muorimeglio(__LINE__.': '.mysqli_error($link),true);
|
||||
//$res=mysqli_query($link,'SELECT Languages.ID AS Lid, CONCAT(Name'.$dlanguc.', \' (\', Code, \')\') AS Txt FROM InstOurLangs LEFT JOIN Languages ON Languages.ID=OurLangID LEFT JOIN Instances ON Instances.ID=InstOurLangs.InstID WHERE Instances.LastOkCheckTS>='.$graceline.' AND Instances.IsMastodon=1 AND InstOurLangs.Pos=1 GROUP BY Languages.ID ORDER BY Name'.$dlanguc.' ASC') or muorimeglio(__LINE__.': '.mysqli_error($link),true);
|
||||
|
||||
while ($row=mysqli_fetch_assoc($res)) {
|
||||
($_GET['lang']==$row['Lid']) ? $selected=' selected' : $selected='';
|
||||
echo('<option value="'.$row['Lid'].'"'.$selected.'>'.$row['Txt'].'</option>'.N);
|
||||
}
|
||||
|
||||
echo('</select>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -394,25 +248,21 @@ echo('</select>
|
|||
<div class="sdinput"><input type="text" id="desc" name="desc" class="sinput" maxlength="64" value="'.hspech($_GET['desc']).'" autofocus></div>
|
||||
</div>
|
||||
|
||||
<div id="mctrl">
|
||||
<div class="sdrow">
|
||||
<input type="button" class="litbut" id="disadvcrib" value="'._('Disable all advanced criteria').'" onclick="endisadvcri();">
|
||||
</div>
|
||||
<div class="sdrow">
|
||||
<div class="sdlabel"><label for="minu" title="'._('Include only instances which have at least this number of users [set to empty to disable this criterion]').'">'._('Users are at least').'</label></div>
|
||||
<div class="sdinput"><input type="number" id="minu" name="minu" min="0" max="'.$minumax.'" class="sinput" value="'.$_GET['minu'].'" onchange="ckadvcri();"></div>
|
||||
<div class="sdinput"><input type="number" id="minu" name="minu" min="0" max="'.$minumax.'" class="sinput" value="'.$_GET['minu'].'"></div>
|
||||
</div>
|
||||
<div class="sdrow">
|
||||
<div class="sdlabel"><label for="maxu" title="'._('Include only instances which have at most this number of users [set to empty to disable this criterion]').'">'._('Users are at most').'</label></div>
|
||||
<div class="sdinput"><input type="number" id="maxu" name="maxu" min="0" max="'.$maxumax.'" class="sinput" value="'.$_GET['maxu'].'" onchange="ckadvcri();"></div>
|
||||
<div class="sdinput"><input type="number" id="maxu" name="maxu" min="0" max="'.$maxumax.'" class="sinput" value="'.$_GET['maxu'].'"></div>
|
||||
</div>
|
||||
<div class="sdrow">
|
||||
<div class="sdlabel"><label for="minau" title="'._('Include only instances which had at least this number of active users during the last 30 days [set to empty to disable this criterion]').'">'._('Active users are at least').'</label></div>
|
||||
<div class="sdinput"><input type="number" id="minau" name="minau" min="0" max="'.$minaumax.'" class="sinput" value="'.$_GET['minau'].'" onchange="ckadvcri();"></div>
|
||||
<div class="sdinput"><input type="number" id="minau" name="minau" min="0" max="'.$minaumax.'" class="sinput" value="'.$_GET['minau'].'"></div>
|
||||
</div>
|
||||
<div class="sdrow">
|
||||
<div class="sdlabel"><label for="minc" title="'._('Include only instances on which the number of available characters per post is at least this [set to empty to disable this criterion]').'">'._('Max. chars per post are at least').'</label></div>
|
||||
<div class="sdinput"><input type="number" id="minc" name="minc" min="0" max="'.$mincmax.'" class="sinput" value="'.$_GET['minc'].'" onchange="ckadvcri();"></div>
|
||||
<div class="sdinput"><input type="number" id="minc" name="minc" min="0" max="'.$mincmax.'" class="sinput" value="'.$_GET['minc'].'"></div>
|
||||
</div>
|
||||
<div class="hrd"></div>
|
||||
<div class="sdrow">
|
||||
|
@ -443,15 +293,6 @@ echo('</select>
|
|||
<input type="hidden" id="lcok" name="lcok" value="'.$_GET['lcok'].'">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script language="JavaScript">
|
||||
ckadvcri();
|
||||
</script>
|
||||
|
||||
<div class="sdcrow">
|
||||
<input type="button" class="litbut" id="mctrlb" value="'._('Advanced criteria').'" onclick="shmctrl()">
|
||||
</div>
|
||||
|
||||
<div class="sdtitb">'._('Order of results').'</div>
|
||||
|
||||
|
@ -472,15 +313,13 @@ echo('</select>
|
|||
<input type="button" class="litbut" value="'._('Reset search').'" onclick="document.location.href=document.location.href.replace(/\\?.*$/,\'\')">
|
||||
</div>
|
||||
|
||||
<input type="hidden" id="advc" name="advc" value="'.$_GET['advc'].'">
|
||||
<input type="hidden" id="p" name="p" value="'.$p.'">
|
||||
</form>
|
||||
|
||||
<script language="JavaScript">
|
||||
mctrlsh='.(($_GET['advc']==1) ? 'false' : 'true').';
|
||||
shmctrl();
|
||||
swhelp();
|
||||
</script>'.N);
|
||||
|
||||
$joins=array();
|
||||
$wheres=array();
|
||||
$wheres[]='Instances.LastOkCheckTS>='.$graceline.' AND Instances.IsMastodon=1 AND Instances.FirstSeen IS NOT NULL';
|
||||
|
@ -744,4 +583,81 @@ echo('</div>'.N);
|
|||
$debug.='TOTAL RENDERING TIME: '.(microtime(true)-$bt).N;
|
||||
if (array_key_exists('debug',$_GET) && $_GET['debug']=='1') echo('<!--'.N.'--- DEBUG INFO ---'.N.$debug.'//-->'.N);
|
||||
|
||||
|
||||
// functions
|
||||
|
||||
function ckgnum($key,$def,$max) {
|
||||
if (array_key_exists($key,$_GET)) {
|
||||
$_GET[$key]=trim($_GET[$key]);
|
||||
if (preg_match('#^\d+$#',$_GET[$key])===1) {
|
||||
$_GET[$key]=$_GET[$key]+0;
|
||||
if ($_GET[$key]>$max) $_GET[$key]=$max;
|
||||
} elseif ($_GET[$key]!='') {
|
||||
$_GET[$key]=$def;
|
||||
}
|
||||
} else {
|
||||
$_GET[$key]=$def;
|
||||
}
|
||||
}
|
||||
|
||||
function nullemp($inp) {
|
||||
if (is_null($inp) || preg_match('/^\s*$/',$inp)===1) return(true);
|
||||
return(false);
|
||||
}
|
||||
|
||||
function ldate($ts,$dateonly=false) {
|
||||
if (nullemp($ts)) return(null);
|
||||
$ts=round($ts);
|
||||
if (!$dateonly)
|
||||
return(gmdate('d/m/Y H:i:s e',$ts));
|
||||
else
|
||||
return(gmdate('d/m/Y e',$ts));
|
||||
}
|
||||
|
||||
function hspech($str) {
|
||||
if (nullemp($str)) return(null);
|
||||
return(htmlspecialchars($str,ENT_QUOTES|ENT_HTML5,'UTF-8'));
|
||||
}
|
||||
|
||||
function muorimeglio($msg,$close) {
|
||||
global $link;
|
||||
if ($close)
|
||||
mysqli_close($link);
|
||||
echo('<p>'.$msg.'</p>'.N.'</section>'.N.'</div>'.N.'</div>'.N.'</body>'.N);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
function nully($str) {
|
||||
// "Not available" in singular form - translators, please omit "{singular}" from translation,
|
||||
// it's there just to diversify this "Not available" from the next one
|
||||
if (nullemp($str)) return('<span class="null">'._('Not available{singular}').'</span>');
|
||||
return($str);
|
||||
}
|
||||
|
||||
function nullyp($str) {
|
||||
// "Not available" in plural form - translators, please omit "{plural}" from translation,
|
||||
// it's there just to diversify this "Not available" from the previous one
|
||||
if (nullemp($str)) return('<span class="null">'._('Not available{plural}').'</span>');
|
||||
return($str);
|
||||
}
|
||||
|
||||
function strip($str,$uri) {
|
||||
if (nullemp($str)) return(null);
|
||||
$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','#</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','#</b>#i','#<i>#i','#</i>#i'],['<strong>','</strong>','<em>','</em>'],$str);
|
||||
$str=preg_replace('#<p>\s*</p>#is','',$str);
|
||||
$str=strip_tags($str,'<a><br><ol><ul><li><p><div><strong><em><small><img>');
|
||||
// all this part below is to try and assign the css "nobott" css class to a possible closing <p>/<ol>/<ul>/<div>,
|
||||
// to avoid the useless and UGLY last bottom-margin :-))
|
||||
$str=preg_replace('#^\s*#m','',$str);// strip all spaces from empty lines
|
||||
$str=preg_replace('#[\r\n]#',' ',$str);// strip all "wrap chars"
|
||||
$str=preg_replace('#(</p>|</ol>|</ul>|</div>)#i','$1'.N,$str);// now add a newline after every </p> and so on
|
||||
$str=rtrim($str);// trim the newline at the end of the whole text block in order for the next preg_replace to match against $ as end of the whole text block
|
||||
$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);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in a new issue