webmaster@1: '. t('Here you can find information about available updates for your installed modules and themes. Note that each module or theme is part of a "project", which may or may not have the same name, and might include multiple modules or themes within it.') .'

'; webmaster@1: $output .= '

'. t('To extend the functionality or to change the look of your site, a number of contributed modules and themes are available.', array('@modules' => 'http://drupal.org/project/modules', '@themes' => 'http://drupal.org/project/themes')) .'

'; webmaster@1: return $output; webmaster@1: case 'admin/build/themes': webmaster@1: case 'admin/build/modules': webmaster@1: include_once './includes/install.inc'; webmaster@1: $status = update_requirements('runtime'); webmaster@1: foreach (array('core', 'contrib') as $report_type) { webmaster@1: $type = 'update_'. $report_type; webmaster@1: if (isset($status[$type]['severity'])) { webmaster@1: if ($status[$type]['severity'] == REQUIREMENT_ERROR) { webmaster@1: drupal_set_message($status[$type]['description'], 'error'); webmaster@1: } webmaster@1: elseif ($status[$type]['severity'] == REQUIREMENT_WARNING) { webmaster@1: drupal_set_message($status[$type]['description'], 'warning'); webmaster@1: } webmaster@1: } webmaster@1: } webmaster@1: return '

'. t('See the available updates page for information on installed modules and themes with new versions released.', array('@available_updates' => url('admin/reports/updates'))) .'

'; webmaster@1: webmaster@1: case 'admin/reports/updates/settings': webmaster@1: case 'admin/reports/status': webmaster@1: // These two pages don't need additional nagging. webmaster@1: break; webmaster@1: webmaster@1: case 'admin/help#update': webmaster@1: $output = '

'. t("The Update status module periodically checks for new versions of your site's software (including contributed modules and themes), and alerts you to available updates.") .'

'; webmaster@1: $output .= '

'. t('The report of available updates will alert you when new releases are available for download. You may configure options for update checking frequency and notifications at the Update status module settings page.', array('@update-report' => url('admin/reports/updates'), '@update-settings' => url('admin/reports/updates/settings'))) .'

'; webmaster@1: $output .= '

'. t('Please note that in order to provide this information, anonymous usage statistics are sent to drupal.org. If desired, you may disable the Update status module from the module administration page.', array('@modules' => url('admin/build/modules'))) .'

'; webmaster@1: $output .= '

'. t('For more information, see the online handbook entry for Update status module.', array('@update' => 'http://drupal.org/handbook/modules/update')) .'

'; webmaster@1: return $output; webmaster@1: webmaster@1: default: webmaster@1: // Otherwise, if we're on *any* admin page and there's a security webmaster@1: // update missing, print an error message about it. webmaster@1: if (arg(0) == 'admin' && strpos($path, '#') === FALSE webmaster@1: && user_access('administer site configuration')) { webmaster@1: include_once './includes/install.inc'; webmaster@1: $status = update_requirements('runtime'); webmaster@1: foreach (array('core', 'contrib') as $report_type) { webmaster@1: $type = 'update_'. $report_type; webmaster@1: if (isset($status[$type]) webmaster@1: && isset($status[$type]['reason']) webmaster@1: && $status[$type]['reason'] === UPDATE_NOT_SECURE) { webmaster@1: drupal_set_message($status[$type]['description'], 'error'); webmaster@1: } webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Implementation of hook_menu(). webmaster@1: */ webmaster@1: function update_menu() { webmaster@1: $items = array(); webmaster@1: webmaster@1: $items['admin/reports/updates'] = array( webmaster@1: 'title' => 'Available updates', webmaster@1: 'description' => 'Get a status report about available updates for your installed modules and themes.', webmaster@1: 'page callback' => 'update_status', webmaster@1: 'access arguments' => array('administer site configuration'), webmaster@1: 'file' => 'update.report.inc', webmaster@1: 'weight' => 10, webmaster@1: ); webmaster@1: $items['admin/reports/updates/list'] = array( webmaster@1: 'title' => 'List', webmaster@1: 'page callback' => 'update_status', webmaster@1: 'access arguments' => array('administer site configuration'), webmaster@1: 'file' => 'update.report.inc', webmaster@1: 'type' => MENU_DEFAULT_LOCAL_TASK, webmaster@1: ); webmaster@1: $items['admin/reports/updates/settings'] = array( webmaster@1: 'title' => 'Settings', webmaster@1: 'page callback' => 'drupal_get_form', webmaster@1: 'page arguments' => array('update_settings'), webmaster@1: 'access arguments' => array('administer site configuration'), webmaster@1: 'file' => 'update.settings.inc', webmaster@1: 'type' => MENU_LOCAL_TASK, webmaster@1: ); webmaster@1: $items['admin/reports/updates/check'] = array( webmaster@1: 'title' => 'Manual update check', webmaster@1: 'page callback' => 'update_manual_status', webmaster@1: 'access arguments' => array('administer site configuration'), webmaster@1: 'file' => 'update.fetch.inc', webmaster@1: 'type' => MENU_CALLBACK, webmaster@1: ); webmaster@1: webmaster@1: return $items; webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Implementation of the hook_theme() registry. webmaster@1: */ webmaster@1: function update_theme() { webmaster@1: return array( webmaster@1: 'update_settings' => array( webmaster@1: 'arguments' => array('form' => NULL), webmaster@1: ), webmaster@1: 'update_report' => array( webmaster@1: 'arguments' => array('data' => NULL), webmaster@1: ), webmaster@1: 'update_version' => array( webmaster@1: 'arguments' => array('version' => NULL, 'tag' => NULL, 'class' => NULL), webmaster@1: ), webmaster@1: ); webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Implementation of hook_requirements. webmaster@1: * webmaster@1: * @return webmaster@1: * An array describing the status of the site regarding available updates. webmaster@1: * If there is no update data, only one record will be returned, indicating webmaster@1: * that the status of core can't be determined. If data is available, there webmaster@1: * will be two records: one for core, and another for all of contrib webmaster@1: * (assuming there are any contributed modules or themes enabled on the webmaster@1: * site). In addition to the fields expected by hook_requirements ('value', webmaster@1: * 'severity', and optionally 'description'), this array will contain a webmaster@1: * 'reason' attribute, which is an integer constant to indicate why the webmaster@1: * given status is being returned (UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT, or webmaster@1: * UPDATE_UNKNOWN). This is used for generating the appropriate e-mail webmaster@1: * notification messages during update_cron(), and might be useful for other webmaster@1: * modules that invoke update_requirements() to find out if the site is up webmaster@1: * to date or not. webmaster@1: * webmaster@1: * @see _update_message_text() webmaster@1: * @see _update_cron_notify() webmaster@1: */ webmaster@1: function update_requirements($phase) { webmaster@1: if ($phase == 'runtime') { webmaster@1: if ($available = update_get_available(FALSE)) { webmaster@1: module_load_include('inc', 'update', 'update.compare'); webmaster@1: $data = update_calculate_project_data($available); webmaster@1: // First, populate the requirements for core: webmaster@1: $requirements['update_core'] = _update_requirement_check($data['drupal'], 'core'); webmaster@1: // We don't want to check drupal a second time. webmaster@1: unset($data['drupal']); webmaster@1: if (!empty($data)) { webmaster@1: // Now, sort our $data array based on each project's status. The webmaster@1: // status constants are numbered in the right order of precedence, so webmaster@1: // we just need to make sure the projects are sorted in ascending webmaster@1: // order of status, and we can look at the first project we find. webmaster@1: uasort($data, '_update_project_status_sort'); webmaster@1: $first_project = reset($data); webmaster@1: $requirements['update_contrib'] = _update_requirement_check($first_project, 'contrib'); webmaster@1: } webmaster@1: } webmaster@1: else { webmaster@1: $requirements['update_core']['title'] = t('Drupal core update status'); webmaster@1: $requirements['update_core']['value'] = t('No update data available'); webmaster@1: $requirements['update_core']['severity'] = REQUIREMENT_WARNING; webmaster@1: $requirements['update_core']['reason'] = UPDATE_UNKNOWN; webmaster@1: $requirements['update_core']['description'] = _update_no_data(); webmaster@1: } webmaster@1: return $requirements; webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Private helper method to fill in the requirements array. webmaster@1: * webmaster@1: * This is shared for both core and contrib to generate the right elements in webmaster@1: * the array for hook_requirements(). webmaster@1: * webmaster@1: * @param $project webmaster@1: * Array of information about the project we're testing as returned by webmaster@1: * update_calculate_project_data(). webmaster@1: * @param $type webmaster@1: * What kind of project is this ('core' or 'contrib'). webmaster@1: * webmaster@1: * @return webmaster@1: * An array to be included in the nested $requirements array. webmaster@1: * webmaster@1: * @see hook_requirements() webmaster@1: * @see update_requirements() webmaster@1: * @see update_calculate_project_data() webmaster@1: */ webmaster@1: function _update_requirement_check($project, $type) { webmaster@1: $requirement = array(); webmaster@1: if ($type == 'core') { webmaster@1: $requirement['title'] = t('Drupal core update status'); webmaster@1: } webmaster@1: else { webmaster@1: $requirement['title'] = t('Module and theme update status'); webmaster@1: } webmaster@1: $status = $project['status']; webmaster@1: if ($status != UPDATE_CURRENT) { webmaster@1: $requirement['reason'] = $status; webmaster@1: $requirement['description'] = _update_message_text($type, $status, TRUE); webmaster@1: $requirement['severity'] = REQUIREMENT_ERROR; webmaster@1: } webmaster@1: switch ($status) { webmaster@1: case UPDATE_NOT_SECURE: webmaster@1: $requirement_label = t('Not secure!'); webmaster@1: break; webmaster@1: case UPDATE_REVOKED: webmaster@1: $requirement_label = t('Revoked!'); webmaster@1: break; webmaster@1: case UPDATE_NOT_SUPPORTED: webmaster@1: $requirement_label = t('Unsupported release'); webmaster@1: break; webmaster@1: case UPDATE_NOT_CURRENT: webmaster@1: $requirement_label = t('Out of date'); webmaster@1: $requirement['severity'] = variable_get('update_notification_threshold', 'all') == 'all' ? REQUIREMENT_ERROR : REQUIREMENT_WARNING; webmaster@1: break; webmaster@1: case UPDATE_UNKNOWN: webmaster@1: case UPDATE_NOT_CHECKED: webmaster@1: $requirement_label = isset($project['reason']) ? $project['reason'] : t('Can not determine status'); webmaster@1: $requirement['severity'] = REQUIREMENT_WARNING; webmaster@1: break; webmaster@1: default: webmaster@1: $requirement_label = t('Up to date'); webmaster@1: } webmaster@1: if ($status != UPDATE_CURRENT && $type == 'core' && isset($project['recommended'])) { webmaster@1: $requirement_label .= ' '. t('(version @version available)', array('@version' => $project['recommended'])); webmaster@1: } webmaster@1: $requirement['value'] = l($requirement_label, 'admin/reports/updates'); webmaster@1: return $requirement; webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Implementation of hook_cron(). webmaster@1: */ webmaster@1: function update_cron() { webmaster@1: $frequency = variable_get('update_check_frequency', 1); webmaster@1: $interval = 60 * 60 * 24 * $frequency; webmaster@1: if (time() - variable_get('update_last_check', 0) > $interval) { webmaster@1: update_refresh(); webmaster@1: _update_cron_notify(); webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Implementation of hook_form_alter(). webmaster@1: * webmaster@1: * Adds a submit handler to the system modules and themes forms, so that if a webmaster@1: * site admin saves either form, we invalidate the cache of available updates. webmaster@1: * webmaster@1: * @see update_invalidate_cache() webmaster@1: */ webmaster@1: function update_form_alter(&$form, $form_state, $form_id) { webmaster@1: if ($form_id == 'system_modules' || $form_id == 'system_themes' ) { webmaster@1: $form['#submit'][] = 'update_invalidate_cache'; webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Prints a warning message when there is no data about available updates. webmaster@1: */ webmaster@1: function _update_no_data() { webmaster@1: $destination = drupal_get_destination(); webmaster@1: return t('No information is available about potential new releases for currently installed modules and themes. To check for updates, you may need to run cron or you can check manually. Please note that checking for available updates can take a long time, so please be patient.', array( webmaster@1: '@run_cron' => url('admin/reports/status/run-cron', array('query' => $destination)), webmaster@1: '@check_manually' => url('admin/reports/updates/check', array('query' => $destination)), webmaster@1: )); webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Internal helper to try to get the update information from the cache webmaster@1: * if possible, and to refresh the cache when necessary. webmaster@1: * webmaster@1: * In addition to checking the cache lifetime, this function also ensures that webmaster@1: * there are no .info files for enabled modules or themes that have a newer webmaster@1: * modification timestamp than the last time we checked for available update webmaster@1: * data. If any .info file was modified, it almost certainly means a new webmaster@1: * version of something was installed. Without fresh available update data, webmaster@1: * the logic in update_calculate_project_data() will be wrong and produce webmaster@1: * confusing, bogus results. webmaster@1: * webmaster@1: * @param $refresh webmaster@1: * Boolean to indicate if this method should refresh the cache automatically webmaster@1: * if there's no data. webmaster@1: * webmaster@1: * @see update_refresh() webmaster@1: * @see update_get_projects() webmaster@1: */ webmaster@1: function update_get_available($refresh = FALSE) { webmaster@1: module_load_include('inc', 'update', 'update.compare'); webmaster@1: $available = array(); webmaster@1: webmaster@1: // First, make sure that none of the .info files have a change time webmaster@1: // newer than the last time we checked for available updates. webmaster@1: $needs_refresh = FALSE; webmaster@1: $last_check = variable_get('update_last_check', 0); webmaster@1: $projects = update_get_projects(); webmaster@1: foreach ($projects as $key => $project) { webmaster@1: if ($project['info']['_info_file_ctime'] > $last_check) { webmaster@1: $needs_refresh = TRUE; webmaster@1: break; webmaster@1: } webmaster@1: } webmaster@1: if (!$needs_refresh && ($cache = cache_get('update_info', 'cache_update')) webmaster@1: && $cache->expire > time()) { webmaster@1: $available = $cache->data; webmaster@1: } webmaster@1: elseif ($needs_refresh || $refresh) { webmaster@1: // If we need to refresh due to a newer .info file, ignore the argument webmaster@1: // and force the refresh (e.g., even for update_requirements()) to prevent webmaster@1: // bogus results. webmaster@1: $available = update_refresh(); webmaster@1: } webmaster@1: return $available; webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Implementation of hook_flush_caches(). webmaster@1: * webmaster@1: * The function update.php (among others) calls this hook to flush the caches. webmaster@1: * Since we're running update.php, we are likely to install a new version of webmaster@1: * something, in which case, we want to check for available update data again. webmaster@1: */ webmaster@1: function update_flush_caches() { webmaster@1: return array('cache_update'); webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Invalidates any cached data relating to update status. webmaster@1: */ webmaster@1: function update_invalidate_cache() { webmaster@1: cache_clear_all('*', 'cache_update', TRUE); webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Wrapper to load the include file and then refresh the release data. webmaster@1: */ webmaster@1: function update_refresh() { webmaster@1: module_load_include('inc', 'update', 'update.fetch'); webmaster@1: return _update_refresh(); webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Implementation of hook_mail(). webmaster@1: * webmaster@1: * Constructs the email notification message when the site is out of date. webmaster@1: * webmaster@1: * @param $key webmaster@1: * Unique key to indicate what message to build, always 'status_notify'. webmaster@1: * @param $message webmaster@1: * Reference to the message array being built. webmaster@1: * @param $params webmaster@1: * Array of parameters to indicate what kind of text to include in the webmaster@1: * message body. This is a keyed array of message type ('core' or 'contrib') webmaster@1: * as the keys, and the status reason constant (UPDATE_NOT_SECURE, etc) for webmaster@1: * the values. webmaster@1: * webmaster@1: * @see drupal_mail() webmaster@1: * @see _update_cron_notify() webmaster@1: * @see _update_message_text() webmaster@1: */ webmaster@1: function update_mail($key, &$message, $params) { webmaster@1: $language = $message['language']; webmaster@1: $langcode = $language->language; webmaster@1: $message['subject'] .= t('New release(s) available for !site_name', array('!site_name' => variable_get('site_name', 'Drupal')), $langcode); webmaster@1: foreach ($params as $msg_type => $msg_reason) { webmaster@1: $message['body'][] = _update_message_text($msg_type, $msg_reason, FALSE, $language); webmaster@1: } webmaster@1: $message['body'][] = t('See the available updates page for more information:', array(), $langcode) ."\n". url('admin/reports/updates', array('absolute' => TRUE, 'language' => $language)); webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Helper function to return the appropriate message text when the site is out webmaster@1: * of date or missing a security update. webmaster@1: * webmaster@1: * These error messages are shared by both update_requirements() for the webmaster@1: * site-wide status report at admin/reports/status and in the body of the webmaster@1: * notification emails generated by update_cron(). webmaster@1: * webmaster@1: * @param $msg_type webmaster@1: * String to indicate what kind of message to generate. Can be either webmaster@1: * 'core' or 'contrib'. webmaster@1: * @param $msg_reason webmaster@1: * Integer constant specifying why message is generated. webmaster@1: * @param $report_link webmaster@1: * Boolean that controls if a link to the updates report should be added. webmaster@1: * @param $language webmaster@1: * An optional language object to use. webmaster@1: * @return webmaster@1: * The properly translated error message for the given key. webmaster@1: */ webmaster@1: function _update_message_text($msg_type, $msg_reason, $report_link = FALSE, $language = NULL) { webmaster@1: $langcode = isset($language) ? $language->language : NULL; webmaster@1: $text = ''; webmaster@1: switch ($msg_reason) { webmaster@1: case UPDATE_NOT_SECURE: webmaster@1: if ($msg_type == 'core') { webmaster@1: $text = t('There is a security update available for your version of Drupal. To ensure the security of your server, you should update immediately!', array(), $langcode); webmaster@1: } webmaster@1: else { webmaster@1: $text = t('There are security updates available for one or more of your modules or themes. To ensure the security of your server, you should update immediately!', array(), $langcode); webmaster@1: } webmaster@1: break; webmaster@1: webmaster@1: case UPDATE_REVOKED: webmaster@1: if ($msg_type == 'core') { webmaster@1: $text = t('Your version of Drupal has been revoked and is no longer available for download. Upgrading is strongly recommended!', array(), $langcode); webmaster@1: } webmaster@1: else { webmaster@1: $text = t('The installed version of at least one of your modules or themes has been revoked and is no longer available for download. Upgrading or disabling is strongly recommended!', array(), $langcode); webmaster@1: } webmaster@1: break; webmaster@1: webmaster@1: case UPDATE_NOT_SUPPORTED: webmaster@1: if ($msg_type == 'core') { webmaster@1: $text = t('Your version of Drupal is no longer supported. Upgrading is strongly recommended!', array(), $langcode); webmaster@1: } webmaster@1: else { webmaster@1: $text = t('The installed version of at least one of your modules or themes is no longer supported. Upgrading or disabling is strongly recommended! Please see the project homepage for more details.', array(), $langcode); webmaster@1: } webmaster@1: break; webmaster@1: webmaster@1: case UPDATE_NOT_CURRENT: webmaster@1: if ($msg_type == 'core') { webmaster@1: $text = t('There are updates available for your version of Drupal. To ensure the proper functioning of your site, you should update as soon as possible.', array(), $langcode); webmaster@1: } webmaster@1: else { webmaster@1: $text = t('There are updates available for one or more of your modules or themes. To ensure the proper functioning of your site, you should update as soon as possible.', array(), $langcode); webmaster@1: } webmaster@1: break; webmaster@1: webmaster@1: case UPDATE_UNKNOWN: webmaster@1: case UPDATE_NOT_CHECKED: webmaster@1: if ($msg_type == 'core') { webmaster@1: $text = t('There was a problem determining the status of available updates for your version of Drupal.', array(), $langcode); webmaster@1: } webmaster@1: else { webmaster@1: $text = t('There was a problem determining the status of available updates for one or more of your modules or themes.', array(), $langcode); webmaster@1: } webmaster@1: break; webmaster@1: } webmaster@1: webmaster@1: if ($report_link) { webmaster@1: $text .= ' '. t('See the available updates page for more information.', array('@available_updates' => url('admin/reports/updates', array('language' => $language))), $langcode); webmaster@1: } webmaster@1: webmaster@1: return $text; webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Private sort function to order projects based on their status. webmaster@1: * webmaster@1: * @see update_requirements() webmaster@1: * @see uasort() webmaster@1: */ webmaster@1: function _update_project_status_sort($a, $b) { webmaster@1: // The status constants are numerically in the right order, so we can webmaster@1: // usually subtract the two to compare in the order we want. However, webmaster@1: // negative status values should be treated as if they are huge, since we webmaster@1: // always want them at the bottom of the list. webmaster@1: $a_status = $a['status'] > 0 ? $a['status'] : (-10 * $a['status']); webmaster@1: $b_status = $b['status'] > 0 ? $b['status'] : (-10 * $b['status']); webmaster@1: return $a_status - $b_status; webmaster@1: }