1.20.x comment.module comment_permalink($cid)

Redirects comment links to the correct page depending on comment settings.

Since comments are paged there is no way to guarantee which page a comment appears on. Comment paging and threading settings may be changed at any time. With threaded comments, an individual comment may move between pages as comments can be added either before or after it in the overall discussion. Therefore we use a central routing function for comment links, which calculates the page number based on current comment settings and returns the full comment view with the pager set dynamically.

Parameters

$cid: A comment identifier.

Return value

The comment listing set to the page on which the comment appears.:

File

modules/comment/comment.module, line 494
Enables users to comment on published content.

Code

function comment_permalink($cid) {
  if (($comment = comment_load($cid)) && ($node = node_load($comment->nid))) {

    // Find the current display page for this comment.
    $page = comment_get_display_page($comment->cid, $node->type);

    // Set $_GET['q'] and $_GET['page'] ourselves so that the node callback
    // behaves as it would when visiting the page directly.
    $_GET['q'] = 'node/' . $node->nid;
    $_GET['page'] = $page;

    // Return the node view, this will show the correct comment in context.
    return menu_execute_active_handler('node/' . $node->nid, FALSE, 'menu_default_route_handler');
  }
  return MENU_NOT_FOUND;
}