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