prod_monitor.theme.inc 14 KB

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