You are here

function simple_fb_connect_requirements in Simple FB Connect 7.2

Same name and namespace in other branches
  1. 8.3 simple_fb_connect.install \simple_fb_connect_requirements()
  2. 8.2 simple_fb_connect.install \simple_fb_connect_requirements()
  3. 7 simple_fb_connect.install \simple_fb_connect_requirements()

Implements hook_requirements().

File

./simple_fb_connect.install, line 11
Install file for Simple FB Connect module. Checks requirements.

Code

function simple_fb_connect_requirements($phase) {
  $requirements = array();
  $t = get_t();
  if ($phase == 'install') {
    if (!function_exists('curl_init')) {
      $requirements['curl']['severity'] = REQUIREMENT_ERROR;
      $requirements['curl']['description'] = $t('Simple FB Connect could not be installed. The cURL library is not installed. Please check the <a href="@url">PHP cURL documentation</a> for information on how to correct this.', array(
        '@url' => 'http://www.php.net/manual/en/curl.setup.php',
      ));
    }
    if (!function_exists('json_decode')) {
      $requirements['json']['severity'] = REQUIREMENT_ERROR;
      $requirements['json']['description'] = $t('Simple FB Connect could not be installed. The JSON library is not installed. Facebook needs the JSON PHP extension.');
    }
    if (version_compare(phpversion(), '5.4.0', '<')) {
      $requirements['php_version']['title'] = $t('PHP version');
      $requirements['php_version']['value'] = check_plain(phpversion());
      $requirements['php_version']['severity'] = REQUIREMENT_ERROR;
      $requirements['php_version']['description'] = $t('Simple FB Connect could not be installed. Facebook PHP SDK v4 requires PHP 5.4 or higher.');
    }

    // Make sure that Libraries module is loaded.
    if (!function_exists('libraries_get_path')) {
      module_load_include('module', 'libraries');
    }

    // Try to check that we have version 4.0.x of the SDK library.
    // - libraries_detect does not work in the install phase so we can't easily check the exact version
    // - We check if sites/all/libraries/facebook-php-sdk-v4/README.md is found.
    $path = libraries_get_path('facebook-php-sdk-v4');
    if (!is_file($path . '/README.md')) {
      $requirements['facebook-php-sdk-v4']['severity'] = REQUIREMENT_ERROR;
      $requirements['facebook-php-sdk-v4']['description'] = $t('Simple FB Connect could not be installed. Facebook PHP SDK library version 4.0.x not found. See README.txt.');
    }
  }
  if ($phase == 'runtime') {
    $sdk = libraries_detect('facebook-php-sdk-v4');
    if (!is_array($sdk) || !$sdk['installed']) {
      $requirements['facebook-php-sdk-v4']['title'] = $t('Facebook PHP SDK v4');
      $requirements['facebook-php-sdk-v4']['value'] = $t('Not installed');
      $requirements['facebook-php-sdk-v4']['severity'] = REQUIREMENT_ERROR;
      $requirements['facebook-php-sdk-v4']['description'] = $t('Facebook PHP SDK library version 4.0.x not found. See README.txt');
    }
    elseif ($sdk['version'] < '4.0' || $sdk['version'] >= '4.1') {
      $requirements['facebook-php-sdk-v4']['title'] = $t('Facebook PHP SDK v4');
      $requirements['facebook-php-sdk-v4']['value'] = $t('Unsupported version detected');
      $requirements['facebook-php-sdk-v4']['severity'] = REQUIREMENT_ERROR;
      $requirements['facebook-php-sdk-v4']['description'] = $t('Version @version detected. See README.txt', array(
        '@version' => $sdk['version'],
      ));
    }
    else {
      $requirements['facebook-php-sdk-v4']['title'] = $t('Facebook PHP SDK v4');
      $requirements['facebook-php-sdk-v4']['value'] = $t('Version @version detected.', array(
        '@version' => $sdk['version'],
      ));
      $requirements['facebook-php-sdk-v4']['severity'] = REQUIREMENT_OK;
    }
  }
  return $requirements;
}