\n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "
Username:
Password:
\n"; $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"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "
Username:
E-mail addres:
\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"; $output .= "

\n"; $output .= " Username:
\n"; $output .= "
\n"; $output .= " Enter your desired username: only letters, numbers and common special characters are allowed.
\n"; $output .= "

\n"; $output .= "

\n"; $output .= " E-mail address:
\n"; $output .= "
\n"; $output .= " You will be sent instructions on how to validate your account via this e-mail address - please make sure it is accurate.
\n"; $output .= "

\n"; $output .= "

\n"; $output .= " \n"; $output .= "

\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"; $output .= "Username:
\n"; $output .= "  $user->userid

\n"; $output .= "Required, unique, and can not be changed.

\n"; $output .= "Real name:
\n"; $output .= "name\">
\n"; $output .= "Optional.

\n"; $output .= "Real e-mail address:
\n"; $output .= "  $user->real_email

\n"; $output .= "Required, unique, can not be changed and is never displayed publicly: only needed in case you lose your password.

\n"; $output .= "Fake e-mail address:
\n"; $output .= "fake_email\">
\n"; $output .= "Optional, and displayed publicly. You may spam proof your real e-mail address if you want.

\n"; $output .= "URL of homepage:
\n"; $output .= "url\">
\n"; $output .= "Optional, but make sure you enter fully qualified URLs only. That is, remember to include \"http://\".

\n"; $output .= "Bio: (255 char. limit)
\n"; $output .= "
\n"; $output .= "Optional. This biographical information is publicly displayed on your user page.

\n"; $output .= "Signature: (255 char. limit)
\n"; $output .= "
\n"; $output .= "Optional. This information will be publicly displayed at the end of your comments.

\n"; $output .= "Password:
\n"; $output .= "
\n"; $output .= "Enter your new password twice if you want to change your current password or leave it blank if you are happy with your current password.

\n"; $output .= "
\n"; $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"; $output .= "Theme:
\n"; foreach ($themes as $key=>$value) { $options1 .= " \n"; } $output .= "
\n"; $output .= "Selecting a different theme will change the look and feel of the site.

\n"; $output .= "Timezone:
\n"; $date = time() - date("Z"); for ($zone = -43200; $zone <= 46800; $zone += 3600) { $options2 .= " \n"; } $output .= "
\n"; $output .= "Select what time you currently have and your timezone settings will be set appropriate.

\n"; $output .= "Maximum number of stories:
\n"; $output .= "stories\">

\n"; $output .= "The maximum number of stories that will be displayed on the main page.

\n"; $options = ""; $options .= ""; $options .= ""; $output .= "Comment display mode:
\n"; $output .= "

\n"; $options = ""; $options .= ""; $options .= ""; $output .= "Comment sort order:
\n"; $output .= "

\n"; $options = ""; $options .= ""; $options .= ""; $options .= ""; $options .= ""; $options .= ""; $options .= ""; $output .= "Comment threshold:
\n"; $output .= "
\n"; $output .= "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.

\n"; $output .= "
\n"; $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"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "
User ID:$user->userid
Name:". format_data($user->name) ."
E-mail:". format_email($user->fake_email) ."
URL:". format_url($user->url) ."
Bio:". format_data($user->bio) ."
Signature:". format_data($user->signature) ."
\n"; ### Display account information: $theme->header(); $theme->box("View your information", $output); $theme->footer(); } elseif ($uname && $account = account_get_user($uname)) { $box1 .= "\n"; $box1 .= " \n"; $box1 .= " \n"; $box1 .= " \n"; $box1 .= " \n"; $box1 .= "
Username:$account->userid
E-mail:". format_email($account->fake_email) ."
URL:". format_url($account->url) ."
Bio:". format_data($account->bio) ."
\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"; $box2 .= " \n"; $box2 .= " \n"; $box2 .= " \n"; $box2 .= "
Comment:sid&cid=$comment->cid&pid=$comment->pid#$comment->cid\">". check_output($comment->subject) ."
Date:". format_date($comment->timestamp) ."
Story:sid\">". check_output($comment->story) ."
\n"; $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 .= "

". date("l, F jS", $diary->timestamp) .":

". check_output($diary->text) ."

[ more ]

\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 .= "

  • ". format_plural($story->count, comment, comments) ." attached to story `id\">". check_output($story->subject) ."`:
  • \n"; $output .= " \n"; } $output = ($output) ? "$msg $output" : "$info
    You have not posted any comments recently.
    \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"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "
    Subject:id\">". check_output($story->subject) ." (". format_plural($story->count, "comment", "comments") .")
    Category:category) ."\">". check_output($story->category) ."
    Date:". format_date($story->timestamp) ."
    \n"; $output .= "

    \n"; } $output = ($output) ? "$msg $output" : "$info

    You have not posted any stories.
    \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"; $box1 .= " \n"; $box1 .= " \n"; $box1 .= " \n"; $box1 .= "
    Comment:sid&cid=$comment->cid&pid=$comment->pid#$comment->cid\">". check_output($comment->subject) ."
    Author:". format_username($comment->userid) ."
    Story:sid\">". check_output($comment->story) ."
    \n"; $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 .= "\n"; $box2 .= " \n"; $box2 .= " \n"; $box2 .= " \n"; $box2 .= " \n"; $box2 .= "
    Users:$users_total users
    Stories:$stories_posted posted, $stories_queued queued, $stories_dumped dumped
    [most frequent posters: $stories_posters ...]
    Comments:$comments_total comments with an average score of $comments_score
    [most frequent posters: $comments_posters ...]
    Diaries:$diaries_total diary entries
    [most frequent posters: $diaries_posters ...]
    \n"; $theme->header(); $theme->box("Recent comments", $box1); $theme->box("Site statistics", $box2); $theme->footer(); } ### Security check: if (strstr($name, " ") || strstr($hash, " ")) { watchdog("error", "account: attempt to provide malicious input through URI"); exit(); } switch ($op) { case "Login": account_session_start($userid, $passwd); header("Location: account.php?op=info"); break; case "E-mail password": account_email_submit($userid, $email); break; case "Create account": account_create_submit($userid, $email); break; case "confirm": account_create_confirm($name, $hash); break; case "Save user information": account_user_save($edit); account_user($user->userid); break; case "Save page settings": account_page_save($edit); header("Location: account.php?op=info"); break; case "logout": account_session_close(); header("Location: account.php?op=info"); break; case "view": switch ($topic) { case "info": account_user($user->userid); break; case "diary": header("Location: diary.php?op=view&name=$user->userid"); break; default: account_user($name); } break; case "track": switch ($topic) { case "site": account_track_site(); break; case "stories": account_track_stories(); break; default: account_track_comments(); } break; case "edit": switch ($topic) { case "user": account_user_edit(); break; case "page": account_page_edit(); break; default: header("Location: diary.php?op=add&name=$user->userid"); } break; default: account_user($user->userid); } ?>