• Welcome to Simple Machines Community Forum. Please login or sign up.

Previous and Next Links for Page Index

Started by phpmycoder, January 22, 2008, 11:23:32 PM

Previous topic - Next topic

NanoSector

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 :)
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

One Quarter

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!

phpmycoder

@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 :)

NanoSector

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 :)
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

Arantor

$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)
No good deed goes unpunished
All helpful urges should be circumvented

NanoSector

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 :)
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

phpmycoder

April 09, 2013, 12:26:20 PM #26 Last Edit: April 09, 2013, 12:42:01 PM by phpmycoder
@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.. ;)

One Quarter

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 [nofollow]
8: Undefined variable: pageindex
File: /var/www/vhosts/XXXX/httpdocs/board/Sources/Subs.php
Line: 710

Any ideas?

phpmycoder

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.


One Quarter

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;
}

phpmycoder

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).


One Quarter

Success.  Defining $pageindex before the // Prev section resolves the error notice.  Functionality was good before and after this fix.

Thanks again!

phpmycoder

$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!

One Quarter

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.

DSystem

I had the same problem One Quarter. Solved with the above change. :)

wolf39us

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?

phpmycoder

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.

Advertisement: