theme.inc 6.07 KB
Newer Older
Dries's avatar
 
Dries committed
1
<?php
2

Kjartan's avatar
Changes  
Kjartan committed
3
class BaseTheme {
Dries's avatar
 
Dries committed
4 5 6 7 8 9 10 11 12 13 14

  function header() {
    $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;
    $this->box(t("Navigation"), implode("<br />", link_page())); $this->user("all", $this); theme_blocks("all", $this);
    print "</td><td valgin=\"top\">";

  }

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

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

Dries's avatar
 
Dries committed
23
  function user($region) {
Dries's avatar
 
Dries committed
24 25 26 27 28
    global $user;

    if ($user->uid) {
      // Display account settings:

Dries's avatar
 
Dries committed
29 30
      $output .= "<div width=\"125\">\n";

Dries's avatar
 
Dries committed
31 32 33
      foreach (module_list() as $name) {
        if (module_hook($name, "link")) {
          $links = module_invoke($name, "link", "menu");
Dries's avatar
 
Dries committed
34 35 36
          foreach ($links as $link) {
            $output .= "$link<br />\n";
          }
Dries's avatar
 
Dries committed
37 38 39 40
        }
      }

      if (user_access("access administration pages")) {
Dries's avatar
 
Dries committed
41 42
        $output .= "<br />\n";
        $output .= "<a href=\"admin.php\">". strtr(t("administer %a"), array("%a" => variable_get("site_name", "drupal"))) ."</a><BR>\n";
Dries's avatar
 
Dries committed
43 44
      }

Dries's avatar
 
Dries committed
45 46
      $output .= "</div>";

Dries's avatar
 
Dries committed
47
      $this->box($user->name, $output, $region);
Dries's avatar
 
Dries committed
48 49 50 51 52 53 54 55 56 57 58
    }
    else {
      $output .= "<div align=\"center\">\n";
      $output .= " <form action=\"module.php?mod=user&op=login\" method=\"post\">\n";
      $output .= "  <b>". t("Username") .":</b><br /><input name=\"edit[name]\" size=\"15\"><p />\n";
      $output .= "  <b>". t("Password") .":</b><br /><input name=\"edit[pass]\" size=\"15\" TYPE=\"password\"><br />\n";
      $output .= "  <input type=\"submit\" value=\"". t("Log in") ."\"><br />\n";
      if (variable_get("account_register", 1)) $output .= "  <a href=\"module.php?mod=user\">". t("REGISTER") ."</a>\n";
      $output .= " </form>\n";
      $output .= "</div>\n";

Dries's avatar
 
Dries committed
59 60 61 62 63 64 65 66 67 68 69
      $this->box(t("Log in"), $output, $region);
    }
  }

  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
70
    }
Dries's avatar
 
Dries committed
71 72 73 74 75 76
    if ($main) {
      $output .= "<br />[ ". $this->links(link_node($node)) ." ]";
    }
    $output .= "<hr />";

    print $output;
Dries's avatar
 
Dries committed
77 78
  }

Dries's avatar
 
Dries committed
79

Kjartan's avatar
Kjartan committed
80
  function comment_controls($threshold = 1, $mode = 3, $order = 1) {
Dries's avatar
 
Dries committed
81 82 83 84 85 86 87 88
    global $user, $id;

    $output .= 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."));

    if (user_access("post comment")) {
      $output .= form_item(t("Add a comment"), "<input type=\"submit\" name=\"op\" value=\"". t("Add comment") ."\" />", t("Click 'Add comment' to start a new thread in the discussion."));
    }

Kjartan's avatar
Kjartan committed
89 90 91
    return $output;
  }

Dries's avatar
 
Dries committed
92 93 94 95 96 97 98 99 100 101 102 103
  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
104 105 106 107 108 109 110 111 112 113 114 115

  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
116 117
}

Dries's avatar
 
Dries committed
118
function theme_init() {
Dries's avatar
 
Dries committed
119 120 121
  global $user, $themes;

  if ($user->theme && file_exists($themes[$user->theme][0])) {
Dries's avatar
 
Dries committed
122
    include_once $themes[$user->theme][0];
Dries's avatar
 
Dries committed
123 124
  }
  else {
Dries's avatar
 
Dries committed
125
    include_once $themes[variable_get("theme_default", key($themes))][0];
Dries's avatar
 
Dries committed
126 127 128 129
  }
  return new Theme();
}

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

Dries's avatar
 
Dries committed
133
  switch (strrchr($PHP_SELF, "/")) {
Dries's avatar
 
Dries committed
134
    case "/node.php":
Dries's avatar
 
Dries committed
135
      if ($region != "left") {
Dries's avatar
 
Dries committed
136
        if ($user->uid) $node = db_fetch_object(db_query("SELECT * FROM node WHERE nid = '$id'"));
Dries's avatar
 
Dries committed
137
        if ($node->status == node_status("queued")) theme_moderation_results($theme, $node, $region);
Dries's avatar
 
Dries committed
138
      }
Dries's avatar
 
Dries committed
139
      break;
Dries's avatar
 
Dries committed
140
    case "/index.php":
Dries's avatar
 
Dries committed
141

Dries's avatar
 
Dries committed
142
      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") : "") ." ORDER BY weight");
Dries's avatar
 
Dries committed
143
      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");
Dries's avatar
 
Dries committed
144
      while ($result && ($block = db_fetch_object($result))) {
Dries's avatar
 
Dries committed
145
        $blocks = module_invoke($block->module, "block");
146
        if ($blocks[$block->delta]["content"])
Dries's avatar
 
Dries committed
147
          $theme->box(t($blocks[$block->delta]["subject"]), $blocks[$block->delta]["content"], $region);
Dries's avatar
 
Dries committed
148 149
      }
      break;
Dries's avatar
 
Dries committed
150 151 152
  }
}

Dries's avatar
 
Dries committed
153
function theme_moderation_results(&$theme, $node, $region) {
154
  foreach (explode(",", $node->users) as $vote) {
Dries's avatar
 
Dries committed
155
    if ($vote) {
156
      $data = explode("=", $vote);
Dries's avatar
 
Dries committed
157 158
      $account = user_load(array("uid" => $data[0]));
      $output .= format_name($account) ." voted '$data[1]'.<br />";
Dries's avatar
 
Dries committed
159 160
    }
  }
Dries's avatar
 
Dries committed
161

162
  $theme->box(t("Moderation results"), ($output ? $output : t("This node has not been moderated yet.")), $region);
Dries's avatar
 
Dries committed
163 164
}

Dries's avatar
 
Dries committed
165
?>