execute($sql); //keep only 5 last keywords $sql = "SELECT id FROM last_keywords ORDER BY search_date DESC LIMIT 5"; $res = $mysql->fetch($sql); $ids = array(); foreach($res as $r){ array_push($ids, $r['id']); } $sql = "DELETE FROM last_keywords WHERE id NOT IN (".implode(',', $ids).")"; $mysql->execute($sql); } if ($_GET["t"] == 1) { } elseif ($_GET["t"] == 2) { $query_sql = "SELECT quotes.*, authors.* FROM quotes INNER JOIN authors ON quotes.authorid = authors.id WHERE quotes.quote LIKE '%".$_GET["w"]."%'"; } elseif ($_GET["t"] == 3) { $query_sql = "SELECT * FROM cats WHERE name LIKE '%".$_GET["w"]."%'"; } elseif ($_GET["t"] == 4) { } $params["w"] = $_GET["w"]; $code_authors = $mysql->getval('banners', 'code', "name LIKE '%".AUTHORS_BANNER_NAME."%'"); if ($_GET["t"] == 1 || $_GET["t"] == 2) { $query_sql = "SELECT quotes.*, authors.*, authors.id as authorid FROM quotes INNER JOIN authors ON quotes.authorid = authors.id WHERE quotes.quote LIKE '%".$_GET["w"]."%'"; $result = $mysql->fetch($query_sql." LIMIT ".(($page - 1 ) * $pagesize).", ". $pagesize); $total = mysql_num_rows($mysql->q($query_sql, true)); $params["total"] = $total; if (!count($result)){ $params['banner'] = $code; $template->assign_vars($params); $template->pparse("no_results"); exit(0); } $query_sql = "SELECT quotes.*, authors.*, authors.id as authorid FROM quotes INNER JOIN authors ON quotes.authorid = authors.id WHERE (firstname LIKE '%rdtak%' OR lastname LIKE '%rdtak%') AND quotes.quote LIKE '%".$_GET["w"]."%'"; $result_ordtak = $mysql->fetch($query_sql); $authors = array(); $categories = array(); foreach ($result_ordtak as $key=>$res) { array_push($authors, $res["authorid"]); } $b = 1; foreach ($result as $key=>$res) { $param["quote"] = $res["quote"]; $param["author"] = "{$res["lastname"]} {$res["firstname"]}"."" ; $cats = array(); for ($i = 0; $i < 5; $i++){ if (!$res["cat$i"]) continue; //slowly, can decrease perfomance $sql = "SELECT name FROM cats WHERE id = {$res["cat$i"]}"; $cat = $mysql->fetch($sql); if (empty($cat[0]['name'])) continue; array_push($cats, "".ucfirst(strtolower($cat[0]['name'])).""); } $param['banner'] = null; // first google ads banner if($b == QUOTES_BANNER_AFTER){ $code = $mysql->getval('banners', 'code', "name LIKE '%".QUOTES_BANNER_NAME."%'"); $param['banner'] = $code; } // put google ads banner after 10 quotes if(count($result)!= 10 && $b == 10){ $code = $mysql->getval('banners', 'code', "name LIKE '%".QUOTES_BANNER_NAME."%'"); $param['banner'] = $code; } if((count($result)<=$SECOND_BANNER_AFTER && $b == count($result)) || $b == $SECOND_BANNER_AFTER){ $SECOND_BANNER_AFTER += 10; $code = $mysql->getval('banners', 'code', "random = '1' order by rand() limit 1"); $param['banner'] = $code; } // put the google ads banner at the bottom af page if there is not enough quotes if(count($result) == $b && count($result) < QUOTES_BANNER_AFTER && $b != 10){ $code = $mysql->getval('banners', 'code', "name LIKE '%".QUOTES_BANNER_NAME."%'"); $param['banner'] = $code; } $b++; $param["categories"] = implode(' - ', $cats); $template->assign_block_vars("quote", $param); } $authors = array_unique($authors); $categories_text = ""; $authors_heading = $authors_text = ""; $first_letter_author = 'O'; if (!empty($_GET['la']) && strpos($alphabet, urldecode($_GET['la'])) !== false){ $first_letter_author = urldecode($_GET['la']); } //sorry, this is crap, i know :( $sql_authors = "SELECT id, firstname, lastname FROM authors WHERE lastname LIKE '$first_letter_author%' AND id IN (0"; $sql_authors_all = "SELECT SUBSTRING(lastname, 1, 1) AS firstletter FROM authors WHERE SUBSTRING(lastname, 1, 1)!=' ' AND INSTR('$alphabet', UPPER(SUBSTRING(lastname, 1, 1))) > 0 AND id IN (0"; $sql_categories = "SELECT id, name FROM cats WHERE name LIKE '%".addslashes($_GET["w"])."%'"; foreach ($authors as $part){ $sql_authors .= "," . $part; $sql_authors_all .= "," . $part; } $sql_authors .= ") ORDER BY lastname ASC, firstname ASC LIMIT ".AUTHORS_SHOW; $sql_authors_all .= ") GROUP BY firstletter"; $sql_categories .= " ORDER BY name ASC LIMIT ".AUTHORS_SHOW; $letters = array(); $result = $mysql->fetch($sql_authors_all); foreach($result as $res){ array_push($letters, $res['firstletter']); } for ($i = 0; $i" . $alphabet[$i] . ""; } } $result = $mysql->fetch($sql_authors); foreach($result as $res){ $authors_text .= "{$res['firstname']} {$res['lastname']} "; } $letters = array(); $result = $mysql->fetch($sql_categories); foreach($result as $res){ $categories_text .= "{$res['name']}"; } $params["categories"] = $categories_text; $params['authors_banner'] = $code_authors; $params["authors"] = $authors_text; $params["authors_heading"] = $authors_text?$authors_heading:null; $params["authors_title"] = $authors_text?"Treff i ordtak:":""; $params['categories_title'] = $categories_text?"Treff i kategorier med ordet {$_GET['w']}:":""; ob_start(); $paging = new paging($page, $total, $pagesize); $paging->setTitle(""); $paging->setNPlinks(false); $paging->setFormat("?page=%d&t=1&w={$_GET['w']}&la=$first_letter_author"); print $paging->getHTML(); $params["paging"] = ob_get_contents(); ob_end_clean(); $template->assign_vars($params); $template->pparse("quote"); } elseif ($_GET["t"] == 3) { if (sizeof($result)>0) { foreach ($result as $key=>$cat) { $vars["name"] = ucfirst(strtolower($cat["name"])); $vars["id"] = $cat["id"]; $template->assign_block_vars("cat", $vars); } } } elseif ($_GET["t"] == 4) { $query_sql = "SELECT * FROM authors WHERE firstname LIKE '%".$_GET["w"]."%' OR lastname LIKE '%".$_GET["w"]."%'"; if (strpos($_GET['w'], ' ')){ list($name, $surname) = explode(' ', $_GET['w']); $query_sql = "SELECT * FROM authors WHERE firstname LIKE '%".$name."%' OR lastname LIKE '%".$surname."%'"; } $result = $mysql->fetch($query_sql); $authors = ""; foreach ($result as $key=>$author) { $authors .= "{$author['firstname']} {$author['lastname']} "; } $params['authors'] = $authors; $params['banner'] = $code_authors; $template->assign_vars($params); $template->pparse("authors"); } ?>