comment.module 3.43 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 $PHP_SELF;
Dries's avatar
 
Dries committed
5
  $result = db_query("SELECT c.*, u.name FROM comments c LEFT JOIN user u ON c.author = u.uid 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" => (strstr($PHP_SELF, "admin.php") ? "admin.php?mod=comment&op=edit&id=$comment->cid" : "node.php?id=$comment->lid&cid=$comment->cid"), "user" => $comment->name, "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
function comment_perm() {
Dries's avatar
 
Dries committed
13 14 15 16 17 18 19 20 21
  return array("access comments", "post comments", "administer comments");
}

function comment_link($type) {
  if ($type == "admin" and user_access("administer comments")) {
    $links[] = "<a href=\"admin.php?mod=comment\">comments</a>";
  }

  return $links ? $links : array();
Dries's avatar
 
Dries committed
22 23
}

Dries's avatar
 
Dries committed
24
function comment_edit($id) {
Dries's avatar
 
Dries committed
25

Dries's avatar
 
Dries committed
26
  $result = db_query("SELECT c.*, u.name, u.uid FROM comments c LEFT JOIN user u ON c.author = u.uid WHERE c.cid = '$id'");
Dries's avatar
 
Dries committed
27 28
  $comment = db_fetch_object($result);

Dries's avatar
 
Dries committed
29
  $form .= form_item(t("Author"), format_name($comment));
Dries's avatar
 
Dries committed
30 31
  $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
32
  $form .= form_submit(t("Submit"));
Dries's avatar
 
Dries committed
33

Dries's avatar
 
Dries committed
34
  return form($form);
Dries's avatar
 
Dries committed
35 36
}

Dries's avatar
 
Dries committed
37 38
function comment_save($id, $edit) {
  db_query("UPDATE comments SET subject = '". check_input($edit[subject]) ."', comment = '". check_input($edit[comment]) ."' WHERE cid = '$id'");
Dries's avatar
Dries committed
39
  watchdog("special", "comment: modified '$edit[subject]'");
Dries's avatar
 
Dries committed
40 41
}

Dries's avatar
 
Dries committed
42
function comment_overview() {
Dries's avatar
 
Dries committed
43
  $result = db_query("SELECT c.*, u.name, u.uid FROM comments c LEFT JOIN user u ON u.uid = c.author ORDER BY timestamp DESC LIMIT 50");
Dries's avatar
 
Dries committed
44

Dries's avatar
 
Dries committed
45
  $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
Dries's avatar
 
Dries committed
46
  $output .= " <TR><TH>subject</TH><TH>author</TH><TH>date</TH><TH COLSPAN=\"2\">operations</TH></TR>\n";
Dries's avatar
 
Dries committed
47
  while ($comment = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
48
    $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_name($comment) ."</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
49 50
  }
  $output .= "</TABLE>\n";
Dries's avatar
 
Dries committed
51

Dries's avatar
 
Dries committed
52
  return $output;
Dries's avatar
 
Dries committed
53 54
}

Dries's avatar
 
Dries committed
55 56
function comment_delete($id) {
  db_query("DELETE FROM comments WHERE cid = '$id'");
Dries's avatar
 
Dries committed
57
  db_query("DELETE FROM moderate WHERE cid = '$id'");
Dries's avatar
 
Dries committed
58 59 60
  watchdog("special", "comment: deleted '$id'");
}

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

Dries's avatar
 
Dries committed
64
  if (user_access("administer comments")) {
Dries's avatar
 
Dries committed
65

Dries's avatar
 
Dries committed
66 67 68 69 70 71 72 73 74 75
    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;
Dries's avatar
 
Dries committed
76 77 78 79
      case "delete":
        print comment_delete(check_input($id));
        print comment_overview();
        break;
Dries's avatar
 
Dries committed
80 81 82 83 84 85 86 87 88 89
      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
90 91 92 93
  }
}

?>