diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/comment.inc | 14 | ||||
-rw-r--r-- | includes/common.inc | 37 | ||||
-rw-r--r-- | includes/theme.inc | 14 | ||||
-rw-r--r-- | includes/user.inc | 39 |
4 files changed, 51 insertions, 53 deletions
diff --git a/includes/comment.inc b/includes/comment.inc index 51aad93f1..57f2bf62e 100644 --- a/includes/comment.inc +++ b/includes/comment.inc @@ -31,12 +31,12 @@ function comment_moderate($moderate) { $none = $comment_votes[key($comment_votes)]; foreach ($moderate as $id=>$vote) { - if ($vote != $comment_votes[$none] && !user_get($user, "history", "c$id")) { - // update the comment's score: - $result = db_query("UPDATE comments SET score = score ". check_input($vote) .", votes = votes + 1 WHERE cid = '". check_input($id) ."'"); - - // update the user's history: - $user = user_set($user, "history", "c$id", $vote); + if ($vote != $comment_votes[$none]) { + $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'"); + } } } } @@ -162,7 +162,7 @@ function comment_moderation($comment) { // preview comment: $output .= " "; } - else if ($user->id && $user->userid != $comment->userid && !user_get($user, "history", "c$comment->cid")) { + else if ($user->id && $user->userid != $comment->userid && !field_get($comment, "users", $user->userid)) { // 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"; diff --git a/includes/common.inc b/includes/common.inc index 0a24fc927..5ca31bf36 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -199,6 +199,43 @@ function form_submit($value) { return "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". check_textfield($value) ."\">\n"; } +function field_get($object, $variable, $field) { + $data = explode(";", $object->$variable); + for (reset($data); current($data); next($data)) { + $entry = explode(":", current($data)); + if (reset($entry) == $field) $rval = end($entry); + } + return $rval; +} + +function field_set($object, $variable, $name, $value) { + $field = $object->$variable; + + if (!$value) { + // remove entry: + $data = explode(";", $field); + for (reset($data); current($data); next($data)) { + $entry = explode(":", current($data)); + if ($entry[0] != $name) $rval .= "$entry[0]:$entry[1];"; + } + } + else if (strstr($field, "$name:")) { + // found: update exsisting entry: + $data = explode(";", $field); + for (reset($data); current($data); next($data)) { + $entry = explode(":", current($data)); + if ($entry[0] == $name) $entry[1] = $value; + $rval .= "$entry[0]:$entry[1];"; + } + } + else { + // not found: + $rval = "$field$name:$value;"; + } + + return $rval; +} + $conf = conf_init(); include_once "includes/$conf.php"; diff --git a/includes/theme.inc b/includes/theme.inc index 2be12b414..269a5da2e 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -102,16 +102,14 @@ function theme_morelink($theme, $node) { } function theme_moderation_results($theme, $node) { - global $user; - - if ($user->id && $node->nid && ($user->id == $node->author || user_get($user, "history", "n$node->nid"))) { - $result = db_query("SELECT * FROM users WHERE history LIKE '%n$node->nid%'"); - while ($account = db_fetch_object($result)) { - $output .= format_username($account->userid) ." voted '". user_get($account, "history", "n$node->nid") ."'.<BR>"; + foreach (explode(";", $node->users) as $vote) { + if ($vote) { + $data = explode(":", $vote); + $output .= format_username($data[0]) ." voted '$data[1]'.<BR>"; } - - $theme->box(t("Moderation results"), ($output ? $output : t("This node has not been moderated yet."))); } + + $theme->box(t("Moderation results"), ($output ? $output : t("This node has not been moderated yet."))); } /* diff --git a/includes/user.inc b/includes/user.inc index 02038cf9b..74254dc2b 100644 --- a/includes/user.inc +++ b/includes/user.inc @@ -52,46 +52,9 @@ function user_save($account, $array) { return user_load(($account->userid ? $account->userid : $array[userid])); } -function user_get($account, $column, $field) { - $data = explode(";", $account->$column); - for (reset($data); current($data); next($data)) { - $entry = explode(":", current($data)); - if (reset($entry) == $field) $rval = end($entry); - } - return $rval; -} - -function user_set($account, $column, $name, $value) { - $field = $account->$column; - - if (!$value) { - // remove entry: - $data = explode(";", $field); - for (reset($data); current($data); next($data)) { - $entry = explode(":", current($data)); - if ($entry[0] != $name) $rval .= "$entry[0]:$entry[1];"; - } - } - else if (strstr($field, "$name:")) { - // found: update exsisting entry: - $data = explode(";", $field); - for (reset($data); current($data); next($data)) { - $entry = explode(":", current($data)); - if ($entry[0] == $name) $entry[1] = $value; - $rval .= "$entry[0]:$entry[1];"; - } - } - else { - // not found: - $rval = "$field$name:$value;"; - } - - return user_save($account, array($column => $rval)); -} - function user_access($account, $section = 0) { global $user; - if ($section) return (user_get($account, "access", $section) || $account->id == 1); + if ($section) return (field_get($account, "access", $section) || $account->id == 1); else return ($account->access || $account->id == 1); } |