Commit 524773f6 authored by Dries's avatar Dries

Yet another large batch of updates:

 - I rearranged some of the code and clean-up some of the mess.

 - Added "blocks" which can be user defined/controlled: check
   to see.  The positioning of blocks is rather basic for the
   moment, so I'm all open for input on that.
parent 8d5b4e7b
<?
include "includes/theme.inc";
include "includes/common.inc";
function account_get_user($uname) {
$result = db_query("SELECT * FROM users WHERE userid = '$uname'");
return db_fetch_object($result);
}
function account_login() {
$output .= "<FORM ACTION=\"account.php\" METHOD=\"post\">\n";
$output .= " <TABLE BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
$output .= " <TR><TH ALIGN=\"right\">Username:</TH><TD><INPUT NAME=\"userid\"></TD></TR>\n";
$output .= " <TR><TH ALIGN=\"right\">Password:</TH><TD><INPUT NAME=\"passwd\" TYPE=\"password\"></TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\" COLSPAN=\"2\"><INPUT NAME=\"op\" TYPE=\"submit\" VALUE=\"Login\"></TD></TR>\n";
$output .= " </TABLE>\n";
$output .= "</FORM>\n";
return $output;
}
function account_email() {
$output .= "<P>Lost your password? Fill out your username and e-mail address, and your password will be mailed to you.</P>\n";
$output .= "<FORM ACTION=\"account.php\" METHOD=\"post\">\n";
......@@ -36,7 +24,7 @@ function account_create($user = "", $error = "") {
global $theme;
if ($error) $output .= "<B><FONT COLOR=\"red\">Failed to register.</FONT>$error</B>\n";
else $output .= "<P>Registering allows you to comment on stories, to moderate comments and pending stories, to maintain an online diary, to customize the look and feel of the site and generally helps you interact with the site more efficiently.</P><P>To create an account, simply fill out this form an click the `Create account' button below. An e-mail will then be sent to you with instructions on how to validate your account.</P>\n";
else $output .= "<P>Registering allows you to comment on stories, to moderate comments and pending stories, to customize the look and feel of the site and generally helps you interact with the site more efficiently.</P><P>To create an account, simply fill out this form an click the `Create account' button below. An e-mail will then be sent to you with instructions on how to validate your account.</P>\n";
$output .= "<FORM ACTION=\"account.php\" METHOD=\"post\">\n";
$output .= "<P>\n";
......@@ -119,15 +107,15 @@ function account_user_edit() {
}
else {
$theme->header();
$theme->box("Login", account_login());
$theme->box("Create user account", account_create());
$theme->box("E-mail password", account_email());
$theme->box("Create new account", account_create());
$theme->footer();
}
}
function account_user_save($edit) {
global $user;
if ($user->id) {
$data[name] = $edit[name];
$data[fake_email] = $edit[fake_email];
......@@ -141,7 +129,7 @@ function account_user_save($edit) {
}
}
function account_page_edit() {
function account_site_edit() {
global $theme, $themes, $user;
if ($user->id) {
......@@ -164,7 +152,12 @@ function account_page_edit() {
$output .= "<SELECT NAME=\"edit[timezone]\">\n$options2</SELECT><BR>\n";
$output .= "<I>Select what time you currently have and your timezone settings will be set appropriate.</I><P>\n";
$output .= "<B>Maximum number of stories:</B><BR>\n";
$output .= "<INPUT NAME=\"edit[stories]\" MAXLENGTH=\"3\" SIZE=\"3\" VALUE=\"$user->stories\"><P>\n";
for ($stories = 10; $stories <= 30; $stories += 5) {
$options3 .= "<OPTION VALUE=\"$stories\"". (($user->stories == $stories) ? " SELECTED" : "") .">$stories</OPTION>\n";
}
$output .= "<SELECT NAME=\"edit[stories]\">\n$options3</SELECT><BR>\n";
$output .= "<I>The maximum number of stories that will be displayed on the main page.</I><P>\n";
$options = "<OPTION VALUE=\"nested\"". ($user->mode == "nested" ? " SELECTED" : "") .">Nested</OPTION>";
$options .= "<OPTION VALUE=\"flat\"". ($user->mode == "flat" ? " SELECTED" : "") .">Flat</OPTION>";
......@@ -186,7 +179,9 @@ function account_page_edit() {
$output .= "<B>Comment threshold:</B><BR>\n";
$output .= "<SELECT NAME=\"edit[threshold]\">$options</SELECT><BR>\n";
$output .= "<I>Comments that scored less than this setting will be ignored. Anonymous comments start at 0, comments of people logged on start at 1 and moderators can add and subtract points.</I><P>\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Save page settings\"><BR>\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Save site settings\"><BR>\n";
$output .= "</FORM>\n";
$theme->header();
......@@ -195,15 +190,15 @@ function account_page_edit() {
}
else {
$theme->header();
$theme->box("Login", account_login());
$theme->box("Create user account", account_create());
$theme->box("E-mail password", account_email());
$theme->box("E-mail password", account_create());
$theme->footer();
}
}
function account_page_save($edit) {
function account_site_save($edit) {
global $user;
if ($user->id) {
$data[theme] = $edit[theme];
$data[timezone] = $edit[timezone];
......@@ -215,6 +210,53 @@ function account_page_save($edit) {
}
}
function account_block_edit() {
global $theme, $user;
if ($user->id) {
$output .= "<FORM ACTION=\"account.php\" METHOD=\"post\">\n";
$output .= "<B>Blocks:</B><BR>\n";
$result = db_query("SELECT * FROM blocks WHERE status = 1");
while ($block = db_fetch_object($result)) {
$entry = db_fetch_object(db_query("SELECT * FROM layout WHERE block = '$block->name' AND user = '$user->id'"));
$options = "";
for ($weight = 0; $weight < 10; $weight++) {
$options .= "<OPTION VALUE=\"$weight\"". (($entry->weight == $weight) ? " SELECTED" : "") .">". (($weight == 0) ? "off" : $weight) ."</OPTION>\n";
}
$output .= "<SELECT NAME=\"edit[$block->name]\">\n$options</SELECT>";
$output .= "$block->name<BR>";
}
$output .= "<I>You can more or less position your blocks by assigning them weights. The heavy blocks sink down whereas the light blocks will be positioned on top.</I><P>\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Save block settings\"><BR>\n";
$output .= "</FORM>\n";
$theme->header();
$theme->box("Edit your blocks", $output);
$theme->footer();
}
else {
$theme->header();
$theme->box("Create user account", account_create());
$theme->box("E-mail password", account_email());
$theme->footer();
}
}
function account_block_save($edit) {
global $user;
if ($user->id) {
db_query("DELETE FROM layout WHERE user = $user->id");
foreach ($edit as $block=>$weight) {
db_query("INSERT INTO layout (user, block, weight) VALUES ('". check_input($user->id) ."', '". check_input($block) ."', '". check_input($weight) ."')");
}
}
}
function account_user($uname) {
global $user, $theme;
......@@ -268,9 +310,8 @@ function account_user($uname) {
else {
### Display login form:
$theme->header();
$theme->box("Login", account_login());
$theme->box("Create user account", account_create());
$theme->box("E-mail password", account_email());
$theme->box("Create new account", account_create());
$theme->footer();
}
}
......@@ -333,7 +374,7 @@ function account_create_submit($userid, $email) {
if ($rval = account_validate($new)) {
$theme->header();
$theme->box("Create new account", account_create($new, $rval));
$theme->box("Create user account", account_create($new, $rval));
$theme->footer();
}
else {
......@@ -351,7 +392,7 @@ function account_create_submit($userid, $email) {
mail($new[real_email], "Account details for $site_name", $message, "From: noreply");
$theme->header();
$theme->box("Create new account", "Congratulations! Your member account has been sucessfully created and further instructions on how to activate your account have been sent to your e-mail address.");
$theme->box("Create user account", "Congratulations! Your member account has been sucessfully created and further instructions on how to activate your account have been sent to your e-mail address.");
$theme->footer();
}
}
......@@ -514,10 +555,14 @@ function account_track_site() {
account_user_save($edit);
account_user($user->userid);
break;
case "Save page settings":
account_page_save($edit);
case "Save site settings":
account_site_save($edit);
header("Location: account.php?op=info");
break;
case "Save block settings":
account_block_save($edit);
account_user($user->userid);
break;
case "logout":
account_session_close();
header("Location: account.php?op=info");
......@@ -551,8 +596,11 @@ function account_track_site() {
case "user":
account_user_edit();
break;
case "page":
account_page_edit();
case "site":
account_site_edit();
break;
case "block":
account_block_edit();
break;
default:
header("Location: module.php?mod=diary&op=add&name=$user->userid");
......
......@@ -3,8 +3,7 @@
// validate user permission:
if (!$user->id || ($user->permissions != 1 && $user->id > 1)) exit();
include_once "includes/theme.inc";
include_once "includes/cron.inc";
include "includes/common.inc";
function admin_page($mod) {
global $repository, $menu, $modules;
......
<?
include "includes/theme.inc";
include "includes/common.inc";
function cron_run($cron) {
global $repository;
......
......@@ -272,7 +272,7 @@ function comment_post($pid, $sid, $subject, $comment) {
}
}
include "includes/theme.inc";
include "includes/common.inc";
include "includes/comment.inc";
### Security check:
......@@ -313,4 +313,4 @@ function comment_post($pid, $sid, $subject, $comment) {
$theme->footer();
}
?>
?>
\ No newline at end of file
......@@ -39,7 +39,7 @@ function error_httpd() {
print "</PRE>\n";
}
include "includes/theme.inc";
include "includes/common.inc";
switch ($op) {
case "flood":
......
<?
include_once "includes/". getenv("HTTP_HOST") .".conf";
include_once "includes/database.inc";
include_once "includes/watchdog.inc";
include_once "includes/function.inc";
include_once "includes/droplet.inc";
include_once "includes/module.inc";
include_once "includes/theme.inc";
include_once "includes/user.inc";
global $user;
$theme = load_theme();
?>
<?
include_once "includes/". getenv("HTTP_HOST") .".conf";
include_once "includes/database.inc";
include_once "includes/watchdog.inc";
include_once "includes/function.inc";
include_once "includes/droplet.inc";
include_once "includes/module.inc";
include_once "includes/widget.inc";
include_once "includes/user.inc";
global $user;
$theme = load_theme();
function theme_account($theme) {
global $user, $site_name;
if ($user->id) {
function submission_number() {
$result = db_query("SELECT COUNT(id) FROM stories WHERE status = 1");
return ($result) ? db_result($result, 0) : 0;
}
### Display account settings:
$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";
$content .= "<LI><A HREF=\"account.php?op=edit&topic=diary\">edit your diary</A></LI>\n";
$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 settings</A></LI>\n";
$content .= "<LI><A HREF=\"account.php?op=edit&topic=block\">edit your blocks</A></LI>\n";
$content .= "<P>\n";
$content .= "<LI><A HREF=\"account.php?op=view&topic=diary\">view your diary</A></LI>\n";
$content .= "<LI><A HREF=\"account.php?op=view&topic=info\">view your information</A></LI>\n";
$content .= "<P>\n";
$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);
}
}
function theme_main_blocks($theme) {
global $PHP_SELF, $user, $id;
switch (strtok($PHP_SELF, ".")) {
case "/discussion":
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;
default:
theme_account($theme);
}
}
function theme_user_blocks($theme) {
global $PHP_SELF, $repository, $user;
if ($user->id && strstr($PHP_SELF, "index.php")) {
$result = db_query("SELECT * FROM layout l LEFT JOIN blocks b ON l.block = b.name WHERE l.user = '$user->id' AND l.weight > 0 AND b.status = '1' ORDER BY weight DESC");
while ($block = db_fetch_object($result)) {
$blocks = module_execute($block->module, "block");
$theme->box($blocks[$block->offset]["subject"], $blocks[$block->offset]["content"]);
}
}
}
function theme_morelink($theme, $story) {
return ($story->article) ? "[ <A HREF=\"discussion.php?id=$story->id\"><FONT COLOR=\"$theme->hlcolor2\"><B>read more</B></FONT></A> | ". strlen($story->article) ." bytes | <A HREF=\"discussion.php?id=$story->id\"><FONT COLOR=\"$theme->hlcolor2\">". format_plural($story->comments, "comment", "comments") ."</FONT></A> ]" : "[ <A HREF=\"discussion.php?id=$story->id\"><FONT COLOR=\"$theme->hlcolor2\">". format_plural($story->comments, "comment", "comments") ."</FONT></A> ]";
}
function theme_moderation_results($theme, $story) {
global $user;
if ($user->id && $story->id && $vote = user_getHistory($user->history, "s$story->id")) {
$output .= "<P><B>You voted `$vote'.</B></P>\n";
$output .= "<P>\n";
$output .= "<B>Other people voted:</B><BR>\n";
$result = db_query("SELECT * FROM users WHERE id != $user->id AND history LIKE '%s$story->id%'");
while ($account = db_fetch_object($result)) {
$output .= "". format_username($account->userid) ." voted `". user_getHistory($account->history, "s$story->id") ."'.<BR>";
}
$theme->box("Moderation results", $output);
}
}
function theme_related_links($theme, $story) {
### Parse story for <A HREF="">-tags:
$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>";
}
### Stories in the same category:
$content .= " <LI>More about <A HREF=\"search.php?category=". urlencode($story->category) ."\">$story->category</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);
}
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);
}
$content .= "<LI><A HREF=\"discussion.php?id=$story->id\">$story->subject</A></LI>\n";
}
$content .= "<P ALIGN=\"right\">[ <A HREF=\"search.php\"><FONT COLOR=\"$theme->hlcolor2\">more</FONT></A> ]</P>";
$theme->box("Older headlines", $content);
}
function theme_comment_moderation($id, $author, $score, $votes) {
global $user, $comment_votes;
if ($user->id && $user->userid != $author && !user_getHistory($user->history, "c$id")) {
$output .= "<SELECT NAME=\"moderate[$id]\">\n";
foreach ($comment_votes as $key=>$value) $output .= " <OPTION VALUE=\"$value\">$key</OPTION>\n";
$output .= "</SELECT>\n";
}
else {
$output .= "<TABLE BORDER=\"0\" CELLSPACING=\"1\" CELLPADDING=\"0\"><TR><TD>score:</TD><TD>". format_data($score) ."</TD></TR><TR><TD>votes:</TD><TD>". format_data($votes) ."</TR></TABLE>";
}
return $output;
}
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");
while ($story = db_fetch_object($result)) $content .= "<LI><A HREF=\"discussion.php?id=$story->id\">$story->subject</A></LI>\n";
$content .= "<P ALIGN=\"right\">[ <A HREF=\"search.php\"><FONT COLOR=\"$theme->hlcolor2\">more</FONT></A> ]</P>";
$theme->box("Latest headlines", $content);
}
?>
<?
function display_module_blocks() {
global $repository, $theme;
function display_block($name, $module) {
global $theme;
if ($blocks = module_execute($name, "block")) {
foreach ($blocks as $id=>$block) {
$theme->box($block["subject"], $block["content"]);
}
function display_account($theme) {
global $user, $site_name;
if ($user->id) {
function submission_number() {
$result = db_query("SELECT COUNT(id) FROM stories WHERE status = 1");
return ($result) ? db_result($result, 0) : 0;
}
### Display account settings:
$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";
$content .= "<LI><A HREF=\"account.php?op=edit&topic=diary\">edit your diary</A></LI>\n";
$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 settings</A></LI>\n";
$content .= "<LI><A HREF=\"account.php?op=edit&topic=block\">edit your blocks</A></LI>\n";
$content .= "<P>\n";
$content .= "<LI><A HREF=\"account.php?op=view&topic=diary\">view your diary</A></LI>\n";
$content .= "<LI><A HREF=\"account.php?op=view&topic=info\">view your information</A></LI>\n";
$content .= "<P>\n";
$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);
}
}
module_iterate("display_block");
function display_main_blocks($theme) {
global $PHP_SELF, $user, $id;
switch (strtok($PHP_SELF, ".")) {
case "/discussion":
if ($user->id) $story = db_fetch_object(db_query("SELECT * FROM stories WHERE id = '$id'"));
if ($story->status == 1) display_moderation_results($theme, $story);
else display_new_headlines($theme);
break;
default:
display_account($theme);
}
}
function display_user_blocks($theme) {
global $repository, $user;
if ($user->id) {
$result = db_query("SELECT * FROM layout l LEFT JOIN blocks b ON l.block = b.name WHERE l.user = '$user->id' AND l.weight > 0 AND b.status = '1' ORDER BY weight DESC");
while ($block = db_fetch_object($result)) {
$blocks = module_execute($block->module, "block");
$theme->box($blocks[$block->offset]["subject"], $blocks[$block->offset]["content"]);
}
}
}
function display_morelink($theme, $story) {
......@@ -98,34 +151,4 @@ function display_new_headlines($theme, $num = 10) {
$theme->box("Latest headlines", $content);
}
function display_account($theme) {
global $user, $site_name;
if ($user->id) {
function submission_number() {
$result = db_query("SELECT COUNT(id) FROM stories WHERE status = 1");
return ($result) ? db_result($result, 0) : 0;
}
### Display account settings:
$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";
$content .= "<LI><A HREF=\"account.php?op=edit&topic=diary\">edit your diary</A></LI>\n";
$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 settings</A></LI>\n";
$content .= "<P>\n";
$content .= "<LI><A HREF=\"account.php?op=view&topic=diary\">view your diary</A></LI>\n";
$content .= "<LI><A HREF=\"account.php?op=view&topic=info\">view your information</A></LI>\n";
$content .= "<P>\n";
$content .= "<LI><A HREF=\"account.php?op=logout\">logout</A></LI>\n";
$theme->box("$user->userid's account", "$content", "NOWRAP");
}
}
?>
<?
include "includes/theme.inc";
include "includes/common.inc";
### Security check:
if (strstr($number, " ") || strstr($date, " ")) {
......
<?
include_once "includes/theme.inc";
include_once "includes/common.inc";
module_execute($mod, "page");
?>
......@@ -5,7 +5,7 @@
"block" => "backend_block",
"admin" => "backend_admin");
include "includes/theme.inc";
include "includes/common.inc";
include "modules/backend.class";
function backend_page() {
......
......@@ -4,8 +4,7 @@
"block" => "diary_block",
"admin" => "diary_admin");
include "includes/theme.inc";
include "includes/common.inc";
function diary_page_overview($num = 20) {
global $theme, $user;
......
......@@ -2,7 +2,7 @@
$module = array("page" => "faq_page");
include "includes/theme.inc";
include "includes/common.inc";
function faq_page() {
global $theme;
......