Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.6KB

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