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.

83 lines
1.9 KiB

  1. <?php
  2. require_once('include/Scrape.php');
  3. require_once('include/follow.php');
  4. function ostatus_subscribe_content(App $a) {
  5. if (! local_user()) {
  6. notice( t('Permission denied.') . EOL);
  7. goaway($_SESSION['return_url']);
  8. // NOTREACHED
  9. }
  10. $o = "<h2>".t("Subscribing to OStatus contacts")."</h2>";
  11. $uid = local_user();
  12. $a = get_app();
  13. $counter = intval($_REQUEST['counter']);
  14. if (get_pconfig($uid, "ostatus", "legacy_friends") == "") {
  15. if ($_REQUEST["url"] == "") {
  16. return $o.t("No contact provided.");
  17. }
  18. $contact = probe_url($_REQUEST["url"]);
  19. if (!$contact) {
  20. return $o.t("Couldn't fetch information for contact.");
  21. }
  22. $api = $contact["baseurl"]."/api/";
  23. // Fetching friends
  24. $data = z_fetch_url($api."statuses/friends.json?screen_name=".$contact["nick"]);
  25. if (!$data["success"]) {
  26. return $o.t("Couldn't fetch friends for contact.");
  27. }
  28. set_pconfig($uid, "ostatus", "legacy_friends", $data["body"]);
  29. }
  30. $friends = json_decode(get_pconfig($uid, "ostatus", "legacy_friends"));
  31. $total = sizeof($friends);
  32. if ($counter >= $total) {
  33. $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.App::get_baseurl().'/settings/connectors">';
  34. del_pconfig($uid, "ostatus", "legacy_friends");
  35. del_pconfig($uid, "ostatus", "legacy_contact");
  36. $o .= t("Done");
  37. return $o;
  38. }
  39. $friend = $friends[$counter++];
  40. $url = $friend->statusnet_profile_url;
  41. $o .= "<p>".$counter."/".$total.": ".$url;
  42. $data = probe_url($url);
  43. if ($data["network"] == NETWORK_OSTATUS) {
  44. $result = new_contact($uid,$url,true);
  45. if ($result["success"]) {
  46. $o .= " - ".t("success");
  47. } else {
  48. $o .= " - ".t("failed");
  49. }
  50. } else {
  51. $o .= " - ".t("ignored");
  52. }
  53. $o .= "</p>";
  54. $o .= "<p>".t("Keep this window open until done.")."</p>";
  55. $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.App::get_baseurl().'/ostatus_subscribe?counter='.$counter.'">';
  56. return $o;
  57. }