]> git.mxchange.org Git - friendica.git/blob - src/Worker/UpdateGContact.php
Remove comment
[friendica.git] / src / Worker / UpdateGContact.php
1 <?php
2
3 /**
4  * @file src/Worker/UpdateGcontact.php
5  */
6
7 namespace Friendica\Worker;
8
9 use Friendica\Database\DBM;
10 use Friendica\Network\Probe;
11 use Friendica\Protocol\PortableContact;
12 use Friendica\Util\DateTimeFormat;
13
14 class UpdateGContact
15 {
16         public static function execute($contact_id)
17         {
18                 global $a;
19
20                 logger('update_gcontact: start');
21
22                 if (empty($contact_id)) {
23                         logger('update_gcontact: no contact');
24                         return;
25                 }
26
27                 $r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id));
28
29                 if (!DBM::is_result($r)) {
30                         return;
31                 }
32
33                 if (!in_array($r[0]["network"], [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS])) {
34                         return;
35                 }
36
37                 $data = Probe::uri($r[0]["url"]);
38
39                 if (!in_array($data["network"], [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS])) {
40                         if ($r[0]["server_url"] != "") {
41                                 PortableContact::checkServer($r[0]["server_url"], $r[0]["network"]);
42                         }
43
44                         q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `id` = %d",
45                                 dbesc(DateTimeFormat::utcNow()), intval($contact_id));
46                         return;
47                 }
48
49                 if (($data["name"] == "") && ($r[0]['name'] != "")) {
50                         $data["name"] = $r[0]['name'];
51                 }
52
53                 if (($data["nick"] == "") && ($r[0]['nick'] != "")) {
54                         $data["nick"] = $r[0]['nick'];
55                 }
56
57                 if (($data["addr"] == "") && ($r[0]['addr'] != "")) {
58                         $data["addr"] = $r[0]['addr'];
59                 }
60
61                 if (($data["photo"] == "") && ($r[0]['photo'] != "")) {
62                         $data["photo"] = $r[0]['photo'];
63                 }
64
65
66                 q("UPDATE `gcontact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
67                                         WHERE `id` = %d",
68                                         dbesc($data["name"]),
69                                         dbesc($data["nick"]),
70                                         dbesc($data["addr"]),
71                                         dbesc($data["photo"]),
72                         intval($contact_id)
73                 );
74
75                 q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
76                                         WHERE `uid` = 0 AND `addr` = '' AND `nurl` = '%s'",
77                                         dbesc($data["name"]),
78                                         dbesc($data["nick"]),
79                                         dbesc($data["addr"]),
80                                         dbesc($data["photo"]),
81                                         dbesc(normalise_link($data["url"]))
82                 );
83
84                 q("UPDATE `contact` SET `addr` = '%s'
85                                         WHERE `uid` != 0 AND `addr` = '' AND `nurl` = '%s'",
86                                         dbesc($data["addr"]),
87                                         dbesc(normalise_link($data["url"]))
88                 );
89         }
90 }