You are here

function fb_requirements in Drupal for Facebook 6.3

Same name and namespace in other branches
  1. 6.2 fb.install \fb_requirements()
  2. 7.4 fb.install \fb_requirements()
  3. 7.3 fb.install \fb_requirements()

Implementation of hook_requirements().

File

./fb.install, line 17
Install file to support fb.module.

Code

function fb_requirements($phase) {
  $t = get_t();
  $items = array();

  // fb.module and Facebook's PHP libs require JSON extensions.
  if (!function_exists('json_encode')) {
    $items[] = array(
      'value' => $t('Not found'),
      'severity' => REQUIREMENT_ERROR,
      'description' => $t('JSON extension for PHP'),
    );
  }

  // Disable these checks at install time, because failure then causes more
  // problems, due to module dependencies and Drupal's poor handling of
  // requirement errors.
  if ($phase != 'runtime') {
    return $items;
  }
  $status = array(
    'title' => $t('Drupal for Facebook Settings'),
  );
  if (function_exists('fb_settings')) {
    if ($phase == 'runtime') {
      $status['value'] = $t('Included');
    }
    $status['severity'] = REQUIREMENT_OK;
  }
  else {
    if ($phase == 'runtime') {
      $status['value'] = $t('Not included');
    }
    $status['severity'] = REQUIREMENT_ERROR;
    $path = drupal_get_path('module', 'fb');
    if (!$path) {

      // Not set during install.php
      $path = 'modules/fb';
    }
    $status['description'] = $t('Add something like <strong>include "%path";</strong> to your settings.php.', array(
      '%path' => $path . '/fb_settings.inc',
    ));
  }
  $items[] = $status;
  $status = array(
    'title' => $t('Facebook PHP SDK'),
  );

  // Find Facebook's PHP SDK.  Use libraries API if enabled.
  $fb_lib_path = function_exists('libraries_get_path') ? libraries_get_path('facebook-php-sdk') : 'sites/all/libraries/facebook-php-sdk';
  $fb_platform = variable_get(FB_VAR_API_FILE, $fb_lib_path . '/src/facebook.php');
  if (class_exists('Facebook')) {
    $status['value'] = Facebook::VERSION;
    if (!defined('Facebook::VERSION') || Facebook::VERSION < "3" || Facebook::VERSION > "4") {
      $status['description'] = $t('Expected version 3.x.y of Facebook PHP SDK.');
      $status['severity'] = REQUIREMENT_ERROR;
    }
    else {
      $status['description'] = $fb_platform;
      $status['severity'] = REQUIREMENT_OK;
    }
  }
  elseif (include $fb_platform) {

    // include() better than file_exists().
    $status['description'] = $t('Facebook SDK found at %path', array(
      '%path' => $fb_platform,
    ));
    $status['severity'] = REQUIREMENT_OK;
    if ($phase == 'runtime') {
      $status['value'] = $t('Found');
    }
  }
  else {
    $status['description'] = $t('Facebook client API not found.  See modules/fb/README.txt');
    $status['severity'] = REQUIREMENT_ERROR;
    if ($phase == 'runtime') {
      $status['value'] = $t('Not found');
    }
  }
  $items[] = $status;

  // If user 0 has fbu in its data, that can cause real problems.  Test copied from fb_devel.module.
  $result = db_query('SELECT count(uid) FROM {users} WHERE data LIKE "%\\"app_specific\\"%" OR data LIKE "%\\"is_app_user\\"%" OR data LIKE "\\"fbu\\"%"');
  $count = db_result($result);
  if ($count) {
    $status = array(
      'title' => $t('Drupal for Facebook obsolete data.'),
      'description' => $t('Early versions of Drupal for Facebook stored information in users table.  Leave fb_devel.module enabled, and this data will be cleared during cron jobs.'),
    );
    $status['value'] = $t('Found %count rows', array(
      '%count' => $count,
    ));
    $status['severity'] = REQUIREMENT_WARNING;
    $items[] = $status;
  }

  // Older versions of modules/fb allowed caching when users are logged into facebook (but anonymous to drupal).
  $result = db_query('SELECT count(cid) FROM {cache_page} WHERE data like \'%"fbu":"%\'');
  $count = db_result($result);
  if ($count) {
    $status = array(
      'title' => $t('Facebook Data in Page Cache'),
      'description' => $t('Pages have been cached while user logged into facebook.  This might show users\' private data to others.  Clearing cache should solve this problem.'),
    );
    $status['value'] = $t('Found %count cached pages', array(
      '%count' => $count,
    ));
    $status['severity'] = REQUIREMENT_ERROR;
    $items[] = $status;
  }
  return $items;
}