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

Dries's avatar
 
Dries committed
3
function comment_search($keys) {
Dries's avatar
 
Dries committed
4
  global $user;
Dries's avatar
 
Dries committed
5
  $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's avatar
 
Dries committed
6
  while ($comment = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
7
    $find[$i++] = 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" => $comment->userid, "date" => $comment->timestamp);
Dries's avatar
 
Dries committed
8 9 10
  }
  return $find;
}
Dries's avatar
 
Dries committed
11 12

function comment_edit($id) {
Dries's avatar
 
Dries committed
13 14
  global $REQUEST_URI;

Dries's avatar
 
Dries committed
15
  $result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.cid = '$id'");
Dries's avatar
 
Dries committed
16 17
  $comment = db_fetch_object($result);

Dries's avatar
 
Dries committed
18 19 20
  $form .= form_item(t("Author"), format_username($comment->userid));
  $form .= form_textfield(t("Subject"), "subject", $comment->subject, 50, 128);
  $form .= form_textarea(t("Comment"), "comment", $comment->comment, 50, 10);
Dries's avatar
 
Dries committed
21
  $form .= form_submit(t("Submit"));
Dries's avatar
 
Dries committed
22

Dries's avatar
 
Dries committed
23
  return form($REQUEST_URI, $form);
Dries's avatar
 
Dries committed
24 25
}

Dries's avatar
 
Dries committed
26 27 28
function comment_save($id, $edit) {
  db_query("UPDATE comments SET subject = '". check_input($edit[subject]) ."', comment = '". check_input($edit[comment]) ."' WHERE cid = '$id'");
  watchdog("message", "comment: modified '$edit[subject]'");
Dries's avatar
 
Dries committed
29 30
}

Dries's avatar
 
Dries committed
31
function comment_overview() {
Dries's avatar
 
Dries committed
32
  $result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON u.id = c.author ORDER BY timestamp DESC LIMIT 50");
Dries's avatar
 
Dries committed
33

Dries's avatar
 
Dries committed
34
  $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
Dries's avatar
 
Dries committed
35
  $output .= " <TR><TH>subject</TH><TH>author</TH><TH>date</TH><TH COLSPAN=\"2\">operations</TH></TR>\n";
Dries's avatar
 
Dries committed
36
  while ($comment = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
37
    $output .= " <TR><TD><A HREF=\"node.php?id=$comment->lid&cid=$comment->cid&pid=$comment->pid#$comment->cid\">". check_output($comment->subject) ."</A></TD><TD>". format_username($comment->userid) ."</TD><TD>". format_date($comment->timestamp, "small") ."</TD><TD><A HREF=\"admin.php?mod=comment&op=edit&id=$comment->cid\">edit comment</A></TD><TD><A HREF=\"admin.php?mod=comment&op=delete&id=$comment->cid\">delete comment</A></TD></TR>\n";
Dries's avatar
 
Dries committed
38 39
  }
  $output .= "</TABLE>\n";
Dries's avatar
 
Dries committed
40

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

function comment_admin() {
Dries's avatar
 
Dries committed
45
  global $op, $id, $edit, $mod, $keys, $order;
Dries's avatar
 
Dries committed
46

Dries's avatar
 
Dries committed
47 48
  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's avatar
 
Dries committed
49 50
  switch ($op) {
    case "edit":
Dries's avatar
 
Dries committed
51
      print comment_edit($id);
Dries's avatar
 
Dries committed
52
      break;
Dries's avatar
 
Dries committed
53
    case "search":
Dries's avatar
 
Dries committed
54 55
      print search_form($keys);
      print search_data($keys, $mod);
Dries's avatar
 
Dries committed
56
      break;
Dries's avatar
 
Dries committed
57
    case t("Submit"):
Dries's avatar
 
Dries committed
58
      print status(comment_save(check_input($id), $edit));
Dries's avatar
 
Dries committed
59
      print comment_overview();
Dries's avatar
 
Dries committed
60 61
      break;
    default:
Dries's avatar
 
Dries committed
62
      print comment_overview();
Dries's avatar
 
Dries committed
63 64 65 66
  }
}

?>