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.

116 lines
2.9 KiB

  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/pidfile.php');
  15. require_once('include/Scrape.php');
  16. require_once("include/socgraph.php");
  17. load_config('config');
  18. load_config('system');
  19. $a->set_baseurl(get_config('system','url'));
  20. load_hooks();
  21. logger('update_gcontact: start');
  22. if(($argc > 1) && (intval($argv[1])))
  23. $contact_id = intval($argv[1]);
  24. if(!$contact_id) {
  25. logger('update_gcontact: no contact');
  26. return;
  27. }
  28. // Don't check this stuff if the function is called by the poller
  29. if (App::callstack() != "poller_run") {
  30. $lockpath = get_lockpath();
  31. if ($lockpath != '') {
  32. $pidfile = new pidfile($lockpath, 'update_gcontact'.$contact_id);
  33. if ($pidfile->is_already_running()) {
  34. logger("update_gcontact: Already running for contact ".$contact_id);
  35. if ($pidfile->running_time() > 9*60) {
  36. $pidfile->kill();
  37. logger("killed stale process");
  38. }
  39. exit;
  40. }
  41. }
  42. }
  43. $r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id));
  44. if (!$r)
  45. return;
  46. if (!in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
  47. return;
  48. $data = probe_url($r[0]["url"]);
  49. if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
  50. if ($r[0]["server_url"] != "")
  51. poco_check_server($r[0]["server_url"], $r[0]["network"]);
  52. q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `id` = %d",
  53. dbesc(datetime_convert()), intval($contact_id));
  54. return;
  55. }
  56. if (($data["name"] == "") AND ($r[0]['name'] != ""))
  57. $data["name"] = $r[0]['name'];
  58. if (($data["nick"] == "") AND ($r[0]['nick'] != ""))
  59. $data["nick"] = $r[0]['nick'];
  60. if (($data["addr"] == "") AND ($r[0]['addr'] != ""))
  61. $data["addr"] = $r[0]['addr'];
  62. if (($data["photo"] == "") AND ($r[0]['photo'] != ""))
  63. $data["photo"] = $r[0]['photo'];
  64. q("UPDATE `gcontact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
  65. WHERE `id` = %d",
  66. dbesc($data["name"]),
  67. dbesc($data["nick"]),
  68. dbesc($data["addr"]),
  69. dbesc($data["photo"]),
  70. intval($contact_id)
  71. );
  72. q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
  73. WHERE `uid` = 0 AND `addr` = '' AND `nurl` = '%s'",
  74. dbesc($data["name"]),
  75. dbesc($data["nick"]),
  76. dbesc($data["addr"]),
  77. dbesc($data["photo"]),
  78. dbesc(normalise_link($data["url"]))
  79. );
  80. q("UPDATE `contact` SET `addr` = '%s'
  81. WHERE `uid` != 0 AND `addr` = '' AND `nurl` = '%s'",
  82. dbesc($data["addr"]),
  83. dbesc(normalise_link($data["url"]))
  84. );
  85. }
  86. if (array_search(__file__,get_included_files())===0){
  87. update_gcontact_run($_SERVER["argv"],$_SERVER["argc"]);
  88. killme();
  89. }