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 18
  global $REQUEST_URI;

Dries's avatar
 
Dries committed
19
  $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
20 21
  $comment = db_fetch_object($result);

Dries's avatar
 
Dries committed
22 23 24
  $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
25
  $form .= form_submit("Submit");
Dries's avatar
 
Dries committed
26

Dries's avatar
 
Dries committed
27
  return form($REQUEST_URI, $form);
Dries's avatar
 
Dries committed
28 29
}

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

Dries's avatar
 
Dries committed
35
function comment_overview() {
Dries's avatar
 
Dries committed
36
  $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
37

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

Dries's avatar
 
Dries committed
45
  return $output;
Dries's avatar
 
Dries committed
46 47 48
}

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

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

?>