function fb_actions_profile_fbml in Drupal for Facebook 5
Same name and namespace in other branches
- 5.2 fb_actions.module \fb_actions_profile_fbml()
File
- ./
fb_actions.module, line 180 - Actions defined here interact with Facebook's API. This makes it possible to notify facebook of various activities as they happen.
Code
function fb_actions_profile_fbml(&$object, $values) {
//dpm(func_get_args(), "fb_actions_profile_fbml");
if ($values['hook'] == 'nodeapi') {
$node = $values['node'];
}
else {
if ($values['hook'] == 'comment') {
$comment = $values['comment'];
$node = node_load($comment->nid);
}
else {
if ($values['hook'] == 'user') {
$account = $values['user'];
// untested
}
}
}
// Determine which app to use
if ($object) {
$fb_app = $object;
}
else {
if ($values['fb_app_nid'] && is_numeric($values['fb_app_nid'])) {
$fb_app = fb_get_app(array(
'nid' => $values['fb_app_nid'],
));
}
else {
if ($values['fb_app_nid'] == FB_APP_CURRENT) {
$fb_app = $GLOBALS['fb_app'];
}
}
}
// Login to facebook as either the current user or the infinite session
if ($fb_app) {
$fb = fb_api_init($fb_app, FB_FBU_ANY);
}
if ($fb && $fb
->get_loggedin_user()) {
global $user;
$fbu = fb_get_fbu($user->uid, $fb_app);
// Replace fb_app related tokens
$body = token_replace($values['body'], 'fb_app', $fb_app);
$body = check_markup($body, $values['body_filter'], FALSE);
// Links in profile FBML must be fully-qualified. Here we attempt to
// replace relative links with fully qualified ones.
global $base_url, $base_path;
$patterns[] = '/"' . str_replace('/', '\\/', $base_path) . '([^"]*)"/';
$replacements[] = '"' . $base_url . '/$1"';
$body = preg_replace($patterns, $replacements, $body);
// Rewrite links to reference canvas pages
if ($fb_app->canvas && function_exists('fb_canvas_process_fbml')) {
$body = fb_canvas_process_fbml($body, $fb_app);
}
if (variable_get('fb_actions_verbose', FALSE)) {
watchdog('fb_actions', t('Setting Facebook profile markup for !user to %body', array(
'!user' => theme('username', $user),
'%body' => htmlentities($body),
)));
}
$fb->api_client
->profile_setFBML($body, $fbu);
fb_report_errors($fb);
}
}