diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/bootstrap.inc | 11 | ||||
-rw-r--r-- | includes/common.inc | 70 | ||||
-rw-r--r-- | includes/theme.inc | 22 |
3 files changed, 67 insertions, 36 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index 9f59b7237..ed274055d 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -60,14 +60,14 @@ function variable_del($name) { } function cache_get($key) { - $cache = db_fetch_object(db_query("SELECT data, created FROM {cache} WHERE cid = '%s'", $key)); + $cache = db_fetch_object(db_query("SELECT data, created, headers FROM {cache} WHERE cid = '%s'", $key)); return $cache->data ? $cache : 0; } -function cache_set($cid, $data, $expire = 0) { - db_query("UPDATE {cache} SET data = '%s', created = %d, expire = %d WHERE cid = '%s'", $data, time(), $expire, $cid); +function cache_set($cid, $data, $expire = 0, $headers = NULL) { + db_query("UPDATE {cache} SET data = '%s', created = %d, expire = %d, headers = '%s' WHERE cid = '%s'", $data, time(), $expire, $headers, $cid); if (!db_affected_rows()) { - db_query("INSERT INTO {cache} (cid, data, created, expire) VALUES('%s', '%s', %d, %d)", $cid, $data, time(), $expire); + db_query("INSERT INTO {cache} (cid, data, created, expire, headers) VALUES('%s', '%s', %d, %d, '%s')", $cid, $data, time(), $expire, $headers); } } @@ -85,7 +85,7 @@ function page_set_cache() { if (!$user->uid && $_SERVER["REQUEST_METHOD"] == "GET") { if ($data = ob_get_contents()) { - cache_set(request_uri(), $data, 1); + cache_set(request_uri(), $data, 1, drupal_get_headers()); } } } @@ -137,6 +137,7 @@ function drupal_page_header() { // Send appropriate response: header("Last-Modified: $date"); header("ETag: $etag"); + header($cache->headers); print $cache->data; /* diff --git a/includes/common.inc b/includes/common.inc index 55f3e6520..26e0d1681 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -88,6 +88,36 @@ function drupal_get_breadcrumb() { /* @} */ /** + * @name HTML head contents + * @ingroup common + * + * Set and get output that should be in the \<head\> tag. + * @{ + */ + +function drupal_set_html_head($data = NULL) { + static $stored_head; + + if (!is_null($data)) { + $stored_head .= "$data\n"; + } + return $stored_head; +} + +function drupal_get_html_head() { + global $base_url; + + $output = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"; + $output .= "<base href=\"$base_url/\" />\n"; + $output .= "<style type=\"text/css\">\n"; + $output .= "@import url(misc/drupal.css);\n"; + $output .= "</style>\n"; + + return $output . drupal_set_html_head(); +} +/* @} */ + +/** * @name URL path * @ingroup common * @@ -124,6 +154,28 @@ function drupal_rebuild_path_map() { */ /** + * @name HTTP headers + * @ingroup common + * + * Functions to get and set the HTTP headers of the current page. + * @{ + */ +function drupal_set_header($header = NULL) { + static $stored_headers; + + if (!is_null($header)) { + header($header); + $stored_headers .= "$header\n"; + } + return $stored_headers; +} + +function drupal_get_headers() { + return drupal_set_header(); +} +/* @} */ + +/** * HTTP redirects. Makes sure the redirected url is formatted correctly and * includes the session ID. * @@ -915,8 +967,6 @@ function drupal_get_normal_path($path) { } function url($url = NULL, $query = NULL, $fragment = NULL) { - global $base_url; - static $script; if (empty($script)) { @@ -939,36 +989,36 @@ function url($url = NULL, $query = NULL, $fragment = NULL) { if (variable_get("clean_url", "0") == "0") { if (isset($url)) { if (isset($query)) { - return "$base_url/$script?q=$url&$query$fragment"; + return "$script?q=$url&$query$fragment"; } else { - return "$base_url/$script?q=$url$fragment"; + return "$script?q=$url$fragment"; } } else { if (isset($query)) { - return "$base_url/$script?$query$fragment"; + return "$script?$query$fragment"; } else { - return "$base_url/$fragment"; + return "$fragment"; } } } else { if (isset($url)) { if (isset($query)) { - return "$base_url/$url?$query$fragment"; + return "$url?$query$fragment"; } else { - return "$base_url/$url$fragment"; + return "$url$fragment"; } } else { if (isset($query)) { - return "$base_url/$script?$query$fragment"; + return "$script?$query$fragment"; } else { - return "$base_url/$fragment"; + return "$fragment"; } } } diff --git a/includes/theme.inc b/includes/theme.inc index e5b5ccbed..0bd2416bf 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -137,7 +137,7 @@ function theme_header() { $output .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">"; $output .= "<head>"; $output .= " <title>". (drupal_get_title() ? drupal_get_title() : variable_get('site_name', "drupal")) ."</title>"; - $output .= theme_head(); + $output .= drupal_get_html_head(); $output .= " <style type=\"text/css\" media=\"all\">"; $output .= " @import url(misc/drupal.css);"; $output .= " </style>"; @@ -462,26 +462,6 @@ function theme_xml_icon($url) { } /** - * Execute hook _head which is run at the start of the page, and output should - * be in the head tags. - * - * @param $main (optional) - * - * @return a string containing the @a error output. - */ -function theme_head($main = 0) { - global $base_url; - $output .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"; - $output .= "<base href=\"$base_url/\" />\n"; - $output .= "<style type=\"text/css\">\n"; - $output .= "@import url(misc/drupal.css);\n"; - $output .= "</style>\n"; - $head = module_invoke_all("head", $main); - $output .= implode($head, "\n"); - return $output; -} - -/** * Execute hook _footer() which is run at the end of the page right before the * \</body> tag. * |