From 043ef60cf55c96eac6aaeffe2e162f9a83532e0b Mon Sep 17 00:00:00 2001 From: pezcurrel Date: Tue, 26 Dec 2023 23:19:52 +0100 Subject: [PATCH] =?UTF-8?q?Made=20it=20know=20when=20among=20instances=20w?= =?UTF-8?q?ith=20a=20given=20language=20there=E2=80=99s=20at=20least=20one?= =?UTF-8?q?=20recommended=20instance;=20if=20so,=20made=20it=20use=20?= =?UTF-8?q?=E2=80=9Crandom,=20recommended=20first=E2=80=9D=20order;=20othe?= =?UTF-8?q?rwise,=20made=20it=20use=20just=20=E2=80=9Crandom=E2=80=9D=20or?= =?UTF-8?q?der;=20made=20it=20know=20to=20javascript=20too,=20so=20the=20f?= =?UTF-8?q?irst=20entry=20in=20the=20order=20menu=20gets=20its=20text=20ch?= =?UTF-8?q?anged=20accordingly;=20added=20a=20checkbox=20to=20exclude=20in?= =?UTF-8?q?stances=20not=20blocking=20threads=20(or=20instances=20about=20?= =?UTF-8?q?which=20it=20is=20unknown=20if=20they=20are=20blocking=20Thread?= =?UTF-8?q?s);=20some=20layout=20flaws=20fixing;=20some=20tidying=20of=20c?= =?UTF-8?q?ode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/site/instances.php | 276 ++++++++++++++++++++++++----------------- 1 file changed, 161 insertions(+), 115 deletions(-) diff --git a/web/site/instances.php b/web/site/instances.php index 4f984f5..4270f84 100644 --- a/web/site/instances.php +++ b/web/site/instances.php @@ -5,7 +5,7 @@ if (!defined('N')) { exit(0); } -$bt=microtime(true); +$bt=hrtime(true); $dlanguc=strtoupper($dlang); @@ -15,7 +15,7 @@ require '../lib/fnum.php'; use function mysqli_real_escape_string as myesc; /*$dlang='fr'; -$dtzbl=array('ca'=>'Europe/Madrid','en'=>'Europe/London','es'=>'Europe/Madrid','fr'=>'Europe/Paris','it'=>'Europe/Rome'); +$dtzbl=['ca'=>'Europe/Madrid','en'=>'Europe/London','es'=>'Europe/Madrid','fr'=>'Europe/Paris','it'=>'Europe/Rome']; date_default_timezone_set($dtzbl[$dlang]);*/ $debug=''; @@ -28,10 +28,10 @@ $oldline=30*24*60*60; // an instance is considered dead if the last time it responded is before the graceline (see code below); we fix it at start of today - $gracetime // $gracetime is defined in mustard/include/gracetime.php -$bti=round($bt); +$bti=round(microtime(true)); $graceline=gmmktime(0,0,0,gmdate('n',$bti),gmdate('j',$bti),gmdate('Y',$bti))-$gracetime; -if (array_key_exists('id',$_GET) && preg_match('/^\d+$/',$_GET['id'])) { +if (array_key_exists('id',$_GET) && preg_match('/^\d+$/',$_GET['id'])===1) { $_GET['id']+=0; $single=true; } else { @@ -131,6 +131,38 @@ function sethid(obj) { document.getElementById(obj).value=0; } +function updord() { + let langsel=document.getElementById("lang"), ordsel=document.getElementById("ord"); + console.log(langswri); + console.log(langsel.value); + if (langswri.indexOf(langsel.value)>=0) { + console.log("si"); + ordsel.options[0].innerHTML="'._('Random, recommended first').'"; + } else { + console.log("no"); + ordsel.options[0].innerHTML="'._('Random').'"; + } +} + +function nocrit() { + document.getElementById("lang").selectedIndex=0; + document.getElementById("desc").value=""; + document.getElementById("minu").value=""; + document.getElementById("maxu").value=""; + document.getElementById("minau").value=""; + document.getElementById("minc").value=""; + document.getElementById("cbexnox").checked=false; + sethid("exnox"); + document.getElementById("cbexregc").checked=false; + sethid("exregc"); + document.getElementById("cbexthf").checked=false; + sethid("exthf"); + document.getElementById("cbexappr").checked=false; + sethid("exappr"); + document.getElementById("cbexlcko").checked=false; + sethid("exlcko"); +} + function presub() { document.getElementById("p").value=1; if (document.getElementById("ord").value=="noxd") { @@ -142,19 +174,19 @@ function presub() { '.N); - $res=mysqli_query($link,'SELECT COUNT(Instances.ID) AS Unknown, SUM(Instances.UserCount) AS UnknownU FROM Instances WHERE Instances.IsMastodon=1 AND Instances.BlockListAvailable=0 AND Instances.LastOkCheckTS>='.$graceline) or muorimeglio(__LINE__.': '.mysqli_error($link),true); + $res=tquery('SELECT COUNT(Instances.ID) AS Unknown, SUM(Instances.UserCount) AS UnknownU FROM Instances WHERE Instances.IsMastodon=1 AND Instances.Threads IS NULL AND Instances.LastOkCheckTS>='.$graceline,__LINE__); $row=mysqli_fetch_assoc($res); $metastats['unknown']=['instances'=>$row['Unknown'], 'users'=>nulltozero($row['UnknownU'])]; - $res=mysqli_query($link,'SELECT COUNT(Instances.ID) AS Suspending, SUM(Instances.UserCount) AS SuspendingU FROM Instances LEFT JOIN InstBlocks ON InstBlocks.InstID=Instances.ID WHERE Instances.IsMastodon=1 AND Instances.BlockListAvailable=1 AND Instances.LastOkCheckTS>='.$graceline.' AND (InstBlocks.Domain LIKE "%.threads.net" OR InstBlocks.Domain="threads.net") AND InstBlocks.Severity="suspend"') or muorimeglio(__LINE__.': '.mysqli_error($link),true); + $res=tquery('SELECT COUNT(Instances.ID) AS Suspending, SUM(Instances.UserCount) AS SuspendingU FROM Instances WHERE Instances.IsMastodon=1 AND Instances.Threads="suspended" AND Instances.LastOkCheckTS>='.$graceline,__LINE__); $row=mysqli_fetch_assoc($res); $metastats['suspending']=['instances'=>$row['Suspending'], 'users'=>nulltozero($row['SuspendingU'])]; - $res=mysqli_query($link,'SELECT COUNT(Instances.ID) AS Silencing, SUM(Instances.UserCount) AS SilencingU FROM Instances LEFT JOIN InstBlocks ON InstBlocks.InstID=Instances.ID WHERE Instances.IsMastodon=1 AND Instances.BlockListAvailable=1 AND Instances.LastOkCheckTS>='.$graceline.' AND (InstBlocks.Domain LIKE "%.threads.net" OR InstBlocks.Domain="threads.net") AND InstBlocks.Severity="silence"') or muorimeglio(__LINE__.': '.mysqli_error($link),true); + $res=tquery('SELECT COUNT(Instances.ID) AS Silencing, SUM(Instances.UserCount) AS SilencingU FROM Instances WHERE Instances.IsMastodon=1 AND Instances.Threads="limited" AND Instances.LastOkCheckTS>='.$graceline,__LINE__); $row=mysqli_fetch_assoc($res); $metastats['silencing']=['instances'=>$row['Silencing'], 'users'=>nulltozero($row['SilencingU'])]; - $res=mysqli_query($link,'SELECT COUNT(ID) AS tinsts, SUM(UserCount) AS tusers, SUM(StatusCount) AS tstatuses, SUM(ActiveUsersMonth) AS tactusers FROM Instances WHERE Instances.IsMastodon=1 AND Instances.LastOkCheckTS>='.$graceline) or muorimeglio(__LINE__.': '.mysqli_error($link),true); + $res=tquery('SELECT COUNT(ID) AS tinsts, SUM(UserCount) AS tusers, SUM(StatusCount) AS tstatuses, SUM(ActiveUsersMonth) AS tactusers FROM Instances WHERE Instances.IsMastodon=1 AND Instances.LastOkCheckTS>='.$graceline,__LINE__); $row=mysqli_fetch_assoc($res); echo(_('

This search engine for Mastodon instances is based on a database that gets updated by our crawler every night (CET). Instances are considered new for 30 days after they are discovered. When an instance has not responded to our daily checks for more than 30 days it’s no longer considered in statistics and searches and it gets checked only on the first of the month, rather than daily, until it possibly responds again. “Random ordering” of results varies daily.

Default search criteria reflect our fondness for a decentralized and egalitarian Fediverse and our attempt to exclude instances accepting fascist, racist, sexist, ableist or sovereignist contents by marking them as noxious.

').N); printf(_('

We currently count %s Mastodon instances, with %s users (%s active during last month) and %s published statuses. [Show Threads suspension / limitation stats].

').N, fnum($row['tinsts'],0,$dlang), fnum($row['tusers'],0,$dlang), fnum($row['tactusers'],0,$dlang), fnum($row['tstatuses'],0,$dlang)); @@ -163,39 +195,39 @@ function presub() { 'instances'=>$row['tinsts']-$metastats['unknown']['instances'], 'users'=>$row['tusers']-$metastats['unknown']['users'], ]; - $metastats['known']['iperc']=100/$row['tinsts']*$metastats['known']['instances']; - $metastats['known']['uperc']=100/$row['tusers']*$metastats['known']['users']; + $metastats['known']['iperc']=$metastats['known']['instances']*100/$row['tinsts']; + $metastats['known']['uperc']=$metastats['known']['users']*100/$row['tusers']; - $metastats['unknown']['iperc']=100/$row['tinsts']*$metastats['unknown']['instances']; - $metastats['unknown']['uperc']=100/$row['tusers']*$metastats['unknown']['users']; + $metastats['unknown']['iperc']=$metastats['unknown']['instances']*100/$row['tinsts']; + $metastats['unknown']['uperc']=$metastats['unknown']['users']*100/$row['tusers']; - $metastats['suspending']['iperc']=100/$row['tinsts']*$metastats['suspending']['instances']; - $metastats['suspending']['uperc']=100/$row['tusers']*$metastats['suspending']['users']; - $metastats['suspending']['kiperc']=100/$metastats['known']['instances']*$metastats['suspending']['instances']; - $metastats['suspending']['kuperc']=100/$metastats['known']['users']*$metastats['suspending']['users']; + $metastats['suspending']['iperc']=$metastats['suspending']['instances']*100/$row['tinsts']; + $metastats['suspending']['uperc']=$metastats['suspending']['users']*100/$row['tusers']; + $metastats['suspending']['kiperc']=$metastats['suspending']['instances']*100/$metastats['known']['instances']; + $metastats['suspending']['kuperc']=$metastats['suspending']['users']*100/$metastats['known']['users']; - $metastats['silencing']['iperc']=100/$row['tinsts']*$metastats['silencing']['instances']; - $metastats['silencing']['uperc']=100/$row['tusers']*$metastats['silencing']['users']; - $metastats['silencing']['kiperc']=100/$metastats['known']['instances']*$metastats['silencing']['instances']; - $metastats['silencing']['kuperc']=100/$metastats['known']['users']*$metastats['silencing']['users']; + $metastats['silencing']['iperc']=$metastats['silencing']['instances']*100/$row['tinsts']; + $metastats['silencing']['uperc']=$metastats['silencing']['users']*100/$row['tusers']; + $metastats['silencing']['kiperc']=$metastats['silencing']['instances']*100/$metastats['known']['instances']; + $metastats['silencing']['kuperc']=$metastats['silencing']['users']*100/$metastats['known']['users']; $metastats['notsuspsil']=[ 'instances'=>$row['tinsts']-$metastats['unknown']['instances']-$metastats['suspending']['instances']-$metastats['silencing']['instances'], 'users'=>$row['tusers']-$metastats['unknown']['users']-$metastats['suspending']['users']-$metastats['silencing']['users'] ]; - $metastats['notsuspsil']['iperc']=100/$row['tinsts']*$metastats['notsuspsil']['instances']; - $metastats['notsuspsil']['uperc']=100/$row['tusers']*$metastats['notsuspsil']['users']; - $metastats['notsuspsil']['kiperc']=100/$metastats['known']['instances']*$metastats['notsuspsil']['instances']; - $metastats['notsuspsil']['kuperc']=100/$metastats['known']['users']*$metastats['notsuspsil']['users']; + $metastats['notsuspsil']['iperc']=$metastats['notsuspsil']['instances']*100/$row['tinsts']; + $metastats['notsuspsil']['uperc']=$metastats['notsuspsil']['users']*100/$row['tusers']; + $metastats['notsuspsil']['kiperc']=$metastats['notsuspsil']['instances']*100/$metastats['known']['instances']; + $metastats['notsuspsil']['kuperc']=$metastats['notsuspsil']['users']*100/$metastats['known']['users']; $metastats['suspsil']=[ 'instances'=>$metastats['suspending']['instances']+$metastats['silencing']['instances'], 'users'=>$metastats['suspending']['users']+$metastats['silencing']['users'] ]; - $metastats['suspsil']['iperc']=100/$row['tinsts']*$metastats['suspsil']['instances']; - $metastats['suspsil']['uperc']=100/$row['tusers']*$metastats['suspsil']['users']; - $metastats['suspsil']['kiperc']=100/$metastats['known']['instances']*$metastats['suspsil']['instances']; - $metastats['suspsil']['kuperc']=100/$metastats['known']['users']*$metastats['suspsil']['users']; + $metastats['suspsil']['iperc']=$metastats['suspsil']['instances']*100/$row['tinsts']; + $metastats['suspsil']['uperc']=$metastats['suspsil']['users']*100/$row['tusers']; + $metastats['suspsil']['kiperc']=$metastats['suspsil']['instances']*100/$metastats['known']['instances']; + $metastats['suspsil']['kuperc']=$metastats['suspsil']['users']*100/$metastats['known']['users']; echo '
@@ -242,7 +274,6 @@ function presub() {
'.N; - if ((array_key_exists('exnox',$_GET) && $_GET['exnox']=='1') || !array_key_exists('exnox',$_GET)) { $_GET['cbexnox']=' checked'; $_GET['exnox']=1; @@ -259,6 +290,15 @@ function presub() { $_GET['exregc']=0; } +// if ((array_key_exists('exthf',$_GET) && $_GET['exthf']=='1') || !array_key_exists('exthf',$_GET)) { + if (array_key_exists('exthf',$_GET) && $_GET['exthf']=='1') { + $_GET['cbexthf']=' checked'; + $_GET['exthf']=1; + } else { + $_GET['cbexthf']=''; + $_GET['exthf']=0; + } + if (array_key_exists('exappr',$_GET) && $_GET['exappr']=='1') { $_GET['cbexappr']=' checked'; $_GET['exappr']=1; @@ -281,7 +321,7 @@ function presub() { else $_GET['lang']=0; } else { - $res=mysqli_query($link,'SELECT ID FROM Languages WHERE Code="'.$dlang.'"') or muorimeglio(__LINE__.': '.mysqli_error($link),true); + $res=tquery('SELECT ID FROM Languages WHERE Code="'.myesc($link,$dlang).'"',__LINE__); if (mysqli_num_rows($res)>0) { $row=mysqli_fetch_assoc($res); $_GET['lang']=$row['ID']; @@ -303,27 +343,33 @@ function presub() { ckgnum('minau',$minaudef,$minaumax); ckgnum('minc',$mincdef,$mincmax); - $order=array( - 'rand'=>array('t'=>_('Random, recommended first'),'q'=>'Instances.Priority DESC, Instances.RPos ASC'), - 'invold'=>array('t'=>_('By users’ involvement (active users / users), descending'),'q'=>'(Instances.ActiveUsersMonth / Instances.UserCount) DESC'), - 'invola'=>array('t'=>_('By users’ involvement (active users / users), ascending'),'q'=>'(Instances.ActiveUsersMonth / Instances.UserCount) ASC'), - 'fseend'=>array('t'=>_('By date and time of first sighting, descending'),'q'=>'Instances.FirstSeen DESC'), - 'fseena'=>array('t'=>_('By date and time of first sighting, ascending'),'q'=>'Instances.FirstSeen ASC'), - 'tusersd'=>array('t'=>_('By number of users, descending'),'q'=>'Instances.UserCount DESC'), - 'tusersa'=>array('t'=>_('By number of users, ascending'),'q'=>'Instances.UserCount ASC'), - 'ausersd'=>array('t'=>_('By number of active users, descending'),'q'=>'Instances.ActiveUsersMonth DESC'), - 'ausersa'=>array('t'=>_('By number of active users, ascending'),'q'=>'Instances.ActiveUsersMonth ASC'), - 'checksd'=>array('t'=>_('By responsiveness to our checks, descending'),'q'=>'(Instances.OkChecks / Instances.TotChecks) DESC, Instances.TotChecks DESC'), - 'checksa'=>array('t'=>_('By responsiveness to our checks, ascending'),'q'=>'(Instances.OkChecks / Instances.TotChecks) ASC, Instances.TotChecks ASC'), - 'charsd'=>array('t'=>_('By available characters per post, descending'),'q'=>'Instances.MaxTootChars DESC'), - 'charsa'=>array('t'=>_('By available characters per post, ascending'),'q'=>'Instances.MaxTootChars ASC'), - 'noxd'=>array('t'=>_('Noxious first (switches off “Exclude noxious”)'),'q'=>'Instances.Noxious DESC') - ); + $order=[ + 'rand'=>['t'=>_('Random'), 'q'=>'Instances.RPos ASC'], + 'invold'=>['t'=>_('By users’ involvement (active users / users), descending'), 'q'=>'(Instances.ActiveUsersMonth / Instances.UserCount) DESC'], + 'invola'=>['t'=>_('By users’ involvement (active users / users), ascending'), 'q'=>'(Instances.ActiveUsersMonth / Instances.UserCount) ASC'], + 'fseend'=>['t'=>_('By date and time of first sighting, descending'), 'q'=>'Instances.FirstSeen DESC'], + 'fseena'=>['t'=>_('By date and time of first sighting, ascending'), 'q'=>'Instances.FirstSeen ASC'], + 'tusersd'=>['t'=>_('By number of users, descending'), 'q'=>'Instances.UserCount DESC'], + 'tusersa'=>['t'=>_('By number of users, ascending'), 'q'=>'Instances.UserCount ASC'], + 'ausersd'=>['t'=>_('By number of active users, descending'), 'q'=>'Instances.ActiveUsersMonth DESC'], + 'ausersa'=>['t'=>_('By number of active users, ascending'), 'q'=>'Instances.ActiveUsersMonth ASC'], + 'checksd'=>['t'=>_('By responsiveness to our checks, descending'), 'q'=>'(Instances.OkChecks / Instances.TotChecks) DESC, Instances.TotChecks DESC'], + 'checksa'=>['t'=>_('By responsiveness to our checks, ascending'), 'q'=>'(Instances.OkChecks / Instances.TotChecks) ASC, Instances.TotChecks ASC'], + 'charsd'=>['t'=>_('By available characters per post, descending'), 'q'=>'Instances.MaxTootChars DESC'], + 'charsa'=>['t'=>_('By available characters per post, ascending'), 'q'=>'Instances.MaxTootChars ASC'], + 'noxd'=>['t'=>_('Noxious first (switches off “Exclude noxious”)'), 'q'=>'Instances.Noxious DESC'] + ]; if (!array_key_exists('ord',$_GET) || !array_key_exists($_GET['ord'],$order)) $_GET['ord']='rand'; - // we have recommended instances only for it language, so... - $withreclangids=[306]; - if (!in_array($_GET['lang'],$withreclangids)) $order['rand']=array('t'=>_('Random'),'q'=>'Instances.RPos ASC'); +// $res=tquery('SELECT COUNT(Instances.ID) AS Recomm FROM Instances LEFT JOIN InstOurLangs ON InstOurLangs.InstID=Instances.ID WHERE InstOurLangs.OurLangID='.$_GET['lang'].' AND Instances.IsMastodon=1 AND Instances.LastOkCheckTS>='.$graceline.' AND InstOurLangs.Pos=1 AND Instances.Priority>127',__LINE__); + $res=tquery('SELECT InstOurLangs.OurLangID FROM Instances LEFT JOIN InstOurLangs ON InstOurLangs.InstID=Instances.ID WHERE Instances.IsMastodon=1 AND Instances.LastOkCheckTS>='.$graceline.' AND InstOurLangs.Pos=1 AND Instances.Priority>127 GROUP BY InstOurLangs.OurLangID',__LINE__); + $langswri=[];// langs with recommended instances + while ($row=mysqli_fetch_assoc($res)) + $langswri[]=$row['OurLangID']; + if (count($langswri)>0) + array_unshift($langswri,0); + if (in_array($_GET['lang'],$langswri)) + $order['rand']=['t'=>_('Random, recommended first'), 'q'=>'Instances.Priority DESC, Instances.RPos ASC']; $p=1; if (array_key_exists('p',$_GET) && preg_match('#^[0-9]+$#',$_GET['p'])===1) $p=$_GET['p']+0; @@ -334,6 +380,7 @@ function presub() { + @@ -345,26 +392,28 @@ function presub() { '.N); ($_GET['lang']==0) ? $selected=' selected' : $selected=''; - - echo('
+ echo '
'._('Search criteria').'
'._('Show instances where...').'
- + '.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.IsMastodon=1 AND Instances.LastOkCheckTS>='.$graceline.' AND InstOurLangs.Pos=1 GROUP BY Languages.ID ORDER BY Name'.$dlanguc.' ASC') or muorimeglio(__LINE__.': '.mysqli_error($link),true); + $res=tquery('SELECT Languages.ID AS Lid, CONCAT(Name'.$dlanguc.', \' [\', Code, \'] (\', COUNT(Languages.ID), \')\') AS Txt FROM InstOurLangs LEFT JOIN Instances ON Instances.ID=InstOurLangs.InstID LEFT JOIN Languages ON Languages.ID=OurLangID WHERE InstOurLangs.Pos=1 AND Instances.IsMastodon=1 AND Instances.LastOkCheckTS>='.$graceline.' GROUP BY Languages.ID ORDER BY Languages.Name'.$dlanguc.' ASC',__LINE__); while ($row=mysqli_fetch_assoc($res)) { ($_GET['lang']==$row['Lid']) ? $selected=' selected' : $selected=''; - echo(''.N); + echo ''.N; } - echo(' + echo '
+
@@ -402,6 +451,13 @@ function presub() {
+
+
+ + +
+
+
@@ -419,10 +475,10 @@ function presub() {
'._('Order of results').'
- '.N; foreach ($order as $key=>$buf) { ($key!=$_GET['ord']) ? $selected='' : $selected=' selected'; - echo(''.N); + echo ''.N; } echo('
@@ -431,8 +487,12 @@ function presub() {
+
+ +
+
- +
@@ -442,8 +502,8 @@ function presub() { swhelp(); '.N); - $joins=array(); - $wheres=array(); + $joins=[]; + $wheres=[]; $wheres[]='Instances.IsMastodon=1 AND Instances.LastOkCheckTS>='.$graceline; if ($_GET['exnox']==1) $wheres[]='Instances.Noxious=0'; if ($_GET['exregc']==1) $wheres[]='Instances.RegOpen=1'; @@ -453,6 +513,7 @@ function presub() { $joins[]='LEFT JOIN InstChecks AS InstChecks ON InstChecks.InstID=Instances.ID AND InstChecks.Time=(SELECT MAX(InstChecks.Time) AS MaxTime FROM InstChecks WHERE InstChecks.InstID=Instances.ID)'; $wheres[]='InstChecks.Status=1'; }*/ + if ($_GET['exthf']==1) $wheres[]='Instances.Threads="suspended"'; if ($_GET['lang']>0) { $joins[]='LEFT JOIN InstOurLangs ON InstOurLangs.InstID=Instances.ID'; $wheres[]='(InstOurLangs.OurLangID='.$_GET['lang'].' AND InstOurLangs.Pos=1)'; @@ -468,10 +529,8 @@ function presub() { $que='SELECT * FROM Instances '.$joins.' '.$wheres.' ORDER BY '.$order[$_GET['ord']]['q']; } -$debug.='QUERY: «'.$que.'»'.N; -$qbt=microtime(true); -$res=mysqli_query($link,$que) or muorimeglio(__LINE__.': '.mysqli_error($link),true); -$debug.='MAIN QUERY EXEC TIME: '.(microtime(true)-$qbt).' sec.'.N; +$debug.='MAIN QUERY: «'.$que.'»'.N; +$res=tquery($que,__LINE__); $itot=mysqli_num_rows($res); $debug.='RESULTS: '.$itot.N; /*if ($itot==0) { @@ -485,15 +544,8 @@ if ($if>=$itot) { $if=0; $p=1; } -$il=$if+$ipp; - -function tquery($query,$line) { - global $link, $debug; - $bt=microtime(true); - $res=mysqli_query($link,$query) or muorimeglio($line.': '.mysqli_error($link),true); - $debug.=(microtime(true)-$bt).' secs. for query «'.$query.'»'.N; - return($res); -} +$ptot=ceil($itot/$ipp); +($p!=$ptot) ? $il=$if+$ipp : $il=$itot; $dfmt=datefmt_create($blang,IntlDateFormatter::MEDIUM,IntlDateFormatter::NONE,'UTC',IntlDateFormatter::GREGORIAN); $defmt=datefmt_create($blang,IntlDateFormatter::SHORT,IntlDateFormatter::MEDIUM,'UTC',IntlDateFormatter::GREGORIAN); @@ -507,9 +559,8 @@ while ($if<$il && $row=mysqli_fetch_assoc($res)) { if (!$single) $out.=' ('.$if.'/'.$itot.')'; $out.='
'.N; ($if<$il) ? $out.='
'.N : $out.='
'.N; - $qbt=microtime(true); $rres=tquery('SELECT CONCAT(Languages.Name'.$dlanguc.'," (",Languages.Code,")") AS Lang FROM InstOurLangs LEFT JOIN Languages ON Languages.ID=InstOurLangs.OurLangID WHERE InstOurLangs.InstID='.$row['ID'].' ORDER BY InstOurLangs.Pos ASC',__LINE__); - $buf=array(); + $buf=[]; while ($rrow=mysqli_fetch_assoc($rres)) $buf[]=hspech($rrow['Lang']); ($row['Thumb']=='unavailable') ? $thumb=$prepath.'imgs/InstThumbUnavailable.svg' : $thumb=$row['Thumb']; @@ -576,38 +627,20 @@ while ($if<$il && $row=mysqli_fetch_assoc($res)) { $out.='
'.N; $out.='
'._('Meta’s Threads moderation').' '; - if ($row['BlockListAvailable']==1) { - $mmres=tquery('SELECT Domain, Severity, Comment FROM InstBlocks WHERE InstID='.$row['ID'],__LINE__); - if (mysqli_num_rows($mmres)>0) { - $tm=false;// tmk: threads moderation - while ($rrow=mysqli_fetch_assoc($mmres)) { - if (preg_match('#^(threads.net|.*\.threads.net)$#i',$rrow['Domain'])==1) { - if ($rrow['Severity']=='suspend') - $out.=_('Threads is suspended'); - elseif ($rrow['Severity']=='silence') - $out.=_('Threads is limited'); - else - $out.=_('Unknown value').': «'.htmlentities($rrow['Severity']).'»'; - $tm=true; - break; - } - } - if (!$tm) - $out.=_('Threads is neither suspended nor limited'); - } else { - $out.=_('Threads is neither suspended nor limited'); - $mmres=false; - } - } else { - $out.=''._('Unknown (moderated servers list is unaccessible)').''; - $mmres=false; - } + if (is_null($row['Threads'])) + $out.=_('Threads is neither suspended nor limited'); + elseif ($row['Threads']=='suspended') + $out.=_('Threads is suspended'); + elseif ($row['Threads']=='limited') + $out.=_('Threads is limited'); + else + $out.=_('Unknown').': «'.htmlentities($row['Threads']).'»'; $out.='
'.N; $out.='
'._('Most used hashtags (last week)').' '; $rres=tquery('SELECT * FROM InstTrends WHERE InstID='.$row['ID'].' ORDER BY Pos ASC',__LINE__); if (mysqli_num_rows($rres)>0) { - $buf=array(); + $buf=[]; while ($rrow=mysqli_fetch_assoc($rres)) $buf[]=''.hspech($rrow['Name']).''; $out.=implode(', ',$buf); @@ -637,9 +670,10 @@ while ($if<$il && $row=mysqli_fetch_assoc($res)) { $out.='
'._('Moderated servers').'
'; $sevmap=['silence'=>_('limited'), 'suspend'=>_('sospeso')]; - if ($mmres!=false) { + $rres=tquery('SELECT Domain, Severity, Comment FROM InstBlocks WHERE InstID='.$row['ID'],__LINE__); + if (mysqli_num_rows($rres)>0) { $out.='
    '.N; - while ($rrow=mysqli_fetch_assoc($mmres)) { + while ($rrow=mysqli_fetch_assoc($rres)) { $out.='
  • '.hspech($rrow['Domain']).': '.$sevmap[$rrow['Severity']]; if (!is_null($rrow['Comment'])) $out.=' - '.hspech($rrow['Comment']);// no strip, do hspech, because moredated server comments don’t support html nor markdown in mastodon $out.='
  • '.N; @@ -686,7 +720,7 @@ while ($if<$il && $row=mysqli_fetch_assoc($res)) { $rres=tquery('SELECT * FROM InstChecks WHERE InstID='.$row['ID'].' ORDER BY Time DESC LIMIT 0,8',__LINE__); $tot=mysqli_num_rows($rres); - $buf=array(); + $buf=[]; while ($rrow=mysqli_fetch_assoc($rres)) $buf[]=$rrow; $out.='
    '._('Last checks (green: OK; red: KO)').'
    '; for ($i=$tot-1; $i>=0; $i--) { @@ -695,7 +729,7 @@ while ($if<$il && $row=mysqli_fetch_assoc($res)) { $out.='>'.datefmt_format($defmt,$buf[$i]['Time']).' UTC'; } $out.='
    '.N; - $out.='
    '._('Succesful checks').': '.$row['OkChecks'].'/'.$row['TotChecks'].' ('.round(100 / $row['TotChecks'] * $row['OkChecks'], 2).'%)
    '.N; + $out.='
    '._('Succesful checks').': '.$row['OkChecks'].'/'.$row['TotChecks'].' ('.round($row['OkChecks']*100/$row['TotChecks'], 2).'%)
    '.N; $out.='
'.N; @@ -706,7 +740,6 @@ mysqli_close($link); echo(''.N); -$ptot=ceil($itot/$ipp); if ($ptot>1) { echo('
'.N); echo('
'.N); @@ -737,7 +770,7 @@ if ($ptot>1) { echo('
'.N); echo('
'.N); -$debug.='TOTAL RENDERING TIME: '.(microtime(true)-$bt).N; +$debug.='TOTAL RENDERING TIME: '.hrte($bt).N; if (array_key_exists('debug',$_GET) && $_GET['debug']=='1') echo(''.N); @@ -758,8 +791,8 @@ function ckgnum($key,$def,$max) { } function nullemp($inp) { - if (is_null($inp) || preg_match('/^\s*$/',$inp)===1) return(true); - return(false); + if (is_null($inp) || preg_match('/^\s*$/',$inp)===1) return true; + return false; } function nulltozero($inp) { @@ -769,7 +802,7 @@ function nulltozero($inp) { function hspech($str) { if (nullemp($str)) return(null); - return(htmlspecialchars($str,ENT_QUOTES|ENT_HTML5,'UTF-8')); + return htmlspecialchars($str,ENT_QUOTES|ENT_HTML5,'UTF-8'); } function muorimeglio($msg,$close) { @@ -784,14 +817,14 @@ 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(''._('Not available{singular}').''); - return($str); + 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(''._('Not available{plural}').''); - return($str); + return $str; } function strip($str,$uri) { @@ -810,7 +843,20 @@ function strip($str,$uri) { $str=preg_replace('#(

|||
)#i','$1'.N,$str);// now add a newline after every

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(['#]*>(.*)

$#i', '#]*>(.*)$#i', '#]*>(.*)$#i', '#]*>(.*)$#i'],['

$1

', '
    $1
', '
    $1
', '
$1
'],$str); - return($str); + return $str; +} + +function hrte($bt) { + return bcdiv(bcsub(hrtime(true),$bt,9),1000000000,9); +} + +function tquery($query,$line) { + global $link, $debug; + $bt=hrtime(true); + //usleep(rand(10000,100000)); + $res=mysqli_query($link,$query) or muorimeglio('Error on line '.$line.': '.mysqli_error($link),true); + $debug.=hrte($bt).' secs. for query «'.$query.'»'.N; + return $res; } ?>