comment.module 3.99 KB
Newer Older
Dries Buytaert's avatar
   
Dries Buytaert committed
1
<?php
Dries Buytaert's avatar
 
Dries Buytaert committed
2

Dries Buytaert's avatar
   
Dries Buytaert committed
3
4
5
6
$module = array("find" => "comment_find",
                "admin" => "comment_admin");

function comment_find($keys) {
Dries Buytaert's avatar
   
Dries Buytaert committed
7
  global $user;
Dries Buytaert's avatar
   
Dries Buytaert committed
8
  $find = array();
Dries Buytaert's avatar
   
Dries Buytaert committed
9
  $result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.subject LIKE '%$keys%' OR c.comment LIKE '%$keys%' ORDER BY c.timestamp DESC LIMIT 20");
Dries Buytaert's avatar
   
Dries Buytaert committed
10
  while ($comment = db_fetch_object($result)) {
Dries Buytaert's avatar
   
Dries Buytaert committed
11
    array_push($find, array("title" => check_output($comment->subject), "link" => (user_access($user, "comment") ? "admin.php?mod=comment&op=edit&id=$comment->cid" : "node.php?id=$comment->lid&cid=$comment->cid"), "user" => $story->userid, "date" => $comment->timestamp));
Dries Buytaert's avatar
   
Dries Buytaert committed
12
13
14
  }
  return $find;
}
Dries Buytaert's avatar
 
Dries Buytaert committed
15

Dries Buytaert's avatar
   
Dries Buytaert committed
16
17
function comment_search() {
  global $keys, $mod;
Dries Buytaert's avatar
   
Dries Buytaert committed
18
19
  print search_form($keys);
  print search_data($keys, $mod);
Dries Buytaert's avatar
   
Dries Buytaert committed
20
21
}

Dries Buytaert's avatar
 
Dries Buytaert committed
22
function comment_edit($id) {
Dries Buytaert's avatar
   
Dries Buytaert committed
23
  $result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.cid = '$id'");
Dries Buytaert's avatar
 
Dries Buytaert committed
24
25
26
27
28

  $comment = db_fetch_object($result);

  $output .= "<FORM ACTION=\"admin.php?mod=comment&op=save&id=$id\" METHOD=\"post\">\n";

29
30
  $output .= "<B>Author:</B><BR>\n";
  $output .= format_username($comment->userid) ."<P>\n";
Dries Buytaert's avatar
 
Dries Buytaert committed
31

32
33
  $output .= "<B>Subject:</B><BR>\n";
  $output .= "<INPUT TYPE=\"text\" NAME=\"subject\" SIZE=\"50\" VALUE=\"". check_textfield($comment->subject) ."\"><P>\n";
Dries Buytaert's avatar
 
Dries Buytaert committed
34
35

  $output .= "<B>Comment:</B><BR>\n";
36
  $output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"comment\">". check_textarea($comment->comment) ."</TEXTAREA><P>\n";
Dries Buytaert's avatar
 
Dries Buytaert committed
37

38
  $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Save comment\">\n";
Dries Buytaert's avatar
 
Dries Buytaert committed
39
  $output .= "</FORM>\n";
Dries Buytaert's avatar
   
Dries Buytaert committed
40

Dries Buytaert's avatar
 
Dries Buytaert committed
41
42
43
44
  print $output;
}

function comment_save($id, $subject, $comment) {
Dries Buytaert's avatar
   
Dries Buytaert committed
45
  db_query("UPDATE comments SET subject = '$subject', comment = '$comment' WHERE cid = '$id'");
46
  watchdog("message", "comment: modified '$subject'");
Dries Buytaert's avatar
 
Dries Buytaert committed
47
48
49
50
51
52
53
54
}

function comment_display($order = "date") {
  // Initialize variables:
  $fields = array("author" => "author", "date" => "timestamp DESC", "subject" => "subject");

  // Perform SQL query:
  $result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON u.id = c.author ORDER BY c.$fields[$order] LIMIT 50");
Dries Buytaert's avatar
   
Dries Buytaert committed
55

Dries Buytaert's avatar
 
Dries Buytaert committed
56
  // Display comments:
Dries Buytaert's avatar
   
Dries Buytaert committed
57
  $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
Dries Buytaert's avatar
 
Dries Buytaert committed
58
  $output .= " <TR>\n";
Dries Buytaert's avatar
   
Dries Buytaert committed
59
  $output .= "  <TH ALIGN=\"right\" COLSPAN=\"3\">\n";
Dries Buytaert's avatar
 
Dries Buytaert committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  $output .= "   <FORM ACTION=\"admin.php?mod=comment\" METHOD=\"post\">\n";
  $output .= "    <SELECT NAME=\"order\">\n";
  foreach ($fields as $key=>$value) {
    $output .= "     <OPTION VALUE=\"$key\"". ($key == $order ? " SELECTED" : "") .">Sort by $key</OPTION>\n";
  }
  $output .= "    </SELECT>\n";
  $output .= "    <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Update\">\n";
  $output .= "   </FORM>\n";
  $output .= "  </TH>\n";
  $output .= " </TR>\n";

  $output .= " <TR>\n";
  $output .= "  <TH>subject</TH>\n";
  $output .= "  <TH>author</TH>\n";
  $output .= "  <TH>operations</TH>\n";
  $output .= " </TR>\n";

  while ($comment = db_fetch_object($result)) {
Dries Buytaert's avatar
   
Dries Buytaert committed
78
    $output .= " <TR><TD>". ($comment->link == "story" ? "<A HREF=\"node.php?id=$comment->lid&cid=$comment->cid&pid=$comment->pid#$comment->cid\">". check_output($comment->subject) ."</A>" : check_output($comment->subject)) ."</TD><TD>". format_username($comment->userid) ."</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=comment&op=edit&id=$comment->cid\">edit</A></TD></TR>\n";
Dries Buytaert's avatar
 
Dries Buytaert committed
79
80
81
  }

  $output .= "</TABLE>\n";
Dries Buytaert's avatar
   
Dries Buytaert committed
82

Dries Buytaert's avatar
 
Dries Buytaert committed
83
84
85
86
87
88
  print $output;
}

function comment_admin() {
  global $op, $id, $subject, $comment, $order;

Dries Buytaert's avatar
   
Dries Buytaert committed
89
90
  print "<SMALL><A HREF=\"admin.php?mod=comment\">overview</A> | <A HREF=\"admin.php?mod=comment&op=search\">search comment</A></SMALL><HR>\n";

Dries Buytaert's avatar
 
Dries Buytaert committed
91
92
93
94
  switch ($op) {
    case "edit":
      comment_edit($id);
      break;
Dries Buytaert's avatar
   
Dries Buytaert committed
95
96
97
    case "search":
      comment_search();
      break;
Dries Buytaert's avatar
 
Dries Buytaert committed
98
    case "Save comment":
Dries Buytaert's avatar
   
Dries Buytaert committed
99
      comment_save(check_input($id), check_input($subject), check_input($comment));
100
      comment_display();
Dries Buytaert's avatar
 
Dries Buytaert committed
101
102
      break;
    case "Update":
Dries Buytaert's avatar
   
Dries Buytaert committed
103
      comment_display(check_input($order));
Dries Buytaert's avatar
 
Dries Buytaert committed
104
105
106
107
108
109
110
      break;
    default:
      comment_display();
  }
}

?>