You are here

function fb_devel_init in Drupal for Facebook 7.3

Same name and namespace in other branches
  1. 6.3 fb_devel.module \fb_devel_init()
  2. 6.2 fb_devel.module \fb_devel_init()

Implements hook_init().

File

./fb_devel.module, line 70
Makes development with Drupal for Facebook much easier. Keep this module enabled until you're confident your app works perfectly.

Code

function fb_devel_init() {
  if (user_access('access devel information')) {

    // Add our module's javascript.
    drupal_add_js(drupal_get_path('module', 'fb_devel') . '/fb_devel.js');
    drupal_add_js(array(
      'fb_devel' => array(
        'verbose' => fb_verbose(),
      ),
    ), 'setting');
  }

  // fb_settings.inc sanity check.
  if (isset($GLOBALS['fb_init_no_settings'])) {
    if (user_access('access administration pages') && (module_exists('fb_canvas') || module_exists('fb_tab'))) {

      // fb_settings.php must be included for canvas or tab support.
      drupal_set_message(t('!drupal_for_facebook (fb_canvas.module) has been enabled, but fb_settings.inc is not included in settings.php.  Please read 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>',
      )), 'error');
    }
  }

  // $conf['fb_apikey'] sanity check.
  if ($apikey = variable_get(FB_VAR_APIKEY, NULL)) {
    $fb_app = fb_get_app(array(
      'apikey' => $apikey,
    ));
    $message = t('Drupal for Facebook no longer uses the \'fb_apikey\' variable.  Change $conf[\'fb_apikey\'] in your settings.php.  Use $conf[\'fb_id\'] instead, and make the value the app id (%app_id) instead of the apikey.', array(
      '%app_id' => $fb_app->id,
    ));
    if (user_access(FB_PERM_ADMINISTER)) {
      drupal_set_message($message, 'error');
    }
    watchdog('fb_devel', $message, array(), WATCHDOG_WARNING);
  }

  // $conf['fb_id'] sanity check
  if ($id = variable_get(FB_VAR_ID, NULL)) {
    if ($label = variable_get(FB_CONNECT_VAR_PRIMARY, NULL)) {
      $fb_app = fb_get_app(array(
        'label' => $label,
      ));
      if ($fb_app && $fb_app->id != $id) {
        $message = t('Drupal for Facebook has detected a problem.  $conf[\'fb_id\'] (%fb_id) is not the same as the primary application %label (%fb_primary_id).', array(
          '%fb_id' => $id,
          '%fb_primary_id' => $fb_app->id,
          '%label' => $fb_app->label,
        ));
        if (user_access(FB_PERM_ADMINISTER)) {
          drupal_set_message($message, 'error');
        }
        watchdog('fb_devel', $message, array(), WATCHDOG_WARNING);
      }
    }
  }

  // fb_user table sanity check
  if (module_exists('fb_user')) {
    if (db_query("SELECT count(*) FROM {authmap} WHERE module='fb_user'")
      ->fetchField()) {
      $message = 'fb_user data has not been migrated from authmap table. Run update.php.';
      $args = array();
      if (user_access('access administration pages')) {
        drupal_set_message(t($message, $args), 'error');
      }
      watchdog('fb_devel', $message, $args, WATCHDOG_ERROR);
    }
  }

  // Old url rewrite sanity check.
  if ($id = fb_settings(FB_SETTINGS_CB)) {
    if ($GLOBALS['_fb_app']->id != $id && $GLOBALS['_fb_app']->apikey == $id) {
      $message = 'Facebook callback URLs have changed.  They now include the app\'s ID, instead of APIKEY.  Your application %label has not been updated.  Either <a target=_top href=!sync_url>sync properties</a> or manually change callbacks on remote settings.';
      $args = array(
        '%label' => $GLOBALS['_fb_app']->title,
        '!sync_url' => url(FB_PATH_ADMIN_APPS . '/' . $GLOBALS['_fb_app']->label . '/fb/set_props', array(
          'fb_url_alter' => FALSE,
        )),
      );
      if (user_access('access administration pages')) {
        drupal_set_message(t($message, $args), 'warning');
      }
      watchdog('fb_devel', $message, $args, WATCHDOG_WARNING);
    }
  }
}