]> git.mxchange.org Git - friendica.git/blob - mod/follow.php
Merge remote-tracking branch 'upstream/develop' into 1504-contact-update
[friendica.git] / mod / follow.php
1 <?php
2
3 require_once('include/Scrape.php');
4 require_once('include/follow.php');
5
6 function follow_content(&$a) {
7
8         if(! local_user()) {
9                 notice( t('Permission denied.') . EOL);
10                 goaway($_SESSION['return_url']);
11                 // NOTREACHED
12         }
13
14         $uid = local_user();
15         $url = notags(trim($_REQUEST['url']));
16
17         $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') LIMIT 1",
18                 intval(local_user()), dbesc(normalise_link($url)), dbesc(normalise_link($url)), dbesc($url));
19
20         if ($r) {
21                 notice(t('You already added this contact.').EOL);
22                 goaway($_SESSION['return_url']);
23                 // NOTREACHED
24         }
25
26         $ret = probe_url($url);
27
28         if($ret['network'] === NETWORK_DFRN) {
29                 $request = $ret["request"];
30                 $tpl = get_markup_template('dfrn_request.tpl');
31         } else {
32                 $request = $a->get_baseurl()."/follow";
33                 $tpl = get_markup_template('auto_request.tpl');
34         }
35
36         $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
37
38         if (!$r) {
39                 notice( t('Permission denied.') . EOL);
40                 goaway($_SESSION['return_url']);
41                 // NOTREACHED
42         }
43
44         $myaddr = $r[0]["url"];
45
46         // Makes the connection request for friendica contacts easier
47         $_SESSION["fastlane"] = $ret["url"];
48
49         $o  = replace_macros($tpl,array(
50                         '$header' => $ret["name"]." (".$ret["addr"].")",
51                         '$photo' => $ret["photo"],
52                         '$desc' => "",
53                         '$pls_answer' => t('Please answer the following:'),
54                         '$does_know_you' => array('knowyou', sprintf(t('Does %s know you?'),$ret["name"]), false, '', array(t('No'),t('Yes'))),
55                         '$add_note' => t('Add a personal note:'),
56                         '$page_desc' => "",
57                         '$friendica' => "",
58                         '$statusnet' => "",
59                         '$diaspora' => "",
60                         '$diasnote' => "",
61                         '$your_address' => t('Your Identity Address:'),
62                         '$invite_desc' => "",
63                         '$emailnet' => "",
64                         '$submit' => t('Submit Request'),
65                         '$cancel' => t('Cancel'),
66                         '$nickname' => "",
67                         '$name' => $ret["name"],
68                         '$url' => $ret["url"],
69                         '$myaddr' => $myaddr,
70                         '$request' => $request
71         ));
72         return $o;
73 }
74
75 function follow_post(&$a) {
76
77         if(! local_user()) {
78                 notice( t('Permission denied.') . EOL);
79                 goaway($_SESSION['return_url']);
80                 // NOTREACHED
81         }
82
83         if ($_REQUEST['cancel'])
84                 goaway($_SESSION['return_url']);
85
86         $uid = local_user();
87         $url = notags(trim($_REQUEST['url']));
88         $return_url = $_SESSION['return_url'];
89
90         // Makes the connection request for friendica contacts easier
91         // This is just a precaution if maybe this page is called somewhere directly via POST
92         $_SESSION["fastlane"] = $url;
93
94         $result = new_contact($uid,$url,true);
95
96         if($result['success'] == false) {
97                 if($result['message'])
98                         notice($result['message']);
99                 goaway($return_url);
100         } elseif ($result['cid'])
101                 goaway($a->get_baseurl().'/contacts/'.$result['cid']);
102
103         info( t('Contact added').EOL);
104
105         if(strstr($return_url,'contacts'))
106                 goaway($a->get_baseurl().'/contacts/'.$contact_id);
107
108         goaway($return_url);
109         // NOTREACHED
110 }