4 use Friendica\Core\System;
6 require_once 'include/probe.php';
7 require_once 'include/follow.php';
9 function ostatus_subscribe_content(App $a) {
12 notice( t('Permission denied.') . EOL);
13 goaway($_SESSION['return_url']);
17 $o = "<h2>".t("Subscribing to OStatus contacts")."</h2>";
23 $counter = intval($_REQUEST['counter']);
25 if (get_pconfig($uid, "ostatus", "legacy_friends") == "") {
27 if ($_REQUEST["url"] == "") {
28 return $o.t("No contact provided.");
31 $contact = probe_url($_REQUEST["url"]);
34 return $o.t("Couldn't fetch information for contact.");
37 $api = $contact["baseurl"]."/api/";
40 $data = z_fetch_url($api."statuses/friends.json?screen_name=".$contact["nick"]);
42 if (!$data["success"]) {
43 return $o.t("Couldn't fetch friends for contact.");
46 set_pconfig($uid, "ostatus", "legacy_friends", $data["body"]);
49 $friends = json_decode(get_pconfig($uid, "ostatus", "legacy_friends"));
51 $total = sizeof($friends);
53 if ($counter >= $total) {
54 $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.System::baseUrl().'/settings/connectors">';
55 del_pconfig($uid, "ostatus", "legacy_friends");
56 del_pconfig($uid, "ostatus", "legacy_contact");
61 $friend = $friends[$counter++];
63 $url = $friend->statusnet_profile_url;
65 $o .= "<p>".$counter."/".$total.": ".$url;
67 $data = probe_url($url);
68 if ($data["network"] == NETWORK_OSTATUS) {
69 $result = new_contact($uid, $url, true, NETWORK_OSTATUS);
70 if ($result["success"]) {
71 $o .= " - ".t("success");
73 $o .= " - ".t("failed");
76 $o .= " - ".t("ignored");
81 $o .= "<p>".t("Keep this window open until done.")."</p>";
83 $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.System::baseUrl().'/ostatus_subscribe?counter='.$counter.'">';