Link to Mod (http://custom.simplemachines.org/mods/index.php?mod=1075)
Creates Previous and Next Links for Page Index (for long topics)
For example:
Prev 1 2 3 [4] 5 Next
[1] 2 3 4 5 Next
Prev 1 2 3 4 [5]
Nice work
goog Mod
Works great, shouldn't this be standard in SMF? :)
Thanks a lot! :D
Works pretty well.
Nice mod!
People on my site kept saying it was hard to change pages, since all other forum software has the prev next links.
Quote from: Neg1 on January 25, 2008, 07:04:49 AM
it was hard to change pages, since all other forum software has the prev next links
exactly!
and thanks for all the kind words :)
Nice little mod. Thanks!
I think you should replace next and prev with > and < because this is more international than the two words. And i think you should add a >> and << for last and First Page, only a thought but i think this would made the mod much more better =).
Bye
DIN1031
Thank you for this mod -- very useful.
Mod update (v2):
- Supports SMF 2.0.2 (although code stays the same..)
- "Prev" and "Next" strings are now in the language files.
Shows "Next" in the message index. Doesn't seem like expected behavior... so I'm reporting it.
These edits will fix the issue:
./Sources/Subs.php
function constructPageIndex($base_url, &$start, $max_value, $num_per_page, $flexible_start = false)
function constructPageIndex($base_url, &$start, $max_value, $num_per_page, $flexible_start = false, $show_prev_next = true)
$pageindex = sprintf($base_link, $tmpStart, $txt['prev page']);
if ($show_prev_next) $pageindex = sprintf($base_link, $tmpStart, $txt['prev page']);
$pageindex = sprintf($base_link, $tmpStart, $txt['next page']);
if ($tmpStart <= $tmpMaxPages && $show_prev_next) $pageindex = sprintf($base_link, $tmpStart, $txt['next page']);
./Sources/MessageIndex.php
$pages .= constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true, false);
$pages .= constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true, false);
Thanks for the fix, live627! I had some trouble with two of your changes, so this is what worked for me (I made these changes after installing the modification):
First two changes in ./Sources/Subs.php were fine.
For the third change in ./Sources/Subs.php, I did instead:
if ($tmpStart <= $tmpMaxPages) $pageindex .= sprintf($base_link, $tmpStart, $txt['next page']);
if ($tmpStart <= $tmpMaxPages && $show_prev_next) $pageindex .= sprintf($base_link, $tmpStart, $txt['next page']);
For ./Sources/MessageIndex.php, I did instead:
$pages .= constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true);
$pages .= constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true, false);
Also thanks to phpmycoder for the original modification :]
Sorry for late reply, I subscribed here with an email I hardly check anymore, but should attend often now.
v2.1:
- Fixed the issue (http://www.simplemachines.org/community/index.php?topic=218408.msg3380840#msg3330833) above by adding !$start_invalid condition.
- Beautified code (just for show, no practical implication).
- All changes still only in Subs.php
If there's any new or old problems popping up please let me know and I will try to attend asap.
All the best,
Gigi
Hi I've been having a problem with this mod, I've installed it via the admin/package manager. and I noticed no options for it, nor was it showing on any pages as if it was working. So I removed it assuming it isn't working, after I removed it, I realized that my font size has increased and now at the top of the page you can see "// PreviousNextPage links $txt['prev page'] = 'Prev'; $txt['next page'] = 'Next';" So I proceed to see if installing and uninstalling it again would work, but no luck, instead, it shows that msg twice on the top of my page. If you'd like to have a look, check famcraft.com I'm no type of coder, I'm fairly new to all of this, but I believe this can be a bug when installing it through the package manager, any help you guys can give me to fix this issue? Thanks in advance.
There are no settable options for this mod. About package manager - have you tested the installation before actually installing? Package manager has a test function where you can see if installation was successful or not before real changes are committed. Most likely this would have returned an error, meaning that it conflicts with other mods (other mods that are already installed have modified the same segments of code, and therefore the package manager cannot install or remove the code segments accurately). So you have to restore your site from a backup, then locate the other conflicting mods.
This mod does not appear to work with my forum (2.0.4). I get a parse error message when trying to install the package, and manual installation does not appear to do anything. Any ideas?
I just tested the mod on a fresh 2.0.4 installation and it installs ok. Please see my post above, it may be conflicting with other mods you installed or with other custom changes in the code.
Can you post exactly which parse error you are getting, that may give a hint as to the specific problem you are experiencing. Also can you attach the php file the error emanates from.
Installation Readme
Warning! This mod has not been tested on your specific installation of SMF. Do not proceed if you get 'Test Failed' messages! Available Readme Languages:
Installations actions for "Previous and Next Links for Page Index"
Installing this package will perform the following actions:
Type Action Description
1. Execute Modification modification.xml Modification parse error
2. Execute Modification modification.xml Modification parse error
Regarding the warning, I have changed the mod so to imply it supports 2.0.4. You can download the new version from the mod page ( http://custom.simplemachines.org/mods/index.php?mod=1075 )
Regarding the parse error, please first try installing the mod on a fresh SMF installation (no other mods). There is probably another mod which modified the same segment of code and therefore the modification isn't being applied as it should.
Great mod :)
I think this would fit rather nice in the SMF core. Maybe it's worth to send in a pull request on GitHub, see what the developers think :)
Quote from: phpmycoder on April 09, 2013, 11:40:05 AM
Regarding the warning, I have changed the mod so to imply it supports 2.0.4. You can download the new version from the mod page ( http://custom.simplemachines.org/mods/index.php?mod=1075 )
Regarding the parse error, please first try installing the mod on a fresh SMF installation (no other mods). There is probably another mod which modified the same segment of code and therefore the modification isn't being applied as it should.
It now works on my modded install. Thanks, PMC!
@One Quarter - I'd guess then the xml you originally downloaded was probably corrupt (maybe the zip file wasn't properly pulled from the server), glad it's working now.
@Yoshi2889 - thanks, quite a few forums have this built in, I also think SMF should catch up on this :)
Quote from: phpmycoder on April 09, 2013, 12:10:25 PM
@Yoshi2889 - thanks, quite a few forums have this built in, I also think SMF should catch up on this :)
I agree :)
Though, what I was suggesting, is that you can built it in the core of SMF yourself, if you'd want to. The development repository is open: http://github.com/SimpleMachines/SMF2.1/ , everyone is welcome to contribute code and possibly try to integrate their mod :)
$start > $num_per_page * $PageContiguous and $pageindex .= sprintf($base_link, 0, '1');
That's an interesting construction. Legal, but interesting in a variety of fun and exciting ways. And if you figure out the operator precedence rules, it does even work as expected. Curiously enough, it might even be just fractionally faster when compiled to op codes. Less readable, less malleable later though.
I would hope that this sort of code does not become mainstream in SMF's trunk though, precisely because while it is completely legal, it isn't very clear what's going on or why.
I'd also note that already SMF 2.1 and all three major forks have this in it (in perhaps different styles or implementations)
Quote from: Arantor on April 09, 2013, 12:14:18 PM
I'd also note that already SMF 2.1 and all three major forks have this in it (in perhaps different styles or implementations)
I see. It's been a long while since I last poked SMF 2.1, though, so I must've missed up on that :)
@Yoshi2889 - Sounds good, I never looked into contributing to the source code, will check it out!
@Arantor - it does work, I have been using these and/or operators since forever, sometimes cramming 5+ lines of code into one. As you mentioned, you need to be acutely aware of operator precedence rules, and yes it can get rather confusing and error prone for follow up programmers once these statements get convoluted, so definitely not recommended for anything other than your own little wise ass code.. ;)
Follow-up question:
After installing this mod, this line of code in Sources/Subs.php:
// Show the current page. (1 ... 6 7 >[8]< 9 10 ... 15)
if (!$start_invalid)
$pageindex .= '[<strong>' . ($start / $num_per_page + 1) . '</strong>] ';
else
$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
is creating an "Undefined variable" error message:
http://XXXX/board/index.php?board=4.0
8: Undefined variable: pageindex
File: /var/www/vhosts/XXXX/httpdocs/board/Sources/Subs.php
Line: 710
Any ideas?
Can you try changing this line in Subs.php:
// "Next"
if ( !$start_invalid )
To:
// "Next"
if ( !$start_invalid && !empty($pageindex) )
This should resolve the problem. If it works ok please let me know so I will update the mod.
phpmycoder, thanks so much for trying to help me!
Unfortunately, your suggestion did not resolve the "Undefined variable" error for $pageindex. I am posting my entire code section here in case it might help. The specific line of code that is returning the error is in the section entitled "Show the current page. (1 ... 6 7 >[8]< 9 10 ... 15)", which is after the "Prev" link and before the "Next" link. I also tried using your suggestion in the "Prev" section, unsuccessfully. Commenting out the "Prev" link code resolves the error, so somehow, the "Prev" link code is messing up that instance of $pageindex.
global $txt;
// "Prev"
if ( !$start_invalid )
{
$tmpStart = $start - $num_per_page;
if ( $start / $num_per_page + 1 > 1 )
{
$pageindex = sprintf($base_link, $tmpStart, $txt['prev page']);
$start > $num_per_page * $PageContiguous and $pageindex .= sprintf($base_link, 0, '1');
}
else
{
$pageindex = $start > $num_per_page * $PageContiguous ? sprintf($base_link, 0, '1') : '';
}
}
// Show the ... after the first page. (1 >...< 6 7 [8] 9 10 ... 15)
if ($start > $num_per_page * ($PageContiguous + 1))
$pageindex .= '<span style="font-weight: bold;" onclick="' . htmlspecialchars('expandPages(this, ' . JavaScriptEscape(($flexible_start ? $base_url : strtr($base_url, array('%' => '%%')) . ';start=%1$d')) . ', ' . $num_per_page . ', ' . ($start - $num_per_page * $PageContiguous) . ', ' . $num_per_page . ');') . '" onmouseover="this.style.cursor = \'pointer\';"> ... </span>';
// 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 .= '[<strong>' . ($start / $num_per_page + 1) . '</strong>] ';
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 .= '<span style="font-weight: bold;" onclick="expandPages(this, \'' . ($flexible_start ? strtr($base_url, array('\'' => '\\\'')) : strtr($base_url, array('%' => '%%', '\'' => '\\\'')) . ';start=%1$d') . '\', ' . ($start + $num_per_page * ($PageContiguous + 1)) . ', ' . $tmpMaxPages . ', ' . $num_per_page . ');" onmouseover="this.style.cursor=\'pointer\';"> ... </span>';
// 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);
// "Next"
if ( !$start_invalid )
{
$tmpMaxPages = (int) --$max_value / $num_per_page * $num_per_page;
$tmpStart = $start + $num_per_page;
$tmpStart <= $tmpMaxPages and $pageindex .= sprintf($base_link, $tmpStart, $txt['next page']);
}
}
return $pageindex;
}
Hmm this is strange since according to the code $pageindex is actually created in the // Prev section.
Let's try this as a last hack:
Find (line 669 here):
else
{
// If they didn't enter an odd value, pretend they did.
Change to:
else
{
$pageindex = '';
// If they didn't enter an odd value, pretend they did.
This just defines $pageindex which is in fact not initially defined under all conditions (regardless of the mod). This should take care of the php notice.
If you find a functionality problem however, and it resolves once you remove the mod, then please let me know and you can then send me your installation of smf if you want so I can look at the specific case (it's pretty much a guessing game trying to resolve it inside the thread).
Success. Defining $pageindex before the // Prev section resolves the error notice. Functionality was good before and after this fix.
Thanks again!
$pageindex has in fact not been properly initiated in the original function (it is only initiated when compact pages is off). Php does initiate variables on its own, not without php notice 8 though ;)
Anyway glad it all worked out!
If it makes any difference, the notice 8 for $pageindex was only being generated on viewing the "board index" (e.g., index.php?board=5.0), and not on any other page (e.g., index.php?topic=79845 or /index.php?action=admin). Maybe I have some issue with a modification to the board index view. Anyway, thanks again.
I had the same problem One Quarter. Solved with the above change. :)
I just installed this modification on 2.0.7 and it works as intended. My only issue is the "Go Up" link has disappeared as a result... is there an adjustment I can make to get this back?
Hi wolf39us;
I will try to look into this on Monday or Tuesday. If you have other mods installed, please make sure it's not them that are causing the problem.