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

Dries's avatar
 
Dries committed
3
function theme_init() {
Dries's avatar
 
Dries committed
4 5 6
  global $user, $themes;

  if ($user->theme && file_exists($themes[$user->theme][0])) {
Dries's avatar
 
Dries committed
7
    include_once $themes[$user->theme][0];
Dries's avatar
 
Dries committed
8 9
  }
  else {
Dries's avatar
 
Dries committed
10
    include_once $themes[variable_get(theme_default, key($themes))][0];
Dries's avatar
 
Dries committed
11 12 13 14
  }
  return new Theme();
}

Dries's avatar
 
Dries committed
15
function theme_link($separator = " | ") {
Kjartan's avatar
Changes  
Kjartan committed
16
  global $repository;
Dries's avatar
 
Dries committed
17 18 19 20 21
  $links[] = "<A HREF=\"index.php\">". t("home") ."</A>";
  $links[] = "<A HREF=\"search.php\">". t("search") ."</A>";
  $links[] = "<A HREF=\"submit.php\">". t("submit") ."</A>";
  if ($repository[forum]) $links[] = "<A HREF=\"module.php?mod=forum\">".t("forum") ."</A>";
  if ($repository[diary]) $links[] = "<A HREF=\"module.php?mod=diary\">". t("diary") ."</A>";
Kjartan's avatar
Changes  
Kjartan committed
22
  $links[] = "<A HREF=\"account.php\">". t("account") ."</A>";
Dries's avatar
 
Dries committed
23 24
  if ($repository[book]) $links[] = "<A HREF=\"module.php?mod=book\">". t("handbook") ."</A>";

Dries's avatar
 
Dries committed
25 26 27
  return implode($separator, $links);
}

Dries's avatar
 
Dries committed
28 29 30 31 32
function theme_menu($name, $module) {
  global $menu;
  if ($module["menu"]) $menu = ($menu) ? array_merge($menu, $module["menu"]()) : $module["menu"]();
}

Dries's avatar
 
Dries committed
33
function theme_account($theme) {
Dries's avatar
 
Dries committed
34
  global $user, $links, $menu;
Dries's avatar
 
Dries committed
35 36

  if ($user->id) {
Dries's avatar
 
Dries committed
37 38


Dries's avatar
 
Dries committed
39
    module_iterate("theme_menu");
Dries's avatar
 
Dries committed
40

Dries's avatar
 
Dries committed
41
    // Display account settings:
Dries's avatar
 
Dries committed
42
    $content .= "<LI><A HREF=\"account.php?op=track&topic=comments\">". t("track your comments") ."</A></LI>\n";
Dries's avatar
 
Dries committed
43
    $content .= "<LI><A HREF=\"account.php?op=track&topic=nodes\">". t("track your nodes") ."</A></LI>\n";
Dries's avatar
 
Dries committed
44
    $content .= "<LI><A HREF=\"account.php?op=track&topic=site\">". strtr(t("track %a"), array("%a" => variable_get(site_name, "drupal"))) ."</A></LI>\n";
Dries's avatar
 
Dries committed
45
    $content .= "<P>\n";
Dries's avatar
 
Dries committed
46 47 48
    $content .= "<LI><A HREF=\"account.php?op=edit&topic=user\">". t("edit your information") ."</A></LI>\n";
    $content .= "<LI><A HREF=\"account.php?op=edit&topic=site\">". t("edit your preferences") ."</A></LI>\n";
    $content .= "<LI><A HREF=\"account.php?op=edit&topic=content\">". t("edit your content") ."</A></LI>\n";
Dries's avatar
 
Dries committed
49
    $content .= "<P>\n";
Dries's avatar
 
Dries committed
50

Dries's avatar
 
Dries committed
51
    if (user_access($user)) {
Dries's avatar
 
Dries committed
52
      $content .= "<LI><A HREF=\"admin.php\">administer ". variable_get(site_name, "drupal") ."</A></LI>\n";
Dries's avatar
 
Dries committed
53 54 55
      $content .= "<P>\n";
    }

Dries's avatar
 
Dries committed
56 57
    if ($menu) {
      foreach ($menu as $link) $content .= "<LI>$link</LI>\n";
Dries's avatar
 
Dries committed
58 59
      $content .= "<P>\n";
    }
Dries's avatar
 
Dries committed
60

Dries's avatar
 
Dries committed
61
    $content .= "<LI><A HREF=\"account.php?op=logout\">". t("logout") ."</A></LI>\n";
Dries's avatar
 
Dries committed
62

Dries's avatar
 
Dries committed
63
    $theme->box(strtr(t("%a's configuration"), array("%a" => $user->userid)), "$content");
Dries's avatar
 
Dries committed
64 65
  }
  else {
Dries's avatar
 
Dries committed
66
    $output .= "<DIV ALIGN=\"center\">\n";
Dries's avatar
 
Dries committed
67 68 69 70 71
    $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";
    $output .= "  <A HREF=\"account.php\">". t("REGISTER") ."</A>\n";
Dries's avatar
 
Dries committed
72
    $output .= " </FORM>\n";
Dries's avatar
 
Dries committed
73
    $output .= "</DIV>\n";
Dries's avatar
 
Dries committed
74

Dries's avatar
 
Dries committed
75
    $theme->box(t("Login"), $output);
Dries's avatar
 
Dries committed
76 77 78 79
  }
}


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

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

Dries's avatar
 
Dries committed
102
function theme_morelink($theme, $node) {
Dries's avatar
 
Dries committed
103
  return ($node->body) ? "[ <A HREF=\"node.php?id=$node->nid\"><FONT COLOR=\"$theme->link\">". t("read more") ."</FONT></A> | ". sizeof(explode(" ", $node->body)) ." ". t("words") ." | <A HREF=\"node.php?id=$node->nid\"><FONT COLOR=\"$theme->link\">". format_plural(node_get_comments($node->nid), "comment", "comments") ."</FONT></A> ]" : "[ <A HREF=\"node.php?id=$node->nid\"><FONT COLOR=\"$theme->link\">". format_plural(node_get_comments($node->nid), "comment", "comments") ."</FONT></A> ]";
Dries's avatar
 
Dries committed
104 105
}

Dries's avatar
 
Dries committed
106
function theme_moderation_results($theme, $node) {
Dries's avatar
 
Dries committed
107 108
  global $user;

Dries's avatar
 
Dries committed
109 110
  if ($user->id && $node->nid && ($user->id == $node->author || user_get($user, "history", "n$node->nid"))) {
    $result = db_query("SELECT * FROM users WHERE history LIKE '%n$node->nid%'");
Dries's avatar
 
Dries committed
111
    while ($account = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
112
      $output .= format_username($account->userid) ." voted '". user_get($account, "history", "n$node->nid") ."'.<BR>";
Dries's avatar
 
Dries committed
113
    }
Dries's avatar
 
Dries committed
114

Dries's avatar
 
Dries committed
115
    $theme->box(t("Moderation results"), ($output ? $output : t("This node has not been moderated yet.")));
Dries's avatar
 
Dries committed
116 117 118
  }
}

Dries's avatar
 
Dries committed
119 120 121 122
/*
//
// depricated -> new block strategy
//
Dries's avatar
 
Dries committed
123
function theme_new_headlines($theme, $num = 10) {
Dries's avatar
 
Dries committed
124
  $result = db_query("SELECT nid, title FROM node WHERE status = 2 AND type = 'story' ORDER BY nid DESC LIMIT $num");
Dries's avatar
 
Dries committed
125
  while ($node = db_fetch_object($result)) $content .= "<LI><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></LI>\n";
Dries's avatar
 
Dries committed
126
  $theme->box(t("Latest headlines"), $content);
Dries's avatar
 
Dries committed
127
}
128

Dries's avatar
 
Dries committed
129 130
function theme_old_headlines($theme, $num = 10) {
  global $user;
Dries's avatar
 
Dries committed
131

Dries's avatar
 
Dries committed
132 133 134 135 136
  $result = db_query("SELECT id, subject, timestamp FROM story WHERE status = 2 ORDER BY timestamp DESC LIMIT ". ($user->nodes ? $user->nodes : $num) .", $num");
  while ($node = db_fetch_object($result)) {
    if ($time != date("F jS", $node->timestamp)) {
      $content .= "<P><B>". date("l, M jS", $node->timestamp) ."</B></P>\n";
      $time = date("F jS", $node->timestamp);
Dries's avatar
 
Dries committed
137
    }
Dries's avatar
 
Dries committed
138
    $content .= "<LI><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></LI>\n";
Dries's avatar
 
Dries committed
139
  }
Dries's avatar
 
Dries committed
140
  $theme->box(t("Older headlines"), $content);
Dries's avatar
 
Dries committed
141
}
Dries's avatar
 
Dries committed
142
*/
Dries's avatar
 
Dries committed
143

Dries's avatar
 
Dries committed
144
?>