// BlogSearchResults - Version 1.0 // Snippet by Henning Mersch // See http://www.henning-mersch.de/snippets.html // Open Source in terms of the GPLv2; see http://www.gnu.org/licenses/gpl.html // This searches a blog table for a given keyword in heading or body text of the entries // Example [ [BlogSearchResults?table=someExternal] ] // The search term is provided by _POST, thus it could be used with SearchForm / SearchResult provided with Etomite. // This is a combination of the snippet 'SearchResults' (part of Etomite distribution) and // parts of the snippet 'NewBlogger' (by Tina Krausser, see http://tina.krausser.net/blogSnippets.html). //Configuration parameters ////////////////////////////////////////////// //configure: The base page of the blog - for linking. $htmlPage = "blog.html"; // Show this if nothing is found: $noResults = '
Additionally, no blog entries match the request.

'; // Show this as header for found matches $resultsText = '
Additionally, these blog entries match the request:

'; //Parameter Parsing (you could change defaults blow this) //////////////////////////////////////////////////////////////////////// //PARAMETER: entries from which authors should be displayed // example: "wizard_OR_igel" returns all entries from wizard and all entries from igel // the keyword "_ALL_" in the string overwrites all other settings and entries from all authors are displayed $showEntriesFromAuthors = isset($showEntriesFromAuthors) ? $showEntriesFromAuthors : "wizard_OR_hmersch_OR_stachelzauberer"; //PARAMETER: date format if (!isset($dateFormat)){ $dateFormat = "l d.m.y"; // Monday 20.10.05 } //***************************************************************************************// // Database settings // Database table to use for storage // entries will be grouped by author and/or category so multiple blogs can use one table //***************************************************************************************// $db = isset($db)?$db:'etShared'; $table = isset($table)?$table:'externalTable'; $dbUser = isset($dbUser)?$dbUser:'etomite'; $dbPWD = isset($dbPWD)?$dbPWD:'xxx'; $host = isset($host)?$host:'localhost'; // START PROCESSING //!!! No Changes blow should be required !!! ////////////////////////////////////////////////////////////////// // if _ALL_ is a part of the author string then entries from all all authors should be // displayed, hence, the categorySelector must be empty $pos = strpos($showEntriesFromAuthors, "_ALL_"); if ($pos === false) { $auths = split('_OR_',$showEntriesFromAuthors); foreach ($auths as $auth){ $authorSelector = isset ($authorSelector) ? $authorSelector." OR author LIKE '%".$auth."%'" : "author LIKE '%".$auth."%'"; } } else { //$authorSelector = ""; } $searchString = isset($_POST['search']) && $_POST['search']!= "{{" && $_POST['search']!= "[[" && $_POST['search']!= "[(" && $_POST['search']!= "[~" && $_POST['search']!= "[*" ? $_POST['search'] : "" ; if(isset($_POST['search']) && $_POST['search']!='') { $search = explode(" ", $_POST['search']); $sql = "SELECT * FROM " . $table . " WHERE (text LIKE '%".$search[0]."%'"; for ($x=1;$x < count($search); $x++) { $sql .= " AND text like '%$search[$x]%'"; } $sql .= " OR title LIKE '%".$search[0]."%' "; for ($x=1;$x < count($search); $x++) { $sql .= " AND title like '%$search[$x]%'"; } if(isset($authorSelector)) $sql .= ") AND ($authorSelector"; $sql.=") ORDER BY date DESC"; //$rs = $etomite->dbQuery($sql); //DEBUG: $SearchForm .= "SQL Query:".$sql; $rs = $etomite->dbExtQuery($host, $dbUser, $dbPWD, $db, $sql); $limit = $etomite->recordCount($rs); if($limit>0) { $SearchForm .= $resultsText; for ($y = 0; $y < $limit; $y++) { $entry=$etomite->fetchRow($rs); $title = ''.htmlentities(stripslashes($entry['title'])).''; $dateText = "".date($dateFormat,strtotime($entry['date'])).""; $SearchForm .= "
$title $dateText

"; } //$SearchForm .= ""; } else { $SearchForm .= $noResults; } } return $SearchForm;