You are here

function theme_update_status_report in Update Status 5.2

Same name and namespace in other branches
  1. 5 update_status.module \theme_update_status_report()

Theme project status report.

2 theme calls to theme_update_status_report()
update_status_settings in ./update_status.module
Menu callback. Show the settings for the update status module.
update_status_status in ./update_status.module
Menu callback. Generate a page about the update status of projects.

File

./update_status.module, line 1316

Code

function theme_update_status_report($data) {
  $last = variable_get('update_status_last', 0);
  $output = '<div class="update-status checked">' . t('Last checked: ') . ($last ? format_interval(time() - $last) . ' ' . t('ago') : t('Never'));
  $output .= ' <span class="check-manually">(' . l(t('Check manually'), 'admin/logs/updates/check') . ')</span>';
  $output .= "</div>\n";
  if (!is_array($data)) {
    $output .= '<p>' . $data . '</p>';
    return $output;
  }
  $header = array();
  $rows = array();
  $notification_level = variable_get('update_status_notification_threshold', 'all');
  foreach ($data as $project) {
    switch ($project['status']) {
      case UPDATE_STATUS_CURRENT:
        $class = 'ok';
        $icon = theme('image', 'misc/watchdog-ok.png', t('ok'), t('ok'));
        break;
      case UPDATE_STATUS_UNKNOWN:
      case UPDATE_STATUS_NOT_FETCHED:
        $class = 'unknown';
        $icon = theme('image', 'misc/watchdog-warning.png', t('unknown'), t('unknown'));
        break;
      case UPDATE_STATUS_NOT_SECURE:
      case UPDATE_STATUS_REVOKED:
      case UPDATE_STATUS_NOT_SUPPORTED:
        $class = 'error';
        $icon = theme('image', 'misc/watchdog-error.png', t('error'), t('error'));
        break;
      case UPDATE_STATUS_NOT_CHECKED:
      case UPDATE_STATUS_NOT_CURRENT:
      default:
        $class = 'warning';
        $icon = theme('image', 'misc/watchdog-warning.png', t('warning'), t('warning'));
        break;
    }
    $row = '<div class="version-status">';
    switch ($project['status']) {
      case UPDATE_STATUS_NOT_SECURE:
        $row .= '<span class="security-error">' . t('Security update required!') . '</span>';
        break;
      case UPDATE_STATUS_REVOKED:
        $row .= '<span class="revoked">' . t('Revoked!') . '</span>';
        break;
      case UPDATE_STATUS_NOT_SUPPORTED:
        $row .= '<span class="not-supported">' . t('Not supported!') . '</span>';
        break;
      case UPDATE_STATUS_NOT_CURRENT:
        $row .= '<span class="not-current">' . t('Update available') . '</span>';
        break;
      case UPDATE_STATUS_CURRENT:
        $row .= '<span class="current">' . t('Up to date') . '</span>';
        break;
      default:
        $row .= check_plain($project['reason']);
        break;
    }
    $row .= '<span class="icon">' . $icon . '</span>';
    $row .= "</div>\n";
    $row .= '<div class="project">';
    if (isset($project['title'])) {
      if (isset($project['link'])) {
        $row .= l($project['title'], $project['link']);
      }
      else {
        $row .= check_plain($project['title']);
      }
    }
    else {
      $row .= check_plain($project['name']);
    }
    $row .= ' ' . check_plain($project['existing_version']);
    if ($project['type'] == 'dev' && !empty($project['datestamp'])) {
      $row .= ' <span class="version-date">(' . format_date($project['datestamp'], 'custom', 'Y-M-d') . ')</span>';
    }
    $row .= "</div>\n";
    $row .= "<div class=\"versions\">\n";
    if (isset($project['recommended'])) {
      if ($project['status'] != UPDATE_STATUS_CURRENT || $project['existing_version'] !== $project['recommended']) {

        // First, figure out what to recommend.
        // If there's only 1 security update and it has the same version we're
        // recommending, give it the same CSS class as if it was recommended,
        // but don't print out a separate "Recommended" line for this project.
        if (!empty($project['security updates']) && count($project['security updates']) == 1 && $project['security updates'][0]['version'] === $project['recommended']) {
          $security_class = ' version-recommended version-recommended-strong';
        }
        else {
          $security_class = '';
          $version_class = 'version-recommended';

          // Apply an extra class if we're displaying both a recommended
          // version and anything else for an extra visual hint.
          if ($project['recommended'] !== $project['latest_version'] || !empty($project['also']) || $project['type'] == 'dev' && isset($project['dev_version']) && $project['latest_version'] !== $project['dev_version'] && $project['recommended'] !== $project['dev_version'] || isset($project['security updates'][0]) && $project['recommended'] !== $project['security updates'][0]) {
            $version_class .= ' version-recommended-strong';
          }
          $row .= theme('update_status_version', $project['releases'][$project['recommended']], t('Recommended version:'), $version_class);
        }

        // Now, print any security updates.
        if (!empty($project['security updates'])) {
          foreach ($project['security updates'] as $security_update) {
            $row .= theme('update_status_version', $security_update, t('Security update:'), 'version-security' . $security_class);
          }
        }
      }
      if ($project['recommended'] !== $project['latest_version']) {
        $row .= theme('update_status_version', $project['releases'][$project['latest_version']], t('Latest version:'), 'version-latest');
      }
      if ($project['type'] == 'dev' && $project['status'] != UPDATE_STATUS_CURRENT && isset($project['dev_version']) && $project['recommended'] !== $project['dev_version']) {
        $row .= theme('update_status_version', $project['releases'][$project['dev_version']], t('Development version:'), 'version-latest');
      }
    }
    if (isset($project['also'])) {
      foreach ($project['also'] as $also) {
        $row .= theme('update_status_version', $project['releases'][$also], t('Also available:'), 'version-also-available');
      }
    }
    $row .= "</div>\n";

    // versions div.
    $row .= "<div class=\"info\">\n";
    if (!empty($project['notes'])) {
      $row .= '<div class="notes">';
      $row .= t('Administrator note: %notes', array(
        '%notes' => $project['notes'],
      ));
      $row .= "</div>\n";
    }
    $row .= '<div class="modules">';
    $row .= t('Includes: %modules', array(
      '%modules' => implode(', ', $project['modules']),
    ));
    $row .= "</div>\n";
    $row .= "</div>\n";

    // info div.
    if (!isset($rows[$project['project_type']])) {
      $rows[$project['project_type']] = array();
    }
    $row_key = isset($project['title']) ? drupal_strtolower($project['title']) : drupal_strtolower($project['name']);
    $rows[$project['project_type']][$row_key] = array(
      'class' => $class,
      'data' => array(
        $row,
      ),
    );
  }
  $project_types = array(
    'core' => t('Drupal core'),
    'module' => t('Modules'),
    'disabled-module' => t('Disabled modules'),
  );
  foreach ($project_types as $type_name => $type_label) {
    if (!empty($rows[$type_name])) {
      ksort($rows[$type_name]);
      $output .= "\n<h3>" . $type_label . "</h3>\n";
      $output .= theme('table', $header, $rows[$type_name], array(
        'class' => 'update-status',
      ));
    }
  }
  drupal_add_css(drupal_get_path('module', 'update_status') . '/update_status.css');
  return $output;
}