]> git.mxchange.org Git - friendica.git/blob - mod/follow.php
Issue 1913: Report invalid feed
[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_PHANTOM) {
35                 notice( t("The network type couldn't be detected. Contact can't be added.") . EOL);
36                 goaway($_SESSION['return_url']);
37                 // NOTREACHED
38         }
39
40         if ($ret["network"] == NETWORK_MAIL)
41                 $ret["url"] = $ret["addr"];
42
43         if($ret['network'] === NETWORK_DFRN) {
44                 $request = $ret["request"];
45                 $tpl = get_markup_template('dfrn_request.tpl');
46         } else {
47                 $request = $a->get_baseurl()."/follow";
48                 $tpl = get_markup_template('auto_request.tpl');
49         }
50
51         $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
52
53         if (!$r) {
54                 notice( t('Permission denied.') . EOL);
55                 goaway($_SESSION['return_url']);
56                 // NOTREACHED
57         }
58
59         $myaddr = $r[0]["url"];
60
61         // Makes the connection request for friendica contacts easier
62         $_SESSION["fastlane"] = $ret["url"];
63
64         $header = $ret["name"];
65
66         if ($ret["addr"] != "")
67                 $header .= " <".$ret["addr"].">";
68
69         $header .= " (".network_to_name($ret['network']).")";
70
71         $o  = replace_macros($tpl,array(
72                         '$header' => htmlentities($header),
73                         '$photo' => $ret["photo"],
74                         '$desc' => "",
75                         '$pls_answer' => t('Please answer the following:'),
76                         '$does_know_you' => array('knowyou', sprintf(t('Does %s know you?'),$ret["name"]), false, '', array(t('No'),t('Yes'))),
77                         '$add_note' => t('Add a personal note:'),
78                         '$page_desc' => "",
79                         '$friendica' => "",
80                         '$statusnet' => "",
81                         '$diaspora' => "",
82                         '$diasnote' => "",
83                         '$your_address' => t('Your Identity Address:'),
84                         '$invite_desc' => "",
85                         '$emailnet' => "",
86                         '$submit' => t('Submit Request'),
87                         '$cancel' => t('Cancel'),
88                         '$nickname' => "",
89                         '$name' => $ret["name"],
90                         '$url' => $ret["url"],
91                         '$myaddr' => $myaddr,
92                         '$request' => $request
93         ));
94         return $o;
95 }
96
97 function follow_post(&$a) {
98
99         if(! local_user()) {
100                 notice( t('Permission denied.') . EOL);
101                 goaway($_SESSION['return_url']);
102                 // NOTREACHED
103         }
104
105         if ($_REQUEST['cancel'])
106                 goaway($_SESSION['return_url']);
107
108         $uid = local_user();
109         $url = notags(trim($_REQUEST['url']));
110         $return_url = $_SESSION['return_url'];
111
112         // Makes the connection request for friendica contacts easier
113         // This is just a precaution if maybe this page is called somewhere directly via POST
114         $_SESSION["fastlane"] = $url;
115
116         $result = new_contact($uid,$url,true);
117
118         if($result['success'] == false) {
119                 if($result['message'])
120                         notice($result['message']);
121                 goaway($return_url);
122         } elseif ($result['cid'])
123                 goaway($a->get_baseurl().'/contacts/'.$result['cid']);
124
125         info( t('Contact added').EOL);
126
127         if(strstr($return_url,'contacts'))
128                 goaway($a->get_baseurl().'/contacts/'.$contact_id);
129
130         goaway($return_url);
131         // NOTREACHED
132 }