I've recently migrated a phpbb2 forum to drupal. Some of the migrated users are not happy because of these two issues:

1. They want a pager (page listing like next back etc) to also appear on the top of the forum (or node if I can't specialize).
2. After they post a reply, they need to be redirected to the last page of that node, not the first one.

I don't mind hacking core if I have to.

Also, if anyone knows off the top of their head how I can stop injecting the signature into the comments text area, that would be great.

Thanks for the help!

Comments

Doomd’s picture

Has anyone had any success with another module like actions or path to go for redirecting people that post replies to the actual reply (last page) of that node?

And I just need some help knowing where I should add the pager code so it displays on the top of the node as well as on the bottom. Thank you!

Doomd’s picture

I figured out how to place the pager on top of the comments section, but not on top of the entire main content page. But it's a start:

in comment.module in lines 839-859 (drupal 4.7.3)

         //START CUSTOM : ADDED BELOW LINE TO PUT PAGER ABOVE COMMENTS AS WELL AS BELOW THEM
         $output .= theme('pager', NULL, $comments_per_page, 0);
	 //END CUSTOM
      while ($comment = db_fetch_object($result)) {
        $comment = drupal_unpack($comment);
        $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
        $comment->depth = count(explode('.', $comment->thread)) - 1;

        if ($mode == COMMENT_MODE_FLAT_COLLAPSED) {
          $output .= theme('comment_flat_collapsed', $comment);
        }
        else if ($mode == COMMENT_MODE_FLAT_EXPANDED) {
          $output .= theme('comment_flat_expanded', $comment);
        }
        else if ($mode == COMMENT_MODE_THREADED_COLLAPSED) {
          $output .= theme('comment_thread_collapsed', $comment);
        }
        else if ($mode == COMMENT_MODE_THREADED_EXPANDED) {
          $output .= theme('comment_thread_expanded', $comment);
        }
      }

      $output .= theme('pager', NULL, $comments_per_page, 0);

As you can see, I just copied the last output line and pasted it above the while loop.

This is NOT a complete solution. I would like to be able to place the pager at the very top, above the first topic. In fact, I would really like to be able to completely eliminate the first post being repeated on every page.

Doomd’s picture

Ok,

I broke down and decided to use javascript to get the page numbers to display on the top of each node in addition to the bottom.

Here's what I did.

I opened up page.tpl.php from my phptemplate theme box_grey and near the top of the main-content area, I inserted the following:

        <td class="main-content" id="content-<?php print $layout ?>">
		<?php print $breadcrumb ?>
<!-- LOOK BELOW...I ADDED A NEW DIV TAG AND gave it id "top_pager" -->
		<div id="top_pager"></div>
        <?php if ($title != ""): ?>
          <h2 class="content-title"><?php print $title ?></h2>
        <?php endif; ?>
        <?php if ($tabs != ""): ?>
          <?php print $tabs ?>
        <?php endif; ?>

Then at the bottom of the same file I inserted this little bit of javascript:

<div id="footer">
  <?php if ($footer_message) : ?>
    <p><?php print $footer_message;?></p>
  <?php endif; ?>
</div><!-- footer -->
 <?php print $closure;?>
<!-- LOOK BELOW...I ADDED A LITTLE JAVASCRIPT -->
<script language="javascript">
<!--
if (document.getElementById('pager')) {
	var tempHTML = document.getElementById('pager').innerHTML;
	document.getElementById('top_pager').innerHTML = tempHTML;
}
-->
</script>
  </body>
</html>

This javascript very simply checks to see if the pager exists, and if it does gets the contents of the DIV with id "pager" (which is generated automatically at the bottom of your content) and places a copy of that content into variable "tempHTML." Then it simply inserts that tempHTML into our new "top_pager" DIV tag that we created above.

The problem with this method is that the top pager controls won't be visible until the rest of the page loads, and of course, it requires javascript so browswers that have that turned off won't enjoy this feature.

NOTE: You may need to change your css file (drupal.css and/or style.css) to include the new ID "top_pager". Otherwise the #top_pager links won't display the same as the regular #pager links.

sinker’s picture

Hey man, that's totally brilliant. I'm implementing that on my site immediately!

sinker’s picture

... is that new top div, if you add top or bottom margins to it, includes them on the page even if there's no pager to plug in. Damn. I had to pull it out 'cause it was wreaking havoc to my pages--too much space on the top! And to not have margins on the pager (the other option) looks really strange.

aymerick’s picture

And now, see the power of jquery:

drupal_add_js('$(document).ready(function() { $("#top_pager").html($("#comments .pager").html()); });', 'inline');

I use this in the template.php file of my theme.

Dries Arnolds’s picture

This sounds hopefull. How do I use it?

I pasted it in my template.php, but I'm guessing it works in conjunction with one of the above solutions? Can you please explain?

zorroposada’s picture

Here is an update to doubledoh's great solution for the top pager:

In page.tpl.php put <div id="top_pager"></div> above <?php print $content; ?>

Then, in the bottom of the page, put

<script language="javascript">
<!--

document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
};


if (document.getElementsByClassName('pager')) {
var pagerElements = document.getElementsByClassName('pager');
var tempHTML = pagerElements[0].innerHTML;
document.getElementById('top_pager').innerHTML = tempHTML;
}
-->

</script>

That will do the trick

Dries Arnolds’s picture

Wow! Thanks! Works like a charm!

My forum users where waiting for this for a long time.

edit: oops, it's not going well in IE. There's an error:
'pagerElements.0.innerHTML' is null or not an object

Any ideas? I'm not really good at javascript.

ryivhnn’s picture

This won't help you with placing the pager but I took the slack/easier option and let the users choose how many comments they want per page :P

The redirection to the first page instead of the last seems to be a long running problem (there are constant questions about it, but they don't seem to get answered as far as I can tell). I'm really hoping they can change it for 4.8 if they're not going to do it in this run.

works at bekandloz | plays at technonaturalist

rkn-dupe’s picture

Just found this solution - thanks its a step in the right direction - but it wouldbe great to be able to do it without JS as you say at the very top and stop the annoying replicating. Surely the place which needs to be modified is in node.module?

And of course the redirection to last post. I think these are all just basic forum must haves.

rkn-dupe’s picture

I've been told the solution lies in using a hook from the pager function and putting that in template.php and then calling it from the appropriate tpl.php file.

ryivhnn’s picture

That's extremely cryptic when you can't code :P

works at bekandloz | plays at technonaturalist

aaron-h’s picture

I wanted to go to the last page of comments for many different reasons and found a pretty easy fix.

Add this in your template.php file:

/* get the last page number of comments*/
function comment_last_page($nid) {
    $last_page = ceil(comment_num_all($nid) / _comment_get_display_setting('comments_per_page'));
    return ($last_page - 1);  // -1 since pages start at 0
}

Then, in the comment.module, find this section in the function comment_form_submit:

if ($cid = comment_save($form_values)) {
    return array('node/'. $form_values['nid'], null, "comment-$cid");
}

Simply replace the null with "page=".comment_last_page($form_values['nid']) so that it looks like this:

if ($cid = comment_save($form_values)) {
    return array('node/'. $form_values['nid'], "page=".comment_last_page($form_values['nid']), "comment-$cid");
}
rkn-dupe’s picture

Thanks, will give it a go!

zigma’s picture

This is cool. I have also been looking for this feature.

zigma’s picture

I just tried reply hack. It works perfect.

Is there a way to display the last page of a forum topic when use clicks on forum topic link.

yngens’s picture

Thank you, aaron-h! Hack works perfectly to get poster to last page and adjusts screen to the last message. However, in blumarine with flatforum it fails to get the screen to the last message.

I am experimenting with Drupal 5.0, but I guess the problem is not with version of the Drupal, but maybe with flatforum module. My guess is that they did not put target anchors to messages, but don't know how to fix it.

Has anyone had similar problem?

___________
www.akyl.org

rkn-dupe’s picture

Aaron - thats great it works!

rkn-dupe’s picture

Am trying to figure out how to get this function which is edited out of comment.module and into its own module or template.php - anyone done this?

Krotty’s picture

Small fix for template.php

/* get the last page number of comments*/
function comment_last_page($nid) {
    $last_page = ceil(comment_num_all($nid)+1 / _comment_get_display_setting('comments_per_page'));
     //+1 to consider our added comment 
    return ($last_page - 1);  // -1 since pages start at 0
}
Tammamtu’s picture

still you didn't consider how the comment are ordered nor viewed.

I edited the patch to consider the ordering.

function comment_last_page($nid) {
    switch (_comment_get_display_setting('sort')) {
	case 1:
	return ( 0 );
	case 2:
	$last_page = ceil((comment_num_all($nid)+1) / _comment_get_display_setting('comments_per_page'));
    return ($last_page - 1);  // -1 since pages start at 0
		}
}

still it's not working if the user is replying to a comment in the page 2 of 4 pages. it will either redirect him to the first or the last page, but not the second one

anyone can help?!

Tammamtu’s picture

anyone .. !!

sol77’s picture

(subscribing)

Siegetheday.Org

Cross_and_Flame’s picture

n/t

Paul Natsuo Kishimoto’s picture

Hi - I'm not sure if this is possible in 4.7.x, but I managed to do this in Drupal 5.1 without hacking core. I'm using PHPTemplate, and there are ways to override theme functions in template.php. If you look at the entire comment_render() function that you modified, you'll see that the last thing it does is call theme('comment_wrapper', $output).

This theming call will look for hooks like *_comment_render(), or give up and fall back to theme_comment_wrapper() which is also in comment.module. This is a great place to jump in and add an extra pager, because the default function only adds a simple DIV.

I added the following code to my template.php file (here I use the example name was 'mytemplate'):

/**
 * Add a pager at the top of a list of comments.
 */
function mytemplate_comment_wrapper($content) {
  $comments_per_page = _comment_get_display_setting('comments_per_page');
  $content = theme('pager', NULL, $comments_per_page, 0) . $content;
  return theme_comment_wrapper($content);
}

What this does, line-by-line:

  1. Retrieve the number of comments per page, which is needed for the pager. I copied this line directly from near the top of comment_render().
  2. Prepend a pager to the content (which has already been given a pager at the end).
  3. Use the default function from comment.module. to wrap the whole thing in a DIV.

Hope this helps. I've got an unruly crowd that's I'm forcing to migrate from phpBB2 to Drupal, just like you, and they're alse asking for your second point — to be sent to the last page from the list of topics. I'll post again if I can figure that one out.

rkn-dupe’s picture

Paul - that looks great - will try it out.

catch’s picture

Paul Kishimoto - jumping to the last unread post - we've got a working patch for that here:

http://drupal.org/node/6162 (right at the end of the thread).

Also, you should put that code for the pager in the phptemplate templates section of the handbook - will preserve it for future people trying to find this.

Paul Natsuo Kishimoto’s picture

... for the tip, catch! I'm checking out the patch you linked, and I'll probably end up applying it to my site.

The new handbook page is #141381.

nishitdas’s picture

Subscribed

yngens’s picture

thank you, paul!

i don't know if it is related only to my theme, but the problem with your code is that it places a pager not actually on top of the page, but the bottom of the very first message of the forum topic (under node text). can you please explain how i could put a pager above subject of the node page, for example.

pcdonohue’s picture

I managed to place the pager on the top of the forum thread the way I wanted by making my own page-forum.tpl.php file, but I also want to duplicate it at the bottom of the thread. You can read more at http://drupal.org/node/167240

I'm trying to produce the same effect that the terminus1525 forums have (see http://www.terminus1525.ca/node/35825 )

momper’s picture

subscribing

charles_elwood’s picture

Subscribe

smoothdzion’s picture

I found another way and I don't think I saw anyone doing it. It takes advantage of the existing theme. It worked for me and I'm on Drupal 5.7.

print theme('pager')

That inserts the pager exactly where I wanted it with a lot less code. It's just using the built in theming I guess. I'm a designer not a programmer. :)

-

Brandon Buttars
http://www.odindev.com

ryivhnn’s picture

Must be a 5.x thing, I know for a fact you couldn't do it 4.7. Much easier :)

works at bekandloz | plays at technonaturalist

cpiontko’s picture

For other noobs -- put the code from the above comment in the header of the view (page section) to add pager at top (drupal 5)

fehin’s picture

subscribing