xtemplate.theme 9.68 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 5 6
if (!class_exists("XTemplate")) {
  include_once("themes/xtemplate/xtemplate.inc");
}
Dries's avatar
 
Dries committed
7 8
$template_directory = variable_get('xtemplate_template', 'default');
$GLOBALS["xtemplate"]->template = new XTemplate('xtemplate.xtmpl', 'themes/xtemplate/' . $template_directory);
Dries's avatar
 
Dries committed
9 10
$GLOBALS["xtemplate"]->template->SetNullBlock(" ");  // "" doesnt work!

Dries's avatar
 
Dries committed
11
function xtemplate_settings() {
Dries's avatar
 
Dries committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
  /*
  ** Compile a list of the available style sheets:
  */

  $fd = opendir('themes/xtemplate');
  while ($file = readdir($fd)) {
    if (is_dir("themes/xtemplate/$file") && !in_array($file, array('.', '..', 'CVS'))) {
      $files[$file] = $file;
    }
  }
  closedir($fd);

  $template_directory = variable_get('xtemplate_template', 'default');
  $group = form_select(t('Template'), 'xtemplate_template', variable_get('xtemplate_template', 'default'), $files, t('Selecting a different template will change the look and feel of your site.  To create a new template, create a new directory under <code>themes/xtemplate</code> and copy the contents of an existing template (e.g. <code>themes/xtemplate/default</code>) into it.  The new template will automatically become available in the selection menu and will be identified by its directory name.'));
  $output = form_group(t('Template selection'), $group);
Dries's avatar
 
Dries committed
27

Dries's avatar
 
Dries committed
28
  $group = form_textarea(t('Logo'), 'xtemplate_logo', variable_get('xtemplate_logo', "<img src=\"themes/xtemplate/$template_directory/logo.gif\" alt=\"Logo\" />"), 70, 4, t('The HTML code for displaying the logo.'));
Dries's avatar
 
Dries committed
29 30
  $group .= form_textarea(t('Primary links'), 'xtemplate_primary_links', variable_get('xtemplate_primary_links', l('edit primary links', 'admin/themes/xtemplate')), 70, 8, t('The HTML code for the primary links.'));
  $group .= form_textarea(t('Secondary links'), 'xtemplate_secondary_links', variable_get('xtemplate_secondary_links', l('edit secondary links', 'admin/themes/xtemplate')), 70, 8, t('The HTML code for the secondary links.'));
Dries's avatar
 
Dries committed
31 32 33
  $group .= form_textarea(t('Message on front page'), 'xtemplate_mission', variable_get('xtemplate_mission', 'edit mission'), 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..'));
  $group .= form_radios(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.'));
  $output .= form_group(t('Header settings'), $group);
Dries's avatar
 
Dries committed
34

Dries's avatar
 
Dries committed
35
  $group = form_checkbox(t('Display pictures with posts'), 'xtemplate_picture_node', 1, variable_get('xtemplate_picture_node', 0), t('Display individualized pictures identifying users with posts they start.'));
Dries's avatar
 
Dries committed
36
  $group .= form_checkbox(t('Display pictures with comments'), 'xtemplate_picture_comment', 1, variable_get('xtemplate_picture_comment', 0), t('Display individualized pictures identifying users with their comments.'));
Dries's avatar
 
Dries committed
37
  $output .= form_group(t('Avatar settings'), $group);
Dries's avatar
 
Dries committed
38

Dries's avatar
 
Dries committed
39
  return $output;
Dries's avatar
 
Dries committed
40 41
}

Dries's avatar
 
Dries committed
42
function xtemplate_help($section) {
Dries's avatar
 
Dries committed
43

Dries's avatar
 
Dries committed
44
  $output = '';
Dries's avatar
 
Dries committed
45

Dries's avatar
 
Dries committed
46
  switch ($section) {
Dries's avatar
 
Dries committed
47
    case 'admin/themes#description':
48
      $output = t('A template driven theme');
Dries's avatar
 
Dries committed
49
      break;
Dries's avatar
 
Dries committed
50 51
  }

Dries's avatar
 
Dries committed
52 53
  return $output;
}
Dries's avatar
 
Dries committed
54

Dries's avatar
 
Dries committed
55
function xtemplate_node($node, $main = 0, $page = 0) {
Dries's avatar
 
Dries committed
56
  global $xtemplate;
Dries's avatar
 
Dries committed
57

Dries's avatar
 
Dries committed
58
  $xtemplate->template->assign(array(
Dries's avatar
 
Dries committed
59 60 61
        "submitted" => t("Submitted by %a on %b.",
                      array("%a" => format_name($node),
                            "%b" => format_date($node->created))),
Dries's avatar
 
Dries committed
62
        "link"      => url("node/$node->nid"),
Dries's avatar
 
Dries committed
63
        "title"     => $node->title,
Dries's avatar
 
Dries committed
64 65
        "author"    => format_name($node),
        "date"      => format_date($node->created),
Dries's avatar
 
Dries committed
66
        "sticky"    => ($main && $node->sticky) ? 'sticky' : '',
Dries's avatar
 
Dries committed
67
        "content"   => ($main && $node->teaser) ? $node->teaser : $node->body));
Dries's avatar
 
Dries committed
68

Dries's avatar
 
Dries committed
69 70 71 72
  if ($page == 0) {
    $xtemplate->template->parse("node.title");
  }

Dries's avatar
 
Dries committed
73 74 75
  if ($picture = theme('user_picture', $node)) {
    $xtemplate->template->assign("picture", $picture);
    $xtemplate->template->parse("node.picture");
Dries's avatar
 
Dries committed
76 77
  }

Dries's avatar
 
Dries committed
78 79
  if (module_exist("taxonomy") && ($taxonomy = taxonomy_link("taxonomy terms", $node))) {
    $xtemplate->template->assign("taxonomy", theme_links($taxonomy));
Dries's avatar
 
Dries committed
80
    $xtemplate->template->parse("node.taxonomy");
Dries's avatar
 
Dries committed
81 82 83 84
  }

  if ($links = link_node($node, $main)) {
    $xtemplate->template->assign("links", theme_links($links));
Dries's avatar
 
Dries committed
85
    $xtemplate->template->parse("node.links");
Dries's avatar
 
Dries committed
86 87
  }

Dries's avatar
 
Dries committed
88
  $xtemplate->template->parse("node");
Dries's avatar
 
Dries committed
89
  $output = $xtemplate->template->text("node");
Dries's avatar
 
Dries committed
90
  $xtemplate->template->reset("node");
Dries's avatar
 
Dries committed
91
  return $output;
Dries's avatar
 
Dries committed
92
}
Dries's avatar
 
Dries committed
93

Dries's avatar
 
Dries committed
94
function xtemplate_comment($comment, $links = 0) {
Dries's avatar
 
Dries committed
95
  global $xtemplate;
Dries's avatar
 
Dries committed
96

Dries's avatar
 
Dries committed
97
  $xtemplate->template->assign(array (
Dries's avatar
 
Dries committed
98 99 100 101
    "new"       => t("new"),
    "submitted" => t("Submitted by %a on %b.",
                      array("%a" => format_name($comment),
                            "%b" => format_date($comment->timestamp))),
Dries's avatar
 
Dries committed
102
    "title"     => l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid"),
Dries's avatar
 
Dries committed
103 104 105
    "author"    => format_name($comment),
    "date"      => format_date($comment->timestamp),
    "content"   => $comment->comment
Dries's avatar
 
Dries committed
106
  ));
Dries's avatar
 
Dries committed
107

Dries's avatar
 
Dries committed
108
  if ($comment->new) {
Dries's avatar
 
Dries committed
109
    $xtemplate->template->parse("comment.new");
Dries's avatar
 
Dries committed
110
  }
Dries's avatar
 
Dries committed
111

Dries's avatar
 
Dries committed
112 113 114
  if ($picture = theme('user_picture', $comment)) {
    $xtemplate->template->assign("picture", $picture);
    $xtemplate->template->parse("comment.picture");
Dries's avatar
 
Dries committed
115 116
  }

Dries's avatar
 
Dries committed
117 118 119
  if ($links) {
    $xtemplate->template->assign("links", $links);
    $xtemplate->template->parse("comment.links");
Dries's avatar
 
Dries committed
120
  }
Dries's avatar
 
Dries committed
121

Dries's avatar
 
Dries committed
122 123 124 125
  $xtemplate->template->parse("comment");
  $output = $xtemplate->template->text("comment");
  $xtemplate->template->reset("comment");

Dries's avatar
 
Dries committed
126
  return $output;
Dries's avatar
 
Dries committed
127
}
Dries's avatar
 
Dries committed
128

Dries's avatar
 
Dries committed
129 130 131 132 133 134 135 136
function xtemplate_page($content, $title = NULL, $breadcrumb = NULL) {
  if (isset($title)) {
    drupal_set_title($title);
  }
  if (isset($breadcrumb)) {
    drupal_set_breadcrumb($breadcrumb);
  }

Dries's avatar
 
Dries committed
137
  global $xtemplate;
Dries's avatar
 
Dries committed
138
  $template_directory = variable_get('xtemplate_template', 'default');
Dries's avatar
 
Dries committed
139 140

  $xtemplate->template->assign(array(
Dries's avatar
 
Dries committed
141 142 143
    "head_title" => (drupal_get_title() ? drupal_get_title() ." | ". variable_get("site_name", "drupal") : variable_get("site_name", "drupal") ." | ". variable_get("site_slogan", "")),
    "site" => variable_get("site_name", "drupal"),
    "head" => drupal_get_html_head(),
Dries's avatar
 
Dries committed
144
    "directory" => "themes/xtemplate/$template_directory",
Dries's avatar
 
Dries committed
145 146
    "onload_attributes" => theme_onload_attribute(),
    "logo" => variable_get('xtemplate_logo', "<img src=\"themes/xtemplate/$template_directory/logo.gif\" alt=\"Logo\" />"),
Dries's avatar
 
Dries committed
147 148
    "primary_links" => variable_get("xtemplate_primary_links", l("edit primary links", "admin/themes/xtemplate")),
    "secondary_links" => variable_get("xtemplate_secondary_links", l("edit secondary links", "admin/themes/xtemplate"))
Dries's avatar
 
Dries committed
149
   ));
Dries's avatar
 
Dries committed
150

Dries's avatar
 
Dries committed
151 152 153 154 155
  if ($tabs = theme('menu_local_tasks')) {
    $xtemplate->template->assign("tabs", $tabs);
    $xtemplate->template->parse("header.title.tabs");
  }

Dries's avatar
 
Dries committed
156 157 158 159 160 161
  if ($title = drupal_get_title()) {
    $xtemplate->template->assign("title", $title);
    $xtemplate->template->assign("breadcrumb", theme("breadcrumb", drupal_get_breadcrumb()));
    $xtemplate->template->parse("header.title");
  }

Dries's avatar
 
Dries committed
162 163
  if ($help = menu_get_active_help()) {
    $xtemplate->template->assign("help", $help);
Dries's avatar
 
Dries committed
164 165 166
    $xtemplate->template->parse("header.help");
  }

Dries's avatar
 
Dries committed
167 168 169 170
  foreach (drupal_get_messages() as $message) {
    list($message, $type) = $message;
    $xtemplate->template->assign("message", ucfirst($message));
    $xtemplate->template->assign("type", $type);
Dries's avatar
 
Dries committed
171 172 173
    $xtemplate->template->parse("header.message");
  }

Dries's avatar
 
Dries committed
174 175 176 177
  if (variable_get("xtemplate_search_box", 1)) {
    $xtemplate->template->assign(array(
          //"search" => search_form(),
          "search_url" => url("search"),
Dries's avatar
 
Dries committed
178 179
          "search_button_text" => t("Search"),
          "search_description" => t("Enter the terms you wish to search for.")
Dries's avatar
 
Dries committed
180 181 182 183
          ));
    $xtemplate->template->parse("header.search_box");
  }

Dries's avatar
 
Dries committed
184 185
  // only parse the mission block if we are on the frontpage ...
  if ($_GET["q"] == variable_get("site_frontpage", "node") && ($mission = variable_get("xtemplate_mission", "edit mission"))) {
Dries's avatar
Dries committed
186
    $xtemplate->template->assign("mission", $mission);
Dries's avatar
 
Dries committed
187
    $xtemplate->template->parse("header.mission");
Dries's avatar
 
Dries committed
188 189
  }

190
  if ($blocks = theme("blocks", "left")) {
Dries's avatar
 
Dries committed
191 192 193 194 195
    $xtemplate->template->assign("blocks", $blocks);
    $xtemplate->template->parse("header.blocks");
  }

  $xtemplate->template->parse("header");
Dries's avatar
 
Dries committed
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
  $output = $xtemplate->template->text("header");

  $output .= "\n<!-- begin content -->\n";
  $output .= $content;
  $output .= "\n<!-- end content -->\n";

  if ($blocks = theme("blocks", "right")) {
    $xtemplate->template->assign("blocks", $blocks);
    $xtemplate->template->parse("footer.blocks");
  }

  // only parse the footer block if site_footer is set
  if ($footer_message = variable_get("site_footer", FALSE)) {
    $xtemplate->template->assign("footer_message", $footer_message);
    $xtemplate->template->parse("footer.message");
  }

  $xtemplate->template->assign("footer", theme_closure());
  $xtemplate->template->parse("footer");

  $output .= $xtemplate->template->text("footer");
Dries's avatar
 
Dries committed
217

Dries's avatar
 
Dries committed
218
  return $output;
Dries's avatar
 
Dries committed
219 220 221
}

function xtemplate_block(&$block) {
Dries's avatar
 
Dries committed
222
  global $xtemplate;
Dries's avatar
 
Dries committed
223 224 225

  // create template variables for all block variables (module, delta, region, subject, content, ...)
  foreach ($block as $key => $value) {
Dries's avatar
 
Dries committed
226
    $xtemplate->template->assign($key == "subject" ? "title" : $key, $value); // TODO: standardize on 'title' (ie. rename all $block["subject"] to "title")
Dries's avatar
 
Dries committed
227 228
  }
  $xtemplate->template->parse("block");
Dries's avatar
 
Dries committed
229
  $output = $xtemplate->template->text("block");
Dries's avatar
 
Dries committed
230
  $xtemplate->template->reset("block");
Dries's avatar
 
Dries committed
231
  return $output;
Dries's avatar
 
Dries committed
232 233 234
}

function xtemplate_box($title, $content, $region = "main") {
Dries's avatar
 
Dries committed
235
  global $xtemplate;
Dries's avatar
 
Dries committed
236 237

  $xtemplate->template->assign(array(
Dries's avatar
 
Dries committed
238
        "title" => $title,
Dries's avatar
 
Dries committed
239 240 241
        "content" => $content));

  $xtemplate->template->parse("box");
Dries's avatar
 
Dries committed
242
  $output = $xtemplate->template->text("box");
Dries's avatar
 
Dries committed
243
  $xtemplate->template->reset("box");
Dries's avatar
 
Dries committed
244
  return $output;
Dries's avatar
 
Dries committed
245 246
}

Dries's avatar
 
Dries committed
247
?>