3 require_once('Scrape.php');
5 function follow_post(&$a) {
8 notice( t('Permission denied.') . EOL);
9 goaway($_SESSION['return_url']);
13 $url = $orig_url = notags(trim($_POST['url']));
15 // remove ajax junk, e.g. Twitter
17 $url = str_replace('/#!/','/',$url);
19 if(! allowed_url($url)) {
20 notice( t('Disallowed profile URL.') . EOL);
21 goaway($_SESSION['return_url']);
25 $ret = probe_url($url);
27 if($ret['network'] === NETWORK_DFRN) {
29 $myaddr = bin2hex($a->get_baseurl() . '/profile/' . $a->user['nickname']);
31 $myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname());
33 goaway($ret['request'] . "&addr=$myaddr");
37 elseif(get_config('system','strict_privacy')) {
38 unset($ret['notify']);
41 // do we have enough information?
43 if(! ((x($ret,'name')) && (x($ret,'poll')) && ((x($ret,'url')) || (x($ret,'addr'))))) {
44 notice( t('The profile address specified does not provide adequate information.') . EOL);
46 notice( t('No compatible communication protocols or feeds were discovered.') . EOL);
48 notice( t('An author or name was not found.') . EOL);
50 notice( t('No browser URL could be matched to this address.') . EOL);
51 if(strpos($url,'@') !== false)
52 notice('Unable to match @-style Identity Address with a known protocol or email contact');
53 goaway($_SESSION['return_url']);
57 if(! $ret['notify']) {
58 notice( t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . EOL);
61 $writeable = ((($ret['network'] === NETWORK_OSTATUS) && ($ret['notify'])) ? 1 : 0);
62 if($ret['network'] === NETWORK_MAIL) {
66 // check if we already have a contact
67 // the poll url is more reliable than the profile url, as we may have
68 // indirect links or webfinger links
70 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `poll` = '%s' LIMIT 1",
77 if($r[0]['rel'] == REL_VIP) {
78 q("UPDATE `contact` SET `rel` = %d , `readonly` = 0 WHERE `id` = %d AND `uid` = %d LIMIT 1",
86 // create contact record
87 $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `addr`, `alias`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`, `priority`,
88 `writable`, `blocked`, `readonly`, `pending` )
89 VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ",
91 dbesc(datetime_convert()),
95 dbesc($ret['notify']),
100 dbesc($ret['network']),
101 intval(($ret['network'] === NETWORK_MAIL) ? REL_BUD : REL_FAN),
102 intval($ret['priority']),
107 $r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
113 notice( t('Unable to retrieve contact information.') . EOL);
114 goaway($_SESSION['return_url']);
119 $contact_id = $r[0]['id'];
121 require_once("Photo.php");
123 $photos = import_profile_photo($ret['photo'],local_user(),$contact_id);
125 $r = q("UPDATE `contact` SET `photo` = '%s',
131 WHERE `id` = %d LIMIT 1
136 dbesc(datetime_convert()),
137 dbesc(datetime_convert()),
138 dbesc(datetime_convert()),
143 // pull feed and consume it, which should subscribe to the hub.
145 proc_run('php',"include/poller.php","$contact_id");
147 // create a follow slap
149 $tpl = get_markup_template('follow_slap.tpl');
150 $slap = replace_macros($tpl, array(
151 '$name' => $a->user['username'],
152 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
153 '$photo' => $a->contact['photo'],
154 '$thumb' => $a->contact['thumb'],
155 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
156 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':follow:' . random_string(),
159 '$content' => t('following'),
160 '$nick' => $a->user['nickname'],
161 '$verb' => ACTIVITY_FOLLOW,
162 '$ostat_follow' => ''
165 $r = q("SELECT `contact`.*, `user`.* FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
166 WHERE `user`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1",
171 if((count($r)) && (x($contact,'notify')) && (strlen($contact['notify']))) {
172 require_once('include/salmon.php');
173 slapper($r[0],$contact['notify'],$slap);
176 goaway($_SESSION['return_url']);