Follow vBSEO on Twitter
vBulletin Modifications
  • Forums
  • Add-Ons
  • Template Modifications
  • Styles
  • Graphics
  • Tutorials
  • Support Center
  • Register
  • vBulletin SEO

Member Log In

Site Navigation

  • Register
  • Members List
  • Social Groups
  • Search
  • Today's Posts
  • Mark Forums Read

Latest Modifications

  • [vB 3.8.4] THX - Hack for VB. 3.8.4
    By: bluedog
  • [vB 3.8.4] Cyb - Chatbox V.2.3
    By: bluedog
  • [vB 4.0.x] PHPKD - Advanced Quick...
    By: PHPKD
  • [vB 3.6.x] StopSpam
    By: flappi282
  • [vB 3.8.x] vBulletin Chat Addon for...
    By: 123flashchat

Latest Template Mods

  • [vB 4.0.x] Remove My Profile Link...
    By: Ak Worm
  • [vB 3.8.x] Images DownloadBox...
    By: cRs!MP
  • [vB 3.8.x] Adviertise Mod On Forum...
    By: MG4
  • [vB 3.8.4] Images PassWordBox...
    By: cRs!MP
  • [vB 3.8.4] Footer Follow Ups
    By: Ak Worm

Latest Styles

  • [vB 4.0.x] 4.0.3 - VB4STYLE-TWEETA...
    By: Belon
  • [vB 4.0.x] [4.0.3] vbdesigns.de...
    By: Belon
  • [vB 3.8.4] CompletevB - Skylight
    By: DreadKnight
  • [vB 3.8.3] [vB 3.8.4] Barcelona...
    By: hoiquantinhoc.com
  • [vB 3.8.3] Natures Walk by vBSkin...
    By: Chri5

Latest Graphics

  • [vB ] [anim.]Team Ranks
    By: cRs!MP
  • [vB ] Abstract Circles (3...
    By: cRs!MP
  • [vB ] PlayStation Rank Images
    By: cRs!MP
  • [vB 3.6.12] Heavy Stroked Button...
    By: Shelley
  • [vB ] Minature Ranks.
    By: Shelley
vBulletin Modifications » General vBulletin Section » vBulletin Modification Tutorials » [How-To] Integrate Mod with forum search results
Reply

 

  • Thread Tools
Old 05-23-2009, 03:54 PM   #1
Idan
Coder
Idan's Avatar

Activity Longevity
0/20 18/20
Today Posts
0/3 sssss1484
Location: Israel
Age: 29
Idan is on a distinguished road
Status: Offline [How-To] Integrate Mod with forum search results
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="$optionvalue" class="$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: PHP: eregi - Manual
  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: PHP: str_replace - Manual


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.
Regards,
Idan.

* Support will only be given via forums !
* If this post solved/aided your problem, please click "mark as aid" / "mark as solution" as explained in here
Reply With Quote

Reply

« [How-To] Simple hack development stages | [How-To] Validate fields or extract information using regular expressions »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Rules

Similar Threads
Thread Thread Starter Forum Replies Last Post
[How-To] Advanced hack modification development stages - Guide #1 Idan vBulletin Modification Tutorials 3 06-24-2009 08:03 AM
[How To] Add Options per forum Ken Iovino vBulletin Modification Tutorials 10 03-03-2007 06:25 PM



All times are GMT. The time now is 05:24 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.
Transverse Styles
  • Top
  • Archive
  • vBSEO
  • Contact Us
LinkBack
LinkBack URL LinkBack URL
About LinkBacks About LinkBacks
Bookmark & Share
Digg this Thread! Digg this Thread!
Add Thread to del.icio.us Add Thread to del.icio.us
Bookmark in Technorati Bookmark in Technorati
Furl this Thread! Furl this Thread!