| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
function comment_reply($node, $pid = NULL) {
|
| 31 |
|
| 32 |
drupal_set_breadcrumb(array(l(t('Home'), NULL), l($node->title, 'node/' . $node->nid)));
|
| 33 |
$op = isset($_POST['op']) ? $_POST['op'] : '';
|
| 34 |
$build = array();
|
| 35 |
|
| 36 |
if (user_access('access comments')) {
|
| 37 |
|
| 38 |
if ($op == t('Preview')) {
|
| 39 |
if (user_access('post comments')) {
|
| 40 |
$build['comment_form'] = drupal_get_form('comment_form', (object) array('pid' => $pid, 'nid' => $node->nid));
|
| 41 |
}
|
| 42 |
|
| 43 |
drupal_set_message(t('You are not authorized to post comments.'), 'error');
|
| 44 |
drupal_goto("node/$node->nid");
|
| 45 |
|
| 46 |
}
|
| 47 |
|
| 48 |
|
| 49 |
if ($pid) {
|
| 50 |
|
| 51 |
$comment = db_query('SELECT c.*, u.uid, u.name AS registered_name, u.signature, u.picture, u.data FROM {comment} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = :cid AND c.status = :status', array(
|
| 52 |
':cid' => $pid,
|
| 53 |
':status' => COMMENT_PUBLISHED,
|
| 54 |
))->fetchObject();
|
| 55 |
if ( $comment ) {
|
| 56 |
|
| 57 |
|
| 58 |
if ($comment->nid != $node->nid) {
|
| 59 |
|
| 60 |
drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
|
| 61 |
drupal_goto("node/$node->nid");
|
| 62 |
}
|
| 63 |
|
| 64 |
$comment = drupal_unpack($comment);
|
| 65 |
$comment->node_type = 'comment_node_' . $node->type;
|
| 66 |
field_attach_load('comment', array($comment->cid => $comment));
|
| 67 |
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
|
| 68 |
$build['comment_parent'] = comment_build($comment);
|
| 69 |
}
|
| 70 |
|
| 71 |
drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
|
| 72 |
drupal_goto("node/$node->nid");
|
| 73 |
|
| 74 |
}
|
| 75 |
|
| 76 |
elseif (user_access('access content')) {
|
| 77 |
$build['comment_node'] = node_build($node);
|
| 78 |
}
|
| 79 |
|
| 80 |
|
| 81 |
if ($node->comment != COMMENT_NODE_OPEN) {
|
| 82 |
drupal_set_message(t("This discussion is closed: you can't post new comments."), 'error');
|
| 83 |
drupal_goto("node/$node->nid");
|
| 84 |
}
|
| 85 |
elseif (user_access('post comments')) {
|
| 86 |
$edit = array('nid' => $node->nid, 'pid' => $pid);
|
| 87 |
$build['comment_form'] = drupal_get_form('comment_form', (object) $edit);
|
| 88 |
}
|
| 89 |
|
| 90 |
drupal_set_message(t('You are not authorized to post comments.'), 'error');
|
| 91 |
drupal_goto("node/$node->nid");
|
| 92 |
|
| 93 |
|
| 94 |
}
|
| 95 |
|
| 96 |
drupal_set_message(t('You are not authorized to view comments.'), 'error');
|
| 97 |
drupal_goto("node/$node->nid");
|
| 98 |
|
| 99 |
|
| 100 |
return $build;
|
| 101 |
}
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
function comment_approve($cid) {
|
| 109 |
|
| 110 |
if ($comment = comment_load($cid)) {
|
| 111 |
$comment->status = COMMENT_PUBLISHED;
|
| 112 |
$comment->comment_format = $comment->format;
|
| 113 |
comment_save($comment);
|
| 114 |
|
| 115 |
drupal_set_message(t('Comment approved.'));
|
| 116 |
drupal_goto('node/' . $comment->nid);
|
| 117 |
}
|
| 118 |
|
| 119 |
drupal_set_message(t('The comment you are approving does not exist.'), 'error');
|
| 120 |
drupal_goto();
|
| 121 |
|
| 122 |
}
|
| 123 |
|