'fb_devel_page', 'type' => MENU_CALLBACK, 'access callback' => TRUE, /* TODO: restrict access */ ); $items['fb/devel/fbu'] = array( 'page callback' => 'fb_devel_fbu_page', 'type' => MENU_CALLBACK, 'access callback' => TRUE, ); // Return some info for debugging AHAH problems $items['fb/devel/js'] = array( 'page callback' => 'fb_devel_js', 'type' => MENU_CALLBACK, 'access callback' => TRUE, ); return $items; } function fb_devel_init() { if (fb_verbose() === 'extreme') { if (arg(0) == 'fb_connect' && arg(1) == 'receiver') { // useful for tracking down tricky connect bugs. watchdog('fb_devel', "Facebook Connect receiver called" . " " . dpr($_REQUEST, 1)); } } // Test if json extensions are loaded. if (defined('SERVICES_JSON_SLICE')) { // defined in facebook's json wrapper, which is not compatible with PHP's JSON extensions. if (user_access('access administration pages')) { drupal_set_message(t("JSON extension for PHP not found. Drupal for Facebook will not work properly without this extension! You can wait for facebook to fix their bug, or install the JSON extension. "), 'error'); } } } function fb_devel_fb($op, $data, &$return) { $fb_app = isset($data['fb_app']) ? $data['fb_app'] : NULL; $fb = isset($data['fb']) ? $data['fb'] : NULL; if ($op == FB_OP_INITIALIZE) { // Sanity check. $nid = fb_settings(FB_SETTINGS_APP_NID); if ($nid && $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 facebook application settings form.', 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, array(), WATCHDOG_ERROR); } // Theme sanity check global $theme; // for debug message if (isset($theme) && !variable_get('site_offline', FALSE)) { $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'), // This link should work with clean URLs // disabled. '!readme' => 'README.txt')); drupal_set_message($message, 'error'); watchdog('fb_devel', $message, array(), WATCHDOG_ERROR); } // path replacement sanity check 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); } // arg_separator sanity check $sep = ini_get('arg_separator.output'); if ($sep != '&') { $message = t('Facebook client libraries will not work properly if arg_separator.output is not "&". Currently the value is "!sep". Please change this in settings.php or php.ini.', array('!sep' => check_plain($sep))); drupal_set_message($message, 'error'); watchdog('fb_devel', $message); } // clean url sanity check if (!variable_get('clean_url', FALSE)) { $message = t('Drupal for Facebook will not function properly until clean URLs are turned on.', array('!url' => url('admin/settings/clean-urls'))); if (user_access('access administration pages')) { drupal_set_message($message, 'error'); } watchdog('fb_devel', $message); } // server URL sanity check // This is an expensive test, because it invokes api_client. try { $props = $fb->api_client->admin_getAppProperties(array('connect_url', 'callback_url')); if (is_array($props)) { foreach ($props as $prop => $url) { if ($url && (strpos($url, $GLOBALS['base_url']) === FALSE)) { $message = t('The Facebook Application labeled %label has a suspicious %prop. The value is %value, while something starting with %url was expected. Consider editing !nodelink.', array('%label' => $fb_app->label, '%prop' => $prop, '%value' => $url, '%url' => $GLOBALS['base_url'], '!nodelink' => l($fb_app->title, 'node/'.$fb_app->nid . '/edit'), )); if (user_access('access administration pages')) { drupal_set_message($message, 'error'); } watchdog('fb_devel', $message); } } } } catch (FacebookRestClientException $e) { if ($e->getCode() == 102) { // Session key invalid or no longer valid 102, which we can ignore. } else { fb_log_exception($e, t('Failed to get app properties for %name.', array('%name' => $fb_app->title))); } } // Moved files sanity check. if (file_exists(drupal_get_path('module', 'fb_devel') . '/fb_feed.module')) { $message = 'Drupal for Facebook modules have moved to modules/fb/contrib/, but your install still has old out-of-date files! Delete the entire modules/fb/ directory and re-install.'; if (user_access('access administration pages')) { drupal_set_message($message, 'error'); } watchdog('fb_devel', $message, array(), WATCHDOG_ERROR); } // Require login sanity check. $fb_app_data = fb_app_get_data($fb_app); if (isset($fb_app_data['fb_user']) && $fb_app_data['fb_user']['require_login'] == FB_USER_OPTION_REQUIRE_LOGIN) { $message = 'Drupal for Facebook options for require login have changed. You must manually edit your application. Look for the require login options under canvas page options. No longer under user options.'; $args = array('!url' => url('node/' . $fb_app->nid . '/edit')); if (user_access('access administration pages')) { drupal_set_message(t($message, $args), 'error'); } watchdog('fb_devel', $message, $args, WATCHDOG_ERROR); } } else if ($op == FB_APP_OP_EVENT) { $type = $data['event_type']; // Facebook has notified us of some event. $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); } else if ($op == FB_OP_CANVAS_EXIT && $data['fb'] && $return) { watchdog('fb_devel', 'Drupal is redirecting a canvas page, destination is %destination.', array('%destination' => $return)); } } /** * Provides a page with useful debug info. * */ function fb_devel_page() { global $fb, $fb_app; global $user; if (isset($_REQUEST['require_login']) && $_REQUEST['require_login']) $fb->require_login(); if ($fb) { // These will work in a canvas page. 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'); //dpm($user, "Local user " . theme('username', $user)); if ($GLOBALS['fb_connect_apikey']) drupal_set_message("fb_connect_apikey = " . $GLOBALS['fb_connect_apikey']); dpm($_COOKIE, 'cookie'); dpm($_REQUEST, "Request"); //dpm($fb_app, "fb_app"); drupal_set_message("session_id returns " . session_id()); //dpm($_SESSION, "session:"); return "This is the facebook debug page."; } /** * A page which tests function which work with facebook user ids */ function fb_devel_fbu_page($fbu = NULL) { if ($fbu) { $output = "
Debug info about facebook id $fbu:
\n"; $friends = fb_get_friends($fbu); //dpm($friends, "fb_get_friends($fbu) returned"); $items = array(); foreach ($friends as $_fbu) { $items[] = l($_fbu, "fb/devel/fbu/{$_fbu}"); } if (count($items)) { $output .= "\nKnown friends:
Local friends:
'; $data .= "session_name() = " . session_name() . "\n"; $data .= "session_id() = " . session_id() . "\n"; $data .= "REQUEST: " . dprint_r($_REQUEST, 1) . "\n"; $data .= "SESSION: " . dprint_r($_SESSION, 1) . "\n"; $data .= ''; print drupal_json(array('status' => TRUE, 'data' => $data)); exit(); } function fb_devel_form_alter(&$form, $form_state, $form_id) { static $count; $count++; if (fb_verbose() === 'extreme') { // most people will not want this... $form['fb_devel'] = array( '#type' => 'fieldset', '#title' => t('Drupal for Facebook Devel'), '#description' => t('For debugging ahah problems......'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['fb_devel']['submit'] = array( '#type' => 'submit', '#value' => t('fb_devel'), '#ahah' => array( 'event' => 'click', 'path' => 'fb/devel/js', 'wrapper' => "fb_devel_wrapper$count", 'method' => 'replace', 'effect' => 'fade', 'progress' => array('type' => 'bar', 'message' => 'XXX'), ), ); $form['fb_devel']['wrap'] = array( '#type' => 'markup', '#value' => "
', '#suffix' => '', '#type' => 'markup', '#value' => dprint_r($val, 1)), ); } } // It's not really a form, but we like collapsible fieldsets return $form; } function fb_devel_user($op, &$edit, &$account, $category = NULL) { if ($op == 'view') { if (user_access('administer users') && user_access('access devel information')) { $account->content['fb_devel'] = array( '#type' => 'fieldset', '#title' => t('Drupal for Facebook Devel'), '#description' => t('Information from facebook API, visible only to administrators.'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => 99, ); foreach (fb_get_all_apps() as $app) { $account->content['fb_devel'][$app->label] = array( '#type' => 'fieldset', '#title' => $app->title, ); if ($fbu = fb_get_fbu($account, $app)) { $fb = fb_api_init($app); $info = fb_users_getInfo(array($fbu), $fb, TRUE); $account->content['fb_devel'][$app->label]['info'] = array( '#type' => 'markup', '#value' => dprint_r($info[0], 1), ); } else { $account->content['fb_devel'][$app->label]['info'] = array( '#type' => 'markup', '#value' => t('No mapping to a facebook account.'), ); } } } } } ?>