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