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

Kjartan Mannes's avatar
Changes    
Kjartan Mannes committed
3
class BaseTheme {
Dries Buytaert's avatar
   
Dries Buytaert committed
4
5
  function links($links, $delimiter = " | ") {
    return implode($delimiter, $links);
Dries Buytaert's avatar
   
Dries Buytaert committed
6
  }
Dries Buytaert's avatar
   
Dries Buytaert committed
7

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

Kjartan Mannes's avatar
Kjartan Mannes committed
12
  function comment_controls($threshold = 1, $mode = 3, $order = 1) {
Dries Buytaert's avatar
   
Dries Buytaert committed
13
14
15
16
17
18
19
20
21
22
23
24
    global $user, $id;

    if ($user->uid) {
      $output .= form_item(t("Node rating"), node_moderation($id) ." <input type=\"submit\" name=\"op\" value=\"". t("Update ratings") ."\" />", t("Nodes and comments can be moderated by assigning them a score: content with a high rating is made more visible."));
    }

    $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 Mannes's avatar
Kjartan Mannes committed
25
26
27
    return $output;
  }

Kjartan Mannes's avatar
Changes    
Kjartan Mannes committed
28
29
}

Dries Buytaert's avatar
   
Dries Buytaert committed
30
function theme_init() {
Dries Buytaert's avatar
   
Dries Buytaert committed
31
32
33
  global $user, $themes;

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

42
function theme_account($region, $theme) {
Dries Buytaert's avatar
   
Dries Buytaert committed
43
  global $user;
Dries Buytaert's avatar
   
Dries Buytaert committed
44

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

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

Dries Buytaert's avatar
   
Dries Buytaert committed
56
57
58
59
60
    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 Buytaert's avatar
   
Dries Buytaert committed
61
    $content .= "</td></tr></table>\n";
Dries Buytaert's avatar
   
Dries Buytaert committed
62

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

Dries Buytaert's avatar
   
Dries Buytaert committed
80
function theme_blocks($region, $theme) {
Dries Buytaert's avatar
   
Dries Buytaert committed
81
  global $id, $PHP_SELF, $user;
Dries Buytaert's avatar
   
Dries Buytaert committed
82

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

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

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

Dries Buytaert's avatar
   
Dries Buytaert committed
114
?>