3 require_once("boot.php");
5 function update_gcontact_run(&$argv, &$argc){
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);
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');
30 load_config('config');
31 load_config('system');
33 $a->set_baseurl(get_config('system','url'));
37 logger('update_gcontact: start');
45 if(($argc > 1) && (intval($argv[1])))
46 $contact_id = intval($argv[1]);
48 if(($argc > 2) && ($argv[2] == "force"))
52 logger('update_gcontact: no contact');
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) {
63 logger("killed stale process");
69 $r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id));
74 $data = probe_url($r[0]["url"]);
76 if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
79 if (($data["name"] == "") AND ($r[0]['name'] != ""))
80 $data["name"] = $r[0]['name'];
82 if (($data["nick"] == "") AND ($r[0]['nick'] != ""))
83 $data["nick"] = $r[0]['nick'];
85 if (($data["addr"] == "") AND ($r[0]['addr'] != ""))
86 $data["addr"] = $r[0]['addr'];
88 if (($data["photo"] == "") AND ($r[0]['photo'] != ""))
89 $data["photo"] = $r[0]['photo'];
92 q("UPDATE `gcontact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
97 dbesc($data["photo"]),
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"]))
111 if (array_search(__file__,get_included_files())===0){
112 update_gcontact_run($_SERVER["argv"],$_SERVER["argc"]);