Fixed some flaws in detecting if Thumb and AdmAvatar are to be set to “unavailable”; fixed “noindex” logic, now it also explictly set AdmAccount to special “OPTED OUT” value when noindex=true

This commit is contained in:
pezcurrel 2022-12-28 17:09:25 +01:00
parent 870e3524ca
commit 2b37228a1c

View file

@ -210,8 +210,6 @@ while ($row=mysqli_fetch_assoc($res))
// since we later need to determine if a value is an integer, and mysql returns integers as strings...
setint($instints,$idata);
$idata['URI']=$opts['hostname'];
$idata['Thumb']='unavailable';
$idata['AdmAvatar']='unavailable';
$instanswered=false;
@ -323,16 +321,17 @@ if ($idata['IsMastodon'] && $idata['Version']>='4.0.0') {
$idata['Title']=trim($buf['title']);
if (isset($buf['description']) && is_string($buf['description']) && !isempty($buf['description']))
$idata['ShortDesc']=trim($buf['description']);
if (isset($buf['thumbnail']['url']) && is_string($buf['thumbnail']['url']) && !isempty($buf['thumbnail']['url']))
if (isset($buf['thumbnail']['url']) && is_string($buf['thumbnail']['url']) && !isempty($buf['thumbnail']['url'])) {
$idata['Thumb']=trim($buf['thumbnail']['url']);
if (!@file_get_contents($idata['Thumb'],false,null,0,512)) $idata['Thumb']='unavailable';
if (!@file_get_contents($idata['Thumb'],false,null,0,512)) $idata['Thumb']='unavailable';
}
if (isset($buf['configuration']['statuses']['max_characters']) && is_int($buf['configuration']['statuses']['max_characters']))
$idata['MaxTootChars']=$buf['configuration']['statuses']['max_characters'];
if (isset($buf['registrations']['approval_required']) && is_bool($buf['registrations']['approval_required']))
$idata['RegReqApproval']=b2i($buf['registrations']['approval_required']);
if (isset($buf['contact']['email']) && is_string($buf['contact']['email']))
$idata['Email']=trim($buf['contact']['email']);
if (isset($buf['contact']['account']['noindex']) && is_bool($buf['contact']['account']['noindex']) && !$buf['contact']['account']['noindex']) {// ......
if (!isset($buf['contact']['account']['noindex']) || (isset($buf['contact']['account']['noindex']) && is_bool($buf['contact']['account']['noindex']) && $buf['contact']['account']['noindex']===false)) {
if (isset($buf['contact']['account']['acct']) && is_string($buf['contact']['account']['acct']) && !isempty($buf['contact']['account']['acct']))
$idata['AdmAccount']=trim($buf['contact']['account']['acct']);
if (isset($buf['contact']['account']['display_name']) && is_string($buf['contact']['account']['display_name']) && !isempty($buf['contact']['account']['display_name']))
@ -343,12 +342,15 @@ if ($idata['IsMastodon'] && $idata['Version']>='4.0.0') {
$idata['AdmNote']=trim($buf['contact']['account']['note']);
if (isset($buf['contact']['account']['url']) && is_string($buf['contact']['account']['url']) && !isempty($buf['contact']['account']['url']))
$idata['AdmURL']=trim($buf['contact']['account']['url']);
if (isset($buf['contact']['account']['avatar']) && is_string($buf['contact']['account']['avatar']) && !isempty($buf['contact']['account']['avatar']))
if (isset($buf['contact']['account']['avatar']) && is_string($buf['contact']['account']['avatar']) && !isempty($buf['contact']['account']['avatar'])) {
$idata['AdmAvatar']=trim($buf['contact']['account']['avatar']);
if (!@file_get_contents($idata['AdmAvatar'],false,null,0,512)) $idata['AdmAvatar']='unavailable';
if (!@file_get_contents($idata['AdmAvatar'],false,null,0,512)) $idata['AdmAvatar']='unavailable';
}
if (isset($buf['contact']['account']['header']) && is_string($buf['contact']['account']['header']) && !isempty($buf['contact']['account']['header']))
$idata['AdmHeader']=trim($buf['contact']['account']['header']);
} else {
if (isset($buf['contact']['account']['noindex']) && is_bool($buf['contact']['account']['noindex']) && $buf['contact']['account']['noindex']===true)
$idata['AdmAccount']='OPTED OUT';// here we rely on the fact that nobody could set "acct" to "OPTED OUT" since it doesn't allow spaces
$idata['AdmAvatar']='unavailable';
}
// domain_count is gone from api v2, and we won't resort to api v1 just to get it when ver. >= 4.0.0
@ -434,9 +436,10 @@ if ($idata['IsMastodon'] && $idata['Version']>='4.0.0') {
$idata['StatusCount']=$buf['stats']['status_count'];
if (isset($buf['stats']['domain_count']) && is_int($buf['stats']['domain_count']))
$idata['DomainCount']=$buf['stats']['domain_count'];
if (isset($buf['thumbnail']) && is_string($buf['thumbnail']) && !isempty($buf['thumbnail']))
if (isset($buf['thumbnail']) && is_string($buf['thumbnail']) && !isempty($buf['thumbnail'])) {
$idata['Thumb']=trim($buf['thumbnail']);
if (!@file_get_contents($idata['Thumb'],false,null,0,512)) $idata['Thumb']='unavailable';
if (!@file_get_contents($idata['Thumb'],false,null,0,512)) $idata['Thumb']='unavailable';
}
if (isset($buf['max_toot_chars']) && is_int($buf['max_toot_chars']))
$idata['MaxTootChars']=$buf['max_toot_chars'];
elseif (isset($buf['configuration']['statuses']['max_characters']) && is_int($buf['configuration']['statuses']['max_characters']))
@ -456,9 +459,10 @@ if ($idata['IsMastodon'] && $idata['Version']>='4.0.0') {
$idata['AdmNote']=trim($buf['contact_account']['note']);
if (isset($buf['contact_account']['url']) && is_string($buf['contact_account']['url']) && !isempty($buf['contact_account']['url']))
$idata['AdmURL']=trim($buf['contact_account']['url']);
if (isset($buf['contact_account']['avatar']) && is_string($buf['contact_account']['avatar']) && !isempty($buf['contact_account']['avatar']))
if (isset($buf['contact_account']['avatar']) && is_string($buf['contact_account']['avatar']) && !isempty($buf['contact_account']['avatar'])) {
$idata['AdmAvatar']=trim($buf['contact_account']['avatar']);
if (!@file_get_contents($idata['AdmAvatar'],false,null,0,512)) $idata['AdmAvatar']='unavailable';
if (!@file_get_contents($idata['AdmAvatar'],false,null,0,512)) $idata['AdmAvatar']='unavailable';
}
if (isset($buf['contact_account']['header']) && is_string($buf['contact_account']['header']) && !isempty($buf['contact_account']['header']))
$idata['AdmHeader']=trim($buf['contact_account']['header']);
if (isset($buf['languages']) && is_array($buf['languages']))
@ -528,6 +532,9 @@ if (is_null($oidata)) {
if ($instanswered) {
$idata['FirstSeen']=$now;
$idata['LastOkCheckTS']=$now;
} else {
$idata['Thumb']='unavailable';
$idata['AdmAvatar']='unavailable';
}
} else {
$query='UPDATE Instances SET ';
@ -559,7 +566,7 @@ if (is_null($oidata)) {
$idata['DomainCount']=$oidata['DomainCount'];
$idata['ActiveUsersMonth']=$oidata['ActiveUsersMonth'];
$idata['ActiveUsersHalfYear']=$oidata['ActiveUsersHalfYear'];
$idata['Thumb']=$oidata['Thumb'];
$idata['Thumb']='unavailable';
$idata['RegOpen']=$oidata['RegOpen'];
$idata['RegReqApproval']=$oidata['RegReqApproval'];
$idata['MaxTootChars']=$oidata['MaxTootChars'];
@ -568,7 +575,7 @@ if (is_null($oidata)) {
$idata['AdmCreatedAt']=$oidata['AdmCreatedAt'];
$idata['AdmNote']=$oidata['AdmNote'];
$idata['AdmURL']=$oidata['AdmURL'];
$idata['AdmAvatar']=$oidata['AdmAvatar'];
$idata['AdmAvatar']='unavailable';
$idata['AdmHeader']=$oidata['AdmHeader'];
}
}