]> git.mxchange.org Git - friendica.git/blob - mod/ostatus_subscribe.php
Fix formatting and PHP notice in mod/photos
[friendica.git] / mod / ostatus_subscribe.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\PConfig;
5 use Friendica\Core\System;
6 use Friendica\Network\Probe;
7
8 require_once 'include/follow.php';
9
10 function ostatus_subscribe_content(App $a) {
11
12         if (! local_user()) {
13                 notice( t('Permission denied.') . EOL);
14                 goaway($_SESSION['return_url']);
15                 // NOTREACHED
16         }
17
18         $o = "<h2>".t("Subscribing to OStatus contacts")."</h2>";
19
20         $uid = local_user();
21
22         $a = get_app();
23
24         $counter = intval($_REQUEST['counter']);
25
26         if (PConfig::get($uid, "ostatus", "legacy_friends") == "") {
27
28                 if ($_REQUEST["url"] == "") {
29                         return $o.t("No contact provided.");
30                 }
31
32                 $contact = Probe::uri($_REQUEST["url"]);
33
34                 if (!$contact) {
35                         return $o.t("Couldn't fetch information for contact.");
36                 }
37
38                 $api = $contact["baseurl"]."/api/";
39
40                 // Fetching friends
41                 $data = z_fetch_url($api."statuses/friends.json?screen_name=".$contact["nick"]);
42
43                 if (!$data["success"]) {
44                         return $o.t("Couldn't fetch friends for contact.");
45                 }
46
47                 PConfig::set($uid, "ostatus", "legacy_friends", $data["body"]);
48         }
49
50         $friends = json_decode(PConfig::get($uid, "ostatus", "legacy_friends"));
51
52         $total = sizeof($friends);
53
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");
58                 $o .= t("Done");
59                 return $o;
60         }
61
62         $friend = $friends[$counter++];
63
64         $url = $friend->statusnet_profile_url;
65
66         $o .= "<p>".$counter."/".$total.": ".$url;
67
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");
73                 } else {
74                         $o .= " - ".t("failed");
75                 }
76         } else {
77                 $o .= " - ".t("ignored");
78         }
79
80         $o .= "</p>";
81
82         $o .= "<p>".t("Keep this window open until done.")."</p>";
83
84         $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.System::baseUrl().'/ostatus_subscribe?counter='.$counter.'">';
85
86         return $o;
87 }