View source
<?php
define('FB_CANVAS_VAR_ADD_JS', 'fb__canvas_add_js');
define('FB_CANVAS_VAR_PROCESS_PAGE', 'fb__canvas_process_page');
define('FB_CANVAS_VAR_PROCESS_ABSOLUTE', 'fb__canvas_process_absolute_links');
function fb_canvas_app() {
$fb_app =& drupal_static('fb_canvas_app');
if ($fb_app === NULL) {
$fb_settings =& drupal_static('fb_settings');
if (!empty($fb_settings['fb__canvas'])) {
$app_id = $fb_settings['fb__canvas'];
$fb_app = fb_application_load($app_id);
}
else {
$fb_app = FALSE;
}
}
return $fb_app;
}
function fb_canvas_fb_app_alter(&$app, &$variable) {
if (!$variable) {
if ($fb_app = fb_canvas_app()) {
$app = $fb_app;
}
}
}
function fb_canvas_custom_theme() {
if ($fb_app = fb_canvas_app()) {
drupal_add_js(array(
'fb_canvas' => array(
'uid' => $GLOBALS['user']->uid,
'namespace' => $fb_app['namespace'],
'client_id' => $fb_app['client_id'],
),
), 'setting');
drupal_add_js(drupal_get_path('module', 'fb_canvas') . '/fb_canvas.js');
if (variable_get(FB_CANVAS_VAR_ADD_JS, TRUE)) {
fb_require_js();
}
}
}
function fb_canvas_menu_get_item_alter(&$router_item, &$path, $original_map) {
}
function fb_canvas_theme_registry_alter(&$items) {
$items['page']['process functions'][] = 'fb_canvas_process_page';
}
function fb_canvas_process_page(&$vars, $hook) {
}
function fb_canvas_page_alter(&$page) {
if (fb_canvas_app() && variable_get(FB_CANVAS_VAR_PROCESS_PAGE, TRUE)) {
if (!isset($page['#post_render'])) {
$page['#post_render'] = array();
}
$page['#post_render'][] = 'fb_canvas_post_render_page';
}
}
function fb_canvas_post_render_page($page, $children) {
include drupal_get_path('module', 'fb') . '/fb.process.inc';
$fb_app = fb_canvas_app();
$page = fb_process($page, array(
'add_target' => '_top',
'absolute_links' => variable_get(FB_CANVAS_VAR_PROCESS_ABSOLUTE, TRUE),
'to_canvas' => $fb_app['namespace'],
));
return $page;
}
function fb_canvas_url_outbound_alter(&$path, &$options, $original_path) {
$options += array(
'fb_canvas' => FALSE,
'fb_url_alter' => TRUE,
);
if ($options['fb_canvas'] && $options['fb_url_alter']) {
if (is_string($options['fb_canvas'])) {
$namespace = $options['fb_canvas'];
}
else {
$fb_app = fb_get_app();
$namespace = $fb_app['namespace'];
}
$options['absolute'] = TRUE;
$options['base_url'] = "//apps.facebook.com/{$namespace}";
}
}