Changed check against “activity” values, which are strings, not integers

This commit is contained in:
pezcurrel 2022-12-22 07:40:41 +01:00
parent c6c3feb500
commit f8cdf2cf3b

View file

@ -326,7 +326,6 @@ if ($idata['IsMastodon'] && $idata['Version']>='4.0.0') {
$buf=@json_decode($buf['cont'],true);
if (is_array($buf)) {
eecho(1,'«'.$opts['hostname'].'»: got instance info from API v2 :-)'.N);
//print_r($buf);
if (isset($buf['title']) && is_string($buf['title']) && !isempty($buf['title']))
$idata['Title']=trim($buf['title']);
if (isset($buf['description']) && is_string($buf['description']) && !isempty($buf['description']))
@ -652,7 +651,8 @@ if (isset($idata['activity']) && is_array($idata['activity'])) {
myq($link,'DELETE FROM InstActivity WHERE InstID='.$instid,__LINE__);
$pos=0;
foreach ($idata['activity'] as $buf) {
if (isset($buf['week']) && is_int($buf['week']) && isset($buf['statuses']) && is_int($buf['statuses']) && isset($buf['logins']) && is_int($buf['logins']) && isset($buf['registrations']) && is_int($buf['registrations'])) {
// these should all be int, but mastodon represents them as strings
if (isset($buf['week']) && is_string($buf['week']) && preg_match('/^\d+$/',$buf['week'])===1 && isset($buf['statuses']) && is_string($buf['statuses']) && preg_match('/^\d+$/',$buf['statuses'])===1 && isset($buf['logins']) && is_string($buf['logins']) && preg_match('/^\d+$/',$buf['logins'])===1 && isset($buf['registrations']) && is_string($buf['registrations']) && preg_match('/^\d+$/',$buf['registrations'])===1) {
$pos++;
myq($link,'INSERT INTO InstActivity (InstID, Week, Statuses, Logins, Registrations, Pos) VALUES ('.$instid.', '.$buf['week'].', '.$buf['statuses'].', '.$buf['logins'].', '.$buf['registrations'].', '.$pos.')',__LINE__);
}