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.
4.4.x
Dries Buytaert 2004-01-14 22:30:09 +00:00
parent 01e9b5a0f0
commit 6fc2070a22
18 changed files with 94 additions and 47 deletions

View File

@ -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

View File

@ -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;

View File

@ -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)
);

View File

@ -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;
/*

View File

@ -87,6 +87,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
@ -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&amp;$query$fragment";
return "$script?q=$url&amp;$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";
}
}
}

View File

@ -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>";
@ -461,26 +461,6 @@ function theme_xml_icon($url) {
return "<div class=\"xml-icon\"><a href=\"$url\"><img src=\"misc/xml.gif\" width=\"36\" height=\"14\" alt=\"". t('XML feed') ."\" /></a></div>";
}
/**
* 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.

View File

@ -729,8 +729,7 @@ function aggregator_page_opml() {
$output .= "</body>\n";
$output .= "</opml>\n";
header("Content-Type: text/xml");
drupal_set_header("Content-Type: text/xml; charset=utf-8");
print $output;
}

View File

@ -729,8 +729,7 @@ function aggregator_page_opml() {
$output .= "</body>\n";
$output .= "</opml>\n";
header("Content-Type: text/xml");
drupal_set_header("Content-Type: text/xml; charset=utf-8");
print $output;
}

View File

@ -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('<link rel="alternate" type="application/rss+xml" title="RSS - '. $title .'" href="'. url("blog/feed/$account->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('<link rel="alternate" type="application/rss+xml" title="RSS - blogs" href="'. url('blog/feed') .'">');
print theme("page", $output);
}

View File

@ -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('<link rel="alternate" type="application/rss+xml" title="RSS - '. $title .'" href="'. url("blog/feed/$account->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('<link rel="alternate" type="application/rss+xml" title="RSS - blogs" href="'. url('blog/feed') .'">');
print theme("page", $output);
}

View File

@ -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 .= "</rss>\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('<link rel="alternate" type="application/rss+xml" title="RSS" href="'. url('node/feed') .'">');
print theme("page", $output, "");
}
}

View File

@ -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 .= "</rss>\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('<link rel="alternate" type="application/rss+xml" title="RSS" href="'. url('node/feed') .'">');
print theme("page", $output, "");
}
}

View File

@ -751,6 +751,8 @@ function taxonomy_page() {
$breadcrumbs[] = l(t('Home'), '');
$breadcrumbs = array_reverse($breadcrumbs);
drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="RSS - '. implode(' : ', $names) .'" href="'. url("taxonomy/feed/or/$taxonomy->str_tids") .'">');
$output = taxonomy_render_nodes(taxonomy_select_nodes($taxonomy));
print theme("page", $output, implode(', ', $names), $breadcrumbs);
break;

View File

@ -751,6 +751,8 @@ function taxonomy_page() {
$breadcrumbs[] = l(t('Home'), '');
$breadcrumbs = array_reverse($breadcrumbs);
drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="RSS - '. implode(' : ', $names) .'" href="'. url("taxonomy/feed/or/$taxonomy->str_tids") .'">');
$output = taxonomy_render_nodes(taxonomy_select_nodes($taxonomy));
print theme("page", $output, implode(', ', $names), $breadcrumbs);
break;

View File

@ -38,7 +38,7 @@ function chameleon_header($title = "") {
$output .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n";
$output .= "<head>\n";
$output .= " <title>". ($title ? $title ." | ". variable_get("site_name", "drupal") : variable_get("site_name", "drupal") ." | ". variable_get("site_slogan", "")) ."</title>\n";
$output .= theme_head();
$output .= drupal_get_html_head();
$output .= " <link rel=\"stylesheet\" type=\"text/css\" href=\"themes/chameleon/default.css\" />\n";
$output .= " <link rel=\"stylesheet\" type=\"text/css\" href=\"". variable_get("chameleon_stylesheet", "themes/chameleon/pure.css") ."\" />\n";
$output .= "</head>";

View File

@ -19,7 +19,7 @@ function marvin_header() {
$output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
$output .= "<html>\n";
$output .= "<head>\n";
$output .= theme_head($main);
$output .= drupal_get_html_head();
$output .= "<title>";
if ($title = drupal_get_title()) {

View File

@ -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\" />"),

View File

@ -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
*/