You are here

function socialfeed_requirements in Social Feed 7

Same name and namespace in other branches
  1. 6 socialfeed.install \socialfeed_requirements()

Implements hook_requirements().

File

./socialfeed.install, line 11
Social Feeds installation functions.

Code

function socialfeed_requirements($phase) {
  $requirements = $library = array();

  // Ensure translations don't break at install time.
  $t = get_t();
  if ($phase == 'runtime') {
    $library['facebook'] = libraries_detect('facebook');
    $library['twitter'] = libraries_detect('twitter');
    $library['instagram'] = libraries_detect('instagram');
    foreach ($library as $key => $value) {
      $error_type = isset($library[$key]['error']) ? drupal_ucfirst($library[$key]['error']) : '';
      $error_message = isset($library[$key]['error message']) ? $library[$key]['error message'] : '';
    }
    if (!function_exists('curl_init')) {
      $requirements['curl']['title'] = $t('cURL library');
      $requirements['curl']['value'] = $t('Not installed');
      $requirements['curl']['severity'] = REQUIREMENT_ERROR;
      $requirements['curl']['description'] = $t('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']['title'] = $t('JSON extension');
      $requirements['json']['value'] = $t('Not installed');
      $requirements['json']['severity'] = REQUIREMENT_ERROR;
      $requirements['json']['description'] = $t('The JSON library is not installed. Facebook needs the JSON PHP extension');
    }
    if (empty($library['facebook']['installed'])) {
      $requirements['facebook'] = array(
        'title' => $t('PHP SDK for Facebook APIs'),
        'value' => $t('@e: At least @a', array(
          '@e' => $error_type,
          '@a' => SOCIALFEED_FACEBOOK_SDK_MIN_PLUGIN_VERSION,
        )),
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('!error You need to download the !facebook,
        place the facebook directory in the %path directory on your server
        and extract the archive
        .', array(
          '!error' => $error_message,
          '!facebook' => l($t('PHP SDK for Facebook APIs'), $library['facebook']['download url']),
          '%path' => 'sites/all/libraries',
        )),
      );
    }
    elseif (version_compare($library['facebook']['version'], SOCIALFEED_FACEBOOK_SDK_MIN_PLUGIN_VERSION, '>=')) {
      $requirements['facebook'] = array(
        'title' => $t('PHP SDK for Facebook APIs'),
        'severity' => REQUIREMENT_OK,
        'value' => 'v' . $library['facebook']['version'] . ' installed',
      );
    }
    else {
      $requirements['facebook'] = array(
        'title' => $t('PHP SDK for Facebook APIs'),
        'value' => $t('At least @a', array(
          '@a' => SOCIALFEED_FACEBOOK_SDK_MIN_PLUGIN_VERSION,
        )),
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('You need to download a later version of the
        !facebook and replace the old version located in the %path directory
        on your server.', array(
          '!facebook' => l($t('PHP SDK for Facebook APIs'), $library['facebook']['download url']),
          '%path' => $library['facebook']['library path'],
        )),
      );
    }
    if (empty($library['twitter']['installed'])) {
      $requirements['twitter'] = array(
        'title' => $t('PHP SDK for Twitter APIs'),
        'value' => $t('@e: At least @a', array(
          '@e' => $error_type,
          '@a' => SOCIALFEED_TWITTER_SDK_MIN_PLUGIN_VERSION,
        )),
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('!error You need to download the !twitter,
        place the twitter directory in the %path directory on your server
        and extract the archive
        .', array(
          '!error' => $error_message,
          '!twitter' => l($t('PHP SDK for Twitter APIs'), $library['twitter']['download url']),
          '%path' => 'sites/all/libraries',
        )),
      );
    }
    elseif (version_compare($library['twitter']['version'], SOCIALFEED_TWITTER_SDK_MIN_PLUGIN_VERSION, '>=')) {
      $requirements['twitter'] = array(
        'title' => $t('PHP SDK for Twitter APIs'),
        'severity' => REQUIREMENT_OK,
        'value' => 'v' . $library['twitter']['version'] . ' installed',
      );
    }
    else {
      $requirements['twitter'] = array(
        'title' => $t('PHP SDK for Twitter APIs'),
        'value' => $t('At least @a', array(
          '@a' => SOCIALFEED_TWITTER_SDK_MIN_PLUGIN_VERSION,
        )),
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('You need to download a later version of the
        !twitter and replace the old version located in the %path directory
        on your server.', array(
          '!twitter' => l($t('PHP SDK for Twitter APIs'), $library['twitter']['download url']),
          '%path' => $library['twitter']['library path'],
        )),
      );
    }
    if (empty($library['instagram']['installed'])) {
      $requirements['instagram'] = array(
        'title' => $t('PHP SDK for Instagram APIs'),
        'value' => $t('@e: At least @a', array(
          '@e' => $error_type,
          '@a' => SOCIALFEED_INSTAGRAM_SDK_MIN_PLUGIN_VERSION,
        )),
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('!error You need to download the !instagram,
        place the instagram directory in the %path directory on your server
        and extract the archive
        .', array(
          '!error' => $error_message,
          '!instagram' => l($t('PHP SDK for Instagram APIs'), $library['instagram']['download url']),
          '%path' => 'sites/all/libraries',
        )),
      );
    }
    elseif (version_compare($library['instagram']['version'], SOCIALFEED_INSTAGRAM_SDK_MIN_PLUGIN_VERSION, '>=')) {
      $requirements['instagram'] = array(
        'title' => $t('PHP SDK for Instagram APIs'),
        'severity' => REQUIREMENT_OK,
        'value' => 'v' . $library['instagram']['version'] . ' installed',
      );
    }
    else {
      $requirements['instagram'] = array(
        'title' => $t('PHP SDK for Instagram APIs'),
        'value' => $t('At least @a', array(
          '@a' => SOCIALFEED_INSTAGRAM_SDK_MIN_PLUGIN_VERSION,
        )),
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('You need to download a later version of the
        !instagram and replace the old version located in the %path directory
        on your server.', array(
          '!instagram' => l($t('PHP SDK for Instagram APIs'), $library['instagram']['download url']),
          '%path' => $library['instagram']['library path'],
        )),
      );
    }
  }
  return $requirements;
}