/[drupal]/contributions/sandbox/jeremy/4.4.0/kerneltrap/comment.module.patch
ViewVC logotype

Contents of /contributions/sandbox/jeremy/4.4.0/kerneltrap/comment.module.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Sat Mar 27 21:52:24 2004 UTC (5 years, 8 months ago) by jeremy
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-patch
storing patches against core 4.4 code used on http://kerneltrap.org/
1 # This patch is only interesting if you're using comment moderation.
2 #
3 # This patch passes $comment->rating to themes, filling it with the top
4 # voted moderation value. For example, if you have the following vote
5 # matrix:
6 # Off topic
7 # Okay
8 # Funny
9 # Insightful
10 #
11 # Now, saw 3 users have moderated a comment as 'Okay', one as 'Funny',
12 # and two as 'Insightful'. This patch sets $comment->rating to 'Okay',
13 # as it has the most votes...
14 #
15 # To use, modify your theme to display $comment->rating.
16 #
17 # No database changes are needed.
18
19 --- modules/comment.module.orig 2004-03-27 13:51:45.126203520 -0500
20 +++ modules/comment.module 2004-03-27 13:54:49.311724736 -0500
21 @@ -205,6 +205,7 @@ function comment_reply($pid, $nid) {
22 if ($pid) {
23 $comment = db_fetch_object(db_query("SELECT c.*, u.uid, u.name, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0", $pid));
24 $comment = drupal_unpack($comment);
25 + $comment->rating = comment_rating($comment);
26 $output .= theme("comment_view", $comment);
27 }
28 else if (user_access("access content")) {
29 @@ -260,6 +261,7 @@ function comment_preview($edit) {
30 if ($edit["pid"]) {
31 $comment = db_fetch_object(db_query("SELECT c.*, u.uid, u.name, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0", $edit["pid"]));
32 $comment = drupal_unpack($comment);
33 + $comment->rating = comment_rating($comment);
34 $output .= theme("comment_view", $comment);
35 }
36 else {
37 @@ -562,6 +564,7 @@ function comment_render($node, $cid = 0)
38 $result = db_query("SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.data, c.score, c.users FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0 GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.data, c.score, c.users", $cid);
39
40 if ($comment = db_fetch_object($result)) {
41 + $comment->rating = comment_rating($comment);
42 $output .= theme("comment_view", $comment, theme('links', module_invoke_all('link', 'comment', $comment, 1)));
43 }
44
45 @@ -685,6 +688,7 @@ function comment_render($node, $cid = 0)
46 while ($comment = db_fetch_object($result)) {
47 $comment = drupal_unpack($comment);
48 $comment->depth = count(explode(".", $comment->thread)) - 1;
49 + $comment->rating = comment_rating($comment);
50
51 if ($mode == 1) {
52 $output .= theme("comment_flat_collapsed", $comment, $threshold_min);
53 @@ -733,6 +737,39 @@ function comment_render($node, $cid = 0)
54 return $output;
55 }
56
57 +function comment_rating($comment) {
58 + static $votes;
59 +
60 + // determine the top rating for this comment
61 + $ratings = unserialize($comment->users);
62 + if ($ratings) {
63 + $count = array();
64 + // count each of the ratings
65 + foreach ($ratings as $key => $rating) {
66 + // key of 0 is not a vote, so skip
67 + if ($key) {
68 + $count[$rating]++;
69 + }
70 + }
71 + // reverse sort the array so the first entry has the most votes
72 + arsort($count);
73 + // the key is the mid + 1, so we subtract 1
74 + $rating = key($count) - 1;
75 + // build the votes object (or use cached version)
76 + if (!isset($votes)) {
77 + $result = db_query("SELECT vote FROM {moderation_votes} ORDER BY mid");
78 + $votes = array();
79 + while ($vote = db_fetch_object($result)) {
80 + $votes[] = $vote;
81 + }
82 + }
83 + // translate the number to a word
84 + return $votes["$rating"]->vote;
85 + }
86 + // no ratings, return nothing
87 + return;
88 +}
89 +
90 function comment_perm() {
91 return array("access comments", "post comments", "administer comments", "moderate comments", "post comments without approval", "administer moderation");
92 }

  ViewVC Help
Powered by ViewVC 1.1.2