diff options
author | Dries Buytaert <dries@buytaert.net> | 2001-05-17 19:14:50 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2001-05-17 19:14:50 +0000 |
commit | 6c387962199f3b57aff1df4bc0c79ded4935f2a1 (patch) | |
tree | 7e547ce9e8455c8154ec722b8c1c0da26999945d | |
parent | e2f051b3854a72e2c7f1af1506f7c3eed6504891 (diff) | |
download | brdo-6c387962199f3b57aff1df4bc0c79ded4935f2a1.tar.gz brdo-6c387962199f3b57aff1df4bc0c79ded4935f2a1.tar.bz2 |
- Fixed bug in account.module.
- Simplified field_set() API.
- Made UnConeD's cool common timestamp format conform with the
general coding style. Sorry to be so picky about this but I
really can't help it. ;)
-rw-r--r-- | includes/comment.inc | 4 | ||||
-rw-r--r-- | includes/common.inc | 30 | ||||
-rw-r--r-- | modules/account.module | 30 | ||||
-rw-r--r-- | modules/queue.module | 2 |
4 files changed, 40 insertions, 26 deletions
diff --git a/includes/comment.inc b/includes/comment.inc index 57f2bf62e..0f7d31ccf 100644 --- a/includes/comment.inc +++ b/includes/comment.inc @@ -35,7 +35,7 @@ function comment_moderate($moderate) { $id = check_input($id); $vote = check_input($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'"); + $result = db_query("UPDATE comments SET score = score $vote, votes = votes + 1, users = '". field_set($comment->users, $user->userid, $vote) ."' WHERE cid = '$id'"); } } } @@ -337,4 +337,4 @@ function comment_render($lid, $cid) { } } -?>
\ No newline at end of file +?> diff --git a/includes/common.inc b/includes/common.inc index 44a353fbb..1c5ea330b 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -97,9 +97,9 @@ function format_plural($count, $singular, $plural) { } function format_interval($timestamp) { - $units = array("year|years"=>31536000, "week|weeks"=>604800, "day|days"=>86400, "hour|hours"=>3600, "min|min"=>60, "sec|sec"=>1); + $units = array("year|years" => 31536000, "week|weeks" => 604800, "day|days" => 86400, "hour|hours" => 3600, "min|min" => 60, "sec|sec" => 1); foreach ($units as $key=>$value) { - $key=explode("|", $key); + $key = explode("|", $key); if ($timestamp >= $value) { $output .= ($output ? " " : "") . format_plural(floor($timestamp / $value), $key[0], $key[1]); $timestamp %= $value; @@ -124,12 +124,16 @@ function format_date($timestamp, $type = "medium", $format = "") { $date = t(date("l", $timestamp)) .", ". t(date("F", $timestamp)) ." ". date("d, Y - H:i", $timestamp); break; case "custom": - for ($i=strlen($format);$i>=0;$c=$format[--$i]) { - if (strstr("DFlMSw",$c)) - $date=t(date($c,$timestamp)).$date; - else if (strstr("AaBdgGhHiIjLmnrstTUYyZz",$c)) - $date=date($c,$timestamp).$date; - else $date=$c.$date; + for ($i = strlen($format); $i >= 0; $c = $format[--$i]) { + if (strstr("DFlMSw", $c)) { + $date=t(date($c, $timestamp)).$date; + } + else if (strstr("AaBdgGhHiIjLmnrstTUYyZz", $c)) { + $date = date($c, $timestamp).$date; + } + else { + $date = $c.$date; + } } break; default: @@ -169,8 +173,8 @@ function format_text($text) { return preg_replace($src, $dst, $text); } -function form($action, $form, $method = "post", $options="") { - return "<FORM ACTION=\"$action\" METHOD=\"$method\"". (!empty($options) ? " $options" : "") .">\n$form</FORM>\n"; +function form($action, $form, $method = "post", $options = 0) { + return "<FORM ACTION=\"$action\" METHOD=\"$method\"". ($options ? " $options" : "") .">\n$form</FORM>\n"; } function form_item($title, $value, $description = 0) { @@ -211,9 +215,7 @@ function field_get($object, $variable, $field) { return $rval; } -function field_set($object, $variable, $name, $value) { - $field = $object->$variable; - +function field_set($field, $name, $value) { if (!$value) { // remove entry: $data = explode(";", $field); @@ -272,4 +274,4 @@ $theme = theme_init(); // set error handler: set_error_handler("error_handler"); -?>
\ No newline at end of file +?> diff --git a/modules/account.module b/modules/account.module index 28faf1fe3..22f3a43f5 100644 --- a/modules/account.module +++ b/modules/account.module @@ -138,9 +138,20 @@ function account_delete($name) { } function account_edit_save($name, $edit) { - foreach ($edit as $key=>$value) if ($key != "access") $query .= "$key = '". addslashes($value) ."', "; + foreach ($edit as $key=>$value) { + if ($key != "access") { + $query .= "$key = '". addslashes($value) ."', "; + } + } db_query("UPDATE users SET $query access = '' WHERE userid = '$name'"); - if ($edit[access]) foreach ($edit[access] as $key=>$value) db_query("UPDATE users SET access = '". field_set(user_load($name), "access", $value, 1) ."'"); + + if ($edit[access]) { + foreach ($edit[access] as $key=>$value) { + $account = user_load($name); + db_query("UPDATE users SET access = '". field_set($account->access, $value, 1) ."' WHERE id = $account->id"); + } + } + watchdog("message", "account: modified user '$name'"); } @@ -169,7 +180,7 @@ function account_edit($name) { $form .= form_textfield(t("Homepage"), "url", $account->url, 30, 55); $form .= form_textarea(t("Bio"), "bio", $account->bio, 35, 5); $form .= form_textarea(t("Signature"), "signature", $account->signature, 35, 5); - $form .= form_hidden("userid", $account->userid); + $form .= form_hidden("name", $account->userid); $form .= form_submit("View account"); $form .= form_submit("Save account"); @@ -183,7 +194,7 @@ function account_view($name) { $result = db_query("SELECT * FROM users WHERE userid = '$name'"); if ($account = db_fetch_object($result)) { - $form .= form_hidden("userid", $account->userid); + $form .= form_hidden("name", $account->userid); $form .= form_submit("Edit account"); $form .= form_submit("Delete account"); @@ -222,7 +233,8 @@ function account_admin() { print "<SMALL><A HREF=\"admin.php?mod=account&op=access\">access control</A> | <A HREF=\"admin.php?mod=account&op=listing\">account listings</A> | <A HREF=\"admin.php?mod=account&op=search\">search account</A> | <A HREF=\"admin.php?mod=account\">overview</A> | <A HREF=\"admin.php?mod=account&op=help\">help</A></SMALL><HR>"; - $type = ($type ? $type : 0); + $type = $type ? $type : 0; + $name = $name ? $name : $edit[name]; switch ($op) { case "access": @@ -241,12 +253,12 @@ function account_admin() { print account_ac(); break; case "Delete account": - print status(account_delete($edit[userid])); + print status(account_delete($name)); print account_overview(account_query($type)); break; case "Edit account": case "edit": - print account_edit(check_input($name)); + print account_edit($name); break; case "help": print account_help(); @@ -259,8 +271,8 @@ function account_admin() { print search_data($keys, $mod); break; case "Save account": - print status(account_edit_save(check_input($edit[userid]), $edit)); - print account_view(check_input($edit[userid])); + print status(account_edit_save($name, $edit)); + print account_view($name); break; case "View account": case "view": diff --git a/modules/queue.module b/modules/queue.module index 25daef56f..d5844bfde 100644 --- a/modules/queue.module +++ b/modules/queue.module @@ -23,7 +23,7 @@ function queue_vote($id, $vote) { if (!field_get($node, "users", $user->userid)) { // Update submission's score- and votes-field: - db_query("UPDATE node SET score = score $vote, votes = votes + 1, users = '". field_set($node, "users", $user->userid, $vote) ."' WHERE nid = $id"); + db_query("UPDATE node SET score = score $vote, votes = votes + 1, users = '". field_set($node->users, $user->userid, $vote) ."' WHERE nid = $id"); if (variable_get("post_threshold", 4, $node) <= $node->score) { node_save(array(nid => $id, status => $status[posted]), array(status)); |