include "includes/theme.inc";
function account_get_user($uname) {
$result = db_query("SELECT * FROM users WHERE userid = '$uname'");
return db_fetch_object($result);
}
function account_login() {
$output .= "
\n";
return $output;
}
function account_email() {
$output .= "
Lost your password? Fill out your username and e-mail address, and your password will be mailed to you.
\n";
$output .= "\n";
return $output;
}
function account_create($user = "", $error = "") {
global $theme;
if ($error) $output .= "Failed to register.$error\n";
else $output .= "
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.
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.
\n";
$output .= "\n";
return $output;
}
function account_session_start($userid, $passwd) {
global $user;
$user = new User($userid, $passwd);
if ($user->id) {
session_start();
session_register("user");
watchdog("message", "session opened for user `$user->userid'");
}
else {
watchdog("warning", "failed login for user `$userid'");
}
}
function account_session_close() {
global $user;
watchdog("message", "session closed for user `$user->userid'");
session_unset();
session_destroy();
unset($user);
}
function account_user_edit() {
global $theme, $user;
if ($user->id) {
### Generate output/content:
$output .= "\n";
### Display output/content:
$theme->header();
$theme->box("Edit your information", $output);
$theme->footer();
}
else {
$theme->header();
$theme->box("Login", account_login());
$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];
$data[url] = $edit[url];
$data[bio] = $edit[bio];
$data[signature] = $edit[signature];
if ($edit[pass1] && $edit[pass1] == $edit[pass2]) $data[passwd] = $edit[pass1];
user_save($data, $user->id);
}
}
function account_page_edit() {
global $theme, $themes, $user;
if ($user->id) {
$output .= "\n";
$theme->header();
$theme->box("Edit your settings", $output);
$theme->footer();
}
else {
$theme->header();
$theme->box("Login", account_login());
$theme->box("E-mail password", account_email());
$theme->box("E-mail password", account_create());
$theme->footer();
}
}
function account_page_save($edit) {
global $user;
if ($user->id) {
$data[theme] = $edit[theme];
$data[timezone] = $edit[timezone];
$data[stories] = $edit[stories];
$data[mode] = $edit[mode];
$data[sort] = $edit[sort];
$data[threshold] = $edit[threshold];
user_save($data, $user->id);
}
}
function account_user($uname) {
global $user, $theme;
if ($user->id && $user->userid == $uname) {
$output .= "
\n";
$result = db_query("SELECT c.cid, c.pid, c.sid, c.subject, c.timestamp, s.subject AS story FROM comments c LEFT JOIN users u ON u.id = c.author LEFT JOIN stories s ON s.id = c.sid WHERE u.userid = '$uname' AND s.status = 2 AND s.timestamp > ". (time() - 1209600) ." ORDER BY cid DESC LIMIT 10");
while ($comment = db_fetch_object($result)) {
$box2 .= "
\n";
$comments++;
}
$result = db_query("SELECT d.* FROM diaries d LEFT JOIN users u ON u.id = d.author WHERE u.userid = '$uname' AND d.timestamp > ". (time() - 1209600) ." ORDER BY id DESC LIMIT 2");
while ($diary = db_fetch_object($result)) {
$box3 .= "
\n";
$diaries++;
}
### Display account information:
$theme->header();
if ($box1) $theme->box("User information for $uname", $box1);
if ($box2) $theme->box("$uname has posted ". format_plural($comments, "comment", "comments") ." recently", $box2);
if ($box3) $theme->box("$uname has posted ". format_plural($diaries, "diary entry", "diary entries") ." recently", $box3);
$theme->footer();
}
else {
### Display login form:
$theme->header();
$theme->box("Login", account_login());
$theme->box("E-mail password", account_email());
$theme->box("Create new account", account_create());
$theme->footer();
}
}
function account_validate($user) {
include "includes/ban.inc";
### Verify username and e-mail address:
if (empty($user[real_email]) || (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$", $user[real_email]))) $error .= "
the specified e-mail address is not valid.
\n";
if (empty($user[userid]) || (ereg("[^a-zA-Z0-9_-]", $user[userid]))) $error .= "
the specified username is not valid.
\n";
if (strlen($user[userid]) > 15) $error .= "
the specified username is too long: it must be less than 15 characters.
\n";
### Check to see whether the username or e-mail address are banned:
if ($ban = ban_match($user[userid], $type2index[usernames])) $error .= "
the specified username is banned for the following reason: $ban->reason.
\n";
if ($ban = ban_match($user[real_email], $type2index[addresses])) $error .= "
the specified e-mail address is banned for the following reason: $ban->reason.
\n";
### Verify whether username and e-mail address are unique:
if (db_num_rows(db_query("SELECT userid FROM users WHERE LOWER(userid) = LOWER('$user[userid]')")) > 0) $error .= "
the specified username is already taken.
\n";
if (db_num_rows(db_query("SELECT real_email FROM users WHERE LOWER(real_email)=LOWER('$user[real_email]')")) > 0) $error .= "
the specified e-mail address is already registered.
\n";
return $error;
}
function account_email_submit($userid, $email) {
global $theme, $site_name, $site_url;
$result = db_query("SELECT id FROM users WHERE userid = '". check_output($userid) ."' AND real_email = '". check_output($email) ."'");
if ($account = db_fetch_object($result)) {
$passwd = account_password();
$status = 1;
$hash = substr(md5("$userid. ". time() .""), 0, 12);
db_query("UPDATE users SET passwd = PASSWORD('$passwd'), hash = '$hash', status = '$status' WHERE userid = '$userid'");
$link = $site_url ."account.php?op=confirm&name=$userid&hash=$hash";
$message = "$userid,\n\n\nyou requested us to e-mail you a new password for your $site_name account. Note that you will need to re-activate your account before you can login. You can do so simply by visiting the URL below:\n\n $link\n\nVisiting this URL will automatically re-activate your account. Once activated you can login using the following information:\n\n username: $userid\n password: $passwd\n\n\n-- $site_name crew\n";
watchdog("message", "new password: `$userid' <$email>");
mail($email, "Account details for $site_name", $message, "From: noreply");
$output = "Your password and further instructions have been sent to your e-mail address.";
}
else {
watchdog("warning", "new password: '$userid' and <$email> do not match");
$output = "Could not sent password: no match for the specified username and e-mail address.";
}
$theme->header();
$theme->box("E-mail password", $output);
$theme->footer();
}
function account_create_submit($userid, $email) {
global $theme, $site_name, $site_url;
$new[userid] = $userid;
$new[real_email] = $email;
if ($rval = account_validate($new)) {
$theme->header();
$theme->box("Create new account", account_create($new, $rval));
$theme->footer();
}
else {
$new[passwd] = account_password();
$new[status] = 1;
$new[hash] = substr(md5("$new[userid]. ". time() .""), 0, 12);
user_save($new);
$link = $site_url ."account.php?op=confirm&name=$new[userid]&hash=$new[hash]";
$message = "$new[userid],\n\n\nsomeone signed up for a user account on $site_name and supplied this email address as their contact. If it wasn't you, don't get your panties in a knot and simply ignore this mail.\n\nIf this was you, you have to activate your account first before you can login. You can do so simply by visiting the URL below:\n\n $link\n\nVisiting this URL will automatically activate your account. Once activated you can login using the following information:\n\n username: $new[userid]\n password: $new[passwd]\n\n\n-- $site_name crew\n";
watchdog("message", "new account: `$new[userid]' <$new[real_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->footer();
}
}
function account_create_confirm($name, $hash) {
global $theme;
$result = db_query("SELECT userid, hash, status FROM users WHERE userid = '$name'");
if ($account = db_fetch_object($result)) {
if ($account->status == 1) {
if ($account->hash == $hash) {
db_query("UPDATE users SET status = 2, hash = '' WHERE userid = '$name'");
$output .= "Your account has been sucessfully confirmed. You can click here to login.\n";
watchdog("message", "$name: account confirmation sucessful");
}
else {
$output .= "Confirmation failed: invalid confirmation hash.\n";
watchdog("warning", "$name: invalid confirmation hash");
}
}
else {
$output .= "Confirmation failed: your account has already been confirmed. You can click here to login.\n";
watchdog("warning", "$name: attempt to re-confirm account");
}
}
else {
$output .= "Confirmation failed: no such account found. ";
watchdog("warning", "$name: attempt to confirm non-existing account");
}
$theme->header();
$theme->box("Account confirmation", $output);
$theme->footer();
}
function account_password($min_length=6) {
mt_srand((double)microtime() * 1000000);
$words = array("foo","bar","guy","neo","tux","moo","sun","asm","dot","god","axe","geek","nerd","fish","hack","star","mice","warp","moon","hero","cola","girl","fish","java","perl","boss","dark","sith","jedi","drop","mojo");
while(strlen($password) < $min_length) $password .= $words[mt_rand(0, count($words))];
return $password;
}
function account_track_comments() {
global $theme, $user;
$msg = "
This page might be helpful in case you want to keep track of your recent comments in any of the current discussions. You are presented an overview of your comments in each of the stories you participated in along with the number of replies each comment got.\n
\n";
$sresult = db_query("SELECT s.id, s.subject, COUNT(s.id) as count FROM comments c LEFT JOIN stories s ON c.sid = s.id WHERE c.author = $user->id GROUP BY s.id DESC LIMIT 5");
while ($story = db_fetch_object($sresult)) {
$output .= "
\n";
$theme->header();
$theme->box("Track your comments", $output);
$theme->footer();
}
function account_track_stories() {
global $theme, $user;
$msg = "
This page might be helpful in case you want to keep track of the stories you contributed. You are presented an overview of your stories along with the number of replies each story got.\n
\n";
$result = db_query("SELECT s.id, s.subject, s.timestamp, s.category, COUNT(s.id) as count FROM comments c LEFT JOIN stories s ON c.sid = s.id WHERE s.status = 2 AND s.author = $user->id GROUP BY s.id DESC");
while ($story = db_fetch_object($result)) {
$output .= "
\n";
$theme->header();
$theme->box("Track your stories", $output);
$theme->footer();
}
function account_track_site() {
global $theme, $user, $site_name;
$result1 = db_query("SELECT c.cid, c.pid, c.sid, c.subject, u.userid, s.subject AS story FROM comments c LEFT JOIN users u ON u.id = c.author LEFT JOIN stories s ON s.id = c.sid WHERE s.status = 2 ORDER BY cid DESC LIMIT 10");
while ($comment = db_fetch_object($result1)) {
$box1 .= "
\n";
}
$users_total = db_result(db_query("SELECT COUNT(id) FROM users"));
$stories_posted = db_result(db_query("SELECT COUNT(id) FROM stories WHERE status = 2"));
$stories_queued = db_result(db_query("SELECT COUNT(id) FROM stories WHERE status = 1"));
$stories_dumped = db_result(db_query("SELECT COUNT(id) FROM stories WHERE status = 0"));
$result = db_query("SELECT u.userid, COUNT(s.author) AS count FROM stories s LEFT JOIN users u ON s.author = u.id GROUP BY s.author ORDER BY count DESC LIMIT 10");
while ($poster = db_fetch_object($result)) $stories_posters .= format_username($poster->userid) .", ";
$comments_total = db_result(db_query("SELECT COUNT(cid) FROM comments"));
$comments_score = db_result(db_query("SELECT TRUNCATE(AVG(score / votes), 2) FROM comments WHERE votes > 0"));
$result = db_query("SELECT u.userid, COUNT(c.author) AS count FROM comments c LEFT JOIN users u ON c.author = u.id GROUP BY c.author ORDER BY count DESC LIMIT 10");
while ($poster = db_fetch_object($result)) $comments_posters .= format_username($poster->userid) .", ";
$diaries_total = db_result(db_query("SELECT COUNT(id) FROM diaries"));
$result = db_query("SELECT u.userid, COUNT(d.author) AS count FROM diaries d LEFT JOIN users u ON d.author = u.id GROUP BY d.author ORDER BY count DESC LIMIT 10");
while ($poster = db_fetch_object($result)) $diaries_posters .= format_username($poster->userid) .", ";
$box2 .= "