Module with Search in HTML

Date 2004/4/12 20:01:26 | Topic: Hacks

I am starting in the XOOPS now and therefore I opted to using static pages and deriving data of mysql. First I did not try to use tinycontent, cjaycontent and etc, but it was not what I wanted. Then observing other codes I implemented a module that shows my pages HTML. The problem was when I gave for account that the SEARCH did not function. I looked in several forums. Some said that solution did not exist, others said to use tinycontent and etc. Then, giving for satisfied I did not decide me I myself to implement my SEARCH in HTML. The solution is adopted is simple consists of:

1 - To define tags assistant of the research in the pages htmls. Is they:

<!-- HTMLSEARCH-TITLE="Its Heading HERE" -->
<!-- HTMLSEARCH-LINK="The Link for the page" -->
The to be looked for text goes HERE

What it must be made is to include these tags in page HTML, can be included how many blocks will be necessary. To observe that it must have Título (HTMLSEARCH-TITLE), Link (HTMLSEARCH-LINK) and only to be definite the beginning (HTMLSEARCH-BEGIN-SEARCH) and the end (HTMLSEARCH-END-SEARCH) of the text where the research will be become fullfilled.

2 - To include in the archive xoops_version.php of the module in question the necessary information for the SEARCH.

// Search
$modversion['hasSearch'] = 1;
$modversion['search']['file'] =
$modversion['search']['func'] = "yourmodule_search";

3 - To inside create of the directory include of its module the archive Inside it must contain the function seumodulo_search(). It is function must return an Array where each line of the Array is an joined item.

$ret[$i]['image'] = $image;
$ret[$i]['link'] = $link;
$ret[$i]['title'] =
$ret[$i]['uid'] = 1;
$ret[$i]['time'] = filemtime($dir . $file);

The function yourmodule_search() covers archives HTML identifies tags of item 1. E returns the result in the Array. Below it follows my function of search. It verifies all the archives of a directory.


function produtos_search($queryarray, $andor, $limit, $offset, $userid){

$ret =
$i = 0;
$k = 0;

// dir to search
$dir =

$image = "images/menu_pe15x17.gif";

if (is_dir($dir)) {
if ($dh = opendir($dir)) {
((($file = readdir($dh)) !== false) && ($i < $limit)) {
if (!is_dir($dir . $file)) {
$array_tmp = file($dir .

$found = false;
$beginsearch = false;
foreach($array_tmp as $v) {

if (substr_count($v,'HTMLSEARCH-TITLE')>=1) {
$begin = strpos($v,
$end = strrpos($v, '"');

$title =
} elseif (substr_count($v,'HTMLSEARCH-LINK')>=1) {

$begin = strpos($v, '"')+1;
$end = strrpos($v, '"');

$link =
} elseif (substr_count($v,'HTMLSEARCH-BEGIN-SEARCH')>=1) {

$text2search = "";
if ($k > $offset)
$beginsearch =
} elseif ((substr_count($v,'HTMLSEARCH-END-SEARCH')>=1) && $beginsearch) {

$text2search = strtoupper($text2search);
if ( is_array($queryarray) && $count = count($queryarray) ) {

if (strpos($text2search,strtoupper(htmlentities($queryarray[0]))) ||
$found = true;

if ($andor == 'AND') {
(strpos($text2search,strtoupper(htmlentities($queryarray[$j]))) ||
$found = $found && true;

$found = $found && false;
} else { // OR

if (strpos($text2search,strtoupper(htmlentities($queryarray[$j]))) ||
$found = $found || true;

$found = $found || false;

$beginsearch = false;

if ($beginsearch) {
$text2search = $text2search.$v;

if ($found) {
$ret[$i]['image'] = $image;
$ret[$i]['link'] = $link;

$ret[$i]['title'] = $title;
$ret[$i]['uid'] = 1;

$ret[$i]['time'] = filemtime($dir . $file);
$found = false;

if ($i >= $limit)


If to want to see the Module in action is alone to go in link: the module of "Produtos" has this implemented code. They see the code of the pages in HTML will have doubts as to place tags. I wait suggestions to optimize the code, as, for example, the code of htmlentities was very bad, to perhaps use regular expressions to find tags and the words to be searched would be better. Well, more ai is to the idea now is alone to share to be able improves it Suggestions will be comings well.


This article comes from XOOPS Web Application System

The URL for this story is: