Maak een snippet die je bijvoorbeeld FlexSearchForm noemt. Dit is de code.
// -----------------------
// Snippet: ExtraFlexSearchForm
// -----------------------
// Version: 0.6c
// Date: 2004.12.22
//sam@snappygraffix.com
// jaredc@honeydewdesign.com
//
// This snippet was designed to create a search form
// that is highly flexible in how it is presented. It
// can be used as both a small, subtle, persistent
// search field element, as well as present the search
// results. All elements are branded with classes/id's
// for easy CSS styling.
// It was extended by Rich from Snappy Graffix Media to
// allow partial matching and LIKE matching of the search term.
// Configure
// $searchButtonText [string]
// Label the search button what
// you wish
$searchButtonText = 'Zoek!';
// $showSearchWithResults [1 | 0]
// If you would like to turn off the search
// form when showing results you can set
// this to false. Can also be set in template
// by using the snippet variable: FSF_showForm
// like this (1=true, 0=false):
// [[FlexSearchForm?FSF_showForm=0]]
$showSearchWithResults = 1;
// $resultsPage [int]
// The default behavior is to show the results on
// the current page, but you may define the results
// page any way you like. The priority is:
//
// 1- snippet variable - set in page template like this:
// [[FlexSearchForm?FSF_landing=int]]
// where int is the page id number of the page you want
// your results on
// 2- querystring variable FSF_form
// 3- variable set here
// 4- use current page
//
// This is VERY handy when you want to put the search form in
// a discrete and/or small place on your page- like a side
// column, but don't want all your results to show up there!
// Set to results page or leave 0 as default
$resultsPage = 0;
// $showResults [1 | 0] (as passed in snippet variable ONLY)
// You can define whether this snippet will show the results
// of the search with it. Do this by assigning the snippet
// variable FSF_showResults as:
// [[FlexSearchForm?FSF_showResults=0]]
//
// This is useful in situations where you want to show the
// search results in a different place than the search form.
// In that type of situation, you would include two of these
// snippets on the same page, one showing results, and one
// showing the form.
//
// Default is true.
// $resultsIntroFailure
// If nothing is found for the search. You should give the user
// some indication that the search was a failure.
$resultsIntroFailure = 'Er zijn geen zoekresultaten. Probeer een algemenere term of probeer een zoekmachine om op het hele internet te zoeken.';
// $grabMax [ int ]
// Set to the max number of records you would like on
// each page. Set to 0 if unlimited.
$grabMax = 14;
// $pageLinkSeparator [ string ]
// What you want, if anything, between your page link numbers
$pageLinkSeparator = " | ";
// Styles
// These styles are included in this snippet:
//
// #FSF_form{}
// #FSF_input {}
// #FSF_submit {}
//
// #FSF_SearchResults {}
// #FSF_resultsIntroFailure{}
// .FSF_result {}
// .FSF_resultLink {}
// .FSF_resultDescription {}
// .FSF_pagination
// .FSF_searchString
// -------------
// End configure
// -------------
// establish whether to show the form or not
$showSearchWithResults = (isset($FSF_showForm))? $FSF_showForm : $showSearchWithResults;
// establish whether to show the results or not
$showResults = (isset($FSF_showResults))? $FSF_showResults : true;
// establish results page
if ($resultsPage > 0){ // locally set
$searchAction = "[~".$resultsPage."~]";
} elseif (isset($FSF_landing)){ // set in snippet
$searchAction = "[~".$FSF_landing."~]";
} else { //otherwise
$searchAction = "[~".$etomite->documentObject['id']."~]";
}
// block sensitive search patterns
$searchString =
isset($_POST['search']) &&
$_POST['search']!= "{{" &&
$_POST['search']!= "[[" &&
$_POST['search']!= "[(" &&
$_POST['search']!= "[~" &&
$_POST['search']!= "[*" ?
$_POST['search'] : "";
// check querystring
$searchString = (isset($_GET['FSF_search']))? urldecode($_GET['FSF_search']): $searchString;
$validSearch = ($searchString != '')? true : false;
//check for offset
$offset = (isset($_GET['FSF_offset']))? $_GET['FSF_offset'] : 0;
// establish form
if (($validSearch && ($showSearchWithResults)) || $showSearchWithResults){
$SearchForm .= '<form style="margin-bottom:0; id="FSF_form" name="SearchForm" action="'.$searchAction.'" method="post">';
$SearchForm .= '<input id="FSF_input" type="text" name="search" value="'.$searchString.'" />';
$SearchForm .= '<input id="FSF_submit" type="submit" name="sub" value="'.$searchButtonText.'" />';
$SearchForm .= '</form>'."";
}
if ($showResults) {
if($validSearch) {
$search = explode(" ", $searchString);
$tbl = $etomite->dbConfig['dbase'] . "." . $etomite->dbConfig['table_prefix'] . "site_content";
$sql = "SELECT id, pagetitle, description ";
$sql .= "FROM $tbl ";
$sql .= "WHERE (pagetitle LIKE '%$searchString%' OR description LIKE '%$searchString%' OR content LIKE '%$searchString%') ";
$sql .= "AND $tbl.published = 1 AND $tbl.searchable=1 AND $tbl.deleted=0;";
// $sql = "SELECT id, pagetitle, description ";
// $sql .= "FROM $tbl ";
// $sql .= "WHERE MATCH($tbl.pagetitle, $tbl.description, $tbl.content) AGAINST('$searchString*') ";
// $sql .= "AND $tbl.published = 1 AND $tbl.searchable=1 AND $tbl.deleted=0;";
$rs = $etomite->dbQuery($sql);
$limit = $etomite->recordCount($rs);
if($limit>0) {
$SearchForm .= '<div id="FSF_searchResults">'." ";
// pagination
if ($grabMax > 0){
$numResultPages = ceil($limit/$grabMax);
$resultPageLinks = '<span class="FSF_pages">Resultaat pagina';
$resultPageLinks .= ($limit>$grabMax)? ': ': ': ';
$resultPageLinkNumber = 1;
for ($nrp=0;$nrp<$limit;$nrp+=$grabMax){
if($offset == ($resultPageLinkNumber-1)*$grabMax){
$resultPageLinks .= $resultPageLinkNumber;
} else {
$resultPageLinks .= '<a href="[~' . $etomite->documentObject['id'] . '~]&FSF_offset=' . $nrp . '&FSF_search=' . urlencode($searchString) . '"> ' . $resultPageLinkNumber . '</a> ';
}
$resultPageLinks .= ($nrp+$grabMax < $limit)? $pageLinkSeparator : '';
$resultPageLinkNumber++;
}
$resultPageLinks .= " </span>";
$SearchForm .= '<p class="FSF_pagination">'.$limit.' Pagina';
$SearchForm .= ($limit>1)?'`s' :'';
$SearchForm .= ' gevonden voor "<span class="FSF_searchString">'.$searchString.'</span>". '.$resultPageLinks."</p>";
}
// search results
$useLimit = ($grabMax > 0)? $offset+$grabMax : $limit;
for ($y = $offset; ($y < $useLimit) && ($y<$limit); $y++) {
$moveToRow = mysql_data_seek($rs,$y);
$SearchFormsrc=$etomite->fetchRow($rs);
$SearchForm.='<div class="FSF_result">'."";
$SearchForm.='<a class="FSF_resultLink" href="[~'.$SearchFormsrc['id'].'~]" title="' . $SearchFormsrc['pagetitle'] . '"> ' . $SearchFormsrc['pagetitle'] . "</a> ";
$SearchForm.=$SearchFormsrc['description']!='' ? '<span class="FSF_resultDescription"> | <i>' . $SearchFormsrc['description'] . "</i></span>" : "";
$SearchForm.='</div><!--end FlexSearchResult-->'."";
}
$SearchForm.='<p class="FSF_pagination">'.$resultPageLinks.'</p>';
$SearchForm.='</div><!--end FlexSearchResults-->'."";
} else {
$SearchForm.='<p id="FSF_resultsIntroFailure">'.$resultsIntroFailure.'</p>';
}
}
}
return $SearchForm;
Standaard roep je de zoekmachine aan via de snippet [[FlexSearchForm]] Er zijn meer opties. Die zal ik hier later plaatsen, moet nu heel snel even door met mijn werk.... Baas boos!










