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
74 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `poll` = '%s' LIMIT 1",
80 if($r[0]['rel'] == REL_VIP) {
81 q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
89 // create contact record
90 $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`,
91 `blocked`, `readonly`, `pending` )
92 VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, 0, 0 ) ",
94 dbesc(datetime_convert()),
99 dbesc($vcard['nick']),
100 dbesc($vcard['photo']),
105 $r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
110 notice( t('Unable to retrieve contact information.') . EOL);
111 goaway($_SESSION['return_url']);
116 $contact_id = $r[0]['id'];
118 require_once("Photo.php");
120 $photo_failure = false;
122 $filename = basename($vcard['photo']);
123 $img_str = fetch_url($vcard['photo'],true);
124 $img = new Photo($img_str);
125 if($img->is_valid()) {
127 $img->scaleImageSquare(175);
129 $hash = photo_new_resource();
131 $r = $img->store(local_user(), $contact_id, $hash, $filename, t('Contact Photos'), 4 );
134 $photo_failure = true;
136 $img->scaleImage(80);
138 $r = $img->store(local_user(), $contact_id, $hash, $filename, t('Contact Photos'), 5 );
141 $photo_failure = true;
143 $photo = $a->get_baseurl() . '/photo/' . $hash . '-4.jpg';
144 $thumb = $a->get_baseurl() . '/photo/' . $hash . '-5.jpg';
147 $photo_failure = true;
150 $photo = $a->get_baseurl() . '/images/default-profile.jpg';
151 $thumb = $a->get_baseurl() . '/images/default-profile-sm.jpg';
154 $r = q("UPDATE `contact` SET `photo` = '%s',
159 WHERE `id` = %d LIMIT 1
163 dbesc(datetime_convert()),
164 dbesc(datetime_convert()),
165 dbesc(datetime_convert()),
170 // pull feed and consume it, which should subscribe to the hub.
173 // create a follow slap
175 $tpl = load_view_file('view/follow_slap.tpl');
176 $slap = replace_macros($tpl, array(
177 '$name' => $a->user['username'],
178 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
179 '$photo' => $a->contact['photo'],
180 '$thumb' => $a->contact['thumb'],
181 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
182 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':follow:' . random_string(),
185 '$content' => t('following'),
186 '$nick' => $a->user['nickname'],
187 '$verb' => ACTIVITY_FOLLOW
190 $r = q("SELECT `contact`.*, `user`.* FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
191 WHERE `user`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1",
195 require_once('include/salmon.php');
196 slapper($r[0],$contact,$slap);
198 goaway($_SESSION['return_url']);