$value) { if ($key != 'sig') { $payload .= $key . '=' . $value; } } if (md5($payload . $application_secret) != $args['sig']) { return NULL; } } if (!isset($args['session_key'])) { // Session key missing first time facebook connect page is loaded (?) if ($access_token = $args['access_token']) { $tokens = explode('|', $access_token); $args['session_key'] = $tokens[1] . '|' . $tokens[2]; } } //print(__FUNCTION__); print_r($args); flush(); // debug return $args; } /** * By changing the $cookie_domain, we force drupal to use a different session * when a user is logged into a facebook application. We base the * $cookie_domain on the id of the application, if we can learn it. * * Facebook provides a number of "migrations" and historically has offered * different data to applications. So the code below tries a variety of ways * to learn the settings. */ if (function_exists('_fb_settings_parse') && ($id = _fb_settings_parse(FB_SETTINGS_CB))) { // Learned id from url rewrite. // Either canvas page or profile tab. fb_settings(FB_SETTINGS_ID, $id); if ($page_id = _fb_settings_parse(FB_SETTINGS_CB_PAGE)) { fb_settings(FB_SETTINGS_TYPE, FB_SETTINGS_TYPE_PAGE_TAB); fb_settings(FB_SETTINGS_PAGE_ID, $page_id); } else { fb_settings(FB_SETTINGS_TYPE, FB_SETTINGS_TYPE_CANVAS); } if (isset($_REQUEST['signed_request']) && ($sr = _fb_settings_parse_signed_request($_REQUEST['signed_request']))) { // Prefer signed request data to cookie data. _fb_settings_honor_signed_request($sr); } else { $data = fb_settings_get_facebook_cookie($id); if (isset($data)) { if (isset($data['uid'])) { fb_settings(FB_SETTINGS_FBU, $data['uid']); } } } } elseif (isset($_REQUEST['signed_request']) && ($sr = _fb_settings_parse_signed_request($_REQUEST['signed_request']))) { // Reach this clause on canvas page when admin has not enabled url_rewrite. // http://developers.facebook.com/docs/authentication/canvas // We get useful info from signed_request only when user is logged in and // therefore oauth_token is set. _fb_settings_honor_signed_request($sr); // Once upon a time, signed_request was only passed on canvas pages. No longer true. // @TODO - somehow detect whether a signed request indicates canvas page or not. //fb_settings(FB_SETTINGS_TYPE, FB_SETTINGS_TYPE_CANVAS); } elseif (isset($_REQUEST['session'])) { // New SDK's use session param for canvas pages. // Deprecated! 'session' has been replaced with 'signed_request'. This clause can go away. $session = json_decode($_REQUEST['session'], TRUE); fb_settings(FB_SETTINGS_TYPE, FB_SETTINGS_TYPE_CANVAS); fb_settings(FB_SETTINGS_FBU, $session['uid']); fb_settings(FB_SETTINGS_TOKEN, $session['access_token']); // Which app? $access_tokens = explode('|', $session['access_token']); if ($app_id = $access_tokens[0]) { fb_settings(FB_SETTINGS_ID, $app_id); } } elseif (isset($_REQUEST['fb_js_session'])) { // Ajax callback via fb.js. $session = json_decode($_REQUEST['fb_js_session'], TRUE); fb_settings(FB_SETTINGS_TYPE, isset($_REQUEST['fb_js_page_type']) ? $_REQUEST['fb_js_page_type'] : FB_SETTINGS_TYPE_CONNECT); fb_settings(FB_SETTINGS_FBU, $session['uid']); fb_settings(FB_SETTINGS_TOKEN, $session['access_token']); // Which app? $access_tokens = explode('|', $session['access_token']); if ($app_id = $access_tokens[0]) { fb_settings(FB_SETTINGS_ID, $app_id); } } else { // We're not in a canvas page. // We might be in a facebook connect page. We have to inspect cookies to make sure. $id = isset($conf['fb_id']) ? $conf['fb_id'] : NULL; $secret = isset($conf['fb_secret']) ? $conf['fb_secret'] : NULL; if ($id) { $session = fb_settings_get_facebook_cookie($id, $secret); // Honor connect session only when cookie is set. if (count($session)) { fb_settings(FB_SETTINGS_ID, $id); fb_settings(FB_SETTINGS_TYPE, FB_SETTINGS_TYPE_CONNECT); fb_settings(FB_SETTINGS_FBU, $session['uid']); } } } if (fb_settings(FB_SETTINGS_TYPE) && fb_settings(FB_SETTINGS_TYPE) != FB_SETTINGS_TYPE_CONNECT) { // Cookie domain unique to app and page type. $unique_id = fb_settings(FB_SETTINGS_ID); $cookie_domain = isset($cookie_domain) ? $cookie_domain : '' . fb_settings(FB_SETTINGS_TYPE) . $unique_id; fb_settings(FB_SETTINGS_COOKIE_DOMAIN, $cookie_domain); // for debugging. } if (fb_settings(FB_SETTINGS_FBU)) { // Disable Drupal cache when logged into facebook. $conf['cache'] = 0; }