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 if(! allowed_url($url)) {
16 notice( t('Disallowed profile URL.') . EOL);
17 goaway($_SESSION['return_url']);
22 $ret = probe_url($url);
25 if($ret['network'] === NETWORK_DFRN) {
27 $myaddr = bin2hex($a->get_baseurl() . '/profile/' . $a->user['nickname']);
29 $myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname());
31 goaway($ret['request'] . "&addr=$myaddr");
36 // do we have enough information?
38 if(! ((x($ret,'name')) && (x($ret,'poll')) && ((x($ret,'url')) || (x($ret,'addr'))))) {
39 notice( t('The profile address specified does not provide adequate information.') . EOL);
40 goaway($_SESSION['return_url']);
44 if(! $ret['notify']) {
45 notice( t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . EOL);
48 $writeable = ((($ret['network'] === NETWORK_OSTATUS) && ($ret['notify'])) ? 1 : 0);
49 if($ret['network'] === NETWORK_MAIL) {
53 // check if we already have a contact
54 // the poll url is more reliable than the profile url, as we may have
55 // indirect links or webfinger links
57 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `poll` = '%s' LIMIT 1",
64 if($r[0]['rel'] == REL_VIP) {
65 q("UPDATE `contact` SET `rel` = %d , `readonly` = 0 WHERE `id` = %d AND `uid` = %d LIMIT 1",
73 // create contact record
74 $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `addr`, `alias`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`, `priority`,
75 `writable`, `blocked`, `readonly`, `pending` )
76 VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ",
78 dbesc(datetime_convert()),
82 dbesc($ret['notify']),
87 dbesc($ret['network']),
88 intval(($ret['network'] === NETWORK_MAIL) ? REL_BUD : REL_FAN),
89 intval($ret['priority']),
94 $r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
100 notice( t('Unable to retrieve contact information.') . EOL);
101 goaway($_SESSION['return_url']);
106 $contact_id = $r[0]['id'];
108 require_once("Photo.php");
110 $photos = import_profile_photo($ret['photo'],local_user(),$contact_id);
112 $r = q("UPDATE `contact` SET `photo` = '%s',
118 WHERE `id` = %d LIMIT 1
123 dbesc(datetime_convert()),
124 dbesc(datetime_convert()),
125 dbesc(datetime_convert()),
130 // pull feed and consume it, which should subscribe to the hub.
132 proc_run('php',"include/poller.php","$contact_id");
134 // create a follow slap
136 $tpl = load_view_file('view/follow_slap.tpl');
137 $slap = replace_macros($tpl, array(
138 '$name' => $a->user['username'],
139 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
140 '$photo' => $a->contact['photo'],
141 '$thumb' => $a->contact['thumb'],
142 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
143 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':follow:' . random_string(),
146 '$content' => t('following'),
147 '$nick' => $a->user['nickname'],
148 '$verb' => ACTIVITY_FOLLOW,
149 '$ostat_follow' => ''
152 $r = q("SELECT `contact`.*, `user`.* FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
153 WHERE `user`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1",
158 if((count($r)) && (x($contact,'notify')) && (strlen($contact['notify']))) {
159 require_once('include/salmon.php');
160 slapper($r[0],$contact['notify'],$slap);
163 goaway($_SESSION['return_url']);