You are here

function lti_tool_provider_requirements in LTI Tool Provider 7

Same name and namespace in other branches
  1. 8 lti_tool_provider.install \lti_tool_provider_requirements()
  2. 2.x lti_tool_provider.install \lti_tool_provider_requirements()

Implements hook_requirements().

File

./lti_tool_provider.install, line 11
Install, update, and uninstall functions for the LTI Tool Provider module.

Code

function lti_tool_provider_requirements($phase) {
  $requirements = array();

  // Ensure translations don't break at install time.
  $t = get_t();
  drupal_load('module', 'libraries');
  $path = libraries_get_path('oauth');
  if (!$path || !file_exists(DRUPAL_ROOT . '/' . $path . '/OAuth.php')) {

    // Since Libraries 2.x, $path is FALSE if the library does not exist.
    $path = 'sites/all/libraries/oauth';
    $requirements['oauth'] = array(
      'title' => $t('OAuth library'),
      'severity' => REQUIREMENT_ERROR,
      'description' => $t('Please download !url, extract the archive and copy the contents to the following location:<br /><code>@path</code>. Make sure the file, OAuth.php, is located at<br /><code>@class</code>.', array(
        '!url' => l('OAuth.php', 'https://github.com/juampy72/OAuth-PHP'),
        '@path' => $path,
        '@class' => $path . '/OAuth.php',
      )),
    );
    if ($phase != 'install') {
      $requirements['oauth']['value'] = $t('Missing');
    }
  }
  else {
    $requirements['oauth'] = array(
      'title' => $t('OAuth library'),
      'severity' => REQUIREMENT_OK,
    );
    if ($phase != 'install') {
      $requirements['oauth']['value'] = $t('Installed');
    }
  }
  if (!drupal_is_cli() && empty($_SERVER['SERVER_NAME'])) {
    $requirements['lti_tool_provider'] = array(
      'title' => $t('LTI OAuth Server Configuration'),
      'severity' => REQUIREMENT_ERROR,
      'description' => $t('Your web server configuration is not providing a valid $_SERVER[\'SERVER_NAME\']. Without this value, OAuth signatures will not match.'),
    );
  }
  elseif (!drupal_is_cli() && empty($_SERVER['SERVER_PORT'])) {
    $requirements['lti_tool_provider'] = array(
      'title' => $t('LTI OAuth Server Configuration'),
      'severity' => REQUIREMENT_ERROR,
      'description' => $t('Your web server configuration is not providing a valid $_SERVER[\'SERVER_PORT\']. Without this value, OAuth signatures will not match.'),
    );
  }
  else {
    $requirements['lti_tool_provider'] = array(
      'title' => $t('LTI OAuth Server Configuration'),
      'severity' => REQUIREMENT_OK,
    );
    if ($phase != 'install') {
      $requirements['lti_tool_provider']['value'] = $t('Server name is') . ' ' . $_SERVER['SERVER_NAME'] . '. ' . $t('Port is') . ' ' . $_SERVER['SERVER_PORT'] . '.';
    }
  }
  return $requirements;
}