comment.module 2.99 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, "edit user comments") ? "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

Dries's avatar
 
Dries committed
12 13 14 15
function comment_perm() {
  return array("view comments", "post comments", "edit comments");
}

Dries's avatar
 
Dries committed
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(t("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 $user, $op, $id, $edit, $mod, $keys, $order;
Dries's avatar
 
Dries committed
50

Dries's avatar
 
Dries committed
51
  if (user_access($user, "edit comments")) {
Dries's avatar
 
Dries committed
52

Dries's avatar
 
Dries committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
    print "<SMALL><A HREF=\"admin.php?mod=comment\">overview</A> | <A HREF=\"admin.php?mod=comment&op=search\">search comment</A></SMALL><HR>\n";

    switch ($op) {
      case "edit":
        print comment_edit($id);
        break;
      case "search":
        print search_form($keys);
        print search_data($keys, $mod);
        break;
      case t("Submit"):
        print status(comment_save(check_input($id), $edit));
        print comment_overview();
        break;
      default:
        print comment_overview();
    }
  }
  else {
    print message_access();
Dries's avatar
 
Dries committed
73 74 75 76
  }
}

?>