Commit 728249cb authored by Dries's avatar Dries
Browse files

- fixed small translation glitch in format_interval
- added a couple of missing t() functions
- improved the comments module, fixed the score problem Jeroen
  reported earlier -> it's slicker but I hope it won't break anything
parent a925539e
......@@ -48,12 +48,12 @@ function account_session_start($userid, $passwd) {
global $user;
if ($userid && $passwd) $user = new User($userid, $passwd);
if ($user->id) session_register("user");
watchdog("message", ($user->id ? "session opened for user `$user->userid'" : "failed login for user `$userid'"));
watchdog("message", ($user->id ? "session opened for user '$user->userid'" : "failed login for user `$userid'"));
}
function account_session_close() {
global $user;
watchdog("message", "session closed for user `$user->userid'");
watchdog("message", "session closed for user '$user->userid'");
session_unset();
session_destroy();
unset($user);
......@@ -67,7 +67,7 @@ function account_user_edit() {
$output .= "<FORM ACTION=\"account.php\" METHOD=\"post\">\n";
$output .= "<B>". t("Username") .":</B><BR>\n";
$output .= "&nbsp; $user->userid<P>\n";
$output .= "$user->userid<P>\n";
$output .= "<I>". t("Required, unique, and can not be changed.") ."</I><P>\n";
$output .= "<B>". t("Real name") .":</B><BR>\n";
......@@ -75,7 +75,7 @@ function account_user_edit() {
$output .= "<I>". t("Optional") .".</I><P>\n";
$output .= "<B>". t("Real e-mail address") .":</B><BR>\n";
$output .= "&nbsp; $user->real_email<P>\n";
$output .= "$user->real_email<P>\n";
$output .= "<I>". t("Required, unique, can not be changed.") ." ". t("Your real e-mail address is never displayed publicly: only needed in case you lose your password.") ."</I><P>\n";
$output .= "<B>". t("Fake e-mail address") .":</B><BR>\n";
......@@ -128,7 +128,7 @@ function account_site_edit() {
if ($user->id) {
$output .= "<FORM ACTION=\"account.php\" METHOD=\"post\">\n";
$output .= "<B>". t("Theme" ) .":</B><BR>\n";
$output .= "<B>". t("Theme") .":</B><BR>\n";
foreach ($themes as $key=>$value) $options1 .= " <OPTION VALUE=\"$key\"". (($user->theme == $key) ? " SELECTED" : "") .">$key - $value[1]</OPTION>\n";
$output .= "<SELECT NAME=\"edit[theme]\">\n$options1</SELECT><BR>\n";
$output .= "<I>". t("Selecting a different theme will change the look and feel of the site.") ."</I><P>\n";
......@@ -319,7 +319,7 @@ function account_email_submit($userid, $email) {
mail($email, $subject, $message, "From: noreply");
$output = "Your password and further instructions have been sent to your e-mail address.";
$output = t("Your password and further instructions have been sent to your e-mail address.");
}
else {
watchdog("warning", "new password: '$userid' and &lt;$email&gt; do not match");
......@@ -371,21 +371,21 @@ function account_create_confirm($name, $hash) {
if ($account->status == 1) {
if ($account->hash == $hash) {
db_query("UPDATE users SET status = 2, hash = '' WHERE userid = '$name'");
$output .= "Your account has been successfully confirmed. You can click <A HREF=\"account.php?op=login\">here</A> to login.\n";
$output = t("Your account has been successfully confirmed.");
watchdog("message", "$name: account confirmation successful");
}
else {
$output .= "Confirmation failed: invalid confirmation hash.\n";
$output = t("Confirmation failed: invalid confirmation hash.");
watchdog("warning", "$name: invalid confirmation hash");
}
}
else {
$output .= "Confirmation failed: your account has already been confirmed. You can click <A HREF=\"account.php?op=login\">here</A> to login.\n";
$output = t("Confirmation failed: your account has already been confirmed.");
watchdog("warning", "$name: attempt to re-confirm account");
}
}
else {
$output .= "Confirmation failed: no such account found.<BR>";
$output = t("Confirmation failed: non-existing account.");
watchdog("warning", "$name: attempt to confirm non-existing account");
}
......
......@@ -53,7 +53,7 @@ function comment_reply($pid, $id) {
if ($pid) {
$item = db_fetch_object(db_query("SELECT comments.*, users.userid FROM comments LEFT JOIN users ON comments.author = users.id WHERE comments.cid = $pid"));
$theme->comment(new Comment($item->userid, $item->subject, $item->comment, $item->timestamp, $item->url, $item->fake_email, comment_score($comment), $comment->votes, $item->cid, $item->lid), "reply to this comment");
comment_view(new Comment($item->userid, $item->subject, $item->comment, $item->timestamp, $item->url, $item->fake_email, comment_score($comment), $comment->votes, $item->cid, $item->lid), t("reply to this comment"));
}
else {
$pid = 0;
......@@ -87,14 +87,14 @@ function comment_reply($pid, $id) {
$output .= "</FORM>\n";
$theme->box("Reply", $output);
$theme->box(t("Reply"), $output);
}
function comment_preview($pid, $id, $subject, $comment) {
global $allowed_html, $link, $REQUEST_URI, $theme, $user;
// Preview comment:
$theme->comment(new Comment($user->userid, $subject, $comment, time(), $user->url, $user->fake_email, 0, 0, 0, 0), "reply to this comment");
comment_view(new Comment($user->userid, $subject, $comment, time(), $user->url, $user->fake_email, 0, 0, 0, 0), t("reply to this comment"));
// Build reply form:
$output .= "<FORM ACTION=\"$REQUEST_URI\" METHOD=\"post\">\n";
......@@ -173,14 +173,16 @@ function comment_moderation($comment) {
global $comment_votes, $op, $user;
if ($op == "reply") {
// preview comment:
$output .= "&nbsp;";
}
else if ($user->id && $user->userid != $comment->userid && !user_get($user, "history", "c$comment->cid")) {
$output .= "<SELECT NAME=\"moderate[$comment->cid]\">\n";
foreach ($comment_votes as $key=>$value) $output .= " <OPTION VALUE=\"$value\">$key</OPTION>\n";
$output .= "</SELECT>\n";
// comment hasn't been moderated yet:
foreach ($comment_votes as $key=>$value) $options .= " <OPTION VALUE=\"$value\">$key</OPTION>\n";
$output .= "<SELECT NAME=\"moderate[$comment->cid]\">$options</SELECT>\n";
}
else {
// comment has already been moderated:
$output .= "<TABLE BORDER=\"0\" CELLSPACING=\"1\" CELLPADDING=\"1\"><TR><TD>". t("score") .":</TD><TD>". check_output($comment->score) ."</TD></TR><TR><TD>". t("votes") .":</TD><TD>". check_output($comment->votes) ."</TR></TABLE>\n";
}
......@@ -202,32 +204,20 @@ function comment_controls($threshold = 1, $mode = 3, $order = 1) {
}
function comment_threshold($threshold) {
$output .= "<SELECT NAME=\"threshold\">\n";
for ($i = -1; $i < 6; $i++) {
$output .= " <OPTION VALUE=\"$i\"". ($threshold == $i ? " SELECTED" : "") .">". t("Filter") ." - $i</OPTION>";
}
$output .= "</SELECT>\n";
return $output;
for ($i = -1; $i < 6; $i++) $options .= " <OPTION VALUE=\"$i\"". ($threshold == $i ? " SELECTED" : "") .">". t("Filter") ." - $i</OPTION>";
return "<SELECT NAME=\"threshold\">$options</SELECT>\n";
}
function comment_mode($mode) {
global $cmodes;
$output .= "<SELECT NAME=\"mode\">\n";
foreach ($cmodes as $key=>$value) {
$output .= " <OPTION VALUE=\"$key\"". ($mode == $key ? " SELECTED" : "") .">$value</OPTION>\n";
}
$output .= "</SELECT>\n";
return $output;
foreach ($cmodes as $key=>$value) $options .= " <OPTION VALUE=\"$key\"". ($mode == $key ? " SELECTED" : "") .">$value</OPTION>\n";
return "<SELECT NAME=\"mode\">$options</SELECT>\n";
}
function comment_order($order) {
global $corder;
$output .= "<SELECT NAME=\"order\">\n";
foreach ($corder as $key=>$value) {
$output .= " <OPTION VALUE=\"$key\"". ($order == $key ? " SELECTED" : "") .">$value</OPTION>\n";
}
$output .= "</SELECT>\n";
return $output;
foreach ($corder as $key=>$value) $options .= " <OPTION VALUE=\"$key\"". ($order == $key ? " SELECTED" : "") .">$value</OPTION>\n";
return "<SELECT NAME=\"order\">$options</SELECT>\n";
}
function comment_query($link, $lid, $order, $pid = -1) {
......@@ -254,44 +244,42 @@ function comment_uri($args = 0) {
function comment_link($comment, $return = 1) {
global $link, $theme;
if ($return) return "<A HREF=\"". comment_uri("id=$comment->lid#$comment->cid") ."\"><FONT COLOR=\"$theme->link\">return</FONT></A> | <A HREF=\"". comment_uri("op=reply&id=$comment->lid&pid=$comment->cid") ."\"><FONT COLOR=\"$theme->link\">reply to this comment</FONT></A>";
else return "<A HREF=\"". comment_uri("op=reply&id=$comment->lid&pid=$comment->cid") ."\"><FONT COLOR=\"$theme->link\">reply to this comment</FONT></A>";
if ($return) return "<A HREF=\"". comment_uri("id=$comment->lid#$comment->cid") ."\"><FONT COLOR=\"$theme->link\">". t("return") ."</FONT></A> | <A HREF=\"". comment_uri("op=reply&id=$comment->lid&pid=$comment->cid") ."\"><FONT COLOR=\"$theme->link\">". t("reply to this comment") ."</FONT></A>";
else return "<A HREF=\"". comment_uri("op=reply&id=$comment->lid&pid=$comment->cid") ."\"><FONT COLOR=\"$theme->link\">". t("reply to this comment") ."</FONT></A>";
}
function comment_comment($comment, $folded = 0) {
function comment_view($comment, $folded = 0) {
global $link, $theme;
// calculate comment's score:
$comment->score = comment_score($comment);
// display comment:
if ($folded) $theme->comment($comment, $folded);
else print "<A HREF=\"". comment_uri("id=$comment->lid&cid=$comment->cid#$comment->cid") ."\">". check_output($comment->subject) ."</A> by ". format_username($comment->userid) ." <SMALL>(". $score = comment_score($comment) .")</SMALL></LI>";
else print "<A HREF=\"". comment_uri("id=$comment->lid&cid=$comment->cid#$comment->cid") ."\">". check_output($comment->subject) ."</A> by ". format_username($comment->userid) ." <SMALL>($comment->score)</SMALL><P>";
}
function comment_thread_min($cid, $threshold) {
global $user, $theme;
global $user;
$result = db_query("SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.pid = $cid ORDER BY c.timestamp, c.cid");
print "<UL>";
while ($comment = db_fetch_object($result)) {
comment_comment($comment);
comment_view($comment);
comment_thread_min($comment->cid, $threshold);
}
print "</UL>";
}
function comment_thread_max($cid, $mode, $threshold, $level = 0, $dummy = 0) {
global $link, $theme, $user;
global $link, $user;
$result = db_query("SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE link = '$link' AND c.pid = $cid ORDER BY c.timestamp, c.cid");
print "<UL>";
while ($comment = db_fetch_object($result)) {
if (comment_visible($comment, $threshold)) {
$comment = new Comment($comment->userid, $comment->subject, $comment->comment, $comment->timestamp, $comment->url, $comment->fake_email, comment_score($comment), $comment->votes, $comment->cid, $comment->lid);
$theme->comment($comment, comment_link($comment, 0));
}
else {
comment_comment($comment);
print "<P>";
}
comment_view($comment, (comment_visible($comment, $threshold) ? comment_link($comment, 0) : 0));
comment_thread_max($comment->cid, $mode, $threshold, $level + 1, $dummy + 1);
}
print "</UL>";
......@@ -318,7 +306,7 @@ function comment_render($lid, $cid) {
if ($cid > 0) {
$result = db_query("SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE cid = $cid");
if ($comment = db_fetch_object($result)) {
$theme->comment($comment, comment_link($comment));
comment_view($comment, comment_link($comment));
}
}
else {
......@@ -336,22 +324,20 @@ function comment_render($lid, $cid) {
else if ($mode == 2) {
$result = comment_query($link, $lid, $order);
while ($comment = db_fetch_object($result)) {
if (comment_visible($comment, $threshold)) {
$theme->comment($comment, comment_link($comment, 0));
}
comment_view($comment, (comment_visible($comment, $threshold) ? comment_link($comment, 0) : 0));
}
}
else if ($mode == 3) {
$result = comment_query($link, $lid, $order, 0);
while ($comment = db_fetch_object($result)) {
comment_comment($comment);
comment_view($comment);
comment_thread_min($comment->cid, $threshold);
}
}
else {
$result = comment_query($link, $lid, $order, 0);
while ($comment = db_fetch_object($result)) {
comment_comment($comment, (comment_visible($comment, $threshold) ? comment_link($comment, 0) : 0));
comment_view($comment, (comment_visible($comment, $threshold) ? comment_link($comment, 0) : 0));
comment_thread_max($comment->cid, $mode, $threshold, $level + 1);
}
}
......@@ -359,8 +345,8 @@ function comment_render($lid, $cid) {
if ($user->id) {
// Print moderation form:
print " <INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$lid\">\n";
print " <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Moderate comments") ."\">\n";
print " <INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$lid\">\n";
print " <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Moderate comments") ."\">\n";
print "</FORM>\n";
}
}
......
<?
/*
* These functions build the foundation for accessing the database:
* it is a general database abstraction layer suitable for several
* databases. Currently, the only supported database is MySQL but
* it should be straightforward to port it to any other database:
* just adjust the handlers to your needs.
*/
function db_connect($host, $user, $pass, $name) {
mysql_pconnect($host, $user, $pass) or die(mysql_Error());
......@@ -45,9 +38,7 @@ function db_result($qid, $field = 0) {
if ($qid) return mysql_result($qid, $field);
}
#
# Automatically connect to database:
#
// Setup database connection:
db_connect($db_host, $db_user, $db_pass, $db_name);
?>
?>
\ No newline at end of file
......@@ -36,19 +36,19 @@ function format_plural($count, $singular, $plural) {
function format_interval($timestamp) {
if ($timestamp >= 86400) {
$output .= format_plural(floor($timestamp / 86400), "day ", "days ");
$output .= format_plural(floor($timestamp / 86400), "day", "days");
$timestamp = $timestamp % 86400;
}
if ($timestamp >= 3600) {
$output .= format_plural(floor($timestamp / 3600), "hour ", "hours ");
$output .= " ". format_plural(floor($timestamp / 3600), "hour", "hours");
$timestamp = $timestamp % 3600;
}
if ($timestamp >= 60) {
$output .= floor($timestamp / 60) ." min ";
$output .= " ". floor($timestamp / 60) ."min";
$timestamp = $timestamp % 60;
}
if ($timestamp > 0) {
$output .= "$timestamp sec";
$output .= " $timestamp sec";
}
return ($output) ? $output : "0 sec";
}
......@@ -74,7 +74,6 @@ function format_date($timestamp, $type = "medium") {
return $date;
}
function format_username($username) {
global $user;
if ($username) return (user_access($user, "account") ? "<A HREF=\"admin.php?mod=account&op=view&name=$username\">$username</A>" : "<A HREF=\"account.php?op=view&name=$username\">$username</A>");
......
......@@ -8,12 +8,11 @@ $db_user = "username";
$db_pass = "password";
$db_name = "database";
#
# Administrative information
#
$site_name = "site name";
$site_url = "http://yourdomain.com/";
$site_url = "http://yourdomain.com/"; // add a trailing slash
$site_email = "info@yourdomain.com";
#
......@@ -89,11 +88,12 @@ $submission_votes = array("neutral (+0)" => "+ 0",
$submission_rate = array("comment" => "60", // 60 seconds = 1 minute
"diary" => "300", // 300 seconds = 5 minutes
"story" => "300"); // 300 seconds = 5 minutes
#
# Submission size:
# the maximum length (i.e. the maximum number of characters) a
# story, a diary entry, or a comment is allowed to be.
#
$submission_size = 12000; // 12.000 characters is more or less 300 lines
$submission_size = 12000; // 12.000 characters is appr. 300 lines
?>
......@@ -101,7 +101,7 @@ function theme_moderation_results($theme, $story) {
$output .= format_username($account->userid) ." voted `". user_get($account, "history", "s$story->id") ."'.<BR>";
}
$theme->box("Moderation results", ($output ? $output : "This story has not been moderated yet."));
$theme->box(t("Moderation results"), ($output ? $output : t("This story has not been moderated yet.")));
}
}
......@@ -115,12 +115,9 @@ function theme_related_links($theme, $story) {
}
// Stories in the same section:
$content .= " <LI>More about <A HREF=\"index.php?section=". urlencode($story->section) ."\">$story->section</A>.</LI>";
$content .= " <LI>". t("More about") ." <A HREF=\"index.php?section=". urlencode($story->section) ."\">$story->section</A>.</LI>";
// Stories from the same author:
if ($story->userid) $content .= " <LI>Also by <A HREF=\"search.php?author=". urlencode($story->userid) ."\">$story->userid</A>.</LI>";
$theme->box("Related links", $content);
$theme->box(t("Related links"), $content);
}
function theme_new_headlines($theme, $num = 10) {
......@@ -129,7 +126,7 @@ function theme_new_headlines($theme, $num = 10) {
$content = "";
$result = db_query("SELECT id, subject FROM stories WHERE status = 2 ORDER BY id DESC LIMIT $num");
while ($story = db_fetch_object($result)) $content .= "<LI><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></LI>\n";
$theme->box("Latest headlines", $content);
$theme->box(t("Latest headlines"), $content);
}
function theme_old_headlines($theme, $num = 10) {
......@@ -145,7 +142,7 @@ function theme_old_headlines($theme, $num = 10) {
}
$content .= "<LI><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></LI>\n";
}
$theme->box("Older headlines", $content);
$theme->box(t("Older headlines"), $content);
}
?>
......@@ -121,7 +121,7 @@ class backend {
$update = round((time() - $this->timestamp) / 60);
// Display box:
$theme->box("$this->site", $content);
$theme->box($this->site, $content);
}
else print "<P>Warning: something whiched happened: specified channel could not be found in database.</P>";
}
......
......@@ -76,7 +76,7 @@ function diary_page_display($username) {
$result = db_query("SELECT d.*, u.userid FROM diaries d LEFT JOIN users u ON d.author = u.id WHERE u.userid = '$username' ORDER BY timestamp DESC");
if ($username == $user->userid) {
$output .= diary_page_entry(time(), "<BIG><A HREF=\"module.php?mod=diary&op=add\">Add new diary entry!</A></BIG><P>");
$output .= diary_page_entry(time(), "<BIG><A HREF=\"module.php?mod=diary&op=add\">". t("Add new diary entry!") ."</A></BIG><P>");
while ($diary = db_fetch_object($result)) $output .= diary_page_entry($diary->timestamp, $diary->text, $diary->id);
}
else {
......
......@@ -102,7 +102,7 @@ function submission_display_item($id) {
$theme->header();
$theme->article($submission, "[ <A HREF=\"module.php?mod=submission\"><FONT COLOR=\"$theme->link\">back</FONT></A> ]");
$theme->box("Moderate story", $output);
$theme->box(t("Moderate story"), $output);
$theme->footer();
}
}
......
......@@ -129,7 +129,7 @@ function abstract($story) {
<TD>
<?PHP
if ($story->updates)
echo "<P><FONT COLOR=\"#E09226\">". t("Editor's note") .":</FONT>". check_output($story->updates, 1) ."</P>";
if ($story->abstract)
......@@ -225,7 +225,7 @@ function article($story, $reply) {
if ($story->updates)
echo "<P>check_output($story->abstract, 1)</P><P><FONT COLOR=\"#E09226\">Editor's note by <A HREF=\"account.php?op=userinfo&uname=$story->editor\">$story->editor</A>:</FONT>$story->updates</P>";
else
else
echo check_output($story->abstract, 1);
if ($story->article)
echo "<P>". check_output($story->article, 1) ."</P>";
......@@ -273,7 +273,7 @@ function comment($comment, $link = "", $thread = "") {
echo " <TR>";
echo " <TD>";
echo " <TABLE BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"0\"WIDTH=\"100%\">";
// Subject:
echo " <TR>";
echo " <TD ALIGN=\"right\" WIDTH=\"5%\">";
......@@ -283,7 +283,7 @@ function comment($comment, $link = "", $thread = "") {
echo " <B>". check_output($comment->subject) ."</B>";
echo " </FONT>";
echo " </TD>";
// Moderation:
echo " <TD BGCOLOR=\"#6C6C6C\" BACKGROUND=\"themes/jeroen/images/menutitle.gif\" ALIGN=\"right\" ROWSPAN=\"2\" VALIGN=\"middle\" WIDTH=\"15%\">";
echo " <FONT COLOR=\"#000000\">";
......@@ -291,7 +291,7 @@ function comment($comment, $link = "", $thread = "") {
echo " </FONT>";
echo " </TD>";
echo " </TR>";
// Author:
echo " <TR>";
echo " <TD ALIGN=\"right\"><FONT COLOR=\"#FEFEFE\">". t("Author") .":</FONT></TD><TD><B>" .format_username($comment->userid) . "</B> ";
......@@ -304,14 +304,14 @@ function comment($comment, $link = "", $thread = "") {
echo " <FONT COLOR=\"#FEFEFE\">on ". format_date($comment->timestamp) ."</FONT>";
echo " </TD>";
echo " </TR>";
echo " </TABLE>";
echo " </TD>";
echo " </TR>";
// Print body of comment:
if ($comment) echo " <TR><TD BGCOLOR=\"#E7E7E7\" BACKGROUND=\"themes/jeroen/images/sketch.gif\">" . check_output($comment->comment, 1) ."</TD></TR>";
// Print thread (if any):
if ($thread) echo " <TR><TD BGCOLOR=\"#E7E7E7\" BACKGROUND=\"themes/jeroen/images/sketch.gif\">$thread</TD></TR>";
......@@ -325,7 +325,7 @@ function comment($comment, $link = "", $thread = "") {
echo " </TR>";
echo " </TABLE>";
echo " <BR>";
} // close comment function
function box($subject, $content, $options = "") {
......
......@@ -22,7 +22,7 @@ class Theme {
// color set #3:
var $bgcolor3 = "#D7D7D7";
var $fgcolor3 = "#000000";
function header() {
global $site_name;
srand((double)microtime()*1000000);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment