home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / drupal-6.0.exe / drupal-6.0 / modules / update / update.report.inc < prev    next >
Encoding:
Text File  |  2008-02-05  |  8.4 KB  |  242 lines

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