- /**
- * Function that handles the ajax response when user clicks a reply button.
- */
- function modern_comments_reply($node, $pid = NULL) {
- if ($node === FALSE) {
- return MENU_NOT_FOUND;
- }
- if (!user_access('post comments') || !user_access('access comments')) {
- return MENU_ACCESS_DENIED;
- }
- // If there is a pid this is a reply to a comment.
- if ($pid) {
- // Make sure the comment is valid and published.
- if (!($comments = comment_load_multiple(array($pid), array('status' => COMMENT_PUBLISHED)))) {
- return MENU_NOT_FOUND;
- }
- $comment = $comments[$pid];
- // Make sure the comment belongs to this node.
- if ($comment->nid != $node->nid) {
- return MENU_NOT_FOUND;
- }
- }
- // Build form.
- $obj = (object) array('nid' => $node->nid);
- if($pid) $obj->pid = $pid;
- $form_build = drupal_get_form("comment_node_{$node->type}_form", $obj);
- $form = drupal_render($form_build);
- $commands[] = ajax_command_remove("#comments form.comment-form");
- if ($pid) {
- $commands[] = ajax_command_append("#comment-id-{$comment->cid}", $form);
- }
- else {
- $commands[] = ajax_command_after("#comment-add-section", $form);
- $commands[] = ajax_command_invoke(NULL, 'scrolltoel', array('#comment-add-section'));
- }
- // This is to remove the "Your comment has been posted" status message that
- // will appear upon refresh. This seems dirty but it means we don't have to
- // rewrite the whole comment_form_submit(). Please chime in if you think this
- // is dumb.
- modern_comments_remove_status($_SESSION);
- return array('#type' => 'ajax', '#commands' => $commands);
- }