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 // remove ajax junk, e.g. Twitter
17 $url = str_replace('/#!/','/',$url);
19 if(! allowed_url($url)) {
20 notice( t('Disallowed profile URL.') . EOL);
21 goaway($_SESSION['return_url']);
25 $ret = probe_url($url);
27 if($ret['network'] === NETWORK_DFRN) {
29 $myaddr = bin2hex($a->get_baseurl() . '/profile/' . $a->user['nickname']);
31 $myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname());
33 goaway($ret['request'] . "&addr=$myaddr");
38 if(get_config('system','dfrn_only')) {
39 notice( t('This site is not configured to allow communications with other networks.') . EOL);
40 notice( t('No compatible communication protocols or feeds were discovered.') . EOL);
41 goaway($_SESSION['return_url']);
45 // do we have enough information?
47 if(! ((x($ret,'name')) && (x($ret,'poll')) && ((x($ret,'url')) || (x($ret,'addr'))))) {
48 notice( t('The profile address specified does not provide adequate information.') . EOL);
50 notice( t('No compatible communication protocols or feeds were discovered.') . EOL);
52 notice( t('An author or name was not found.') . EOL);
54 notice( t('No browser URL could be matched to this address.') . EOL);
55 if(strpos($url,'@') !== false)
56 notice('Unable to match @-style Identity Address with a known protocol or email contact');
57 goaway($_SESSION['return_url']);
60 if($ret['network'] === NETWORK_OSTATUS && get_config('system','ostatus_disabled')) {
61 notice( t('The profile address specified belongs to a network which has been disabled on this site.') . EOL);
65 if(! $ret['notify']) {
66 notice( t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . EOL);
69 $writeable = ((($ret['network'] === NETWORK_OSTATUS) && ($ret['notify'])) ? 1 : 0);
70 if($ret['network'] === NETWORK_MAIL) {
75 // check if we already have a contact
76 // the poll url is more reliable than the profile url, as we may have
77 // indirect links or webfinger links
79 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `poll` = '%s' LIMIT 1",
86 if($r[0]['rel'] == CONTACT_IS_FOLLOWER) {
87 q("UPDATE `contact` SET `rel` = %d , `readonly` = 0 WHERE `id` = %d AND `uid` = %d LIMIT 1",
88 intval(CONTACT_IS_FRIEND),
95 // create contact record
96 $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `addr`, `alias`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`, `priority`,
97 `writable`, `blocked`, `readonly`, `pending` )
98 VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ",
100 dbesc(datetime_convert()),
103 dbesc($ret['alias']),
104 dbesc($ret['notify']),
108 dbesc($ret['photo']),
109 dbesc($ret['network']),
110 intval(($ret['network'] === NETWORK_MAIL) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING),
111 intval($ret['priority']),
116 $r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
122 notice( t('Unable to retrieve contact information.') . EOL);
123 goaway($_SESSION['return_url']);
128 $contact_id = $r[0]['id'];
130 require_once("Photo.php");
132 $photos = import_profile_photo($ret['photo'],local_user(),$contact_id);
134 $r = q("UPDATE `contact` SET `photo` = '%s',
140 WHERE `id` = %d LIMIT 1
145 dbesc(datetime_convert()),
146 dbesc(datetime_convert()),
147 dbesc(datetime_convert()),
152 // pull feed and consume it, which should subscribe to the hub.
154 proc_run('php',"include/poller.php","$contact_id");
156 // create a follow slap
158 $tpl = get_markup_template('follow_slap.tpl');
159 $slap = replace_macros($tpl, array(
160 '$name' => $a->user['username'],
161 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
162 '$photo' => $a->contact['photo'],
163 '$thumb' => $a->contact['thumb'],
164 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
165 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':follow:' . random_string(),
168 '$content' => t('following'),
169 '$nick' => $a->user['nickname'],
170 '$verb' => ACTIVITY_FOLLOW,
171 '$ostat_follow' => ''
174 $r = q("SELECT `contact`.*, `user`.* FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
175 WHERE `user`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1",
180 if(($contact['network'] == NETWORK_OSTATUS) && (strlen($contact['notify']))) {
181 require_once('include/salmon.php');
182 slapper($r[0],$contact['notify'],$slap);
184 if($contact['network'] == NETWORK_DIASPORA) {
185 require_once('include/diaspora.php');
186 $ret = diaspora_share($a->user,$r[0]);
187 logger('mod_follow: diaspora_share returns: ' . $ret);
191 goaway($_SESSION['return_url']);