/[drupal]/drupal/modules/update/update.report.inc
ViewVC logotype

Contents of /drupal/modules/update/update.report.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.27 - (show annotations) (download) (as text)
Fri Oct 23 22:24:19 2009 UTC (4 weeks, 6 days ago) by webchick
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-10, HEAD
Changes since 1.26: +2 -2 lines
File MIME type: text/x-php
#600974 by effulgentsia, JohnAlbin, sun, and Damien Tournoud: Allow theme functions to take one argument without any hacks. NOTE: This is an API change in hook_theme().
1 <?php
2 // $Id: update.report.inc,v 1.26 2009/10/15 21:19:31 webchick Exp $
3
4 /**
5 * @file
6 * Code required only when rendering the available updates report.
7 */
8
9 /**
10 * Menu callback. Generate a page about the update status of projects.
11 */
12 function update_status() {
13 if ($available = update_get_available(TRUE)) {
14 module_load_include('inc', 'update', 'update.compare');
15 $data = update_calculate_project_data($available);
16 return theme('update_report', array('data' => $data));
17 }
18 else {
19 return theme('update_report', array('data' => _update_no_data()));
20 }
21 }
22
23 /**
24 * Theme project status report.
25 *
26 * @ingroup themeable
27 */
28 function theme_update_report($variables) {
29 $data = $variables['data'];
30
31 $last = variable_get('update_last_check', 0);
32 $output = theme('update_last_check', array('last' => $last));
33
34 if (!is_array($data)) {
35 $output .= '<p>' . $data . '</p>';
36 return $output;
37 }
38
39 $header = array();
40 $rows = array();
41
42 $notification_level = variable_get('update_notification_threshold', 'all');
43
44 // Create an array of status values keyed by module or theme name, since
45 // we'll need this while generating the report if we have to cross reference
46 // anything (e.g. subthemes which have base themes missing an update).
47 foreach ($data as $project) {
48 foreach ($project['includes'] as $key => $name) {
49 $status[$key] = $project['status'];
50 }
51 }
52
53 foreach ($data as $project) {
54 switch ($project['status']) {
55 case UPDATE_CURRENT:
56 $class = 'ok';
57 $icon = theme('image', array('path' => 'misc/watchdog-ok.png', 'alt' => t('ok'), 'title' => t('ok')));
58 break;
59 case UPDATE_UNKNOWN:
60 case UPDATE_FETCH_PENDING:
61 case UPDATE_NOT_FETCHED:
62 $class = 'unknown';
63 $icon = theme('image', array('path' => 'misc/watchdog-warning.png', 'alt' => t('warning'), 'title' => t('warning')));
64 break;
65 case UPDATE_NOT_SECURE:
66 case UPDATE_REVOKED:
67 case UPDATE_NOT_SUPPORTED:
68 $class = 'error';
69 $icon = theme('image', array('path' => 'misc/watchdog-error.png', 'alt' => t('error'), 'title' => t('error')));
70 break;
71 case UPDATE_NOT_CHECKED:
72 case UPDATE_NOT_CURRENT:
73 default:
74 $class = 'warning';
75 $icon = theme('image', array('path' => 'misc/watchdog-warning.png', 'alt' => t('warning'), 'title' => t('warning')));
76 break;
77 }
78
79 $row = '<div class="version-status">';
80 $status_label = theme('update_status_label', array('status' => $project['status']));
81 $row .= !empty($status_label) ? $status_label : check_plain($project['reason']);
82 $row .= '<span class="icon">' . $icon . '</span>';
83 $row .= "</div>\n";
84
85 $row .= '<div class="project">';
86 if (isset($project['title'])) {
87 if (isset($project['link'])) {
88 $row .= l($project['title'], $project['link']);
89 }
90 else {
91 $row .= check_plain($project['title']);
92 }
93 }
94 else {
95 $row .= check_plain($project['name']);
96 }
97 $row .= ' ' . check_plain($project['existing_version']);
98 if ($project['install_type'] == 'dev' && !empty($project['datestamp'])) {
99 $row .= ' <span class="version-date">(' . format_date($project['datestamp'], 'custom', 'Y-M-d') . ')</span>';
100 }
101 $row .= "</div>\n";
102
103 $row .= "<div class=\"versions\">\n";
104
105 if (isset($project['recommended'])) {
106 if ($project['status'] != UPDATE_CURRENT || $project['existing_version'] !== $project['recommended']) {
107
108 // First, figure out what to recommend.
109 // If there's only 1 security update and it has the same version we're
110 // recommending, give it the same CSS class as if it was recommended,
111 // but don't print out a separate "Recommended" line for this project.
112 if (!empty($project['security updates']) && count($project['security updates']) == 1 && $project['security updates'][0]['version'] === $project['recommended']) {
113 $security_class = ' version-recommended version-recommended-strong';
114 }
115 else {
116 $security_class = array();
117 $version_class[] = 'version-recommended';
118 // Apply an extra class if we're displaying both a recommended
119 // version and anything else for an extra visual hint.
120 if ($project['recommended'] !== $project['latest_version']
121 || !empty($project['also'])
122 || ($project['install_type'] == 'dev'
123 && isset($project['dev_version'])
124 && $project['latest_version'] !== $project['dev_version']
125 && $project['recommended'] !== $project['dev_version'])
126 || (isset($project['security updates'][0])
127 && $project['recommended'] !== $project['security updates'][0])
128 ) {
129 $version_class[] = 'version-recommended-strong';
130 }
131 $row .= theme('update_version', array('version' => $project['releases'][$project['recommended']], 'tag' => t('Recommended version:'), 'class' => $version_class));
132 }
133
134 // Now, print any security updates.
135 if (!empty($project['security updates'])) {
136 foreach ($project['security updates'] as $security_update) {
137 $row .= theme('update_version', array('version' => $security_update, 'tag' => t('Security update:'), 'class' => 'version-security' . $security_class));
138 }
139 }
140 }
141
142 if ($project['recommended'] !== $project['latest_version']) {
143 $row .= theme('update_version', array('version' => $project['releases'][$project['latest_version']], 'tag' => t('Latest version:'), 'class' => array('version-latest')));
144 }
145 if ($project['install_type'] == 'dev'
146 && $project['status'] != UPDATE_CURRENT
147 && isset($project['dev_version'])
148 && $project['recommended'] !== $project['dev_version']) {
149 $row .= theme('update_version', array('version' => $project['releases'][$project['dev_version']], 'tag' => t('Development version:'), 'class' => array('version-latest')));
150 }
151 }
152
153 if (isset($project['also'])) {
154 foreach ($project['also'] as $also) {
155 $row .= theme('update_version', array('version' => $project['releases'][$also], 'tag' => t('Also available:'), 'class' => array('version-also-available')));
156 }
157 }
158
159 $row .= "</div>\n"; // versions div.
160
161 $row .= "<div class=\"info\">\n";
162 if (!empty($project['extra'])) {
163 $row .= '<div class="extra">' . "\n";
164 foreach ($project['extra'] as $key => $value) {
165 $row .= '<div class="' . implode(' ', $value['class']) . '">';
166 $row .= check_plain($value['label']) . ': ';
167 $row .= theme('placeholder', array('text' => $value['data']));
168 $row .= "</div>\n";
169 }
170 $row .= "</div>\n"; // extra div.
171 }
172
173 $row .= '<div class="includes">';
174 sort($project['includes']);
175 if (!empty($project['disabled'])) {
176 sort($project['disabled']);
177 // Make sure we start with a clean slate for each project in the report.
178 $includes_items = array();
179 $row .= t('Includes:');
180 $includes_items[] = t('Enabled: %includes', array('%includes' => implode(', ', $project['includes'])));
181 $includes_items[] = t('Disabled: %disabled', array('%disabled' => implode(', ', $project['disabled'])));
182 $row .= theme('item_list', array('items' => $includes_items));
183 }
184 else {
185 $row .= t('Includes: %includes', array('%includes' => implode(', ', $project['includes'])));
186 }
187 $row .= "</div>\n";
188
189 if (!empty($project['base_themes'])) {
190 $row .= '<div class="basethemes">';
191 asort($project['base_themes']);
192 $base_themes = array();
193 foreach ($project['base_themes'] as $base_key => $base_theme) {
194 switch ($status[$base_key]) {
195 case UPDATE_NOT_SECURE:
196 case UPDATE_REVOKED:
197 case UPDATE_NOT_SUPPORTED:
198 $base_themes[] = t('%base_theme (!base_label)', array('%base_theme' => $base_theme, '!base_label' => theme('update_status_label', array('status' => $status[$base_key]))));
199 break;
200
201 default:
202 $base_themes[] = theme('placeholder', array('text' => $base_theme));
203 }
204 }
205 $row .= t('Depends on: !basethemes', array('!basethemes' => implode(', ', $base_themes)));
206 $row .= "</div>\n";
207 }
208
209 if (!empty($project['sub_themes'])) {
210 $row .= '<div class="subthemes">';
211 sort($project['sub_themes']);
212 $row .= t('Required by: %subthemes', array('%subthemes' => implode(', ', $project['sub_themes'])));
213 $row .= "</div>\n";
214 }
215
216 $row .= "</div>\n"; // info div.
217
218 if (!isset($rows[$project['project_type']])) {
219 $rows[$project['project_type']] = array();
220 }
221 $row_key = isset($project['title']) ? drupal_strtolower($project['title']) : drupal_strtolower($project['name']);
222 $rows[$project['project_type']][$row_key] = array(
223 'class' => array($class),
224 'data' => array($row),
225 );
226 }
227
228 $project_types = array(
229 'core' => t('Drupal core'),
230 'module' => t('Modules'),
231 'theme' => t('Themes'),
232 'module-disabled' => t('Disabled modules'),
233 'theme-disabled' => t('Disabled themes'),
234 );
235 foreach ($project_types as $type_name => $type_label) {
236 if (!empty($rows[$type_name])) {
237 ksort($rows[$type_name]);
238 $output .= "\n<h3>" . $type_label . "</h3>\n";
239 $output .= theme('table', array('header' => $header, 'rows' => $rows[$type_name], 'attributes' => array('class' => array('update'))));
240 }
241 }
242 drupal_add_css(drupal_get_path('module', 'update') . '/update.css');
243 return $output;
244 }
245
246 /**
247 * Generate the HTML for the label to display for a project's update status.
248 *
249 * @param $variables
250 * An associative array containing:
251 * - status: The integer code for a project's current update status.
252 *
253 * @see update_calculate_project_data()
254 */
255 function theme_update_status_label($variables) {
256 switch ($variables['status']) {
257 case UPDATE_NOT_SECURE:
258 return '<span class="security-error">' . t('Security update required!') . '</span>';
259
260 case UPDATE_REVOKED:
261 return '<span class="revoked">' . t('Revoked!') . '</span>';
262
263 case UPDATE_NOT_SUPPORTED:
264 return '<span class="not-supported">' . t('Not supported!') . '</span>';
265
266 case UPDATE_NOT_CURRENT:
267 return '<span class="not-current">' . t('Update available') . '</span>';
268
269 case UPDATE_CURRENT:
270 return '<span class="current">' . t('Up to date') . '</span>';
271
272 }
273 }
274
275 /**
276 * Theme the version display of a project.
277 *
278 * @ingroup themeable
279 */
280 function theme_update_version($variables) {
281 $version = $variables['version'];
282 $tag = $variables['tag'];
283 $class = $variables['class'];
284
285 $output = '';
286 $output .= '<table class="version ' . $class . '">';
287 $output .= '<tr>';
288 $output .= '<td class="version-title">' . $tag . "</td>\n";
289 $output .= '<td class="version-details">';
290 $output .= l($version['version'], $version['release_link']);
291 $output .= ' <span class="version-date">(' . format_date($version['date'], 'custom', 'Y-M-d') . ')</span>';
292 $output .= "</td>\n";
293 $output .= '<td class="version-links">';
294 $links = array();
295 $links['update-download'] = array(
296 'title' => t('Download'),
297 'href' => $version['download_link'],
298 );
299 $links['update-release-notes'] = array(
300 'title' => t('Release notes'),
301 'href' => $version['release_link'],
302 );
303 $output .= theme('links', array('links' => $links));
304 $output .= '</td>';
305 $output .= '</tr>';
306 $output .= "</table>\n";
307 return $output;
308 }

  ViewVC Help
Powered by ViewVC 1.1.2