|
1 <?php |
|
2 // $Id: update.report.inc,v 1.10.2.4 2009/06/09 11:08:32 goba 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', $data); |
|
17 } |
|
18 else { |
|
19 return theme('update_report', _update_no_data()); |
|
20 } |
|
21 } |
|
22 |
|
23 /** |
|
24 * Theme project status report. |
|
25 * |
|
26 * @ingroup themeable |
|
27 */ |
|
28 function theme_update_report($data) { |
|
29 $last = variable_get('update_last_check', 0); |
|
30 $output = '<div class="update checked">'. ($last ? t('Last checked: @time ago', array('@time' => format_interval(time() - $last))) : t('Last checked: never')); |
|
31 $output .= ' <span class="check-manually">('. l(t('Check manually'), 'admin/reports/updates/check') .')</span>'; |
|
32 $output .= "</div>\n"; |
|
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 foreach ($data as $project) { |
|
45 switch ($project['status']) { |
|
46 case UPDATE_CURRENT: |
|
47 $class = 'ok'; |
|
48 $icon = theme('image', 'misc/watchdog-ok.png', t('ok'), t('ok')); |
|
49 break; |
|
50 case UPDATE_UNKNOWN: |
|
51 case UPDATE_NOT_FETCHED: |
|
52 $class = 'unknown'; |
|
53 $icon = theme('image', 'misc/watchdog-warning.png', t('warning'), t('warning')); |
|
54 break; |
|
55 case UPDATE_NOT_SECURE: |
|
56 case UPDATE_REVOKED: |
|
57 case UPDATE_NOT_SUPPORTED: |
|
58 $class = 'error'; |
|
59 $icon = theme('image', 'misc/watchdog-error.png', t('error'), t('error')); |
|
60 break; |
|
61 case UPDATE_NOT_CHECKED: |
|
62 case UPDATE_NOT_CURRENT: |
|
63 default: |
|
64 $class = 'warning'; |
|
65 $icon = theme('image', 'misc/watchdog-warning.png', t('warning'), t('warning')); |
|
66 break; |
|
67 } |
|
68 |
|
69 $row = '<div class="version-status">'; |
|
70 switch ($project['status']) { |
|
71 case UPDATE_NOT_SECURE: |
|
72 $row .= '<span class="security-error">'. t('Security update required!') .'</span>'; |
|
73 break; |
|
74 case UPDATE_REVOKED: |
|
75 $row .= '<span class="revoked">'. t('Revoked!') .'</span>'; |
|
76 break; |
|
77 case UPDATE_NOT_SUPPORTED: |
|
78 $row .= '<span class="not-supported">'. t('Not supported!') .'</span>'; |
|
79 break; |
|
80 case UPDATE_NOT_CURRENT: |
|
81 $row .= '<span class="not-current">'. t('Update available') .'</span>'; |
|
82 break; |
|
83 case UPDATE_CURRENT: |
|
84 $row .= '<span class="current">'. t('Up to date') .'</span>'; |
|
85 break; |
|
86 default: |
|
87 $row .= check_plain($project['reason']); |
|
88 break; |
|
89 } |
|
90 $row .= '<span class="icon">'. $icon .'</span>'; |
|
91 $row .= "</div>\n"; |
|
92 |
|
93 $row .= '<div class="project">'; |
|
94 if (isset($project['title'])) { |
|
95 if (isset($project['link'])) { |
|
96 $row .= l($project['title'], $project['link']); |
|
97 } |
|
98 else { |
|
99 $row .= check_plain($project['title']); |
|
100 } |
|
101 } |
|
102 else { |
|
103 $row .= check_plain($project['name']); |
|
104 } |
|
105 $row .= ' '. check_plain($project['existing_version']); |
|
106 if ($project['install_type'] == 'dev' && !empty($project['datestamp'])) { |
|
107 $row .= ' <span class="version-date">('. format_date($project['datestamp'], 'custom', 'Y-M-d') .')</span>'; |
|
108 } |
|
109 $row .= "</div>\n"; |
|
110 |
|
111 $row .= "<div class=\"versions\">\n"; |
|
112 |
|
113 if (isset($project['recommended'])) { |
|
114 if ($project['status'] != UPDATE_CURRENT || $project['existing_version'] !== $project['recommended']) { |
|
115 |
|
116 // First, figure out what to recommend. |
|
117 // If there's only 1 security update and it has the same version we're |
|
118 // recommending, give it the same CSS class as if it was recommended, |
|
119 // but don't print out a separate "Recommended" line for this project. |
|
120 if (!empty($project['security updates']) && count($project['security updates']) == 1 && $project['security updates'][0]['version'] === $project['recommended']) { |
|
121 $security_class = ' version-recommended version-recommended-strong'; |
|
122 } |
|
123 else { |
|
124 $security_class = ''; |
|
125 $version_class = 'version-recommended'; |
|
126 // Apply an extra class if we're displaying both a recommended |
|
127 // version and anything else for an extra visual hint. |
|
128 if ($project['recommended'] !== $project['latest_version'] |
|
129 || !empty($project['also']) |
|
130 || ($project['install_type'] == 'dev' |
|
131 && isset($project['dev_version']) |
|
132 && $project['latest_version'] !== $project['dev_version'] |
|
133 && $project['recommended'] !== $project['dev_version']) |
|
134 || (isset($project['security updates'][0]) |
|
135 && $project['recommended'] !== $project['security updates'][0]) |
|
136 ) { |
|
137 $version_class .= ' version-recommended-strong'; |
|
138 } |
|
139 $row .= theme('update_version', $project['releases'][$project['recommended']], t('Recommended version:'), $version_class); |
|
140 } |
|
141 |
|
142 // Now, print any security updates. |
|
143 if (!empty($project['security updates'])) { |
|
144 foreach ($project['security updates'] as $security_update) { |
|
145 $row .= theme('update_version', $security_update, t('Security update:'), 'version-security'. $security_class); |
|
146 } |
|
147 } |
|
148 } |
|
149 |
|
150 if ($project['recommended'] !== $project['latest_version']) { |
|
151 $row .= theme('update_version', $project['releases'][$project['latest_version']], t('Latest version:'), 'version-latest'); |
|
152 } |
|
153 if ($project['install_type'] == 'dev' |
|
154 && $project['status'] != UPDATE_CURRENT |
|
155 && isset($project['dev_version']) |
|
156 && $project['recommended'] !== $project['dev_version']) { |
|
157 $row .= theme('update_version', $project['releases'][$project['dev_version']], t('Development version:'), 'version-latest'); |
|
158 } |
|
159 } |
|
160 |
|
161 if (isset($project['also'])) { |
|
162 foreach ($project['also'] as $also) { |
|
163 $row .= theme('update_version', $project['releases'][$also], t('Also available:'), 'version-also-available'); |
|
164 } |
|
165 } |
|
166 |
|
167 $row .= "</div>\n"; // versions div. |
|
168 |
|
169 $row .= "<div class=\"info\">\n"; |
|
170 if (!empty($project['extra'])) { |
|
171 $row .= '<div class="extra">'."\n"; |
|
172 foreach ($project['extra'] as $key => $value) { |
|
173 $row .= '<div class="'. $value['class'] .'">'; |
|
174 $row .= check_plain($value['label']) .': '; |
|
175 $row .= theme('placeholder', $value['data']); |
|
176 $row .= "</div>\n"; |
|
177 } |
|
178 $row .= "</div>\n"; // extra div. |
|
179 } |
|
180 |
|
181 $row .= '<div class="includes">'; |
|
182 sort($project['includes']); |
|
183 $row .= t('Includes: %includes', array('%includes' => implode(', ', $project['includes']))); |
|
184 $row .= "</div>\n"; |
|
185 |
|
186 $row .= "</div>\n"; // info div. |
|
187 |
|
188 if (!isset($rows[$project['project_type']])) { |
|
189 $rows[$project['project_type']] = array(); |
|
190 } |
|
191 $rows[$project['project_type']][] = array( |
|
192 'class' => $class, |
|
193 'data' => array($row), |
|
194 ); |
|
195 } |
|
196 |
|
197 $project_types = array( |
|
198 'core' => t('Drupal core'), |
|
199 'module' => t('Modules'), |
|
200 'theme' => t('Themes'), |
|
201 'disabled-module' => t('Disabled modules'), |
|
202 'disabled-theme' => t('Disabled themes'), |
|
203 ); |
|
204 foreach ($project_types as $type_name => $type_label) { |
|
205 if (!empty($rows[$type_name])) { |
|
206 $output .= "\n<h3>". $type_label ."</h3>\n"; |
|
207 $output .= theme('table', $header, $rows[$type_name], array('class' => 'update')); |
|
208 } |
|
209 } |
|
210 drupal_add_css(drupal_get_path('module', 'update') .'/update.css'); |
|
211 return $output; |
|
212 } |
|
213 |
|
214 /** |
|
215 * Theme the version display of a project. |
|
216 * |
|
217 * @ingroup themeable |
|
218 */ |
|
219 function theme_update_version($version, $tag, $class) { |
|
220 $output = ''; |
|
221 $output .= '<table class="version '. $class .'">'; |
|
222 $output .= '<tr>'; |
|
223 $output .= '<td class="version-title">'. $tag ."</td>\n"; |
|
224 $output .= '<td class="version-details">'; |
|
225 $output .= l($version['version'], $version['release_link']); |
|
226 $output .= ' <span class="version-date">('. format_date($version['date'], 'custom', 'Y-M-d') .')</span>'; |
|
227 $output .= "</td>\n"; |
|
228 $output .= '<td class="version-links">'; |
|
229 $links = array(); |
|
230 $links['update-download'] = array( |
|
231 'title' => t('Download'), |
|
232 'href' => $version['download_link'], |
|
233 ); |
|
234 $links['update-release-notes'] = array( |
|
235 'title' => t('Release notes'), |
|
236 'href' => $version['release_link'], |
|
237 ); |
|
238 $output .= theme('links', $links); |
|
239 $output .= '</td>'; |
|
240 $output .= '</tr>'; |
|
241 $output .= "</table>\n"; |
|
242 return $output; |
|
243 } |