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