4 use Friendica\Core\PConfig;
5 use Friendica\Core\System;
6 use Friendica\Network\Probe;
8 require_once 'include/follow.php';
10 function ostatus_subscribe_content(App $a) {
13 notice( t('Permission denied.') . EOL);
14 goaway($_SESSION['return_url']);
18 $o = "<h2>".t("Subscribing to OStatus contacts")."</h2>";
24 $counter = intval($_REQUEST['counter']);
26 if (PConfig::get($uid, "ostatus", "legacy_friends") == "") {
28 if ($_REQUEST["url"] == "") {
29 return $o.t("No contact provided.");
32 $contact = Probe::uri($_REQUEST["url"]);
35 return $o.t("Couldn't fetch information for contact.");
38 $api = $contact["baseurl"]."/api/";
41 $data = z_fetch_url($api."statuses/friends.json?screen_name=".$contact["nick"]);
43 if (!$data["success"]) {
44 return $o.t("Couldn't fetch friends for contact.");
47 PConfig::set($uid, "ostatus", "legacy_friends", $data["body"]);
50 $friends = json_decode(PConfig::get($uid, "ostatus", "legacy_friends"));
52 $total = sizeof($friends);
54 if ($counter >= $total) {
55 $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.System::baseUrl().'/settings/connectors">';
56 PConfig::delete($uid, "ostatus", "legacy_friends");
57 PConfig::delete($uid, "ostatus", "legacy_contact");
62 $friend = $friends[$counter++];
64 $url = $friend->statusnet_profile_url;
66 $o .= "<p>".$counter."/".$total.": ".$url;
68 $data = Probe::uri($url);
69 if ($data["network"] == NETWORK_OSTATUS) {
70 $result = new_contact($uid, $url, true, NETWORK_OSTATUS);
71 if ($result["success"]) {
72 $o .= " - ".t("success");
74 $o .= " - ".t("failed");
77 $o .= " - ".t("ignored");
82 $o .= "<p>".t("Keep this window open until done.")."</p>";
84 $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.System::baseUrl().'/ostatus_subscribe?counter='.$counter.'">';