]> git.mxchange.org Git - friendica.git/blob - mod/ostatus_subscribe.php
Merge remote-tracking branch 'upstream/develop' into develop
[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
28                 $contact = probe_url($_REQUEST["url"]);
29
30                 if (!$contact) {
31                         return $o.t("Couldn't fetch information for contact.");
32                 }
33
34                 $api = $contact["baseurl"]."/api/";
35
36                 // Fetching friends
37                 $data = z_fetch_url($api."statuses/friends.json?screen_name=".$contact["nick"]);
38
39                 if (!$data["success"]) {
40                         return $o.t("Couldn't fetch friends for contact.");
41                 }
42
43                 set_pconfig($uid, "ostatus", "legacy_friends", $data["body"]);
44         }
45
46         $friends = json_decode(get_pconfig($uid, "ostatus", "legacy_friends"));
47
48         $total = sizeof($friends);
49
50         if ($counter >= $total) {
51                 $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.App::get_baseurl().'/settings/connectors">';
52                 del_pconfig($uid, "ostatus", "legacy_friends");
53                 del_pconfig($uid, "ostatus", "legacy_contact");
54                 $o .= t("Done");
55                 return $o;
56         }
57
58         $friend = $friends[$counter++];
59
60         $url = $friend->statusnet_profile_url;
61
62         $o .= "<p>".$counter."/".$total.": ".$url;
63
64         $data = probe_url($url);
65         if ($data["network"] == NETWORK_OSTATUS) {
66                 $result = new_contact($uid,$url,true);
67                 if ($result["success"]) {
68                         $o .= " - ".t("success");
69                 } else {
70                         $o .= " - ".t("failed");
71                 }
72         } else {
73                 $o .= " - ".t("ignored");
74         }
75
76         $o .= "</p>";
77
78         $o .= "<p>".t("Keep this window open until done.")."</p>";
79
80         $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.App::get_baseurl().'/ostatus_subscribe?counter='.$counter.'">';
81
82         return $o;
83 }