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);
19 require_once('include/pidfile.php');
20 require_once('include/Scrape.php');
21 require_once("include/socgraph.php");
23 load_config('config');
24 load_config('system');
26 $a->set_baseurl(get_config('system','url'));
30 logger('update_gcontact: start');
32 if(($argc > 1) && (intval($argv[1])))
33 $contact_id = intval($argv[1]);
36 logger('update_gcontact: no contact');
40 $lockpath = get_lockpath();
41 if ($lockpath != '') {
42 $pidfile = new pidfile($lockpath, 'update_gcontact'.$contact_id);
43 if ($pidfile->is_already_running()) {
44 logger("update_gcontact: Already running for contact ".$contact_id);
45 if ($pidfile->running_time() > 9*60) {
47 logger("killed stale process");
53 $r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id));
58 if (!in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
61 $data = probe_url($r[0]["url"]);
63 if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
64 if ($r[0]["server_url"] != "")
65 poco_check_server($r[0]["server_url"], $r[0]["network"]);
67 q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `id` = %d",
68 dbesc(datetime_convert()), intval($contact_id));
72 if (($data["name"] == "") AND ($r[0]['name'] != ""))
73 $data["name"] = $r[0]['name'];
75 if (($data["nick"] == "") AND ($r[0]['nick'] != ""))
76 $data["nick"] = $r[0]['nick'];
78 if (($data["addr"] == "") AND ($r[0]['addr'] != ""))
79 $data["addr"] = $r[0]['addr'];
81 if (($data["photo"] == "") AND ($r[0]['photo'] != ""))
82 $data["photo"] = $r[0]['photo'];
85 q("UPDATE `gcontact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
90 dbesc($data["photo"]),
94 q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
95 WHERE `uid` = 0 AND `addr` = '' AND `nurl` = '%s'",
99 dbesc($data["photo"]),
100 dbesc(normalise_link($data["url"]))
103 q("UPDATE `contact` SET `addr` = '%s'
104 WHERE `uid` != 0 AND `addr` = '' AND `nurl` = '%s'",
105 dbesc($data["addr"]),
106 dbesc(normalise_link($data["url"]))
110 if (array_search(__file__,get_included_files())===0){
111 update_gcontact_run($_SERVER["argv"],$_SERVER["argc"]);