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