Don't like ads? PRO users don't see any ads ;-)
Guest

Browse

By: a guest on Mar 11th, 2012  |  syntax: PHP  |  size: 15.18 KB  |  hits: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /*
  3. +------------------------------------------------
  4. |   TBDev.net BitTorrent Tracker PHP
  5. |   =============================================
  6. |   by CoLdFuSiOn
  7. |   (c) 2003 - 2009 TBDev.Net
  8. |   http://www.tbdev.net
  9. |   =============================================
  10. |   svn: http://sourceforge.net/projects/tbdevnet/
  11. |   Licence Info: GPL
  12. +------------------------------------------------
  13. |   $Date$
  14. |   $Revision$
  15. |   $Author$
  16. |   $URL$
  17. +------------------------------------------------
  18. */
  19. ob_start("ob_gzhandler");
  20.  
  21. require_once("include/bittorrent.php");
  22. require_once "include/user_functions.php";
  23. require_once "include/torrenttable_functions.php";
  24. require_once "include/pager_functions.php";
  25.  
  26. dbconn(false);
  27.  
  28. loggedinorreturn();
  29.  
  30.     $lang = array_merge( load_language('global'), load_language('browse'), load_language('torrenttable_functions') );
  31.         $mod = $CURUSER["class"] >= UC_MODERATOR;
  32.        
  33.         parked();
  34.    
  35.     $HTMLOUT = '';
  36.         $HTMLOUT .= "<script language='Javascript' src='scripts/suggest.js' type='text/javascript'></script>";
  37.    
  38.     $cats = genrelist();
  39.  
  40.     if(isset($_GET["search"]))
  41.     {
  42.       $searchstr = unesc($_GET["search"]);
  43.       $cleansearchstr = searchfield($searchstr);
  44.       if (empty($cleansearchstr))
  45.         unset($cleansearchstr);
  46.     }
  47.         if (isset($_GET['sort']) && isset($_GET['type'])) {
  48.     $column = '';
  49.     $ascdesc = '';
  50.  
  51.     switch ($_GET['sort']) {
  52.         case '1': $column = "name";
  53.             break;
  54.         case '2': $column = "numfiles";
  55.             break;
  56.         case '3': $column = "comments";
  57.             break;
  58.         case '4': $column = "added";
  59.             break;
  60.         case '5': $column = "size";
  61.             break;
  62.         case '6': $column = "times_completed";
  63.             break;
  64.         case '7': $column = "seeders";
  65.             break;
  66.         case '8': $column = "leechers";
  67.             break;
  68.         case '9': $column = "owner";
  69.             break;
  70.         default: $column = "id";
  71.             break;
  72.     }
  73.  
  74.     switch ($_GET['type']) {
  75.         case 'asc': $ascdesc = "ASC";
  76.             $linkascdesc = "asc";
  77.             break;
  78.         case 'desc': $ascdesc = "DESC";
  79.             $linkascdesc = "desc";
  80.             break;
  81.         default: $ascdesc = "DESC";
  82.             $linkascdesc = "desc";
  83.             break;
  84.     }
  85.  
  86.     $orderby = "ORDER BY torrents." . $column . " " . $ascdesc;
  87.     $pagerlink = "sort=" . intval($_GET['sort']) . "&amp;type=" . $linkascdesc . "&amp;";
  88.     } else {
  89.     $orderby = "ORDER BY torrents.sticky ASC, torrents.id DESC";
  90.     $pagerlink = "";
  91.     }
  92.  
  93.     //$orderby = "ORDER BY torrents.sticky ASC, torrents.id DESC";
  94.  
  95.     $addparam = "";
  96.     $wherea = array();
  97.     $wherecatina = array();
  98.  
  99.     if (isset($_GET["incldead"]) &&  $_GET["incldead"] == 1)
  100.     {
  101.       $addparam .= "incldead=1&amp;";
  102.       if (!isset($CURUSER) || get_user_class() < UC_ADMINISTRATOR)
  103.         $wherea[] = "banned != 'yes'";
  104.     }
  105.     elseif (isset($_GET["incldead"]) && $_GET["incldead"] == 2)
  106.       {
  107.       $addparam .= "incldead=2&amp;";
  108.         $wherea[] = "visible = 'no'";
  109.       }
  110.       else
  111.         $wherea[] = "visible = 'yes'";
  112.  
  113.     $category = (isset($_GET["cat"])) ? (int)$_GET["cat"] : false;
  114.  
  115.     $all = isset($_GET["all"]) ? $_GET["all"] : false;
  116.         $_by = (isset($_GET["_by"]) ? 0 + $_GET["_by"] : 0);
  117.  
  118.     if (!$all)
  119.     {
  120.       if (!$_GET && $CURUSER["notifs"])
  121.       {
  122.         $all = True;
  123.         foreach ($cats as $cat)
  124.         {
  125.           $all &= $cat['id'];
  126.           if (strpos($CURUSER["notifs"], "[cat" . $cat['id'] . "]") !== False)
  127.           {
  128.             $wherecatina[] = $cat['id'];
  129.             $addparam .= "c{$cat['id']}=1&amp;";
  130.           }
  131.         }
  132.       }
  133.       elseif ($category)
  134.       {
  135.         if (!is_valid_id($category))
  136.           stderr("{$lang['browse_error']}", "{$lang['browse_invalid_cat']}");
  137.         $wherecatina[] = $category;
  138.         $addparam .= "cat=$category&amp;";
  139.       }
  140.       else
  141.       {
  142.         $all = True;
  143.         foreach ($cats as $cat)
  144.         {
  145.           $all &= isset($_GET["c{$cat['id']}"]);
  146.           if (isset($_GET["c{$cat['id']}"]))
  147.           {
  148.             $wherecatina[] = $cat['id'];
  149.             $addparam .= "c{$cat['id']}=1&amp;";
  150.           }
  151.         }
  152.       }
  153.     }
  154.    
  155.     if ($all)
  156.     {
  157.       $wherecatina = array();
  158.       $addparam = "";
  159.     }
  160.  
  161.     if (count($wherecatina) > 1)
  162.       $wherecatin = implode(",",$wherecatina);
  163.     elseif (count($wherecatina) == 1)
  164.       $wherea[] = "category = $wherecatina[0]";
  165.  
  166.     $wherebase = $wherea;
  167.  
  168.     if (isset($cleansearchstr)) {
  169.         if ($_by == 0) {
  170.         $wherea[] = "torrents.name LIKE (" . sqlesc($searchstr) . ")";
  171.         } elseif ($_by == 1) {
  172.         $wherea[] = "MATCH (search_text, ori_descr) AGAINST (" . sqlesc($searchstr) . ")";
  173.         } elseif ($_by == 2) {
  174.         $wherea[] = "MATCH (search_text, ori_descr) AGAINST (" . sqlesc($searchstr) . ")";
  175.                 } elseif ($_by == 3) {
  176.         $query = mysql_query("SELECT id FROM users WHERE username = ".sqlesc($searchstr)." LIMIT 1");
  177.         if (mysql_num_rows($query) > 0)
  178.                                 {
  179.                                         $user = mysql_fetch_assoc($query);
  180.                                        
  181.                         $wherea[] = "torrents.owner = ".sqlesc($user['id']).(!$mod ? " AND torrents.anonymous != 'yes'" : "");
  182.                                 }
  183.                                
  184.         }
  185.         $addparam .= "search=" . urlencode($searchstr) . "&";
  186.         $orderby = "";
  187.     }
  188.  
  189.     $where = implode(" AND ", $wherea);
  190.    
  191.     if (isset($wherecatin))
  192.       $where .= ($where ? " AND " : "") . "category IN(" . $wherecatin . ")";
  193.  
  194.     if ($where != "")
  195.       $where = "WHERE $where";
  196.  
  197.     $res = mysql_query("SELECT COUNT(*) FROM torrents $where AND category NOT IN (6, 36, 4, 26, 31, 1, 34)") or die(mysql_error());
  198.     $row = mysql_fetch_array($res,MYSQL_NUM);
  199.     $count = $row[0];
  200.  
  201.     if (!$count && isset($cleansearchstr))
  202.         {
  203.         $wherea = $wherebase;
  204.         $orderby = "ORDER BY id DESC";
  205.         $searcha = explode(" ", $cleansearchstr);
  206.         $sc = 0;
  207.         foreach ($searcha as $searchss)
  208.         {
  209.         if (strlen($searchss) <= 1)
  210.         continue;
  211.         $sc++;
  212.         if ($sc > 5)
  213.         break;
  214.         $ssa = array();
  215.                
  216.                 if ($_by == 0) {
  217.  foreach (array("torrents.name") as $sss)
  218.                         $ssa[] = "$sss LIKE '%" . sqlwildcardesc($searchss) . "%'";
  219.                         $wherea[] = "(" . implode(" OR ", $ssa) . ")";
  220.                 } elseif ($_by == 1) {
  221.  foreach (array("search_text", "ori_descr") as $sss)
  222.                         $ssa[] = "$sss LIKE '%" . sqlwildcardesc($searchss) . "%'";
  223.                         $wherea[] = "(" . implode(" OR ", $ssa) . ")";
  224.                 } elseif ($_by == 2) {
  225.  foreach (array("search_text", "ori_descr") as $sss)
  226.                         $ssa[] = "$sss LIKE '%" . sqlwildcardesc($searchss) . "%'";
  227.                         $wherea[] = "(" . implode(" OR ", $ssa) . ")";
  228.                         } elseif ($_by == 3) {
  229.  foreach (array("torrents.owner") as $sss)
  230.                         $ssa[] = "$sss LIKE '%" . sqlwildcardesc($searchss) . "%'";
  231.                         $wherea[] = "(" . implode(" OR ", $ssa) . ")";
  232.  }
  233.                
  234.  }
  235.    
  236.       if ($sc)
  237.       {
  238.         $where = implode(" AND ", $wherea);
  239.         if ($where != "")
  240.           $where = "WHERE $where";
  241.                   $q = "SELECT COUNT(*) FROM torrents $where AND category NOT IN (6, 36, 4, 26, 31, 1, 34)";
  242.                 $res = mysql_query($q);
  243.         $row = mysql_fetch_array($res);
  244.         $count = $row[0];
  245.       }
  246.     }
  247.  
  248.     $torrentsperpage = $CURUSER["torrentsperpage"];
  249.     if (!$torrentsperpage)
  250.       $torrentsperpage = 25;
  251.  
  252.     if ($count)
  253.     {
  254.         if ($addparam != "") {
  255.             if ($pagerlink != "") {
  256.                 if ($addparam{strlen($addparam)-1} != ";") { // & = &amp;
  257.                     $addparam = $addparam . "&" . $pagerlink;
  258.                 } else {
  259.                     $addparam = $addparam . $pagerlink;
  260.                 }
  261.             }
  262.         } else {
  263.             $addparam = $pagerlink;
  264.         }
  265.       //list($pagertop, $pagerbottom, $limit) = pager($torrentsperpage, $count, "browse.php?" . $addparam);
  266.       $pager = pager($torrentsperpage, $count, "browse.php?" . $addparam);
  267.  
  268.       $query = "SELECT torrents.id, torrents.category, torrents.leechers, torrents.seeders, torrents.name, torrents.times_completed, torrents.size, torrents.added, torrents.type, torrents.sticky, torrents.nuked, torrents.nukereason, torrents.requrl, torrents.description, torrents.anonymous, torrents.free, torrents.comments,torrents.numfiles,torrents.filename,torrents.owner,IF(torrents.nfo <> '', 1, 0) as nfoav," .
  269.     //  "IF(torrents.numratings < {$TBDEV['minvotes']}, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating, categories.name AS cat_name, categories.image AS cat_pic, users.username FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id $where $orderby $limit";
  270.       "categories.name AS cat_name, categories.image AS cat_pic, users.username, freeslots.tid, freeslots.uid, freeslots.free AS freeslot, freeslots.double AS doubleup FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id LEFT JOIN freeslots ON (torrents.id=freeslots.tid AND freeslots.uid={$CURUSER['id']}) $where AND torrents.category NOT IN (6, 36, 4, 26, 31, 1, 34) $orderby {$pager['limit']}";
  271.       $res = mysql_query($query) or die(mysql_error());
  272.     }
  273.     else
  274.     {
  275.       unset($res);
  276.     }
  277.    
  278.     if (isset($cleansearchstr))
  279.       $title = "{$lang['browse_search']}\"$searchstr\"";
  280.     else
  281.       $title = '';
  282.  
  283.  
  284.  
  285.  
  286.     //$HTMLOUT .= "<div id='wrapper' style='width:90%;border:1px solid black;background-color:blue;'>";
  287.  
  288.  
  289.     //print out the tag cloud
  290.     //require_once "include/searchcloud_functions.php";
  291.     //$HTMLOUT .= cloud() . "</div><br /><br />";
  292.  
  293.     $HTMLOUT .= "<form method='get' action='browse.php'>
  294.    <table class='bottom'>
  295.    <tr><br />
  296.    <td class='bottom'>
  297.      <table class='bottom'>
  298.      <tr>";
  299.  
  300.  
  301.     $i = 0;
  302.     $catsperrow = 7;
  303.     foreach ($cats as $cat)
  304.     {
  305.       $HTMLOUT .= ($i && $i % $catsperrow == 0) ? "</tr><tr>" : "";
  306.       $HTMLOUT .= "<td class='bottom' style='padding-bottom: 2px;padding-left: 7px;align:center;border:0px solid;'>
  307.      <input name='c".$cat['id']."' type=\"checkbox\" " . (in_array($cat['id'],$wherecatina) ? "checked='checked' " : "") . "value='1' /><a class='catlink' href='browse.php?cat={$cat['id']}'>" . htmlspecialchars($cat['name']) . "</a></td>\n";
  308.       $i++;
  309.     }
  310.  
  311.     $alllink = "<div align='left'>(<a href='browse.php?all=1'><b>{$lang['browse_show_all']}</b></a>)</div>";
  312.  
  313.     $ncats = count($cats);
  314.     $nrows = ceil($ncats/$catsperrow);
  315.     $lastrowcols = $ncats % $catsperrow;
  316.  
  317.     if ($lastrowcols != 0)
  318.     {
  319.       if ($catsperrow - $lastrowcols != 1)
  320.         {
  321.           $HTMLOUT .= "<td class='bottom' rowspan='" . ($catsperrow  - $lastrowcols - 1) . "'>&nbsp;</td>";
  322.         }
  323.       //$HTMLOUT .= "<td class='bottom' style=\"padding-left: 5px\">$alllink</td>\n";
  324.     }
  325.  
  326.     $selected = (isset($_GET["incldead"])) ? (int)$_GET["incldead"] : "";
  327.  
  328.     $HTMLOUT .= "</tr>
  329.    </table>
  330.    </td>
  331.  
  332.    <td class='bottom'>
  333.    <table class='main'>
  334.      <tr>
  335.        <td class='bottom' style='padding: 1px;padding-left: 10px'>
  336.          <select name='incldead'>
  337.    <option value='0'>{$lang['browse_active']}</option>
  338.    <option value='1'".($selected == 1 ? " selected='selected'" : "").">{$lang['browse_inc_dead1']}</option>
  339.    <option value='2'".($selected == 2 ? " selected='selected'" : "").">{$lang['browse_dead']}</option>
  340.          </select>
  341.        </td><br />";
  342.        
  343. /*
  344.     if ($ncats % $catsperrow == 0)
  345.     {
  346.       $HTMLOUT .= "<td class='bottom' style='padding-left: 15px' rowspan='$nrows' valign='middle' align='right'>$alllink</td>\n";
  347.     }*/
  348. $HTMLOUT .= "</tr>
  349.      <tr>
  350.        <td class='bottom' style='padding: 1px;padding-left: 10px'>
  351.        <div align='center'>
  352.          <input type='submit' class='btn' value='{$lang['browse_go']}' />
  353.        </div>
  354.        </td>
  355.      </tr>
  356.      </table>
  357.    </td>
  358.    </tr>
  359.    </table>
  360.    </form>";
  361.  
  362.  
  363. $HTMLOUT .= "<table class='bottom' border='0' cellspacing='0' cellpadding='0'><tr><td class='embedded'><br />
  364.  
  365.        <form method='get' action='browse.php'>
  366.        {$lang['browse_search1']}
  367.        <input type='text' id='searchinput' name='search' autocomplete='off' style='width: 240px;' ondblclick='suggest(event.keyCode,this.value);' onkeyup='suggest(event.keyCode,this.value);' onkeypress='return noenter(event.keyCode);' value='' />
  368.        {$lang['browse_by']}
  369. <select name='_by'>
  370.        <option value='0'> {$lang['browse_name']}</option>
  371.        <option value='1'".($_by == '1' ? ' selected' : '').">{$lang['browse_description']}</option>
  372. <option value='2'".($_by == '2' ? ' selected' : '')."> {$lang['browse_both']}</option>
  373. <option value='3'".($_by == '3' ? ' selected' : '')."> {$lang['browse_uploader']}</option>
  374. </select>
  375.        {$lang['browse_in']}
  376.        <select name='cat'>
  377.        <option value='0'>{$lang['browse_all_types']}</option>";
  378.  
  379.  
  380.  
  381.         $cats = genrelist();
  382.         $catdropdown = "";
  383.         foreach ($cats as $cat) {
  384.         $catdropdown .= "<option value=\"" . $cat["id"] . "\"";
  385.         $getcat = (isset($_GET["cat"])?$_GET["cat"]:'');
  386.         if ($cat["id"] == $getcat)
  387.         $catdropdown .= " selected='selected'";
  388.         $catdropdown .= ">" . htmlspecialchars($cat["name"]) . "</option>\n";
  389.         }
  390.  
  391.         $deadchkbox = "<input type='checkbox' name='incldead' value='1'";
  392.         if (isset($_GET["incldead"]))
  393.         $deadchkbox .= " checked='checked'";
  394.         $deadchkbox .= " /> {$lang['browse_inc_dead']}";
  395.  
  396.  
  397.         $HTMLOUT .= $catdropdown;
  398.        
  399.         $HTMLOUT .= "</select>
  400.        $deadchkbox
  401.        <input type='submit' value='{$lang['browse_search_btn']}' class='btn' />
  402.        </form>
  403.  
  404. <div id='suggcontainer' style='text-align: left; width: 520px; display: none;'>
  405. <div id='suggestions' style='cursor: default; position: absolute; background-color: #257EBA; border: 1px solid #257EBA;'></div>
  406. </div>
  407.        </td></tr></table>";
  408.        
  409.        
  410.     if (isset($cleansearchstr))
  411.     {
  412.       $HTMLOUT .= "<h2>{$lang['browse_search']}\"" . htmlentities($searchstr, ENT_QUOTES) . "\"</h2>\n";
  413.     }
  414.    
  415.     if ($count)
  416.     {
  417.       $HTMLOUT .= $pager['pagertop'];
  418.  
  419.       $HTMLOUT .= torrenttable($res);
  420.  
  421.       $HTMLOUT .= $pager['pagerbottom'];
  422.     }
  423.     else
  424.     {
  425.       if (isset($cleansearchstr))
  426.       {
  427.         $HTMLOUT .= "<h2>{$lang['browse_not_found']}</h2>\n";
  428.         $HTMLOUT .= "<p>{$lang['browse_tryagain']}</p>\n";
  429.       }
  430.       else
  431.       {
  432.         $HTMLOUT .= "<h2>{$lang['browse_nothing']}</h2>\n";
  433.         $HTMLOUT .= "<p>{$lang['browse_sorry']}(</p>\n";
  434.       }
  435.     }
  436.  
  437. /////////////////////// HTML OUTPUT //////////////////////////////
  438. mysql_query("UPDATE users SET last_browse=".TIME_NOW." where id=".$CURUSER['id']);
  439.     print stdhead($title) . $HTMLOUT . stdfoot();
  440.  
  441. ?>