phpBB2Refugees.com Logo
Not affiliated with or endorsed by the phpBB Group

Register •  Login 

Continue the legacy...

Welcome to all phpBB2 Refugees!Wave Smilie

This site is intended to continue support for the legacy 2.x line of the phpBB2 bulletin board package. If you are a fan of phpBB2, please, by all means register, post, and help us out by offering your suggestions. We are primarily a community and support network. Our secondary goal is to provide a phpBB2 MOD Author and Styles area.

How about unlimited pages in forums? viewforum.php?f=1&s


 
Search this topic... | Search General Support... | Search Box
Register or Login to Post    Index » General Support  Previous TopicPrint TopicNext Topic
Author Message
bengurion
Board Member



Joined: 16 Sep 2018

Posts: 21



PostPosted: Sat Dec 08, 2018 11:23 pm 
Post subject: How about unlimited pages in forums? viewforum.php?f=1&s

As you know, if in one forum you have more than 1 page the format of the link is like this -
Code:
/viewforum.php?f=1&start=20


But even if you don't have more pages you can enter in the url -
Code:
viewforum.php?f=1&start=180000

And it WILL WORK. But will show only sticked messages in that forum.

Question : how to not open anything at all (like 404 error) or how to make a canonical link for any url more than exists for the last page of the forum?

Because search engines keep indexing and throwing out unlimited "pages" from forums and keep arguing that they are doubles.
icon_cry.gif

Thank you!
Back to top
Salvatos
Board Member



Joined: 19 Feb 2009

Posts: 439
Location: Québec


flag
PostPosted: Sun Dec 09, 2018 4:09 am 
Post subject: Re: How about unlimited pages in forums? viewforum.php?f=1&a

I don't know about canonical URLs and I don't have much time to look into this at all, but maybe I can help you get going. Lines 311-343 in viewforum.php look like a good place to introduce a redirection or some other behavior of your choice:
Code:
//
// Grab all the basic data (all topics except announcements)
// for this forum
//
$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time
   FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2
   WHERE t.forum_id = $forum_id
      AND t.topic_poster = u.user_id
      AND p.post_id = t.topic_first_post_id
      AND p2.post_id = t.topic_last_post_id
      AND u2.user_id = p2.poster_id
      AND t.topic_type <> " . POST_ANNOUNCE . "
      $limit_topics_time
   ORDER BY t.topic_type DESC, t.topic_last_post_id DESC
   LIMIT $start, ".$board_config['topics_per_page'];
if ( !($result = $db->sql_query($sql)) )
{
   message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
}

$total_topics = 0;
while( $row = $db->sql_fetchrow($result) )
{
   $topic_rowset[] = $row;
   $total_topics++;
}

$db->sql_freeresult($result);

//
// Total topics ...
//
$total_topics += $total_announcements;

I suspect that $total_topics will remain at 0 if there is nothing but announcements and stickies for the requested page, so you could add a condition there before $total_announcements is added to it. Maybe a different message_die() or a redirection. You might want to use one of the following error messages for message_die(), but you would have to check topic ordering beforehand if you pick the first two:
Code:
$lang['No_newer_topics'] = 'There are no newer topics in this forum';
$lang['No_older_topics'] = 'There are no older topics in this forum';
$lang['No_search_match'] = 'No topics or posts met your search criteria';
Back to top
bengurion
Board Member



Joined: 16 Sep 2018

Posts: 21



PostPosted: Sun Dec 09, 2018 12:47 pm 
Post subject: Re: How about unlimited pages in forums? viewforum.php?f=1&a

Salvatos wrote:
I don't know about canonical URLs and I don't have much time to look into this at all, but maybe I can help you get going. Lines 311-343 in viewforum.php look like a good place to introduce a redirection or some other behavior of your choice:
Code:
//
// Grab all the basic data (all topics except announcements)
// for this forum
//
$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time
   FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2
   WHERE t.forum_id = $forum_id
      AND t.topic_poster = u.user_id
      AND p.post_id = t.topic_first_post_id
      AND p2.post_id = t.topic_last_post_id
      AND u2.user_id = p2.poster_id
      AND t.topic_type <> " . POST_ANNOUNCE . "
      $limit_topics_time
   ORDER BY t.topic_type DESC, t.topic_last_post_id DESC
   LIMIT $start, ".$board_config['topics_per_page'];
if ( !($result = $db->sql_query($sql)) )
{
   message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
}

$total_topics = 0;
while( $row = $db->sql_fetchrow($result) )
{
   $topic_rowset[] = $row;
   $total_topics++;
}

$db->sql_freeresult($result);

//
// Total topics ...
//
$total_topics += $total_announcements;

I suspect that $total_topics will remain at 0 if there is nothing but announcements and stickies for the requested page, so you could add a condition there before $total_announcements is added to it. Maybe a different message_die() or a redirection. You might want to use one of the following error messages for message_die(), but you would have to check topic ordering beforehand if you pick the first two:
Code:
$lang['No_newer_topics'] = 'There are no newer topics in this forum';
$lang['No_older_topics'] = 'There are no older topics in this forum';
$lang['No_search_match'] = 'No topics or posts met your search criteria';



How to make a normal redirect? I tried message_die like this but it did not work. It just converted all pages in the empty ones.
I put it just before $total_topics += $total_announcements;

Code:
if ($total_topics = 0)
      {
         message_die(GENERAL_MESSAGE, 'Forum_not_exist');
      }   
Back to top
bengurion
Board Member



Joined: 16 Sep 2018

Posts: 21



PostPosted: Sun Dec 09, 2018 2:23 pm 
Post subject: Re: How about unlimited pages in forums? viewforum.php?f=1&a

Ok all solved!
Put this after
$total_topics += $total_announcements;
$topics_count -= $total_announcements;

Code:
if($total_topics-$total_announcements <= 0){
    header("HTTP/1.0 404 Not Found");
    message_die(GENERAL_MESSAGE, 'Forum_not_exist');
}
Back to top
Salvatos
Board Member



Joined: 19 Feb 2009

Posts: 439
Location: Québec


flag
PostPosted: Sun Dec 09, 2018 7:15 pm 
Post subject: Re: How about unlimited pages in forums? viewforum.php?f=1&a

Glad you got it solved icon_smile.gif

Your error with the first attempt probably had to do with the single equal sign in the if condition (one sign sets the variable, two signs compares it, and three signs compares it exactly [something about matching types rather than just values, but I couldn't explain it off the top of my head]). If I'm not mistaken, the way the check was written, you were setting $total_posts to 0, then executing the condition if the operation succeeded (which it would always do, normally); therefore every page triggered the message_die().
Back to top
Display posts from previous:   
Register or Login to Post    Index » General Support  Previous TopicPrint TopicNext Topic
Page 1 of 1 All times are GMT
 
Jump to:  

Index • About • FAQ • Rules • Privacy • Search •  Register •  Login 
Not affiliated with or endorsed by the phpBB Group
Powered by phpBB2 © phpBB Group
Generated in 0.0263 seconds using 15 queries. (SQL 0.0024 Parse 0.0008 Other 0.0230)
phpBB Customizations by the phpBBDoctor.com
Template Design by DeLFlo and MomentsOfLight.com Moments of Light Logo