phpBB3 Forum Search Results - Need full path

Discussion forum for MOD Writers regarding MOD Development.
Locked
Tobins
Registered User
Posts: 1
Joined: Sun Mar 20, 2011 2:20 pm

phpBB3 Forum Search Results - Need full path

Post by Tobins »

Support Request Template
What version of phpBB are you using? phpBB 3.0.8 RC1
What is your board's URL? Interal
Who do you host your board with? Private Server
How did you install your board? I used the download package from phpBB.com
Is your board a fresh install or a conversion? Fresh Install
Do you have any MODs installed? No
Is registration required to reproduce this issue? No
What styles do you currently have installed? SubSilver2
What language(s) is your board currently using? British English
Which database type/version are you using? MySQL 5
What is your level of experience? Experienced with PHP and phpBB
When did your problem begin? N/A
Please describe your problem. When you search for a term on the board, the post's forum is shown underneath each result. I have a very dynamic forum with many forums and subforums. If the search results show a post from a subforum, it only shows the subforum's name, it doesn't give the full path (e.g. General Discussion -> Forum Games. It just shows Forum Games.) I want it to show the full forum path, because I have various subforums named the same thing, from a higher forum. This can be very confusing to users.

Can someone give me a little help? I'd be extremely grateful! Thanks so much!

-Tobins
Generated by SRT Generator ($Rev: 4778 $)
User avatar
AmigoJack
Registered User
Posts: 5774
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: phpBB3 Forum Search Results - Need full path

Post by AmigoJack »

Keep in mind that this will impact the database additionally, since for every forum its parent must be found, and then the parent of the parent again... until a forum has no parent anymore. A forum doesn't have stored its full path with it.

Open /search.php and find:

Code: Select all

        foreach ($rowset as $row) 
Before, add:

Code: Select all

        /*** 2011-03-21 BEGIN AmigoJack
            Show forum path for every result. Be aware that this impacts the database
            since we need to know each parent of a forum until we reach a forum which
            has no parent anymore. ***/
                
        $aForumData= $aForumFind= $aForumPath= array();

        // We need to query the parent of all forums from this results page
        foreach( $rowset as $aRow ) {
            $aForumFind[]= $aRow['forum_id'];
            $aForumPath[$aRow['forum_id']]= '';  // These are our targets
        }
        
        // Should be encountered at least once
        while( count( $aForumFind ) ) {
            $sql= 'SELECT forum_id, forum_name, parent_id
                FROM '. FORUMS_TABLE. '
                WHERE '. $db-> sql_in_set( 'forum_id', $aForumFind );
            $rSql= $db-> sql_query( $sql );

            // Reset since we will fill it again with the parents of the query results
            $aForumFind= array();
            while( $aRow= $db-> sql_fetchrow( $rSql ) ) {
                $aForumData[$aRow['forum_id']]= $aRow;  // Expand our knowledge
                if( $aRow['parent_id'] ) $aForumFind[]= $aRow['parent_id'];  // Has a parent? Loop at least once more
            }
            $db-> sql_freeresult( $rSql );
        }

        // Now build the paths
        foreach( $aForumPath as $k1=> $v1 ) {
            $iForum= $k1;
            $aForumPath[$k1]= $aForumData[$iForum]['forum_name'];
            
            // Walk from child to his ancestors
            while( $aForumData[$iForum]['parent_id'] ) {
                $iForum= (int)$aForumData[$iForum]['parent_id'];
                $aForumPath[$k1]= $aForumData[$iForum]['forum_name']. ' <strong>&#8249;</strong> '. $aForumPath[$k1];
            }
        }
        /*** 2011-03-21 END ***/ 
Find:

Code: Select all

                'FORUM_TITLE'        => $row['forum_name'], 
Replace with:

Code: Select all

                /*** 2011-03-21 BEGIN AmigoJack
                    Full forum path instead of title only ***/
                //'FORUM_TITLE'        => $row['forum_name'],
                'FORUM_TITLE'        => $aForumPath[$forum_id],
                /*** 2011-03-21 END ***/ 
Tested.
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.
User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: phpBB3 Forum Search Results - Need full path

Post by Volksdevil »

Hi Amigojack,

great post. :D Is there a way we can get it to just show the next parent up before the forum rather than the full path? Would be superb for me if you could show me how. :)
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60
User avatar
AmigoJack
Registered User
Posts: 5774
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: phpBB3 Forum Search Results - Need full path

Post by AmigoJack »

In my code, find:

Code: Select all

                $aForumPath[$k1]= $aForumData[$iForum]['forum_name']. ' <strong>&#8249;</strong> '. $aForumPath[$k1]; 
After, add:

Code: Select all

                break; 
Untested.
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.
User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: phpBB3 Forum Search Results - Need full path

Post by Volksdevil »

Seems to do the job, thank you 8-)

Just so I know (learn a little) is that code now still searching for ALL parents, but the break stops it displaying anything after the first parent?
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60
User avatar
AmigoJack
Registered User
Posts: 5774
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: phpBB3 Forum Search Results - Need full path

Post by AmigoJack »

Yes - it loops because we also need to find data for the lowest forum itself. I cannot test it right now, but a quick and dirty fix would be to change these lines:

Code: Select all

        // Should be encountered at least once
        while( count( $aForumFind ) ) { 
into these:

Code: Select all

        // Should be encountered at least once
        $iLoop= 0;  // No more than 2 loops
        while( count( $aForumFind )&& $iLoop++< 2 ) { 
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.
User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: phpBB3 Forum Search Results - Need full path

Post by Volksdevil »

Cheers for that. I've made the change. What would be the difference? A lesser impact on the database or something? :)
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60
User avatar
AmigoJack
Registered User
Posts: 5774
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: phpBB3 Forum Search Results - Need full path

Post by AmigoJack »

Yes, you save (lightweight) database queries for each additional forum level, which in overall can vary a lot between boards with few forum levels and those which have deep nested forums.
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.
User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: phpBB3 Forum Search Results - Need full path

Post by Volksdevil »

Thanks for the info. 8-)
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60
Locked

Return to “[3.0.x] MOD Writers Discussion”