diff options
Diffstat (limited to 'modules/comment/comment.module')
-rw-r--r-- | modules/comment/comment.module | 94 |
1 files changed, 36 insertions, 58 deletions
diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 78d35c039..4a737557d 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -1,5 +1,4 @@ <?php -// $Id$ /** * @file @@ -495,6 +494,7 @@ function comment_permalink($cid) { * * @param integer $number * (optional) The maximum number of comments to find. Defaults to 10. + * * @return * An array of comment objects or an empty array if there are no recent * comments visible to the current user. @@ -502,15 +502,12 @@ function comment_permalink($cid) { function comment_get_recent($number = 10) { $query = db_select('comment', 'c'); $query->innerJoin('node', 'n', 'n.nid = c.nid'); - $query->innerJoin('node_comment_statistics', 'ncs', 'ncs.nid = c.nid'); $query->addTag('node_access'); $comments = $query ->fields('c') - ->condition('ncs.comment_count', 0, '>') ->condition('c.status', COMMENT_PUBLISHED) ->condition('n.status', NODE_PUBLISHED) - ->orderBy('ncs.last_comment_timestamp', 'DESC') - ->orderBy('c.cid', 'DESC') + ->orderBy('c.created', 'DESC') ->range(0, $number) ->execute() ->fetchAll(); @@ -989,8 +986,8 @@ function comment_build_content($comment, $node, $view_mode = 'full', $langcode = $comment->content = array(); // Build fields content. - field_attach_prepare_view('comment', array($comment->cid => $comment), $view_mode); - entity_prepare_view('comment', array($comment->cid => $comment)); + field_attach_prepare_view('comment', array($comment->cid => $comment), $view_mode, $langcode); + entity_prepare_view('comment', array($comment->cid => $comment), $langcode); $comment->content += field_attach_view('comment', $comment, $view_mode, $langcode); $comment->content['links'] = array( @@ -1092,8 +1089,8 @@ function comment_links($comment, $node) { * An array in the format expected by drupal_render(). */ function comment_view_multiple($comments, $node, $view_mode = 'full', $weight = 0, $langcode = NULL) { - field_attach_prepare_view('comment', $comments, $view_mode); - entity_prepare_view('comment', $comments); + field_attach_prepare_view('comment', $comments, $view_mode, $langcode); + entity_prepare_view('comment', $comments, $langcode); $build = array( '#sorted' => TRUE, @@ -1406,15 +1403,15 @@ function comment_user_delete($account) { } /** - * This is *not* a hook_access() implementation. This function is called - * to determine whether the current user has access to a particular comment. + * Determines whether the current user has access to a particular comment. * * Authenticated users can edit their comments as long they have not been - * replied to. This prevents people from changing or revising their - * statements based on the replies to their posts. + * replied to. This prevents people from changing or revising their statements + * based on the replies to their posts. * * @param $op - * The operation that is to be performed on the comment. Only 'edit' is recognized now. + * The operation that is to be performed on the comment. Only 'edit' is + * recognized now. * @param $comment * The comment object. * @return @@ -1468,28 +1465,15 @@ function comment_save($comment) { module_invoke_all('entity_presave', $comment, 'comment'); if ($comment->cid) { - // Update the comment in the database. - db_update('comment') - ->fields(array( - 'status' => $comment->status, - 'created' => $comment->created, - 'changed' => $comment->changed, - 'subject' => $comment->subject, - 'uid' => $comment->uid, - 'name' => $comment->name, - 'mail' => $comment->mail, - 'homepage' => $comment->homepage, - 'language' => $comment->language, - )) - ->condition('cid', $comment->cid) - ->execute(); + + drupal_write_record('comment', $comment, 'cid'); // Ignore slave server temporarily to give time for the // saved comment to be propagated to the slave. db_ignore_slave(); // Update the {node_comment_statistics} table prior to executing hooks. - _comment_update_node_statistics($comment->nid); + _comment_update_node_statistics($comment->nid); field_attach_update('comment', $comment); // Allow modules to respond to the updating of a comment. @@ -1554,23 +1538,16 @@ function comment_save($comment) { $comment->name = $user->name; } - $comment->cid = db_insert('comment') - ->fields(array( - 'nid' => $comment->nid, - 'pid' => empty($comment->pid) ? 0 : $comment->pid, - 'uid' => $comment->uid, - 'subject' => $comment->subject, - 'hostname' => ip_address(), - 'created' => $comment->created, - 'changed' => $comment->changed, - 'status' => $comment->status, - 'thread' => $thread, - 'name' => $comment->name, - 'mail' => $comment->mail, - 'homepage' => $comment->homepage, - 'language' => $comment->language, - )) - ->execute(); + // Ensure the parent id (pid) has a value set. + if (empty($comment->pid)) { + $comment->pid = 0; + } + + // Add the values which aren't passed into the function. + $comment->thread = $thread; + $comment->hostname = ip_address(); + + drupal_write_record('comment', $comment); // Ignore slave server temporarily to give time for the // created comment to be propagated to the slave. @@ -1929,11 +1906,9 @@ function comment_form($form, &$form_state, $comment) { '#default_value' => $author, '#maxlength' => 60, '#size' => 30, + '#description' => t('Leave blank for %anonymous.', array('%anonymous' => variable_get('anonymous', t('Anonymous')))), + '#autocomplete_path' => 'user/autocomplete', ); - // If the comment is by a registered user, allow to autocomplete username. - if ($comment->registered_name != '') { - $form['author']['name']['#autocomplete_path'] = 'user/autocomplete'; - } } elseif ($user->uid) { $form['author']['_author'] = array( @@ -2114,18 +2089,21 @@ function comment_form_validate($form, &$form_state) { entity_form_field_validate('comment', $form, $form_state); if (!empty($form_state['values']['cid'])) { + // Verify the name in case it is being changed from being anonymous. + $account = user_load_by_name($form_state['values']['name']); + $form_state['values']['uid'] = $account ? $account->uid : 0; + if ($form_state['values']['date'] && strtotime($form_state['values']['date']) === FALSE) { form_set_error('date', t('You have to specify a valid date.')); } - if ($form_state['values']['name'] && !$form_state['values']['is_anonymous'] && !$account = user_load_by_name($form_state['values']['name'])) { + if ($form_state['values']['name'] && !$form_state['values']['is_anonymous'] && !$account) { form_set_error('name', t('You have to specify a valid author.')); } } - - // Validate anonymous comment author fields (if given). - if ($form_state['values']['is_anonymous']) { - // If the (original) author of this comment was an anonymous user, verify - // that no registered user with this name exists. + elseif ($form_state['values']['is_anonymous']) { + // Validate anonymous comment author fields (if given). If the (original) + // author of this comment was an anonymous user, verify that no registered + // user with this name exists. if ($form_state['values']['name']) { $query = db_select('users', 'u'); $query->addField('u', 'uid', 'uid'); @@ -2216,7 +2194,7 @@ function comment_form_submit($form, &$form_state) { $comment = comment_form_submit_build_comment($form, $form_state); if (user_access('post comments') && (user_access('administer comments') || $node->comment == COMMENT_NODE_OPEN)) { // Save the anonymous user information to a cookie for reuse. - if (!$comment->uid) { + if (user_is_anonymous()) { user_cookie_save(array_intersect_key($form_state['values'], array_flip(array('name', 'mail', 'homepage')))); } |