]> git.mxchange.org Git - friendica.git/blob - include/update_gcontact.php
Now there is only the worker.
[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         if(!$contact_id) {
17                 logger('update_gcontact: no contact');
18                 return;
19         }
20
21         $r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id));
22
23         if (!$r)
24                 return;
25
26         if (!in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
27                 return;
28
29         $data = probe_url($r[0]["url"]);
30
31         if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
32                 if ($r[0]["server_url"] != "")
33                         poco_check_server($r[0]["server_url"], $r[0]["network"]);
34
35                 q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `id` = %d",
36                         dbesc(datetime_convert()), intval($contact_id));
37                 return;
38         }
39
40         if (($data["name"] == "") AND ($r[0]['name'] != ""))
41                 $data["name"] = $r[0]['name'];
42
43         if (($data["nick"] == "") AND ($r[0]['nick'] != ""))
44                 $data["nick"] = $r[0]['nick'];
45
46         if (($data["addr"] == "") AND ($r[0]['addr'] != ""))
47                 $data["addr"] = $r[0]['addr'];
48
49         if (($data["photo"] == "") AND ($r[0]['photo'] != ""))
50                 $data["photo"] = $r[0]['photo'];
51
52
53         q("UPDATE `gcontact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
54                                 WHERE `id` = %d",
55                                 dbesc($data["name"]),
56                                 dbesc($data["nick"]),
57                                 dbesc($data["addr"]),
58                                 dbesc($data["photo"]),
59                                 intval($contact_id)
60                         );
61
62         q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
63                                 WHERE `uid` = 0 AND `addr` = '' AND `nurl` = '%s'",
64                                 dbesc($data["name"]),
65                                 dbesc($data["nick"]),
66                                 dbesc($data["addr"]),
67                                 dbesc($data["photo"]),
68                                 dbesc(normalise_link($data["url"]))
69                         );
70
71         q("UPDATE `contact` SET `addr` = '%s'
72                                 WHERE `uid` != 0 AND `addr` = '' AND `nurl` = '%s'",
73                                 dbesc($data["addr"]),
74                                 dbesc(normalise_link($data["url"]))
75                         );
76 }