function fb_page_alter in Drupal for Facebook 7.3
Implements hook_page_alter(). Can alter the $page['page_bottom'] hidden region here.
File
- ./
fb.module, line 846 - This is the core required module of Drupal for Facebook.
Code
function fb_page_alter(&$page) {
global $_fb, $_fb_app;
// This element recommended by facebook. http://developers.facebook.com/docs/reference/javascript/
$output = "<div id=\"fb-root\" class=\"fb_module\"></div>\n";
$settings = fb_js_settings();
$output .= "<script type=\"text/javascript\">\n";
$output .= "<!--//--><![CDATA[//><!--\n";
// Pending javascript that needs to execute after FB is initialized.
$js_array = fb_invoke(FB_OP_JS, array(
'fb' => $GLOBALS['_fb'],
'fb_app' => $GLOBALS['_fb_app'],
), array());
if (count($js_array)) {
// The function we define in the footer will be called after FB is initialized.
$output .= "FB_JS.initHandler = function() {\n";
//$output .= "debugger;\n";
$output .= implode("\n ", $js_array);
$output .= "};\n";
$output .= "jQuery(document).bind('fb_init', FB_JS.initHandler);\n\n";
}
// Our settings. We add them here, as late during request as possible.
$output .= " jQuery.extend(Drupal.settings, " . json_encode(array(
'fb' => fb_js_settings(),
)) . ");\n\n";
// Initialize FB.
$output .= "if (typeof(FB) == 'undefined') {\n";
// Load the JS SDK asynchronously.
// http://developers.facebook.com/docs/reference/javascript/
$output .= " var e = document.createElement('script');\n";
$output .= " e.async = true;\n";
$output .= " e.src = Drupal.settings.fb.js_sdk_url;\n";
$output .= " document.getElementById('fb-root').appendChild(e);\n";
$output .= "}\n\n";
$output .= "\n//--><!]]>\n";
$output .= "\n</script>\n";
$page['page_bottom']['fb'] = array(
'#type' => 'markup',
'#markup' => $output,
);
}