xtemplate.theme 3.14 KB
Newer Older
Dries's avatar
 
Dries committed
1 2 3 4 5 6
<?php

class Theme_xtemplate extends BaseTheme {

  function system($field) {
    $system["name"] = "xtemplate";
Dries's avatar
 
Dries committed
7
    $system["description"] = "a template driven theme";
Dries's avatar
 
Dries committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

    return $system[$field];
  }

  function Theme_xtemplate() {
    include_once("themes/xtemplate/xtemplate.inc");

    $this->template = new XTemplate("themes/xtemplate/xtemplate.xtmpl");
    $this->template->SetNullBlock(" ");  // "" doesnt work!
  }

  function node($node, $main) {

    $this->template->assign(array (
       "title"     => ucfirst($node->title),
       "author"    => format_name($node),
       "date"      => format_date($node->created),
       "content"   => ($main && $node->teaser) ?
                      check_output($node->teaser) :
                      check_output($node->body)));

Dries's avatar
 
Dries committed
29 30 31 32
    if ($taxonomy = taxonomy_link("taxonomy terms", $node)) {
      $this->template->assign("taxonomy", $this->links($taxonomy));
    }

Dries's avatar
 
Dries committed
33 34 35
    if ($links = link_node($node, $main)) {
      $this->template->assign("links", $this->links($links));
    }
Dries's avatar
 
Dries committed
36

Dries's avatar
 
Dries committed
37 38 39
    $this->template->parse("node");
    print $this->template->text("node");
    $this->template->reset("node");
Dries's avatar
 
Dries committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
  }

  function comment($comment, $link = 0) {
    $this->template->assign(array (
        "title"     => ucfirst($comment->subject),
        "author"    => format_name($comment),
        "date"      => format_date($comment->timestamp),
        "content"   => check_output($comment->comment),
        "links"     => $link));

    if ($comment->new) {
      $this->template->parse("comment_new");
      print $this->template->text("comment_new");
      $this->template->reset("comment_new");
    }
    else {
      $this->template->parse("comment_old");
      print $this->template->text("comment_old");
      $this->template->reset("comment_old");
    }
  }

Dries's avatar
 
Dries committed
62
  function header($title = "") {
Dries's avatar
 
Dries committed
63
    $this->template->assign(array(
Dries's avatar
 
Dries committed
64 65
      "title" => ($title ? $title." | ". variable_get("site_name", "drupal") : variable_get("site_name", "drupal") ." | ". variable_get("site_slogan", "")),
      "head" => theme_head(),
Dries's avatar
 
Dries committed
66
      "links" => $this->links(link_page())
Dries's avatar
 
Dries committed
67 68 69 70 71
    ));

    if (!arg(0)) {
      $this->template->parse("header.message");
    }
Dries's avatar
 
Dries committed
72 73 74

    $this->template->parse("header");
    print $this->template->text("header");
Dries's avatar
 
Dries committed
75
  }
Dries's avatar
 
Dries committed
76

Dries's avatar
 
Dries committed
77
  function block($title, $content, $region = "main") {
Dries's avatar
 
Dries committed
78
    $this->template->assign(array(
Dries's avatar
 
Dries committed
79 80 81
      "subject" => $title,
      "content" => $content
    ));
Dries's avatar
 
Dries committed
82

Dries's avatar
 
Dries committed
83 84 85
    $this->template->parse("block");
    print $this->template->text("block");
    $this->template->reset("block");
Dries's avatar
 
Dries committed
86 87 88 89 90
  }

  function box($title, $content, $region = "main") {
    if ($title && $content) {
      $this->template->assign(array(
Dries's avatar
 
Dries committed
91
        "subject" => $title,
Dries's avatar
 
Dries committed
92 93
        "content" => $content));

Dries's avatar
 
Dries committed
94 95 96
      $this->template->parse("box");
      print $this->template->text("box");
      $this->template->reset("box");
Dries's avatar
 
Dries committed
97 98 99 100
    }
  }

  function footer() {
Dries's avatar
 
Dries committed
101 102 103 104 105 106
    // unfortunately, theme_blocks PRINTS the blocks instead of RETURNING them.
    // so we need some output buffering
    ob_start();
    theme_blocks("all");
    $this->template->assign("blocks", ob_get_contents());
    ob_end_clean();
Dries's avatar
 
Dries committed
107 108 109 110 111 112

    $this->template->parse("footer");
    print $this->template->text("footer");
  }
}
?>