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 PConfig::delete($uid, "ostatus", "legacy_contact");
33 return $o.L10n::t("No contact provided.");
36 $contact = Probe::uri($_REQUEST["url"]);
39 PConfig::delete($uid, "ostatus", "legacy_contact");
40 return $o.L10n::t("Couldn't fetch information for contact.");
43 $api = $contact["baseurl"]."/api/";
46 $data = Network::curl($api."statuses/friends.json?screen_name=".$contact["nick"]);
48 if (!$data["success"]) {
49 PConfig::delete($uid, "ostatus", "legacy_contact");
50 return $o.L10n::t("Couldn't fetch friends for contact.");
53 PConfig::set($uid, "ostatus", "legacy_friends", $data["body"]);
56 $friends = json_decode(PConfig::get($uid, "ostatus", "legacy_friends"));
58 $total = sizeof($friends);
60 if ($counter >= $total) {
61 $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.System::baseUrl().'/settings/connectors">';
62 PConfig::delete($uid, "ostatus", "legacy_friends");
63 PConfig::delete($uid, "ostatus", "legacy_contact");
64 $o .= L10n::t("Done");
68 $friend = $friends[$counter++];
70 $url = $friend->statusnet_profile_url;
72 $o .= "<p>".$counter."/".$total.": ".$url;
74 $data = Probe::uri($url);
75 if ($data["network"] == NETWORK_OSTATUS) {
76 $result = Contact::createFromProbe($uid, $url, true, NETWORK_OSTATUS);
77 if ($result["success"]) {
78 $o .= " - ".L10n::t("success");
80 $o .= " - ".L10n::t("failed");
83 $o .= " - ".L10n::t("ignored");
88 $o .= "<p>".L10n::t("Keep this window open until done.")."</p>";
90 $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.System::baseUrl().'/ostatus_subscribe?counter='.$counter.'">';