diff options
author | Dries Buytaert <dries@buytaert.net> | 2001-08-11 14:54:39 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2001-08-11 14:54:39 +0000 |
commit | 808b6b6cae71afd741023a0c08a6c925f2198752 (patch) | |
tree | d17e890898959601d841227fecd538f135371bfc /includes | |
parent | 876536a955b783c4f82185dc45557ef3b1bd949f (diff) | |
download | brdo-808b6b6cae71afd741023a0c08a6c925f2198752.tar.gz brdo-808b6b6cae71afd741023a0c08a6c925f2198752.tar.bz2 |
- Changed the authentication and login scheme as discussed on the mailing
list.
- Fixed the export function in book.module (patch my Julian).
- Fixed the comment alignment (comments got truncated).
Diffstat (limited to 'includes')
-rw-r--r-- | includes/comment.inc | 47 | ||||
-rw-r--r-- | includes/common.inc | 14 | ||||
-rw-r--r-- | includes/node.inc | 2 | ||||
-rw-r--r-- | includes/search.inc | 2 | ||||
-rw-r--r-- | includes/theme.inc | 7 | ||||
-rw-r--r-- | includes/user.inc | 24 |
6 files changed, 56 insertions, 40 deletions
diff --git a/includes/comment.inc b/includes/comment.inc index 757a27c89..1e9853325 100644 --- a/includes/comment.inc +++ b/includes/comment.inc @@ -10,8 +10,8 @@ $cmodes = array(1 => "List - min", 2 => "List - max", 3 => "Threaded - min", 4 = $corder = array(1 => "Date - new", 2 => "Date - old", 3 => "Rate - high", 4 => "Rate - low"); class Comment { - function Comment($userid, $subject, $comment, $timestamp, $url, $fake_email, $score, $votes, $cid, $lid) { - $this->userid = $userid; + function Comment($name, $subject, $comment, $timestamp, $url, $fake_email, $score, $votes, $cid, $lid) { + $this->name = $name; $this->subject = $subject; $this->comment = $comment; $this->timestamp = $timestamp; @@ -35,8 +35,8 @@ function comment_moderate($moderate) { $id = check_output($id); $vote = check_output($vote); $comment = db_fetch_object(db_query("SELECT * FROM comments WHERE cid = '$id'")); - if ($comment && !field_get($comment->users, $user->userid)) { - $result = db_query("UPDATE comments SET score = score $vote, votes = votes + 1, users = '". field_set($comment->users, $user->userid, $vote) ."' WHERE cid = '$id'"); + if ($comment && !field_get($comment->users, $user->id)) { + $result = db_query("UPDATE comments SET score = score $vote, votes = votes + 1, users = '". field_set($comment->users, $user->id, $vote) ."' WHERE cid = '$id'"); } } } @@ -52,7 +52,7 @@ function comment_form($edit) { global $REQUEST_URI, $user; // name field: - $form .= form_item(t("Your name"), format_username($user->userid, $user->name)); + $form .= form_item(t("Your name"), format_name($user->name)); // subject field: $form .= form_textfield(t("Subject"), "subject", $edit[subject], 50, 64); @@ -79,8 +79,8 @@ function comment_reply($pid, $id) { global $theme; 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'")); - 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")); + $item = db_fetch_object(db_query("SELECT c.*, u.name FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.cid = '$pid'")); + comment_view(new Comment($item->name, $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 { node_view(node_get_object(array("nid" => $id))); @@ -99,7 +99,7 @@ function comment_preview($edit) { global $REQUEST_URI, $theme, $user; // Preview comment: - comment_view(new Comment($user->userid, check_preview($edit[subject]), check_preview($edit[comment]), time(), check_preview($user->url), check_preview($user->fake_email), 0, 0, 0, 0), t("reply to this comment")); + comment_view(new Comment($user->name, check_preview($edit[subject]), check_preview($edit[comment]), time(), check_preview($user->url), check_preview($user->fake_email), 0, 0, 0, 0), t("reply to this comment")); $theme->box(t("Reply"), comment_form($edit)); } @@ -125,7 +125,7 @@ function comment_post($edit) { watchdog("special", "comment: added '$edit[subject]'"); // add comment to database: - db_query("INSERT INTO comments (lid, pid, author, subject, comment, hostname, timestamp, score) VALUES ('". check_input($edit[id]) ."', '". check_input($edit[pid]) ."', '$user->id', '". check_input($edit[subject]) ."', '". check_input($edit[comment]) ."', '". getenv("REMOTE_ADDR") ."', '". time() ."', '". ($user->userid ? 1 : 0) ."')"); + db_query("INSERT INTO comments (lid, pid, author, subject, comment, hostname, timestamp, score) VALUES ('". check_input($edit[id]) ."', '". check_input($edit[pid]) ."', '$user->id', '". check_input($edit[subject]) ."', '". check_input($edit[comment]) ."', '". getenv("REMOTE_ADDR") ."', '". time() ."', '". ($user->name ? 1 : 0) ."')"); // clear cache: cache_clear(); @@ -150,7 +150,7 @@ function comment_moderation($comment) { // preview comment: $output .= " "; } - else if ($user->id && $user->userid != $comment->userid && !field_get($comment->users, $user->userid)) { + else if ($user->id && $user->name != $comment->name && !field_get($comment->users, $user->id)) { // 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"; @@ -216,7 +216,7 @@ function comment_view($comment, $folded = 0) { // 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, $comment->name) ." <SMALL>($comment->score)</SMALL><P>"; + else print "<A HREF=\"". comment_uri("id=$comment->lid&cid=$comment->cid#$comment->cid") ."\">". check_output($comment->subject) ."</A> by ". format_name($comment->name) ." <SMALL>($comment->score)</SMALL><P>"; } function comment_thread_min($cid, $threshold) { @@ -235,14 +235,33 @@ function comment_thread_min($cid, $threshold) { function comment_thread_max($cid, $mode, $threshold, $level = 0, $dummy = 0) { global $user; + /* + ** We had quite a few browser specific issues with expanded comments below + ** the top level getting truncated on the right hand side. A range of + ** solutions have been suggested and tried but either the right margins of + ** the comments didn't line up as well, or the heavily nested tables made + ** for slow rendering and cluttered HTML. This is the best work-around in + ** terms of speed and size. + */ + $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"); + if ($level > 1) { + print "</td></tr></table>\n"; + } + + print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td width=\"". ($level * 25) ."\"> </td><td>\n"; + while ($comment = db_fetch_object($result)) { - print "<table width=100%><tr><td><ul>"; comment_view($comment, (comment_visible($comment, $threshold) ? comment_links($comment, 0) : 0)); + // print "comment at level $level\n"; comment_thread_max($comment->cid, $mode, $threshold, $level + 1, $dummy + 1); - print "</ul></td></tr></table>"; } + + if ($level < 2) { + print "</td></tr></table>\n"; + } + } function comment_render($lid, $cid) { @@ -278,7 +297,7 @@ function comment_render($lid, $cid) { print " <TR><TH>Subject</TH><TH>Author</TH><TH>Date</TH><TH>Score</TH></TR>\n"; while ($comment = db_fetch_object($result)) { if (comment_visible($comment, $threshold)) { - print " <TR><TD><A HREF=\"". comment_uri("id=$comment->lid&cid=$comment->cid#$comment->cid") ."\">". check_output($comment->subject) ."</A></TD><TD>". format_username($comment->userid, $comment->name) ."</TD><TD>". format_date($comment->timestamp, "small") ."</TD><TD>". comment_score($comment) ."</TD></TR>\n"; + print " <TR><TD><A HREF=\"". comment_uri("id=$comment->lid&cid=$comment->cid#$comment->cid") ."\">". check_output($comment->subject) ."</A></TD><TD>". format_name($comment->name) ."</TD><TD>". format_date($comment->timestamp, "small") ."</TD><TD>". comment_score($comment) ."</TD></TR>\n"; } } print "</TABLE>\n"; diff --git a/includes/common.inc b/includes/common.inc index a46ae405b..d347cc64f 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -204,9 +204,17 @@ function format_date($timestamp, $type = "medium", $format = "") { return $date; } -function format_username($username, $realname="") { - if ($username) return (user_access("administer users") ? "<A HREF=\"admin.php?mod=account&op=view&name=". urlencode($username) ."\">". check_output($realname ? $realname : $username) ."</A>" : "<A HREF=\"account.php?op=view&name=". urlencode($username) ."\">". check_output($realname ? $realname : $username) ."</A>"); - else return variable_get(anonymous, "Anonymous"); +function format_name($username, $realname = "") { + if ($realname) { + watchdog("special", "format_name - FIX ME"); + return "<font color=\"red\">FIX ME</font>\n"; + } + else if ($username) { + return (user_access("administer users") ? "<a href=\"admin.php?mod=account&op=view&name=". urlencode($username) ."\">". $username ."</a>" : "<a href=\"account.php?op=view&name=". urlencode($username) ."\">$username</a>"); + } + else { + return variable_get(anonymous, "Anonymous"); + } } function format_email($address) { diff --git a/includes/node.inc b/includes/node.inc index de8b36f19..70a0472af 100644 --- a/includes/node.inc +++ b/includes/node.inc @@ -16,7 +16,7 @@ function _node_get($conditions) { } if ($type) { - return db_query("SELECT n.*, l.*, u.userid, u.name FROM node n LEFT JOIN $type l ON n.lid = l.lid AND n.nid = l.nid LEFT JOIN users u ON n.author = u.id WHERE $where ORDER BY n.timestamp DESC"); + return db_query("SELECT n.*, l.*, u.name FROM node n LEFT JOIN $type l ON n.lid = l.lid AND n.nid = l.nid LEFT JOIN users u ON n.author = u.id WHERE $where ORDER BY n.timestamp DESC"); } } diff --git a/includes/search.inc b/includes/search.inc index 5be56fb48..8e74cd4f7 100644 --- a/includes/search.inc +++ b/includes/search.inc @@ -14,7 +14,7 @@ function search_data($keys, $type) { foreach ($result as $entry) { $output .= "<p>\n"; $output .= " <b><u><a href=\"$entry[link]\" />$entry[title]</a></u></b><br />"; - $output .= " <small>$entry[link]". ($entry[user] ? " - ". format_username($entry[user], $entry[name]) : "") ."". ($entry[date] ? " - ". format_date($entry[date], "small") : "") ."</small>"; + $output .= " <small>$entry[link]". ($entry[user] ? " - ". format_name($entry[user], $entry[name]) : "") ."". ($entry[date] ? " - ". format_date($entry[date], "small") : "") ."</small>"; $output .= "</p>\n"; } } diff --git a/includes/theme.inc b/includes/theme.inc index 6950e9712..1ff536d18 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -8,7 +8,7 @@ class BaseTheme { function image($name) { return "misc/$name"; } - + function comment_controls($threshold = 1, $mode = 3, $order = 1) { global $REQUEST_URI, $user; $output .= "<DIV ALIGN=\"CENTER\">\n"; @@ -67,7 +67,7 @@ function theme_account($region, $theme) { $content .= "<a href=\"account.php?op=logout\">". t("logout") ."</a>\n"; $content .= "</td></tr></table>\n"; - $theme->box($user->userid, $content, $region); + $theme->box($user->name, $content, $region); } else { $output .= "<div align=\"center\">\n"; @@ -109,7 +109,8 @@ function theme_moderation_results($theme, $node, $region) { foreach (explode(",", $node->users) as $vote) { if ($vote) { $data = explode("=", $vote); - $output .= format_username($data[0]) ." voted '$data[1]'.<br />"; + $account = user_get($data[0]); + $output .= format_name($account->name) ." voted '$data[1]'.<br />"; } } diff --git a/includes/user.inc b/includes/user.inc index 721ccfd25..c6fc7249c 100644 --- a/includes/user.inc +++ b/includes/user.inc @@ -3,7 +3,7 @@ class User { function User($userid, $passwd = 0) { if ($passwd) { - $result = db_query("SELECT u.*, r.perm FROM users u LEFT JOIN role r ON u.role = r.name WHERE LOWER(userid) = LOWER('$userid') && passwd = PASSWORD('$passwd') AND status = 2"); + $result = db_query("SELECT u.*, r.perm FROM users u LEFT JOIN role r ON u.role = r.name WHERE (LOWER(u.userid) = LOWER('$userid') OR LOWER(u.name) = LOWER('$userid')) AND u.passwd = PASSWORD('$passwd') AND u.status = 2"); if (db_num_rows($result) == 1) { foreach (db_fetch_row($result) as $key=>$value) { $field = mysql_field_name($result, $key); $this->$field = stripslashes($value); $this->field[] = $field; } db_query("UPDATE users SET last_access = '". time() ."', last_host = '$GLOBALS[REMOTE_ADDR]' WHERE id = $this->id"); @@ -19,6 +19,10 @@ class User { } } +function user_get($uid) { + return db_fetch_object(db_query("SELECT * FROM users WHERE id = '". check_output($uid) ."'")); +} + function user_init() { global $db_name; session_name($db_name); @@ -49,7 +53,7 @@ function user_save($account, $array) { else db_query("INSERT INTO users SET $query last_access = '". time() ."', last_host = '$GLOBALS[REMOTE_ADDR]'"); // return account: - return user_load(($account->userid ? $account->userid : $array[userid])); + return user_load($array[userid] ? $array[userid] : $account->userid); } function user_access($perm) { @@ -92,20 +96,4 @@ function user_validate_mail($mail) { if (!eregi("^[_+\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$", $mail)) return t("the e-mail address '$email' is not valid."); } -function user_validate($user) { - // Verify username: - if ($error = user_validate_name($user[userid])) return $error; - - // Verify e-mail address: - if ($error = user_validate_mail($user[real_email])) return $error; - - // Check to see whether the username or e-mail address are banned: - if ($ban = user_ban($user[userid], "username")) return t("the username '$user[userid]' is banned") .": <I>$ban->reason</I>."; - if ($ban = user_ban($user[real_email], "e-mail address")) return t("the e-mail address '$user[real_email]' is banned") .": <I>$ban->reason</I>."; - - // 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) return t("the username '$user[userid]' is already taken."); - if (db_num_rows(db_query("SELECT real_email FROM users WHERE LOWER(real_email) = LOWER('$user[real_email]')")) > 0) return t("the e-mail address '$user[real_email]' is already in use by another account."); -} - ?>
\ No newline at end of file |