theme.inc 6.33 KB
Newer Older
1 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
function theme_account($theme) {
Dries's avatar
 
Dries committed
16
  global $user, $site_name, $links, $menu;
Dries's avatar
 
Dries committed
17 18

  if ($user->id) {
Dries's avatar
 
Dries committed
19 20 21 22 23 24

    function submission_number() {
      $result = db_query("SELECT COUNT(id) FROM stories WHERE status = 1");
      return ($result) ? db_result($result, 0) : 0;
    }

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

    module_iterate("menu");

Dries's avatar
 
Dries committed
32
    // Display account settings:
Dries's avatar
 
Dries committed
33 34
    $content .= "<LI><A HREF=\"account.php?op=track&topic=comments\">". t("track your comments") ."</A></LI>\n";
    $content .= "<LI><A HREF=\"account.php?op=track&topic=stories\">". t("track your stories") ."</A></LI>\n";
Dries's avatar
 
Dries committed
35
    $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
36
    $content .= "<P>\n";
Dries's avatar
 
Dries committed
37 38 39
    $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
40
    $content .= "<P>\n";
Dries's avatar
 
Dries committed
41

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

Dries's avatar
 
Dries committed
47 48
    if ($menu) {
      foreach ($menu as $link) $content .= "<LI>$link</LI>\n";
Dries's avatar
 
Dries committed
49 50
      $content .= "<P>\n";
    }
Dries's avatar
 
Dries committed
51

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

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

Dries's avatar
 
Dries committed
66
    $theme->box(t("Login"), $output);
Dries's avatar
 
Dries committed
67 68 69 70
  }
}


Dries's avatar
 
Dries committed
71
function theme_blocks($region, $theme) {
Dries's avatar
 
Dries committed
72
  global $id, $PHP_SELF, $user;
Dries's avatar
 
Dries committed
73

Dries's avatar
 
Dries committed
74 75
  switch (strrchr($PHP_SELF, "/")) {
    case "/story.php":
Dries's avatar
 
Dries committed
76 77 78 79 80
      if ($region != "left") {
        if ($user->id) $story = db_fetch_object(db_query("SELECT * FROM stories WHERE id = '$id'"));
        if ($story->status == 1) theme_moderation_results($theme, $story);
        else theme_new_headlines($theme);
      }
Dries's avatar
 
Dries committed
81
      break;
Dries's avatar
 
Dries committed
82
    case "/index.php":
Dries's avatar
Dries committed
83
      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
84
      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
85 86
      while ($block = db_fetch_object($result)) {
        $blocks = module_execute($block->module, "block");
Dries's avatar
 
Dries committed
87
        $theme->box(t($blocks[$block->offset]["subject"]), $blocks[$block->offset]["content"]);
Dries's avatar
 
Dries committed
88 89
      }
      break;
Dries's avatar
 
Dries committed
90 91 92 93
  }
}

function theme_morelink($theme, $story) {
Dries's avatar
 
Dries committed
94
  return ($story->article) ? "[ <A HREF=\"story.php?id=$story->id\"><FONT COLOR=\"$theme->link\"><B>". t("read more") ."</B></FONT></A> | ". sizeof(explode(" ", $story->article)) ." ". t("words") ." | <A HREF=\"story.php?id=$story->id\"><FONT COLOR=\"$theme->link\">". format_plural($story->comments, "comment", "comments") ."</FONT></A> ]" : "[ <A HREF=\"story.php?id=$story->id\"><FONT COLOR=\"$theme->link\">". format_plural($story->comments, "comment", "comments") ."</FONT></A> ]";
Dries's avatar
 
Dries committed
95 96 97 98 99
}

function theme_moderation_results($theme, $story) {
  global $user;

Dries's avatar
 
Dries committed
100
  if ($user->id && $story->id && ($user->id == $story->author || user_get($user, "history", "s$story->id"))) {
Dries's avatar
 
Dries committed
101
    $result = db_query("SELECT * FROM users WHERE history LIKE '%s$story->id%'");
Dries's avatar
 
Dries committed
102
    while ($account = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
103
      $output .= format_username($account->userid) ." voted `". user_get($account, "history", "s$story->id") ."'.<BR>";
Dries's avatar
 
Dries committed
104
    }
Dries's avatar
 
Dries committed
105

Dries's avatar
 
Dries committed
106
    $theme->box(t("Moderation results"), ($output ? $output : t("This story has not been moderated yet.")));
Dries's avatar
 
Dries committed
107 108 109 110
  }
}

function theme_related_links($theme, $story) {
Dries's avatar
 
Dries committed
111
  // Parse story for <A HREF="">-tags:
Dries's avatar
 
Dries committed
112 113 114 115 116 117 118
  $text = stripslashes("$story->abstract $story->updates $story->article");
  while ($text = stristr($text, "<A HREF=")) {
    $link = substr($text, 0, strpos(strtolower($text), "</a>") + 4);
    $text = stristr($text, "</A>");
    if (!stristr($link, "mailto:")) $content .= "<LI>$link</LI>";
  }

Dries's avatar
 
Dries committed
119
  // Stories in the same section:
Dries's avatar
 
Dries committed
120
  $content .= " <LI>". t("More about") ." <A HREF=\"index.php?section=". urlencode($story->section) ."\">$story->section</A>.</LI>";
Dries's avatar
 
Dries committed
121

Dries's avatar
 
Dries committed
122
  $theme->box(t("Related links"), $content);
Dries's avatar
 
Dries committed
123 124 125 126 127 128 129
}

function theme_new_headlines($theme, $num = 10) {
  global $user;

  $content = "";
  $result = db_query("SELECT id, subject FROM stories WHERE status = 2 ORDER BY id DESC LIMIT $num");
Dries's avatar
 
Dries committed
130
  while ($story = db_fetch_object($result)) $content .= "<LI><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></LI>\n";
Dries's avatar
 
Dries committed
131
  $theme->box(t("Latest headlines"), $content);
Dries's avatar
 
Dries committed
132
}
133

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

Dries's avatar
 
Dries committed
137 138 139
  if ($user->stories) $result = db_query("SELECT id, subject, timestamp FROM stories WHERE status = 2 ORDER BY timestamp DESC LIMIT $user->stories, $num");
  else $result = db_query("SELECT id, subject, timestamp FROM stories WHERE status = 2 ORDER BY timestamp DESC LIMIT $num, $num");

Dries's avatar
 
Dries committed
140
  while ($story = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
141 142 143 144
    if ($time != date("F jS", $story->timestamp)) {
      $content .= "<P><B>". date("l, M jS", $story->timestamp) ."</B></P>\n";
      $time = date("F jS", $story->timestamp);
    }
Dries's avatar
 
Dries committed
145
    $content .= "<LI><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></LI>\n";
Dries's avatar
 
Dries committed
146
  }
Dries's avatar
 
Dries committed
147
  $theme->box(t("Older headlines"), $content);
Dries's avatar
 
Dries committed
148 149
}

Dries's avatar
 
Dries committed
150
?>