2016-09-27, 07:50 PM
Look at this code section:
The commented-out code clearly indicates that the MyBB devs were aware that here is something grossly afoul.
Just look at the corrected if statement line to understand what was the error.
It is important to be aware that the forum cache is sometimes wrong.
In these cases $lastpost['lastpost'] just is an empty string. Obviously then comparing with a number "zero" will not yield the expected result.
The correct way to do this is just to do a boolean check (see more information about this topic in the first user-contributed note in this php documentation page)
The comparison ("does this forum contain posts at all?") I added works around this cache bug which occurs under special circumstances on forums that do not yet have posts.
(A better solution would ofc be to fix the cache problem. But this is quite complex. It would be pointless to invest time in this as MyBB 1.8 series has already almost reached the state of abandonware.)
//if(!$forum_read)
//{
//$forum_read = $mybb->user['lastvisit'];
//}
// If the lastpost is greater than the last visit and is greater than the forum read date, we have a new post
if($lastpost['lastpost'] > $forum_read && $lastpost['lastpost'] != 0)
The commented-out code clearly indicates that the MyBB devs were aware that here is something grossly afoul.
Just look at the corrected if statement line to understand what was the error.
if($lastpost['lastpost'] > $forum_read && $lastpost['lastpost'] && $forum['posts'])
It is important to be aware that the forum cache is sometimes wrong.
In these cases $lastpost['lastpost'] just is an empty string. Obviously then comparing with a number "zero" will not yield the expected result.
The correct way to do this is just to do a boolean check (see more information about this topic in the first user-contributed note in this php documentation page)
The comparison ("does this forum contain posts at all?") I added works around this cache bug which occurs under special circumstances on forums that do not yet have posts.
(A better solution would ofc be to fix the cache problem. But this is quite complex. It would be pointless to invest time in this as MyBB 1.8 series has already almost reached the state of abandonware.)