1
rlankford
Local Search Block
  • 2007/3/26 20:45

  • rlankford

  • Not too shy to talk

  • Posts: 158

  • Since: 2004/8/27


This may be somewhere else, but I thought I would post this for anyone who might be interested:

Situation:
You're users want to be able to search on a module-by-module basis. But they don't like having to navigate to search.php and selecting the module first. Rather, they just want to search directly from within each module for content only within that module.

This can be accomplished with the following. Create a new block called "Local Search" that looks like this:

Resized Image

Now, plug the following code into the block:

global $xoopsModule, $xoopsConfig;
$currentModuleName = "Not in a module!";
$currentModuleID = 0;

if (isset($xoopsModule) and is_object($xoopsModule)) {
    if ($xoopsModule->getVar('hassearch')) {
        $currentModuleName = $xoopsModule->getVar('name');
        $currentModuleID = $xoopsModule->getVar('mid');
        
        ?>
        
        
          Search echo $currentModuleName?>
        
        
          
            echo XOOPS_URL?>/search.php" method="get">
              
              
              echo $currentModuleID ?>' checked='checked' />module could go here, but we don't care

              
            
          
        
        
            } else {
        echo 
"Local Search Not Available.";
    }
}


That's it! Now you'll get a "Local Search" block on every page. For pages inside a particular module, entering a search term will call search.php and limit it only to that module. On pages that aren't apart of any specific module, the user will just see a message indicating that the local search feature isn't currently available.

Enjoy!



Edit: After having thought about it for a few minutes, it would work better if I took into account the 'hasSearch' parameter in xoops_version.php for each of the modules. I've updated the code in this post to now account for this. So, now you'll get the "Local Search Not Available" message when clicking on modules that do not support search (like polls or contact us). My earlier code would try to support the search on any page that was in a module (vs. search.php -- which is not in any module). But now it'll at least ensure that the module supports search before jumping in!

2
vaughan
Re: Local Search Block
  • 2007/3/26 20:58

  • vaughan

  • Friend of XOOPS

  • Posts: 680

  • Since: 2005/11/26


thanks again, you're getting pretty regular with these small but very useful features :) great work.

ps. i sent you a pm over at smartfactory.

3
Anonymous
Re: Local Search Block
  • 2007/3/26 21:08

  • Anonymous

  • Posts: 0

  • Since:


This I must try tomorrow - thank you

I'm thinking "Site Search" on the homepage, local search on the module pages.......

Login

Who's Online

241 user(s) are online (162 user(s) are browsing Support Forums)


Members: 0


Guests: 241


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits