function fb_actions_profile_fbml in Drupal for Facebook 5.2
Same name and namespace in other branches
- 5 fb_actions.module \fb_actions_profile_fbml()
File
- ./fb_actions.module, line 101
- 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) {
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'];
}
}
}
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'];
}
}
}
$fb = $values['fb'];
if (!$fb && $fb_app) {
$fb = fb_api_init($fb_app, FB_FBU_ANY);
}
if ($fb) {
global $user;
$fbu = fb_get_fbu($user->uid, $fb_app);
$body = token_replace($values['body'], 'fb_app', $fb_app);
$body = check_markup($body, $values['body_filter'], FALSE);
if ($profile_main) {
$profile_main = check_markup($profile_main, $values['body_filter'], FALSE);
}
if ($mobile_profile) {
$mobile_profile = check_markup($mobile_profile, $values['body_filter'], FALSE);
}
global $base_url, $base_path;
$patterns[] = '/"' . str_replace('/', '\\/', $base_path) . '([^"]*)"/';
$replacements[] = '"' . $base_url . '/$1"';
$body = preg_replace($patterns, $replacements, $body);
if ($profile_main) {
$profile_main = preg_replace($patterns, $replacements, $profile_main);
}
if ($mobile_profile) {
$mobile_profile = preg_replace($patterns, $replacements, $mobile_profile);
}
if ($fb_app->canvas && function_exists('fb_canvas_process_fbml')) {
$body = fb_canvas_process_fbml($body, $fb_app);
if ($profile_main) {
$profile_main = fb_canvas_process_fbml($profile_main, $fb_app);
}
if ($mobile_profile) {
$mobile_profile = fb_canvas_process_fbml($mobile_profile, $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),
)));
}
try {
$fb->api_client
->profile_setFBML(NULL, $fbu, $body, NULL, $mobile_profile, $profile_main);
} catch (Exception $e) {
fb_log_exception($e, t('Failed to set profile FBML'), $fb);
}
}
}