update.report.inc

Code required only when rendering the available updates report.

Archivo

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

Functions

Nombreorden descendente Descripción
theme_update_report Theme project status report.
theme_update_version Theme the version display of a project.
update_status Menu callback. Generate a page about the update status of projects.