3 * @file mod/ostatus_subscribe.php
7 use Friendica\Core\L10n;
8 use Friendica\Core\PConfig;
9 use Friendica\Core\Protocol;
10 use Friendica\Core\System;
11 use Friendica\Model\Contact;
12 use Friendica\Network\Probe;
13 use Friendica\Util\Network;
15 function ostatus_subscribe_content(App $a)
18 notice(L10n::t('Permission denied.') . EOL);
19 $a->internalRedirect('ostatus_subscribe');
23 $o = '<h2>' . L10n::t('Subscribing to OStatus contacts') . '</h2>';
29 $counter = intval($_REQUEST['counter']);
31 if (PConfig::get($uid, 'ostatus', 'legacy_friends') == '') {
33 if ($_REQUEST['url'] == '') {
34 PConfig::delete($uid, 'ostatus', 'legacy_contact');
35 return $o . L10n::t('No contact provided.');
38 $contact = Probe::uri($_REQUEST['url']);
41 PConfig::delete($uid, 'ostatus', 'legacy_contact');
42 return $o . L10n::t('Couldn\'t fetch information for contact.');
45 $api = $contact['baseurl'] . '/api/';
48 $curlResult = Network::curl($api . 'statuses/friends.json?screen_name=' . $contact['nick']);
50 if (!$curlResult->isSuccess()) {
51 PConfig::delete($uid, 'ostatus', 'legacy_contact');
52 return $o . L10n::t('Couldn\'t fetch friends for contact.');
55 PConfig::set($uid, 'ostatus', 'legacy_friends', $curlResult->getBody());
58 $friends = json_decode(PConfig::get($uid, 'ostatus', 'legacy_friends'));
60 if (empty($friends)) {
64 $total = sizeof($friends);
66 if ($counter >= $total) {
67 $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL=' . System::baseUrl() . '/settings/connectors">';
68 PConfig::delete($uid, 'ostatus', 'legacy_friends');
69 PConfig::delete($uid, 'ostatus', 'legacy_contact');
70 $o .= L10n::t('Done');
74 $friend = $friends[$counter++];
76 $url = $friend->statusnet_profile_url;
78 $o .= '<p>' . $counter . '/' . $total . ': ' . $url;
80 $probed = Probe::uri($url);
81 if ($probed['network'] == Protocol::OSTATUS) {
82 $result = Contact::createFromProbe($uid, $url, true, Protocol::OSTATUS);
83 if ($result['success']) {
84 $o .= ' - ' . L10n::t('success');
86 $o .= ' - ' . L10n::t('failed');
89 $o .= ' - ' . L10n::t('ignored');
94 $o .= '<p>' . L10n::t('Keep this window open until done.') . '</p>';
96 $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL=' . System::baseUrl() . '/ostatus_subscribe?counter=' . $counter . '">';