copy-paste and update of original search action.
displays pagenames and lines in page where the phrase was found.
new param – clean, if true – omits the phrase from result lines.
by pkmk
mailto:salna@ktl.mii.lt
bugs:0001283
/actions/searchline.php
<?php
if (($topic == 1) || ($title == 1)) $mode = "topic"; else $mode = "full";
if ($_REQUEST["topic"] == "on") $mode = "topic";
//if (!$delim) $delim="---";
if (!in_array($style,array("br","ul","ol","comma"))) $style="ol";
$i = 0;
if ($filter!="pages") $filter = "all";
if (!isset($clean)) $clean = false;
if ($vars[0] != "") $phrase = $vars[0]; else { $phrase=""; $form=1; }
if ($phrase == "") $phrase = $_REQUEST["phrase"];
if ($phrase)
{
if (strlen($phrase)>2)
{
if ($mode == "topic") $results = $this->TagSearch($phrase);
else $results = $this->FullTextSearchWithBody($phrase, ($filter=="all"?0:1));
$phrase = htmlspecialchars($phrase);
if ($results)
{
if (!$nomark) print( "<fieldset><legend><strong>".
$this->GetResourceValue(($mode=="topic"?"Topic":"")."SearchResults").
" \"$phrase\":</strong></legend>");
if ($style=="ul") print "<ul class=\"SearchResults\">\n";
if ($style=="ol") print "<ol class=\"SearchResults\">\n";
foreach ($results as $page)
if (!$this->config["hide_locked"] || $this->HasAccess("read",$page["tag"]) && $page["tag"] != $this->getPageTag() )
{
if ($style=="ul" || $style=="ol") print "<li>";
if ($style=="comma" && $i>0) print ",\n";
print($this->Link("/".$page["tag"],"",$page["tag"]));
print(" " . getLineWithPhrase($phrase, $page["body"], $clean));
if ($style=="br") print "<br />\n";
if ($style=="ul" || $style=="ol") print "</li>\n";
$i++;
}
if ($style=="ul") print "</ul>";
if ($style=="ol") print "</ol>";
if (!$nomark) print("</fieldset>");
}
else
if (!$nomark) echo $this->GetResourceValue("NoResultsFor")."\"$phrase\".";
}
else
if (!$nomark) echo $this->GetResourceValue("NoResultsFor")."\"$phrase\".";
}
function getLineWithPhrase($phrase, $string, $cleanup)
{
$lines = split("\n", $string);
$result = "";
foreach ($lines as $line)
{
if (strpos($line, $phrase))
{
if ($result) $result .= "<br/>\n";
$result .= $cleanup ? str_replace("$phrase", "", $line) : $line;
}
}
return $result;
}
?>
update to wacko.php
<?
function FullTextSearchWithBody($phrase,$filter) { return $this->LoadAll("select ".$this->pages_meta.", body from ".$this->config["table_prefix"]."pages where latest = 'Y' and (( match(body) against('".quote($phrase)."') or lower(tag) like lower('%".quote($phrase)."%')) ".($filter?"and comment_on=''":"")." )"); }
?>