]> git.mxchange.org Git - friendica.git/blob - include/update_gcontact.php
The contact template now displays the address if available
[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
20         require_once('include/session.php');
21         require_once('include/datetime.php');
22         require_once('library/simplepie/simplepie.inc');
23         require_once('include/items.php');
24         require_once('include/Contact.php');
25         require_once('include/email.php');
26         require_once('include/socgraph.php');
27         require_once('include/pidfile.php');
28         require_once('include/queue_fn.php');
29
30         load_config('config');
31         load_config('system');
32
33         $a->set_baseurl(get_config('system','url'));
34
35         load_hooks();
36
37         logger('update_gcontact: start');
38
39         $manual_id  = 0;
40         $generation = 0;
41         $hub_update = false;
42         $force      = false;
43         $restart    = false;
44
45         if(($argc > 1) && (intval($argv[1])))
46                 $contact_id = intval($argv[1]);
47
48         if(($argc > 2) && ($argv[2] == "force"))
49                 $force = true;
50
51         if(!$contact_id) {
52                 logger('update_gcontact: no contact');
53                 return;
54         }
55
56         $lockpath = get_lockpath();
57         if ($lockpath != '') {
58                 $pidfile = new pidfile($lockpath, 'update_gcontact'.$contact_id);
59                 if ($pidfile->is_already_running()) {
60                         logger("update_gcontact: Already running for contact ".$contact_id);
61                         if ($pidfile->running_time() > 9*60) {
62                                 $pidfile->kill();
63                                 logger("killed stale process");
64                         }
65                         exit;
66                 }
67         }
68
69         $r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id));
70
71         if (!$r)
72                 return;
73
74         $data = probe_url($r[0]["url"]);
75
76         if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
77                 return;
78
79         if (($data["name"] == "") AND ($r[0]['name'] != ""))
80                 $data["name"] = $r[0]['name'];
81
82         if (($data["nick"] == "") AND ($r[0]['nick'] != ""))
83                 $data["nick"] = $r[0]['nick'];
84
85         if (($data["addr"] == "") AND ($r[0]['addr'] != ""))
86                 $data["addr"] = $r[0]['addr'];
87
88         if (($data["photo"] == "") AND ($r[0]['photo'] != ""))
89                 $data["photo"] = $r[0]['photo'];
90
91
92         q("UPDATE `gcontact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
93                                 WHERE `id` = %d",
94                                 dbesc($data["name"]),
95                                 dbesc($data["nick"]),
96                                 dbesc($data["addr"]),
97                                 dbesc($data["photo"]),
98                                 intval($contact_id)
99                         );
100
101         q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
102                                 WHERE `uid` = 0 AND `nurl` = '%s'",
103                                 dbesc($data["name"]),
104                                 dbesc($data["nick"]),
105                                 dbesc($data["addr"]),
106                                 dbesc($data["photo"]),
107                                 dbesc(normalise_link($data["url"]))
108                         );
109 }
110
111 if (array_search(__file__,get_included_files())===0){
112   update_gcontact_run($_SERVER["argv"],$_SERVER["argc"]);
113   killme();
114 }