theme.inc 3.99 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
  function links($links, $delimiter = " | ") {
    return implode($delimiter, $links);
Dries's avatar
 
Dries committed
6
  }
Dries's avatar
 
Dries committed
7

Dries's avatar
 
Dries committed
8 9
  function image($name) {
    return "misc/$name";
Dries's avatar
 
Dries committed
10
  }
Dries's avatar
 
Dries committed
11

Kjartan's avatar
Kjartan committed
12 13 14 15
  function comment_controls($threshold = 1, $mode = 3, $order = 1) {
    global $REQUEST_URI, $user;
    $output .= "<DIV ALIGN=\"CENTER\">\n";
    $output .= "<FORM METHOD=\"post\" ACTION=\"$REQUEST_URI\">\n";
Dries's avatar
 
Dries committed
16 17 18
    $output .= comment_mode(($user->uid ? $user->mode : $mode));
    $output .= comment_order(($user->uid ? $user->sort : $order));
    $output .= comment_threshold(($user->uid ? $user->threshold : $threshold));
Kjartan's avatar
Kjartan committed
19 20 21 22 23 24 25
    $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Update settings") ."\">\n";
    $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Add comment") ."\">\n";
    $output .= "</FORM>\n";
    $output .= "</DIV>\n";
    return $output;
  }

Kjartan's avatar
Changes  
Kjartan committed
26 27
}

Dries's avatar
 
Dries committed
28
function theme_init() {
Dries's avatar
 
Dries committed
29 30 31
  global $user, $themes;

  if ($user->theme && file_exists($themes[$user->theme][0])) {
Dries's avatar
 
Dries committed
32
    include_once $themes[$user->theme][0];
Dries's avatar
 
Dries committed
33 34
  }
  else {
Dries's avatar
 
Dries committed
35
    include_once $themes[variable_get("theme_default", key($themes))][0];
Dries's avatar
 
Dries committed
36 37 38 39
  }
  return new Theme();
}

40
function theme_account($region, $theme) {
Dries's avatar
 
Dries committed
41
  global $user;
Dries's avatar
 
Dries committed
42

Dries's avatar
 
Dries committed
43
  if ($user->uid) {
Dries's avatar
 
Dries committed
44
    // Display account settings:
Dries's avatar
 
Dries committed
45
    $content .= "<table><tr><td nowrap=\"nowrap\">\n";
Dries's avatar
 
Dries committed
46

Dries's avatar
 
Dries committed
47
    foreach (module_list() as $name) {
Dries's avatar
 
Dries committed
48 49
      if (module_hook($name, "link")) {
        $links = module_invoke($name, "link", "menu");
Dries's avatar
 
Dries committed
50
        foreach ($links as $link) $content .= "$link<br />\n";
Dries's avatar
 
Dries committed
51
      }
Dries's avatar
 
Dries committed
52
    }
Dries's avatar
 
Dries committed
53

Dries's avatar
 
Dries committed
54 55 56 57 58
    if (user_access("access administration pages")) {
      $content .= "<p />\n";
      $content .= "<a href=\"admin.php\">". strtr(t("administer %a"), array("%a" => variable_get("site_name", "drupal"))) ."</a><BR>\n";
    }

Dries's avatar
 
Dries committed
59
    $content .= "</td></tr></table>\n";
Dries's avatar
 
Dries committed
60

Dries's avatar
 
Dries committed
61
    $theme->box($user->name, $content, $region);
Dries's avatar
 
Dries committed
62
  }
Dries's avatar
 
Dries committed
63 64 65 66 67 68 69 70 71 72 73 74 75
  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";

    $theme->box(t("Log in"), $output, $region);
  }

Dries's avatar
 
Dries committed
76 77
}

Dries's avatar
 
Dries committed
78
function theme_blocks($region, $theme) {
Dries's avatar
 
Dries committed
79
  global $id, $PHP_SELF, $status, $user;
Dries's avatar
 
Dries committed
80

Dries's avatar
 
Dries committed
81
  switch (strrchr($PHP_SELF, "/")) {
Dries's avatar
 
Dries committed
82
    case "/node.php":
Dries's avatar
 
Dries committed
83
      if ($region != "left") {
Dries's avatar
 
Dries committed
84
        if ($user->uid) $node = db_fetch_object(db_query("SELECT * FROM node WHERE nid = '$id'"));
85
        if ($node->status == $status[queued]) theme_moderation_results($theme, $node, $region);
Dries's avatar
 
Dries committed
86
      }
Dries's avatar
 
Dries committed
87
      break;
Dries's avatar
 
Dries committed
88
    case "/index.php":
Dries's avatar
 
Dries committed
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.user = '$user->uid'))". (($region == "left" || $region == "right") ? ($region == "left" ? " AND b.region = 0" : " AND b.region = 1") : "") ." ORDER BY weight");
Dries's avatar
 
Dries committed
90
      else $result = db_query("SELECT * FROM blocks WHERE status = 2". (($region == "left" || $region == "right") ? ($region == "left" ? " AND region = 0" : " AND region = 1") : "") ." ORDER BY weight");
Dries's avatar
 
Dries committed
91
      while ($block = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
92
        $blocks = module_invoke($block->module, "block");
93
        $theme->box(t($blocks[$block->offset]["subject"]), $blocks[$block->offset]["content"], $region);
Dries's avatar
 
Dries committed
94 95
      }
      break;
Dries's avatar
 
Dries committed
96 97 98
  }
}

99
function theme_moderation_results($theme, $node, $region) {
100
  foreach (explode(",", $node->users) as $vote) {
Dries's avatar
 
Dries committed
101
    if ($vote) {
102
      $data = explode("=", $vote);
Dries's avatar
 
Dries committed
103 104
      $account = user_load(array("uid" => $data[0]));
      $output .= format_name($account) ." voted '$data[1]'.<br />";
Dries's avatar
 
Dries committed
105 106
    }
  }
Dries's avatar
 
Dries committed
107

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

Dries's avatar
 
Dries committed
111
?>