update.report.inc

  1. drupal
    1. 6 modules/update/update.report.inc
    2. 7 modules/update/update.report.inc
    3. 8 core/modules/update/update.report.inc

Code required only when rendering the available updates report.

Functions & methods

NameDescription
theme_update_reportReturns HTML for the project status report.
theme_update_status_labelReturns HTML for a label to display for a project's update status.
theme_update_versionReturns HTML for the version display of a project.
update_statusMenu callback. Generate a page about the update status of projects.

File

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