]> git.mxchange.org Git - friendica.git/blob - mod/follow.php
provide a way to disable mailbox integration
[friendica.git] / mod / follow.php
1 <?php
2
3 require_once('Scrape.php');
4
5 function follow_post(&$a) {
6
7         if(! local_user()) {
8                 notice( t('Permission denied.') . EOL);
9                 goaway($_SESSION['return_url']);
10                 // NOTREACHED
11         }
12
13         $url = $orig_url = notags(trim($_POST['url']));
14
15         $ret = probe_url($url);
16
17
18         if($ret['network'] === NETWORK_DFRN) {
19                 if(strlen($a->path))
20                         $myaddr = bin2hex($a->get_baseurl() . '/profile/' . $a->user['nickname']);
21                 else
22                         $myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname());
23  
24                 goaway($ret['request'] . "&addr=$myaddr");
25                 
26                 // NOTREACHED
27         }
28
29         // do we have enough information?
30         
31         if(! ((x($ret,'name')) && (x($ret,'poll')) && ((x($ret,'url')) || (x($ret,'addr'))))) {
32                 notice( t('The profile address specified does not provide adequate information.') . EOL);
33                 goaway($_SESSION['return_url']);
34         }
35
36
37         if(! $ret['notify']) {
38                 notice( t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . EOL);
39         }
40
41         $writeable = ((($ret['network'] === NETWORK_OSTATUS) && ($ret['notify'])) ? 1 : 0);
42         if($ret['network'] === NETWORK_MAIL) {
43                 $writeable = 1;
44                 
45         }
46         // check if we already have a contact
47         // the poll url is more reliable than the profile url, as we may have
48         // indirect links or webfinger links
49
50         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `poll` = '%s' LIMIT 1",
51                 intval(local_user()),
52                 dbesc($ret['poll'])
53         );                      
54
55         if(count($r)) {
56                 // update contact
57                 if($r[0]['rel'] == REL_VIP) {
58                         q("UPDATE `contact` SET `rel` = %d , `readonly` = 0 WHERE `id` = %d AND `uid` = %d LIMIT 1",
59                                 intval(REL_BUD),
60                                 intval($r[0]['id']),
61                                 intval(local_user())
62                         );
63                 }
64         }
65         else {
66                 // create contact record 
67                 $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `addr`, `alias`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`, `priority`,
68                         `writable`, `blocked`, `readonly`, `pending` )
69                         VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ",
70                         intval(local_user()),
71                         dbesc(datetime_convert()),
72                         dbesc($ret['url']),
73                         dbesc($ret['addr']),
74                         dbesc($ret['alias']),
75                         dbesc($ret['notify']),
76                         dbesc($ret['poll']),
77                         dbesc($ret['name']),
78                         dbesc($ret['nick']),
79                         dbesc($ret['photo']),
80                         dbesc($ret['network']),
81                         intval(($ret['network'] === NETWORK_MAIL) ? REL_BUD : REL_FAN),
82                         intval($ret['priority']),
83                         intval($writeable)
84                 );
85         }
86
87         $r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
88                 dbesc($ret['url']),
89                 intval(local_user())
90         );
91
92         if(! count($r)) {
93                 notice( t('Unable to retrieve contact information.') . EOL);
94                 goaway($_SESSION['return_url']);
95                 // NOTREACHED
96         }
97
98         $contact = $r[0];
99         $contact_id  = $r[0]['id'];
100
101         require_once("Photo.php");
102
103         $photos = import_profile_photo($ret['photo'],local_user(),$contact_id);
104
105         $r = q("UPDATE `contact` SET `photo` = '%s', 
106                         `thumb` = '%s',
107                         `micro` = '%s', 
108                         `name-date` = '%s', 
109                         `uri-date` = '%s', 
110                         `avatar-date` = '%s'
111                         WHERE `id` = %d LIMIT 1
112                 ",
113                         dbesc($photos[0]),
114                         dbesc($photos[1]),
115                         dbesc($photos[2]),
116                         dbesc(datetime_convert()),
117                         dbesc(datetime_convert()),
118                         dbesc(datetime_convert()),
119                         intval($contact_id)
120                 );                      
121
122
123         // pull feed and consume it, which should subscribe to the hub.
124
125         proc_run('php',"include/poller.php","$contact_id");
126
127         // create a follow slap
128
129         $tpl = load_view_file('view/follow_slap.tpl');
130         $slap = replace_macros($tpl, array(
131                 '$name' => $a->user['username'],
132                 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
133                 '$photo' => $a->contact['photo'],
134                 '$thumb' => $a->contact['thumb'],
135                 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
136                 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':follow:' . random_string(),
137                 '$title' => '',
138                 '$type' => 'text',
139                 '$content' => t('following'),
140                 '$nick' => $a->user['nickname'],
141                 '$verb' => ACTIVITY_FOLLOW,
142                 '$ostat_follow' => ''
143         ));
144
145         $r = q("SELECT `contact`.*, `user`.* FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid` 
146                         WHERE `user`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1",
147                         intval(local_user())
148         );
149
150
151         if((count($r)) && (x($contact,'notify')) && (strlen($contact['notify']))) {
152                 require_once('include/salmon.php');
153                 slapper($r[0],$contact['notify'],$slap);
154         }
155
156         goaway($_SESSION['return_url']);
157         // NOTREACHED
158 }