You are here

function theme_update_detailed_email_message in Update Status Detailed Email 6

Same name and namespace in other branches
  1. 7 update_detailed_email.module \theme_update_detailed_email_message()

Theme the detailed update email.

Much of the code is taken from the original theme_update_report(). The changes are primarily focused on making the outputted HTML more email-friendly.

Parameters

$data: An array of update information for installed modules.

Return value

Themed output.

1 theme call to theme_update_detailed_email_message()
theme_update_detailed_email in ./update_detailed_email.module
Theme function to override the original update theme function.

File

./update_detailed_email.module, line 145
Adds detail to the email message Drupal core's Update Status sends.

Code

function theme_update_detailed_email_message($data) {
  $output = '<html><head><meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">';
  $output .= "<title>Update Status</title></head><body>\n";
  if (!is_array($data)) {
    $output .= '<p>' . $data . '</p>';
    return $output;
  }
  $rows = array();
  $notification_level = variable_get('update_notification_threshold', 'all');
  foreach ($data as $project) {

    // Don't include modules that are up to date.
    // If set to only notify of security updates, don't include non-security updates in the email.
    if ($notification_level == 'all' && $project['status'] != UPDATE_CURRENT || $notification_level == 'security' && $project['status'] == UPDATE_NOT_SECURE) {
      $row = '<p>';
      switch ($project['status']) {
        case UPDATE_NOT_SECURE:
          $row .= t('Security update required!');
          break;
        case UPDATE_REVOKED:
          $row .= t('Revoked!');
          break;
        case UPDATE_NOT_SUPPORTED:
          $row .= t('Not supported!');
          break;
        case UPDATE_NOT_CURRENT:
          $row .= t('Update available');
          break;
        default:
          $row .= check_plain($project['reason']);
          break;
      }
      $row .= "<br />\n";

      // Project title
      if (isset($project['title'])) {
        if (isset($project['link'])) {
          $row .= l($project['title'], $project['link']);
        }
        else {
          $row .= check_plain($project['title']);
        }
      }
      else {
        $row .= check_plain($project['name']);
      }

      // Project version
      $row .= ' ' . check_plain($project['existing_version']);

      // Project date
      if ($project['install_type'] == 'dev' && !empty($project['datestamp'])) {
        $row .= ' (' . format_date($project['datestamp'], 'custom', 'Y-M-d') . ')';
      }

      // Versions
      if (isset($project['recommended'])) {

        // Recommended
        if ($project['existing_version'] !== $project['recommended']) {
          $row .= theme('update_detailed_email_message_version', $project['releases'][$project['recommended']], 'Recommended version:');

          // Now, print any security updates.
          if (!empty($project['security updates'])) {
            foreach ($project['security updates'] as $security_update) {
              $row .= theme('update_detailed_email_message_version', $security_update, 'Security update:');
            }
          }
        }

        // Latest
        if ($project['recommended'] !== $project['latest_version']) {
          $row .= theme('update_detailed_email_message_version', $project['releases'][$project['latest_version']], 'Latest version:');
        }

        // Development
        if ($project['install_type'] == 'dev' && isset($project['dev_version']) && $project['recommended'] !== $project['dev_version']) {
          $row .= theme('update_detailed_email_message_version', $project['releases'][$project['dev_version']], 'Development version:');
        }
      }

      // Also available
      if (isset($project['also'])) {
        foreach ($project['also'] as $also) {
          $row .= theme('update_detailed_email_message_version', $project['releases'][$also], 'Also available:');
        }
      }
      $row .= "<br />\n";

      // Extra
      if (!empty($project['extra'])) {
        foreach ($project['extra'] as $key => $value) {
          $row .= check_plain($value['label']) . ': ';
          $row .= theme('placeholder', $value['data']);
          $row .= '<br />';
        }
      }

      // Includes
      sort($project['includes']);
      $row .= t('Includes: %includes', array(
        '%includes' => implode(', ', $project['includes']),
      ));

      // Base themes
      if (!empty($project['base_themes'])) {
        sort($project['base_themes']);

        // We use !dependencies and manually call theme('placeholder') here to
        // avoid breakding the D6 string freeze. This identical string is
        // already in modules/system/system.admin.inc.
        $row .= "<br />\n";
        $row .= t('Depends on: !dependencies', array(
          '!dependencies' => theme('placeholder', implode(', ', $project['base_themes'])),
        ));
      }

      // Sub-themes
      if (!empty($project['sub_themes'])) {
        sort($project['sub_themes']);

        // We use !required and manually call theme('placeholder') here to avoid
        // breakding the D6 string freeze. This identical string is already in
        // modules/system/system.admin.inc.
        $row .= "<br />\n";
        $row .= t('Required by: !required', array(
          '!required' => theme('placeholder', implode(', ', $project['sub_themes'])),
        ));
      }
      $row .= "</p>\n";
      if (!isset($rows[$project['project_type']])) {
        $rows[$project['project_type']] = array();
      }
      $row_key = isset($project['title']) ? drupal_strtolower($project['title']) : drupal_strtolower($project['name']);
      $rows[$project['project_type']][$row_key] = array(
        'data' => array(
          $row,
        ),
      );
    }
  }
  $project_types = array(
    'core' => t('Drupal core'),
    'module' => t('Modules'),
    'theme' => t('Themes'),
    'disabled-module' => t('Disabled modules'),
    'disabled-theme' => t('Disabled themes'),
  );
  foreach ($project_types as $type_name => $type_label) {
    if (!empty($rows[$type_name])) {
      ksort($rows[$type_name]);
      $output .= '<p><strong>' . $type_label . "</strong></p>\n";
      foreach ($rows[$type_name] as $list) {
        $output .= $list['data'][0];
      }
    }
  }
  $output .= '</body></html>';
  return $output;
}