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

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

  }

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

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

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

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

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

Dries's avatar
 
Dries committed
64

Kjartan's avatar
Kjartan committed
65
  function comment_controls($threshold = 1, $mode = 3, $order = 1) {
Dries's avatar
 
Dries committed
66
    return form_item(t("Comment viewing options"), comment_mode($mode) . comment_order($order) . comment_threshold($threshold) ." <input type=\"submit\" name=\"op\" value=\"". t("Update settings") ."\" />", t("Select your prefered way to display the comments and click 'Update settings' to active your changes."));
Kjartan's avatar
Kjartan committed
67 68
  }

Dries's avatar
 
Dries committed
69 70 71 72 73
  function comment($comment, $link = 0) {
    $output .= "<a name=\"$comment->cid\"></a>";
    $output .= "<div style=\"border: 1px solid; padding: 10px;\">";
    $output .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
    $output .= " <tr><td><div style=\"font-size: 110%; font-weight: bold;\">". check_output($comment->subject) ."</div></td><td align=\"right\" rowspan=\"2\" valign=\"top\">". comment_moderation($comment) ."</td></tr>";
Dries's avatar
 
Dries committed
74
    $output .= " <tr><td><div style=\"margin-left: 10px; padding-bottom: 10px; font-size: 90%;\">". t("by %a on %b", array("%a" => format_name($comment), "%b" => format_date($comment->timestamp))) ."</div></td></tr>";
Dries's avatar
 
Dries committed
75 76 77 78 79 80
    $output .= " <tr><td colspan=\"2\">". check_output($comment->comment, 1) ."</td></tr>";
    $output .= " <tr><td align=\"right\" colspan=\"2\">$link</td></tr>";
    $output .= "</table>";
    $output .= "</div><br />";
    print $output;
  }
Dries's avatar
 
Dries committed
81 82 83 84 85 86 87 88 89 90 91 92

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

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

Kjartan's avatar
Changes  
Kjartan committed
93 94
}

95 96
function theme_list() {
  static $list;
Dries's avatar
 
Dries committed
97

98 99 100 101
  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
102 103 104
      if (file_exists($theme->filename)) {
        $list[$theme->name] = $theme;
      }
105
    }
Dries's avatar
 
Dries committed
106
  }
107 108 109 110 111 112 113 114 115 116 117

  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
118
    $theme_class = "Theme_$name";
119 120
    @$obj =& new $theme_class;
    return $obj;
Dries's avatar
 
Dries committed
121
  }
122

123 124 125
  watchdog("warning", "No valid themes enabled.");
  @$obj =& new BaseTheme;
  return $obj;
Dries's avatar
 
Dries committed
126 127
}

Dries's avatar
 
Dries committed
128
function theme_blocks($region, &$theme) {
Dries's avatar
 
Dries committed
129
  global $id, $PHP_SELF, $user;
Dries's avatar
 
Dries committed
130

131
  $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
132

133
  while ($result && ($block = db_fetch_object($result))) {
134 135 136
    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
137
        $theme->box($blocks[$block->delta]["subject"], $blocks[$block->delta]["content"], $region);
138
      }
Dries's avatar
 
Dries committed
139 140 141
    }
  }
}
142

Dries's avatar
 
Dries committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156
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
157
?>