convert($q)); echo strtr($TEMPLATE["HEADING"],$replace); flush(); $query = convert($q); if ($query){ $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password); mysql_select_db($mysql_database, $bd); $array_query = split(" ",$query); $stop_words = array ("a","by","from","of","on","to","an","for","in","the","with","and","not","or","same"); function non_stop_words($var){ global $stop_words; return !in_array($var,$stop_words); }; $array_query = array_filter($array_query, "non_stop_words"); rsort($array_query); $sentence = "SELECT {$prefix}pages.id, {$prefix}pages.url, {$prefix}pages.title, {$prefix}pages.description, {$prefix}pages.keywords, {$prefix}pages.accepted, {$prefix}pages.ip, {$prefix}pages.category, {$prefix}categories.name AS category_name FROM {$prefix}pages, {$prefix}categories WHERE {$prefix}categories.id = {$prefix}pages.category"; for ($x = 0; $x < min(4,count($array_query)); $x++){ if ($x == 0){ $sentence .= " AND (";}; $sentence .= " {$prefix}pages.title LIKE '%{$array_query[$x]}%' OR {$prefix}pages.keywords LIKE '%{$array_query[$x]}%' OR {$prefix}pages.description LIKE '%{$array_query[$x]}%' OR {$prefix}pages.url LIKE '%{$array_query[$x]}%'"; if ($x != min(4,count($array_query))-1){ $sentence .= " OR "; }else{ $sentence .= ")"; }; }; $sql = mysql_query($sentence); $n_results = mysql_num_rows($sql); if ($n_results > 0){ $query2 = implode(" ",$array_query); for ($x = 0; $x < $n_results; $x++){ $results[$x] = mysql_fetch_array($sql, MYSQL_ASSOC); $results[$x]["score"] = match(convert($results[$x]["title"]),$query2,40) + match(convert($results[$x]["keywords"]),$query2,30) + match(convert($results[$x]["description"]),$query2,20) + match(convert($results[$x]["url"]),$query2,10); if ($results[$x]["score"] > 0){ $n_pages += 1; $pages[$n_pages-1] = $results[$x]; }; }; if ($n_pages > 1){ usort($pages,"sort_results"); }; }; mysql_close(); if ($show_additional_results){ flush(); require_once("include_ppc.php"); $ppc_results = ppc_results(ucwords(convert($q))); $total_pages += count($ppc_results); for ($x = 1; $x <= count($ppc_results); $x++){ $n_pages += 1; $pages[$n_pages-1] = $ppc_results[$x]; }; $e = min($s + $n - 1, (int) $n_pages); }; }; if ($s == 0) $s = 1; $n = 10; $e = min($s + $n - 1, (int) $n_pages); if ($n_pages > 0){ $replace = array("[STARTING_PAGE_NUMBER]" => $s, "[ENDING_PAGE_NUMBER]" => $e, "[TOTAL_PAGES]" => $n_pages, "[SEARCH_TERM]" => convert($q)); echo strtr($TEMPLATE["PAGES"]["HEADING"],$replace); for ($x = $s-1; $x < $e; $x++){ if ($pages[$x]["category"] > 1){ $category_url = $dir.'index.php?c='.$pages[$x]["category"]; }else{ $category_url = $dir; }; if ($pages[$x]["domain"]){ $replace = array("[PAGE_NUMBER]" => $x, "[PAGE_TITLE]" => $pages[$x]["title"], "[PAGE_DESCRIPTION]" => $pages[$x]["description"], "[PAGE_URL]" => $pages[$x]["url"], "[PAGE_DOMAIN]" => $pages[$x]["domain"], "[CATEGORY_NAME]" => $pages[$x]["category_name"], "[CATEGORY_URL]" => $category_url); echo strtr($TEMPLATE["PAGES"]["FEED_PAGE"],$replace); }else{ $replace = array("[PAGE_NUMBER]" => $x, "[PAGE_TITLE]" => $pages[$x]["title"], "[PAGE_DESCRIPTION]" => $pages[$x]["description"], "[PAGE_URL]" => $pages[$x]["url"], "[CATEGORY_NAME]" => $pages[$x]["category_name"], "[CATEGORY_URL]" => $category_url); echo strtr($TEMPLATE["PAGES"]["PAGE"],$replace); }; }; if ($s != 1 || $e != $n_pages){ function pagination($s){ global $q, $dir; $query = $dir.'search.php?q='.urlencode(convert($q)); if ($s > 1) $query .= '&s='.$s; return $query; }; echo $TEMPLATE["PAGES"]["PAGINATION"]["HEADING"]; if ($s != 1){ $previous = $s - $n; $replace = array("[PAGINATION_URL]" => pagination($previous)); echo strtr($TEMPLATE["PAGES"]["PAGINATION"]["PREVIOUS"],$replace); }; for ($x = 1; $x <= ceil($n_pages/$n); $x++){ $current = ($x-1) * $n + 1; if ($current == $s){ $replace = array("[PAGINATION_NUMBER]" => $x); echo strtr($TEMPLATE["PAGES"]["PAGINATION"]["CURRENT_NUMBER"],$replace); }else{ $replace = array("[PAGINATION_NUMBER]" => $x, "[PAGINATION_URL]" => pagination($current)); echo strtr($TEMPLATE["PAGES"]["PAGINATION"]["NUMBER"],$replace); }; }; if ($e < $n_pages){ $next = $s + $n; $replace = array("[PAGINATION_URL]" => pagination($next)); echo strtr($TEMPLATE["PAGES"]["PAGINATION"]["NEXT"],$replace); }; echo $TEMPLATE["PAGES"]["PAGINATION"]["FOOTER"]; }; echo $TEMPLATE["PAGES"]["FOOTER"]; }else{ $replace = array("[SEARCH_TERM]" => convert($q)); echo strtr($TEMPLATE["PAGES"]["NO_PAGES"],$replace); }; echo $TEMPLATE["FOOTER"]; ?>