94 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			Plaintext
		
	
	
			
		
		
	
	
			94 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			Plaintext
		
	
	
<?php
 | 
						|
// $Id$
 | 
						|
 | 
						|
function comment_search($keys) {
 | 
						|
  global $PHP_SELF;
 | 
						|
  $result = db_query("SELECT c.*, u.name FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.subject LIKE '%$keys%' OR c.comment LIKE '%$keys%' ORDER BY c.timestamp DESC LIMIT 20");
 | 
						|
  while ($comment = db_fetch_object($result)) {
 | 
						|
    $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);
 | 
						|
  }
 | 
						|
  return $find;
 | 
						|
}
 | 
						|
 | 
						|
function comment_perm() {
 | 
						|
  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();
 | 
						|
}
 | 
						|
 | 
						|
function comment_edit($id) {
 | 
						|
 | 
						|
  $result = db_query("SELECT c.*, u.name, u.uid FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.cid = '$id'");
 | 
						|
  $comment = db_fetch_object($result);
 | 
						|
 | 
						|
  $form .= form_item(t("Author"), format_name($comment));
 | 
						|
  $form .= form_textfield(t("Subject"), "subject", $comment->subject, 50, 128);
 | 
						|
  $form .= form_textarea(t("Comment"), "comment", $comment->comment, 50, 10);
 | 
						|
  $form .= form_submit(t("Submit"));
 | 
						|
 | 
						|
  return form($form);
 | 
						|
}
 | 
						|
 | 
						|
function comment_save($id, $edit) {
 | 
						|
  db_query("UPDATE comments SET subject = '". check_input($edit[subject]) ."', comment = '". check_input($edit[comment]) ."' WHERE cid = '$id'");
 | 
						|
  watchdog("special", "comment: modified '$edit[subject]'");
 | 
						|
}
 | 
						|
 | 
						|
function comment_overview() {
 | 
						|
  $result = db_query("SELECT c.*, u.name, u.uid FROM comments c LEFT JOIN users u ON u.uid = c.uid ORDER BY timestamp DESC LIMIT 50");
 | 
						|
 | 
						|
  $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
 | 
						|
  $output .= " <TR><TH>subject</TH><TH>author</TH><TH>date</TH><TH COLSPAN=\"2\">operations</TH></TR>\n";
 | 
						|
  while ($comment = db_fetch_object($result)) {
 | 
						|
    $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";
 | 
						|
  }
 | 
						|
  $output .= "</TABLE>\n";
 | 
						|
 | 
						|
  return $output;
 | 
						|
}
 | 
						|
 | 
						|
function comment_delete($id) {
 | 
						|
  db_query("DELETE FROM comments WHERE cid = '$id'");
 | 
						|
  db_query("DELETE FROM moderate WHERE cid = '$id'");
 | 
						|
  watchdog("special", "comment: deleted '$id'");
 | 
						|
}
 | 
						|
 | 
						|
function comment_admin() {
 | 
						|
  global $op, $id, $edit, $mod, $keys, $order;
 | 
						|
 | 
						|
  if (user_access("administer comments")) {
 | 
						|
 | 
						|
    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_type("comment", "admin.php?mod=comment&op=search");
 | 
						|
        break;
 | 
						|
      case "delete":
 | 
						|
        print comment_delete(check_input($id));
 | 
						|
        print comment_overview();
 | 
						|
        break;
 | 
						|
      case t("Submit"):
 | 
						|
        print status(comment_save(check_input($id), $edit));
 | 
						|
        print comment_overview();
 | 
						|
        break;
 | 
						|
      default:
 | 
						|
        print comment_overview();
 | 
						|
    }
 | 
						|
  }
 | 
						|
  else {
 | 
						|
    print message_access();
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
?>
 |