function paginate($num_pages, $cur_page, $link, $args = null) { global $lang_common; $pages = array(); $link_to_all = false; // If $cur_page == -1, we link to all pages (used in viewforum.php) if ($cur_page == -1) { $cur_page = 1; $link_to_all = true; } if ($num_pages <= 1) { $pages = array('<strong class="item1">1</strong>'); } else { // Add a previous page link if ($num_pages > 1 && $cur_page > 1) { $pages[] = '<a rel="prev"' . (empty($pages) ? ' class="item1"' : '') . ' href="' . get_sublink($link, 'page/$1', $cur_page - 1, $args) . '">' . $lang_common['Previous'] . '</a>'; } if ($cur_page > 3) { $pages[] = '<a' . (empty($pages) ? ' class="item1"' : '') . ' href="' . $link . '">1</a>'; if ($cur_page > 5) { $pages[] = '<span class="spacer">' . $lang_common['Spacer'] . '</span>'; } } // Don't ask me how the following works. It just does, OK? :-) for ($current = $cur_page == 5 ? $cur_page - 3 : $cur_page - 2, $stop = $cur_page + 4 == $num_pages ? $cur_page + 4 : $cur_page + 3; $current < $stop; ++$current) { if ($current < 1 || $current > $num_pages) { continue; } elseif ($current != $cur_page || $link_to_all) { $pages[] = '<a' . (empty($pages) ? ' class="item1"' : '') . ' href="' . str_replace('#', '', get_sublink($link, 'page/$1', $current, $args)) . '">' . forum_number_format($current) . '</a>'; } else { $pages[] = '<strong' . (empty($pages) ? ' class="item1"' : '') . '>' . forum_number_format($current) . '</strong>'; } } if ($cur_page <= $num_pages - 3) { if ($cur_page != $num_pages - 3 && $cur_page != $num_pages - 4) { $pages[] = '<span class="spacer">' . $lang_common['Spacer'] . '</span>'; } $pages[] = '<a' . (empty($pages) ? ' class="item1"' : '') . ' href="' . get_sublink($link, 'page/$1', $num_pages, $args) . '">' . forum_number_format($num_pages) . '</a>'; } // Add a next page link if ($num_pages > 1 && !$link_to_all && $cur_page < $num_pages) { $pages[] = '<a rel="next"' . (empty($pages) ? ' class="item1"' : '') . ' href="' . get_sublink($link, 'page/$1', $cur_page + 1, $args) . '">' . $lang_common['Next'] . '</a>'; } } return implode(' ', $pages); }
function paginate($num_pages, $cur_page, $link, $args = null) { global $lang_common, $panther_config, $panther_url; $pages = array(); $link_to_all = false; // If $cur_page == -1, we link to all pages (used in viewforum.php) if ($cur_page == -1) { $cur_page = 1; $link_to_all = true; } if ($num_pages > 1) { if ($cur_page > 1) { $pages[] = array('item' => true, 'href' => str_replace('#', '', get_sublink($link, $panther_url['page'], $cur_page - 1, $args)), 'current' => $lang_common['Previous']); } if ($cur_page > 3) { $pages[] = array('item' => empty($pages) ? true : false, 'href' => $link, 'current' => 1); if ($cur_page > 5) { $pages[] = $lang_common['Spacer']; } } // Don't ask me how the following works. It just does, OK? =) for ($current = $cur_page == 5 ? $cur_page - 3 : $cur_page - 2, $stop = $cur_page + 4 == $num_pages ? $cur_page + 4 : $cur_page + 3; $current < $stop; ++$current) { if ($current < 1 || $current > $num_pages) { continue; } else { if ($current != $cur_page || $link_to_all) { $pages[] = array('item' => empty($pages) ? true : false, 'href' => str_replace('#', '', get_sublink($link, $panther_url['page'], $current, $args)), 'current' => forum_number_format($current)); } else { $pages[] = array('item' => empty($pages) ? true : false, 'current' => forum_number_format($current)); } } } if ($cur_page <= $num_pages - 3) { if ($cur_page != $num_pages - 3 && $cur_page != $num_pages - 4) { $pages[] = $lang_common['Spacer']; } $pages[] = array('item' => empty($pages) ? true : false, 'href' => get_sublink($link, $panther_url['page'], $num_pages, $args), 'current' => forum_number_format($num_pages)); } // Add a next page link if ($num_pages > 1 && !$link_to_all && $cur_page < $num_pages) { $pages[] = array('item' => empty($pages) ? true : false, 'rel' => 'next', 'href' => get_sublink($link, $panther_url['page'], $cur_page + 1, $args), 'current' => $lang_common['Next']); } } $tpl = load_template('pagination.tpl'); return $tpl->render(array('num_pages' => $num_pages, 'cur_page' => $cur_page, 'pages' => $pages, 'link' => $link)); }