Diaspora Pods IP Locations of Diaspora pods on {$_SERVER['HTTP_HOST']} EOF; try { $pods = R::getAll(' SELECT name, monthsmonitored, responsetimelast7, uptimelast7, dateupdated, score, domain, country, lat, long FROM pods_apiv1 '); } catch (\RedBeanPHP\RedException $e) { die('Error in SQL query: ' . $e->getMessage()); } foreach ($pods as $pod) { $summary = sprintf( 'This pod %1$s has been watched for %2$s months and its average ping time is %3$s with uptime of %4$s%% this month and was last checked on %5$s. On a score of 100 this pod is a %6$s right now', htmlentities($pod['name'] ?? '', ENT_QUOTES), $pod['monthsmonitored'], $pod['responsetimelast7'], $pod['uptimelast7'], $pod['dateupdated'], $pod['score'] ); echo << https://{$pod['domain']} urn:{$pod['domain']} Pod Location is: {$pod['country']} {$summary} {$pod['lat']} {$pod['long']} {$pod['domain']} EOF; } echo ''; } elseif ($_format === 'json') { try { $pods = R::getAll(' SELECT id, domain, status, secure, score, userrating, adminrating, city, state, country, lat, long, ip, ipv6, pingdomurl, monthsmonitored, uptimelast7, responsetimelast7, local_posts, comment_counts, dateCreated, dateUpdated, dateLaststats, hidden FROM pods_apiv1 '); } catch (\RedBeanPHP\RedException $e) { die('Error in SQL query: ' . $e->getMessage()); } //json output, thx Vipul A M for fixing this header('Content-type: application/json'); $obj = [ 'podcount' => count($pods), 'pods' => allToString($pods), ]; if ($_method === 'jsonp') { print $_callback . '(' . json_encode($obj) . ')'; } else { print json_encode($obj); } } else { try { $pods = R::getAll(' SELECT domain, uptimelast7, country FROM pods_apiv1 '); } catch (\RedBeanPHP\RedException $e) { die('Error in SQL query: ' . $e->getMessage()); } $i = 0; foreach ($pods as $pod) { $i++ > 0 && print ','; printf( '%1$s Up %2$s%% This Month - Located in: %3$s', $pod['domain'], $pod['uptimelast7'], $pod['country'] ); } } /** * Convert all passed items to strings. * * This method is for backwards compatibility of APIv1 only! * After v2 is released and stable, this can safely be removed. * * @param array $arr List of all elements to stringify. * * @return array */ function allToString(array $arr) { $ret = $arr; foreach ($ret as &$item) { if (is_array($item)) { $item = allToString($item); continue; } $item !== null && $item = (string) $item; unset($item); } return $ret; }