".$keyword.""; $var .= $replacement." "; $str = str_ireplace($keyword, $replacement, $str); } /* Apply Important Style */ $str = str_ireplace(rtrim($var), "".$keywords."", $str); return $str; } //phpinfo(32); // handle new searches $results =''; $adv = '
'; if (isset($_GET["search"]) || (isset($_POST["submit"]) && $_POST["submit"] == 'search' && !empty($_POST["term"])) ) { // get the current time $now = date("Y-m-d H:i:s"); // get the submitted term and prepare it for the database query if(isset($_GET["search"])) $term = mysql_real_escape_string(strip_tags(trim($_GET['search']))); else $term = mysql_real_escape_string(strip_tags(trim($_POST['term']))); $searchTerms = explode(' ', $term); $searchTermBits = array(); foreach ($searchTerms as $terms) { $terms = trim($terms); if (!empty($terms)) { $searchTermBits[] = "content LIKE '%$term%' OR title LIKE '%$term%' OR tags LIKE '%$term%' OR keywords LIKE '%$term%' "; } } $sql = "SELECT * FROM `news` WHERE `lang`= '".$language."' AND ( ".implode(' OR ', $searchTermBits)." )"; //echo $sql; $result = $db->query($sql); $skaits = $result->size(); $nr=1; while ($row = $result->fetch()) { $arr_menu = explode (",", ltrim($row['for_menu'],',') ); if(!empty($arr_menu[0])) $idMenu=$arr_menu[0]; //nosakam kads ID ir pirmais ierakstits attiecigajam rakstam else $idMenu=4;//gadijuma ja nav defineta nodaļa tad uz ALL menu //echo $idMenu.' / '.$row['for_menu']; $sql_menu = "SELECT `seo_".$language."` as seo_name FROM `menu` where `ID`='".$idMenu."'"; //meklejam menu ID $result_menu = $db->query($sql_menu); while ($row_menu = $result_menu->fetch()) { $menu_name=$row_menu['seo_name']; } $article_title=strip_tags(htmlspecialchars_decode($row['title'])); $article_title_seo=$row['seo_title']; $article_link=''; $article_content=getFirstSentence($row['content']); $article[] = '
'; $article[] = $article_link.'

'.hightlight($article_title, $term).'

'.$nr.' '.hightlight($article_content, $term).' '.$article_link.'['.txt_read_more.']

';//'.$row['datums'].' | if($nr == 2 || $nr == 10 || $nr==20) $article[] = $adv; $nr=$nr+1; //$article[] = '
'; } $article[] = '
'; echo join('',$article); if($skaits>0) { // parbaudam vai ir meklets iepriekš if (mysql_result(mysql_query("SELECT COUNT(id) FROM search WHERE term = '$term' AND language = '".$language."'"), 0) > 0) { // the term exists - update the counter and the last search timestamp mysql_query("UPDATE search SET counter = counter+1, last_search = '$now' WHERE term = '$term'"); } else { // the term does not exist - insert a new record mysql_query("INSERT INTO search (term, last_search, language) VALUES ('$term', '$now', '".$language."')"); } } else{ // if there is no matching rows do following mysql_query("INSERT INTO search_bad (term, last_search, language, success) VALUES ('$term', '$now', '".$language."', 1)"); //neveigsmigs meklejums echo '

'.txt_no_results.'

'; } } ?>