debugging = false; // Generate a cacheid to make url parameters work $cacheid = md5(serialize($req)); // Expire cache in x seconds $t->caching = true; $t->force_compile= false; $t->cache_lifetime = 600; $t->clear_all_cache('index-t.ihtml'); if (!$_REQUEST['searchsss'] and $t->is_cached('index-t.ihtml', $cacheid) and !$_REQUEST['force_refresh']) { $t->display('index-t.ihtml', $cacheid); die(); } elseif ($_REQUEST['searchsss']) { $t->caching = false; } elseif ($_REQUEST['force_refresh']) { // FIXME: Add clear cache code } $where = array(); $where_clause = ''; $show_per_page = 50; $page = $_REQUEST['page']; // $search = $_REQUEST['searchsss']; ///$search = preg_replace("/[^A-Za-z0-9]/","",$submitted_search); $search_array = array(); $search_array = gen_search_terms($search); $category = (int)$_REQUEST['category']; if (!$category) $category = (int)$_REQUEST['cat']; $incldead = $_REQUEST['incldead']; $sort = $_REQUEST['sort']; //Sort on column switch ($sort) { case 'added': case 'comments': case 'seeders': case 'leechers': case 'times_completed': $orderby = "ORDER BY torrents.$sort DESC"; break; case 'username': $orderby = "ORDER BY users.$sort ASC"; break; // Name is artist name case 'name': $orderby = "ORDER BY cat_name ASC"; break; case 'active': $orderby = "ORDER BY torrents.last_action DESC"; break; default: // $orderby = "ORDER BY torrents.added DESC"; $orderby = "ORDER BY torrents.added DESC"; break; } // Process pager variable if ($page) { $limit = "LIMIT " . $page .", " . $show_per_page; } else { $limit = "LIMIT 0, " . $show_per_page; } // If the user checked the 'include w/ no seeders' box, add to where clause if ($incldead) { $where[] = "banned <> 'yes'"; } else { // Only show visible ones $where[] = "visible = 'yes' AND seeders > 0"; } // If the user searched for a specific category, add that to where clause if ($_REQUEST['cat']) { $where[] = "category = $category"; } // If user wants to filter set the where switch ($_REQUEST['filter']) { case 'nophish': $where[] = "category <> 5"; break; case 'nodead': $where[] = "category <> 8"; break; case 'noreseed': $where[] = "reseeded = ''"; break; case 'nophgd': $where[] = "category <> 5 AND category <> 8"; break; case 'none': break; default: break; } // If the user searched for a specific string, add that to the where clause if ($search) { // $cacheid = $search.$cat; // LOG ALL SEARCHES //DO NOT Cache search results // $t->cache_lifetime = 0; // $where[] = "MATCH (search_text, ori_descr) AGAINST ('$search')"; } $where[] = '1 = 1'; $where_clause = implode(' AND ', $where); if ($search) { $where_string = implode(' AND ', $search_array); $where_clause = $where_clause . " AND " . $where_string; } echo $where_clause; //exit; $count = $db->getOne("SELECT count(*) FROM torrents WHERE $where_clause"); // Originally if no records were found a LIKE would be used. This // isn't necessary because the MATCH is much more precise and doing // this simply causes more sql overhaed $additionals = 0; // Retrieve the list of torrents but limit with above values $torrents = $db->getAll(" SELECT torrents.id, torrents.name, filename, save_as, torrents.category, size, type, numfiles, views, hits, comments, times_completed, leechers, seeders, banned, owner, numratings, ratingsum, dblink, ref_dbshow, ref_dbshn, ref_shows, reseeded, unix_timestamp(torrents.added) as added, unix_timestamp(torrents.reseeded) as unix_reseeded, categories.name AS cat_name, users.username FROM users, torrents, categories WHERE torrents.owner = users.id AND Category = categories.id AND banned = 'no' AND $where_clause $orderby $limit; "); //This prepares the param for each type below //We then use this to create links that manipulate the torrent table $sorturl = urlparams(sort); $filterurl = urlparams(filter); $caturl = urlparams(cat); // Assign Template Variables $t->assign(array( 'request' => serialize ($req), 'torrents' => $torrents, 'count' => $count, 'search' => $search, 'cat' => $cat, 'caturl' => $caturl, 'page' => $page, 'filterurl' => $filterurl, 'sorturl' => $sorturl, 'show_per_page' => $show_per_page )); //$t->display('index-t.ihtml'); $t->display('index-t.ihtml', $cacheid); ?>