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