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 $ret = probe_url($url);
18 if($ret['network'] === NETWORK_DFRN) {
20 $myaddr = bin2hex($a->get_baseurl() . '/profile/' . $a->user['nickname']);
22 $myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname());
24 goaway($ret['request'] . "&addr=$myaddr");
29 // do we have enough information?
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']);
37 if(! $ret['notify']) {
38 notice( t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . EOL);
41 $writeable = ((($ret['network'] === NETWORK_OSTATUS) && ($ret['notify'])) ? 1 : 0);
42 if($ret['network'] === NETWORK_MAIL) {
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
50 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `poll` = '%s' LIMIT 1",
57 if($r[0]['rel'] == REL_VIP) {
58 q("UPDATE `contact` SET `rel` = %d , `readonly` = 0 WHERE `id` = %d AND `uid` = %d LIMIT 1",
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 ) ",
71 dbesc(datetime_convert()),
75 dbesc($ret['notify']),
80 dbesc($ret['network']),
81 intval(($ret['network'] === NETWORK_MAIL) ? REL_BUD : REL_FAN),
82 intval($ret['priority']),
87 $r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
93 notice( t('Unable to retrieve contact information.') . EOL);
94 goaway($_SESSION['return_url']);
99 $contact_id = $r[0]['id'];
101 require_once("Photo.php");
103 $photos = import_profile_photo($ret['photo'],local_user(),$contact_id);
105 $r = q("UPDATE `contact` SET `photo` = '%s',
111 WHERE `id` = %d LIMIT 1
116 dbesc(datetime_convert()),
117 dbesc(datetime_convert()),
118 dbesc(datetime_convert()),
123 // pull feed and consume it, which should subscribe to the hub.
125 proc_run('php',"include/poller.php","$contact_id");
127 // create a follow slap
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(),
139 '$content' => t('following'),
140 '$nick' => $a->user['nickname'],
141 '$verb' => ACTIVITY_FOLLOW,
142 '$ostat_follow' => ''
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",
151 if((count($r)) && (x($contact,'notify')) && (strlen($contact['notify']))) {
152 require_once('include/salmon.php');
153 slapper($r[0],$contact['notify'],$slap);
156 goaway($_SESSION['return_url']);