1 - To define tags assistant of the research in the pages htmls. Is they:
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'] =
"include/search.inc.php";
$modversion['search']['func'] = "yourmodule_search";
3 - To inside create of the directory include of its module the archive search.inc.php. 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'] =
$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 =
array();
$i = 0;
$k = 0;
// dir to search
$dir =
"modules/produtos/templates/";
$image = "images/menu_pe15x17.gif";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while
((($file = readdir($dh)) !== false) && ($i < $limit)) {
if (!is_dir($dir . $file)) {
$array_tmp = file($dir .
$file);
$found = false;
$beginsearch = false;
foreach($array_tmp as $v) {
if (substr_count($v,'HTMLSEARCH-TITLE')>=1) {
$begin = strpos($v,
'"')+1;
$end = strrpos($v, '"');
$title =
trim(substr($v,$begin,$end-$begin));
} elseif (substr_count($v,'HTMLSEARCH-LINK')>=1) {
$begin = strpos($v, '"')+1;
$end = strrpos($v, '"');
$link =
trim(substr($v,$begin,$end-$begin));
} elseif (substr_count($v,'HTMLSEARCH-BEGIN-SEARCH')>=1) {
$text2search = "";
$k++;
if ($k > $offset)
$beginsearch =
true;
} 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]))) ||
strpos(strtoupper(htmlentities($title)),strtoupper(htmlentities($queryarray[0]))))
$found = true;
for($j=1;$j<$count;$j++){
if ($andor == 'AND') {
if
(strpos($text2search,strtoupper(htmlentities($queryarray[$j]))) ||
strpos(strtoupper(htmlentities($title)),strtoupper(htmlentities($queryarray[$j]))))
$found = $found && true;
else
$found = $found && false;
} else { // OR
if (strpos($text2search,strtoupper(htmlentities($queryarray[$j]))) ||
strpos(strtoupper(htmlentities($title)),strtoupper(htmlentities($queryarray[$j]))))
$found = $found || true;
else
$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);
$i++;
$found = false;
if ($i >= $limit)
break;
}
}
unset($array_tmp);
}
}
closedir($dh);
}
}
return
$ret;
}
?>
If to want to see the Module in action is alone to go in link:
http://ciaandarilhos.cordeiropereira.com.br 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.
Ulisses