[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/modules/update/ -> update.report.inc (source)

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


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7