You are here

function _warden_generate_site_data in Warden 7

Same name and namespace in other branches
  1. 6 warden.page.inc \_warden_generate_site_data()

Generate all the site's data for Warden.

Return value

array The site's data as an array.

2 calls to _warden_generate_site_data()
drush_warden_show_module_data in ./warden.drush.inc
Prints out the details of the data that the will be reported to Warden.
_warden_update_warden in ./warden.page.inc
Update Warden with latest site data.

File

./warden.page.inc, line 39
Logic for warden output

Code

function _warden_generate_site_data() {
  global $base_url;
  $system_modules = system_list('module_enabled');
  $system_themes = list_themes(TRUE);
  $res = array(
    'core' => array(),
    'contrib' => array(),
    'custom' => array(),
    'library' => array(),
    'url' => $base_url,
  );

  // Go over themes.
  if (variable_get('warden_match_contrib', TRUE)) {
    foreach ($system_themes as $theme) {
      if (isset($theme->info['package']) && $theme->info['package'] == 'Core') {
        continue;
      }
      if (isset($theme->info['version'])) {
        $res['contrib'][$theme->name] = array(
          "version" => $theme->info['version'],
        );
      }
    }
  }

  // Go over modules.
  foreach ($system_modules as $module => $module_info) {
    $filename = $module_info->filename;

    // Match for custom modules.
    if (variable_get('warden_match_custom', TRUE)) {
      $regex = variable_get('warden_preg_match_custom', '{^sites\\/([A-z,\\.,\\-]+)\\/modules\\/custom\\/*}');
      if (preg_match($regex, $filename)) {

        // if this is part of a project, only set the project.
        if (isset($module_info->info['project'])) {
          $res['custom'][$module_info->info['project']] = array(
            "version" => $module_info->info['version'],
          );
        }
        else {
          $res['custom'][$module] = array(
            "version" => $module_info->info['version'],
          );
        }
      }
    }
    else {
      $res['custom'] = "disabled";
    }

    // Match for contrib modules.
    if (variable_get('warden_match_contrib', TRUE)) {
      $regex = variable_get('warden_preg_match_contrib', '{^sites\\/([A-z,\\.,\\-]+)\\/modules\\/contrib\\/*}');
      if (preg_match($regex, $filename)) {

        // if this is part of a project, only set the project.
        if (isset($module_info->info['project'])) {
          $res['contrib'][$module_info->info['project']] = array(
            "version" => $module_info->info['version'],
          );
        }
        else {
          $res['contrib'][$module] = array(
            "version" => $module_info->info['version'],
          );
        }
      }
    }
    else {
      $res['contrib'] = "disabled";
    }

    // Core modules.
    if (variable_get('warden_match_core', TRUE)) {
      if (strtolower($module_info->info['package']) == "core") {
        $res['core'][$module] = array(
          "version" => $module_info->info['version'],
        );
      }
    }
    else {
      $res['core'] = "disabled";
    }
  }

  // Javascript libraries.
  if (variable_get('warden_match_libraries', FALSE)) {
    $res['library'] = variable_get('warden_list_libraries', array());
  }
  else {
    $res['library'] = 'disabled';
  }

  // Include Drupal core version.
  if (!isset($res['core']['drupal'])) {
    $res['core']['drupal'] = array(
      "version" => VERSION,
    );
  }
  $res['site_name'] = variable_get('site_name', $base_url);

  // Sign the request with our local key and the timestamp.
  $res['key'] = _warden_get_local_token();
  $res['time'] = time();
  return $res;
}