]> git.mxchange.org Git - friendica.git/blob - include/update_gcontact.php
Merge remote-tracking branch 'upstream/master'
[friendica.git] / include / update_gcontact.php
1 <?php
2
3 use \Friendica\Core\Config;
4
5 require_once("boot.php");
6
7 function update_gcontact_run(&$argv, &$argc){
8         global $a, $db;
9
10         if(is_null($a)) {
11                 $a = new App;
12         }
13
14         if(is_null($db)) {
15                 @include(".htconfig.php");
16                 require_once("include/dba.php");
17                 $db = new dba($db_host, $db_user, $db_pass, $db_data);
18                 unset($db_host, $db_user, $db_pass, $db_data);
19         };
20
21         require_once('include/Scrape.php');
22         require_once("include/socgraph.php");
23
24         Config::load();
25
26         $a->set_baseurl(get_config('system','url'));
27
28         load_hooks();
29
30         logger('update_gcontact: start');
31
32         if(($argc > 1) && (intval($argv[1])))
33                 $contact_id = intval($argv[1]);
34
35         if(!$contact_id) {
36                 logger('update_gcontact: no contact');
37                 return;
38         }
39
40         // Don't check this stuff if the function is called by the poller
41         if (App::callstack() != "poller_run")
42                 if (App::is_already_running('update_gcontact'.$contact_id, '', 540))
43                         return;
44
45         $r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id));
46
47         if (!$r)
48                 return;
49
50         if (!in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
51                 return;
52
53         $data = probe_url($r[0]["url"]);
54
55         if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
56                 if ($r[0]["server_url"] != "")
57                         poco_check_server($r[0]["server_url"], $r[0]["network"]);
58
59                 q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `id` = %d",
60                         dbesc(datetime_convert()), intval($contact_id));
61                 return;
62         }
63
64         if (($data["name"] == "") AND ($r[0]['name'] != ""))
65                 $data["name"] = $r[0]['name'];
66
67         if (($data["nick"] == "") AND ($r[0]['nick'] != ""))
68                 $data["nick"] = $r[0]['nick'];
69
70         if (($data["addr"] == "") AND ($r[0]['addr'] != ""))
71                 $data["addr"] = $r[0]['addr'];
72
73         if (($data["photo"] == "") AND ($r[0]['photo'] != ""))
74                 $data["photo"] = $r[0]['photo'];
75
76
77         q("UPDATE `gcontact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
78                                 WHERE `id` = %d",
79                                 dbesc($data["name"]),
80                                 dbesc($data["nick"]),
81                                 dbesc($data["addr"]),
82                                 dbesc($data["photo"]),
83                                 intval($contact_id)
84                         );
85
86         q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
87                                 WHERE `uid` = 0 AND `addr` = '' AND `nurl` = '%s'",
88                                 dbesc($data["name"]),
89                                 dbesc($data["nick"]),
90                                 dbesc($data["addr"]),
91                                 dbesc($data["photo"]),
92                                 dbesc(normalise_link($data["url"]))
93                         );
94
95         q("UPDATE `contact` SET `addr` = '%s'
96                                 WHERE `uid` != 0 AND `addr` = '' AND `nurl` = '%s'",
97                                 dbesc($data["addr"]),
98                                 dbesc(normalise_link($data["url"]))
99                         );
100 }
101
102 if (array_search(__file__,get_included_files())===0){
103         update_gcontact_run($_SERVER["argv"],$_SERVER["argc"]);
104         killme();
105 }