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

Kjartan's avatar
Changes  
Kjartan committed
3
class BaseTheme {
Kjartan's avatar
Changes  
Kjartan committed
4 5 6 7 8
  function links(&$links, $state = 0) {
    // $state = 0 : default behaviour
    // $state = 1 : main page
    // $state = 2 : theme_link()
    // Subject to change coz its messy
Dries's avatar
 
Dries committed
9
    foreach ($links as $link) {
Kjartan's avatar
Changes  
Kjartan committed
10
      if ($link[0]) $_links[] = count($link) == 2 ? "<A HREF=\"$link[0]\"><FONT COLOR=\"$theme->link\">". t($link[1]) ."</FONT></A>" : t($link[0]);
Kjartan's avatar
Changes  
Kjartan committed
11
    }
Dries's avatar
 
Dries committed
12

Kjartan's avatar
Changes  
Kjartan committed
13
    return ($_links ? implode(" | ", $_links) : "");
Dries's avatar
 
Dries committed
14
  }
Kjartan's avatar
Changes  
Kjartan committed
15 16
}

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

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

Kjartan's avatar
Changes  
Kjartan committed
29
function theme_link() {
Dries's avatar
 
Dries committed
30
  global $user, $theme;
Kjartan's avatar
Changes  
Kjartan committed
31 32 33 34
  $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
35 36

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

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

Dries's avatar
 
Dries committed
43

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

  if ($user->id) {
Dries's avatar
 
Dries committed
48
    // Display account settings:
Dries's avatar
 
Dries committed
49 50 51
    $content .= "<A HREF=\"account.php?op=track&topic=comments\">". t("track your comments") ."</A><BR>\n";
    $content .= "<A HREF=\"account.php?op=track&topic=nodes\">". t("track your nodes") ."</A><BR>\n";
    $content .= "<A HREF=\"account.php?op=track&topic=site\">". strtr(t("track %a"), array("%a" => variable_get("site_name", "drupal"))) ."</A><BR>\n";
Dries's avatar
 
Dries committed
52
    $content .= "<P>\n";
Dries's avatar
 
Dries committed
53 54 55
    $content .= "<A HREF=\"account.php?op=edit&topic=user\">". t("edit your information") ."</A><BR>\n";
    $content .= "<A HREF=\"account.php?op=edit&topic=site\">". t("edit your preferences") ."</A><BR>\n";
    $content .= "<A HREF=\"account.php?op=edit&topic=content\">". t("edit your content") ."</A><BR>\n";
Dries's avatar
 
Dries committed
56
    $content .= "<P>\n";
Dries's avatar
 
Dries committed
57

Dries's avatar
 
Dries committed
58
    if (user_access($user, "access administration pages")) {
Dries's avatar
 
Dries committed
59
      $content .= "<A HREF=\"admin.php\">". strtr(t("administer %a"), array("%a" => variable_get("site_name", "drupal"))) ."</A><BR>\n";
Dries's avatar
 
Dries committed
60
      $content .= "<P>\n";
Dries's avatar
 
Dries committed
61 62
    }

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

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

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

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


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

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

Dries's avatar
 
Dries committed
111
function theme_moderation_results($theme, $node) {
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
      $output .= format_username($data[0]) ." voted '$data[1]'.<BR>";
Dries's avatar
 
Dries committed
116 117
    }
  }
Dries's avatar
 
Dries committed
118 119

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

Dries's avatar
 
Dries committed
122 123 124 125
/*
//
// depricated -> new block strategy
//
Dries's avatar
 
Dries committed
126
function theme_new_headlines($theme, $num = 10) {
Dries's avatar
 
Dries committed
127
  $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
128
  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
129
  $theme->box(t("Latest headlines"), $content);
Dries's avatar
 
Dries committed
130
}
131

Dries's avatar
 
Dries committed
132 133
function theme_old_headlines($theme, $num = 10) {
  global $user;
Dries's avatar
 
Dries committed
134

Dries's avatar
 
Dries committed
135 136 137 138 139
  $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
140
    }
Dries's avatar
 
Dries committed
141
    $content .= "<LI><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></LI>\n";
Dries's avatar
 
Dries committed
142
  }
Dries's avatar
 
Dries committed
143
  $theme->box(t("Older headlines"), $content);
Dries's avatar
 
Dries committed
144
}
Dries's avatar
 
Dries committed
145
*/
Dries's avatar
 
Dries committed
146

Dries's avatar
 
Dries committed
147
?>