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);
54 // Google doesn't use absolute url in profile photos
56 if((x($vcard,'photo')) && substr($vcard['photo'],0,1) == '/') {
57 $h = parse_url($hcard);
59 $vcard['photo'] = $h['scheme'] . '://' . $h['host'] . $vcard['photo'];
66 // do we have enough information?
70 $vcard['fn'] = $vcard['nick'];
72 logger('follow: poll=' . $poll . ' notify=' . $notify . ' profile=' . $profile . ' vcard=' . print_r($vcard,true));
74 if(! ((x($vcard['fn'])) && ($poll) && ($profile))) {
75 notice( t('The profile address specified does not provide adequate information.') . EOL);
76 goaway($_SESSION['return_url']);
80 notice( t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . EOL);
83 if(! x($vcard,'photo'))
84 $vcard['photo'] = $a->get_baseurl() . '/images/default-profile.jpg' ;
86 // check if we already have a contact
87 // the poll url is more reliable than the profile url, as we may have
88 // indirect links or webfinger links
90 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `poll` = '%s' LIMIT 1",
97 if($r[0]['rel'] == REL_VIP) {
98 q("UPDATE `contact` SET `rel` = %d , `readonly` = 0 WHERE `id` = %d AND `uid` = %d LIMIT 1",
106 // create contact record
107 $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`,
108 `blocked`, `readonly`, `pending` )
109 VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, 0, 0 ) ",
110 intval(local_user()),
111 dbesc(datetime_convert()),
116 dbesc($vcard['nick']),
117 dbesc($vcard['photo']),
123 $r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
129 notice( t('Unable to retrieve contact information.') . EOL);
130 goaway($_SESSION['return_url']);
135 $contact_id = $r[0]['id'];
137 require_once("Photo.php");
139 $photos = import_profile_photo($vcard['photo'],local_user(),$contact_id);
141 $r = q("UPDATE `contact` SET `photo` = '%s',
147 WHERE `id` = %d LIMIT 1
152 dbesc(datetime_convert()),
153 dbesc(datetime_convert()),
154 dbesc(datetime_convert()),
159 // pull feed and consume it, which should subscribe to the hub.
162 // create a follow slap
164 $tpl = load_view_file('view/follow_slap.tpl');
165 $slap = replace_macros($tpl, array(
166 '$name' => $a->user['username'],
167 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
168 '$photo' => $a->contact['photo'],
169 '$thumb' => $a->contact['thumb'],
170 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
171 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':follow:' . random_string(),
174 '$content' => t('following'),
175 '$nick' => $a->user['nickname'],
176 '$verb' => ACTIVITY_FOLLOW
179 $r = q("SELECT `contact`.*, `user`.* FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
180 WHERE `user`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1",
185 if((count($r)) && (x($contact,'notify')) && (strlen($contact['notify']))) {
186 require_once('include/salmon.php');
187 slapper($r[0],$contact['notify'],$slap);
190 goaway($_SESSION['return_url']);