xtemplate.theme 6.46 KB
Newer Older
Dries's avatar
 
Dries committed
1
<?php
Dries's avatar
 
Dries committed
2
// $Id$
Dries's avatar
 
Dries committed
3

Dries's avatar
 
Dries committed
4
function xtemplate_settings() {
Dries's avatar
 
Dries committed
5 6 7 8 9 10 11
  $output  = form_select(t("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(t("Message on front page"), "xtemplate_message", variable_get("xtemplate_message", "edit message"), 70, 6, t("This text will be displayed on the front page.  It can be used to display a mission statement, announcement or site description.."));
  $output .= form_textfield(t("Stylesheet URL"), "xtemplate_stylesheet", variable_get("xtemplate_stylesheet", "themes/xtemplate/xtemplate.css"), 100, 300, t("The URL for your theme's cascading stylesheet."));
  $output .= form_textarea(t("Logo"), "xtemplate_logo", variable_get("xtemplate_logo", "<img src=\"themes/xtemplate/images/druplicon.gif\" />"), 70, 4, t("The HTML code for displaying the logo."));
  $output .= form_textarea(t("Primary links"), "xtemplate_primary_links", variable_get("xtemplate_primary_links", l("edit primary links", "admin/system/themes/xtemplate")), 70, 8, t("The HTML code for the primary links."));
  $output .= form_textarea(t("Secondary links"), "xtemplate_secondary_links", variable_get("xtemplate_secondary_links", l("edit secondary links", "admin/system/themes/xtemplate")), 70, 8, t("The HTML code for the secondary links."));
  $output .= form_select(t("Search box"), "xtemplate_search_box", variable_get("xtemplate_search_box", 0), array(t("Disabled"), t("Enabled")), t("Show a search box in the upper right corner."));
Dries's avatar
 
Dries committed
12
 return $output;
Dries's avatar
 
Dries committed
13 14
}

Dries's avatar
 
Dries committed
15 16 17 18
class Theme_xtemplate extends BaseTheme {

  function system($field) {
    $system["name"] = "xtemplate";
Dries's avatar
 
Dries committed
19
    $system["description"] = "a template driven theme";
Dries's avatar
 
Dries committed
20 21 22 23 24

    return $system[$field];
  }

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

Dries's avatar
 
Dries committed
29 30
    $this->sidebar = variable_get("xtemplate_sidebar", "right");

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

Dries's avatar
 
Dries committed
35
  function node($node, $main = 0) {
Dries's avatar
 
Dries committed
36

37
    $this->template->assign(array(
Dries's avatar
 
Dries committed
38
       "link"      => node_url($node),
Dries's avatar
 
Dries committed
39 40 41
       "title"     => ucfirst($node->title),
       "author"    => format_name($node),
       "date"      => format_date($node->created),
Dries's avatar
 
Dries committed
42
       "content"   => ($main && $node->teaser) ? $node->teaser : $node->body));
Dries's avatar
 
Dries committed
43

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

Dries's avatar
 
Dries committed
48 49 50
    if ($links = link_node($node, $main)) {
      $this->template->assign("links", $this->links($links));
    }
Dries's avatar
 
Dries committed
51

Dries's avatar
 
Dries committed
52 53 54
    $this->template->parse("node");
    print $this->template->text("node");
    $this->template->reset("node");
Dries's avatar
 
Dries committed
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),
Dries's avatar
 
Dries committed
62
        "content"   => $comment->comment,
Dries's avatar
 
Dries committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76
        "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
77
  function header($title = "") {
Dries's avatar
 
Dries committed
78
    $this->template->assign(array(
Dries's avatar
 
Dries committed
79 80
      "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
81
      "stylesheet" => variable_get("xtemplate_stylesheet", "themes/xtemplate/xtemplate.css"),
Dries's avatar
 
Dries committed
82
      "onload_attributes" => theme_onload_attribute(),
Dries's avatar
 
Dries committed
83
      "logo" => variable_get("xtemplate_logo", "<img src=\"themes/xtemplate/images/druplicon.gif\" />"),
Dries's avatar
 
Dries committed
84 85
      "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
86
    ));
Dries's avatar
 
Dries committed
87

Dries's avatar
 
Dries committed
88 89 90 91 92 93 94 95
    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
96

Dries's avatar
 
Dries committed
97 98 99
    // only parse the message block if we are on the frontpage ...
    if ($_GET["q"] == variable_get("site_frontpage", "node") && ($message = variable_get("xtemplate_message", "edit message"))) {
      $this->template->assign("header_message", $message);
Dries's avatar
 
Dries committed
100 101
      $this->template->parse("header.message");
    }
Dries's avatar
 
Dries committed
102

Dries's avatar
 
Dries committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
    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's avatar
 
Dries committed
119 120
    $this->template->parse("header");
    print $this->template->text("header");
Dries's avatar
 
Dries committed
121
  }
Dries's avatar
 
Dries committed
122

Dries's avatar
 
Dries committed
123
  function block($title, $content, $region = "main") {
Dries's avatar
 
Dries committed
124
    $this->template->assign(array(
Dries's avatar
 
Dries committed
125 126 127
      "subject" => $title,
      "content" => $content
    ));
Dries's avatar
 
Dries committed
128

Dries's avatar
 
Dries committed
129 130 131
    $this->template->parse("block");
    print $this->template->text("block");
    $this->template->reset("block");
Dries's avatar
 
Dries committed
132 133 134
  }

  function box($title, $content, $region = "main") {
135 136 137
    $this->template->assign(array(
      "subject" => $title,
      "content" => $content));
Dries's avatar
 
Dries committed
138

139 140 141
    $this->template->parse("box");
    print $this->template->text("box");
    $this->template->reset("box");
Dries's avatar
 
Dries committed
142 143 144
  }

  function footer() {
Dries's avatar
 
Dries committed
145

Dries's avatar
 
Dries committed
146
    ob_start();
Dries's avatar
 
Dries committed
147 148 149 150 151 152 153 154

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

Dries's avatar
 
Dries committed
155 156 157 158
    if ($blocks = ob_get_contents()) {
      $this->template->assign("blocks", $blocks);
      $this->template->parse("footer.blocks");
    }
Dries's avatar
 
Dries committed
159

Dries's avatar
 
Dries committed
160
    ob_end_clean();
Dries's avatar
 
Dries committed
161

Dries's avatar
 
Dries committed
162 163 164 165 166
    // only parse the footer block if site_footer is set
    if ($footer_message = variable_get("site_footer", FALSE)) {
      $this->template->assign("footer_message", $footer_message);
      $this->template->parse("footer.message");
    }
Dries's avatar
 
Dries committed
167

Dries's avatar
 
Dries committed
168
    $this->template->assign("footer", theme_footer());
Dries's avatar
 
Dries committed
169
    $this->template->parse("footer");
Dries's avatar
 
Dries committed
170

Dries's avatar
 
Dries committed
171 172 173 174
    print $this->template->text("footer");
  }
}
?>