You are here

function w3c_validator_site_validation_report_page in W3C Validator 7

W3C validation report page definition.

_state

Parameters

array $form:

1 string reference to 'w3c_validator_site_validation_report_page'
w3c_validator_menu in ./w3c_validator.module
Implements hook_menu().

File

./w3c_validator.site_validation_report.page.inc, line 14
Page description for site W3C validation report.

Code

function w3c_validator_site_validation_report_page($form, $form_state) {
  $header = $rows = array();

  // ---
  // Build the advanced operation form
  $warning = t('This will revalidate all of the following pages. This operation may be long.');
  $method = variable_get('w3c_validator_method', 'w3c_markup_validator');
  if ($method == 'w3c_markup_validator') {
    $baseUrl = variable_get('w3c_validator_api_endpoint_uri', 'http://validator.w3.org/check');
    if ($baseUrl == 'http://validator.w3.org/check') {
      $warning .= '<br/><br/><i><b>' . t('BEWARE : You are using the online W3C HTML Validator at http://validator.w3.org/check.') . '<br/>' . t('This may be consider spam and abuse of service. Therefore, performing this operation, you may get banned temporarily.') . '</b></i>';
    }
  }
  $form['advanced_operations'] = array(
    '#type' => 'fieldset',
    '#title' => t('advanced operations'),
    '#description' => $warning,
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['advanced_operations']['w3c_validator_revalidate_all'] = array(
    '#type' => 'submit',
    '#value' => 'Re-validate all pages',
    '#prefix' => '<br/>',
  );

  // ---
  // Build the report form
  // Retrieve the list of all page to validate.
  $all_site_pages = _w3c_validator_find_all_pages_to_validate();

  // Retrieve the list of already validated pges.
  $all_validated_pages = _w3c_validator_find_all_validated_pages();
  foreach ($all_site_pages as $page_url => $page) {
    $is_validated = FALSE;

    // Check if the page is validated.
    if (isset($all_validated_pages[$page_url])) {

      // Retrieve the validation result.
      $validation_result = $all_validated_pages[$page_url];
      $is_validated = TRUE;
      if ($validation_result->need_validation) {
        $validation_class = 'warning';
      }
      else {
        if ($validation_result->validity) {
          $validation_class = $validation_result->warning_count ? 'warning' : 'status';
        }
        else {
          $validation_class = 'error';
        }
      }
    }
    else {
      $validation_result = null;
      $validation_class = 'unknown';
    }

    // Render a row for a result
    $row = theme('w3c_validator_site_validation_report_row', array(
      'page' => $page,
      'validation' => $validation_result,
    ));
    $rows[] = array(
      'data' => array(
        array(
          'data' => $row,
          'class' => 'w3c_validator-wrapper collapsed',
        ),
      ),
      'class' => array(
        $validation_class,
      ),
    );
  }
  $output = theme('table', array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'class' => array(
        'w3c_validator-report',
      ),
    ),
  ));
  $form['w3c_validation-report'] = array(
    '#type' => 'markup',
    '#markup' => $output,
  );

  // We use the core update module CSS to re-use the color definitions.
  // Plus add our own css and js.
  drupal_add_css(drupal_get_path('module', 'update') . '/update.css');
  drupal_add_css(drupal_get_path('module', 'w3c_validator') . '/css/w3c_validator.css');
  drupal_add_js(drupal_get_path('module', 'w3c_validator') . '/js/w3c_validator.js');
  return $form;
}