]> git.mxchange.org Git - friendica.git/blob - include/update_gcontact.php
Revert "Coding convention applied - part 1"
[friendica.git] / include / update_gcontact.php
1 <?php
2
3 use \Friendica\Core\Config;
4
5 function update_gcontact_run(&$argv, &$argc){
6         global $a;
7
8         require_once('include/Scrape.php');
9         require_once('include/socgraph.php');
10
11         logger('update_gcontact: start');
12
13         if (($argc > 1) && (intval($argv[1]))) {
14                 $contact_id = intval($argv[1]);
15         }
16
17         if (!$contact_id) {
18                 logger('update_gcontact: no contact');
19                 return;
20         }
21
22         $r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id));
23
24         if (!$r)
25                 return;
26
27         if (!in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
28                 return;
29
30         $data = probe_url($r[0]["url"]);
31
32         if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
33                 if ($r[0]["server_url"] != "")
34                         poco_check_server($r[0]["server_url"], $r[0]["network"]);
35
36                 q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `id` = %d",
37                         dbesc(datetime_convert()), intval($contact_id));
38                 return;
39         }
40
41         if (($data["name"] == "") AND ($r[0]['name'] != ""))
42                 $data["name"] = $r[0]['name'];
43
44         if (($data["nick"] == "") AND ($r[0]['nick'] != ""))
45                 $data["nick"] = $r[0]['nick'];
46
47         if (($data["addr"] == "") AND ($r[0]['addr'] != ""))
48                 $data["addr"] = $r[0]['addr'];
49
50         if (($data["photo"] == "") AND ($r[0]['photo'] != ""))
51                 $data["photo"] = $r[0]['photo'];
52
53
54         q("UPDATE `gcontact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
55                                 WHERE `id` = %d",
56                                 dbesc($data["name"]),
57                                 dbesc($data["nick"]),
58                                 dbesc($data["addr"]),
59                                 dbesc($data["photo"]),
60                                 intval($contact_id)
61                         );
62
63         q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
64                                 WHERE `uid` = 0 AND `addr` = '' AND `nurl` = '%s'",
65                                 dbesc($data["name"]),
66                                 dbesc($data["nick"]),
67                                 dbesc($data["addr"]),
68                                 dbesc($data["photo"]),
69                                 dbesc(normalise_link($data["url"]))
70                         );
71
72         q("UPDATE `contact` SET `addr` = '%s'
73                                 WHERE `uid` != 0 AND `addr` = '' AND `nurl` = '%s'",
74                                 dbesc($data["addr"]),
75                                 dbesc(normalise_link($data["url"]))
76                         );
77 }