xtemplate.theme 4.9 KB
Newer Older
Dries's avatar
 
Dries committed
1 2
<?php

Dries's avatar
 
Dries committed
3 4
function xtemplate_settings() {
  $output = form_textarea("Message on front page", "xtemplate_message", variable_get("xtemplate_message", "edit message"), 70, 6, "This text will be displayed on the front page.  It can be used to display a mission statement, announcement or site description..");
Dries's avatar
 
Dries committed
5 6
  $output .= form_textarea("Primary links", "xtemplate_primary_links", variable_get("xtemplate_primary_links", l("edit primary links", "admin/system/themes/xtemplate")), 70, 6, "The primary links.");
  $output .= form_textarea("Secondary links", "xtemplate_secondary_links", variable_get("xtemplate_secondary_links", l("edit secondary links", "admin/system/themes/xtemplate")), 70, 6, "The secondary links.");
Dries's avatar
 
Dries committed
7 8 9 10
  $output .= form_select("Search box", "xtemplate_search_box", variable_get("xtemplate_search_box", 0), array(t("Disabled"), t("Enabled")), "Show a search box in the upper right corner.");
  return $output;
}

Dries's avatar
 
Dries committed
11 12 13 14
class Theme_xtemplate extends BaseTheme {

  function system($field) {
    $system["name"] = "xtemplate";
Dries's avatar
 
Dries committed
15
    $system["description"] = "a template driven theme";
Dries's avatar
 
Dries committed
16 17 18 19 20

    return $system[$field];
  }

  function Theme_xtemplate() {
Dries's avatar
 
Dries committed
21 22 23
    if (!class_exists("XTemplate")) {
      include_once("themes/xtemplate/xtemplate.inc");
    }
Dries's avatar
 
Dries committed
24 25 26 27 28

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

Dries's avatar
 
Dries committed
29
  function node($node, $main = 0) {
Dries's avatar
 
Dries committed
30 31 32 33 34 35 36 37 38

    $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
39 40 41 42
    if ($taxonomy = taxonomy_link("taxonomy terms", $node)) {
      $this->template->assign("taxonomy", $this->links($taxonomy));
    }

Dries's avatar
 
Dries committed
43 44 45
    if ($links = link_node($node, $main)) {
      $this->template->assign("links", $this->links($links));
    }
Dries's avatar
 
Dries committed
46

Dries's avatar
 
Dries committed
47 48 49
    $this->template->parse("node");
    print $this->template->text("node");
    $this->template->reset("node");
Dries's avatar
 
Dries committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
  }

  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
72
  function header($title = "") {
Dries's avatar
 
Dries committed
73 74
    global $base_url;

Dries's avatar
 
Dries committed
75
    $this->template->assign(array(
Dries's avatar
 
Dries committed
76 77
      "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
78
      "base" => "$base_url/",
Dries's avatar
 
Dries committed
79
      "onload_attributes" => theme_onload_attribute(),
Dries's avatar
 
Dries committed
80 81
      "primary_links" => variable_get("xtemplate_primary_links", l("edit primary links", "admin/system/themes/xtemplate")),
      "secondary_links" => variable_get("xtemplate_secondary_links", l("edit secondary links", "admin/system/themes/xtemplate"))
Dries's avatar
 
Dries committed
82
    ));
Dries's avatar
 
Dries committed
83 84 85 86 87 88 89 90
    if (variable_get("xtemplate_search_box", 1)) {
      $this->template->assign(array(
        //"search" => search_form(),
        "search_url" => url("search"),
        "search_button_text" => t("Search")
      ));
      $this->template->parse("header.search_box");
    }
Dries's avatar
 
Dries committed
91 92

    if (!arg(0)) {
Dries's avatar
 
Dries committed
93
      $this->template->assign("header_message", variable_get("xtemplate_message", l("edit message", "admin/system/themes/xtemplate")));
Dries's avatar
 
Dries committed
94 95
      $this->template->parse("header.message");
    }
Dries's avatar
 
Dries committed
96 97 98

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

Dries's avatar
 
Dries committed
101
  function block($title, $content, $region = "main") {
Dries's avatar
 
Dries committed
102
    $this->template->assign(array(
Dries's avatar
 
Dries committed
103 104 105
      "subject" => $title,
      "content" => $content
    ));
Dries's avatar
 
Dries committed
106

Dries's avatar
 
Dries committed
107 108 109
    $this->template->parse("block");
    print $this->template->text("block");
    $this->template->reset("block");
Dries's avatar
 
Dries committed
110 111 112 113 114
  }

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

Dries's avatar
 
Dries committed
118 119 120
      $this->template->parse("box");
      print $this->template->text("box");
      $this->template->reset("box");
Dries's avatar
 
Dries committed
121 122 123 124
    }
  }

  function footer() {
Dries's avatar
 
Dries committed
125 126 127 128
    // unfortunately, theme_blocks PRINTS the blocks instead of RETURNING them.
    // so we need some output buffering
    ob_start();
    theme_blocks("all");
Dries's avatar
 
Dries committed
129 130
    $this->template->assign( array(
      "blocks" => ob_get_contents(),
Dries's avatar
 
Dries committed
131 132
      "footer_message" => variable_get("site_footer", ""),
      "footer" => theme_footer()
Dries's avatar
 
Dries committed
133
    ));
Dries's avatar
 
Dries committed
134
    ob_end_clean();
Dries's avatar
 
Dries committed
135 136 137 138 139 140

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