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