3 * @file src/Worker/DiscoverPoCo.php
5 namespace Friendica\Worker;
7 use Friendica\Core\Cache;
8 use Friendica\Core\Config;
9 use Friendica\Core\Logger;
10 use Friendica\Core\Protocol;
11 use Friendica\Core\Worker;
12 use Friendica\Database\DBA;
13 use Friendica\Model\GContact;
14 use Friendica\Model\Contact;
15 use Friendica\Model\GServer;
16 use Friendica\Network\Probe;
17 use Friendica\Protocol\PortableContact;
18 use Friendica\Util\DateTimeFormat;
19 use Friendica\Util\Network;
20 use Friendica\Util\Strings;
24 /// @todo Clean up this mess of a parameter hell and split it in several classes
25 public static function execute($command = '', $param1 = '', $param2 = '', $param3 = '', $param4 = '')
28 This function can be called in these ways:
29 - checkcontact: Updates gcontact entries
30 - server <poco url>: Searches for the poco server list. "poco url" is base64 encoded.
31 - update_server: Frequently check the first 250 servers for vitality.
32 - PortableContact::load: Load POCO data from a given POCO address
37 if ($command == "server") {
38 $server_url = $param1;
39 if ($server_url == "") {
42 $server_url = filter_var($server_url, FILTER_SANITIZE_URL);
43 if (substr(Strings::normaliseLink($server_url), 0, 7) != "http://") {
46 $result = "Checking server ".$server_url." - ";
47 $ret = GServer::check($server_url);
53 Logger::log($result, Logger::DEBUG);
54 } elseif ($command == "update_server") {
56 } elseif ($command == "load") {
57 if (!empty($param4)) {
62 PortableContact::load(intval($param1), intval($param2), intval($param3), $url);
63 } elseif ($command !== "") {
64 Logger::log("Unknown or missing parameter ".$command."\n");
68 Logger::log('start '.$search);
70 if (($mode == 0) && ($search == "") && (Config::get('system', 'poco_discovery') != PortableContact::DISABLED)) {
71 // Query Friendica and Hubzilla servers for their users
72 PortableContact::discover();
74 // Query GNU Social servers for their users ("statistics" addon has to be enabled on the GS server)
75 if (!Config::get('system', 'ostatus_disabled')) {
76 GContact::discoverGsUsers();
80 Logger::log('end '.$search);
86 * @brief Updates the first 250 servers
89 private static function updateServer() {
90 $r = q("SELECT `url`, `created`, `last_failure`, `last_contact` FROM `gserver` ORDER BY rand()");
92 if (!DBA::isResult($r)) {
98 foreach ($r AS $server) {
99 if (!PortableContact::updateNeeded($server["created"], "", $server["last_failure"], $server["last_contact"])) {
102 Logger::log('Update server status for server '.$server["url"], Logger::DEBUG);
104 Worker::add(PRIORITY_LOW, "DiscoverPoCo", "server", $server["url"]);
106 if (++$updated > 250) {