theme.inc 4.17 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 {
Dries's avatar
 
Dries committed
10

11 12 13 14 15 16 17 18
  function system($field) {
    $system["name"] = "I need a name o'wise one!";
    $system["author"] = "What is your name master?";
    $system["description"] = "What am I mighty one?";

    return $system[$field];
  }

19
  function header($title = "") {
Dries's avatar
 
Dries committed
20 21 22 23
    $output .= "<html><head><title>". variable_get(site_name, "drupal") ."</title></head><body>";
    $output .= "<table border=\"0\" cellspacing=\"4\" cellpadding=\"4\"><tr><td valign=\"top\" width=\"170\">";

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

  }

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

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

Dries's avatar
 
Dries committed
37 38 39 40 41 42 43
  function node($node, $main) {
    $output .= "<b>". check_output($node->title) ."</b> by ". format_name($node) ."<br />";
    if ($main && $node->teaser) {
      $output .= strip_tags(check_output($node->teaser, 1));
    }
    else {
      $output .= check_output($node->body, 1);
Dries's avatar
 
Dries committed
44
    }
45 46
    if ($links = link_node($node, $main)) {
      $output .= "<br />[ ". $this->links($links) ." ]";
Dries's avatar
 
Dries committed
47 48 49 50
    }
    $output .= "<hr />";

    print $output;
Dries's avatar
 
Dries committed
51 52
  }

Dries's avatar
 
Dries committed
53

Kjartan's avatar
Kjartan committed
54
  function comment_controls($threshold = 1, $mode = 3, $order = 1) {
Dries's avatar
 
Dries committed
55
    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
56 57
  }

Dries's avatar
 
Dries committed
58 59 60 61 62
  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
63
    $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
64 65 66 67 68 69
    $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
70 71 72 73 74 75 76 77 78 79 80 81

  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
82 83
}

84 85
function theme_list() {
  static $list;
Dries's avatar
 
Dries committed
86

87 88 89 90 91 92
  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)) {
      $list[$theme->name] = $theme;
    }
Dries's avatar
 
Dries committed
93
  }
94 95 96 97 98 99 100 101 102 103 104

  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
105
    $theme_class = "Theme_$name";
106 107
    @$obj =& new $theme_class;
    return $obj;
Dries's avatar
 
Dries committed
108
  }
109

110 111 112
  watchdog("warning", "No valid themes enabled.");
  @$obj =& new BaseTheme;
  return $obj;
Dries's avatar
 
Dries committed
113 114
}

Dries's avatar
 
Dries committed
115
function theme_blocks($region, &$theme) {
Dries's avatar
 
Dries committed
116
  global $id, $PHP_SELF, $user;
Dries's avatar
 
Dries committed
117

118
  $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
119

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

Dries's avatar
 
Dries committed
130
?>