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