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