In nodes that have several pages of comments, token [comment-link] is only correct for the first page of comments.
The token is formed as www.site.com/node/nodeid#comment-commentID
Whereas it should be www.site.com/node/nodeid?page=pageid#comment-commentID
Here pageid=0 for the first page of comments, =1 for the second, etc.

Comments

jaydub’s picture

I believe that it won't be easy to sort that out in the Drupal 5 version given that this issue: #6162: #new links don't work on paged threads was only just fixed in Drupal 6.

If you backport the patch in that issue to your Drupal 5 then perhaps it would be resolvable.

jaydub’s picture

I will test to see if this is an issue on 6.x but for 5.x it will end up being a won't fix since the issue mentioned in #1 wasn't fixed until the 6.x release of Drupal.

jaydub’s picture

Issue tags: +activity-6.x-1-0-rc1

tagging

jaydub’s picture

Assigned: Unassigned » jaydub
jaydub’s picture

I'm thinking that this won't be possible. From my searching I can't find a core method to take a given comment cid and get a page number returned. There is a method for getting page numbers when finding the first new comment but that doesn't help here. Am I missing some magic bullet here?

sirkitree’s picture

There was some weirdness with caching these and such which I totally re-wrote yesterday for the next version. Here's what I came up with instead, maybe this will help out.

/**
 * Token module integration. Defines available default tokens.
 */
function comment_activity_token_list($type = 'all') {
  if ($type == 'comment') {
    $tokens['comment'] = array(
      'parent-id'			=> t('The Id of the parent'),
      'parent-type'   => t('The type of parent (comment/node)'),
      'parent-title'		=> t('The subject of the parent comment'),
      'parent-link'			=> t('Link to the parent comment'),
      'parent-author-uid' 	=> t('User Id of the person who authored the parent of this comment'),
      'parent-author-name' 		=> t('Username of the person who authored the parent of this comment'),

      'parent-node-id'  			=> t('The Id of the parent node'),
      'parent-node-type' 			=> t('The type of the parent node'),
      'parent-node-title'  			=> t('Title of the parent node'),
      'parent-node-link'  			=> t('Link to the parent node'),
      'parent-node-author-uid' 		=> t('User Id of the person who authored the parent node'),
      'parent-node-author-name'		=> t('The username of the person who authored the parent node'),

      'comment-cid'					=> t('The Id of the comment'),
      'comment-title' 			=> t('The subject of the comment'),
      'comment-link'				=> t('Link to the comment'),
    );
    return $tokens;
  }
}

/**
 * Token module integration. Defines available default token values.
 */
function comment_activity_token_values($type, $comment = NULL, $options = array()) {
  if ($type == 'comment' && !empty($comment)) {
    // parent data could be node or comment. if a pid exists the parent is a comment.
    if ($comment->pid) {
      // parent is a comment
      $data['parent-id'] = $comment->pid;
      $data['parent-type'] = 'comment';
      $data['parent-title'] = db_result(db_query('SELECT subject FROM {comments} WHERE cid = %d', $comment->cid));
      $data['parent-link'] = l($data['parent-title'], 'node/'. $comment->nid, array('fragment' => 'comment-'. $comment->cid));
      $data['parent-author-uid'] = $comment->uid;
      $data['parent-author-name'] = $comment->author;
    }
    else {
      // parent is a node
      $data['parent-id'] = $data['parent-node-id'] = $comment->nid;
      $data['parent-type'] = 'node';
      $data['parent-node-type'] = theme('activity_node_type', db_result(db_query('SELECT type FROM {node} WHERE nid = %d', $comment->nid)));
      $data['parent-title'] = $data['parent-node-title'] = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $comment->nid));
      $data['parent-link'] = $data['parent-node-link'] = l($data['parent-title'], 'node/'. $comment->nid);
      $data['parent-author-uid'] = $data['parent-node-author-uid'] = db_result(db_query('SELECT uid FROM {node} WHERE nid = %d', $comment->nid));
      $data['parent-author-name'] = $data['parent-node-author-name'] = db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $data['parent-node-author-uid']));
    }

    //comment data
    $data['comment-cid'] = $comment->cid;
    $data['comment-title'] = $comment->subject;
    $data['comment-link'] = l($data['comment-title'], 'node/'. $comment->nid, array('fragment' => 'comment-'. $comment->cid));
  }  
  return $data;
}
jaydub’s picture

The link to the comment in your example code still doesn't address the page number issue. A comment to a node or to another comment may be on a page other than the first page depending on the number of comments per page setting, the sort order of comments as well as whether comments are flat or threaded.

So the comment-link would need a 'page' query value. Finding out what the page value is though is the problem and it's a tough one. I don't see an easy way to do this given that it's not even in core comment.module.

dicreat’s picture

subscribe

Scott Reynolds’s picture

Version: 5.x-4.x-dev » 6.x-2.x-dev

This is only doable in 6 and beyond

http://api.drupal.org/api/function/comment_new_page_count/6

Takes the node and returns the page.

Working on this now for Activity2.

Scott Reynolds’s picture

Version: 6.x-2.x-dev » 6.x-1.x-dev
Status: Active » Patch (to be ported)
StatusFileSize
new1.24 KB

heres the patch i committed

http://drupal.org/cvs?commit=281408

Scott Reynolds’s picture

A related technique for maybe D5 sites? http://drupal.org/node/604098#comment-2206414

Scott Reynolds’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
Status: Patch (to be ported) » Needs work

hmm ok so its trickier then that. It won't always work. In D7 this is fixed by creating a 'comment/CID' path that sets up the right page for the node_view. I think we can still backport that patch, Gabor might be on board.

Scott Reynolds’s picture

Scott Reynolds’s picture

StatusFileSize
new919 bytes

if you apply the patch in #26966: Fix comment links when paging is used. and this patch for 6.2 comments across multiple pages will work properly.

sirkitree’s picture

Status: Needs work » Fixed

Committed.

Status: Fixed » Closed (fixed)
Issue tags: -activity-6.x-1-0-rc1

Automatically closed -- issue fixed for 2 weeks with no activity.