]> git.mxchange.org Git - friendica.git/blob - src/Worker/DiscoverPoCo.php
"UpdateServers" added
[friendica.git] / src / Worker / DiscoverPoCo.php
1 <?php
2 /**
3  * @file src/Worker/DiscoverPoCo.php
4  */
5 namespace Friendica\Worker;
6
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;
21
22 class DiscoverPoCo
23 {
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 = '')
26         {
27                 /*
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                 - PortableContact::load: Load POCO data from a given POCO address
32                 */
33
34                 $search = "";
35                 $mode = 0;
36                 if ($command == "server") {
37                         $server_url = $param1;
38                         if ($server_url == "") {
39                                 return;
40                         }
41                         $server_url = filter_var($server_url, FILTER_SANITIZE_URL);
42                         if (substr(Strings::normaliseLink($server_url), 0, 7) != "http://") {
43                                 return;
44                         }
45                         $result = "Checking server ".$server_url." - ";
46                         $ret = GServer::check($server_url);
47                         if ($ret) {
48                                 $result .= "success";
49                         } else {
50                                 $result .= "failed";
51                         }
52                         Logger::log($result, Logger::DEBUG);
53                 } elseif ($command == "load") {
54                         if (!empty($param4)) {
55                                 $url = $param4;
56                         } else {
57                                 $url = '';
58                         }
59                         PortableContact::load(intval($param1), intval($param2), intval($param3), $url);
60                 } elseif ($command !== "") {
61                         Logger::log("Unknown or missing parameter ".$command."\n");
62                         return;
63                 }
64
65                 Logger::log('start '.$search);
66
67                 if (($mode == 0) && ($search == "") && (Config::get('system', 'poco_discovery') != PortableContact::DISABLED)) {
68                         // Query Friendica and Hubzilla servers for their users
69                         PortableContact::discover();
70
71                         // Query GNU Social servers for their users ("statistics" addon has to be enabled on the GS server)
72                         if (!Config::get('system', 'ostatus_disabled')) {
73                                 GContact::discoverGsUsers();
74                         }
75                 }
76
77                 Logger::log('end '.$search);
78
79                 return;
80         }
81 }