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