View source
<?php
function fb_devel_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'fb/devel',
'callback' => 'fb_devel_page',
'type' => MENU_CALLBACK,
'access' => TRUE,
);
$items[] = array(
'path' => 'fb/devel/fbu',
'callback' => 'fb_devel_fbu_page',
'type' => MENU_CALLBACK,
'access' => TRUE,
);
}
return $items;
}
function fb_devel_fb($op, $data, &$return) {
$fb_app = $data['fb_app'];
$fb = $data['fb'];
if ($op == FB_OP_INITIALIZE) {
$nid = fb_settings(FB_SETTINGS_APP_NID);
if ($nid) {
if ($nid != $fb_app->nid) {
$message = t('fb_app id (%fb_app_id) does not equal fb settings id (%fb_settings_id). This is usually caused by the wrong callback url on your <a href="!url">facebook application settings form</a>.', array(
'%fb_app_id' => $fb_app->nid,
'%fb_settings_id' => $nid,
'!url' => "http://www.facebook.com/developers/apps.php",
));
drupal_set_message($message, 'error');
watchdog('fb_devel', $message);
}
global $theme;
if (isset($theme)) {
$message = t('Drupal for Facebook is unable to override the theme settings. This is usually because some module causes theme_init() to be invoked before fb_init(). See the !readme.', array(
'!drupal_for_facebook' => l(t('Drupal for Facebook'), 'http://drupal.org/project/fb'),
'!readme' => '<a href=' . base_path() . '/' . drupal_get_path('module', 'fb') . '/README.txt>README.txt</a>',
));
drupal_set_message($message, 'error');
watchdog('fb_devel', $message);
}
global $base_path;
if ($base_path == "/{$fb_app->canvas}/") {
$message = t('Facebook canvas page matches Drupal base_path (%base_path). This is currently not supported.', array(
'%base_path' => $base_path,
));
drupal_set_message($message, 'error');
watchdog('fb_devel', $message);
}
}
}
else {
if ($op == FB_APP_OP_EVENT) {
$type = $data['event_type'];
$message = t('Facebook has notified the %label application of a %type event.', array(
'%label' => $fb_app->label,
'%type' => $type,
));
$message .= dprint_r($data, 1);
$message .= dprint_r($_REQUEST, 1);
watchdog('fb_devel', $message);
}
}
}
function fb_devel_page() {
global $fb, $fb_app;
global $user;
if ($_REQUEST['require_login']) {
$fb
->require_login();
}
if ($fb) {
drupal_set_message("in_fb_canvas returns " . $fb
->in_fb_canvas());
drupal_set_message("get_loggedin_user returns " . $fb
->get_loggedin_user());
drupal_set_message("current_url returns " . $fb
->current_url());
drupal_set_message("base_url: " . $GLOBALS['base_url']);
drupal_set_message("base_path: " . $GLOBALS['base_path']);
drupal_set_message("url() returns: " . url());
drupal_set_message("session_key is " . $fb->api_client->session_key);
}
if ($fbu = fb_get_fbu($user)) {
$path = "fb/devel/fbu/{$fbu}";
drupal_set_message(t("Learn more about the current user at !link", array(
'!link' => l($path, $path),
)));
}
dpm(fb_get_fbu($user), 'Facebook user via fb_get_fbu');
if ($GLOBALS['fb_connect_apikey']) {
drupal_set_message("fb_connect_apikey = " . $GLOBALS['fb_connect_apikey']);
}
dpm($_COOKIE, 'cookie');
dpm($_REQUEST, "Request");
drupal_set_message("session_id returns " . session_id());
return "This is the facebook debug page.";
}
function fb_devel_fbu_page($fbu = NULL) {
if ($fbu) {
$output = "<p>Debug info about facebook id {$fbu}:</p>\n";
$friends = fb_get_friends($fbu);
$items = array();
foreach ($friends as $_fbu) {
$items[] = l($_fbu, "fb/devel/fbu/{$_fbu}");
}
if (count($items)) {
$output .= "\n<p>Known friends:<ul><li>";
$output .= implode("</li>\n <li>", $items);
$output .= "</li></ul></p>\n\n";
}
$local_friends = fb_user_get_local_friends($fbu);
$items = array();
foreach ($local_friends as $uid) {
$account = user_load(array(
'uid' => $uid,
));
$items[] = theme('username', $account);
}
if (count($items)) {
$output .= "\n<p>Local friends:<ul><li>";
$output .= implode("</li>\n <li>", $items);
$output .= "</li></ul></p>\n\n";
}
}
else {
drupal_set_message("You have to specify a facebook user id.", 'error');
}
return $output;
}
function fb_devel_block($op = 'list', $delta = 0, $edit = array()) {
if ($op == 'list') {
$items[0]['info'] = t('Facebook Devel Page Info');
return $items;
}
else {
if ($op == 'view') {
return array(
'subject' => t('Facebook Devel Page Info'),
'content' => drupal_get_form('fb_devel_canvas_info'),
);
}
}
}
function fb_devel_canvas_info() {
global $fb, $fb_app;
global $user;
global $base_url;
global $base_path;
$info = array();
$nid = fb_settings(FB_SETTINGS_APP_NID);
if ($fb) {
if ($fb
->in_fb_canvas()) {
$info['Page Status'] = t('Rendering FBML canvas page.');
}
else {
if ($fb
->in_frame()) {
$info['Page Status'] = t('Rendering iframe.');
}
else {
if ($nid) {
$info['Page Status'] = t('Global fb instance is set (followed link in iframe, or handling a form).');
}
else {
$info['Page Status'] = t('Connected via Facebook Connect');
}
}
}
$info['fb_facebook_user'] = fb_facebook_user();
}
else {
$info['Page Status'] = t('Not a canvas page.');
}
$info['local user'] = theme('username', $user);
$info['fb_get_fbu'] = fb_get_fbu($user->uid);
$info['base_url'] = $base_url;
$info['base_path'] = $base_path;
$info['url() returns'] = url();
$info['session_id'] = session_id();
$info['session_name'] = session_name();
$info['request'] = $_REQUEST;
$info['fb_app'] = $fb_app;
$info['session'] = $_SESSION;
$info['cookies'] = $_COOKIE;
$form = array();
foreach ($info as $key => $val) {
if (is_string($val) || is_numeric($val) || !$val) {
$form[] = array(
'#value' => t($key) . ' = ' . $val,
'#weight' => count($form),
'#suffix' => '<br/>',
);
}
else {
$form[] = array(
'#type' => 'fieldset',
'#title' => t($key),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => count($form),
'value' => array(
'#prefix' => '<pre>',
'#suffix' => '</pre>',
'#type' => 'markup',
'#value' => dprint_r($val, 1),
),
);
}
}
return $form;
}