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

Kjartan's avatar
Changes  
Kjartan committed
3 4 5 6 7 8 9 10 11 12 13 14
class BaseTheme {
    function links($links = array(), $status = 0, $node = 0) {
      if ($status == 1)
        $links = array_merge(theme_morelink($node), $links);
      foreach ($links as $link) {
        $_links[] = count($link) == 2 ? "<A HREF=\"$link[0]\"><FONT COLOR=\"$theme->link\">". t($link[1]) ."</FONT></A>" : t($link[0]);
      }
      if ($status == 2) return ($_links ? implode(" | ", $_links) : "");
      else return ($_links ? "[ ". implode(" | ", $_links) ." ]" : "");
    }
}

Dries's avatar
 
Dries committed
15
function theme_init() {
Dries's avatar
 
Dries committed
16 17 18
  global $user, $themes;

  if ($user->theme && file_exists($themes[$user->theme][0])) {
Dries's avatar
 
Dries committed
19
    include_once $themes[$user->theme][0];
Dries's avatar
 
Dries committed
20 21
  }
  else {
Dries's avatar
 
Dries committed
22
    include_once $themes[variable_get("theme_default", key($themes))][0];
Dries's avatar
 
Dries committed
23 24 25 26
  }
  return new Theme();
}

Kjartan's avatar
Changes  
Kjartan committed
27 28 29 30 31 32
function theme_link() {
  global $theme;
  $links[] = array("index.php",  t("home"));
  $links[] = array("search.php",  t("search"));
  $links[] = array("submit.php",  t("submit"));
  $links[] = array("account.php",  t("account"));
Dries's avatar
 
Dries committed
33 34

  foreach (module_list() as $name) {
Kjartan's avatar
Changes  
Kjartan committed
35
    if (module_hook($name, "page")) $links[] = array("module.php?mod=$name", t($name));
Dries's avatar
 
Dries committed
36 37 38 39 40
  }

//  if (module_exist("forum")) $links[] = "<A HREF=\"module.php?mod=forum\">".t("forum") ."</A>";
//  if (module_exist("diary")) $links[] = "<A HREF=\"module.php?mod=diary\">". t("diary") ."</A>";
//  if (module_exist("book")) $links[] = "<A HREF=\"module.php?mod=book\">". t("handbook") ."</A>";
Dries's avatar
 
Dries committed
41

Kjartan's avatar
Changes  
Kjartan committed
42
  return $theme->links($links, 2);
Dries's avatar
 
Dries committed
43 44
}

Dries's avatar
 
Dries committed
45

Dries's avatar
 
Dries committed
46
function theme_account($theme) {
Dries's avatar
 
Dries committed
47
  global $user;
Dries's avatar
 
Dries committed
48 49

  if ($user->id) {
Dries's avatar
 
Dries committed
50
    // Display account settings:
Dries's avatar
 
Dries committed
51
    $content .= "<LI><A HREF=\"account.php?op=track&topic=comments\">". t("track your comments") ."</A></LI>\n";
Dries's avatar
 
Dries committed
52
    $content .= "<LI><A HREF=\"account.php?op=track&topic=nodes\">". t("track your nodes") ."</A></LI>\n";
Dries's avatar
 
Dries committed
53
    $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
54
    $content .= "<P>\n";
Dries's avatar
 
Dries committed
55 56 57
    $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
58
    $content .= "<P>\n";
Dries's avatar
 
Dries committed
59

Dries's avatar
 
Dries committed
60
    if (user_access($user)) {
Dries's avatar
 
Dries committed
61
      $content .= "<LI><A HREF=\"admin.php\">administer ". variable_get("site_name", "drupal") ."</A></LI>\n";
Dries's avatar
 
Dries committed
62 63 64
      $content .= "<P>\n";
    }

Dries's avatar
 
Dries committed
65 66 67 68
    foreach (module_list() as $name) {
      if ($links = module_invoke($name, "menu")) {
        foreach ($links as $link) $content .= "<LI>$link</LI>\n";
      }
Dries's avatar
 
Dries committed
69
    }
Dries's avatar
 
Dries committed
70
    if ($link) $content .= "<P>\n";
Dries's avatar
 
Dries committed
71

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

Dries's avatar
 
Dries committed
74
    $theme->box(strtr(t("%a's configuration"), array("%a" => $user->userid)), "$content");
Dries's avatar
 
Dries committed
75 76
  }
  else {
Dries's avatar
 
Dries committed
77
    $output .= "<DIV ALIGN=\"center\">\n";
Dries's avatar
 
Dries committed
78 79 80 81 82
    $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
83
    $output .= " </FORM>\n";
Dries's avatar
 
Dries committed
84
    $output .= "</DIV>\n";
Dries's avatar
 
Dries committed
85

Dries's avatar
 
Dries committed
86
    $theme->box(t("Login"), $output);
Dries's avatar
 
Dries committed
87 88 89 90
  }
}


Dries's avatar
 
Dries committed
91
function theme_blocks($region, $theme) {
Dries's avatar
 
Dries committed
92
  global $id, $PHP_SELF, $status, $user;
Dries's avatar
 
Dries committed
93

Dries's avatar
 
Dries committed
94
  switch (strrchr($PHP_SELF, "/")) {
Dries's avatar
 
Dries committed
95
    case "/node.php":
Dries's avatar
 
Dries committed
96
      if ($region != "left") {
Dries's avatar
 
Dries committed
97
        if ($user->id) $node = db_fetch_object(db_query("SELECT * FROM node WHERE nid = '$id'"));
Dries's avatar
 
Dries committed
98
        if ($node->status == $status[queued]) theme_moderation_results($theme, $node);
Dries's avatar
 
Dries committed
99
        // else theme_new_headlines($theme);
Dries's avatar
 
Dries committed
100
      }
Dries's avatar
 
Dries committed
101
      break;
Dries's avatar
 
Dries committed
102
    case "/index.php":
Dries's avatar
Dries committed
103
      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
104
      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
105
      while ($block = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
106
        $blocks = module_invoke($block->module, "block");
Dries's avatar
 
Dries committed
107
        $theme->box(t($blocks[$block->offset]["subject"]), $blocks[$block->offset]["content"]);
Dries's avatar
 
Dries committed
108 109
      }
      break;
Dries's avatar
 
Dries committed
110 111 112
  }
}

Kjartan's avatar
Changes  
Kjartan committed
113
function theme_morelink(&$node) {
Dries's avatar
 
Dries committed
114
  if ($node->body) {
Kjartan's avatar
Changes  
Kjartan committed
115
    $links[] = array("node.php?id=$node->nid", t("read more"));
Dries's avatar
 
Dries committed
116 117
  }
  if ($node->comment) {
Kjartan's avatar
Changes  
Kjartan committed
118
    $links[] = array("node.php?id=$node->nid", format_plural(node_get_comments($node->nid), "comment", "comments"));
Dries's avatar
 
Dries committed
119 120
  }

Kjartan's avatar
Changes  
Kjartan committed
121
  return $links;
Dries's avatar
 
Dries committed
122 123
}

Dries's avatar
 
Dries committed
124
function theme_moderation_results($theme, $node) {
Dries's avatar
 
Dries committed
125 126 127 128
  foreach (explode(";", $node->users) as $vote) {
    if ($vote) {
      $data = explode(":", $vote);
      $output .= format_username($data[0]) ." voted '$data[1]'.<BR>";
Dries's avatar
 
Dries committed
129 130
    }
  }
Dries's avatar
 
Dries committed
131 132

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

Dries's avatar
 
Dries committed
135 136 137 138
/*
//
// depricated -> new block strategy
//
Dries's avatar
 
Dries committed
139
function theme_new_headlines($theme, $num = 10) {
Dries's avatar
 
Dries committed
140
  $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
141
  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
142
  $theme->box(t("Latest headlines"), $content);
Dries's avatar
 
Dries committed
143
}
144

Dries's avatar
 
Dries committed
145 146
function theme_old_headlines($theme, $num = 10) {
  global $user;
Dries's avatar
 
Dries committed
147

Dries's avatar
 
Dries committed
148 149 150 151 152
  $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
153
    }
Dries's avatar
 
Dries committed
154
    $content .= "<LI><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></LI>\n";
Dries's avatar
 
Dries committed
155
  }
Dries's avatar
 
Dries committed
156
  $theme->box(t("Older headlines"), $content);
Dries's avatar
 
Dries committed
157
}
Dries's avatar
 
Dries committed
158
*/
Dries's avatar
 
Dries committed
159

Dries's avatar
 
Dries committed
160
?>