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