3 * @file mod/ostatus_subscribe.php
6 use Friendica\Core\L10n;
7 use Friendica\Core\PConfig;
8 use Friendica\Core\Protocol;
9 use Friendica\Core\System;
10 use Friendica\Model\Contact;
11 use Friendica\Network\Probe;
12 use Friendica\Util\Network;
14 function ostatus_subscribe_content(App $a) {
17 notice(L10n::t('Permission denied.') . EOL);
18 goaway($_SESSION['return_url']);
22 $o = "<h2>".L10n::t("Subscribing to OStatus contacts")."</h2>";
28 $counter = intval($_REQUEST['counter']);
30 if (PConfig::get($uid, "ostatus", "legacy_friends") == "") {
32 if ($_REQUEST["url"] == "") {
33 PConfig::delete($uid, "ostatus", "legacy_contact");
34 return $o.L10n::t("No contact provided.");
37 $contact = Probe::uri($_REQUEST["url"]);
40 PConfig::delete($uid, "ostatus", "legacy_contact");
41 return $o.L10n::t("Couldn't fetch information for contact.");
44 $api = $contact["baseurl"]."/api/";
47 $data = Network::curl($api."statuses/friends.json?screen_name=".$contact["nick"]);
49 if (!$data["success"]) {
50 PConfig::delete($uid, "ostatus", "legacy_contact");
51 return $o.L10n::t("Couldn't fetch friends for contact.");
54 PConfig::set($uid, "ostatus", "legacy_friends", $data["body"]);
57 $friends = json_decode(PConfig::get($uid, "ostatus", "legacy_friends"));
59 $total = sizeof($friends);
61 if ($counter >= $total) {
62 $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.System::baseUrl().'/settings/connectors">';
63 PConfig::delete($uid, "ostatus", "legacy_friends");
64 PConfig::delete($uid, "ostatus", "legacy_contact");
65 $o .= L10n::t("Done");
69 $friend = $friends[$counter++];
71 $url = $friend->statusnet_profile_url;
73 $o .= "<p>".$counter."/".$total.": ".$url;
75 $data = Probe::uri($url);
76 if ($data["network"] == Protocol::OSTATUS) {
77 $result = Contact::createFromProbe($uid, $url, true, Protocol::OSTATUS);
78 if ($result["success"]) {
79 $o .= " - ".L10n::t("success");
81 $o .= " - ".L10n::t("failed");
84 $o .= " - ".L10n::t("ignored");
89 $o .= "<p>".L10n::t("Keep this window open until done.")."</p>";
91 $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.System::baseUrl().'/ostatus_subscribe?counter='.$counter.'">';