function fb_ajax_event in Drupal for Facebook 6.3
Same name and namespace in other branches
- 7.4 fb.module \fb_ajax_event()
- 7.3 fb.module \fb_ajax_event()
Ajax callback handles an event from facebook's javascript sdk.
http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe
Return value
Array of javascript to be evaluated by the page which called this callback.
See also
fb.js and
File
- ./
fb.module, line 1655 - This is the core required module of Drupal for Facebook.
Code
function fb_ajax_event($event_type) {
global $_fb, $_fb_app;
$js_array = array();
if (isset($_REQUEST['appId'])) {
$_fb_app = fb_get_app(array(
'id' => $_REQUEST['appId'],
));
// Remember signed_request in session, in case third party cookies are disabled.
if (isset($_REQUEST['signed_request']) && $_REQUEST['signed_request'] && variable_get(FB_VAR_USE_SESSION, TRUE)) {
$_SESSION['_fb_' . $_fb_app->id] = $_REQUEST['signed_request'];
}
elseif (isset($_REQUEST['access_token']) && $_REQUEST['access_token'] && variable_get(FB_VAR_USE_SESSION, TRUE)) {
$_SESSION['_fb_token_' . $_fb_app->id] = $_REQUEST['access_token'];
}
else {
unset($_SESSION['_fb_' . $_fb_app->id]);
unset($_SESSION['_fb_token_' . $_fb_app->id]);
}
if ($_fb_app) {
$_fb = fb_api_init($_fb_app);
// Data to pass to hook_fb.
$data = array(
'fb_app' => $_fb_app,
'fb' => $_fb,
'event_type' => $event_type,
'event_data' => $_POST,
);
$js_array = fb_invoke(FB_OP_AJAX_EVENT, $data, $js_array);
}
else {
watchdog('fb', 'fb_ajax_event did not find application %id', array(
'%id' => $_REQUEST['appId'],
), WATCHDOG_ERROR);
}
if ($event_type == 'session_change') {
// Session change is a special case. If user has logged out of
// facebook, we want a new drupal session. We do this here, even if
// fb_user.module is not enabled.
if (!isset($_POST['fbu']) || !$_POST['fbu']) {
// Logout, not login.
_fb_logout();
}
}
}
else {
watchdog('fb', 'fb_ajax_event called badly. Not passed appId.', array(), WATCHDOG_ERROR);
// Trying to track down what makes this happen.
if (fb_verbose() == 'extreme') {
watchdog('fb', 'fb_ajax_event called badly. Not passed appId. trace: !trace', array(
'!trace' => '<pre>' . print_r(debug_backtrace(), 1) . '</pre>',
), WATCHDOG_ERROR);
}
}
drupal_json(array_values($js_array));
//exit();
}