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