09 Sort Browse Columns

Started by Mindless, July 21, 2012, 07:47:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ZajferX

works very well tnx a lot for this :D

FlashBR

#7
forget it its fixed!

FlashBR

giving me that error, Deprecated: mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead. in C:\xampp\htdocs\include\torrenttable_functions.php on line 54

      $get_name = mysql_escape_string(strip_tags(str_replace(array("\"", "'"), array("", ""), $get_name)));

        $get_value = mysql_escape_string(strip_tags(str_replace(array("\"", "'"), array("", ""), $get_value)));

know why?

BACDAFUCUP

lol i dident see that.. :) thanks for the help it works perfect right now. :)

denede

#4
for me it works fine. it seems u did something wrong. :)

in browse you should remove
$orderby = "ORDER BY torrents.sticky ASC, torrents.id DESC";

if you see you have 2 of them.
one above ..
so it will remain only

     }
     
        $orderby = "ORDER BY torrents." . $column . " " . $ascdesc;
        $pagerlink = "sort=" . intval($_GET['sort']) . "&type=" . $linkascdesc . "&";
        } else {
        $orderby = "ORDER BY torrents.sticky ASC, torrents.id DESC";
        $pagerlink = "";
        }

    $addparam = "";
    $wherea = array();
    $wherecatina = array();

BACDAFUCUP

#3
hi there.. Thanks for this mod..
i can not get it to work. i have tried 4 times now :(

i can not see what there is wrong. i have looked and looked. So i hope there is a friendly soul there can find the problem. :)

if i click on comments, added, seeders, leechers etc. there is nothing happens its just updating the site but with no sort change.
i can when i hover over my mouse the link says "browse.php?sort=5&type=desc" when i click on it again it says "browse.php?sort=5&type=asc"
browse.php look like this
Code (php) Select
<?php
/*
+------------------------------------------------
|   TBDev.net BitTorrent Tracker PHP
|   =============================================
|   by CoLdFuSiOn
|   (c) 2003 - 2009 TBDev.Net
|   http://www.tbdev.net
|   =============================================
|   svn: http://sourceforge.net/projects/tbdevnet/
|   Licence Info: GPL
+------------------------------------------------
|   $Date$
|   $Revision$
|   $Author$
|   $URL$
+------------------------------------------------
*/
ob_start("ob_gzhandler");

require_once(
"include/bittorrent.php");
require_once 
"include/user_functions.php";
require_once 
"include/torrenttable_functions.php";
require_once 
"include/pager_functions.php";

dbconn(false);

loggedinorreturn();

    
$lang array_mergeload_language('global'), load_language('browse'), load_language('torrenttable_functions') );
    
    
$HTMLOUT '';
    
    
$cats genrelist();

       
$searchstr = (isset($_GET['search']) ? unesc($_GET['search']) : '');
    
$cleansearchstr searchfield($searchstr);
    if (empty(
$cleansearchstr))
        unset(
$cleansearchstr);
    if (isset(
$_GET['sort']) && isset($_GET['type'])) {
        
$column '';
        
$ascdesc '';
     
        switch (
$_GET['sort']) {
            case 
'1'$column "name";
                break;
            case 
'2'$column "numfiles";
                break;
            case 
'3'$column "comments";
                break;
            case 
'4'$column "added";
                break;
            case 
'5'$column "size";
                break;
            case 
'6'$column "times_completed";
                break;
            case 
'7'$column "seeders";
                break;
            case 
'8'$column "leechers";
                break;
            case 
'9'$column "owner";
                break;
            default: 
$column "id";
                break;
        }
     
        switch (
$_GET['type']) {
            case 
'asc'$ascdesc "ASC";
                
$linkascdesc "asc";
                break;
            case 
'desc'$ascdesc "DESC";
                
$linkascdesc "desc";
                break;
            default: 
$ascdesc "DESC";
                
$linkascdesc "desc";
                break;
        }
     
        
$orderby "ORDER BY torrents." $column " " $ascdesc;
        
$pagerlink "sort=" intval($_GET['sort']) . "&type=" $linkascdesc "&";
        } else {
        
$orderby "ORDER BY torrents.sticky ASC, torrents.id DESC";
        
$pagerlink "";
        }

    
$orderby "ORDER BY torrents.sticky ASC, torrents.id DESC";

    
$addparam "";
    
$wherea = array();
    
$wherecatina = array();

    if (isset(
$_GET["incldead"]) &&  $_GET["incldead"] == 1)
    {
      
$addparam .= "incldead=1&amp;";
      if (!isset(
$CURUSER) || get_user_class() < UC_ADMINISTRATOR)
        
$wherea[] = "banned != 'yes'";
    }
    else
    {
      if (isset(
$_GET["incldead"]) && $_GET["incldead"] == 2)
      {
      
$addparam .= "incldead=2&amp;";
        
$wherea[] = "visible = 'no'";
      }
      else
        
$wherea[] = "visible = 'yes'";
    }
    
    
$category = (isset($_GET["cat"])) ? (int)$_GET["cat"] : false;

    
$all = isset($_GET["all"]) ? $_GET["all"] : false;

    if (!
$all)
    {
      if (!
$_GET && $CURUSER["notifs"])
      {
        
$all True;
        foreach (
$cats as $cat)
        {
          
$all &= $cat['id'];
          if (
strpos($CURUSER["notifs"], "[cat" $cat['id'] . "]") !== False)
          {
            
$wherecatina[] = $cat['id'];
            
$addparam .= "c{$cat['id']}=1&amp;";
          }
        }
      }
      elseif (
$category)
      {
        if (!
is_valid_id($category))
          
stderr("{$lang['browse_error']}""{$lang['browse_invalid_cat']}");
        
$wherecatina[] = $category;
        
$addparam .= "cat=$category&amp;";
      }
      else
      {
        
$all True;
        foreach (
$cats as $cat)
        {
          
$all &= isset($_GET["c{$cat['id']}"]);
          if (isset(
$_GET["c{$cat['id']}"]))
          {
            
$wherecatina[] = $cat['id'];
            
$addparam .= "c{$cat['id']}=1&amp;";
          }
        }
      }
    }
    
    if (
$all)
    {
      
$wherecatina = array();
      
$addparam "";
    }

    if (
count($wherecatina) > 1)
      
$wherecatin implode(",",$wherecatina);
    elseif (
count($wherecatina) == 1)
      
$wherea[] = "category = $wherecatina[0]";

    
$wherebase $wherea;

    if (isset(
$cleansearchstr))
    {
      
$wherea[] = "MATCH (search_text, ori_descr) AGAINST (" sqlesc($searchstr) . ")";
      
//$wherea[] = "0";
      
$addparam .= "search=" urlencode($searchstr) . "&amp;";
      
$orderby "";
      
      
/////////////// SEARCH CLOUD MALARKY //////////////////////

        
$searchcloud sqlesc($cleansearchstr);
       
// $r = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM searchcloud WHERE searchedfor = $searchcloud"), MYSQL_NUM);
        //$a = $r[0];
        //if ($a)
           // mysql_query("UPDATE searchcloud SET howmuch = howmuch + 1 WHERE searchedfor = $searchcloud");
        //else
           // mysql_query("INSERT INTO searchcloud (searchedfor, howmuch) VALUES ($searchcloud, 1)");
        
@mysql_query("INSERT INTO searchcloud (searchedfor, howmuch) VALUES ($searchcloud, 1)
                    ON DUPLICATE KEY UPDATE howmuch=howmuch+1"
);
      
/////////////// SEARCH CLOUD MALARKY END ///////////////////
    
}

    
$where implode(" AND "$wherea);
    
    if (isset(
$wherecatin))
      
$where .= ($where " AND " "") . "category IN(" $wherecatin ")";

    if (
$where != "")
      
$where "WHERE $where";

    
$res mysql_query("SELECT COUNT(*) FROM torrents $where") or die(mysql_error());
    
$row mysql_fetch_array($res,MYSQL_NUM);
    
$count $row[0];

    if (!
$count && isset($cleansearchstr)) 
    {
      
$wherea $wherebase;
      
$orderby "ORDER BY id DESC";
      
$searcha explode(" "$cleansearchstr);
      
$sc 0;
      foreach (
$searcha as $searchss
      {
        if (
strlen($searchss) <= 1)
          continue;
        
$sc++;
        if (
$sc 5)
          break;
        
$ssa = array();
        foreach (array(
"search_text""ori_descr") as $sss)
          
$ssa[] = "$sss LIKE '%" sqlwildcardesc($searchss) . "%'";
        
$wherea[] = "(" implode(" OR "$ssa) . ")";
      }
    
      if (
$sc
      {
        
$where implode(" AND "$wherea);
        if (
$where != "")
          
$where "WHERE $where";
        
$res mysql_query("SELECT COUNT(*) FROM torrents $where");
        
$row mysql_fetch_array($res,MYSQL_NUM);
        
$count $row[0];
      }
    }

    
$torrentsperpage $CURUSER["torrentsperpage"];
    if (!
$torrentsperpage)
      
$torrentsperpage 15;

    if (
$count)
    {
    if ($addparam != "") {
                if (
$pagerlink != "") {
                    if (
$addparam{strlen($addparam)-1} != ";") { // & = &amp;
                        
$addparam $addparam "&" $pagerlink;
                    } else {
                        
$addparam $addparam $pagerlink;
                    }
                }
            } else {
                
$addparam $pagerlink;
            }
      
//list($pagertop, $pagerbottom, $limit) = pager($torrentsperpage, $count, "browse.php?" . $addparam);
      
$pager pager($torrentsperpage$count"browse.php?" $addparam);

      
$query "SELECT torrents.id, torrents.category, torrents.leechers, torrents.seeders, torrents.sticky, torrents.name, torrents.times_completed, torrents.size, torrents.added, torrents.type,  torrents.comments,torrents.numfiles,torrents.filename,torrents.owner,IF(torrents.nfo <> '', 1, 0) as nfoav," .
    
// "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";
      
"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 {$pager['limit']}";
      
$res mysql_query($query) or die(mysql_error());
    }
    else
    {
      unset(
$res);
    }
    
    if (isset(
$cleansearchstr))
      
$title "{$lang['browse_search']}\"$searchstr\"";
    else
      
$title '';




    
$HTMLOUT .= "<div id='wrapper' style='width:90%;border:1px solid black;background-color:pink;'>";


    
//print out the tag cloud
    
require_once "include/searchcloud_functions.php";
    
$HTMLOUT .= cloud() . "</div><br /><br />";

    
$HTMLOUT .= "<form method='get' action='browse.php'>
    <table class='bottom'>
    <tr>
    <td class='bottom'>
      <table class='bottom'>
      <tr>"
;


    
$i 0;
    
$catsperrow 7;
    foreach (
$cats as $cat)
    {
      
$HTMLOUT .= ($i && $i $catsperrow == 0) ? "</tr><tr>" "";
      
$HTMLOUT .= "<td class='bottom' style='padding-bottom: 2px;padding-left: 7px;align:left;border:1px solid;'>
      <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";
      
$i++;
    }

    
$alllink "<div align='left'>(<a href='browse.php?all=1'><b>{$lang['browse_show_all']}</b></a>)</div>";

    
$ncats count($cats);
    
$nrows ceil($ncats/$catsperrow);
    
$lastrowcols $ncats $catsperrow;

    if (
$lastrowcols != 0)
    {
      if (
$catsperrow $lastrowcols != 1)
        {
          
$HTMLOUT .= "<td class='bottom' rowspan='" . ($catsperrow  $lastrowcols 1) . "'>&nbsp;</td>";
        }
      
$HTMLOUT .= "<td class='bottom' style=\"padding-left: 5px\">$alllink</td>\n";
    }

    
$selected = (isset($_GET["incldead"])) ? (int)$_GET["incldead"] : "";

    
$HTMLOUT .= "</tr>
    </table>
    </td>

    <td class='bottom'>
    <table class='main'>
      <tr>
        <td class='bottom' style='padding: 1px;padding-left: 10px'>
          <select name='incldead'>
    <option value='0'>
{$lang['browse_active']}</option>
    <option value='1'"
.($selected == " selected='selected'" "").">{$lang['browse_inc_dead']}</option>
    <option value='2'"
.($selected == " selected='selected'" "").">{$lang['browse_dead']}</option>
          </select>
        </td>"
;
        

    if (
$ncats $catsperrow == 0)
    {
      
$HTMLOUT .= "<td class='bottom' style='padding-left: 15px' rowspan='$nrows' valign='middle' align='right'>$alllink</td>\n";
    }

    
$HTMLOUT .= "</tr>
      <tr>
        <td class='bottom' style='padding: 1px;padding-left: 10px'>
        <div align='center'>
          <input type='submit' class='btn' value='
{$lang['browse_go']}' />
        </div>
        </td>
      </tr>
      </table>
    </td>
    </tr>
    </table>
    </form>"
;



    if (isset(
$cleansearchstr))
    {
      
$HTMLOUT .= "<h2>{$lang['browse_search']}\"" htmlentities($searchstrENT_QUOTES) . "\"</h2>\n";
    }
    
    if (
$count
    {
      
$HTMLOUT .= $pager['pagertop'];

      
$HTMLOUT .= torrenttable($res);

      
$HTMLOUT .= $pager['pagerbottom'];
    }
    else 
    {
      if (isset(
$cleansearchstr)) 
      {
        
$HTMLOUT .= "<h2>{$lang['browse_not_found']}</h2>\n";
        
$HTMLOUT .= "<p>{$lang['browse_tryagain']}</p>\n";
      }
      else 
      {
        
$HTMLOUT .= "<h2>{$lang['browse_nothing']}</h2>\n";
        
$HTMLOUT .= "<p>{$lang['browse_sorry']}(</p>\n";
      }
    }

/////////////////////// HTML OUTPUT //////////////////////////////

    
print stdhead($title) . $HTMLOUT stdfoot();

?>


My torrenttable_functions.php looks like this.
Code (php) Select
<?php
/*
+------------------------------------------------
|   TBDev.net BitTorrent Tracker PHP
|   =============================================
|   by CoLdFuSiOn
|   (c) 2003 - 2009 TBDev.Net
|   http://www.tbdev.net
|   =============================================
|   svn: http://sourceforge.net/projects/tbdevnet/
|   Licence Info: GPL
+------------------------------------------------
|   $Date$
|   $Revision$
|   $Author$
|   $URL$
+------------------------------------------------
*/
function linkcolor($num) {
    if (!
$num)
        return 
"red";
//    if ($num == 1)
//        return "yellow";
    
return "green";
}

function 
torrenttable($res$variant "index") {
    global 
$TBDEV$CURUSER$lang;

    
$wait 0;
    
$htmlout '';
    
    if (
$CURUSER["class"] < UC_VIP)
    {
      
$gigs $CURUSER["uploaded"] / (1024*1024*1024);
      
$ratio = (($CURUSER["downloaded"] > 0) ? ($CURUSER["uploaded"] / $CURUSER["downloaded"]) : 0);
      if (
$ratio 0.5 || $gigs 5$wait 48;
      elseif (
$ratio 0.65 || $gigs 6.5$wait 24;
      elseif (
$ratio 0.8 || $gigs 8$wait 12;
      elseif (
$ratio 0.95 || $gigs 9.5$wait 6;
      else 
$wait 0;
    }

        
$oldlink '';
        
$count_get 0;
        
$char '';
        
$description '';
        
$type '';
        
$sort '';
        
$row '';
        foreach (
$_GET as $get_name => $get_value) {
            
$get_name mysql_escape_string(strip_tags(str_replace(array("\"""'"), array(""""), $get_name)));
     
            
$get_value mysql_escape_string(strip_tags(str_replace(array("\"""'"), array(""""), $get_value)));
     
            if (
$get_name != "sort" && $get_name != "type") {
                if (
$count_get 0) {
                    
$oldlink $oldlink "&amp;" $get_name "=" $get_value;
                } else {
                    
$oldlink = ($oldlink) . $get_name "=" $get_value;
                }
                
$count_get++;
            }
        }
     
        if (
$count_get 0) {
            
$oldlink $oldlink "&amp;";
        }
     
        if (isset(
$_GET["sort"]) && $_GET["sort"] == "1") {
            if (isset(
$_GET["type"]) && $_GET["type"] == "desc") {
                
$link1 "asc";
            } else {
                
$link1 "desc";
            }
        }
        if (isset(
$_GET["sort"]) && $_GET["sort"] == "2") {
            if (isset(
$_GET["type"]) && $_GET["type"] == "desc") {
                
$link2 "asc";
            } else {
                
$link2 "desc";
            }
        }
        if (isset(
$_GET["sort"]) && $_GET["sort"] == "3") {
            if (isset(
$_GET["type"]) && $_GET["type"] == "desc") {
                
$link3 "asc";
            } else {
                
$link3 "desc";
            }
        }
        if (isset(
$_GET["sort"]) && $_GET["sort"] == "4") {
            if (isset(
$_GET["type"]) && $_GET["type"] == "desc") {
                
$link4 "asc";
            } else {
                
$link4 "desc";
            }
        }
        if (isset(
$_GET["sort"]) && $_GET["sort"] == "5") {
            if (isset(
$_GET["type"]) && $_GET["type"] == "desc") {
                
$link5 "asc";
            } else {
                
$link5 "desc";
            }
        }
        if (isset(
$_GET["sort"]) && $_GET["sort"] == "6") {
            if (isset(
$_GET["type"]) && $_GET["type"] == "desc") {
                
$link6 "asc";
            } else {
                
$link6 "desc";
            }
        }
        if (isset(
$_GET["sort"]) && $_GET["sort"] == "7") {
            if (isset(
$_GET["type"]) && $_GET["type"] == "desc") {
                
$link7 "asc";
            } else {
                
$link7 "desc";
            }
        }
        if (isset(
$_GET["sort"]) && $_GET["sort"] == "8") {
            if (isset(
$_GET["type"]) && $_GET["type"] == "desc") {
                
$link8 "asc";
            } else {
                
$link8 "desc";
            }
        }
        if (isset(
$_GET["sort"]) && $_GET["sort"] == "9") {
            if (isset(
$_GET["type"]) && $_GET["type"] == "desc") {
                
$link9 "asc";
            } else {
                
$link9 "desc";
            }
        }
     
        if (empty(
$link1)) {
            
$link1 "asc";
        }
        if (empty(
$link2)) {
            
$link2 "desc";
        }
        if (empty(
$link3)) {
            
$link3 "desc";
        }
        if (empty(
$link4)) {
            
$link4 "desc";
        }
        if (empty(
$link5)) {
            
$link5 "desc";
        }
        if (empty(
$link6)) {
            
$link6 "desc";
        }
        if (empty(
$link7)) {
            
$link7 "desc";
        }
        if (empty(
$link8)) {
            
$link8 "desc";
        }
        if (empty(
$link9)) {
            
$link9 "desc";
        }
     
     
       
$htmlout .= "<table border='1' cellspacing='0' cellpadding='5'>
      <tr>
      <td class='colhead' align='center'>
{$lang["torrenttable_type"]}</td>
      <td class='colhead' align='left'><a href='
{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=1&amp;type={$link1}'>{$lang["torrenttable_name"]}</a></td>";
       
       if (
$wait)
       {
       
$htmlout .="<td class='colhead' align='center'>{$lang["torrenttable_wait"]}</td>\n";
       }    
     
       if (
$variant == "mytorrents")
       {
       
$htmlout .= "<td class='colhead' align='center'>{$lang["torrenttable_edit"]}</td>\n";
       
$htmlout .= "<td class='colhead' align='center'>{$lang["torrenttable_visible"]}</td>\n";
       }
     
       
$htmlout .= "<td class='colhead' align='right'><a href='{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=2&amp;type={$link2}'>{$lang["torrenttable_files"]}</a></td>
      <td class='colhead' align='right'><a href='
{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=3&amp;type={$link3}'>{$lang["torrenttable_comments"]}</a></td>
      <td class='colhead' align='center'><a href='
{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=4&amp;type={$link4}'>{$lang["torrenttable_added"]}</a></td>
      <td class='colhead' align='center'>
{$lang["torrenttable_ttl"]}</td>
      <td class='colhead' align='center'><a href='
{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=5&amp;type={$link5}'>{$lang["torrenttable_size"]}</a></td>
      <td class='colhead' align='center'><a href='
{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=6&amp;type={$link6}'>{$lang["torrenttable_snatched"]}</a></td>
      <td class='colhead' align='right'><a href='
{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=7&amp;type={$link7}'>{$lang["torrenttable_seeders"]}</a></td>
      <td class='colhead' align='right'><a href='
{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=8&amp;type={$link8}'>{$lang["torrenttable_leechers"]}</a></td>";
     
       if (
$variant == 'index')
       
$htmlout .= "<td class='colhead' align='center'><a href='{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=9&amp;type={$link9}'>{$lang["torrenttable_uppedby"]}</a></td>\n";

    
$htmlout .= "</tr>\n";

    while (
$row mysql_fetch_assoc($res)) 
    {
        
$id $row["id"];
        
$htmlout .= "<tr>\n";

        
$htmlout .= "<td align='center' style='padding: 0px'>";
        if (isset(
$row["cat_name"])) 
        {
            
$htmlout .= "<a href='browse.php?cat={$row['category']}'>";
            if (isset(
$row["cat_pic"]) && $row["cat_pic"] != "")
                
$htmlout .= "<img border='0' src='{$TBDEV['pic_base_url']}caticons/{$row['cat_pic']}' alt='{$row['cat_name']}' />";
            else
            {
                
$htmlout .= $row["cat_name"];
            }
            
$htmlout .= "</a>";
        }
        else
        {
            
$htmlout .= "-";
        }
        
$htmlout .= "</td>\n";

        
$dispname htmlspecialchars($row["name"]);
        
        
$htmlout .= "<td align='left'><a href='details.php?";
        if (
$variant == "mytorrents")
            
$htmlout .= "returnto=" urlencode($_SERVER["REQUEST_URI"]) . "&amp;";
        
$htmlout .= "id=$id";
        if (
$variant == "index")
            
$htmlout .= "&amp;hit=1";
    $sticky = ($row['sticky']=="yes" "<img src='{$TBDEV['pic_base_url']}sticky.gif' border='0' alt='Sticky' title='sticky' />" "");
            
$htmlout .= "'><b>$dispname</b></a>&nbsp;&nbsp;$sticky\n";

if ($wait)
{
  $elapsed floor((time() - $row["added"]) / 3600);
        if ($elapsed $wait)
        {
          $color dechex(floor(127*($wait $elapsed)/48 128)*65536);
          $htmlout .= "<td align='center'><span style='white-space: nowrap;'><a href='faq.php#dl8'><font color='$color'>" number_format($wait $elapsed) . " ".$lang["torrenttable_wait_h"]."</font></a></span></td>\n";
        }
        else
          $htmlout .= "<td align='center'><span style='white-space: nowrap;'>{$lang["torrenttable_wait_none"]}</span></td>\n";
        }

/*
        if ($row["nfoav"] && get_user_class() >= UC_POWER_USER)
          print("<a href='viewnfo.php?id=$row[id]''><img src='{$TBDEV['pic_base_url']}viewnfo.gif" border='0' alt='".$lang["torrenttable_view_nfo_alt"]."' /></a>\n");
        if ($variant == "index")
            print("<a href='download.php/$id/" . rawurlencode($row["filename"]) . "'><img src='{$TBDEV['pic_base_url']}download.gif' border='0' alt='".$lang["torrenttable_download_alt"]."' /></a>\n");

        else */ 
        
if ($variant == "mytorrents")
            
$htmlout .= "</td><td align='center'><a href='edit.php?returnto=" urlencode($_SERVER["REQUEST_URI"]) . "&amp;id={$row['id']}'>".$lang["torrenttable_edit"]."</a>\n";
        
$htmlout .= "</td>\n";
        
        if (
$variant == "mytorrents"
        {
            
$htmlout .= "<td align='right'>";
            if (
$row["visible"] == "no")
                
$htmlout .= "<b>".$lang["torrenttable_not_visible"]."</b>";
            else
                
$htmlout .= "".$lang["torrenttable_visible"]."";
            
$htmlout .= "</td>\n";
        }

        if (
$row["type"] == "single")
        {
            
$htmlout .= "<td align='right'>{$row["numfiles"]}</td>\n";
        }
        else 
        {
            if (
$variant == "index")
            {
                
$htmlout .= "<td align='right'><b><a href='filelist.php?id=$id'>" $row["numfiles"] . "</a></b></td>\n";
            }
            else
            {
                
$htmlout .= "<td align='right'><b><a href='filelist.php?id=$id'>" $row["numfiles"] . "</a></b></td>\n";
            }
        }

        if (!
$row["comments"])
        {
            
$htmlout .= "<td align='right'>{$row["comments"]}</td>\n";
        }
        else 
        {
            if (
$variant == "index")
            {
                
$htmlout .= "<td align='right'><b><a href='details.php?id=$id&amp;hit=1&amp;tocomm=1'>" $row["comments"] . "</a></b></td>\n";
            }
            else
            {
                
$htmlout .= "<td align='right'><b><a href='details.php?id=$id&amp;page=0#startcomments'>" $row["comments"] . "</a></b></td>\n";
            }
        }

/*
        print("<td align='center'>");
        if (!isset($row["rating"]))
            print("---");
        else {
            $rating = round($row["rating"] * 2) / 2;
            $rating = ratingpic($row["rating"]);
            if (!isset($rating))
                print("---");
            else
                print($rating);
        }
        print("</td>\n");
*/
        
$htmlout .= "<td align='center'><span style='white-space: nowrap;'>" str_replace(",""<br />"get_date$row['added'],'')) . "</span></td>\n";
        
$ttl = (28*24) - floor((time() - $row["added"]) / 3600);

if ($ttl == 1
                   
$ttl .= "<br />".$lang["torrenttable_hour_singular"].""
                else 
                   
$ttl .= "<br />".$lang["torrenttable_hour_plural"]."";
    
    
$htmlout .= "<td align='center'>$ttl</td>\n
    <td align='center'>" 
str_replace(" ""<br />"mksize($row["size"])) . "</td>\n";
//        print("<td align='right'>" . $row["views"] . "</td>\n");
//        print("<td align='right'>" . $row["hits"] . "</td>\n");

        
            
if ($row["times_completed"] != 1)
              
$_s "".$lang["torrenttable_time_plural"]."";
            else
              
$_s "".$lang["torrenttable_time_singular"]."";
            
$htmlout .= "<td align='center'><a href=snatches.php?id=$id>" number_format($row["times_completed"]) . "<br />$_s</td>\n";

        if (
$row["seeders"]) 
        {
            if (
$variant == "index")
            {
               if (
$row["leechers"]) $ratio $row["seeders"] / $row["leechers"]; else $ratio 1;
                
$htmlout .= "<td align='right'><b><a href='peerlist.php?id=$id#seeders'>
                <font color='" 
.get_slr_color($ratio) . "'>{$row["seeders"]}</font></a></b></td>\n";
            }
            else
            {
                
$htmlout .= "<td align='right'><b><a class='" linkcolor($row["seeders"]) . "' href='peerlist.php?id=$id#seeders'>{$row["seeders"]}</a></b></td>\n";
            }
        }
        else
        {
            
$htmlout .= "<td align='right'><span class='" linkcolor($row["seeders"]) . "'>" $row["seeders"] . "</span></td>\n";
        }

        if (
$row["leechers"]) 
        {
            if (
$variant == "index")
                
$htmlout .= "<td align='right'><b><a href='peerlist.php?id=$id#leechers'>" .
                   
number_format($row["leechers"]) . "</a></b></td>\n";
            else
                
$htmlout .= "<td align='right'><b><a class='" linkcolor($row["leechers"]) . "' href='peerlist.php?id=$id#leechers'>{$row["leechers"]}</a></b></td>\n";
        }
        else
            
$htmlout .= "<td align='right'>0</td>\n";

        if (
$variant == "index")
            
$htmlout .= "<td align='center'>" . (isset($row["username"]) ? ("<a href='userdetails.php?id=" $row["owner"] . "'><b>" htmlspecialchars($row["username"]) . "</b></a>") : "<i>(".$lang["torrenttable_unknown_uploader"].")</i>") . "</td>\n";

       
$htmlout .= "</tr>\n";
    }

    
$htmlout .= "</table>\n";

    return 
$htmlout;
}

function 
commenttable($rows)
{
global $CURUSER$TBDEV;


$lang load_language'torrenttable_functions' );

$htmlout '';
$count 0;

$htmlout .= begin_main_frame();
$htmlout .= begin_frame();

foreach ($rows as $row)
{
$htmlout .= "<p class='sub'>#{$row["id"]} {$lang["commenttable_by"]} ";
    if (isset(
$row["username"]))
{
$title $row["title"];
if ($title == "")
$title get_user_class_name($row["class"]);
else
$title htmlspecialchars($title);
        
$htmlout .= "<a name='comm{$row["id"]}' href='userdetails.php?id={$row["user"]}'><b>" .
        
htmlspecialchars($row["username"]) . "</b></a>" . ($row["donor"] == "yes" "<img src='{$TBDEV['pic_base_url']}star.gif' alt='".$lang["commenttable_donor_alt"]."' />" "") . ($row["warned"] == "yes" "<img src=".
    
"'{$TBDEV['pic_base_url']}warned.gif' alt='".$lang["commenttable_warned_alt"]."' />" "") . " ($title)\n";
}
else
   
$htmlout .= "<a name='comm{$row["id"]}'><i>(".$lang["commenttable_orphaned"].")</i></a>\n";

$htmlout .= get_date$row['added'],'');
$htmlout .= ($row["user"] == $CURUSER["id"] || get_user_class() >= UC_MODERATOR "- [<a href='comment.php?action=edit&amp;cid={$row['id']}'>".$lang["commenttable_edit"]."</a>]" "") .
(get_user_class() >= UC_MODERATOR "- [<a href='comment.php?action=delete&amp;cid={$row['id']}'>".$lang["commenttable_delete"]."</a>]" "") .
($row["editedby"] && get_user_class() >= UC_MODERATOR "- [<a href='comment.php?action=vieworiginal&amp;cid={$row['id']}'>".$lang["commenttable_view_original"]."</a>]" "") . "</p>\n";
$avatar = ($CURUSER["avatars"] == "yes" htmlspecialchars($row["avatar"]) : "");

if (!$avatar)
$avatar "{$TBDEV['pic_base_url']}default_avatar.gif";
$text format_comment($row["text"]);
    if (
$row["editedby"])
    
$text .= "<p><font size='1' class='small'>".$lang["commenttable_last_edited_by"]." <a href='userdetails.php?id={$row['editedby']}'><b>{$row['username']}</b></a> ".$lang["commenttable_last_edited_at"]." ".get_date($row['editedat'],'DATE')."</font></p>\n";
$htmlout .= begin_table(true);
$htmlout .= "<tr valign='top'>\n";
$htmlout .= "<td align='center' width='150' style='padding: 0px'><img width='{$row['av_w']}' height='{$row['av_h']}' src='{$avatar}' alt='' /></td>\n";
$htmlout .= "<td class='text'>$text</td>\n";
$htmlout .= "</tr>\n";
     
$htmlout .= end_table();
  }
$htmlout .= end_frame();
$htmlout .= end_main_frame();

return $htmlout;
}


?>


Best regards

denede

#2
thank you :)

Mindless

Credits go to the author = MarkoStamcar.
Credits also to putyn and pdq.
Xhtml valid.

@ file browse.php find :
 
Code (php) Select
if(isset($_GET["search"]))
    {
      $searchstr = unesc($_GET["search"]);
      $cleansearchstr = searchfield($searchstr);
      if (empty($cleansearchstr))
        unset($cleansearchstr);
    }


Replace it with this :

Code (php) Select
$searchstr = (isset($_GET['search']) ? unesc($_GET['search']) : '');
$cleansearchstr = searchfield($searchstr);
if (empty($cleansearchstr))
    unset($cleansearchstr);
if (isset($_GET['sort']) && isset($_GET['type'])) {
    $column = '';
    $ascdesc = '';

    switch ($_GET['sort']) {
        case '1': $column = "name";
            break;
        case '2': $column = "numfiles";
            break;
        case '3': $column = "comments";
            break;
        case '4': $column = "added";
            break;
        case '5': $column = "size";
            break;
        case '6': $column = "times_completed";
            break;
        case '7': $column = "seeders";
            break;
        case '8': $column = "leechers";
            break;
        case '9': $column = "owner";
            break;
        default: $column = "id";
            break;
    }

    switch ($_GET['type']) {
        case 'asc': $ascdesc = "ASC";
            $linkascdesc = "asc";
            break;
        case 'desc': $ascdesc = "DESC";
            $linkascdesc = "desc";
            break;
        default: $ascdesc = "DESC";
            $linkascdesc = "desc";
            break;
    }

    $orderby = "ORDER BY torrents." . $column . " " . $ascdesc;
    $pagerlink = "sort=" . intval($_GET['sort']) . "&type=" . $linkascdesc . "&";
    } else {
    $orderby = "ORDER BY torrents.sticky ASC, torrents.id DESC";
    $pagerlink = "";
    }

   
*Note if you dont use sticky torrents then this line here :

Code (php) Select
$orderby = "ORDER BY torrents.sticky ASC, torrents.id DESC";

Should be

Code (php) Select
$orderby = "ORDER BY torrents.id DESC";

Make sure you do that part correctly before posting unknown column = torrents.sticky

Next still in browse.php find

Code (php) Select
$torrentsperpage = $CURUSER["torrentsperpage"];
    if (!$torrentsperpage)
      $torrentsperpage = 15;

    if ($count)
    {

   
Under it add :

Code (php) Select
if ($addparam != "") {
            if ($pagerlink != "") {
                if ($addparam{strlen($addparam)-1} != ";") { // & = &amp;
                    $addparam = $addparam . "&" . $pagerlink;
                } else {
                    $addparam = $addparam . $pagerlink;
                }
            }
        } else {
            $addparam = $pagerlink;
        }

       
@file include/torrent_table_functions find :

Code (php) Select
$htmlout .= "<table border='1' cellspacing='0' cellpadding='5'>
    <tr>
    <td class='colhead' align='center'>{$lang["torrenttable_type"]}</td>
    <td class='colhead' align='left'>{$lang["torrenttable_name"]}</td>
    <!--<td class='heading' align='left'>{$lang["torrenttable_dl"]}</td>-->";

if ($wait)
{
$htmlout .= "<td class='colhead' align='center'>{$lang["torrenttable_wait"]}</td>\n";
}

if ($variant == "mytorrents")
  {
  $htmlout .= "<td class='colhead' align='center'>{$lang["torrenttable_edit"]}</td>\n";
    $htmlout .= "<td class='colhead' align='center'>{$lang["torrenttable_visible"]}</td>\n";
}


    $htmlout .= "<td class='colhead' align='right'>{$lang["torrenttable_files"]}</td>
    <td class='colhead' align='right'>{$lang["torrenttable_comments"]}</td>
    <!--<td class='colhead' align='center'>{$lang["torrenttable_rating"]}</td>-->
    <td class='colhead' align='center'>{$lang["torrenttable_added"]}</td>
    <td class='colhead' align='center'>{$lang["torrenttable_ttl"]}</td>
    <td class='colhead' align='center'>{$lang["torrenttable_size"]}</td>
    <!--
    <td class='colhead' align='right'>{$lang["torrenttable_views"]}</td>
    <td class='colhead' align='right'>{$lang["torrenttable_hits"]}</td>
    -->
    <td class='colhead' align='center'>{$lang["torrenttable_snatched"]}</td>
    <td class='colhead' align='right'>{$lang["torrenttable_seeders"]}</td>
    <td class='colhead' align='right'>{$lang["torrenttable_leechers"]}</td>";


    if ($variant == 'index')
        $htmlout .= "<td class='colhead' align='center'>{$lang["torrenttable_uppedby"]}</td>\n";

       
And replace the full section with this :

Code (php) Select
$oldlink = '';
    $count_get = 0;
    $char = '';
    $description = '';
    $type = '';
    $sort = '';
    $row = '';
    foreach ($_GET as $get_name => $get_value) {
        $get_name = mysql_escape_string(strip_tags(str_replace(array("\"", "'"), array("", ""), $get_name)));

        $get_value = mysql_escape_string(strip_tags(str_replace(array("\"", "'"), array("", ""), $get_value)));

        if ($get_name != "sort" && $get_name != "type") {
            if ($count_get > 0) {
                $oldlink = $oldlink . "&amp;" . $get_name . "=" . $get_value;
            } else {
                $oldlink = ($oldlink) . $get_name . "=" . $get_value;
            }
            $count_get++;
        }
    }

    if ($count_get > 0) {
        $oldlink = $oldlink . "&amp;";
    }

    if (isset($_GET["sort"]) && $_GET["sort"] == "1") {
        if (isset($_GET["type"]) && $_GET["type"] == "desc") {
            $link1 = "asc";
        } else {
            $link1 = "desc";
        }
    }
    if (isset($_GET["sort"]) && $_GET["sort"] == "2") {
        if (isset($_GET["type"]) && $_GET["type"] == "desc") {
            $link2 = "asc";
        } else {
            $link2 = "desc";
        }
    }
    if (isset($_GET["sort"]) && $_GET["sort"] == "3") {
        if (isset($_GET["type"]) && $_GET["type"] == "desc") {
            $link3 = "asc";
        } else {
            $link3 = "desc";
        }
    }
    if (isset($_GET["sort"]) && $_GET["sort"] == "4") {
        if (isset($_GET["type"]) && $_GET["type"] == "desc") {
            $link4 = "asc";
        } else {
            $link4 = "desc";
        }
    }
    if (isset($_GET["sort"]) && $_GET["sort"] == "5") {
        if (isset($_GET["type"]) && $_GET["type"] == "desc") {
            $link5 = "asc";
        } else {
            $link5 = "desc";
        }
    }
    if (isset($_GET["sort"]) && $_GET["sort"] == "6") {
        if (isset($_GET["type"]) && $_GET["type"] == "desc") {
            $link6 = "asc";
        } else {
            $link6 = "desc";
        }
    }
    if (isset($_GET["sort"]) && $_GET["sort"] == "7") {
        if (isset($_GET["type"]) && $_GET["type"] == "desc") {
            $link7 = "asc";
        } else {
            $link7 = "desc";
        }
    }
    if (isset($_GET["sort"]) && $_GET["sort"] == "8") {
        if (isset($_GET["type"]) && $_GET["type"] == "desc") {
            $link8 = "asc";
        } else {
            $link8 = "desc";
        }
    }
    if (isset($_GET["sort"]) && $_GET["sort"] == "9") {
        if (isset($_GET["type"]) && $_GET["type"] == "desc") {
            $link9 = "asc";
        } else {
            $link9 = "desc";
        }
    }

    if (empty($link1)) {
        $link1 = "asc";
    }
    if (empty($link2)) {
        $link2 = "desc";
    }
    if (empty($link3)) {
        $link3 = "desc";
    }
    if (empty($link4)) {
        $link4 = "desc";
    }
    if (empty($link5)) {
        $link5 = "desc";
    }
    if (empty($link6)) {
        $link6 = "desc";
    }
    if (empty($link7)) {
        $link7 = "desc";
    }
    if (empty($link8)) {
        $link8 = "desc";
    }
    if (empty($link9)) {
        $link9 = "desc";
    }
 

   $htmlout .= "<table border='1' cellspacing='0' cellpadding='5'>
   <tr>
   <td class='colhead' align='center'>{$lang["torrenttable_type"]}</td>
   <td class='colhead' align='left'><a href='{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=1&amp;type={$link1}'>{$lang["torrenttable_name"]}</a></td>";
   
   if ($wait)
   {
   $htmlout .="<td class='colhead' align='center'>{$lang["torrenttable_wait"]}</td>\n";
   }   

   if ($variant == "mytorrents")
   {
   $htmlout .= "<td class='colhead' align='center'>{$lang["torrenttable_edit"]}</td>\n";
   $htmlout .= "<td class='colhead' align='center'>{$lang["torrenttable_visible"]}</td>\n";
   }

   $htmlout .= "<td class='colhead' align='right'><a href='{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=2&amp;type={$link2}'>{$lang["torrenttable_files"]}</a></td>
   <td class='colhead' align='right'><a href='{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=3&amp;type={$link3}'>{$lang["torrenttable_comments"]}</a></td>
   <td class='colhead' align='center'><a href='{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=4&amp;type={$link4}'>{$lang["torrenttable_added"]}</a></td>
   <td class='colhead' align='center'>{$lang["torrenttable_ttl"]}</td>
   <td class='colhead' align='center'><a href='{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=5&amp;type={$link5}'>{$lang["torrenttable_size"]}</a></td>
   <td class='colhead' align='center'><a href='{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=6&amp;type={$link6}'>{$lang["torrenttable_snatched"]}</a></td>
   <td class='colhead' align='right'><a href='{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=7&amp;type={$link7}'>{$lang["torrenttable_seeders"]}</a></td>
   <td class='colhead' align='right'><a href='{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=8&amp;type={$link8}'>{$lang["torrenttable_leechers"]}</a></td>";

   if ($variant == 'index')
   $htmlout .= "<td class='colhead' align='center'><a href='{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=9&amp;type={$link9}'>{$lang["torrenttable_uppedby"]}</a></td>\n";

   
And thats it for a default unmoddifed torrenttable, if you have extras then add them or post if you cant - ensure you back up your files before modifying - Any errors or issues please post them - If you want an image on your torrenttable its as easy as replacing the {$lang["torrenttable_leechers"]} entrys for all columns with an img link.