I did notice that there is integration for the Comment Page module, however I see that that module is no longer being maintained in favor of the Permalink module. So I have some quick little code for optional Permalink integration:


/**
 * This function just translates the permalink directly into the comment link variable,
 * and presupposes that the template file is altered to allow the comment_link in nodes.
 * I set the text for node links in Permalink settings to "#0" to match the comments.
 */
function HOOK_preprocess_node(&$variables) {
  $variables['comment_link'] = $variables['permalink'];
}

/**
 * This function replaces the link in the comment link to comment/$cid, rather than adding
 * a different link under "(permalink)". The latter would be simpler, though, assuming that
 * comment links are set to that text in Permalink settings.
 */
function HOOK_preprocess_comment(&$variables) {
  // Replace comment link with link from permalink module
  if (module_exists('permalink')) {
    static $post_number = 0;
    _advanced_forum_topic_nid($vars['node']->nid);

    $post_per_page = _comment_get_display_setting('comments_per_page', $variables['node']);
    $page_number = ($_GET['page'] ? $_GET['page'] : 0);

    $post_number++;
    $linktext = '#' . (($page_number * $post_per_page) + $post_number);

#### Notice that this is the part that's different from the existing code
    $permalink = permalink_link_render($hook, $vars['comment']);
    $variables['comment_link'] = l($linktext, $permalink['href'], $permalink);
####
  }

  // Alternatively, we just need this if we want the old behavior resulting in '#X (permalink)'
  // $variables['comment_link'] .= ' ' . $variables['permalink']}

That's a standalone solution, but this is what you'd actually add to advanced_forum.module in advanced_forum_preprocess_comment, before the existing Comment Page code:

# ...
  // Replace comment link with link from permalink module
  if (module_exists('permalink')) {
    $permalink = permalink_link_render($hook, $vars['comment']);
    $variables['comment_link'] = l($linktext, $permalink['href'], $permalink);
  }
# ...

That's because the rest of the earlier code is just to get $linktext, which is already defined in the module's preprocess function.

It's not a lot to get it working, but I just figured it would be nice to add to or replace the Comment Page functionality with this.

CommentFileSizeAuthor
#8 advf-permalink.patch737 bytesmeustrus

Comments

michelle’s picture

Version: 6.x-1.1 » 6.x-2.x-dev

Going to bump this one to 2.x. Looks like a good idea but will need to test it before committing.

Michelle

aharown07’s picture

Would love to see this.
Presently I'm adding the $permalink to my post.tpl.php to put a link right beside the post number link. Easier to get folks to use it. But it would be swell to see the $permalink replace the standard one there.
(since this solves the pesky comment pagination issues)

aharown07’s picture

meustrus.... any chance you could turn this to a patch on 6x2 alpha13? I'm wanting to test but having trouble figuring out how to modify advanced_forum.module properly (namely, I don't see advanced_forum_preprocess_comment in there anywhere and don't really know how to code it)

Edit: for others interested in this, a css workaround that involves covering up the comment# with a transparent permalink icon...

In your custom advanced_forum.mytheme.post.tpl.php, add a line to print the permalink...

 <?php if (!$top_post): ?>
      <span class="forum-post-number"><?php print $comment_link . ' ' . $page_link; ?></span>
      <span class="comment-permalink"><?php print $permalink; ?></span> 
    <?php endif; ?>
  </div> <?php // End of post info div ?>

Add a transparent .png file to your theme images folder. In this case, it's clear40x16.png (but the image needs to be wide enough. I ended up going with 40x16... it has to cover up the comment #)

In your theme css file (or wherever you're putting your forum css theming overrides)

.comment-permalink a {
float: right;
background: url(images/clear40x16.png) no-repeat right center;
padding-right: 44px;
color: white;
}
.forum-post-number {
margin-left: -40px;
}

What happens: the permalink link prints next to the comment number. The css places the transparent image beside it--the image is part of the link so it's clickable. The css adjusts margin for the comment number so that it slides behind the transparent .png file. Also, we turn the "permalink" link text into the background color. In this case, white.

Disclaimer: I'm pretty sure this won't work in some older browsers!
(So far, OK in IE7,8 and latest Chrome, Opera & Firefox... may need to tweak css a bit for positioning)

meustrus’s picture

I've taken a look at the 2.x version. The _preprocess_ functions are in individual files in the "advanced_forum/includes" directory. I would make a patch, but I don't know how.

aharown07’s picture

Thanks... I'm using my css workaround for now. But need to test in some more browsers. It's not really the "right" way to do it I suppose.

michelle’s picture

Status: Needs review » Needs work

This discussion has gotten a little crazy... There's no need to go covering things up with images. I'd be happy to add Permalink support but I'm concerned about the lack of activity on that module. I already got burned by Comment Page. Don't want to have that happen again. See #917408: Port Permalink to D7

Michelle

aharown07’s picture

Not sure what the future of Permalink is. As a solution to the comment paging problem it will not be needed in D7... since that seems to be fixed in core (or so I'm told).
My only interest in it is as a way to get comment links to take folks to the comment in question--regardless of what page it's on. (As patched, Permalink does that now, even in Views.)

meustrus’s picture

Status: Needs work » Needs review
StatusFileSize
new737 bytes

I'm not sure why Comment Page fell out of favor...something to do with a security problem that the maintainer didn't want to fix, I gather. I doubt the same thing will happen to Permalink, especially since it has a commercial sponsor. In any case, here's a very simple patch against 6.x-2.x-dev. I would definitely prefer to change the HREF of the link, but this patch makes Permalink perform in the spirit of the Comment Page integration.

michelle’s picture

Status: Needs review » Reviewed & tested by the community

Ok, I've installed Permalink and tried it out and found this patch isn't needed. I just changed the template to use $permalink instead of $page_link and it works without any changes in the preprocess. Unfortunately, it doesn't work with Node Comments so I'll have to note that in the docs.

I don't know what you mean by "I would definitely prefer to change the HREF of the link"

Setting this RTBC for the moment... I can't commit the change until I finish some other changes I'm making.

Michelle

aharown07’s picture

Would the template be post.tpl.php? When I replace $page_link with $permalink there the result is a comment number (non-permalinking) with a permalink next to it.

michelle’s picture

Yeah, the permalink goes next to the comment number. That's how it was with Comment Page. The comment number is really a permalink, too, unless you change the number of comments per page and mess it up. But I don't have a problem adding the Permalink module's link as well if people want it.

Michelle

meustrus’s picture

What I meant by "I would definitely prefer to change the HREF of the link" is that I would rather the comment number link to the permalink, instead of having a separate permalink next to it. And sure, you could change the variable in the template to $permalink, if that's what you'd prefer. This is the code in the patch:

  // Link to redirect create by Permalink module, if it exists
  if (isset($variables['permalink']) {
    $variables['page_link'] = $variables['permalink'];
  }

(which actually looks like there's a syntax error)

This is what I'd rather do, though:

  // Link to redirect create by Permalink module, if it exists
  if (module_exists('permalink')) {
    $permalink = permalink_link_render($hook, $vars['comment']);
    $variables['comment_link'] = l($linktext, $permalink['href'], $permalink);
  }
michelle’s picture

Ah... Hmm... I guess it depends where the permalink links to. Since it doesn't work with Node Comment and my core Comment dev site isn't set up, yet, I haven't been able to test it. With Comment Page, that link took you to a page just for the comment whereas the linked number took you to that comment in the context of the thread. So I'll have to see what Permalink does. Though the question is, if it takes you to the comment within the thread just like the comment # does, what's the point of using it?

Michelle

michelle’s picture

Status: Reviewed & tested by the community » Needs work

Forgot to change the status. This needs some more thought and work.

Michelle

aharown07’s picture

"if it takes you to the comment within the thread just like the comment # does, what's the point of using it?"

The comment # only works consistently if users never change the comments per page setting or if the comment in question is on page one.

michelle’s picture

Ok, got my core comment dev site set up and had a look at what Permalink is doing. It does show the comment in the context of the thread, which is good, but the URL is like example.com/comment/11855#comment-11855 which seems to be a Permalink specific thing. That means that the links are only permanent as long as you have Permalink installed whereas the normal comment link offers a link that is permanent without any other module.

So, personally, I don't see the point of the Permalink module for this but I guess others do or we wouldn't have this issue. Since both methods show the comment in the context of the thread and not as a separate page like Comment Page did, it makes sense to use the Permalink in place of the included link when it's installed.

Michelle

michelle’s picture

The comment # only works consistently if users never change the comments per page setting or if the comment in question is on page one.

Yes, but how often does that happen? Generally you pick a number of comments per page and stick with it. And you'll still end up on the same thread at least even if that happens. With the Permalink module, the links will totally 404 if you decide to remove it at some point.

Michelle

michelle’s picture

Status: Needs work » Fixed

Ok, committed.

Michelle

meustrus’s picture

Just for clarity, it looks like what was committed was the method I preferred, replacing the link with the permalink rather than appending it as was the behavior with Comment Page. It also appears that Comment Page integration code was removed (not like it matters, since its project page has a big "DO NOT USE THIS" disclaimer).

Status: Fixed » Closed (fixed)

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