3 require_once('Scrape.php');
5 function follow_post(&$a) {
8 notice( t('Permission denied.') . EOL);
9 goaway($_SESSION['return_url']);
13 $url = notags(trim($_POST['url']));
18 foreach($links as $link) {
19 if($link['@attributes']['rel'] === NAMESPACE_DFRN)
20 $dfrn = $link['@attributes']['href'];
21 if($link['@attributes']['rel'] === 'salmon')
22 $notify = $link['@attributes']['href'];
23 if($link['@attributes']['rel'] === NAMESPACE_FEED)
24 $poll = $link['@attributes']['href'];
25 if($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard')
26 $hcard = $link['@attributes']['href'];
27 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
28 $profile = $link['@attributes']['href'];
34 // If we find a DFRN site, send our subscriber to the other person's
35 // dfrn_request page and all the other details will get sorted.
38 $ret = scrape_dfrn($dfrn);
39 if(is_array($ret) && x($ret,'dfrn-request')) {
41 $myaddr = urlencode($a->get_baseurl() . '/profile/' . $a->user['nickname']);
43 $myaddr = urlencode($a->user['nickname'] . '@' . $a->get_hostname());
45 goaway($ret['dfrn-request'] . "&address=$myaddr");
52 $vcard = scrape_vcard($hcard);
58 // do we have enough information?
62 $vcard['fn'] = $vcard['nick'];
64 if(! ((x($vcard['fn'])) && ($poll) && ($notify) && ($profile))) {
65 notice( t('The profile address specified does not provide adequate information.') . EOL);
66 goaway($_SESSION['return_url']);
69 if(! x($vcard,'photo'))
70 $vcard['photo'] = $a->get_baseurl() . '/images/default-profile.jpg' ;
72 // check if we already have a contact
73 // the poll url is more reliable than the profile url, as we may have
74 // indirect links or webfinger links
76 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `poll` = '%s' LIMIT 1",
82 if($r[0]['rel'] == REL_VIP) {
83 q("UPDATE `contact` SET `rel` = %d , `readonly` = 0 WHERE `id` = %d AND `uid` = %d LIMIT 1",
91 // create contact record
92 $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`,
93 `blocked`, `readonly`, `pending` )
94 VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, 0, 0 ) ",
96 dbesc(datetime_convert()),
101 dbesc($vcard['nick']),
102 dbesc($vcard['photo']),
107 $r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
112 notice( t('Unable to retrieve contact information.') . EOL);
113 goaway($_SESSION['return_url']);
118 $contact_id = $r[0]['id'];
120 require_once("Photo.php");
122 $photos = import_profile_photo($vcard['photo'],local_user(),$contact_id);
124 $r = q("UPDATE `contact` SET `photo` = '%s',
129 WHERE `id` = %d LIMIT 1
133 dbesc(datetime_convert()),
134 dbesc(datetime_convert()),
135 dbesc(datetime_convert()),
140 // pull feed and consume it, which should subscribe to the hub.
143 // create a follow slap
145 $tpl = load_view_file('view/follow_slap.tpl');
146 $slap = replace_macros($tpl, array(
147 '$name' => $a->user['username'],
148 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
149 '$photo' => $a->contact['photo'],
150 '$thumb' => $a->contact['thumb'],
151 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
152 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':follow:' . random_string(),
155 '$content' => t('following'),
156 '$nick' => $a->user['nickname'],
157 '$verb' => ACTIVITY_FOLLOW
160 $r = q("SELECT `contact`.*, `user`.* FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
161 WHERE `user`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1",
165 require_once('include/salmon.php');
166 slapper($r[0],$contact,$slap);
168 goaway($_SESSION['return_url']);