3 * @file mod/ostatus_subscribe.php
6 use Friendica\Core\L10n;
7 use Friendica\Core\PConfig;
8 use Friendica\Core\System;
9 use Friendica\Model\Contact;
10 use Friendica\Network\Probe;
11 use Friendica\Util\Network;
13 function ostatus_subscribe_content(App $a) {
16 notice(L10n::t('Permission denied.') . EOL);
17 goaway($_SESSION['return_url']);
21 $o = "<h2>".L10n::t("Subscribing to OStatus contacts")."</h2>";
27 $counter = intval($_REQUEST['counter']);
29 if (PConfig::get($uid, "ostatus", "legacy_friends") == "") {
31 if ($_REQUEST["url"] == "") {
32 return $o.L10n::t("No contact provided.");
35 $contact = Probe::uri($_REQUEST["url"]);
38 return $o.L10n::t("Couldn't fetch information for contact.");
41 $api = $contact["baseurl"]."/api/";
44 $data = Network::curl($api."statuses/friends.json?screen_name=".$contact["nick"]);
46 if (!$data["success"]) {
47 return $o.L10n::t("Couldn't fetch friends for contact.");
50 PConfig::set($uid, "ostatus", "legacy_friends", $data["body"]);
53 $friends = json_decode(PConfig::get($uid, "ostatus", "legacy_friends"));
55 $total = sizeof($friends);
57 if ($counter >= $total) {
58 $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.System::baseUrl().'/settings/connectors">';
59 PConfig::delete($uid, "ostatus", "legacy_friends");
60 PConfig::delete($uid, "ostatus", "legacy_contact");
61 $o .= L10n::t("Done");
65 $friend = $friends[$counter++];
67 $url = $friend->statusnet_profile_url;
69 $o .= "<p>".$counter."/".$total.": ".$url;
71 $data = Probe::uri($url);
72 if ($data["network"] == NETWORK_OSTATUS) {
73 $result = Contact::createFromProbe($uid, $url, true, NETWORK_OSTATUS);
74 if ($result["success"]) {
75 $o .= " - ".L10n::t("success");
77 $o .= " - ".L10n::t("failed");
80 $o .= " - ".L10n::t("ignored");
85 $o .= "<p>".L10n::t("Keep this window open until done.")."</p>";
87 $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.System::baseUrl().'/ostatus_subscribe?counter='.$counter.'">';