diff --git a/web/site/users.php b/web/site/users.php new file mode 100644 index 0000000..0070e1b --- /dev/null +++ b/web/site/users.php @@ -0,0 +1,651 @@ +'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; + +if (array_key_exists('id',$_GET) && preg_match('/^\d+$/',$_GET['id'])) { + $_GET['id']+=0; + $single=true; +} else { + $single=false; +} + +//$getc=count($_GET); +//forzo $getc a 1 per non mostrare mai la spiega di come funziona il motore di ricerca +$getc=1; + +if (array_key_exists('advc',$_GET)) { + ($_GET['advc']=='1') ? $_GET['advc']=1 : $_GET['advc']=0; +} else { + $_GET['advc']=0; +} + +$minudef=10; +$minumax=10000000000; +$maxudef=30000; +$maxumax=10000000000; +$minaudef=10; +$minaumax=10000000; +$minkidef=500; +$minkimax=100000; + +echo(' +
+
+
+ +

'._('Users').'

+ +'.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',$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('

'.$msg.'

'.N.'
'.N.'
'.N.'
'.N.''.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(''._('Not available{singular}').''); + 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); +} +function strip($str,$uri) { + if (nullemp($str)) return(null); + while (preg_match('#^\s*#',$str)===1) $str=preg_replace('#^\s*#','',$str); + while (preg_match('#\s*$#',$str)===1) $str=preg_replace('#\s*$#','',$str); + while (preg_match('#\s*#s',$str)===1) + $str=preg_replace('#\s*#s','
',$str); + $str=preg_replace('#]*)?>.*#s','',$str); + $str=preg_replace('#

This is our search engine for Mastodon users. It works this way...

').N); +printf(_('

We currently count %s Mastodon users.

').N, fnum($row['totusers'],0,$dlang)); + +if ((array_key_exists('noxious',$_GET) && $_GET['noxious']=='1') || !array_key_exists('noxious',$_GET)) { + $_GET['cbnoxious']=' checked'; + $_GET['noxious']=1; +} else { + $_GET['cbnoxious']=''; + $_GET['noxious']=0; +} +//echo('

noxious: '.$_GET['noxious'].'

'); + +if ((array_key_exists('creg',$_GET) && $_GET['creg']=='1') || !array_key_exists('creg',$_GET)) { + $_GET['cbcreg']=' checked'; + $_GET['creg']=1; +} else { + $_GET['cbcreg']=''; + $_GET['creg']=0; +} + +if (array_key_exists('appr',$_GET) && $_GET['appr']=='1') { + $_GET['cbappr']=' checked'; + $_GET['appr']=1; +} else { + $_GET['cbappr']=''; + $_GET['appr']=0; +} + +if (array_key_exists('lcok',$_GET) && $_GET['lcok']=='1') { + $_GET['cblcok']=' checked'; + $_GET['lcok']=1; +} else { + $_GET['cblcok']=''; + $_GET['lcok']=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=mysqli_query($link,'SELECT ID FROM Languages WHERE Code="'.$dlang.'"') or muorimeglio(__LINE__.': '.mysqli_error($link),true); + 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']=''; + +function ckgnum($key,$def,$max) { + if (array_key_exists($key,$_GET)) { + $_GET[$key]=trim($_GET[$key]); + if (preg_match('#^[0-9]+$#',$_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']; +ckgnum('minau',$minaudef,$minaumax); +ckgnum('minki',$minkidef,$minkimax); + +$order=array( + 'rand'=>array('t'=>_('Random, recommended first'),'q'=>'Instances.Priority DESC, Instances.RPos ASC'), +// 'feat'=>array('t'=>_('Prima le consigliate'),'q'=>'Instances.Priority DESC'), +// partecipazione: totusers/activeusers +// 'part'=>array('t'=>_('Partecipazione (decr.)'),'q'=>'(Instances.UserCount / Instances.ActiveUsersMonth) ASC'), + 'tusersa'=>array('t'=>_('By number of users, ascending'),'q'=>'Instances.UserCount ASC'), + 'tusersd'=>array('t'=>_('By number of users, descending'),'q'=>'Instances.UserCount DESC'), + 'ausersd'=>array('t'=>_('By number of active users, descending'),'q'=>'Instances.ActiveUsersMonth DESC'), + 'kinstsd'=>array('t'=>_('By number of known instances, descending'),'q'=>'Instances.DomainCount DESC'), + 'charsd'=>array('t'=>_('By maximum number of characters per toot, descending'),'q'=>'Instances.MaxTootChars DESC'), +// 'open'=>array('t'=>_('Prima quelle con iscriz. aperte'),'q'=>'Instances.RegOpen DESC, Instances.RegReqApproval ASC'), +// 'alph'=>array('t'=>_('Alfabetico'),'q'=>'Instances.URI ASC'), +// new non ha senso di esistere visto che c'è firstseen +// 'new'=>array('t'=>_('Prima le nuove'),'q'=>'Instances.New DESC'), +// 'name'=>array('t'=>_('Nome (crescente)'),'q'=>'Instances.Title ASC'), +// 'admc'=>array('t'=>_('Data creazione account admin'),'q'=>'IF (Instances.AdmCreatedAt IS NULL, 9999999999, Instances.AdmCreatedAt) ASC'), +// 'fseena'=>array('t'=>_('Data di “avvistamento” cresc.'),'q'=>'Instances.FirstSeen ASC'), +// 'fseend'=>array('t'=>_('Data di “avvistamento” decr.'),'q'=>'Instances.FirstSeen DESC'), +); +if (!(array_key_exists('ord',$_GET) && array_key_exists($_GET['ord'],$order))) + $_GET['ord']='rand'; +if ($_GET['lang']==0) $order['rand']=array('t'=>_('Random'),'q'=>'Instances.RPos ASC'); + +$p=1; +if (array_key_exists('p',$_GET) && preg_match('#^[0-9]+$#',$_GET['p'])===1) $p=$_GET['p']+0; + +echo('
+ + + + + + + + + + + + + +
'.N); +($_GET['lang']==0) ? $selected=' selected' : $selected=''; +echo('
+
'._('Search criteria').'
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+ + + +
+ +
+ +
'._('Order of results').'
+ +
+ +
+ +
+ +
+ +
+ +
+ + + +
+ +'.N); +$joins=array(); +$wheres=array(); +$wheres[]='Instances.Dead=0 AND Instances.IsMastodon=1 AND Instances.FirstSeen IS NOT NULL'; +if ($_GET['noxious']==1) $wheres[]='Instances.Noxious=0'; +if ($_GET['creg']==1) $wheres[]='Instances.RegOpen=1'; +if ($_GET['appr']==1) $wheres[]='Instances.RegReqApproval=0'; +if ($_GET['lcok']==1) $wheres[]='Instances.LastCheckOk=1'; +/*if ($_GET['lcok']==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['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['minki']!='') $wheres[]='Instances.DomainCount>='.$_GET['minki']; +$joins=implode(' ',$joins); +$wheres='WHERE '.implode(' AND ',$wheres); +if (!$single) + $que='SELECT * FROM Instances '.$joins.' '.$wheres.' ORDER BY '.$order[$_GET['ord']]['q']; +else + $que='SELECT * FROM Instances WHERE ID='.$_GET['id']; +$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; +$itot=mysqli_num_rows($res); +$debug.='RESULTS: '.$itot.N; +$ipp=10;// istanze per pagina +$if=$ipp*($p-1); +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); +} + +mysqli_data_seek($res,$if); +while ($if<$il && $row=mysqli_fetch_assoc($res)) { + $if++; + $out='
'.hspech($row['URI']).''; + if (!$single) $out.=' ('.$if.'/'.$itot.')'; + $out.='
'.N.'
'.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(); + while ($rrow=mysqli_fetch_assoc($rres)) + $buf[]=hspech($rrow['Lang']); + $out.='
'; +// if (!is_null($row['Priority'])) $out.=''; + if (!is_null($row['Priority'])) $out.='
'._('Recommended').'
'; + $out.='
'.N; + $out.='
'.N; + $out.=''.N; + /*$out.='
'._('Consigliata').' '; + (!is_null($row['Priority'])) ? $out.=''._('Si!').'' : $out.=_('No'); + $out.='
'.N;*/ + $out.='
'._('Languages').' '.nully(implode(', ',$buf)).'
'.N; + $out.='
'._('Users').' '.nully(fnum($row['UserCount'],0,$dlang)).'
'.N; + $out.='
'._('Active users (last month)').' '.nully(fnum($row['ActiveUsersMonth'],0,$dlang)).'
'.N; + $out.='
'._('Active users (last six months)').' '.nully(fnum($row['ActiveUsersHalfYear'],0,$dlang)).'
'.N; + $out.='
'._('Known instances').' '.nully(fnum($row['DomainCount'],0,$dlang)).'
'.N; + $out.='
'.N; + + $out.='
'.N; + $out.='
'._('Characters per toot (max)').' '; + if (nullemp(fnum($row['MaxTootChars'],0,$dlang))) + $out.='500'; + else + $out.=$row['MaxTootChars']; + $out.='
'.N; + $out.='
'._('Noxious').' '; + ($row['Noxious']==1) ? $out.=''._('Yes (see why below)').'' : $out.=''._('No').''; + $out.='
'.N; + $out.='
'._('New').' '; + ($row['New']==1) ? $out.=''._('Yes!').'' : $out.=_('No'); + $out.='
'.N; + $out.='
'._('Software').' '.nully(hspech(ucfirst($row['Software']))).' '.nully(hspech($row['Version'])).'
'.N; + + $out.='
'._('Registrations').' '; + ($row['RegReqApproval']==1) ? $buf=' ('._('by admin approval').')' : $buf=''; + if (nullemp($row['RegOpen'])) + $out.=''._('Not available{singular}').''; + elseif ($row['RegOpen']==1) + $out.=''._('Open').''.$buf; + else + $out.=''._('Closed').''; + $out.='
'.N; + $out.='
'._('E-mail').' '; + if (nullemp($row['Email'])) + $out.=''._('Not available{singular}').''; + else + $out.=''.$row['Email'].''; + $out.='
'.N; + $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(); + while ($rrow=mysqli_fetch_assoc($rres)) + $buf[]=''.hspech($rrow['Name']).''; + $out.=implode(', ',$buf); + } else { + $out.=''._('Not available{plural}').''; + } + $out.='
'.N; + + if ($row['Noxious']) { + $out.='
'._('Why we consider this instance noxious').'
'.nully(strip(nl2br(trim(n2es($row['NoxReason'])),false),$row['URI'])).'
'.N; + } + + $out.='
'._('Short description').'
'.nully(strip(nl2br(trim(n2es($row['ShortDesc'])),false),$row['URI'])).'
'.N; + $out.='
'._('Long description').'
'.nully(strip(trim(n2es($row['LongDesc'])),$row['URI'])).'
'.N; + + $out.='
'._('Admin account').' '.nully(hspech($row['AdmAccount'])).'
'._('Date of creation').' '.nully(ldate($row['AdmCreatedAt'],true)).'
'._('Admin name').' '.nully(hspech($row['AdmDisplayName'])).'
'._('Admin notes').'
'.nullyp(strip(trim(n2es($row['AdmNote'])),$row['URI'])).'
'.N; + $out.='
'; + + $out.='
'._('Stats').'
'; + + $rres=tquery('SELECT COUNT(InstID) AS cnt, SUM(Statuses) AS tstatuses, SUM(Logins) AS tlogins, SUM(Registrations) AS tregs FROM InstActivity WHERE InstID='.$row['ID'],__LINE__); + $out.='
'._('Last 12 weeks activity'); + if (mysqli_num_rows($rres)>0) { + $rrow=mysqli_fetch_assoc($rres); + if ($rrow['cnt']>0) + $out.=' ('._('totals:').' '.$rrow['tstatuses'].' '._('statuses').', '.$rrow['tlogins'].' '._('logins').', '.$rrow['tregs'].' '._('registrations').')'; + } + $out.='
'.N; + $rres=tquery('SELECT * FROM InstActivity WHERE InstID='.$row['ID'].' ORDER BY Week ASC',__LINE__); + $out.=''; + $tot=mysqli_num_rows($rres); + if ($tot>0) { + while ($rrow=mysqli_fetch_assoc($rres)) + // initials for Statuses, Logins, Registrations + $out.=''; + } else { + $out.=''; + } + $out.='
'._('S').': '.$rrow['Statuses'].'
'._('L').': '.$rrow['Logins'].'
'._('R').': '.$rrow['Registrations'].'
'._('Not available{singular}').'
'.N; + + $rres=tquery('SELECT * FROM InstChecks WHERE InstID='.$row['ID'].' ORDER BY Time DESC LIMIT 0,8',__LINE__); + $tot=mysqli_num_rows($rres); + $buf=array(); + while ($rrow=mysqli_fetch_assoc($rres)) $buf[]=$rrow; + $out.='
'._('Last checks (green: OK; red: KO)').'
'; + for ($i=$tot-1; $i>=0; $i--) { + $out.='
'; + } + $out.='
'.N; + + $out.='
'.N; + + $out.='
'.N; + echo($out); +} +mysqli_close($link); + +echo(''.N); + +$ptot=ceil($itot/$ipp); +if ($ptot>1) { + echo('
'.N); + echo('
'.N); + $pnav=''; + if ($p>1) + $pnav.=''; + else + $pnav.=''; + //$pnav.=''; + $pnav.=''.N; + if ($p<$ptot) + $pnav.=''; + else + $pnav.=''; + $pnav.='
Page '.$p.'/'.$ptot.'
'.N; + echo($pnav); + echo('
'.N); +} + +echo(''.N); +echo(''.N); + +$debug.='TOTAL RENDERING TIME: '.(microtime(true)-$bt).N; +if (array_key_exists('debug',$_GET) && $_GET['debug']=='1') echo(''.N); + +?>