theme.inc 3.97 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
  }
Kjartan's avatar
Changes  
Kjartan committed
7 8
}

Dries's avatar
 
Dries committed
9
function theme_init() {
Dries's avatar
 
Dries committed
10 11 12
  global $user, $themes;

  if ($user->theme && file_exists($themes[$user->theme][0])) {
Dries's avatar
 
Dries committed
13
    include_once $themes[$user->theme][0];
Dries's avatar
 
Dries committed
14 15
  }
  else {
Dries's avatar
 
Dries committed
16
    include_once $themes[variable_get("theme_default", key($themes))][0];
Dries's avatar
 
Dries committed
17 18 19 20
  }
  return new Theme();
}

21
function theme_account($region, $theme) {
Dries's avatar
 
Dries committed
22
  global $user;
Dries's avatar
 
Dries committed
23 24

  if ($user->id) {
Dries's avatar
 
Dries committed
25
    // Display account settings:
Dries's avatar
 
Dries committed
26 27 28 29 30 31 32 33
    $content .= "<table><tr><td nowrap=\"nowrap\">\n";
    $content .= "<a href=\"account.php?op=edit&type=information\">". t("your information") ."</a><BR>\n";
    $content .= "<a href=\"account.php?op=edit&type=settings\">". t("your settings") ."</a><BR>\n";
    $content .= "<a href=\"account.php?op=edit&type=blocks\">". t("your blocks") ."</a><BR>\n";
    $content .= "<a href=\"account.php?op=view&type=comments\">". t("your comments") ."</a><BR>\n";
    $content .= "<a href=\"account.php?op=view&type=contributions\">". t("your contributions") ."</a><BR>\n";
    $content .= "<a href=\"account.php?op=view&type=site\">". strtr(t("your %a"), array("%a" => variable_get("site_name", "drupal"))) ."</a><BR>\n";
    $content .= "<p />\n";
Dries's avatar
 
Dries committed
34

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

Dries's avatar
 
Dries committed
40
    foreach (module_list() as $name) {
Dries's avatar
 
Dries committed
41 42
      if (module_hook($name, "link")) {
        $links = module_invoke($name, "link", "menu");
Dries's avatar
 
Dries committed
43
        foreach ($links as $link) $content .= "$link<br />\n";
Dries's avatar
 
Dries committed
44
      }
Dries's avatar
 
Dries committed
45
    }
Dries's avatar
 
Dries committed
46
    if ($link) $content .= "<p />\n";
Dries's avatar
 
Dries committed
47

Dries's avatar
 
Dries committed
48 49
    $content .= "<a href=\"account.php?op=logout\">". t("logout") ."</a>\n";
    $content .= "</td></tr></table>\n";
Dries's avatar
 
Dries committed
50

51
    $theme->box($user->userid, $content, $region);
Dries's avatar
 
Dries committed
52 53
  }
  else {
Dries's avatar
 
Dries committed
54 55 56 57 58 59 60 61
    $output .= "<div align=\"center\">\n";
    $output .= " <form action=\"account.php?op=login\" method=\"post\">\n";
    $output .= "  <b>". t("Username") .":</b><br /><input name=\"userid\" size=\"15\"><p />\n";
    $output .= "  <b>". t("Password") .":</b><br /><input name=\"passwd\" size=\"15\" TYPE=\"password\"><br />\n";
    $output .= "  <input type=\"submit\" value=\"". t("Login") ."\"><br />\n";
    if (variable_get("account_register", 1)) $output .= "  <a href=\"account.php\">". t("REGISTER") ."</a>\n";
    $output .= " </form>\n";
    $output .= "</div>\n";
Dries's avatar
 
Dries committed
62

63
    $theme->box(t("Login"), $output, $region);
Dries's avatar
 
Dries committed
64 65 66 67
  }
}


Dries's avatar
 
Dries committed
68
function theme_blocks($region, $theme) {
Dries's avatar
 
Dries committed
69
  global $id, $PHP_SELF, $status, $user;
Dries's avatar
 
Dries committed
70

Dries's avatar
 
Dries committed
71
  switch (strrchr($PHP_SELF, "/")) {
Dries's avatar
 
Dries committed
72
    case "/node.php":
Dries's avatar
 
Dries committed
73
      if ($region != "left") {
Dries's avatar
 
Dries committed
74
        if ($user->id) $node = db_fetch_object(db_query("SELECT * FROM node WHERE nid = '$id'"));
75
        if ($node->status == $status[queued]) theme_moderation_results($theme, $node, $region);
Dries's avatar
 
Dries committed
76
      }
Dries's avatar
 
Dries committed
77
      break;
Dries's avatar
 
Dries committed
78
    case "/index.php":
Dries's avatar
Dries committed
79
      if ($user->id) $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->id'))". (($region == "left" || $region == "right") ? ($region == "left" ? " AND b.region = 0" : " AND b.region = 1") : "") ." ORDER BY weight");
Dries's avatar
 
Dries committed
80
      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
81
      while ($block = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
82
        $blocks = module_invoke($block->module, "block");
83
        $theme->box(t($blocks[$block->offset]["subject"]), $blocks[$block->offset]["content"], $region);
Dries's avatar
 
Dries committed
84 85
      }
      break;
Dries's avatar
 
Dries committed
86 87 88
  }
}

89
function theme_moderation_results($theme, $node, $region) {
90
  foreach (explode(",", $node->users) as $vote) {
Dries's avatar
 
Dries committed
91
    if ($vote) {
92
      $data = explode("=", $vote);
Dries's avatar
 
Dries committed
93
      $output .= format_username($data[0]) ." voted '$data[1]'.<br />";
Dries's avatar
 
Dries committed
94 95
    }
  }
Dries's avatar
 
Dries committed
96

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

Dries's avatar
 
Dries committed
100
?>