1
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:
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; ?>: |
|
} 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!