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

4 5 6 7 8
/**
* Basic theme
*
* @package theme system
*/
Kjartan's avatar
Changes  
Kjartan committed
9
class BaseTheme {
10 11
  var $background = "#ffffff";
  var $foreground = "#000000";
Dries's avatar
 
Dries 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 = "") {
Kjartan's avatar
Kjartan committed
22
    $output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n";
Dries's avatar
 
Dries 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's avatar
 
Dries 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's avatar
 
Dries committed
30
    print "</td><td valign=\"top\">";
Dries's avatar
 
Dries committed
31 32 33

  }

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

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

Dries's avatar
 
Dries committed
42
  function node($node, $main) {
43 44 45 46 47
    if (function_exists("taxonomy_node_get_terms")) {
      foreach (taxonomy_node_get_terms($node->nid) as $term) {
        $terms[] = l($term->name, array("or" => $term->tid), "index");
      }
    }
Dries's avatar
 
Dries committed
48

49 50 51 52
    $output = "<b>". check_output($node->title) ."</b> by ". format_name($node) ."<br />";
    if (count($terms)) {
      $output .= "<small>(". $this->links($terms) .")</small><br />";
    }
Dries's avatar
 
Dries committed
53
    if ($main && $node->teaser) {
Dries's avatar
 
Dries committed
54
      $output .= check_output($node->teaser, 1);
Dries's avatar
 
Dries committed
55 56 57
    }
    else {
      $output .= check_output($node->body, 1);
Dries's avatar
 
Dries committed
58
    }
59 60
    if ($links = link_node($node, $main)) {
      $output .= "<br />[ ". $this->links($links) ." ]";
Dries's avatar
 
Dries committed
61 62 63 64
    }
    $output .= "<hr />";

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

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

  function footer() {
Kjartan's avatar
Kjartan committed
73
    $output = "</td></tr></table>";
Dries's avatar
 
Dries committed
74 75 76 77
    $output .= "</body></html>";
    print $output;
  }

Kjartan's avatar
Changes  
Kjartan committed
78 79
}

Dries's avatar
 
Dries committed
80 81 82 83 84 85 86 87
function theme_mark() {
  /*
  ** Return a marker.  Used to indicate new comments or required form
  ** fields.
  */
  return "<span style=\"color: red;\">*</span>";
}

Dries's avatar
 
Dries committed
88
function theme_item_list($items = array(), $title = NULL) {
Dries's avatar
 
Dries committed
89 90 91 92
  /*
  ** Return a formatted array of items.
  */

Dries's avatar
 
Dries committed
93
  if (isset($title)) {
Dries's avatar
 
Dries committed
94 95 96
    $output .= "<b>$title</b><br />";
  }

Dries's avatar
 
Dries committed
97 98 99 100
  if (isset($items)) {
    foreach ($items as $item) {
      $output .= "- $item<br />";
    }
Dries's avatar
 
Dries committed
101 102 103 104 105
  }

  return $output;
}

Dries's avatar
 
Dries committed
106 107 108 109 110 111 112
function theme_error($message) {
  /*
  ** Return an error message.
  */
  return "<div style=\"color: red;\">$message</div>";
}

113 114
function theme_list() {
  static $list;
Dries's avatar
 
Dries committed
115

116 117 118 119
  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's avatar
 
Dries committed
120 121 122
      if (file_exists($theme->filename)) {
        $list[$theme->name] = $theme;
      }
123
    }
Dries's avatar
 
Dries committed
124
  }
125 126 127 128

  return $list;
}

Dries's avatar
 
Dries committed
129 130
function theme_head($main = 0) {
  $head = module_invoke_all("head", $main);
Dries's avatar
 
Dries committed
131
  return implode($head, "\n");
Dries's avatar
 
Dries committed
132 133
}

134 135 136 137 138 139 140
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);
Kjartan's avatar
Kjartan committed
141
    $theme_class = "Theme_$name";
142 143
    @$obj =& new $theme_class();
    $obj->path = dirname($themes[$name]->filename);
144
    return $obj;
Dries's avatar
 
Dries committed
145
  }
146

147 148
  @$obj =& new BaseTheme;
  return $obj;
Dries's avatar
 
Dries committed
149 150
}

Dries's avatar
 
Dries committed
151
function theme_blocks($region, &$theme) {
Dries's avatar
 
Dries committed
152
  global $user, $PHP_SELF;
Dries's avatar
 
Dries committed
153

Dries's avatar
 
Dries committed
154
  $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's avatar
 
Dries committed
155

156
  while ($result && ($block = db_fetch_object($result))) {
Dries's avatar
 
Dries committed
157 158 159 160
    if ((($block->status && (!$user->uid || !$block->custom)) || ($block->custom && $user->block[$block->module][$block->delta])) && (!$block->path || preg_match("|$block->path|", $PHP_SELF))) {
      $block_data = module_invoke($block->module, "block", "view", $block->delta);
      if ($block_data["content"]) {
        $theme->box($block_data["subject"], $block_data["content"], $region);
161
      }
Dries's avatar
 
Dries committed
162 163 164
    }
  }
}
165

Dries's avatar
 
Dries committed
166 167 168
function theme_invoke() {
  global $theme;
  $args = func_get_args();
Dries's avatar
 
Dries committed
169

Dries's avatar
 
Dries committed
170 171 172 173
  $function = array_shift($args);

  if (method_exists($theme, $function)) {
    return call_user_method_array($function, $theme, $args);
Dries's avatar
 
Dries committed
174
  }
Dries's avatar
 
Dries committed
175 176 177 178 179
  else {
    return call_user_func_array($function, $args);
  }
}

Dries's avatar
 
Dries committed
180
?>