From 6fc2070a22cda40d174db205847dca4c214eeea6 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Wed, 14 Jan 2004 22:30:09 +0000 Subject: [PATCH] Patch 5114 by Kjartan: - Adds drupal_set_header() and drupal_get_headers(). - Cache now stores custom headers. - Replace theme_head() with drupal_get_html_head(), added drupal_set_html_head(). - Added RSS autodiscover links to node, blog and taxonomy pages. --- database/database.mssql | 3 +- database/database.mysql | 1 + database/database.pgsql | 1 + includes/bootstrap.inc | 11 +++-- includes/common.inc | 70 ++++++++++++++++++++++++---- includes/theme.inc | 22 +-------- modules/aggregator.module | 3 +- modules/aggregator/aggregator.module | 3 +- modules/blog.module | 2 + modules/blog/blog.module | 2 + modules/node.module | 3 +- modules/node/node.module | 3 +- modules/taxonomy.module | 2 + modules/taxonomy/taxonomy.module | 2 + themes/chameleon/chameleon.theme | 2 +- themes/marvin/marvin.theme | 2 +- themes/xtemplate/xtemplate.theme | 2 +- update.php | 7 ++- 18 files changed, 94 insertions(+), 47 deletions(-) diff --git a/database/database.mssql b/database/database.mssql index d87740512c5..77a02200284 100644 --- a/database/database.mssql +++ b/database/database.mssql @@ -68,7 +68,8 @@ CREATE TABLE [dbo].[cache] ( [cid] [varchar] (255) NOT NULL , [data] [text] NULL , [expire] [int] NOT NULL , - [created] [int] NOT NULL + [created] [int] NOT NULL , + [headers] [text] NOT NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO diff --git a/database/database.mysql b/database/database.mysql index fd9b300bb0a..a876a308413 100644 --- a/database/database.mysql +++ b/database/database.mysql @@ -108,6 +108,7 @@ CREATE TABLE cache ( data longtext, expire int(11) NOT NULL default '0', created int(11) NOT NULL default '0', + headers text, PRIMARY KEY (cid) ) TYPE=MyISAM; diff --git a/database/database.pgsql b/database/database.pgsql index a125d4ca16a..2cc7feaf346 100644 --- a/database/database.pgsql +++ b/database/database.pgsql @@ -106,6 +106,7 @@ CREATE TABLE cache ( data text default '', expire integer NOT NULL default '0', created integer NOT NULL default '0', + headers text default '', PRIMARY KEY (cid) ); diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index 9f59b7237fb..ed274055d11 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 55f3e652093..26e0d16812f 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -87,6 +87,36 @@ function drupal_get_breadcrumb() { } /* @} */ +/** + * @name HTML head contents + * @ingroup common + * + * Set and get output that should be in the \ 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 = ""; + $output .= "\n"; + $output .= "\n"; + + return $output . drupal_set_html_head(); +} +/* @} */ + /** * @name URL path * @ingroup common @@ -123,6 +153,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 e5b5ccbedb9..0bd2416bf62 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -137,7 +137,7 @@ function theme_header() { $output .= ""; $output .= ""; $output .= " ". (drupal_get_title() ? drupal_get_title() : variable_get('site_name', "drupal")) .""; - $output .= theme_head(); + $output .= drupal_get_html_head(); $output .= " "; @@ -461,26 +461,6 @@ function theme_xml_icon($url) { return "
\"".
"; } -/** - * 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 .= ""; - $output .= "\n"; - $output .= "\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 * \ tag. diff --git a/modules/aggregator.module b/modules/aggregator.module index e7c807961db..da9ecb4da6a 100644 --- a/modules/aggregator.module +++ b/modules/aggregator.module @@ -729,8 +729,7 @@ function aggregator_page_opml() { $output .= "\n"; $output .= "\n"; - header("Content-Type: text/xml"); - + drupal_set_header("Content-Type: text/xml; charset=utf-8"); print $output; } diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module index e7c807961db..da9ecb4da6a 100644 --- a/modules/aggregator/aggregator.module +++ b/modules/aggregator/aggregator.module @@ -729,8 +729,7 @@ function aggregator_page_opml() { $output .= "\n"; $output .= "\n"; - header("Content-Type: text/xml"); - + drupal_set_header("Content-Type: text/xml; charset=utf-8"); print $output; } diff --git a/modules/blog.module b/modules/blog.module index eb0a52d7909..5ee3470cec7 100644 --- a/modules/blog.module +++ b/modules/blog.module @@ -125,6 +125,7 @@ function blog_page_user($uid) { $output .= theme('pager', NULL, variable_get("default_nodes_main", 10)); $output .= theme('xml_icon', url("blog/feed/$account->uid")); + drupal_set_html_head('uid") .'">'); print theme("page", $output, $title); } @@ -141,6 +142,7 @@ function blog_page_last() { $output .= theme('pager', NULL, variable_get("default_nodes_main", 10)); $output .= theme('xml_icon', url('blog/feed')); + drupal_set_html_head(''); print theme("page", $output); } diff --git a/modules/blog/blog.module b/modules/blog/blog.module index eb0a52d7909..5ee3470cec7 100644 --- a/modules/blog/blog.module +++ b/modules/blog/blog.module @@ -125,6 +125,7 @@ function blog_page_user($uid) { $output .= theme('pager', NULL, variable_get("default_nodes_main", 10)); $output .= theme('xml_icon', url("blog/feed/$account->uid")); + drupal_set_html_head('uid") .'">'); print theme("page", $output, $title); } @@ -141,6 +142,7 @@ function blog_page_last() { $output .= theme('pager', NULL, variable_get("default_nodes_main", 10)); $output .= theme('xml_icon', url('blog/feed')); + drupal_set_html_head(''); print theme("page", $output); } diff --git a/modules/node.module b/modules/node.module index 7f1b2a53211..0800cb94f45 100644 --- a/modules/node.module +++ b/modules/node.module @@ -964,7 +964,7 @@ function node_feed($nodes = 0, $channel = array()) { $output .= format_rss_channel($channel["title"], $channel["link"], $channel["description"], $items, $channel["language"]); $output .= "\n"; - header("Content-Type: text/xml"); + drupal_set_header("Content-Type: text/xml; charset=utf-8"); print $output; } @@ -1506,6 +1506,7 @@ function node_page() { $output .= node_view(node_load(array("nid" => $node->nid, "type" => $node->type)), 1); } $output .= theme('pager', NULL, variable_get("default_nodes_main", 10)); + drupal_set_html_head(''); print theme("page", $output, ""); } } diff --git a/modules/node/node.module b/modules/node/node.module index 7f1b2a53211..0800cb94f45 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -964,7 +964,7 @@ function node_feed($nodes = 0, $channel = array()) { $output .= format_rss_channel($channel["title"], $channel["link"], $channel["description"], $items, $channel["language"]); $output .= "\n"; - header("Content-Type: text/xml"); + drupal_set_header("Content-Type: text/xml; charset=utf-8"); print $output; } @@ -1506,6 +1506,7 @@ function node_page() { $output .= node_view(node_load(array("nid" => $node->nid, "type" => $node->type)), 1); } $output .= theme('pager', NULL, variable_get("default_nodes_main", 10)); + drupal_set_html_head(''); print theme("page", $output, ""); } } diff --git a/modules/taxonomy.module b/modules/taxonomy.module index cc6f92ec57f..40b3e3472e3 100644 --- a/modules/taxonomy.module +++ b/modules/taxonomy.module @@ -751,6 +751,8 @@ function taxonomy_page() { $breadcrumbs[] = l(t('Home'), ''); $breadcrumbs = array_reverse($breadcrumbs); + drupal_set_html_head('str_tids") .'">'); + $output = taxonomy_render_nodes(taxonomy_select_nodes($taxonomy)); print theme("page", $output, implode(', ', $names), $breadcrumbs); break; diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index cc6f92ec57f..40b3e3472e3 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -751,6 +751,8 @@ function taxonomy_page() { $breadcrumbs[] = l(t('Home'), ''); $breadcrumbs = array_reverse($breadcrumbs); + drupal_set_html_head('str_tids") .'">'); + $output = taxonomy_render_nodes(taxonomy_select_nodes($taxonomy)); print theme("page", $output, implode(', ', $names), $breadcrumbs); break; diff --git a/themes/chameleon/chameleon.theme b/themes/chameleon/chameleon.theme index a162bb33e7e..0bb52adb03f 100644 --- a/themes/chameleon/chameleon.theme +++ b/themes/chameleon/chameleon.theme @@ -38,7 +38,7 @@ function chameleon_header($title = "") { $output .= "\n"; $output .= "\n"; $output .= " ". ($title ? $title ." | ". variable_get("site_name", "drupal") : variable_get("site_name", "drupal") ." | ". variable_get("site_slogan", "")) ."\n"; - $output .= theme_head(); + $output .= drupal_get_html_head(); $output .= " \n"; $output .= " \n"; $output .= ""; diff --git a/themes/marvin/marvin.theme b/themes/marvin/marvin.theme index b2d8d8316b7..0c090370a9b 100644 --- a/themes/marvin/marvin.theme +++ b/themes/marvin/marvin.theme @@ -19,7 +19,7 @@ function marvin_header() { $output = "\n"; $output .= "\n"; $output .= "\n"; - $output .= theme_head($main); + $output .= drupal_get_html_head(); $output .= ""; if ($title = drupal_get_title()) { diff --git a/themes/xtemplate/xtemplate.theme b/themes/xtemplate/xtemplate.theme index 1c5e6e97751..bac833398b1 100644 --- a/themes/xtemplate/xtemplate.theme +++ b/themes/xtemplate/xtemplate.theme @@ -92,7 +92,7 @@ function xtemplate_header() { $xtemplate->template->assign(array( "head_title" => (drupal_get_title() ? drupal_get_title() ." | ". variable_get("site_name", "drupal") : variable_get("site_name", "drupal") ." | ". variable_get("site_slogan", "")), "site" => variable_get("site_name", "drupal"), - "head" => theme_head(), + "head" => drupal_get_html_head(), "stylesheet" => variable_get("xtemplate_stylesheet", "themes/xtemplate/xtemplate.css"), "onload_attributes" => theme_onload_attribute(), "logo" => variable_get("xtemplate_logo", "<img src=\"themes/xtemplate/images/druplicon.gif\" />"), diff --git a/update.php b/update.php index 0ef7aef62ab..f4b07e769ad 100644 --- a/update.php +++ b/update.php @@ -65,7 +65,8 @@ $mysql_updates = array( "2003-12-03" => "update_73", "2003-12-06" => "update_74", "2004-01-06" => "update_75", - "2004-01-11" => "update_76" + "2004-01-11" => "update_76", + "2004-01-13" => "update_77" ); function update_32() { @@ -604,6 +605,10 @@ function update_76() { update_sql("ALTER TABLE {feed} ADD image longtext"); } +function update_77() { + update_sql("ALTER TABLE {cache} ADD headers text"); +} + /* ** System functions */