theme.inc 6.39 KB
Newer Older
1 2
<?

Dries's avatar
 
Dries committed
3
function theme_account($theme) {
Dries's avatar
 
Dries committed
4
  global $user, $site_name, $links, $menu;
Dries's avatar
 
Dries committed
5 6 7 8 9 10 11 12
  
  if ($user->id) { 

    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
13 14
    function menu($name, $module) {
      global $menu;
Dries's avatar
 
Dries committed
15
      if ($module["menu"]) $menu = ($menu) ? array_merge($menu, $module["menu"]()) : $module["menu"]();
Dries's avatar
 
Dries committed
16 17 18 19
    }

    module_iterate("menu");

Dries's avatar
 
Dries committed
20
    // Display account settings:
Dries's avatar
 
Dries committed
21 22 23 24 25 26
    $content .= "<LI><A HREF=\"account.php?op=track&topic=comments\">track your comments</A></LI>\n";
    $content .= "<LI><A HREF=\"account.php?op=track&topic=stories\">track your stories</A></LI>\n";
    $content .= "<LI><A HREF=\"account.php?op=track&topic=site\">track $site_name</A></LI>\n";
    $content .= "<P>\n";
    $content .= "<LI><A HREF=\"submission.php\">submission queue</A> (<FONT COLOR=\"red\">". submission_number() ."</FONT>)</LI>\n";
    $content .= "<P>\n";
Dries's avatar
 
Dries committed
27 28 29
    $content .= "<LI><A HREF=\"account.php?op=edit&topic=user\">edit your information</A></LI>\n";
    $content .= "<LI><A HREF=\"account.php?op=edit&topic=site\">edit your preferences</A></LI>\n";
    $content .= "<LI><A HREF=\"account.php?op=edit&topic=content\">edit site content</A></LI>\n";
Dries's avatar
 
Dries committed
30
    $content .= "<P>\n";
Dries's avatar
 
Dries committed
31 32

    if (($user->id) && ($user->permissions == 1 || $user->id == 1)) {
Dries's avatar
 
Dries committed
33
      $content .= "<LI><A HREF=\"admin.php\">administer ". $site_name ."</A></LI>\n";
Dries's avatar
 
Dries committed
34 35 36 37
      $content .= "<P>\n";
    }

    if ($menu && ksort($menu)) {
Dries's avatar
 
Dries committed
38 39 40
      foreach ($menu as $link=>$url) $content .= "<LI><A HREF=\"$url\">$link</A></LI>\n";
      $content .= "<P>\n";
    }
Dries's avatar
 
Dries committed
41

Dries's avatar
 
Dries committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    $content .= "<LI><A HREF=\"account.php?op=logout\">logout</A></LI>\n";

    $theme->box("$user->userid's configuration", "$content");
  }
  else {
    $output .= "<CENTER>\n";
    $output .= " <FORM ACTION=\"account.php?op=Login\" METHOD=\"post\">\n";
    $output .= "  <P><B>Username:</B><BR><INPUT NAME=\"userid\" SIZE=\"15\"></P>\n";
    $output .= "  <P><B>Password:</B><BR><INPUT NAME=\"passwd\" SIZE=\"15\" TYPE=\"password\"></P>\n";
    $output .= "  <P><INPUT NAME=\"op\" TYPE=\"submit\" VALUE=\"Login\"></P>\n";
    $output .= "  <P><A HREF=\"account.php\">REGISTER</A></P>\n";
    $output .= " </FORM>\n";
    $output .= "</CENTER>\n";

    $theme->box("Login", $output);
  }
}


Dries's avatar
 
Dries committed
61
function theme_blocks($region, $theme) {
Dries's avatar
 
Dries committed
62
  global $id, $PHP_SELF, $user;
Dries's avatar
 
Dries committed
63 64
 
  switch (strtok($PHP_SELF, ".")) {
Dries's avatar
 
Dries committed
65
    case "/story":
Dries's avatar
 
Dries committed
66 67 68 69
      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);
      break;
Dries's avatar
 
Dries committed
70
    case "/index":
Dries's avatar
 
Dries committed
71 72
      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 AND l.user = '$user->id'))". (($region == "left" || $region == "right") ? ($region == "left" ? " AND b.region = 0" : " AND b.region = 1") : "") ." ORDER BY weight");
      else $result = db_query("SELECT * FROM blocks WHERE status = 2 ORDER BY weight");
Dries's avatar
 
Dries committed
73 74 75 76 77
      while ($block = db_fetch_object($result)) {
        $blocks = module_execute($block->module, "block");
        $theme->box($blocks[$block->offset]["subject"], $blocks[$block->offset]["content"]);     
      }
      break;
Dries's avatar
 
Dries committed
78 79 80 81
  }
}

function theme_morelink($theme, $story) {
Dries's avatar
 
Dries committed
82
  return ($story->article) ? "[ <A HREF=\"story.php?id=$story->id\"><FONT COLOR=\"$theme->hlcolor2\"><B>read more</B></FONT></A> | ". strlen($story->article) ." bytes | <A HREF=\"story.php?id=$story->id\"><FONT COLOR=\"$theme->hlcolor2\">". format_plural($story->comments, "comment", "comments") ."</FONT></A> ]" : "[ <A HREF=\"story.php?id=$story->id\"><FONT COLOR=\"$theme->hlcolor2\">". format_plural($story->comments, "comment", "comments") ."</FONT></A> ]";
Dries's avatar
 
Dries committed
83 84 85 86 87
}

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

Dries's avatar
 
Dries committed
88 89
  if ($user->id && $story->id && ($user->id == $story->author || user_getHistory($user->history, "s$story->id"))) {
    $result = db_query("SELECT * FROM users WHERE history LIKE '%s$story->id%'");
Dries's avatar
 
Dries committed
90
    while ($account = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
91
      $output .= format_username($account->userid) ." voted `". user_getHistory($account->history, "s$story->id") ."'.<BR>";
Dries's avatar
 
Dries committed
92 93
    }
    
Dries's avatar
 
Dries committed
94
    $theme->box("Moderation results", ($output ? $output : "This story has not been moderated yet."));
Dries's avatar
 
Dries committed
95 96 97 98
  }
}

function theme_related_links($theme, $story) {
Dries's avatar
 
Dries committed
99
  // Parse story for <A HREF="">-tags:
Dries's avatar
 
Dries committed
100 101 102 103 104 105 106
  $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
107
  // Stories in the same category: 
Dries's avatar
 
Dries committed
108 109
  $content .= " <LI>More about <A HREF=\"search.php?category=". urlencode($story->category) ."\">$story->category</A>.</LI>";

Dries's avatar
 
Dries committed
110
  // Stories from the same author:
Dries's avatar
 
Dries committed
111 112 113 114 115 116 117 118 119 120
  if ($story->userid) $content .= " <LI>Also by <A HREF=\"search.php?author=". urlencode($story->userid) ."\">$story->userid</A>.</LI>";

  $theme->box("Related links", $content);
}

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
121
  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
122 123 124
  $content .= "<P ALIGN=\"right\">[ <A HREF=\"search.php\"><FONT COLOR=\"$theme->hlcolor2\">more</FONT></A> ]</P>";
  $theme->box("Latest headlines", $content);
}
125

Dries's avatar
 
Dries committed
126 127 128 129 130 131 132 133 134 135 136
function theme_old_headlines($theme, $num = 10) {
  global $user;
  
  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");

  while ($story = db_fetch_object($result)) {    
    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
137
    $content .= "<LI><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></LI>\n";
Dries's avatar
 
Dries committed
138 139 140 141 142 143
  }
  $content .= "<P ALIGN=\"right\">[ <A HREF=\"search.php\"><FONT COLOR=\"$theme->hlcolor2\">more</FONT></A> ]</P>";

  $theme->box("Older headlines", $content);
}

Dries's avatar
 
Dries committed
144
?>