Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: phpmycoder on January 22, 2008, 11:23:32 PM

Title: Previous and Next Links for Page Index
Post by: phpmycoder on January 22, 2008, 11:23:32 PM
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]
Title: Re: Previous and Next Links for Page Index
Post by: Apllicmz on January 23, 2008, 12:17:17 AM
Nice work
goog Mod
Title: Re: Previous and Next Links for Page Index
Post by: [Lucien] on January 23, 2008, 07:43:53 AM
Works great, shouldn't this be standard in SMF?  :)

Thanks a lot!  :D
Title: Re: Previous and Next Links for Page Index
Post by: Mick. on January 23, 2008, 06:04:50 PM
Works pretty well.
Title: Re: Previous and Next Links for Page Index
Post by: Neg1 on January 25, 2008, 07:04:49 AM
Nice mod!

People on my site kept saying it was hard to change pages, since all other forum software has the prev next links.
Title: Re: Previous and Next Links for Page Index
Post by: phpmycoder on January 25, 2008, 08:13:30 AM
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 :)
Title: Re: Previous and Next Links for Page Index
Post by: digit on January 27, 2008, 07:00:11 AM
Nice little mod.  Thanks!
Title: Re: Previous and Next Links for Page Index
Post by: ディン1031 on April 26, 2008, 04:18:39 AM
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
Title: Re: Previous and Next Links for Page Index
Post by: dcmouser on February 15, 2011, 10:01:18 AM
Thank you for this mod -- very useful.
Title: Re: Previous and Next Links for Page Index
Post by: phpmycoder on February 15, 2012, 02:14:46 PM
Mod update (v2):

- Supports SMF 2.0.2 (although code stays the same..)

- "Prev" and "Next" strings are now in the language files.
Title: Re: Previous and Next Links for Page Index
Post by: live627 on May 09, 2012, 01:29:33 AM
Shows "Next" in the message index. Doesn't seem like expected behavior... so I'm reporting it.
Title: Re: Previous and Next Links for Page Index
Post by: live627 on May 09, 2012, 02:11:08 AM
These edits will fix the issue:

./Sources/Subs.php

Code (Find) Select
function constructPageIndex($base_url, &$start, $max_value, $num_per_page, $flexible_start = false)

Code (Replace with) Select
function constructPageIndex($base_url, &$start, $max_value, $num_per_page, $flexible_start = false, $show_prev_next = true)

Code (Find) Select
$pageindex = sprintf($base_link, $tmpStart, $txt['prev page']);

Code (Replace with) Select
if ($show_prev_next) $pageindex = sprintf($base_link, $tmpStart, $txt['prev page']);

Code (Find) Select
$pageindex = sprintf($base_link, $tmpStart, $txt['next page']);

Code (Replace with) Select
if ($tmpStart <= $tmpMaxPages && $show_prev_next) $pageindex = sprintf($base_link, $tmpStart, $txt['next page']);

./Sources/MessageIndex.php

Code (Find) Select
$pages .= constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true, false);

Code (Replace with) Select
$pages .= constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true, false);
Title: Re: Previous and Next Links for Page Index
Post by: Firia on July 11, 2012, 02:13:11 AM
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:

Code (find) Select
if ($tmpStart <= $tmpMaxPages) $pageindex .= sprintf($base_link, $tmpStart, $txt['next page']);

Code (replace with) Select
if ($tmpStart <= $tmpMaxPages && $show_prev_next) $pageindex .= sprintf($base_link, $tmpStart, $txt['next page']);


For ./Sources/MessageIndex.php, I did instead:

Code (find) Select
$pages .= constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true);

Code (replace with) Select
$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 :]
Title: Re: Previous and Next Links for Page Index
Post by: phpmycoder on July 28, 2012, 01:31:27 PM
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
Title: Re: Previous and Next Links for Page Index
Post by: bknysnake on November 08, 2012, 03:22:09 AM
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.
Title: Re: Previous and Next Links for Page Index
Post by: phpmycoder on November 08, 2012, 06:55:30 AM
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.
Title: Re: Previous and Next Links for Page Index
Post by: One Quarter on April 06, 2013, 01:15:02 AM
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?
Title: Re: Previous and Next Links for Page Index
Post by: phpmycoder on April 07, 2013, 04:44:35 AM
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.
Title: Re: Previous and Next Links for Page Index
Post by: One Quarter on April 09, 2013, 11:29:26 AM
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
Title: Re: Previous and Next Links for Page Index
Post by: 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.
Title: Re: Previous and Next Links for Page Index
Post by: NanoSector on April 09, 2013, 12:00:47 PM
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 :)
Title: Re: Previous and Next Links for Page Index
Post by: One Quarter on April 09, 2013, 12:02:15 PM
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!
Title: Re: Previous and Next Links for Page Index
Post by: phpmycoder on April 09, 2013, 12:10:25 PM
@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 :)
Title: Re: Previous and Next Links for Page Index
Post by: NanoSector on April 09, 2013, 12:12:41 PM
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 :)
Title: Re: Previous and Next Links for Page Index
Post by: Arantor on April 09, 2013, 12:14:18 PM
$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)
Title: Re: Previous and Next Links for Page Index
Post by: NanoSector on April 09, 2013, 12:15:35 PM
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 :)
Title: Re: Previous and Next Links for Page Index
Post by: phpmycoder on April 09, 2013, 12:26:20 PM
@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.. ;)
Title: Re: Previous and Next Links for Page Index
Post by: One Quarter on April 09, 2013, 12:44:47 PM
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?
Title: Re: Previous and Next Links for Page Index
Post by: phpmycoder on April 10, 2013, 03:32:56 PM
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.

Title: Re: Previous and Next Links for Page Index
Post by: One Quarter on April 10, 2013, 04:06:56 PM
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;
}
Title: Re: Previous and Next Links for Page Index
Post by: phpmycoder on April 10, 2013, 04:29:34 PM
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).

Title: Re: Previous and Next Links for Page Index
Post by: One Quarter on April 10, 2013, 04:35:25 PM
Success.  Defining $pageindex before the // Prev section resolves the error notice.  Functionality was good before and after this fix.

Thanks again!
Title: Re: Previous and Next Links for Page Index
Post by: phpmycoder on April 11, 2013, 07:45:11 AM
$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!
Title: Re: Previous and Next Links for Page Index
Post by: One Quarter on April 11, 2013, 09:03:40 AM
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.
Title: Re: Previous and Next Links for Page Index
Post by: DSystem on April 21, 2013, 10:11:11 AM
I had the same problem One Quarter. Solved with the above change. :)
Title: Re: Previous and Next Links for Page Index
Post by: wolf39us on March 22, 2014, 12:09:33 PM
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?
Title: Re: Previous and Next Links for Page Index
Post by: phpmycoder on March 22, 2014, 01:40:33 PM
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.