prod_monitor.theme.inc 14 KB

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