Skip to content
Snippets Groups Projects
Commit 048bec13 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #13148 by Morbus: less globals.

parent b0051893
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -114,11 +114,8 @@ function drupal_set_html_head($data = NULL) { ...@@ -114,11 +114,8 @@ function drupal_set_html_head($data = NULL) {
* Retrieve output to be displayed in the head tag of the HTML page. * Retrieve output to be displayed in the head tag of the HTML page.
*/ */
function drupal_get_html_head() { function drupal_get_html_head() {
global $base_path;
$output = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"; $output = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
$output .= theme('stylesheet_import', $base_path .'misc/drupal.css'); $output .= theme('stylesheet_import', base_path() .'misc/drupal.css');
return $output . drupal_set_html_head(); return $output . drupal_set_html_head();
} }
...@@ -237,7 +234,6 @@ function drupal_goto($path = '', $query = NULL, $fragment = NULL) { ...@@ -237,7 +234,6 @@ function drupal_goto($path = '', $query = NULL, $fragment = NULL) {
exit(); exit();
} }
/** /**
* Generates a site off-line message * Generates a site off-line message
*/ */
...@@ -918,7 +914,7 @@ function url($path = NULL, $query = NULL, $fragment = NULL, $absolute = FALSE) { ...@@ -918,7 +914,7 @@ function url($path = NULL, $query = NULL, $fragment = NULL, $absolute = FALSE) {
return $path . $fragment; return $path . $fragment;
} }
global $base_url, $base_path; global $base_url;
static $script; static $script;
static $clean_url; static $clean_url;
...@@ -934,7 +930,7 @@ function url($path = NULL, $query = NULL, $fragment = NULL, $absolute = FALSE) { ...@@ -934,7 +930,7 @@ function url($path = NULL, $query = NULL, $fragment = NULL, $absolute = FALSE) {
$clean_url = (bool)variable_get('clean_url', '0'); $clean_url = (bool)variable_get('clean_url', '0');
} }
$base = ($absolute ? $base_url . '/' : $base_path); $base = ($absolute ? $base_url . '/' : base_path());
// The special path '<front>' links to the default front page. // The special path '<front>' links to the default front page.
if (isset($path) && $path != '<front>') { if (isset($path) && $path != '<front>') {
...@@ -1110,6 +1106,14 @@ function drupal_get_path($type, $name) { ...@@ -1110,6 +1106,14 @@ function drupal_get_path($type, $name) {
return dirname(drupal_get_filename($type, $name)); return dirname(drupal_get_filename($type, $name));
} }
/**
* Returns the base URL path of the Drupal installation.
* At the very least, this will always default to /.
*/
function base_path() {
return $GLOBALS['base_path'];
}
/** /**
* Provide a substitute clone() function for PHP4. * Provide a substitute clone() function for PHP4.
*/ */
...@@ -1124,7 +1128,6 @@ function drupal_add_link($attributes) { ...@@ -1124,7 +1128,6 @@ function drupal_add_link($attributes) {
drupal_set_html_head('<link'. drupal_attributes($attributes) ." />\n"); drupal_set_html_head('<link'. drupal_attributes($attributes) ." />\n");
} }
/** /**
* Add a JavaScript file to the output. * Add a JavaScript file to the output.
* *
...@@ -1133,15 +1136,14 @@ function drupal_add_link($attributes) { ...@@ -1133,15 +1136,14 @@ function drupal_add_link($attributes) {
* depends on the 'killswitch' inside it. * depends on the 'killswitch' inside it.
*/ */
function drupal_add_js($file) { function drupal_add_js($file) {
global $base_path;
static $sent = array(); static $sent = array();
if (!isset($sent['misc/drupal.js'])) { if (!isset($sent['misc/drupal.js'])) {
drupal_set_html_head('<script type="text/javascript" src="'. $base_path .'misc/drupal.js"></script>'); drupal_set_html_head('<script type="text/javascript" src="'. base_path() .'misc/drupal.js"></script>');
$sent['misc/drupal.js'] = true; $sent['misc/drupal.js'] = true;
} }
if (!isset($sent[$file])) { if (!isset($sent[$file])) {
drupal_set_html_head('<script type="text/javascript" src="'. check_url($base_path . $file) .'"></script>'); drupal_set_html_head('<script type="text/javascript" src="'. check_url(base_path() . $file) .'"></script>');
$sent[$file] = true; $sent[$file] = true;
} }
} }
......
...@@ -280,7 +280,7 @@ function theme_get_settings($key = NULL) { ...@@ -280,7 +280,7 @@ function theme_get_settings($key = NULL) {
* The value of the requested setting, NULL if the setting does not exist. * The value of the requested setting, NULL if the setting does not exist.
*/ */
function theme_get_setting($setting_name, $refresh = FALSE) { function theme_get_setting($setting_name, $refresh = FALSE) {
global $theme_key, $base_path; global $theme_key;
static $settings; static $settings;
if (empty($settings) || $refresh) { if (empty($settings) || $refresh) {
...@@ -298,7 +298,7 @@ function theme_get_setting($setting_name, $refresh = FALSE) { ...@@ -298,7 +298,7 @@ function theme_get_setting($setting_name, $refresh = FALSE) {
} }
if ($settings['toggle_logo']) { if ($settings['toggle_logo']) {
$settings['logo'] = $base_path; $settings['logo'] = base_path();
if ($settings['default_logo']) { if ($settings['default_logo']) {
$settings['logo'] .= dirname($theme_object->filename) .'/logo.png'; $settings['logo'] .= dirname($theme_object->filename) .'/logo.png';
} }
...@@ -308,7 +308,7 @@ function theme_get_setting($setting_name, $refresh = FALSE) { ...@@ -308,7 +308,7 @@ function theme_get_setting($setting_name, $refresh = FALSE) {
} }
if ($settings['toggle_favicon']) { if ($settings['toggle_favicon']) {
$settings['favicon'] = $base_path; $settings['favicon'] = base_path();
if ($settings['default_favicon']) { if ($settings['default_favicon']) {
if (file_exists($favicon = dirname($theme_object->filename) .'/favicon.ico')) { if (file_exists($favicon = dirname($theme_object->filename) .'/favicon.ico')) {
$settings['favicon'] .= $favicon; $settings['favicon'] .= $favicon;
...@@ -331,12 +331,11 @@ function theme_get_setting($setting_name, $refresh = FALSE) { ...@@ -331,12 +331,11 @@ function theme_get_setting($setting_name, $refresh = FALSE) {
* drupal_set_html_head() to enforce the correct CSS cascading order. * drupal_set_html_head() to enforce the correct CSS cascading order.
*/ */
function theme_add_style($path = '', $media = 'all') { function theme_add_style($path = '', $media = 'all') {
global $base_path;
static $styles = array(); static $styles = array();
if ($path && !isset($styles["$media:$path"])) { if ($path && !isset($styles["$media:$path"])) {
$style = new stdClass(); $style = new stdClass();
$style->path = $base_path. $path; $style->path = base_path() . $path;
$style->media = $media; $style->media = $media;
$styles["$media:$path"] = $style; $styles["$media:$path"] = $style;
} }
...@@ -427,10 +426,9 @@ function theme_page($content) { ...@@ -427,10 +426,9 @@ function theme_page($content) {
} }
function theme_maintenance_page($content) { function theme_maintenance_page($content) {
global $base_path;
drupal_set_header('Content-Type: text/html; charset=utf-8'); drupal_set_header('Content-Type: text/html; charset=utf-8');
theme('add_style', 'misc/maintenance.css'); theme('add_style', 'misc/maintenance.css');
drupal_set_html_head('<link rel="shortcut icon" href="'. $base_path .'misc/favicon.ico" type="image/x-icon" />'); drupal_set_html_head('<link rel="shortcut icon" href="'. base_path() .'misc/favicon.ico" type="image/x-icon" />');
$output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; $output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
$output .= '<html xmlns="http://www.w3.org/1999/xhtml">'; $output .= '<html xmlns="http://www.w3.org/1999/xhtml">';
$output .= '<head>'; $output .= '<head>';
...@@ -515,10 +513,9 @@ function theme_links($links, $delimiter = ' | ') { ...@@ -515,10 +513,9 @@ function theme_links($links, $delimiter = ' | ') {
* A string containing the image tag. * A string containing the image tag.
*/ */
function theme_image($path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) { function theme_image($path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
global $base_path;
if (!$getsize || (is_file($path) && (list($width, $height, $type, $image_attributes) = @getimagesize($path)))) { if (!$getsize || (is_file($path) && (list($width, $height, $type, $image_attributes) = @getimagesize($path)))) {
$attributes = drupal_attributes($attributes); $attributes = drupal_attributes($attributes);
return '<img src="'. check_url($base_path. $path) .'" alt="'. check_plain($alt) .'" title="'. check_plain($title) .'" '. $image_attributes . $attributes .' />'; return '<img src="'. check_url(base_path() . $path) .'" alt="'. check_plain($alt) .'" title="'. check_plain($title) .'" '. $image_attributes . $attributes .' />';
} }
} }
......
...@@ -22,7 +22,6 @@ function chameleon_regions() { ...@@ -22,7 +22,6 @@ function chameleon_regions() {
} }
function chameleon_page($content) { function chameleon_page($content) {
global $base_path;
$language = $GLOBALS['locale']; $language = $GLOBALS['locale'];
if (theme_get_setting('toggle_favicon')) { if (theme_get_setting('toggle_favicon')) {
...@@ -43,7 +42,7 @@ function chameleon_page($content) { ...@@ -43,7 +42,7 @@ function chameleon_page($content) {
$output .= " <div id=\"header\">"; $output .= " <div id=\"header\">";
if ($logo = theme_get_setting('logo')) { if ($logo = theme_get_setting('logo')) {
$output .= " <a href=\"$base_path\" title=\"". t('Home') ."\"><img src=\"$logo\" alt=\"". t('Home') ."\" /></a>"; $output .= " <a href=\"". base_path() ."\" title=\"". t('Home') ."\"><img src=\"$logo\" alt=\"". t('Home') ."\" /></a>";
} }
if (theme_get_setting('toggle_name')) { if (theme_get_setting('toggle_name')) {
$output .= " <h1 class=\"site-name title\">". l(variable_get('site_name', 'drupal'), ""). "</h1>"; $output .= " <h1 class=\"site-name title\">". l(variable_get('site_name', 'drupal'), ""). "</h1>";
......
...@@ -140,9 +140,8 @@ function phptemplate_features() { ...@@ -140,9 +140,8 @@ function phptemplate_features() {
* into a pluggable template engine. * into a pluggable template engine.
*/ */
function phptemplate_page($content) { function phptemplate_page($content) {
global $base_path;
/* Set title and breadcrumb to declared values */
/* Set title and breadcrumb to declared values */
if ($_GET['q'] == variable_get('site_frontpage', 'node')) { if ($_GET['q'] == variable_get('site_frontpage', 'node')) {
$mission = theme_get_setting('mission'); $mission = theme_get_setting('mission');
$frontpage = true; $frontpage = true;
...@@ -186,7 +185,7 @@ function phptemplate_page($content) { ...@@ -186,7 +185,7 @@ function phptemplate_page($content) {
} }
$variables = array( $variables = array(
'base_path' => $base_path, 'base_path' => base_path(),
'breadcrumb' => theme('breadcrumb', drupal_get_breadcrumb()), 'breadcrumb' => theme('breadcrumb', drupal_get_breadcrumb()),
'closure' => theme('closure'), 'closure' => theme('closure'),
'content' => '<!-- begin content -->' . $content . '<!-- end content -->', 'content' => '<!-- begin content -->' . $content . '<!-- end content -->',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment