function fb_connect_footer in Drupal for Facebook 6.2
Same name and namespace in other branches
- 5.2 fb_connect.module \fb_connect_footer()
Include facebook javascript in the footer of the current page.
File
- ./
fb_connect.module, line 428 - Support for Facebook Connect features
Code
function fb_connect_footer($is_front) {
// Do nothing on FBML pages
if (fb_is_fbml_canvas()) {
return;
}
global $base_path;
$fb_feature_src = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' && !variable_get('fb_force_no_ssl', FALSE) ? "https://ssl.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" : "http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php";
$feature_data = fb_connect_require_feature();
$option_data = fb_connect_init_option();
if (count($feature_data)) {
foreach ($feature_data as $data) {
// Give other modules a chance to add javascript which executes after init.
$extra = fb_invoke(FB_OP_CONNECT_JS_INIT, $data, array());
$extra_js = implode("\n", $extra);
$fb_app = $data['fb_app'];
$features = $data['features'];
$options = json_encode($option_data[$fb_app->apikey]);
// Hack! What's the way to json_encode a function name?
$options = str_replace('"{', '', $options);
$options = str_replace('}"', '', $options);
// drupal_add_js cannot add external javascript, so we use hook_footer instead.
$output = '<script src="' . $fb_feature_src . '" type="text/javascript"></script>';
$output .= "\n";
$feature_list = '["' . implode('","', $features) . '"]';
// Put together the URL for the receiver. The prefix must be identical to the apps connect URL.
//$receiver = fb_connect_get_connect_url($fb_app) . "fb_connect/receiver"; // OLD WAY. XXX
$receiver = variable_get('fb_xd_receiver', url(drupal_get_path('module', 'fb') . '/fb_receiver.html', array(
'absolute' => TRUE,
)));
$output .= "\n<script type=\"text/javascript\">\n \$(document).ready(function() {\n FB_RequireFeatures({$feature_list}, function () {\n\n //FB.FBDebug.logLevel = 4;\n //FB.FBDebug.isEnabled = true;\n\n FB.XFBML.Host.autoParseDomTree = false;\n\n FB.init(\"{$fb_app->apikey}\", \"{$receiver}\", {$options});\n });\n });\n";
// Extra JS after successful fbConnect init.
$output .= "\n FB.ensureInit(function()\n {\n FB_Connect.init();\n {$extra_js}\n });\n";
$output .= "\n</script>\n";
}
}
return $output;
}