theme.inc 5.17 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

Dries's avatar
 
Dries committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
  function user($region, $theme) {
    global $user;

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

      foreach (module_list() as $name) {
        if (module_hook($name, "link")) {
          $links = module_invoke($name, "link", "menu");
          foreach ($links as $link) $content .= "$link<br />\n";
        }
      }

      if (user_access("access administration pages")) {
        $content .= "<br />\n";
        $content .= "<a href=\"admin.php\">". strtr(t("administer %a"), array("%a" => variable_get("site_name", "drupal"))) ."</a><BR>\n";
      }

      $theme->box($user->name, $content, $region);
    }
    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);
    }
  }

Kjartan's avatar
Kjartan committed
46
  function comment_controls($threshold = 1, $mode = 3, $order = 1) {
Dries's avatar
 
Dries committed
47 48 49 50 51 52 53 54 55 56 57 58
    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's avatar
Kjartan committed
59 60 61
    return $output;
  }

Dries's avatar
 
Dries committed
62 63 64 65 66 67 68 69 70 71 72 73
  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;
  }
Kjartan's avatar
Changes  
Kjartan committed
74 75
}

Dries's avatar
 
Dries committed
76
function theme_init() {
Dries's avatar
 
Dries committed
77 78 79
  global $user, $themes;

  if ($user->theme && file_exists($themes[$user->theme][0])) {
Dries's avatar
 
Dries committed
80
    include_once $themes[$user->theme][0];
Dries's avatar
 
Dries committed
81 82
  }
  else {
Dries's avatar
 
Dries committed
83
    include_once $themes[variable_get("theme_default", key($themes))][0];
Dries's avatar
 
Dries committed
84 85 86 87
  }
  return new Theme();
}

Dries's avatar
 
Dries committed
88
function theme_blocks($region, $theme) {
Dries's avatar
 
Dries committed
89
  global $id, $PHP_SELF, $user;
Dries's avatar
 
Dries committed
90

Dries's avatar
 
Dries committed
91
  switch (strrchr($PHP_SELF, "/")) {
Dries's avatar
 
Dries committed
92
    case "/node.php":
Dries's avatar
 
Dries committed
93
      if ($region != "left") {
Dries's avatar
 
Dries committed
94
        if ($user->uid) $node = db_fetch_object(db_query("SELECT * FROM node WHERE nid = '$id'"));
Dries's avatar
 
Dries committed
95
        if ($node->status == node_status("queued")) theme_moderation_results($theme, $node, $region);
Dries's avatar
 
Dries committed
96
      }
Dries's avatar
 
Dries committed
97
      break;
Dries's avatar
 
Dries committed
98
    case "/index.php":
Dries's avatar
 
Dries committed
99 100

      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.userid = '$user->uid'))". (($region == "left" || $region == "right") ? ($region == "left" ? " AND b.region = 0" : " AND b.region = 1") : "") ." ORDER BY weight");
Dries's avatar
 
Dries committed
101
      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
102
      while ($result && ($block = db_fetch_object($result))) {
Dries's avatar
 
Dries committed
103
        $blocks = module_invoke($block->module, "block");
104
        if ($blocks[$block->offset]["content"])
Dries's avatar
 
Dries committed
105
          $theme->box(t($blocks[$block->delta]["subject"]), $blocks[$block->delta]["content"], $region);
Dries's avatar
 
Dries committed
106 107
      }
      break;
Dries's avatar
 
Dries committed
108 109 110
  }
}

111
function theme_moderation_results($theme, $node, $region) {
112
  foreach (explode(",", $node->users) as $vote) {
Dries's avatar
 
Dries committed
113
    if ($vote) {
114
      $data = explode("=", $vote);
Dries's avatar
 
Dries committed
115 116
      $account = user_load(array("uid" => $data[0]));
      $output .= format_name($account) ." voted '$data[1]'.<br />";
Dries's avatar
 
Dries committed
117 118
    }
  }
Dries's avatar
 
Dries committed
119

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

Dries's avatar
 
Dries committed
123
?>