diff --git a/core/includes/archiver.inc b/core/includes/archiver.inc index 3ce1173..835d46f 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 952b4ea..0ef2d9d 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -3,6 +3,8 @@ use Symfony\Component\ClassLoader\UniversalClassLoader; use Symfony\Component\ClassLoader\ApcUniversalClassLoader; +use Drupal\Core\Request; + /** * @file * Functions that need to be loaded on every Drupal request. @@ -718,13 +720,6 @@ function drupal_environment_initialize() { $_SERVER['HTTP_HOST'] = ''; } - // When clean URLs are enabled, emulate ?q=foo/bar using REQUEST_URI. It is - // not possible to append the query string using mod_rewrite without the B - // flag (this was added in Apache 2.2.8), because mod_rewrite unescapes the - // path before passing it on to PHP. This is a problem when the path contains - // e.g. "&" or "%" that have special meanings in URLs and must be encoded. - $_GET['q'] = request_path(); - // Enforce E_STRICT, but allow users to set levels not part of E_STRICT. error_reporting(E_STRICT | E_ALL | error_reporting()); @@ -1955,7 +1950,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, $php_compatible; + static $random_state, $bytes; // 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)) { @@ -1967,11 +1962,6 @@ 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')) { @@ -1981,11 +1971,6 @@ 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 @@ -2725,157 +2710,59 @@ function language_default() { } /** + * Returns the request object for the current request. + * + * @return Drupal\Core\Request + * The request object for this request, as populated from the PHP superglobals. + */ +function request() { + $request = &drupal_static(__FUNCTION__); + if (empty($request)) { + $request = Request::createFromGlobals(); + } + return $request; +} + +/** * Returns the requested URL path of the page being viewed. * - * Examples: - * - http://example.com/node/306 returns "node/306". - * - http://example.com/drupalfolder/node/306 returns "node/306" while - * base_path() returns "/drupalfolder/". - * - http://example.com/path/alias (which is a path alias for node/306) returns - * "path/alias" as opposed to the internal path. - * - http://example.com/index.php returns an empty string (meaning: front page). - * - http://example.com/index.php?page=1 returns an empty string. + * @deprecated * * @return * The requested Drupal URL path. * - * @see current_path() + * @see Drupal\Core\Request::requestPath() */ function request_path() { - static $path; - - if (isset($path)) { - return $path; - } - - if (isset($_GET['q'])) { - // This is a request with a ?q=foo/bar query string. $_GET['q'] is - // overwritten in drupal_path_initialize(), but request_path() is called - // very early in the bootstrap process, so the original value is saved in - // $path and returned in later calls. - $path = $_GET['q']; - } - elseif (isset($_SERVER['REQUEST_URI'])) { - // This request is either a clean URL, or 'index.php', or nonsense. - // Extract the path from REQUEST_URI. - $request_path = strtok($_SERVER['REQUEST_URI'], '?'); - $base_path_len = strlen(rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/')); - // Unescape and strip $base_path prefix, leaving q without a leading slash. - $path = substr(urldecode($request_path), $base_path_len + 1); - // If the path equals the script filename, either because 'index.php' was - // explicitly provided in the URL, or because the server added it to - // $_SERVER['REQUEST_URI'] even when it wasn't provided in the URL (some - // versions of Microsoft IIS do this), the front page should be served. - if ($path == basename($_SERVER['PHP_SELF'])) { - $path = ''; - } - } - else { - // This is the front page. - $path = ''; - } - - // Under certain conditions Apache's RewriteRule directive prepends the value - // assigned to $_GET['q'] with a slash. Moreover we can always have a trailing - // slash in place, hence we need to normalize $_GET['q']. - $path = trim($path, '/'); - - return $path; + return request()->requestPath(); } /** * Returns a component of the current Drupal path. * - * When viewing a page at the path "admin/structure/types", for example, arg(0) - * returns "admin", arg(1) returns "structure", and arg(2) returns "types". - * - * Avoid use of this function where possible, as resulting code is hard to - * read. In menu callback functions, attempt to use named arguments. See the - * explanation in menu.inc for how to construct callbacks that take arguments. - * When attempting to use this function to load an element from the current - * path, e.g. loading the node on a node page, use menu_get_object() instead. - * - * @param $index - * The index of the component, where each component is separated by a '/' - * (forward-slash), and where the first component has an index of 0 (zero). - * @param $path - * A path to break into components. Defaults to the path of the current page. + * @deprecated * * @return * The component specified by $index, or NULL if the specified component was - * not found. If called without arguments, it returns an array containing all - * the components of the current path. + * not found. */ function arg($index = NULL, $path = NULL) { - // Even though $arguments doesn't need to be resettable for any functional - // reasons (the result of explode() does not depend on any run-time - // information), it should be resettable anyway in case a module needs to - // free up the memory used by it. - // Use the advanced drupal_static() pattern, since this is called very often. - static $drupal_static_fast; - if (!isset($drupal_static_fast)) { - $drupal_static_fast['arguments'] = &drupal_static(__FUNCTION__); - } - $arguments = &$drupal_static_fast['arguments']; - - if (!isset($path)) { - $path = $_GET['q']; - } - if (!isset($arguments[$path])) { - $arguments[$path] = explode('/', $path); - } - if (!isset($index)) { - return $arguments[$path]; - } - if (isset($arguments[$path][$index])) { - return $arguments[$path][$index]; - } + return request()->pathElement($index); } /** * Returns the IP address of the client machine. * - * If Drupal is behind a reverse proxy, we use the X-Forwarded-For header - * instead of $_SERVER['REMOTE_ADDR'], which would be the IP address of - * the proxy server, and not the client's. The actual header name can be - * configured by the reverse_proxy_header variable. + * @deprecated * * @return * IP address of client machine, adjusted for reverse proxy and/or cluster * environments. + * + * @see Symfony\Component\HttpFoundation\Request::getClientIp() */ function ip_address() { - $ip_address = &drupal_static(__FUNCTION__); - - if (!isset($ip_address)) { - $ip_address = $_SERVER['REMOTE_ADDR']; - - if (variable_get('reverse_proxy', 0)) { - $reverse_proxy_header = variable_get('reverse_proxy_header', 'HTTP_X_FORWARDED_FOR'); - if (!empty($_SERVER[$reverse_proxy_header])) { - // If an array of known reverse proxy IPs is provided, then trust - // the XFF header if request really comes from one of them. - $reverse_proxy_addresses = variable_get('reverse_proxy_addresses', array()); - - // Turn XFF header into an array. - $forwarded = explode(',', $_SERVER[$reverse_proxy_header]); - - // Trim the forwarded IPs; they may have been delimited by commas and spaces. - $forwarded = array_map('trim', $forwarded); - - // Tack direct client IP onto end of forwarded array. - $forwarded[] = $ip_address; - - // Eliminate all trusted IPs. - $untrusted = array_diff($forwarded, $reverse_proxy_addresses); - - // The right-most IP is the most specific we can trust. - $ip_address = array_pop($untrusted); - } - } - } - - return $ip_address; + return request()->getClientIp(variable_get('reverse_proxy', 0)); } /** diff --git a/core/includes/cache.inc b/core/includes/cache.inc index d3c3414..ab14bd4 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 f840e5c..e2c8784 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1850,9 +1850,7 @@ function format_interval($interval, $granularity = 2, $langcode = NULL) { * A UNIX timestamp to format. * @param $type * (optional) The format to use, one of: - * - One of the built-in formats: 'short', 'medium', 'long', 'html_datetime', - * 'html_date', 'html_time', 'html_yearless_date', 'html_week', - * 'html_month', 'html_year'. + * - 'short', 'medium', or 'long' (the corresponding built-in date formats). * - 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,34 +1903,6 @@ 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; @@ -6750,9 +6720,6 @@ 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), ), @@ -6786,9 +6753,6 @@ 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 84bd0d1..fea93c1 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -434,7 +434,7 @@ function menu_set_item($path, $router_item) { function menu_get_item($path = NULL, $router_item = NULL) { $router_items = &drupal_static(__FUNCTION__); if (!isset($path)) { - $path = $_GET['q']; + $path = request()->systemPath(); } if (isset($router_item)) { $router_items[$path] = $router_item; @@ -445,12 +445,20 @@ function menu_get_item($path = NULL, $router_item = NULL) { if (variable_get('menu_rebuild_needed', FALSE) || !variable_get('menu_masks', array())) { menu_rebuild(); } - $original_map = arg(NULL, $path); - - $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(); + $original_map = explode('/', $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); + } if ($router_item) { // Allow modules to alter the router item before it is translated and // checked for access. @@ -1697,7 +1705,7 @@ function menu_get_active_help() { return ''; } - $arg = drupal_help_arg(arg(NULL)); + $arg = drupal_help_arg(explode('/', request()->systemPath())); foreach (module_implements('help') as $module) { $function = $module . '_help'; diff --git a/core/includes/path.inc b/core/includes/path.inc index 44bf3fe..04f5f06 100644 --- a/core/includes/path.inc +++ b/core/includes/path.inc @@ -292,7 +292,7 @@ function drupal_is_front_page() { if (!isset($is_front_page)) { // As drupal_path_initialize updates $_GET['q'] with the 'site_frontpage' path, // we can check it against the 'site_frontpage' variable. - $is_front_page = ($_GET['q'] == variable_get('site_frontpage', 'user')); + $is_front_page = (request()->get('q') == variable_get('site_frontpage', 'user')); } return $is_front_page; @@ -352,7 +352,7 @@ function drupal_match_path($path, $patterns) { * @see request_path() */ function current_path() { - return $_GET['q']; + return request()->systemPath(); } /** diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 5088c41..9983a18 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1475,66 +1475,6 @@ 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