<?php
// $Id$

/**
 * @file
 * Installer for the SEO Compliance Checker
 */

/**
 * Implements hook_requirements().
 * @param string $phase
 */
function seo_checker_requirements($phase) {
  $t = get_t();
  $requirements = array();

  if ($phase == 'runtime') {
    $ok = FALSE;
    $types = array();
    foreach (_node_types_build()->types as $code => $type) {
      $types[] = $type->name;
      $ok |= variable_get('seo_checker_' . $code, 0);
    }
    $requirements['seo_content_types']['title'] = $t('SEO Compliance Checker - Content Types');
    if ($ok) {
      $requirements['seo_content_types']['value'] = $t('Enabled for content types !types.', array("!types" => implode(', ', $types)));
      $requirements['seo_content_types']['severity'] = REQUIREMENT_OK;
    } else {
      $requirements['seo_content_types']['value'] = $t('No Content Types Enabled');
      $requirements['seo_content_types']['description'] = $t("In order for the SEO Compliance Checker to work you have to !enable it for at least one content type.", array("!enable" => l("enable", "admin/config/content/seo_checker")));
      $requirements['seo_content_types']['severity'] = REQUIREMENT_WARNING;
    }

    $rules = module_invoke_all('register_seo_rules');
    $requirements['seo_rules']['title'] = $t('SEO Compliance Checker - Enabled Rules');
    if (count($rules) > 0) {
      $requirements['seo_rules']['value'] = $t('There are !count enabled SEO rules.', array('!count' => count($rules)));
      $requirements['seo_rules']['severity'] = REQUIREMENT_OK;
    } else {
      $requirements['seo_rules']['value'] = $t('No SEO Rules Enabled');
      $requirements['seo_rules']['description'] = $t("In order for the SEO Compliance Checker to work you have to !enable submodules that implement rules.", array("!enable" => l("enable", "admin/modules")));
      $requirements['seo_rules']['severity'] = REQUIREMENT_WARNING;
    }

  }
  return $requirements;
}

/**
 * Implements hook_install().
 */
function seo_checker_install() {
  variable_set('jquery_update_compression_type', 'none');
}

/**
 * Implements hook_update_N().
 */
function seo_checker_update_7000() {
  $allow_failures = variable_get('seo_checker_allow_failures', 1);
  if ($allow_failures == 0) {
    variable_set('seo_checker_allow_failures', 'no-failures');
  }
  elseif ($allow_failures == 1) {
    variable_set('seo_checker_allow_failures', 'show-preview-only');
  }
  return array();
}
