From cfd31c93f1f4a4453f7f67e9bf5d3826f9cfce2f Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 1 Feb 2003 19:54:19 +0000 Subject: [PATCH] Patch by Ax: - Bad usage of css ID's: they may be used for a single element only, but were used as #node, #block, which can occur multiple times in a single page. - Moved HTML from theme to template - thats what templates are all about! - Added support for head() hook - Added support for diffentiating between boxes and blocks. - Typo: secundary -> secondary --- includes/theme.inc | 16 ++++- themes/xtemplate/xtemplate.css | 40 +++++------ themes/xtemplate/xtemplate.inc | 19 +++++- themes/xtemplate/xtemplate.theme | 93 +++++++++++--------------- themes/xtemplate/xtemplate.xtmpl | 111 +++++++++++++++++++------------ 5 files changed, 157 insertions(+), 122 deletions(-) diff --git a/includes/theme.inc b/includes/theme.inc index 7a023991a39..d206c22ec17 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -69,6 +69,12 @@ class BaseTheme { print $output; } + function block($subject, $content, $region = "main") { + global $theme; + + $theme->box($subject, $content, $region); + } + function footer() { $output = ""; $output .= ""; @@ -148,7 +154,13 @@ function theme_init() { return $obj; } -function theme_blocks($region, &$theme) { +/** + * Render blocks available for $user and $region calling $theme->block($region). + * + * @param string $region main|left|right + * @param + */ +function theme_blocks($region) { global $user, $PHP_SELF; $result = db_query("SELECT * FROM blocks WHERE (status = '1' OR custom = '1') ". ($region != "all" ? "AND region = '%s' " : "") ."ORDER BY weight, module", $region == "left" ? 0 : 1); @@ -157,7 +169,7 @@ function theme_blocks($region, &$theme) { if ((($block->status && (!$user->uid || !$block->custom)) || ($block->custom && $user->block[$block->module][$block->delta])) && (!$block->path || preg_match("|$block->path|", $PHP_SELF))) { $block_data = module_invoke($block->module, "block", "view", $block->delta); if ($block_data["content"]) { - $theme->box($block_data["subject"], $block_data["content"], $region); + theme_invoke("block", $block_data["subject"], $block_data["content"], $region); } } } diff --git a/themes/xtemplate/xtemplate.css b/themes/xtemplate/xtemplate.css index e1cf7fd5ade..f4014fac059 100644 --- a/themes/xtemplate/xtemplate.css +++ b/themes/xtemplate/xtemplate.css @@ -28,30 +28,30 @@ p { img { border-width: 0; } -table #menu { +.header .menu { background-color: #69c; padding: 5px 5px 0px 5px; } -#menu logo { +.menu logo { vertical-align: bottom; float: left; } -#menu #links { +.menu #links { text-align: right; float: right; color: #9cf; } -#menu #links #primary { +.menu #links #primary { font-size: 1.1em; } -#menu #links #primary a { +.menu #links #primary a { color: #fff; font-weight: bold; } -#menu #links #secundary { +.menu #links #secondary { font-size: 0.7em; } -#menu #links #secundary a { +.menu #links #secondary a { color: #9cf; font-weight: bold; } @@ -67,61 +67,61 @@ table #menu { #sidebar { background-color: #ddd; } -table #node { +table .node { padding-bottom: 25px; } -table #block { +table .block, table .box { padding: 15px 15px 15px 15px; margin: 5px 0px 5px 0px; } -table #comment { +table .comment { border: 1px solid #bbb; padding: 15px 15px 15px 15px; margin: 5px 0px 5px 0px; } -#node #title, #block #title, #node #title a { +.node .title, .block .title, .box .title, .node .title a, .box .title a { padding-bottom: 5px; font-weight: bold; font-size: 1.2em; color: #888; } -#node #author, #comment #author { +.node .author, .comment .author { color: #999; font-size: 0.8em; padding-bottom: 10px; } -#node #taxonomy { +.node .taxonomy { color: #999; font-size: 0.8em; padding: 15px; } -#node #taxonomy a { +.node .taxonomy a { color: #369; } -#node #content, #comment #content { +.node .content, .comment .content { padding-top: 5px; } -#node #links, #comment #links { +.node .links, .comment .links { padding-top: 10px; color: #999; } -#node #links a, #comment #links a { +.node .links a, .comment .links a { font-weight: bold; color: #369; } -#comment #title { +.comment .title { font-weight: bold; font-size: 1.1em; color: #888; } -#comment #new { +.comment .new { text-align: right; font-weight: bold; font-size: 0.7em; float: right; color: red; } -#block #content { +.block .content, .box .content { font-size: 0.9em/1.1em; } diff --git a/themes/xtemplate/xtemplate.inc b/themes/xtemplate/xtemplate.inc index 363943ac6a7..dbe67106a89 100644 --- a/themes/xtemplate/xtemplate.inc +++ b/themes/xtemplate/xtemplate.inc @@ -1,4 +1,4 @@ - secondary + Revision 1.1 2003/01/20 21:00:31 dries - Added a template driven theme. diff --git a/themes/xtemplate/xtemplate.theme b/themes/xtemplate/xtemplate.theme index 70cf2751942..cde00817faa 100644 --- a/themes/xtemplate/xtemplate.theme +++ b/themes/xtemplate/xtemplate.theme @@ -3,11 +3,12 @@ class Theme_xtemplate extends BaseTheme { var $primary_links = "edit me"; - var $secundary_links = "edit me"; + var $secondary_links = "edit me"; var $message = "edit me"; function system($field) { $system["name"] = "xtemplate"; + $system["description"] = "a template driven theme"; return $system[$field]; } @@ -36,13 +37,13 @@ class Theme_xtemplate extends BaseTheme { check_output($node->teaser) : check_output($node->body))); - if ($links = link_node($node, $main)) { - $this->template->assign("links", $this->links($links)); - } + if ($links = link_node($node, $main)) { + $this->template->assign("links", $this->links($links)); + } - $this->template->parse("node"); - print $this->template->text("node"); - $this->template->reset("node"); + $this->template->parse("node"); + print $this->template->text("node"); + $this->template->reset("node"); } function comment($comment, $link = 0) { @@ -65,73 +66,53 @@ class Theme_xtemplate extends BaseTheme { } } - function header() { + function header($title = "") { $this->template->assign(array( - "name" => variable_get("site_name", ""), - "slogan" => variable_get("site_slogan", ""))); + "title" => ($title ? $title." | ". variable_get("site_name", "drupal") : variable_get("site_name", "drupal") ." | ". variable_get("site_slogan", "")), + "head" => theme_head(), + "primary" => $this->primary_links, + "secondary" => $this->secondary_links + )); + + if (!arg(0)) { + $this->template->assign("message", $this->message); + $this->template->parse("header.message"); + } $this->template->parse("header"); print $this->template->text("header"); + } - ?> - - - - - - - -
- template->assign(array( - "message" => $this->message)); - - $this->template->parse("message"); - print $this->template->text("message"); - } - - ?> -
- template->parse("block"); + print $this->template->text("block"); + $this->template->reset("block"); } function box($title, $content, $region = "main") { if ($title && $content) { $this->template->assign(array( - "title" => $title, + "subject" => $title, "content" => $content)); - $this->template->parse("block"); - print $this->template->text("block"); - $this->template->reset("block"); + $this->template->parse("box"); + print $this->template->text("box"); + $this->template->reset("box"); } } function footer() { - global $user; - - ?> -
- template->assign("blocks", ob_get_contents()); + ob_end_clean(); $this->template->parse("footer"); print $this->template->text("footer"); diff --git a/themes/xtemplate/xtemplate.xtmpl b/themes/xtemplate/xtemplate.xtmpl index 2084d19d6d4..be2869fd83c 100644 --- a/themes/xtemplate/xtemplate.xtmpl +++ b/themes/xtemplate/xtemplate.xtmpl @@ -2,68 +2,93 @@ - - {name} - {slogan} - - - + + + {title} + + {head} + + + + + + + + + + + + + + +
+ +
{message}
+ +
- - -
{secundary}
-
{primary}
-
- - - - - -
{message}
- - -
-
{title}
- Submitted by {author} on {date}. - {taxonomy} -
{content}
- +
+
{title}
+ Submitted by {author} on {date}. + {taxonomy} +
{content}
+
-
- new -
{title}
-
Posted by {author} on {date}.
-
{content}
- -
+
+ new +
{title}
+
Posted by {author} on {date}.
+
{content}
+ +
-
-
{title}
-
Posted by {author} on {date}.
-
{content}
- -
+
+
{title}
+
Posted by {author} on {date}.
+
{content}
+ +
+ +
+
{subject}
+
{content}
+
+ + + -
-
{title}
-
{content}
+
+
{subject}
+
{content}
- +
+
+ +