]> git.mxchange.org Git - friendica.git/commitdiff
We can now return a list of known servers
authorMichael <heluecht@pirati.ca>
Sat, 4 Mar 2017 11:04:00 +0000 (11:04 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 4 Mar 2017 11:04:00 +0000 (11:04 +0000)
include/socgraph.php
mod/poco.php

index cf78024dee0801c116dc76b483cd76bfa6a2b3a3..6a97e285cffaab5fb31a74aae093c64ac3bd0ea3 100644 (file)
@@ -2024,4 +2024,25 @@ function gs_discover() {
                q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"]));
        }
 }
+
+/**
+ * @brief Returns a list of all known servers
+ * @return array List of server urls
+ */
+function poco_serverlist() {
+       $r = q("SELECT `id`, `url`, `site_name` AS `displayName`, `network`, `platform`, `version` FROM `gserver`
+               WHERE `network` IN ('%s', '%s', '%s') AND `last_contact` > `last_failure`
+               ORDER BY `last_contact`
+               LIMIT 1000",
+               dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
+       if (!dbm::is_result($r)) {
+               return false;
+       }
+       $list = array();
+       foreach ($r AS $server) {
+               $server['id'] = (int)$server['id'];
+               $list[] = $server;
+       }
+       return $list;
+}
 ?>
index 4ce075301cb9b1ed5ad27496fb3025bddf5ad06d..422bfe5b7c88e0957b3842c54840fefb869d2fa0 100644 (file)
@@ -27,6 +27,12 @@ function poco_init(App $a) {
        $justme = false;
        $global = false;
 
+       if($a->argc > 1 && $a->argv[1] === '@server') {
+               $ret = poco_serverlist();
+               header('Content-type: application/json');
+               echo json_encode($ret);
+               killme();
+       }
        if($a->argc > 1 && $a->argv[1] === '@global') {
                $global = true;
                $update_limit = date("Y-m-d H:i:s", time() - 30 * 86400);
@@ -314,11 +320,9 @@ function poco_init(App $a) {
 
                                $ret['entry'][] = $entry;
                        }
-               }
-               else
+               } else
                        $ret['entry'][] = array();
-       }
-       else
+       } else
                http_status_exit(500);
 
        logger("End of poco", LOGGER_DEBUG);
@@ -332,8 +336,7 @@ function poco_init(App $a) {
                header('Content-type: application/json');
                echo json_encode($ret);
                killme();
-       }
-       else
+       } else
                http_status_exit(500);