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

Kjartan's avatar
Changes  
Kjartan committed
4
class BaseTheme {
Dries's avatar
 
Dries committed
5

6
  function header($title = "") {
Dries's avatar
 
Dries committed
7 8 9 10
    $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;
11
    $this->box(t("Navigation"), @implode("<br />", link_page())); theme_blocks("all", $this);
Dries's avatar
 
Dries committed
12
    print "</td><td valign=\"top\">";
Dries's avatar
 
Dries committed
13 14 15

  }

Dries's avatar
 
Dries committed
16
  function links($links, $delimiter = " | ") {
17
    return @implode($delimiter, $links);
Dries's avatar
 
Dries committed
18
  }
Dries's avatar
 
Dries committed
19

Dries's avatar
 
Dries committed
20 21
  function image($name) {
    return "misc/$name";
Dries's avatar
 
Dries committed
22
  }
Dries's avatar
 
Dries committed
23

Dries's avatar
 
Dries committed
24 25 26 27 28 29 30
  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
31
    }
32 33
    if ($links = link_node($node, $main)) {
      $output .= "<br />[ ". $this->links($links) ." ]";
Dries's avatar
 
Dries committed
34 35 36 37
    }
    $output .= "<hr />";

    print $output;
Dries's avatar
 
Dries committed
38 39
  }

Dries's avatar
 
Dries committed
40

Kjartan's avatar
Kjartan committed
41
  function comment_controls($threshold = 1, $mode = 3, $order = 1) {
Dries's avatar
 
Dries committed
42
    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
43 44
  }

Dries's avatar
 
Dries committed
45 46 47 48 49 50 51 52 53 54 55 56
  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>";
    $output .= " <tr><td><div style=\"margin-left: 10px; padding-bottom: 10px; font-size: 90%;\">". sprintf(t("by %s on %s"), format_name($comment), format_date($comment->timestamp)) ."</div></td></tr>";
    $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
57 58 59 60 61 62 63 64 65 66 67 68

  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
69 70
}

Dries's avatar
 
Dries committed
71
function theme_init() {
Dries's avatar
 
Dries committed
72 73
  global $user, $themes;

74 75
  if ($user->theme && file_exists($themes[$theme_name = $user->theme][0])) {
    include_once $themes[$theme_name][0];
Dries's avatar
 
Dries committed
76 77
  }
  else {
78
    include_once $themes[$theme_name = variable_get("theme_default", key($themes))][0];
Dries's avatar
 
Dries committed
79
  }
80 81 82

  $theme_class = 'Theme_'. $theme_name;
  return new $theme_class();
Dries's avatar
 
Dries committed
83 84
}

Dries's avatar
 
Dries committed
85
function theme_blocks($region, &$theme) {
86
  global $id, $PHP_SELF, $REQUEST_URI, $user;
Dries's avatar
 
Dries committed
87

88 89
  if ($user->uid) {
    $result = db_query("SELECT * FROM blocks b LEFT JOIN layout l ON b.name = l.block WHERE (b.status = 2 OR (b.status = 1 AND l.uid = '$user->uid'))". (($region == "left" OR $region == "right") ? ($region == "left" ? " AND b.region = 0" : " AND b.region = 1") : "") ." AND (b.path = '' OR '". strrchr($REQUEST_URI, "/") ."' RLIKE b.path) ORDER BY weight");
Dries's avatar
 
Dries committed
90
  }
91 92 93 94 95 96 97
  else {
    $result = db_query("SELECT * FROM blocks WHERE status = 2". (($region == "left" OR $region == "right") ? ($region == "left" ? " AND region = 0" : " AND region = 1") : "") ." ORDER BY weight");
  }
  while ($result && ($block = db_fetch_object($result))) {
    $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
98 99 100
    }
  }
}
101

Dries's avatar
 
Dries committed
102
?>