Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
How-To Integrate Mod with forum search results
IdanB's Avatar
IdanB
Join Date: May 2009
Posts: 171

Electronics Engineer working as Software Developer. Knowledge of: C / C++ / C# / ASP.NET / PHP / TCL / VHDL. Active Staff & Coder position @ vBHackers.com

Israel
Show Printable Version Email this Page Subscription
IdanB IdanB is offline 05-22-2009, 10:00 PM

Anyone who ever written a modification that was based on some custom access permissions (logic driven) should be aware about the "search" & "advanced search" pitfalls.

Let me explain the "problems" of these issues:
Say for example you wrote a mod that hide/deny certain thread/forum from user. Coder worked hard with mod coding, and made sure that user wouldnt see the link to that thread (either on forumhome, forumdisplay, thread listing, etc.). However, one need to remember the "search option & the fact that specific thread could be returned as part of search results shown to user.

The problem consisted of 2 pitfalls:
  1. Post listing in the search results.
  2. Forum listing in the advanced search.

Now that we recognize the problems, lets talk solutions

Solution to problem 1:
hook location: search_results_prebits
Code Approach Explained:
This hook will allow us to manipulate the results before sent to screen.
the search results are located into array var $itemids.
Common way to handle this, is by looping the array vars, and should we find any result line we wish to hide, we can simply unset it.
Code Example:
Lets assume we want to match for "forum id" & hide certain forum posts based on some logic behind it, thae hook plugin will look as follows:
PHP Code:
foreach ($itemids as $key => $post)
{
    
// here will be some mod logic
    // i'll show some "dummy" mod logic that will match post forum id with some hidden forum id
    // Once logic decided on hide, it will set var flag named $hide_post to 1
    // else flag will be set to 0
   
$hide_post 0;
   if ( 
$post['forumid'] == $my_hidden_forum_id )
   {
       
$hide_post 1;
   } 
   
   if ( 
$hide_post )
   {
         unset(
$itemids[$key]);
   }


Solution to problem 2:
hook location: search_intro
Walkthrough: understanding what's going on in the background :
This hook will allow us to manipulate the data before showing the "advanced search" screen.
looking at the "search_forums" template, you will see this code secton:
PHP Code:
<select style="width:100%" name="forumchoice[]" size="13" multiple="multiple">
                            <
option value="0" $noforumselected>$vbphrase[search_all_open_forums]</option>
                            <
option value="subscribed">$vbphrase[search_subscribed_forums]</option>
                            
$searchforumbits
                        
</select
So we have a listbox (HTML select control), that it's items are placed by code into $searchforumbits. Taking a closer look into "search.php" will show you the following line:
PHP Code:
eval('$searchforumbits .= "' fetch_template('option') . '";'); 
option is tempalte that looks like this:
PHP Code:
<option value="$optionvalueclass="$optionclass$optionselected>$optiontitle</option
Code Approach Explained:
Hence, what we understand from all the above, inside the $forumbits var i'll find block of text, consisting of <option> lines, one for each of the forums we have.
Note since this is built inside the search.php (lines 2069-2100) we have no hook inside, allowing us to act during build of this list. Therefore our only option is to "retro" process this text block

Code Example:
My suggested code approach method is as follows:
PHP Code:
$option_bits explode("\r\n",$searchforumbits);

foreach ( 
$option_bits as $forum_line )
{
   
// match for forumid
   
if ( eregi('value="([0-9]+)"'$forum_line$dump) )
   {
       
// again here we need mod logic decide if we should hide forum from list or not
       // as before lets assume this was set here into flag called $hide_forum
      
...

       if ( 
$hide_forum )
       {
          
// user not allowed to see this forum - this forum line should be removed
          
$searchforumbits str_replace($forum_line,"",$searchforumbits);
       }
   }

Code Explained:
  1. PHP function eregi() allows to perform regular expression match (the i means "case insensitive"). you can read about function eregi() here: http://www.php.net/eregi
  2. Regular expression written match for the number inside the value="x".
  3. The $dump holds the results. results is inside $dump[1] ($dump[0] holds the entire string matched);
  4. Once we've confirmed we want this line removed, we use php function str_replace() to replace forum option line with empty string. You can read about function str_replace here: http://www.php.net/manual/en/function.str-replace.php


That's it

Hope this small guide helped anyone that wanted to do some modification integration into search option on forum & didnt know where to place code or how.
Reply With Quote
  #2  
Old 05-25-2009, 09:29 AM
Come2Daddy Come2Daddy is offline
 
Join Date: May 2008
Posts: 128
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've been waiting your new tutorial
great one
Reply With Quote
  #3  
Old 06-01-2009, 07:10 AM
almohd's Avatar
almohd almohd is offline
 
Join Date: Feb 2009
Location: Bahrain
Posts: 68
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:44 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04438 seconds
  • Memory Usage 2,223KB
  • Queries Executed 18 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (5)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (2)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete