• Welcome to Simple Machines Community Forum. Please login or sign up.
September 28, 2021, 01:18:42 PM

News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord


<Next Page> tag on messages with multiple pages

Started by c5Quad, December 09, 2007, 08:22:49 PM

Previous topic - Next topic

Arantor

Had it made a difference that would be more odd.

Is that the only change you've made to constructPageIndex?
No good deed goes unpunished
All helpful urges should be circumvented

Antechinus

Yup. Complete function is now as follows:

// Constructs a page list.
// $pageindex = constructPageIndex($scripturl . '?board=' . $board, $_REQUEST['start'], $num_messages, $maxindex, true);
function constructPageIndex($base_url, &$start, $max_value, $num_per_page, $flexible_start = false)
{
global $modSettings, $txt;

// Save whether $start was less than 0 or not.
$start_invalid = $start < 0;

// Make sure $start is a proper variable - not less than 0.
if ($start_invalid)
$start = 0;
// Not greater than the upper bound.
elseif ($start >= $max_value)
$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
// And it has to be a multiple of $num_per_page!
else
$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));

// Wireless will need the protocol on the URL somewhere.
if (WIRELESS)
$base_url .= ';' . WIRELESS_PROTOCOL;

$base_link = '<a class="navPages" href="' . ($flexible_start ? $base_url : strtr($base_url, array('%' => '%%')) . ';start=%d') . '">%s</a> ';

// Compact pages is off or on?
if (empty($modSettings['compactTopicPagesEnable']))
{
// Show the left arrow.
$pageindex = $start == 0 ? ' ' : sprintf($base_link, $start - $num_per_page, '«');

// Show all the pages.
$display_page = 1;
for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
$pageindex .= $start == $counter && !$start_invalid ? '<b>' . $display_page++ . '</b> ' : sprintf($base_link, $counter, $display_page++);

// Show the right arrow.
$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
if ($start != $counter - $max_value && !$start_invalid)
$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, '»');
}
else
{
// If they didn't enter an odd value, pretend they did.
$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;

$pageindex = '';

// Show 'Prev'
if ($start >= $num_per_page)
$pageindex .= sprintf($base_link, $start - $num_per_page, '<span class="nextprev">', $txt['pi_prev'],'</span>');

// Show the first page. (>1< ... 6 7 [8] 9 10 ... 15)
if ($start > $num_per_page * $PageContiguous)
$pageindex .= sprintf($base_link, 0, '1');
else
$pageindex .= '';

// Show the ... after the first page.  (1 >...< 6 7 [8] 9 10 ... 15)
if ($start > $num_per_page * ($PageContiguous + 1))
$pageindex .= '<b> ... </b>';

// Show the pages before the current one. (1 ... >6 7< [8] 9 10 ... 15)
for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
if ($start >= $num_per_page * $nCont)
{
$tmpStart = $start - $num_per_page * $nCont;
$pageindex.= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
}

// Show the current page. (1 ... 6 7 >[8]< 9 10 ... 15)
if (!$start_invalid)
$pageindex .= '[<b>' . ($start / $num_per_page + 1) . '</b>] ';
else
$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);

// Show the pages after the current one... (1 ... 6 7 [8] >9 10< ... 15)
$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
if ($start + $num_per_page * $nCont <= $tmpMaxPages)
{
$tmpStart = $start + $num_per_page * $nCont;
$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
}

// Show the '...' part near the end. (1 ... 6 7 [8] 9 10 >...< 15)
if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
$pageindex .= '<b> ... </b>';

// Show the last number in the list. (1 ... 6 7 [8] 9 10 ... >15<)
if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);

// Show 'Next'.
$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
if (($display_page <= $tmpMaxPages)&&($tmpMaxPages > 1))
$pageindex .= sprintf($base_link, $display_page, '<span class="nextprev">',$txt['pi_next'],'</span>');

}

return $pageindex;
}

Arantor

I see absolutely no reason why that shouldn't work. At that point the language files should be loaded :S
No good deed goes unpunished
All helpful urges should be circumvented

Antechinus

rofl. Finally got it. Wrong syntax. Instead of  ' , $txt['pi_prev'] , '  it has to be ' . $txt['pi_prev'] . '

That works. ;D

Antechinus

Ok I think this while thing is solved now. All it needs is a nice little xml file or two.

Arantor

AH, that makes sense. Subtle one that.

Good to know it's sorted.
No good deed goes unpunished
All helpful urges should be circumvented

Antechinus

Thanks for your help. I'll zip the thing up and blow up my test site. ;)

Antechinus

Hey got an improvement for that code for the relative links up in head. When there was no previous page, only a next page, no link tag was inserted at all into the header tag. This sorts it out really well:

  if (!empty($context['links']['next']))
    echo '<link rel="next" href="', $context['links']['next'], '" />';
  else if (!empty($context['current_topic']))
    echo '<link rel="next" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=next" />';
  if (!empty($context['links']['prev']))
    echo '<link rel="prev" href="', $context['links']['prev'], '" />';
  else if (!empty($context['current_topic']))
    echo '<link rel="prev" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=prev" />';


That covers all bases. It will go to the next or previous page even if one of those is missing, and it will also take you to the next or previous topics when you run out of pages in the current topic. Best of both worlds.  :)

Arantor

Awesome :)

Yeah, I didn't think about that case.
No good deed goes unpunished
All helpful urges should be circumvented

spritzer

Antechinus did you get any further with this (did it work on your test site)?

I've just converted our large forum over from phpbb, and the only complaint so far is the inability to goto next/previous page, so wouldn't mind giving it a go.


Antechinus

I never made it into a mod (been too busy with other things) but the code works perfectly.

spritzer


Advertisement: