summaryrefslogtreecommitdiff
path: root/includes/theme.inc
blob: 1822da23a0c42c4d1223abe9efae996458b33a91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php
// $Id$

/**
* Basic theme
*
* @package theme system
*/
class BaseTheme {
  var $background = "#ffffff";
  var $foreground = "#000000";

  function system($field) {
    $system["name"] = "Basic theme";
    $system["author"] = "Drupal";
    $system["description"] = "Basic theme. Lynx friendly";

    return $system[$field];
  }

  function header($title = "") {
    global $base_url;

    $output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n";
    $output .= "<html><head><title>". $title ? $title : variable_get(site_name, "drupal") ."</title>";
    $output .= "<base href=\"$base_url/\" />";
    $output .= theme_head($main);
    $output .= "</head><body bgcolor=\"$this->background\" text=\"$this->foreground". theme_onload_attribute(). "\">";
    $output .= "<table border=\"0\" cellspacing=\"4\" cellpadding=\"4\"><tr><td valign=\"top\" width=\"170\">";

    print $output;
    $this->box(t("Navigation"), @implode("<br />", link_page())); theme_blocks("all", $this);
    print "</td><td valign=\"top\">";

  }

  function links($links, $delimiter = " | ") {
    return implode($delimiter, $links);
  }

  function image($name) {
    return "misc/$name";
  }

  function node($node, $main) {
    if (module_exist("taxonomy")) {
      $terms = taxonomy_link("taxonomy terms", $node);
    }

    $output = "<b>$node->title</b> by ". format_name($node) ."<br />";

    if (count($terms)) {
      $output .= "<small>(". $this->links($terms) .")</small><br />";
    }

    if ($main && $node->teaser) {
      $output .= check_output($node->teaser);
    }
    else {
      $output .= check_output($node->body);
    }
    if ($links = link_node($node, $main)) {
      $output .= "<br />[ ". $this->links($links) ." ]";
    }
    $output .= "<hr />";

    print $output;
  }

  function box($subject, $content, $region = "main") {
    $output = "<p><b>$subject</b><br />$content</p>";
    print $output;
  }

  function block($subject, $content, $region = "main") {
    global $theme;

    $theme->box($subject, $content, $region);
  }

  function footer() {
    $output = "</td></tr></table>";
    $output .= theme_footer();
    $output .= "</body></html>";
    print $output;
  }

}

function theme_mark() {
  /*
  ** Return a marker.  Used to indicate new comments or required form
  ** fields.
  */
  return "<span style=\"color: red;\">*</span>";
}

function theme_item_list($items = array(), $title = NULL) {
  /*
  ** Return a formatted array of items.
  */

  if (isset($title)) {
    $output .= "<b>$title</b><br />";
  }

  if (isset($items)) {
    foreach ($items as $item) {
      $output .= "- $item<br />";
    }
  }

  return $output;
}

function theme_error($message) {
  /*
  ** Return an error message.
  */
  return "<div style=\"color: red;\">$message</div>";
}

function theme_list($refresh = 0) {
  static $list;

  if ($refresh) {
    unset($list);
  }

  if (!$list) {
    $list = array();
    $result = db_query("SELECT * FROM system where type = 'theme' AND status = '1' ORDER BY name");
    while ($theme = db_fetch_object($result)) {
      if (file_exists($theme->filename)) {
        $list[$theme->name] = $theme;
      }
    }
  }

  return $list;
}

function theme_head($main = 0) {
  $head = module_invoke_all("head", $main);
  return implode($head, "\n");
}

/*
 * Execute hook _footer() which is run at the end of the page right before
 * the </body> tag
 */
function theme_footer($main = 0) {
  $footer = module_invoke_all("footer", $main);
  return implode($footer, "\n");
}

function theme_init() {
  global $user;

  $themes = theme_list();
  $name = $user->theme ? $user->theme : variable_get("theme_default", 0);

  if (is_object($themes[$name])) {
    include_once($themes[$name]->filename);
    $class = "Theme_$name";
    $instance =& new $class();
    $instance->path = dirname($themes[$name]->filename);
  }
  else {
    $instance =& new BaseTheme;
  }

  return $instance;
}

/**
 * Render blocks available for $user and $region calling $theme->block($region).
 *
 * @param   string  $region   main|left|right
 */
function theme_blocks($region) {
  global $user, $REQUEST_URI;

  $result = db_query("SELECT * FROM blocks WHERE (status = '1' OR custom = '1') ". ($region != "all" ? "AND region = %d " : "") ."ORDER BY weight, module", $region == "left" ? 0 : 1);

  while ($result && ($block = db_fetch_object($result))) {
    if ((($block->status && (!$user->uid || !$block->custom)) || ($block->custom && $user->block[$block->module][$block->delta])) && (!$block->path || preg_match('/'. str_replace('/', '\/', $block->path) .'/', request_uri()))) {
      $block_data = module_invoke($block->module, "block", "view", $block->delta);
      if ($block_data["content"]) {
        theme("block", $block_data["subject"], $block_data["content"], $region);
      }
    }
  }
}

function theme() {
  global $theme;
  $args = func_get_args();

  $function = array_shift($args);

  if (method_exists($theme, $function)) {
    return call_user_method_array($function, $theme, $args);
  }
  else {
    return call_user_func_array($function, $args);
  }
}

/*
 * Call _onload hook in all modules to enable modules to insert javascript
 * that will get run once the page has been loaded by the browser
 */
function theme_onload_attribute($theme_onloads = array()) {
  if (!is_array($theme_onloads)) {
    $theme_onloads = array($theme_onloads);
  }
  // Merge theme onloads (javascript rollovers, image preloads, etc.)
  // with module onloads (htmlarea, etc.)
  $onloads = array_merge(module_invoke_all("onload"), $theme_onloads);
  if (count($onloads)) {
    return " onload=\"" . implode("; ", $onloads) . "\"";
  }
  return;
}

?>