]> git.mxchange.org Git - friendica.git/blob - mod/ostatus_subscribe.php
Merge branch 'develop' into rewrites/dbm_is_result
[friendica.git] / mod / ostatus_subscribe.php
1 <?php
2
3 require_once('include/Scrape.php');
4 require_once('include/follow.php');
5
6 function ostatus_subscribe_content(App &$a) {
7
8         if (! local_user()) {
9                 notice( t('Permission denied.') . EOL);
10                 goaway($_SESSION['return_url']);
11                 // NOTREACHED
12         }
13
14         $o = "<h2>".t("Subscribing to OStatus contacts")."</h2>";
15
16         $uid = local_user();
17
18         $a = get_app();
19
20         $counter = intval($_REQUEST['counter']);
21
22         if (get_pconfig($uid, "ostatus", "legacy_friends") == "") {
23
24                 if ($_REQUEST["url"] == "")
25                         return $o.t("No contact provided.");
26
27                 $contact = probe_url($_REQUEST["url"]);
28
29                 if (!$contact)
30                         return $o.t("Couldn't fetch information for contact.");
31
32                 $api = $contact["baseurl"]."/api/";
33
34                 // Fetching friends
35                 $data = z_fetch_url($api."statuses/friends.json?screen_name=".$contact["nick"]);
36
37                 if (!$data["success"])
38                         return $o.t("Couldn't fetch friends for contact.");
39
40                 set_pconfig($uid, "ostatus", "legacy_friends", $data["body"]);
41         }
42
43         $friends = json_decode(get_pconfig($uid, "ostatus", "legacy_friends"));
44
45         $total = sizeof($friends);
46
47         if ($counter >= $total) {
48                 $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.App::get_baseurl().'/settings/connectors">';
49                 del_pconfig($uid, "ostatus", "legacy_friends");
50                 del_pconfig($uid, "ostatus", "legacy_contact");
51                 $o .= t("Done");
52                 return $o;
53         }
54
55         $friend = $friends[$counter++];
56
57         $url = $friend->statusnet_profile_url;
58
59         $o .= "<p>".$counter."/".$total.": ".$url;
60
61         $data = probe_url($url);
62         if ($data["network"] == NETWORK_OSTATUS) {
63                 $result = new_contact($uid,$url,true);
64                 if ($result["success"])
65                         $o .= " - ".t("success");
66                 else
67                         $o .= " - ".t("failed");
68         } else
69                 $o .= " - ".t("ignored");
70
71         $o .= "</p>";
72
73         $o .= "<p>".t("Keep this window open until done.")."</p>";
74
75         $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.App::get_baseurl().'/ostatus_subscribe?counter='.$counter.'">';
76
77         return $o;
78 }