]> git.mxchange.org Git - friendica.git/blob - mod/follow.php
Merge pull request #1897 from annando/3.4.2
[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         // There is a current issue. It seems as if you can't start following a Friendica that is following you
19         // With Diaspora this works - but Friendica is special, it seems ...
20         $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND
21                 (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
22                 `network` != '%s' LIMIT 1",
23                 intval(local_user()), dbesc(CONTACT_IS_FOLLOWER), dbesc(NETWORK_DFRN), dbesc(normalise_link($url)),
24                 dbesc(normalise_link($url)), dbesc($url), dbesc(NETWORK_STATUSNET));
25
26         if ($r) {
27                 notice(t('You already added this contact.').EOL);
28                 goaway($_SESSION['return_url']);
29                 // NOTREACHED
30         }
31
32         $ret = probe_url($url);
33
34         if ($ret["network"] == NETWORK_MAIL)
35                 $ret["url"] = $ret["addr"];
36
37         if($ret['network'] === NETWORK_DFRN) {
38                 $request = $ret["request"];
39                 $tpl = get_markup_template('dfrn_request.tpl');
40         } else {
41                 $request = $a->get_baseurl()."/follow";
42                 $tpl = get_markup_template('auto_request.tpl');
43         }
44
45         $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
46
47         if (!$r) {
48                 notice( t('Permission denied.') . EOL);
49                 goaway($_SESSION['return_url']);
50                 // NOTREACHED
51         }
52
53         $myaddr = $r[0]["url"];
54
55         // Makes the connection request for friendica contacts easier
56         $_SESSION["fastlane"] = $ret["url"];
57
58         $header = $ret["name"];
59
60         if ($ret["addr"] != "")
61                 $header .= " <".$ret["addr"].">";
62
63         $header .= " (".network_to_name($ret['network']).")";
64
65         $o  = replace_macros($tpl,array(
66                         '$header' => htmlentities($header),
67                         '$photo' => $ret["photo"],
68                         '$desc' => "",
69                         '$pls_answer' => t('Please answer the following:'),
70                         '$does_know_you' => array('knowyou', sprintf(t('Does %s know you?'),$ret["name"]), false, '', array(t('No'),t('Yes'))),
71                         '$add_note' => t('Add a personal note:'),
72                         '$page_desc' => "",
73                         '$friendica' => "",
74                         '$statusnet' => "",
75                         '$diaspora' => "",
76                         '$diasnote' => "",
77                         '$your_address' => t('Your Identity Address:'),
78                         '$invite_desc' => "",
79                         '$emailnet' => "",
80                         '$submit' => t('Submit Request'),
81                         '$cancel' => t('Cancel'),
82                         '$nickname' => "",
83                         '$name' => $ret["name"],
84                         '$url' => $ret["url"],
85                         '$myaddr' => $myaddr,
86                         '$request' => $request
87         ));
88         return $o;
89 }
90
91 function follow_post(&$a) {
92
93         if(! local_user()) {
94                 notice( t('Permission denied.') . EOL);
95                 goaway($_SESSION['return_url']);
96                 // NOTREACHED
97         }
98
99         if ($_REQUEST['cancel'])
100                 goaway($_SESSION['return_url']);
101
102         $uid = local_user();
103         $url = notags(trim($_REQUEST['url']));
104         $return_url = $_SESSION['return_url'];
105
106         // Makes the connection request for friendica contacts easier
107         // This is just a precaution if maybe this page is called somewhere directly via POST
108         $_SESSION["fastlane"] = $url;
109
110         $result = new_contact($uid,$url,true);
111
112         if($result['success'] == false) {
113                 if($result['message'])
114                         notice($result['message']);
115                 goaway($return_url);
116         } elseif ($result['cid'])
117                 goaway($a->get_baseurl().'/contacts/'.$result['cid']);
118
119         info( t('Contact added').EOL);
120
121         if(strstr($return_url,'contacts'))
122                 goaway($a->get_baseurl().'/contacts/'.$contact_id);
123
124         goaway($return_url);
125         // NOTREACHED
126 }