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

Dries Buytaert's avatar
   
Dries Buytaert committed
3
function xtemplate_settings() {
Dries Buytaert's avatar
   
Dries Buytaert committed
4
5
  $output  = form_select("Sidebar placement", "xtemplate_sidebar", variable_get("xtemplate_sidebar", "right"), array("none" => t("No sidebars"), "left" => t("Sidebar on the left"), "right" => t("Sidebar on the right"), "both" => t("Sidebar on the left and the right")));
  $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 Buytaert's avatar
   
Dries Buytaert committed
6
7
  $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 Buytaert's avatar
   
Dries Buytaert committed
8
  $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.");
Dries Buytaert's avatar
   
Dries Buytaert committed
9
 return $output;
Dries Buytaert's avatar
   
Dries Buytaert committed
10
11
}

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

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

    return $system[$field];
  }

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

Dries Buytaert's avatar
   
Dries Buytaert committed
26
27
    $this->sidebar = variable_get("xtemplate_sidebar", "right");

Dries Buytaert's avatar
 
Dries Buytaert committed
28
29
30
31
    $this->template = new XTemplate("themes/xtemplate/xtemplate.xtmpl");
    $this->template->SetNullBlock(" ");  // "" doesnt work!
  }

Dries Buytaert's avatar
   
Dries Buytaert committed
32
  function node($node, $main = 0) {
Dries Buytaert's avatar
 
Dries Buytaert committed
33

34
35
    $this->template->assign(array(
       "link"      => url("node/view/$node->nid"),
Dries Buytaert's avatar
 
Dries Buytaert committed
36
37
38
       "title"     => ucfirst($node->title),
       "author"    => format_name($node),
       "date"      => format_date($node->created),
Dries Buytaert's avatar
   
Dries Buytaert committed
39
       "content"   => ($main && $node->teaser) ? $node->teaser : $node->body));
Dries Buytaert's avatar
 
Dries Buytaert committed
40

Dries Buytaert's avatar
   
Dries Buytaert committed
41
    if (module_exist("taxonomy") && ($taxonomy = taxonomy_link("taxonomy terms", $node))) {
Dries Buytaert's avatar
   
Dries Buytaert committed
42
43
44
      $this->template->assign("taxonomy", $this->links($taxonomy));
    }

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

Dries Buytaert's avatar
   
Dries Buytaert committed
49
50
51
    $this->template->parse("node");
    print $this->template->text("node");
    $this->template->reset("node");
Dries Buytaert's avatar
 
Dries Buytaert committed
52
53
54
55
56
57
58
  }

  function comment($comment, $link = 0) {
    $this->template->assign(array (
        "title"     => ucfirst($comment->subject),
        "author"    => format_name($comment),
        "date"      => format_date($comment->timestamp),
Dries Buytaert's avatar
   
Dries Buytaert committed
59
        "content"   => $comment->comment,
Dries Buytaert's avatar
 
Dries Buytaert committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
        "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 Buytaert's avatar
   
Dries Buytaert committed
74
  function header($title = "") {
Dries Buytaert's avatar
 
Dries Buytaert committed
75
    $this->template->assign(array(
Dries Buytaert's avatar
   
Dries Buytaert committed
76
77
      "title" => ($title ? $title." | ". variable_get("site_name", "drupal") : variable_get("site_name", "drupal") ." | ". variable_get("site_slogan", "")),
      "head" => theme_head(),
Dries Buytaert's avatar
   
Dries Buytaert committed
78
      "onload_attributes" => theme_onload_attribute(),
Dries Buytaert's avatar
   
Dries Buytaert committed
79
80
      "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 Buytaert's avatar
   
Dries Buytaert committed
81
    ));
Dries Buytaert's avatar
   
Dries Buytaert committed
82

Dries Buytaert's avatar
   
Dries Buytaert 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 Buytaert's avatar
   
Dries Buytaert committed
91

Dries Buytaert's avatar
   
Dries Buytaert committed
92
    if ($_GET["q"] == variable_get("site_frontpage", "node")) {
Dries Buytaert's avatar
   
Dries Buytaert committed
93
      $this->template->assign("header_message", variable_get("xtemplate_message", l("edit message", "admin/system/themes/xtemplate")));
Dries Buytaert's avatar
   
Dries Buytaert committed
94
95
      $this->template->parse("header.message");
    }
Dries Buytaert's avatar
 
Dries Buytaert committed
96

Dries Buytaert's avatar
   
Dries Buytaert committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    ob_start();

    if ($this->sidebar == "left") {
      theme_blocks("all");
    }
    else if ($this->sidebar == "both") {
      theme_blocks("left");
    }

    if ($blocks = ob_get_contents()) {
      $this->template->assign("blocks", $blocks);
      $this->template->parse("header.blocks");
    }

    ob_end_clean();

Dries Buytaert's avatar
 
Dries Buytaert committed
113
114
    $this->template->parse("header");
    print $this->template->text("header");
Dries Buytaert's avatar
   
Dries Buytaert committed
115
116


Dries Buytaert's avatar
   
Dries Buytaert committed
117
  }
Dries Buytaert's avatar
 
Dries Buytaert committed
118

Dries Buytaert's avatar
   
Dries Buytaert committed
119
  function block($title, $content, $region = "main") {
Dries Buytaert's avatar
 
Dries Buytaert committed
120
    $this->template->assign(array(
Dries Buytaert's avatar
   
Dries Buytaert committed
121
122
123
      "subject" => $title,
      "content" => $content
    ));
Dries Buytaert's avatar
 
Dries Buytaert committed
124

Dries Buytaert's avatar
   
Dries Buytaert committed
125
126
127
    $this->template->parse("block");
    print $this->template->text("block");
    $this->template->reset("block");
Dries Buytaert's avatar
 
Dries Buytaert committed
128
129
130
  }

  function box($title, $content, $region = "main") {
131
132
133
    $this->template->assign(array(
      "subject" => $title,
      "content" => $content));
Dries Buytaert's avatar
 
Dries Buytaert committed
134

135
136
137
    $this->template->parse("box");
    print $this->template->text("box");
    $this->template->reset("box");
Dries Buytaert's avatar
 
Dries Buytaert committed
138
139
140
  }

  function footer() {
Dries Buytaert's avatar
   
Dries Buytaert committed
141

Dries Buytaert's avatar
   
Dries Buytaert committed
142
    ob_start();
Dries Buytaert's avatar
   
Dries Buytaert committed
143
144
145
146
147
148
149
150

    if ($this->sidebar == "right") {
      theme_blocks("all");
    }
    else if ($this->sidebar == "both") {
      theme_blocks("right");
    }

Dries Buytaert's avatar
   
Dries Buytaert committed
151
152
153
154
    if ($blocks = ob_get_contents()) {
      $this->template->assign("blocks", $blocks);
      $this->template->parse("footer.blocks");
    }
Dries Buytaert's avatar
   
Dries Buytaert committed
155

Dries Buytaert's avatar
   
Dries Buytaert committed
156
    ob_end_clean();
Dries Buytaert's avatar
   
Dries Buytaert committed
157

Dries Buytaert's avatar
   
Dries Buytaert committed
158
    $this->template->assign( array(
Dries Buytaert's avatar
   
Dries Buytaert committed
159
160
      "footer_message" => variable_get("site_footer", ""),
      "footer" => theme_footer()
Dries Buytaert's avatar
   
Dries Buytaert committed
161
    ));
Dries Buytaert's avatar
 
Dries Buytaert committed
162
163
164
165
166
167

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