]> git.mxchange.org Git - friendica.git/blob - mod/follow.php
fbe4602f5b5b1082e89625acbbc9a7465375724a
[friendica.git] / mod / follow.php
1 <?php
2
3 use Friendica\App;
4
5 require_once('include/Scrape.php');
6 require_once 'include/follow.php';
7 require_once 'include/Contact.php';
8 require_once 'include/contact_selectors.php';
9
10 function follow_content(App $a) {
11
12         if (! local_user()) {
13                 notice( t('Permission denied.') . EOL);
14                 goaway($_SESSION['return_url']);
15                 // NOTREACHED
16         }
17
18         $uid = local_user();
19         $url = notags(trim($_REQUEST['url']));
20
21         $submit = t('Submit Request');
22
23         // There is a current issue. It seems as if you can't start following a Friendica that is following you
24         // With Diaspora this works - but Friendica is special, it seems ...
25         $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND
26                 (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
27                 `network` != '%s' LIMIT 1",
28                 intval(local_user()), dbesc(CONTACT_IS_FOLLOWER), dbesc(NETWORK_DFRN), dbesc(normalise_link($url)),
29                 dbesc(normalise_link($url)), dbesc($url), dbesc(NETWORK_STATUSNET));
30
31         if ($r) {
32                 notice(t('You already added this contact.').EOL);
33                 $submit = "";
34                 //goaway($_SESSION['return_url']);
35                 // NOTREACHED
36         }
37
38         $ret = probe_url($url);
39
40         if (($ret["network"] == NETWORK_DIASPORA) AND !get_config('system','diaspora_enabled')) {
41                 notice( t("Diaspora support isn't enabled. Contact can't be added.") . EOL);
42                 $submit = "";
43                 //goaway($_SESSION['return_url']);
44                 // NOTREACHED
45         }
46
47         if (($ret["network"] == NETWORK_OSTATUS) AND get_config('system','ostatus_disabled')) {
48                 notice( t("OStatus support is disabled. Contact can't be added.") . EOL);
49                 $submit = "";
50                 //goaway($_SESSION['return_url']);
51                 // NOTREACHED
52         }
53
54         if ($ret["network"] == NETWORK_PHANTOM) {
55                 notice( t("The network type couldn't be detected. Contact can't be added.") . EOL);
56                 $submit = "";
57                 //goaway($_SESSION['return_url']);
58                 // NOTREACHED
59         }
60
61         if ($ret["network"] == NETWORK_MAIL) {
62                 $ret["url"] = $ret["addr"];
63         }
64
65         if ($ret['network'] === NETWORK_DFRN) {
66                 $request = $ret["request"];
67                 $tpl = get_markup_template('dfrn_request.tpl');
68         } else {
69                 $request = App::get_baseurl()."/follow";
70                 $tpl = get_markup_template('auto_request.tpl');
71         }
72
73         $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
74
75         if (!$r) {
76                 notice( t('Permission denied.') . EOL);
77                 goaway($_SESSION['return_url']);
78                 // NOTREACHED
79         }
80
81         $myaddr = $r[0]["url"];
82         $gcontact_id = 0;
83
84         // Makes the connection request for friendica contacts easier
85         $_SESSION["fastlane"] = $ret["url"];
86
87         $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
88                 normalise_link($ret["url"]));
89
90         if (!$r) {
91                 $r = array(array("location" => "", "about" => "", "keywords" => ""));
92         } else {
93                 $gcontact_id = $r[0]["id"];
94         }
95
96         if ($ret['network'] === NETWORK_DIASPORA) {
97                 $r[0]["location"] = "";
98                 $r[0]["about"] = "";
99         }
100
101         $header = $ret["name"];
102
103         if ($ret["addr"] != "") {
104                 $header .= " <".$ret["addr"].">";
105         }
106
107         //$header .= " (".network_to_name($ret['network'], $ret['url']).")";
108         $header = t("Connect/Follow");
109
110         $o  = replace_macros($tpl,array(
111                         '$header' => htmlentities($header),
112                         //'$photo' => proxy_url($ret["photo"], false, PROXY_SIZE_SMALL),
113                         '$desc' => "",
114                         '$pls_answer' => t('Please answer the following:'),
115                         '$does_know_you' => array('knowyou', sprintf(t('Does %s know you?'),$ret["name"]), false, '', array(t('No'), t('Yes'))),
116                         '$add_note' => t('Add a personal note:'),
117                         '$page_desc' => "",
118                         '$friendica' => "",
119                         '$statusnet' => "",
120                         '$diaspora' => "",
121                         '$diasnote' => "",
122                         '$your_address' => t('Your Identity Address:'),
123                         '$invite_desc' => "",
124                         '$emailnet' => "",
125                         '$submit' => $submit,
126                         '$cancel' => t('Cancel'),
127                         '$nickname' => "",
128                         '$name' => $ret["name"],
129                         '$url' => $ret["url"],
130                         '$zrl' => zrl($ret["url"]),
131                         '$url_label' => t("Profile URL"),
132                         '$myaddr' => $myaddr,
133                         '$request' => $request,
134                         /*'$location' => bbcode($r[0]["location"]),
135                         '$location_label' => t("Location:"),
136                         '$about' => bbcode($r[0]["about"], false, false),
137                         '$about_label' => t("About:"), */
138                         '$keywords' => $r[0]["keywords"],
139                         '$keywords_label' => t("Tags:")
140         ));
141
142         $a->page['aside'] = "";
143         profile_load($a, "", 0, get_contact_details_by_url($ret["url"]));
144
145         if ($gcontact_id <> 0) {
146                 $o .= replace_macros(get_markup_template('section_title.tpl'),
147                                                 array('$title' => t('Status Messages and Posts')
148                 ));
149
150                 // Show last public posts
151                 $o .= posts_from_contact_url($a, $ret["url"]);
152         }
153
154         return $o;
155 }
156
157 function follow_post(App $a) {
158
159         if (! local_user()) {
160                 notice( t('Permission denied.') . EOL);
161                 goaway($_SESSION['return_url']);
162                 // NOTREACHED
163         }
164
165         if ($_REQUEST['cancel']) {
166                 goaway($_SESSION['return_url']);
167         }
168
169         $uid = local_user();
170         $url = notags(trim($_REQUEST['url']));
171         $return_url = $_SESSION['return_url'];
172
173         // Makes the connection request for friendica contacts easier
174         // This is just a precaution if maybe this page is called somewhere directly via POST
175         $_SESSION["fastlane"] = $url;
176
177         $result = new_contact($uid,$url,true);
178
179         if ($result['success'] == false) {
180                 if ($result['message']) {
181                         notice($result['message']);
182                 }
183                 goaway($return_url);
184         } elseif ($result['cid']) {
185                 goaway(App::get_baseurl().'/contacts/'.$result['cid']);
186         }
187
188         info( t('Contact added').EOL);
189
190         if (strstr($return_url,'contacts')) {
191                 goaway(App::get_baseurl().'/contacts/'.$contact_id);
192         }
193
194         goaway($return_url);
195         // NOTREACHED
196 }