From 1f273dac01429237ada147633138266a490ec378 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 8 Nov 2003 11:56:33 +0000 Subject: - Committed stage 1 of the theme system improvements. Some TODO's: * The sidebars of theme Marvin and theme UnConeD look unstyled. * CSS-ify theme UnConeD so we can remove the class around the functions. * Rewrite theme_init() not to use a class and simplify theme() accordingly. --- includes/theme.inc | 180 +++++++++++++++++++++++++++++------------------------ 1 file changed, 99 insertions(+), 81 deletions(-) (limited to 'includes') diff --git a/includes/theme.inc b/includes/theme.inc index 6c9beb363..97ab463f4 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -6,106 +6,111 @@ * * @package theme system */ -class BaseTheme { - var $background = "#ffffff"; - var $foreground = "#000000"; - - function system($field) { - $system["name"] = "Basic theme"; - $system["author"] = "Drupal"; - $system["description"] = "Basic theme. Lynx friendly"; - - return $system[$field]; - } - function header($title = "") { - global $base_url; - $output = "\n"; - $output .= ""; - $output .= "". $title ? $title : variable_get(site_name, "drupal") .""; - $output .= theme_head($main); - $output .= "background; color: $this->foreground;\"". theme_onload_attribute(). "\">"; - $output .= "
"; +function theme_help($section) { - print $output; - $this->box(t("Navigation"), @implode("
", link_page())); theme_blocks("all", $this); - print "
"; + $ouptout = ""; + switch ($section) { + case 'admin/system/themes#description': + $output = t("The base theme"); + break; } - function links($links, $delimiter = " | ") { - return implode($delimiter, $links); - } + return $output; +} - function image($name) { - return "misc/$name"; - } +class BaseTheme { +} - function breadcrumb($breadcrumb) { - print "
". implode($breadcrumb, " » ") ."
"; - } +function theme_header($title = "") { + global $base_url; - function node($node, $main) { - if (module_exist("taxonomy")) { - $terms = taxonomy_link("taxonomy terms", $node); - } + $output = "\n"; + $output .= ""; + $output .= "". $title ? $title : variable_get(site_name, "drupal") .""; + $output .= theme_head($main); + $output .= ""; + $output .= "
"; + + print $output; + theme("box", t("Navigation"), @implode("
", link_page())); + theme_blocks("all", $this); + print "
"; +} - $output = "

$node->title

by ". format_name($node); +function theme_links($links, $delimiter = " | ") { + return implode($delimiter, $links); +} - if (count($terms)) { - $output .= "(". $this->links($terms) .")
"; - } +function theme_image($name) { + return "misc/$name"; +} - if ($main && $node->teaser) { - $output .= $node->teaser; - } - else { - $output .= $node->body; - } - if ($links = link_node($node, $main)) { - $output .= "
[ ". $this->links($links) ." ]"; - } - $output .= "
"; +function theme_breadcrumb($breadcrumb) { + print "
". implode($breadcrumb, " » ") ."
"; +} - print $output; +function theme_node($node, $main) { + if (module_exist("taxonomy")) { + $terms = taxonomy_link("taxonomy terms", $node); } - function box($subject, $content, $region = "main") { - $output = "

$subject

$content

"; - print $output; + $output = "

$node->title

by ". format_name($node); + + if (count($terms)) { + $output .= " (". theme("links", $terms) .")
"; } - /** - * Render a block. - * - * You can style your blocks by defining .block (all blocks), - * .block-module (all blocks of module module), - * and \#block-module-delta (specific block of - * module module with delta delta) in your - * theme's CSS. - * - * @param $block object "indexed with" fields from database - * table 'blocks' ($block->module, $block->delta, $block->region, - * ...) and fields returned by module_block("view") - * ($block->subject, $block->content, ...). - */ - function block($block) { - $output = "
module\" id=\"block-$block->module-$block->delta\">"; - $output .= "

$block->subject

"; - $output .= "
$block->content
"; - $output .= "
"; - print $output; + if ($main && $node->teaser) { + $output .= $node->teaser; + } + else { + $output .= $node->body; } - function footer() { - $output = "
"; - $output .= theme_footer(); - $output .= ""; - print $output; + if ($links = link_node($node, $main)) { + $output .= "
[ ". theme("links", $links) ." ]"; } + $output .= "
"; + + print $output; +} + +function theme_box($subject, $content, $region = "main") { + $output = "

$subject

$content

"; + print $output; +} + +/** + * Render a block. + * + * You can style your blocks by defining .block (all blocks), + * .block-module (all blocks of module module), + * and \#block-module-delta (specific block of + * module module with delta delta) in your + * theme's CSS. + * + * @param $block object "indexed with" fields from database + * table 'blocks' ($block->module, $block->delta, $block->region, + * ...) and fields returned by module_block("view") + * ($block->subject, $block->content, ...). + */ +function theme_block($block) { + $output = "
module\" id=\"block-$block->module-$block->delta\">"; + $output .= "

$block->subject

"; + $output .= "
$block->content
"; + $output .= "
"; + print $output; +} -} // End of BaseTheme class // +function theme_footer() { + $output = "
"; + $output .= theme_footer(); + $output .= ""; + print $output; +} /** * Return a marker. Used to indicate new comments or required form @@ -178,7 +183,7 @@ function theme_head($main = 0) { * Execute hook _footer() which is run at the end of the page right * before the tag */ -function theme_footer($main = 0) { +function theme_closure($main = 0) { $footer = module_invoke_all("footer", $main); return implode($footer, "\n"); } @@ -199,6 +204,8 @@ function theme_init() { $instance =& new BaseTheme; } + $instance->theme = $name; + return $instance; } @@ -224,15 +231,26 @@ function theme_blocks($region) { function theme() { global $theme; + $args = func_get_args(); $function = array_shift($args); - if (method_exists($theme, $function)) { + $name = $theme->theme; + + if (function_exists($name ."_". $function)) { + return call_user_func_array($name ."_". $function, $args); + } + else if (method_exists($theme, $function)) { return call_user_method_array($function, $theme, $args); + // temporary fall-back; can be removed as soon the $theme-object is no more + } + else if (function_exists("theme_". $function)) { + return call_user_func_array("theme_". $function, $args); } else { return call_user_func_array($function, $args); + // temporary fall-back; can be removed as soon the $theme-object is no more } } -- cgit v1.2.3