update.report.inc 11.8 KB
Newer Older
1 2 3 4 5 6 7 8
<?php

/**
 * @file
 * Code required only when rendering the available updates report.
 */

/**
9 10
 * Returns HTML for the project status report.
 *
11
 * @param array $variables
12 13
 *   An associative array containing:
 *   - data: An array of data about each project's status.
14 15
 *
 * @ingroup themeable
16
 */
17 18 19
function theme_update_report($variables) {
  $data = $variables['data'];

20
  $last = Drupal::state()->get('update.last_check') ?: 0;
21
  $output = theme('update_last_check', array('last' => $last));
22 23

  if (!is_array($data)) {
24
    $output .= '<p>' . $data . '</p>';
25 26 27 28 29 30
    return $output;
  }

  $header = array();
  $rows = array();

31
  $notification_level = config('update.settings')->get('notification.threshold');
32

33 34 35 36 37 38 39 40 41
  // Create an array of status values keyed by module or theme name, since
  // we'll need this while generating the report if we have to cross reference
  // anything (e.g. subthemes which have base themes missing an update).
  foreach ($data as $project) {
    foreach ($project['includes'] as $key => $name) {
      $status[$key] = $project['status'];
    }
  }

42 43 44 45
  foreach ($data as $project) {
    switch ($project['status']) {
      case UPDATE_CURRENT:
        $class = 'ok';
46
        $icon = theme('image', array('uri' => 'core/misc/watchdog-ok.png', 'width' => 18, 'height' => 18, 'alt' => t('ok'), 'title' => t('ok')));
47
        break;
48
      case UPDATE_UNKNOWN:
49
      case UPDATE_FETCH_PENDING:
50
      case UPDATE_NOT_FETCHED:
51
        $class = 'unknown';
52
        $icon = theme('image', array('uri' => 'core/misc/watchdog-warning.png', 'width' => 18, 'height' => 18, 'alt' => t('warning'), 'title' => t('warning')));
53
        break;
54
      case UPDATE_NOT_SECURE:
55 56
      case UPDATE_REVOKED:
      case UPDATE_NOT_SUPPORTED:
57
        $class = 'error';
58
        $icon = theme('image', array('uri' => 'core/misc/watchdog-error.png', 'width' => 18, 'height' => 18, 'alt' => t('error'), 'title' => t('error')));
59 60
        break;
      case UPDATE_NOT_CHECKED:
61 62 63
      case UPDATE_NOT_CURRENT:
      default:
        $class = 'warning';
64
        $icon = theme('image', array('uri' => 'core/misc/watchdog-warning.png', 'width' => 18, 'height' => 18, 'alt' => t('warning'), 'title' => t('warning')));
65 66 67 68
        break;
    }

    $row = '<div class="version-status">';
69
    $status_label = theme('update_status_label', array('status' => $project['status']));
70
    $row .= !empty($status_label) ? $status_label : check_plain($project['reason']);
71
    $row .= '<span class="icon">' . $icon . '</span>';
72 73 74 75 76 77 78 79 80 81 82 83 84 85
    $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']);
    }
86
    $row .= ' ' . check_plain($project['existing_version']);
87
    if ($project['install_type'] == 'dev' && !empty($project['datestamp'])) {
88
      $row .= ' <span class="version-date">(' . format_date($project['datestamp'], 'custom', 'Y-M-d') . ')</span>';
89 90 91
    }
    $row .= "</div>\n";

92 93 94
    $versions_inner = '';
    $security_class = array();
    $version_class = array();
95
    if (isset($project['recommended'])) {
96
      if ($project['status'] != UPDATE_CURRENT || $project['existing_version'] !== $project['recommended']) {
97 98 99 100 101

        // 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.
102
        if (!empty($project['security updates']) && count($project['security updates']) == 1 && $project['security updates'][0]['version'] === $project['recommended']) {
103 104
          $security_class[] = 'version-recommended';
          $security_class[] = 'version-recommended-strong';
105 106
        }
        else {
107
          $version_class[] = 'version-recommended';
108 109
          // Apply an extra class if we're displaying both a recommended
          // version and anything else for an extra visual hint.
110
          if ($project['recommended'] !== $project['latest_version']
111 112
              || !empty($project['also'])
              || ($project['install_type'] == 'dev'
113 114 115
                && isset($project['dev_version'])
                && $project['latest_version'] !== $project['dev_version']
                && $project['recommended'] !== $project['dev_version'])
116
              || (isset($project['security updates'][0])
117
                && $project['recommended'] !== $project['security updates'][0])
118
              ) {
119
            $version_class[] = 'version-recommended-strong';
120
          }
121
          $versions_inner .= theme('update_version', array('version' => $project['releases'][$project['recommended']], 'tag' => t('Recommended version:'), 'class' => $version_class));
122 123 124 125
        }

        // Now, print any security updates.
        if (!empty($project['security updates'])) {
126
          $security_class[] = 'version-security';
127
          foreach ($project['security updates'] as $security_update) {
128
            $versions_inner .= theme('update_version', array('version' => $security_update, 'tag' => t('Security update:'), 'class' => $security_class));
129 130 131 132
          }
        }
      }

133
      if ($project['recommended'] !== $project['latest_version']) {
134
        $versions_inner .= theme('update_version', array('version' => $project['releases'][$project['latest_version']], 'tag' => t('Latest version:'), 'class' => array('version-latest')));
135 136 137
      }
      if ($project['install_type'] == 'dev'
          && $project['status'] != UPDATE_CURRENT
138
          && isset($project['dev_version'])
139
          && $project['recommended'] !== $project['dev_version']) {
140
        $versions_inner .= theme('update_version', array('version' => $project['releases'][$project['dev_version']], 'tag' => t('Development version:'), 'class' => array('version-latest')));
141 142 143 144 145
      }
    }

    if (isset($project['also'])) {
      foreach ($project['also'] as $also) {
146
        $versions_inner .= theme('update_version', array('version' => $project['releases'][$also], 'tag' => t('Also available:'), 'class' => array('version-also-available')));
147 148 149
      }
    }

150 151 152
    if (!empty($versions_inner)) {
      $row .= "<div class=\"versions\">\n" . $versions_inner . "</div>\n";
    }
153 154
    $row .= "<div class=\"info\">\n";
    if (!empty($project['extra'])) {
155
      $row .= '<div class="extra">' . "\n";
156
      foreach ($project['extra'] as $key => $value) {
157
        $row .= '<div class="' . implode(' ', $value['class']) . '">';
158
        $row .= check_plain($value['label']) . ': ';
159
        $row .= drupal_placeholder($value['data']);
160 161 162 163 164 165 166
        $row .= "</div>\n";
      }
      $row .= "</div>\n";  // extra div.
    }

    $row .= '<div class="includes">';
    sort($project['includes']);
167 168 169 170 171 172 173
    if (!empty($project['disabled'])) {
      sort($project['disabled']);
      // Make sure we start with a clean slate for each project in the report.
      $includes_items = array();
      $row .= t('Includes:');
      $includes_items[] = t('Enabled: %includes', array('%includes' => implode(', ', $project['includes'])));
      $includes_items[] = t('Disabled: %disabled', array('%disabled' => implode(', ', $project['disabled'])));
174
      $row .= theme('item_list', array('items' => $includes_items));
175 176 177 178
    }
    else {
      $row .= t('Includes: %includes', array('%includes' => implode(', ', $project['includes'])));
    }
179 180
    $row .= "</div>\n";

181 182 183 184 185 186 187 188 189
    if (!empty($project['base_themes'])) {
      $row .= '<div class="basethemes">';
      asort($project['base_themes']);
      $base_themes = array();
      foreach ($project['base_themes'] as $base_key => $base_theme) {
        switch ($status[$base_key]) {
          case UPDATE_NOT_SECURE:
          case UPDATE_REVOKED:
          case UPDATE_NOT_SUPPORTED:
190
            $base_themes[] = t('%base_theme (!base_label)', array('%base_theme' => $base_theme, '!base_label' => theme('update_status_label', array('status' => $status[$base_key]))));
191
            break;
192

193
          default:
194
            $base_themes[] = drupal_placeholder($base_theme);
195 196 197 198 199 200 201 202 203 204 205 206 207
        }
      }
      $row .= t('Depends on: !basethemes', array('!basethemes' => implode(', ', $base_themes)));
      $row .= "</div>\n";
    }

    if (!empty($project['sub_themes'])) {
      $row .= '<div class="subthemes">';
      sort($project['sub_themes']);
      $row .= t('Required by: %subthemes', array('%subthemes' => implode(', ', $project['sub_themes'])));
      $row .= "</div>\n";
    }

208 209 210 211 212
    $row .= "</div>\n"; // info div.

    if (!isset($rows[$project['project_type']])) {
      $rows[$project['project_type']] = array();
    }
213 214
    $row_key = isset($project['title']) ? drupal_strtolower($project['title']) : drupal_strtolower($project['name']);
    $rows[$project['project_type']][$row_key] = array(
215
      'class' => array($class),
216 217 218 219 220 221 222 223
      'data' => array($row),
    );
  }

  $project_types = array(
    'core' => t('Drupal core'),
    'module' => t('Modules'),
    'theme' => t('Themes'),
224 225
    'module-disabled' => t('Disabled modules'),
    'theme-disabled' => t('Disabled themes'),
226 227 228
  );
  foreach ($project_types as $type_name => $type_label) {
    if (!empty($rows[$type_name])) {
229
      ksort($rows[$type_name]);
230
      $output .= "\n<h3>" . $type_label . "</h3>\n";
231
      $output .= theme('table', array('header' => $header, 'rows' => $rows[$type_name], 'attributes' => array('class' => array('update'))));
232 233
    }
  }
234
  drupal_add_css(drupal_get_path('module', 'update') . '/update.css');
235 236 237
  return $output;
}

238
/**
239
 * Returns HTML for a label to display for a project's update status.
240
 *
241
 * @param array $variables
242 243
 *   An associative array containing:
 *   - status: The integer code for a project's current update status.
244 245
 *
 * @see update_calculate_project_data()
246
 * @ingroup themeable
247
 */
248 249
function theme_update_status_label($variables) {
  switch ($variables['status']) {
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
    case UPDATE_NOT_SECURE:
      return '<span class="security-error">' . t('Security update required!') . '</span>';

    case UPDATE_REVOKED:
      return '<span class="revoked">' . t('Revoked!') . '</span>';

    case UPDATE_NOT_SUPPORTED:
      return '<span class="not-supported">' . t('Not supported!') . '</span>';

    case UPDATE_NOT_CURRENT:
      return '<span class="not-current">' . t('Update available') . '</span>';

    case UPDATE_CURRENT:
      return '<span class="current">' . t('Up to date') . '</span>';

  }
}

268
/**
269 270
 * Returns HTML for the version display of a project.
 *
271
 * @param array $variables
272 273 274 275 276 277 278 279
 *   An associative array containing:
 *   - version: An array of data about the latest released version, containing:
 *     - version: The version number.
 *     - release_link: The URL for the release notes.
 *     - date: The date of the release.
 *     - download_link: The URL for the downloadable file.
 *   - tag: The title of the project.
 *   - class: A string containing extra classes for the wrapping table.
280 281 282
 *
 * @ingroup themeable
 */
283 284 285
function theme_update_version($variables) {
  $version = $variables['version'];
  $tag = $variables['tag'];
286
  $class = implode(' ', $variables['class']);
287

288
  $output = '';
289
  $output .= '<table class="version ' . $class . '">';
290
  $output .= '<tr>';
291
  $output .= '<td class="version-title">' . $tag . "</td>\n";
292 293
  $output .= '<td class="version-details">';
  $output .= l($version['version'], $version['release_link']);
294
  $output .= ' <span class="version-date">(' . format_date($version['date'], 'custom', 'Y-M-d') . ')</span>';
295 296 297 298 299 300 301 302 303 304 305
  $output .= "</td>\n";
  $output .= '<td class="version-links">';
  $links = array();
  $links['update-download'] = array(
    'title' => t('Download'),
    'href' => $version['download_link'],
  );
  $links['update-release-notes'] = array(
    'title' => t('Release notes'),
    'href' => $version['release_link'],
  );
306
  $output .= theme('links__update_version', array('links' => $links));
307 308 309 310 311
  $output .= '</td>';
  $output .= '</tr>';
  $output .= "</table>\n";
  return $output;
}