theme.inc 4.68 KB
Newer Older
Dries Buytaert's avatar
   
Dries Buytaert committed
1
<?php
2
// $Id$
3

4
5
6
7
8
/**
* Basic theme
*
* @package theme system
*/
Kjartan Mannes's avatar
Changes    
Kjartan Mannes committed
9
class BaseTheme {
10
11
  var $background = "#ffffff";
  var $foreground = "#000000";
Dries Buytaert's avatar
   
Dries Buytaert committed
12

13
  function system($field) {
14
15
16
    $system["name"] = "Basic theme";
    $system["author"] = "Drupal";
    $system["description"] = "Basic theme. Lynx friendly";
17
18
19
20

    return $system[$field];
  }

21
  function header($title = "") {
22
    $output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n";
Dries Buytaert's avatar
   
Dries Buytaert committed
23
24
25
    $output .= "<html><head><title>". variable_get(site_name, "drupal") ."</title>";
    $output .= theme_head($main);
    $output .= "</head><body bgcolor=\"$this->background\" text=\"$this->foreground\">";
Dries Buytaert's avatar
   
Dries Buytaert committed
26
27
28
    $output .= "<table border=\"0\" cellspacing=\"4\" cellpadding=\"4\"><tr><td valign=\"top\" width=\"170\">";

    print $output;
29
    $this->box(t("Navigation"), @implode("<br />", link_page())); theme_blocks("all", $this);
Dries Buytaert's avatar
   
Dries Buytaert committed
30
    print "</td><td valign=\"top\">";
Dries Buytaert's avatar
   
Dries Buytaert committed
31
32
33

  }

Dries Buytaert's avatar
   
Dries Buytaert committed
34
  function links($links, $delimiter = " | ") {
35
    return implode($delimiter, $links);
Dries Buytaert's avatar
   
Dries Buytaert committed
36
  }
Dries Buytaert's avatar
   
Dries Buytaert committed
37

Dries Buytaert's avatar
   
Dries Buytaert committed
38
39
  function image($name) {
    return "misc/$name";
Dries Buytaert's avatar
   
Dries Buytaert committed
40
  }
Dries Buytaert's avatar
   
Dries Buytaert committed
41

Dries Buytaert's avatar
   
Dries Buytaert committed
42
  function node($node, $main) {
Dries Buytaert's avatar
   
Dries Buytaert committed
43
44
    if (module_exist("taxonomy")) {
      $terms = taxonomy_link("taxonomy terms", $node);
45
    }
Dries Buytaert's avatar
   
Dries Buytaert committed
46

Dries Buytaert's avatar
   
Dries Buytaert committed
47
    $output = "<b>$node->title</b> by ". format_name($node) ."<br />";
Dries Buytaert's avatar
   
Dries Buytaert committed
48

49
50
51
    if (count($terms)) {
      $output .= "<small>(". $this->links($terms) .")</small><br />";
    }
Dries Buytaert's avatar
   
Dries Buytaert committed
52

Dries Buytaert's avatar
   
Dries Buytaert committed
53
    if ($main && $node->teaser) {
Dries Buytaert's avatar
   
Dries Buytaert committed
54
      $output .= check_output($node->teaser);
Dries Buytaert's avatar
   
Dries Buytaert committed
55
56
    }
    else {
Dries Buytaert's avatar
   
Dries Buytaert committed
57
      $output .= check_output($node->body);
Dries Buytaert's avatar
   
Dries Buytaert committed
58
    }
59
60
    if ($links = link_node($node, $main)) {
      $output .= "<br />[ ". $this->links($links) ." ]";
Dries Buytaert's avatar
   
Dries Buytaert committed
61
62
63
64
    }
    $output .= "<hr />";

    print $output;
Dries Buytaert's avatar
   
Dries Buytaert committed
65
66
  }

Dries Buytaert's avatar
   
Dries Buytaert committed
67
  function box($subject, $content, $region = "main") {
Dries Buytaert's avatar
   
Dries Buytaert committed
68
    $output = "<p><b>$subject</b><br />$content</p>";
Dries Buytaert's avatar
   
Dries Buytaert committed
69
70
71
    print $output;
  }

Dries Buytaert's avatar
   
Dries Buytaert committed
72
73
74
75
76
77
  function block($subject, $content, $region = "main") {
    global $theme;

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

Dries Buytaert's avatar
   
Dries Buytaert committed
78
  function footer() {
79
    $output = "</td></tr></table>";
Dries Buytaert's avatar
   
Dries Buytaert committed
80
81
82
83
    $output .= "</body></html>";
    print $output;
  }

Kjartan Mannes's avatar
Changes    
Kjartan Mannes committed
84
85
}

Dries Buytaert's avatar
   
Dries Buytaert committed
86
87
88
89
90
91
92
93
function theme_mark() {
  /*
  ** Return a marker.  Used to indicate new comments or required form
  ** fields.
  */
  return "<span style=\"color: red;\">*</span>";
}

Dries Buytaert's avatar
   
Dries Buytaert committed
94
function theme_item_list($items = array(), $title = NULL) {
Dries Buytaert's avatar
   
Dries Buytaert committed
95
96
97
98
  /*
  ** Return a formatted array of items.
  */

Dries Buytaert's avatar
   
Dries Buytaert committed
99
  if (isset($title)) {
Dries Buytaert's avatar
   
Dries Buytaert committed
100
101
102
    $output .= "<b>$title</b><br />";
  }

Dries Buytaert's avatar
   
Dries Buytaert committed
103
104
105
106
  if (isset($items)) {
    foreach ($items as $item) {
      $output .= "- $item<br />";
    }
Dries Buytaert's avatar
   
Dries Buytaert committed
107
108
109
110
111
  }

  return $output;
}

Dries Buytaert's avatar
   
Dries Buytaert committed
112
113
114
115
116
117
118
function theme_error($message) {
  /*
  ** Return an error message.
  */
  return "<div style=\"color: red;\">$message</div>";
}

Dries Buytaert's avatar
   
Dries Buytaert committed
119
function theme_list($refresh = 0) {
120
  static $list;
Dries Buytaert's avatar
   
Dries Buytaert committed
121

Dries Buytaert's avatar
   
Dries Buytaert committed
122
123
124
125
  if ($refresh) {
    unset($list);
  }

126
127
128
129
  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)) {
Dries Buytaert's avatar
   
Dries Buytaert committed
130
131
132
      if (file_exists($theme->filename)) {
        $list[$theme->name] = $theme;
      }
133
    }
Dries Buytaert's avatar
   
Dries Buytaert committed
134
  }
135
136
137
138

  return $list;
}

Dries Buytaert's avatar
   
Dries Buytaert committed
139
140
function theme_head($main = 0) {
  $head = module_invoke_all("head", $main);
Dries Buytaert's avatar
   
Dries Buytaert committed
141
  return implode($head, "\n");
Dries Buytaert's avatar
   
Dries Buytaert committed
142
143
}

144
145
146
147
148
function theme_init() {
  global $user;

  $themes = theme_list();
  $name = $user->theme ? $user->theme : variable_get("theme_default", 0);
Dries Buytaert's avatar
   
Dries Buytaert committed
149

150
151
  if (is_object($themes[$name])) {
    include_once($themes[$name]->filename);
Dries Buytaert's avatar
   
Dries Buytaert committed
152
153
154
155
156
157
    $class = "Theme_$name";
    $instance =& new $class();
    $instance->path = dirname($themes[$name]->filename);
  }
  else {
    $instance =& new BaseTheme;
Dries Buytaert's avatar
   
Dries Buytaert committed
158
  }
159

Dries Buytaert's avatar
   
Dries Buytaert committed
160
  return $instance;
Dries Buytaert's avatar
   
Dries Buytaert committed
161
162
}

Dries Buytaert's avatar
   
Dries Buytaert committed
163
164
165
166
167
168
/**
 * Render blocks available for $user and $region calling $theme->block($region).
 *
 * @param   string  $region   main|left|right
 */
function theme_blocks($region) {
Dries Buytaert's avatar
   
Dries Buytaert committed
169
  global $user, $REQUEST_URI;
Dries Buytaert's avatar
   
Dries Buytaert committed
170

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

173
  while ($result && ($block = db_fetch_object($result))) {
Dries Buytaert's avatar
   
Dries Buytaert committed
174
    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()))) {
Dries Buytaert's avatar
   
Dries Buytaert committed
175
176
      $block_data = module_invoke($block->module, "block", "view", $block->delta);
      if ($block_data["content"]) {
177
        theme("block", $block_data["subject"], $block_data["content"], $region);
178
      }
Dries Buytaert's avatar
   
Dries Buytaert committed
179
180
181
    }
  }
}
182

183
function theme() {
Dries Buytaert's avatar
   
Dries Buytaert committed
184
185
  global $theme;
  $args = func_get_args();
Dries Buytaert's avatar
   
Dries Buytaert committed
186

Dries Buytaert's avatar
   
Dries Buytaert committed
187
188
189
190
  $function = array_shift($args);

  if (method_exists($theme, $function)) {
    return call_user_method_array($function, $theme, $args);
Dries Buytaert's avatar
   
Dries Buytaert committed
191
  }
Dries Buytaert's avatar
   
Dries Buytaert committed
192
193
194
195
196
  else {
    return call_user_func_array($function, $args);
  }
}

Dries Buytaert's avatar
   
Dries Buytaert committed
197
?>