theme.inc 3.65 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";
23
    $output .= "<html><head><title>". variable_get(site_name, "drupal") ."</title></head><body bgcolor=\"$this->background\" text=\"$this->foreground\">";
Dries's avatar
 
Dries committed
24 25 26
    $output .= "<table border=\"0\" cellspacing=\"4\" cellpadding=\"4\"><tr><td valign=\"top\" width=\"170\">";

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

  }

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

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

Dries's avatar
 
Dries committed
40
  function node($node, $main) {
41 42 43 44 45
    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
46

47 48 49 50
    $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
51 52 53 54 55
    if ($main && $node->teaser) {
      $output .= strip_tags(check_output($node->teaser, 1));
    }
    else {
      $output .= check_output($node->body, 1);
Dries's avatar
 
Dries committed
56
    }
57 58
    if ($links = link_node($node, $main)) {
      $output .= "<br />[ ". $this->links($links) ." ]";
Dries's avatar
 
Dries committed
59 60 61 62
    }
    $output .= "<hr />";

    print $output;
Dries's avatar
 
Dries committed
63 64
  }

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

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

Kjartan's avatar
Changes  
Kjartan committed
76 77
}

78 79
function theme_list() {
  static $list;
Dries's avatar
 
Dries committed
80

81 82 83 84
  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
85 86 87
      if (file_exists($theme->filename)) {
        $list[$theme->name] = $theme;
      }
88
    }
Dries's avatar
 
Dries committed
89
  }
90 91 92 93 94 95 96 97 98 99 100

  return $list;
}

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
101
    $theme_class = "Theme_$name";
102 103
    @$obj =& new $theme_class;
    return $obj;
Dries's avatar
 
Dries committed
104
  }
105

106 107
  @$obj =& new BaseTheme;
  return $obj;
Dries's avatar
 
Dries committed
108 109
}

Dries's avatar
 
Dries committed
110
function theme_blocks($region, &$theme) {
Dries's avatar
 
Dries committed
111
  global $id, $PHP_SELF, $user;
Dries's avatar
 
Dries committed
112

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

115
  while ($result && ($block = db_fetch_object($result))) {
116 117 118
    if (($block->status && (!$user->uid || !$block->custom)) || ($block->custom && $user->block[$block->name])) {
      $blocks = module_invoke($block->module, "block");
      if ($blocks[$block->delta]["content"]) {
Dries's avatar
 
Dries committed
119
        $theme->box($blocks[$block->delta]["subject"], $blocks[$block->delta]["content"], $region);
120
      }
Dries's avatar
 
Dries committed
121 122 123
    }
  }
}
124

Dries's avatar
 
Dries committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138
function theme_invoke() {
  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);
  }
}

Dries's avatar
 
Dries committed
139
?>