theme.inc 5.4 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 10 11 12 13 14
  }
  else {
    include_once $themes[key($themes)][0];
  }
  return new Theme();
}

Dries's avatar
 
Dries committed
15 16 17 18 19
function theme_menu($name, $module) {
  global $menu;
  if ($module["menu"]) $menu = ($menu) ? array_merge($menu, $module["menu"]()) : $module["menu"]();
}

Dries's avatar
 
Dries committed
20
function theme_account($theme) {
Dries's avatar
 
Dries committed
21
  global $user, $site_name, $links, $menu;
Dries's avatar
 
Dries committed
22 23

  if ($user->id) {
Dries's avatar
 
Dries committed
24 25


Dries's avatar
 
Dries committed
26
    module_iterate("theme_menu");
Dries's avatar
 
Dries committed
27

Dries's avatar
 
Dries committed
28
    // Display account settings:
Dries's avatar
 
Dries committed
29
    $content .= "<LI><A HREF=\"account.php?op=track&topic=comments\">". t("track your comments") ."</A></LI>\n";
Dries's avatar
 
Dries committed
30
    $content .= "<LI><A HREF=\"account.php?op=track&topic=nodes\">". t("track your nodes") ."</A></LI>\n";
Dries's avatar
 
Dries committed
31
    $content .= "<LI><A HREF=\"account.php?op=track&topic=site\">". strtr(t("track %a"), array("%a" => $site_name)) ."</A></LI>\n";
Dries's avatar
 
Dries committed
32
    $content .= "<P>\n";
Dries's avatar
 
Dries committed
33 34 35
    $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
36
    $content .= "<P>\n";
Dries's avatar
 
Dries committed
37

Dries's avatar
 
Dries committed
38
    if (user_access($user)) {
Dries's avatar
 
Dries committed
39
      $content .= "<LI><A HREF=\"admin.php\">administer ". $site_name ."</A></LI>\n";
Dries's avatar
 
Dries committed
40 41 42
      $content .= "<P>\n";
    }

Dries's avatar
 
Dries committed
43 44
    if ($menu) {
      foreach ($menu as $link) $content .= "<LI>$link</LI>\n";
Dries's avatar
 
Dries committed
45 46
      $content .= "<P>\n";
    }
Dries's avatar
 
Dries committed
47

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

Dries's avatar
 
Dries committed
50
    $theme->box(strtr(t("%a's configuration"), array("%a" => $user->userid)), "$content");
Dries's avatar
 
Dries committed
51 52 53
  }
  else {
    $output .= "<CENTER>\n";
Dries's avatar
 
Dries committed
54 55 56 57 58
    $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
59 60 61
    $output .= " </FORM>\n";
    $output .= "</CENTER>\n";

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


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

Dries's avatar
 
Dries committed
70
  switch (strrchr($PHP_SELF, "/")) {
Dries's avatar
 
Dries committed
71
    case "/node.php":
Dries's avatar
 
Dries committed
72
      if ($region != "left") {
Dries's avatar
 
Dries committed
73 74 75
        if ($user->id) $node = db_fetch_object(db_query("SELECT * FROM nodes WHERE nid = '$id'"));
        if ($node->status == 1) theme_moderation_results($theme, $node);
        // else theme_new_headlines($theme);
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 82
      while ($block = db_fetch_object($result)) {
        $blocks = module_execute($block->module, "block");
Dries's avatar
 
Dries committed
83
        $theme->box(t($blocks[$block->offset]["subject"]), $blocks[$block->offset]["content"]);
Dries's avatar
 
Dries committed
84 85
      }
      break;
Dries's avatar
 
Dries committed
86 87 88
  }
}

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

Dries's avatar
 
Dries committed
93
function theme_moderation_results($theme, $node) {
Dries's avatar
 
Dries committed
94 95
  global $user;

Dries's avatar
 
Dries committed
96 97
  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
98
    while ($account = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
99
      $output .= format_username($account->userid) ." voted '". user_get($account, "history", "n$node->nid") ."'.<BR>";
Dries's avatar
 
Dries committed
100
    }
Dries's avatar
 
Dries committed
101

Dries's avatar
 
Dries committed
102
    $theme->box(t("Moderation results"), ($output ? $output : t("This story has not been moderated yet.")));
Dries's avatar
 
Dries committed
103 104 105 106
  }
}

function theme_new_headlines($theme, $num = 10) {
Dries's avatar
 
Dries committed
107 108
  $result = db_query("SELECT nid, title FROM nodes WHERE status = 2 AND type = 'story' ORDER BY nid DESC LIMIT $num");
  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
109
  $theme->box(t("Latest headlines"), $content);
Dries's avatar
 
Dries committed
110
}
111

Dries's avatar
 
Dries committed
112 113
function theme_old_headlines($theme, $num = 10) {
  global $user;
Dries's avatar
 
Dries committed
114

Dries's avatar
 
Dries committed
115 116 117 118 119
  $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
120
    }
Dries's avatar
 
Dries committed
121
    $content .= "<LI><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></LI>\n";
Dries's avatar
 
Dries committed
122
  }
Dries's avatar
 
Dries committed
123
  $theme->box(t("Older headlines"), $content);
Dries's avatar
 
Dries committed
124 125
}

Dries's avatar
 
Dries committed
126
?>