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