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

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

function comment_find($keys) {
Dries's avatar
 
Dries committed
7
  global $user;
Dries's avatar
 
Dries committed
8
  $find = array();
Dries's avatar
 
Dries 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's avatar
 
Dries committed
10
  while ($comment = db_fetch_object($result)) {
Dries's avatar
 
Dries 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" => $comment->userid, "date" => $comment->timestamp));
Dries's avatar
 
Dries committed
12 13 14
  }
  return $find;
}
Dries's avatar
 
Dries committed
15 16

function comment_edit($id) {
Dries's avatar
 
Dries committed
17
  $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
18 19
  $comment = db_fetch_object($result);

Dries's avatar
 
Dries committed
20 21 22 23
  $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);
  $form .= form_submit("Save comment");
Dries's avatar
 
Dries committed
24

Dries's avatar
 
Dries committed
25
  return form("admin.php?mod=comment&id=$id", $form);
Dries's avatar
 
Dries committed
26 27
}

Dries's avatar
 
Dries committed
28 29 30
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
31 32
}

Dries's avatar
 
Dries committed
33 34
function comment_display() {
  $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
35

Dries's avatar
 
Dries committed
36
  $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
Dries's avatar
 
Dries committed
37
  $output .= " <TR><TH>subject</TH><TH>author</TH><TH>date</TH><TH COLSPAN=\"2\">operations</TH></TR>\n";
Dries's avatar
 
Dries committed
38
  while ($comment = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
39
    $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
40 41
  }
  $output .= "</TABLE>\n";
Dries's avatar
 
Dries committed
42

Dries's avatar
 
Dries committed
43
  return $output;
Dries's avatar
 
Dries committed
44 45 46
}

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

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

?>