update.report.inc 12 KB

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