this.');
exit(0);
}
$bt=hrtime(true);
$dlanguc=strtoupper($dlang);
require '../lib/n2es.php';
require '../lib/gracetime.php';
require '../lib/fnum.php';
use function mysqli_real_escape_string as myesc;
/*$dlang='fr';
$dtzbl=['ca'=>'Europe/Madrid','en'=>'Europe/London','es'=>'Europe/Madrid','fr'=>'Europe/Paris','it'=>'Europe/Rome'];
date_default_timezone_set($dtzbl[$dlang]);*/
$debug='';
$debug.='REQUEST_URI: '.$_SERVER['REQUEST_URI'].N;
$debug.='$_GET: '.print_r($_GET,1);
$debug.='LOCALE: '.$locale.N;
// an instance is displayed as "New" if its age, relative to the InsertTS field, is less or equal than this (currently 31 days)
$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(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'])===1) {
$_GET['id']+=0;
$single=true;
} else {
$single=false;
}
//$getc=count($_GET);
//forcing $getc to 1 to never display the explanation of search engine workings
$getc=1;
$minudef=10;
$minumax=4294967295;
$maxudef=30000;
$maxumax=4294967295;
$minaudef=10;
$minaumax=4294967295;
$mincdef='';
$mincmax=16777215;
$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');
// if and when ... put it soon after below
/*
*/
echo('
'.N);
if ($single) {
echo('↑ '._('Go to search').'
'.N);
$p=1;
$que='SELECT * FROM Instances WHERE ID='.$_GET['id'];
} else {
echo('
'._('Instances').'
'.N);
$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=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=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=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));
$metastats['known']=[
'instances'=>$row['tinsts']-$metastats['unknown']['instances'],
'users'=>$row['tusers']-$metastats['unknown']['users'],
];
$metastats['known']['iperc']=$metastats['known']['instances']*100/$row['tinsts'];
$metastats['known']['uperc']=$metastats['known']['users']*100/$row['tusers'];
$metastats['unknown']['iperc']=$metastats['unknown']['instances']*100/$row['tinsts'];
$metastats['unknown']['uperc']=$metastats['unknown']['users']*100/$row['tusers'];
$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']=$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']=$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']=$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
''.N;
if ((array_key_exists('exnox',$_GET) && $_GET['exnox']=='1') || !array_key_exists('exnox',$_GET)) {
$_GET['cbexnox']=' checked';
$_GET['exnox']=1;
} else {
$_GET['cbexnox']='';
$_GET['exnox']=0;
}
if ((array_key_exists('exregc',$_GET) && $_GET['exregc']=='1') || !array_key_exists('exregc',$_GET)) {
$_GET['cbexregc']=' checked';
$_GET['exregc']=1;
} else {
$_GET['cbexregc']='';
$_GET['exregc']=0;
}
// if ((array_key_exists('inths',$_GET) && $_GET['inths']=='1') || !array_key_exists('inths',$_GET)) {
if (array_key_exists('inths',$_GET) && $_GET['inths']=='1') {
$_GET['cbinths']=' checked';
$_GET['inths']=1;
} else {
$_GET['cbinths']='';
$_GET['inths']=0;
}
if (array_key_exists('exappr',$_GET) && $_GET['exappr']=='1') {
$_GET['cbexappr']=' checked';
$_GET['exappr']=1;
} else {
$_GET['cbexappr']='';
$_GET['exappr']=0;
}
if (array_key_exists('exlcko',$_GET) && $_GET['exlcko']=='1') {
$_GET['cbexlcko']=' checked';
$_GET['exlcko']=1;
} else {
$_GET['cbexlcko']='';
$_GET['exlcko']=0;
}
if (array_key_exists('lang',$_GET)) {
if (preg_match('#^[0-9]+$#',$_GET['lang'])===1)
$_GET['lang']=$_GET['lang']+0;
else
$_GET['lang']=0;
} else {
$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'];
} else {
$_GET['lang']=0;
}
}
if ($_GET['lang']>5000000000) $_GET['lang']=0;
if (array_key_exists('desc',$_GET) && preg_match('#^.+$#',$_GET['lang'])===1)
$_GET['desc']=trim(n2es($_GET['desc']));
else
$_GET['desc']='';
if (mb_strlen($_GET['desc'])>64) $_GET['desc']='';
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'];
ckgnum('minau',$minaudef,$minaumax);
ckgnum('minc',$mincdef,$mincmax);
$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';
// $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;
echo(''._('Search instances').'
'.N);
($_GET['lang']==0) ? $selected=' selected' : $selected='';
echo '
'.N);
$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';
if ($_GET['exappr']==1) $wheres[]='Instances.RegReqApproval=0';
if ($_GET['exlcko']==1) $wheres[]='Instances.WasLastCheckOk=1';
/*if ($_GET['exlcko']==1) {
$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['inths']==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)';
}
$buf=preg_replace('#%#','\%',myesc($link,$_GET['desc']));
if ($_GET['desc']!='') $wheres[]='(Instances.URI LIKE "%'.$buf.'%" OR Instances.Title LIKE "%'.$buf.'%" OR Instances.ShortDesc LIKE "%'.$buf.'%" OR Instances.LongDesc LIKE "%'.$buf.'%")';
if ($_GET['minu']!='') $wheres[]='Instances.UserCount>='.$_GET['minu'];
if ($_GET['maxu']!='') $wheres[]='Instances.UserCount<='.$_GET['maxu'];
if ($_GET['minau']!='') $wheres[]='Instances.ActiveUsersMonth>='.$_GET['minau'];
if ($_GET['minc']!='' && $_GET['minc']!='""') $wheres[]='Instances.MaxTootChars>='.$_GET['minc'];
$joins=implode(' ',$joins);
$wheres='WHERE '.implode(' AND ',$wheres);
$que='SELECT * FROM Instances '.$joins.' '.$wheres.' ORDER BY '.$order[$_GET['ord']]['q'];
}
$debug.='MAIN QUERY: «'.$que.'»'.N;
$res=tquery($que,__LINE__);
$itot=mysqli_num_rows($res);
$debug.='RESULTS: '.$itot.N;
/*if ($itot==0) {
echo(_('No instance matches with the search criteria.').N.''.N.'
'.N.'
'.N.'