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;
-
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('
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;
}
?>