diff --git a/core/includes/archiver.inc b/core/includes/archiver.inc index 835d46f338d..3ce1173906b 100644 --- a/core/includes/archiver.inc +++ b/core/includes/archiver.inc @@ -51,12 +51,12 @@ interface ArchiverInterface { * @param $files * Optionally specify a list of files to be extracted. Files are * relative to the root of the archive. If not specified, all files - * in the archive will be extracted + * in the archive will be extracted. * * @return ArchiverInterface * The called object. */ - public function extract($path, Array $files = array()); + public function extract($path, array $files = array()); /** * Lists all files in the archive. diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 03ed352dc6d..5b280e4d4a3 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -1956,7 +1956,7 @@ function drupal_block_denied($ip) { */ function drupal_random_bytes($count) { // $random_state does not use drupal_static as it stores random bytes. - static $random_state, $bytes; + static $random_state, $bytes, $php_compatible; // Initialize on the first call. The contents of $_SERVER includes a mix of // user-specific and system information that varies a little with each page. if (!isset($random_state)) { @@ -1968,6 +1968,11 @@ function drupal_random_bytes($count) { $bytes = ''; } if (strlen($bytes) < $count) { + // PHP versions prior 5.3.4 experienced openssl_random_pseudo_bytes() + // locking on Windows and rendered it unusable. + if (!isset($php_compatible)) { + $php_compatible = version_compare(PHP_VERSION, '5.3.4', '>='); + } // /dev/urandom is available on many *nix systems and is considered the // best commonly available pseudo-random source. if ($fh = @fopen('/dev/urandom', 'rb')) { @@ -1977,6 +1982,11 @@ function drupal_random_bytes($count) { $bytes .= fread($fh, max(4096, $count)); fclose($fh); } + // openssl_random_pseudo_bytes() will find entropy in a system-dependent + // way. + elseif ($php_compatible && function_exists('openssl_random_pseudo_bytes')) { + $bytes .= openssl_random_pseudo_bytes($count - strlen($bytes)); + } // If /dev/urandom is not available or returns no bytes, this loop will // generate a good set of pseudo-random bytes on any system. // Note that it may be important that our $random_state is passed @@ -2694,6 +2704,41 @@ function language_list($only_enabled = FALSE) { return $only_enabled ? $languages['enabled'] : $languages['all']; } +/** + * Loads a language object from the database. + * + * @param $langcode + * The language code. + * + * @return + * A fully-populated language object or FALSE. + */ +function language_load($langcode) { + $languages = language_list(); + return isset($languages[$langcode]) ? $languages[$langcode] : FALSE; +} + +/** + * Produced the printed name for a language for display. + * + * @param $langcode + * The language code. + * + * @return + * The printed name of the language. + */ +function language_name($langcode) { + if ($langcode == LANGUAGE_NONE) { + return t('None'); + } + + if ($language = language_load($langcode)) { + return $language->name; + } + + return t('Unknown (@langcode)', array('@langcode' => $langcode)); +} + /** * Returns the default language used on the site. * diff --git a/core/includes/cache.inc b/core/includes/cache.inc index ab14bd47cc5..d3c3414fd4c 100644 --- a/core/includes/cache.inc +++ b/core/includes/cache.inc @@ -11,8 +11,8 @@ * By default, this returns an instance of the Drupal\Core\Cache\DatabaseBackend * class. * - * Classes implementing Drupal\Core\Cache\CacheBackendInterface can register themselves - * both as a default implementation and for specific bins. + * Classes implementing Drupal\Core\Cache\CacheBackendInterface can register + * themselves both as a default implementation and for specific bins. * * @param $bin * The cache bin for which the cache object should be returned, defaults to diff --git a/core/includes/common.inc b/core/includes/common.inc index 0962d904087..a83551312ae 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1852,7 +1852,9 @@ function format_interval($interval, $granularity = 2, $langcode = NULL) { * A UNIX timestamp to format. * @param $type * (optional) The format to use, one of: - * - 'short', 'medium', or 'long' (the corresponding built-in date formats). + * - One of the built-in formats: 'short', 'medium', 'long', 'html_datetime', + * 'html_date', 'html_time', 'html_yearless_date', 'html_week', + * 'html_month', 'html_year'. * - The name of a date type defined by a module in hook_date_format_types(), * if it's been assigned a format. * - The machine name of an administrator-defined date format. @@ -1905,6 +1907,34 @@ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NUL $format = variable_get('date_format_long', 'l, F j, Y - H:i'); break; + case 'html_datetime': + $format = variable_get('date_format_html_datetime', 'Y-m-d\TH:i:sO'); + break; + + case 'html_date': + $format = variable_get('date_format_html_date', 'Y-m-d'); + break; + + case 'html_time': + $format = variable_get('date_format_html_time', 'H:i:s'); + break; + + case 'html_yearless_date': + $format = variable_get('date_format_html_yearless_date', 'm-d'); + break; + + case 'html_week': + $format = variable_get('date_format_html_week', 'Y-\WW'); + break; + + case 'html_month': + $format = variable_get('date_format_html_month', 'Y-m'); + break; + + case 'html_year': + $format = variable_get('date_format_html_year', 'Y'); + break; + case 'custom': // No change to format. break; @@ -6722,6 +6752,9 @@ function drupal_common_theme() { 'render element' => 'elements', 'template' => 'region', ), + 'datetime' => array( + 'variables' => array('timestamp' => NULL, 'text' => NULL, 'attributes' => array(), 'html' => FALSE), + ), 'status_messages' => array( 'variables' => array('display' => NULL), ), @@ -6755,6 +6788,9 @@ function drupal_common_theme() { 'table' => array( 'variables' => array('header' => NULL, 'rows' => NULL, 'attributes' => array(), 'caption' => NULL, 'colgroups' => array(), 'sticky' => TRUE, 'empty' => ''), ), + 'meter' => array( + 'variables' => array('display_value' => NULL, 'form' => NULL, 'high' => NULL, 'low' => NULL, 'max' => NULL, 'min' => NULL, 'optimum' => NULL, 'value' => NULL, 'percentage' => NULL, 'attributes' => array()), + ), 'tablesort_indicator' => array( 'variables' => array('style' => NULL), ), diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 40f9bfee385..84bd0d1e125 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -447,18 +447,10 @@ function menu_get_item($path = NULL, $router_item = NULL) { } $original_map = arg(NULL, $path); - // Since there is no limit to the length of $path, use a hash to keep it - // short yet unique. - $cid = 'menu_item:' . hash('sha256', $path); - if ($cached = cache('menu')->get($cid)) { - $router_item = $cached->data; - } - else { - $parts = array_slice($original_map, 0, MENU_MAX_PARTS); - $ancestors = menu_get_ancestors($parts); - $router_item = db_query_range('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC', 0, 1, array(':ancestors' => $ancestors))->fetchAssoc(); - cache('menu')->set($cid, $router_item); - } + $parts = array_slice($original_map, 0, MENU_MAX_PARTS); + $ancestors = menu_get_ancestors($parts); + $router_item = db_query_range('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC', 0, 1, array(':ancestors' => $ancestors))->fetchAssoc(); + if ($router_item) { // Allow modules to alter the router item before it is translated and // checked for access. diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 40c4f35c4a9..5088c416683 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1474,6 +1474,66 @@ function theme_disable($theme_list) { * @{ */ +/** + * Preprocess variables for theme_datetime(). + */ +function template_preprocess_datetime(&$variables) { + // Format the 'datetime' attribute based on the timestamp. + // @see http://www.w3.org/TR/html5-author/the-time-element.html#attr-time-datetime + if (!isset($variables['attributes']['datetime']) && isset($variables['timestamp'])) { + $variables['attributes']['datetime'] = format_date($variables['timestamp'], 'html_datetime', '', 'UTC'); + } + + // If no text was provided, try to auto-generate it. + if (!isset($variables['text'])) { + // Format and use a human-readable version of the timestamp, if any. + if (isset($variables['timestamp'])) { + $variables['text'] = format_date($variables['timestamp']); + $variables['html'] = FALSE; + } + // Otherwise, use the literal datetime attribute. + elseif (isset($variables['attributes']['datetime'])) { + $variables['text'] = $variables['attributes']['datetime']; + $variables['html'] = FALSE; + } + } +} + +/** + * Returns HTML for a date / time. + * + * @param $variables + * An associative array containing: + * - timestamp: (optional) A UNIX timestamp for the datetime attribute. If the + * datetime cannot be represented as a UNIX timestamp, use a valid datetime + * attribute value in $variables['attributes']['datetime']. + * - text: (optional) The content to display within the