function fb_devel_fb in Drupal for Facebook 6.2
Same name and namespace in other branches
- 5.2 fb_devel.module \fb_devel_fb()
- 5 fb_devel.module \fb_devel_fb()
- 6.3 fb_devel.module \fb_devel_fb()
- 7.4 fb_devel.module \fb_devel_fb()
- 7.3 fb_devel.module \fb_devel_fb()
File
- ./
fb_devel.module, line 49 - Makes development with Drupal for Facebook much easier. Keep this module enabled until you're confident your app works perfectly.
Code
function fb_devel_fb($op, $data, &$return) {
$fb_app = isset($data['fb_app']) ? $data['fb_app'] : NULL;
$fb = isset($data['fb']) ? $data['fb'] : NULL;
$errors = 0;
if ($op == FB_OP_INITIALIZE) {
if (fb_settings(FB_SETTINGS_APIKEY) && $fb_app->apikey != fb_settings(FB_SETTINGS_APIKEY)) {
$message = t('Drupal for Facebook has detected a problem. The global app has an apikey (%fb_app_apikey), while the settings indicates a different apikey (%fb_settings_apikey).', array(
'%fb_app_apikey' => $fb_app->apikey,
'%fb_settings_apikey' => fb_settings(FB_SETTINGS_APIKEY),
));
drupal_set_message($message, 'error');
watchdog('fb_devel', $message, array(), WATCHDOG_WARNING);
$errors++;
}
$label = fb_settings(FB_SETTINGS_CB);
// deprecated nid check.
if ($label == $fb_app->nid) {
$message = t('Facebook callback is using deprecated node id (%nid) instead of application label (%label). <a href="!url">Editing the application</a> will usually correct this problem, which was caused by an update to the Drupal for Facebook modules. Sorry for the inconvenience.', array(
'%nid' => $fb_app->nid,
'%label' => $fb_app->label,
'!url' => url(FB_PATH_ADMIN_APPS . '/' . $fb_app->label),
));
drupal_set_message($message, 'warning');
watchdog('fb_devel', $message, array(), WATCHDOG_WARNING);
$errors++;
}
elseif ($label && $label != $fb_app->label) {
$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->label,
'%fb_settings_id' => $label,
'!url' => "http://www.facebook.com/developers/apps.php",
));
drupal_set_message($message, 'warning');
watchdog('fb_devel', $message, array(), WATCHDOG_WARNING);
$errors++;
}
// Theme sanity check. Earlier errors cause this to fail.
global $theme;
// for debug message
if (!$errors && 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' => '<a href=' . base_path() . '/' . drupal_get_path('module', 'fb') . '/README.txt>README.txt</a>',
));
drupal_set_message($message, 'error');
watchdog('fb_devel', $message, array(), WATCHDOG_WARNING);
}
// Catch badly formed links ASAP.
if ($label && (fb_is_connect() && !fb_is_iframe_canvas())) {
// Skip check on callbacks from facebook.
if (arg(0) != 'fb_app' || arg(1) != 'event') {
$message = t('URL starts with %prefix. This should never happen on connect pages. Did the previous page have a badly formed link?', array(
'%prefix' => FB_SETTINGS_CB . '/' . $label,
));
drupal_set_message($message, 'error');
$errors++;
}
}
// 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);
}
// 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 !applink.', array(
'%label' => $fb_app->label,
'%prop' => $prop,
'%value' => $url,
'%url' => $GLOBALS['base_url'],
'!applink' => l($fb_app->label, FB_PATH_ADMIN_APPS . '/' . $fb_app->label),
));
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,
)));
}
}
// Require login sanity check.
$fb_app_data = fb_get_app_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 <a href=!url>edit your application</a>. Look for the require login options under canvas page options. No longer under user options.';
$args = array(
'!url' => url(FB_PATH_ADMIN_APPS . '/' . $fb_app->label),
);
if (user_access('access administration pages')) {
drupal_set_message(t($message, $args), 'error');
}
watchdog('fb_devel', $message, $args, WATCHDOG_ERROR);
}
}
elseif ($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);
}
elseif ($op == FB_OP_CANVAS_EXIT && $data['fb'] && $return) {
watchdog('fb_devel', 'Drupal is redirecting a canvas page, destination is %destination.', array(
'%destination' => $return,
));
}
}