]> git.mxchange.org Git - friendica.git/blob - mod/follow.php
new api for notifications
[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.php');
6 require_once('include/contact_selectors.php');
7
8 if(! function_exists('follow_content')) {
9 function follow_content(&$a) {
10
11         if(! local_user()) {
12                 notice( t('Permission denied.') . EOL);
13                 goaway($_SESSION['return_url']);
14                 // NOTREACHED
15         }
16
17         $uid = local_user();
18         $url = notags(trim($_REQUEST['url']));
19
20         $submit = t('Submit Request');
21
22         // There is a current issue. It seems as if you can't start following a Friendica that is following you
23         // With Diaspora this works - but Friendica is special, it seems ...
24         $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND
25                 (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
26                 `network` != '%s' LIMIT 1",
27                 intval(local_user()), dbesc(CONTACT_IS_FOLLOWER), dbesc(NETWORK_DFRN), dbesc(normalise_link($url)),
28                 dbesc(normalise_link($url)), dbesc($url), dbesc(NETWORK_STATUSNET));
29
30         if ($r) {
31                 notice(t('You already added this contact.').EOL);
32                 $submit = "";
33                 //goaway($_SESSION['return_url']);
34                 // NOTREACHED
35         }
36
37         $ret = probe_url($url);
38
39         if (($ret["network"] == NETWORK_DIASPORA) AND !get_config('system','diaspora_enabled')) {
40                 notice( t("Diaspora support isn't enabled. Contact can't be added.") . EOL);
41                 $submit = "";
42                 //goaway($_SESSION['return_url']);
43                 // NOTREACHED
44         }
45
46         if (($ret["network"] == NETWORK_OSTATUS) AND get_config('system','ostatus_disabled')) {
47                 notice( t("OStatus support is disabled. Contact can't be added.") . EOL);
48                 $submit = "";
49                 //goaway($_SESSION['return_url']);
50                 // NOTREACHED
51         }
52
53         if ($ret["network"] == NETWORK_PHANTOM) {
54                 notice( t("The network type couldn't be detected. Contact can't be added.") . EOL);
55                 $submit = "";
56                 //goaway($_SESSION['return_url']);
57                 // NOTREACHED
58         }
59
60         if ($ret["network"] == NETWORK_MAIL)
61                 $ret["url"] = $ret["addr"];
62
63         if($ret['network'] === NETWORK_DFRN) {
64                 $request = $ret["request"];
65                 $tpl = get_markup_template('dfrn_request.tpl');
66         } else {
67                 $request = $a->get_baseurl()."/follow";
68                 $tpl = get_markup_template('auto_request.tpl');
69         }
70
71         $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
72
73         if (!$r) {
74                 notice( t('Permission denied.') . EOL);
75                 goaway($_SESSION['return_url']);
76                 // NOTREACHED
77         }
78
79         $myaddr = $r[0]["url"];
80         $gcontact_id = 0;
81
82         // Makes the connection request for friendica contacts easier
83         $_SESSION["fastlane"] = $ret["url"];
84
85         $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
86                 normalise_link($ret["url"]));
87
88         if (!$r)
89                 $r = array(array("location" => "", "about" => "", "keywords" => ""));
90         else
91                 $gcontact_id = $r[0]["id"];
92
93         if($ret['network'] === NETWORK_DIASPORA) {
94                 $r[0]["location"] = "";
95                 $r[0]["about"] = "";
96         }
97
98         $header = $ret["name"];
99
100         if ($ret["addr"] != "")
101                 $header .= " <".$ret["addr"].">";
102
103         //$header .= " (".network_to_name($ret['network'], $ret['url']).")";
104         $header = t("Connect/Follow");
105
106         $o  = replace_macros($tpl,array(
107                         '$header' => htmlentities($header),
108                         //'$photo' => proxy_url($ret["photo"], false, PROXY_SIZE_SMALL),
109                         '$desc' => "",
110                         '$pls_answer' => t('Please answer the following:'),
111                         '$does_know_you' => array('knowyou', sprintf(t('Does %s know you?'),$ret["name"]), false, '', array(t('No'),t('Yes'))),
112                         '$add_note' => t('Add a personal note:'),
113                         '$page_desc' => "",
114                         '$friendica' => "",
115                         '$statusnet' => "",
116                         '$diaspora' => "",
117                         '$diasnote' => "",
118                         '$your_address' => t('Your Identity Address:'),
119                         '$invite_desc' => "",
120                         '$emailnet' => "",
121                         '$submit' => $submit,
122                         '$cancel' => t('Cancel'),
123                         '$nickname' => "",
124                         '$name' => $ret["name"],
125                         '$url' => $ret["url"],
126                         '$zrl' => zrl($ret["url"]),
127                         '$url_label' => t("Profile URL"),
128                         '$myaddr' => $myaddr,
129                         '$request' => $request,
130                         /*'$location' => bbcode($r[0]["location"]),
131                         '$location_label' => t("Location:"),
132                         '$about' => bbcode($r[0]["about"], false, false),
133                         '$about_label' => t("About:"), */
134                         '$keywords' => $r[0]["keywords"],
135                         '$keywords_label' => t("Tags:")
136         ));
137
138         $a->page['aside'] = "";
139         profile_load($a, "", 0, get_contact_details_by_url($ret["url"]));
140
141         // Show last public posts
142         if ($gcontact_id <> 0) {
143                 $o .= replace_macros(get_markup_template('section_title.tpl'),
144                                                 array('$title' => t('Status Messages and Posts')
145                 ));
146
147                 $o .= posts_from_gcontact($a, $gcontact_id);
148         }
149
150         return $o;
151 }
152 }
153
154 if(! function_exists('follow_post')) {
155 function follow_post(&$a) {
156
157         if(! local_user()) {
158                 notice( t('Permission denied.') . EOL);
159                 goaway($_SESSION['return_url']);
160                 // NOTREACHED
161         }
162
163         if ($_REQUEST['cancel'])
164                 goaway($_SESSION['return_url']);
165
166         $uid = local_user();
167         $url = notags(trim($_REQUEST['url']));
168         $return_url = $_SESSION['return_url'];
169
170         // Makes the connection request for friendica contacts easier
171         // This is just a precaution if maybe this page is called somewhere directly via POST
172         $_SESSION["fastlane"] = $url;
173
174         $result = new_contact($uid,$url,true);
175
176         if($result['success'] == false) {
177                 if($result['message'])
178                         notice($result['message']);
179                 goaway($return_url);
180         } elseif ($result['cid'])
181                 goaway($a->get_baseurl().'/contacts/'.$result['cid']);
182
183         info( t('Contact added').EOL);
184
185         if(strstr($return_url,'contacts'))
186                 goaway($a->get_baseurl().'/contacts/'.$contact_id);
187
188         goaway($return_url);
189         // NOTREACHED
190 }
191 }