Bravo List

Bravo List (http://www.bvlist.com/index.php)
-   TBDev (http://www.bvlist.com/forumdisplay.php?f=20)
-   -   ajax browse help please (http://www.bvlist.com/showthread.php?t=8723)

sharpie 6th January 2013 02:49

ajax browse help please
 
can anyone help me please im trying to add torrent new tags so when a new torrent gets uploaded it says new, to this ajax browse but not having any success

Code:

require_once("include/bittorrent.php");
if(eregi(basename(__FILE__),$_SERVER['REQUEST_URI'])){
        print("

You know you're not allowed to look directly at scripts.. so stop trying to peak

");
        die();
}

//        ==        TheHippy Ajax Browse Class 2010
//
//        ==       
class browseTorrents extends db {

        // $active statuses are 1=active only, 2=dead only, 3=active and dead
        public function getTorrentList($cats_id=0,$active=3,$page=1,$stext=0)
        {
                $cats = genrelist();
                $cattotal = count($cats);
                $output        =        "";
              $perpage = "25";
                $offset = ($page - 1) * $perpage;
                $where        =        "";
                $ccase        =        "";
                if($cats_id != "0"){
                        $where        =        " WHERE ";
                                $ccase        .=        "`torrents`.`category`='" . urlencode($cats_id) . "'";
                }
                if($stext        != "0"){
                        if($where == " WHERE "){
                                $ccase        .=        " AND `torrents`.`name` LIKE '%" . htmlspecialchars($stext) . "%'";
                        } else {
                                $where = " WHERE ";
                                $ccase        .=        "`torrents`.`name` LIKE '%" . htmlspecialchars($stext) . "%'";
                        }
                }
                switch($active)
                {
                        case 1:
                        if($where == " WHERE "){
                                $ccase        .=        " AND `torrents`.`visible`='yes'";
                        } else {
                                $where = " WHERE ";
                                $ccase        .=        "`torrents`.`visible`='yes'";
                        }
                        break;
                        case 2:
                        if($where == " WHERE "){
                                $ccase        .=        " AND `torrents`.`visible`='no'";
                        } else {
                                $where = " WHERE ";
                                $ccase        .=        "`torrents`.`visible`='no'";
                        }
                        break;
                        case 3:
                        break;
                }

                //        =        This counts the total torrents for pagination
                $sql2        =        "SELECT `torrents`.`id`, `torrents`.`name` AS `torrentname`, `torrents`.`filename`, `torrents`.`description`,`torrents`.`category`, `torrents`.`size`, `torrents`.`added`, `torrents`.`type`, `torrents`.`numfiles`, `torrents`.`comments`, `torrents`.`views`, `torrents`.`hits`, `torrents`.`times_completed`, `torrents`.`leechers`, `torrents`.`seeders`, `torrents`.`owner`, `users`.`username`,`users`.`privacy`, `users`.`id` AS `user_id`, `categories`.`name` FROM `torrents` LEFT JOIN `users` ON `users`.`id`=`torrents`.`owner` LEFT JOIN `categories` ON `categories`.`id`=`torrents`.`category` " . $where . $ccase . "";
                $gettotals        =        $this->query($sql2);
                $totalt                =        $this->rows;
                $maxpage        =        ceil($totalt/$perpage);
                $npage        =        array();
                //        =        This makes the pagination
                if($page > 1){
                                $pagefirst        =        "document.getElementById('page').value='1';";
                                $npage[]        =        " « First Page ";
                                $pagel                =        "document.getElementById('page').value='$maxpage';";
                                $lastpage        =        "" . $maxpage . "";
                                $pageback        =        $page-1;
                                $pageba                =        "document.getElementById('page').value='$pageback';";
                                $npage[]        =        " ";
                        if($page < $maxpage){
                                $pageforr        =        $page+1;
                                $pagefor        =        "document.getElementById('page').value='$pageforr';";
                                $npage[]        =        " ";
                                $pagelast        =        "document.getElementById('page').value='$maxpage';";
                                $npage[]        =        " Last Page » ";
                                $pagel                =        "document.getElementById('page').value='$maxpage';";
                                $lastpage        =        "" . $maxpage . "";
                        }       
                }
                if($maxpage > 1){
                if($page == 1){
                        $pageforr        =        $page+1;
                        $pagefor        =        "document.getElementById('page').value='$pageforr';";
                        $npage[]        =        " ";
                        $pagelast        =        "document.getElementById('page').value='$maxpage';";
                        $npage[]        =        " Last Page »";
                }
                }
                        $output                .=        "Refresh Table";
                        $output                .=        "Total Torrents found: $totalt";
                        foreach($npage as $key=>$val) {
                                $output        .=        $val;
                        }
                $output                .=        "
";
                //        =        This makes the actual query to populate the table of results

                $sql        =        "SELECT `torrents`.`id`, `torrents`.`name` AS `torrentname`, `torrents`.`filename`, `torrents`.`ori_descr`, torrents.free,`torrents`.`category`, torrents.10days, categories.name AS cat_name, categories.image AS cat_pic, `torrents`.`size`, `torrents`.`added`, `torrents`.`type`, `torrents`.`numfiles`, `torrents`.`comments`, `torrents`.`views`, `torrents`.`hits`, `torrents`.`times_completed`, `torrents`.`leechers`, `torrents`.`seeders`, `torrents`.`owner`, `users`.`username`,`users`.`privacy`, `users`.`id` AS `user_id`, `categories`.`name`,users.class as owner_class FROM `torrents` LEFT JOIN `users` ON `users`.`id`=`torrents`.`owner` LEFT JOIN `categories` ON `categories`.`id`=`torrents`.`category` " . $where . $ccase . " ORDER BY `torrents`.`id` DESC LIMIT $offset,$perpage";
                $tors        =        $this->query($sql);
                $total        =        $this->rows;

                //        = Start building what'll be displayed in the users browser
                if($this->rows > 0){
                $output        .=        "\n";
                $output        .=        "\n";
                $output        .=        "        \n";
                $output        .=        "                \n";
                $output        .=        "                \n";
                $output        .=        "                \n";
                $output        .=        "                \n";
                $output        .=        "                \n";
                $output        .=        "                \n";
                $output        .=        "                \n";
                $output        .=        "                \n";
                $output        .=        "                \n";
                $output        .=        "        \n";
                        while($tor        =        mysql_fetch_array($tors)){
/*                                $ttl = (28*24) - floor((time() - $tor["added"]) / 3600);                                               
                                if ($ttl == 1){
                                        $ttl .= "Hour";
                                } else {
                                        $ttl .= "Hours";
                                }
*/

                                $leecha                =        "";
                                $leechb                =        "";
                                $seeda                =        "";
                                $seedb                =        "";
                                if($tor['leechers'] > 0){
                                        $leecha        =        "";       
                                        $leechb        =        "
";
                                }
                                if($tor['seeders'] > 0){
                                        $seeda        =        "";       
                                        $seedb        =        "
";
                                }
                                if($tor['comments'] >= 1){
                                        $com1        =        "";       
                                        $com2        =        "
";
                                }

        $thisisfrees = ($tor[free]=="yes" ? "" : "");
        $doubleuptag = ($tor["10days"]=="yes" ? "x2" : "");     
$dispname = htmlspecialchars($tor["torrentname"]);
$dispname1 = htmlspecialchars($tor["ori_descr"]);
if (get_user_class() >= UC_VIP){
$dl = ("Download");
}        $added = "" . get_elapsed_times(sql_timestamp_to_unix_timestamp($tor["added"])) . " ago";
                                $detaila        =        "";
                                $detailb        =        "
";
                                $filesa                =        "";
                                $filesb                =        "
";
                                $ownera                =        "";
                                $ownerb                =        "
";
                                $catega                =        "";
                                $categb                =        "
";
                                $downla                =        "";
                                $downlb                =        "
";       
                                $output        .=        "       
";
                                $output        .=        "                \n";
                            $output        .=        "                \n";
//                                $output        .=        "                \n";
                                $output        .=        "                \n";
                                $output        .=        "                \n";
                                $output        .=        "                \n";
                                $output        .=        "                \n";
                                $output        .=        "                \n";
                                $output        .=        "                \n";
                                $output        .=        "        ";
                        }
                $output        .=        "
GenreNameAddedCommentsSizeSnatchesSeedersLeechersUpped by
". $detaila . $tor['torrentname'] . $detailb ."$dl $thisisfrees $doubleuptag\n";
                                $output        .=        "               
$added" . $ttl . "" . $tor['comments'] . "" . str_replace(" ", " ", mksize($tor["size"])) . "" . $tor['times_completed'] . "" . $seeda . $tor['seeders'] . $seedb . "" . $leecha . $tor['leechers'] . $leechb . "" . $ownera . $tor['username'] . $ownerb . "
\n";
                } else {
                        $output.=        "

Sorry: There are no torrents that match your criteria, try amending your options.

";       
                }
                        $output                .=        "
Total Torrents found: $totalt";
                        foreach($npage as $key=>$val) {
                                $output        .=        $val;
                        }
                        $output                .=        "
";
                        // = Amend with your website address below...
                        //$output.=        "Link to this page: https://gettorrents.org/browse.php?cat_id=" . $cats_id . "&active=" . $active . "&page=" . $page . "&search=" . $stext . "";
                return $output;
        }
}
?>


wMan 6th January 2013 02:58

im looking for the browse.php with cats dro down so n i do not le the one that on it to an oe have a good browse page ?


this one crap

PHP Code:

<?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();

    if(isset(
$_GET["search"])) 
    {
      
$searchstr unesc($_GET["search"]);
      
$cleansearchstr searchfield($searchstr);
      if (empty(
$cleansearchstr))
        unset(
$cleansearchstr);
    }

    
$orderby "ORDER BY torrents.id DESC";

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

    if (isset(
$_GET["incldead"]) &&  $_GET["incldead"] == 1)
    {
      
$addparam .= "incldead=1&";
      if (!isset(
$CURUSER) || get_user_class() < UC_ADMINISTRATOR)
        
$wherea[] = "banned != 'yes'";
    }
    else
    {
      if (isset(
$_GET["incldead"]) && $_GET["incldead"] == 2)
      {
      
$addparam .= "incldead=2&";
        
$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&";
          }
        }
      }
      elseif (
$category)
      {
        if (!
is_valid_id($category))
          
stderr("{$lang['browse_error']}""{$lang['browse_invalid_cat']}");
        
$wherecatina[] = $category;
        
$addparam .= "cat=$category&";
      }
      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&";
          }
        }
      }
    }
    
    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) . "&";
      
$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)
    {
      
//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.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 class='thecloud'>";


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

    
$HTMLOUT .= "
                 <div class='cblock'>
                     <div class='cblock-header'>Browse</div>
                     <div class='cblock-lb'>Browse your desired torrents!</div>
                     <div class='cblock-content'>"
;
    
$HTMLOUT .= "
                         <form method='get' action='browse.php'>
                              <div class='base-layer'>
                                  <div class='table-row'>"
;
    
$i 0;
    
$catsperrow 4;
    foreach (
$cats as $cat)
    {
      
$HTMLOUT .= ($i && $i $catsperrow == 0) ? "</div><div class='space-line'></div><div class='table-row'>" "";
      
$HTMLOUT .= "
                                      <div class='left-layer'>
                                          <p class='text'>
                                            <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']}'>" htmlsafechars($cat['name']) . "</a>
                                          </p>
                                      </div>\n"
;
      
$i++;
    }

    
$HTMLOUT .= "
                                  </div>
                              </div>"
;

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

    
$HTMLOUT .= "<div style='float:left; padding:8px;'>";
    
$HTMLOUT .= "    <table>
                           <tr>"
;

    
$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>
                 </div>
                 <div style='float:left; padding:5px;'>
                     <table>
                           <tr>
                              <td class='bottom'>
                                 <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>
                     </table>
                 </div>
                 <div style='float:left;'>
                     <table>
                           <tr>
                              <td class='bottom'>
                                 <input type='submit' value='
{$lang['browse_go']}' />
                              </td>
                           </tr>
                     </table>
                 </div>
   </form>"
;

    
$HTMLOUT .= "<div class='clear'>&nbsp;</div>";

    
$HTMLOUT .= "<div style='width:100%; height:100%; margin:0 auto;'>";



    if (isset(
$cleansearchstr))
    {
      
$HTMLOUT .= "<h2>{$lang['browse_search']}\"" htmlsafechars$searchstr ) . "\"</h2>\n";
    }

    if (
$count)
    {
      
$HTMLOUT .= $pager['pagertop'];

      
$HTMLOUT .= torrenttable($res);

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

    
$HTMLOUT .= "
                 </div>"
;


    
$HTMLOUT .= "
      </div></div>"
;

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

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

?>


ndbj 6th January 2013 08:10

Don't know if this will do, but try:


change this:

PHP Code:

$output    .=    "        <td align=\"left\"><b>"$detaila $tor['torrentname'] . $detailb ."$dl $thisisfrees $doubleuptag</b></a>\n"

to this:

PHP Code:

if (sql_timestamp_to_unix_timestamp($tor["added"]) >= $last_browse)
$output    .=    "        <td align=\"left\"><b>"$detaila $tor['torrentname'] . $detailb ."$dl $thisisfrees $doubleuptag &nbsp;(<font color=red>New</font>)</b></a>\n";
else
$output    .=    "        <td align=\"left\"><b>"$detaila $tor['torrentname'] . $detailb ."$dl $thisisfrees $doubleuptag</b></a>\n"


sharpie 6th January 2013 16:32

yup that works then i add this code in but to clear the new tags but not working it used to work before i updated the browse.php to ajax
Code:

if ($_GET['clear_new']){
mysql_query("UPDATE users SET last_browse=".gmtime()." where id=".$CURUSER['id']);
header("Location: browse.php");
}

Click HERE to Clear NEW! tags

so in my first post is browse.class.php

and this is the borwse.php

Code:

//ini_set("display_errors","2");
//ERROR_REPORTING(E_ALL);
// == If not working, uncomment above for debugging.

/*
+------------------------------------------------
|  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$
+------------------------------------------------
                                = Ajax Browse by TheHippy 2010
*/
ob_start("ob_gzhandler");

require_once("include/bittorrent.php");
include("class/db.class.php");
include("class/browse.class.php");
dbconn(false);

loggedinorreturn();
getpage();
parked();
if ($_GET['clear_new']){
mysql_query("UPDATE users SET last_browse=".gmtime()." where id=".$CURUSER['id']);
header("Location: browse.php");
}
$torrents = array();
        $res = mysql_query("SELECT torrent, seeder, COUNT(*) AS c FROM peers GROUP BY torrent, seeder");
        while ($row = mysql_fetch_assoc($res)) {
                if ($row["seeder"] == "yes")
                        $key = "seeders";
                else
                        $key = "leechers";
                $torrents[$row["torrent"]][$key] = $row["c"];
        }

        $res = mysql_query("SELECT torrent, COUNT(*) AS c FROM comments GROUP BY torrent");
        while ($row = mysql_fetch_assoc($res)) {
                $torrents[$row["torrent"]]["comments"] = $row["c"];
        }

        $fields = explode(":", "comments:leechers:seeders");
        $res = mysql_query("SELECT id, seeders, leechers, comments FROM torrents");
        while ($row = mysql_fetch_assoc($res)) {
                $id = $row["id"];
                $torr = $torrents[$id];
                foreach ($fields as $field) {
                        if (!isset($torr[$field]))
                                $torr[$field] = 0;
                }
                $update = array();
                foreach ($fields as $field) {
                        if ($torr[$field] != $row[$field])
                                $update[] = "$field = " . $torr[$field];
                }
                if (count($update))
                        mysql_query("UPDATE torrents SET " . implode(",", $update) . " WHERE id = $id");
}
      $deadtime = deadtime();
      mysql_query("DELETE FROM peers WHERE last_action < FROM_UNIXTIME($deadtime)");

        $deadtime -= $max_dead_torrent_time;
        mysql_query("UPDATE torrents SET visible='no' WHERE visible='yes' AND last_action < FROM_UNIXTIME($deadtime)");
//--- Added by Wilba --------------------------------
//mysql_query("UPDATE users SET last_browse=".gmtime()." where id=".$CURUSER['id']);
//---------------------------------------------------
mysql_query("UPDATE torrents SET free = 'yes' WHERE free = 'no' AND seeders>='3'")or sqlerr(__FILE__, __LINE__);
mysql_query("UPDATE torrents SET free = 'no' WHERE free = 'yes' AND seeders<'10'") or sqlerr(__FILE__, __LINE__);
mysql_query("UPDATE torrents SET free = 'yes' WHERE size > '1073741824' AND seeders>='1'") or sqlerr(__FILE__, __LINE__);
mysql_query("UPDATE torrents SET free = 'no' WHERE size > '1073741824' AND seeders<'10'") or sqlerr(__FILE__, __LINE__);
mysql_query("UPDATE torrents SET free = 'yes' WHERE size > '1073741824'") or sqlerr(__FILE__, __LINE__);
//mysql_query ("UPDATE torrents SET request = 'yes' WHERE request = ''") or sqlerr(__FILE__, __LINE__);
//mysql_query ("UPDATE torrents SET request = 'yes' WHERE request = 'no'") or sqlerr(__FILE__, __LINE__);

//=== remove donor status if time up AND set class back to power user... remember to set the class number for your system===//
$res = mysql_query("SELECT id, modcomment FROM users WHERE donor='yes' AND donoruntil < NOW() AND donoruntil <> '0000-00-00 00:00:00'") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) > 0)
{
$dt = sqlesc(get_date_time());
$subject = sqlesc("Donor status removed by system.");
$msg = sqlesc("Your Donor status has timed out and has been auto-removed by the system, and your VIP status has been removed. We would like to thank you once again for your support to Gettorrents.org. If you wish to re-new your donation, you can do so by going to http://gettorrents.org/donate.php. Cheers!\n");
while ($arr = mysql_fetch_assoc($res))
{
///---AUTOSYSTEM MODCOMMENT---//
$modcomment = htmlspecialchars($arr["modcomment"]);
$modcomment = gmdate("d-m-Y") . " - Donor status removed by -System.\n". $modcomment;
$modcom = sqlesc($modcomment);
///---AUTOSYSTEM MODCOMMENT---//
mysql_query("UPDATE users SET class = '0', donor = 'no', donoruntil = '0000-00-00 00:00:00', modcomment = $modcom WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__);
mysql_query("INSERT INTO messages (sender, receiver, added, msg, subject, poster) VALUES(0, $arr[id], $dt, $msg, $subject, 0)") or sqlerr(__FILE__, __LINE__);
}
}
//===end===//

//=== remove donor status if time up AND set class back to power user... remember to set the class number for your system===//
$res = mysql_query("SELECT id, modcomment FROM users WHERE donor='no' AND donoruntil < NOW() AND donoruntil <> '0000-00-00 00:00:00'") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) > 0)
{
$dt = sqlesc(get_date_time());
$subject = sqlesc("Donor status removed by system.");
$msg = sqlesc("Your Donor status has timed out and has been auto-removed by the system, and your VIP status has been removed. We would like to thank you once again for your support to Gettorrents.org. If you wish to re-new your donation, you can do so by going to http://gettorrents.org/donate.php. Cheers!\n");
while ($arr = mysql_fetch_assoc($res))
{
///---AUTOSYSTEM MODCOMMENT---//
$modcomment = htmlspecialchars($arr["modcomment"]);
$modcomment = gmdate("d-m-Y") . " - Donor status removed by -System.\n". $modcomment;
$modcom = sqlesc($modcomment);
///---AUTOSYSTEM MODCOMMENT---//
mysql_query("UPDATE users SET class = '0', donor = 'no', donoruntil = '0000-00-00 00:00:00', modcomment = $modcom WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__);
mysql_query("INSERT INTO messages (sender, receiver, added, msg, subject, poster) VALUES(0, $arr[id], $dt, $msg, $subject, 0)") or sqlerr(__FILE__, __LINE__);
}
}
//===end===//

    //$HTMLOUT .= "";
    $cats = genrelist();
        $output        =        "";
        $cid        =        (isset($_GET['cat_id'])) ? $_GET['cat_id'] : "0";
        $aid        =        (isset($_GET['active'])) ? $_GET['active'] : "3";
        $pid        =        (isset($_GET['page'])) ? $_GET['page'] : "1";
        $stext        =        (isset($_GET['search'])) ? htmlspecialchars($_GET['search']) : "";
       
        $output.=        "";
        $output.=        "";
        $output.=        "";

        $cattotal = count($cats);
        $i                =        2;
        $output.=        "
:view_cate('view_cate_area', 'view_cate_link');\"> Show categories
Active Only\n";
        $output.=        "Dead Only\n";
        $output.=        "Active+Dead\n";
        $output.=        "All\n";
      foreach($cats as $cat){
                $output        .=        "" . $cat['name'] . "\n";

                if($i        ==8){
                        $output.=        "";

                        $i = 1;
                } else {
                        $i++;       
                }
        }
                $output.=        "
Search:  RSS
Can't find what you want? Request it Here!       Also check out Torrents needing seeds
\n";

/////////////////////// HTML OUTPUT //////////////////////////////
    print stdhead();
      if ($CURUSER["class"] >= UC_USER)
  {
/** shoutbox display **/
if ($CURUSER['shoutbox'] == 'yes')
require_once("ajaxchat.php");
$shout_toggle = ($CURUSER['shoutbox'] === 'no' ? '
Turn Shoutbox on

' : '');
echo $shout_toggle;
}
//top5();
        print $output;
        $btors        =        new browseTorrents;
        print("

");
        print($btors->getTorrentList());
        print("
");
        print("");
        print stdfoot();

?>


ndbj 7th January 2013 03:16

Do you need something to clear New Tags?
Does Refresh or just an F5 won't work?

sharpie 7th January 2013 03:36

An f5 doesn't clear new tags m8 even the clear tag code I posted above doesn't work but it did work on old browse I had

ndbj 7th January 2013 07:27

i understand now.
maybe something with the $last_browse
show me your include/bittorrent.php

\n");
                print("\n");
                print("\n");
                print("\n");
    end_table();
  }
        end_frame();
        end_main_frame();
}
//---------------------------------
//---- CHECK EMAIL ADDY WITH DNS
//---------------------------------
function check_email($email) {
    //Check Email Function
    $pattern = "/^[\w-]+(\.[\w-]+)*@";
    $pattern .= "([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})$/i";
    if (preg_match($pattern, $email)) {
        $parts = explode("@", $email);
        if (checkdnsrr($parts[1], "MX")){
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
//---------------------------------
//---- CHECK EMAIL ADDY WITH DNS
//---------------------------------
//putyn's rate mod
function getRate($id,$what) {
        GLOBAL $CURUSER;
        if($id == 0 || !in_array($what,array("topic","torrent")))
            return;
           
    $q = sql_query("SELECT sum(r.rating) as sum, count(r.rating) as count, r2.id as rated, r2.rating  FROM rating as r  LEFT JOIN rating as r2 ON (r2.".$what." = ".$id." AND r2.user = ".$CURUSER["id"].") WHERE r.".$what." = ".$id." GROUP BY r.".$what );
    $a = mysql_fetch_assoc($q);
   
        $p = ($a["count"] > 0 ? round((($a["sum"] / $a["count"]) * 20), 2) : 0);
        if($a["rated"])
            $rate = "";
        else {
            $i=1;
            $rate = "";
        }
        switch($what) {
            case "torrent" : $return = "
".$rate."
";
            break;
            case "topic" : $return = "
sharpie 7th January 2013 12:31

1 Attachment(s)
i think the $last_browse needs to be incorporated into the browse.class.php somehow
Code:

require_once('include/ctracker.php');
function local_user()
{
  return $_SERVER["SERVER_ADDR"] == $_SERVER["REMOTE_ADDR"];
}

if(!file_exists('include/config.php'))
            //die("Site is down for maintenance, please check back again later... thanks
");
      header("Refresh: 0; url=maintenance.php");
require_once('include/config.php');
if(empty($mysql_user) && empty($mysql_pass))
            //die("Site is down for maintenance, please check back again later.. thanks
");
      header("Refresh: 0; url=maintenance.php");
//Directory for cache
$CACHE = "cache"; # local path to cache, chmod 777 but deny access with .htaccess
function genreforumlist() {
global $CURUSER;
$res = mysql_query("SELECT id, name FROM forums WHERE minclassread<=$CURUSER[class] ORDER BY name");

while ($row = mysql_fetch_assoc($res))
$ret[] = $row;
return $ret;
}
/*
// Force HTTPS for security
if($_SERVER["HTTPS"] != "on") {
 $pageURL = "Location: https://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
 }
 header($pageURL);
}
*/
function getcountryid(){
$isps = array("pacbell.net"=>"United States of America",
"comcast.net"=>"United States of America",
"telia.com"=>"sweden",
"telecomplete.net"=>"United Kingdom",
"t-dialin.net"=>"germany",
"verizon.net"=>"United States of America",
"arcor-ip.net"=>"germany",
"fastres.net"=>"italy",
"skanova.com"=>"sweden",
"coltfrance.com"=>"france",
"rima-tde.net"=>"spain",
"svorka.net"=>"norway",
"nextgentel.com"=>"norway",
"perspektivbredband.net"=>"sweden",
"bezeqint.net"=>"israel",
"linnea.com"=>"sweden",
"sbcglobal.net"=>"United States of America",
"btcentralplus.com"=>"United Kingdom",
"cable.ntl.com"=>"United Kingdom",
"adelphia.net"=>"United States of America",
"telus.net"=>"canada",
"qwest.net"=>"United States of America",
"cox.net"=>"United States of America",
"ntl.com"=>"United Kingdom",
"bulldogdsl.com"=>"United Kingdom",
"as9105.com"=>"United Kingdom",
"virgin.net"=>"United Kingdom",
"tesco.net"=>"United Kingdom",
"bredband2.com"=>"Sweden",
"siol.net"=>"Slovenia",
"romtelecom.net"=>"Romania",
"blixtvik.net"=>"Sweden",
"pipex.com"=>"United Kingdom",
"barak-online.net"=>"israel",
"netatonce.net"=>"Sweden",
"plus.com"=>"United Kingdom",
"gaoland.net"=>"France",
"glocalnet.net"=>"Sweden",
"freedom2surf.net"=>"United Kingdom",
"btopenworld.com"=>"United Kingdom",
"proxad.net"=>"France",
"suomi.net"=>"Finland",
"siwnet.net"=>"Sweden",
"ono.com"=>"Spain",
"rogers.com"=>"Canada",
"rr.com"=>"United States of America",
"shawcable.net"=>"Canada",
"bellsouth.net"=>"United States of America",
"mindspring.com"=>"United States of America",
"optonline.net"=>"United States of America",
"charter.com"=>"United States of America",
"ameritech.net"=>"United States of America",
"wideopenwest.com"=>"United States of America",
"on.net"=>"Australia",
"auna.net"=>"Spain",
"mtulink.net"=>"Norway",
"triera.net"=>"Slovenia",
"mundo-r.com"=>"Spain",
"rcn.com"=>"United States of America",
"as1901.net"=>"Austria",
"swbell.net"=>"United States of America",
"insightBB.com"=>"United States of America",
"mchsi.com"=>"United States of America",
"aland.net"=>"Finland",
"touchtelindia.net"=>"India",
"cgocable.net"=>"Canada",
"videotron.ca"=>"Canada",
"dynamic.amis.hr"=>"Croatia",
"touchtelindia.net"=>"India",
"7starnet.com"=>"India",
"sify.net"=>"India",
"ukrtel.net"=>"Ukraine",
"asianet.co.th"=>"Thailand",
"emirates.net.ae"=>"United Arab Emirates",
"qdsl.olypen.com"=>"United States of America",
"alltel.net"=>"United States of America",
"aol.com"=>"United States of America",
"exatt.net"=>"United States of America",
"sprint-hsd.net"=>"United States of America",
"clearwire-dns.net"=>"United States of America",
"panline.net"=>"United States of America",
"ornskoldsvik.com"=>"Sweden",
"bbtec.net"=>"Japan",
"t-2.net"=>"Slovenia",
"pldt.net"=>"Philippines",
"cablebg.net"=>"Bulgaria",
"lvivnet.org"=>"Ukraine",
"evolvatelecom.net"=>"Romania");
$cc = array("se"=>1,
"us"=>2,
"ru"=>3,
"fi"=>4,
"ca"=>5,
"fr"=>6,
"de"=>7,
"cn"=>8,
"it"=>9,
"dk"=>10,
"no"=>11,
"uk"=>12,
"ie"=>13,
"pl"=>14,
"nl"=>15,
"be"=>16,
"jp"=>17,
"br"=>18,
"ar"=>19,
"au"=>20,
"nz"=>21,
"es"=>23,
"pt"=>24,
"mx"=>25,
"sg"=>26,
"za"=>29,
"kr"=>30,
"jm"=>31,
"lu"=>32,
"hk"=>33,
"bz"=>34,
"dz"=>35,
"ao"=>36,
"at"=>37,
"yu"=>38,
"as"=>39,
"my"=>40,
"do"=>41,
"gr"=>42,
"gt"=>43,
"il"=>44,
"pk"=>45,
"cz"=>46,
"yu"=>47,
"sc"=>48,
"tw"=>49,
"pr"=>50,
"cl"=>51,
"cu"=>52,
"cg"=>53,
"af"=>54,
"tr"=>55,
"uz"=>56,
"ch"=>57,
"ki"=>58,
"ph"=>59,
"bf"=>60,
"ng"=>61,
"is"=>62,
"nr"=>63,
"si"=>64,
"al"=>65,
"tm"=>66,
"ba"=>67,
"ad"=>68,
"lt"=>69,
"in"=>70,
"an"=>71,
"ua"=>72,
"ve"=>73,
"hu"=>74,
"ro"=>75,
"vu"=>76,
"vn"=>77,
"tt"=>78,
"hn"=>79,
"ec"=>81,
"bs"=>82,
"pe"=>83,
"kh"=>84,
"bb"=>85,
"bd"=>86,
"la"=>87,
"uy"=>88,
"ag"=>89,
"py"=>90,
"th"=>93,
"sn"=>94,
"tg"=>95,
"hr"=>97,
"ee"=>98,
"co"=>99,
"lb"=>100,
"lv"=>101,
"cr"=>102,
"eg"=>103,
"bg"=>104
);
$dom = gethostbyaddr(getip());
preg_match("@[^\.]+\.([^\.]+)$@i",$dom,$matches);

if (strlen($matches[1]) == 2 && isset($cc[strtolower($matches[1])])){//got them by their country code (.uk etc)
return $cc[strtolower($matches[1])];

}elseif (isset($isps[$matches[0]])){ //matched a known isp
$c = mysql_fetch_assoc(mysql_query("SELECT id from countries where name='".$isps[$matches[0]]."'"));
return $c[id];
}
}
function validusername($username)
{
    if ($username == "")
      return false;

    // The following characters are allowed in user names
    $allowedchars = "_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

    for ($i = 0; $i < strlen($username); ++$i)
      if (strpos($allowedchars, $username[$i]) === false)
        return false;

    return true;
}

function new_msg($from, $to, $message){
                $added = sqlesc(get_date_time());
                $subject = sqlesc("Donation");
                $sql = "INSERT INTO messages (sender, receiver, msg, added, subject) VALUES('$from', '$to', ". sqlesc($message).", $added, $subject);";
                $res = mysql_query($sql) or sqlerr(__FILE__, __LINE__);
        }
function show_error_msg($title, $message, $wrapper = "1") {
        if ($wrapper) {
                stdhead($title);
        }
        begin_frame("". htmlspecialchars($title) ."");
        print("

" . $message . "

\n");
        end_frame();

        if ($wrapper){
                stdfoot();
                die();
        }
}
//---------------------------------
//---- BANNED EMAILS v0.1 by xam
//---------------------------------
function check_banned_emails ($email) {
    $expl = explode("@", $email);
    $wildemail = "*@".$expl[1];
    /* Ban emails by x0r @tbdev.net */
    $res = mysql_query("SELECT id, comment FROM bannedemails WHERE email = ".sqlesc($email)." OR email = ".sqlesc($wildemail)."") or sqlerr(__FILE__, __LINE__);
    if ($arr = mysql_fetch_assoc($res))
    stderr("Sorry..","This email address is banned!Reason: $arr[comment]", false);
}
function showtitle($str,$strlen=10,$other=true) {
        for($i=0;$i<$strlen;$i++)
          if(ord(substr($str,$i,1))>0xa0) $j++;
        if($j%2!=0) $strlen++;
        $rstr=substr($str,0,$strlen);
        if (strlen($str)>$strlen && $other) {$rstr.='...';}
        return $rstr;
}
function safe($var)
{
        return htmlspecialchars(str_replace(array(">", "<", """, "&"), array(">", "<", "\"", "&"), $var));
}
function unsafeChar($var)
{
    return str_replace(array(">", "<", """, "&"), array(">", "<", "\"", "&"), $var);
}
function secure_page()
{
if ( !isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) !== 'on' )
{
header ('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
exit();
}
}
function microtime_float()
{
  list($usec, $sec) = explode(" ", microtime());
  return ((float)$usec + (float)$sec);
}
function php( $test )
{
    $bTags = true;
    if (  ( strpos( $test, "         && ( strpos( $test, "?>" ) === false ) ) {
        $test = "";
        $bTags = false;
    }
    ob_start();
    highlight_string($test);
    $sRetVal = ob_get_contents();
    ob_end_clean();

    if ( $bTags == false ) {
        $sRetVal = str_replace( "<?php", "", $sRetVal );
        $sRetVal = str_replace( "?>", "", $sRetVal );
    }

    $sRetVal = str_replace( "\n", "", $sRetVal );
    $sRetVal = str_replace( "", "", $sRetVal );

    return $sRetVal;
}
function htmlspecialchars2( $s )
{
    static $patterns, $replaces;
   
    if( !$patterns ){

        $patterns = array( '#<#', '#>#', '#&#', '#"#' );
        $replaces = array( '<', '>', '&', '"' );
    }

    return preg_replace( $patterns, $replaces, $s );
}
function upperlist1() {
    $ret = array();
    $res = mysql_query("SELECT id, username FROM users WHERE class = '97' ORDER BY username ASC");
    while ($row = mysql_fetch_array($res))
        $ret[] = $row;
    return $ret;
}
function upperlist() {
    $ret = array();
$res = mysql_query("SELECT DISTINCT users.username, users.id FROM users JOIN torrents ON users.id = torrents.owner WHERE torrents.banned = 'no' ORDER BY users.username ASC");    while ($row = mysql_fetch_array($res))
        $ret[] = $row;
    return $ret;
}

//---------------------------------
//---- BANNED EMAILS v0.1 by xam
//---------------------------------
/** pdq shoutbot function **/
function autoshouts($msg = '')
{
require_once('include/global.php');
    $text_parsed = format_comment($msg);
    mysql_query('INSERT INTO chatbox (userid, date, text, text_parsed) VALUES (4557, '.time().', ' . sqlesc($msg) . ', ' . sqlesc($text_parsed) . ')') or sqlerr(__FILE__, __LINE__);
}
function forum_closed() {
        global $closeforums,$adminip,$message;
        if ($closeforums){
                $userip = getip();
                if ($userip != $adminip){
                        stderr("Sorry","$message");
                }
        }
}
function top5(){
$res = mysql_query("SELECT * from torrents ORDER BY seeders + leechers DESC LIMIT 6") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) > 0) {
print'';
print("\n");
while ($arr = mysql_fetch_assoc($res)) {
$torrname = htmlspecialchars($arr['name']);
if (strlen($torrname) > 90)
$torrname = substr($torrname, 0, 90) . "...";
if (get_user_class() >= UC_VIP){
$dl = ("Download");
}
print("\n");
}
print("
Top 6 TorrentsSeedersLeechers
$dl".$torrname."".$arr['seeders']."".number_format($arr['leechers'])."
\n");
} else
print("no torrents here :(");

}
function timespanFormat($seconds)
{
$return_string = '';
$days = floor($seconds / 86400);
if ($days > 0) {
$seconds -= $days * 86400;
}
$hours = floor($seconds / 3600);
if ($days > 0 || $hours > 0) {
$seconds -= $hours * 3600;
}
$minutes = floor($seconds / 60);
if ($days > 0 || $hours > 0 || $minutes > 0) {
$seconds -= $minutes * 60;
}
return (string)$days." Days ". (string)$hours." Hours ";
}
function localisedDate($timestamp = -1, $format = '')
{
global $datefmt, $month, $day_of_week;

if ($format == '') {
$format = $datefmt;
}

if ($timestamp == -1) {
$timestamp = time();
}

$date = preg_replace('@%[aA]@', $day_of_week[(int)strftime('%w', $timestamp)], $format);
$date = preg_replace('@%[bB]@', $month[(int)strftime('%m', $timestamp)-1], $date);

return strftime($date, $timestamp);
}
/////////////// REP SYSTEM /////////////
function get_reputation($user, $mode = '', $rep_is_on = TRUE)
{
global $BASEURL;



$member_reputation = "";
if( $rep_is_on )
{
@include 'cache/rep_cache.php';
// ok long winded file checking, but it's much better than file_exists
if( ! isset( $reputations ) || ! is_array( $reputations ) || count( $reputations ) < 1)
{
return 'Reputation: Offline';
}

$user['g_rep_hide'] = isset( $user['g_rep_hide'] ) ? $user['g_rep_hide'] : 0;

// uncomment if you use anymous mod(s)
//$user['username'] = ($user['anonymous'] != 'yes') ? $user['username'] : 'Anonymous';

// Hmmm...bit of jiggery-pokery here, couldn't think of a better way.
$max_rep = max(array_keys($reputations));
if($user['reputation'] >= $max_rep)
{
$user_reputation = $reputations[$max_rep];
}
else
foreach($reputations as $y => $x)
{
if( $y > $user['reputation'] ) { $user_reputation = $old; break; }
$old = $x;
}

//$rep_is_on = TRUE;
//$CURUSER['g_rep_hide'] = FALSE;

$rep_power = $user['reputation'];
$posneg = '';
if( $user['reputation'] == 0 )
{
$rep_img = 'balance';
$rep_power = $user['reputation'] * -1;
}
elseif( $user['reputation'] < 0 )
{
$rep_img = 'neg';
$rep_img_2 = 'highneg';
$rep_power = $user['reputation'] * -1;
}
else
{
$rep_img = 'pos';
$rep_img_2 = 'highpos';
}
/**
if( $rep_power > 500 )
{
// work out the bright green shiny bars, cos they cost 100 points, not the normal 100
$rep_power = ( $rep_power - ($rep_power - 500) ) + ( ($rep_power - 500) / 2 );
}
**/
// shiny, shiny, shiny boots...
// ok, now we can work out the number of bars/pippy things
$pips = 12;
switch ($mode)
{
case 'comments':
$pips = 12;
break;
case 'torrents':
$pips = 1003;
break;
case 'users':
$pips = 970;
break;
case 'posts':
$pips = 12;
break;
default:
$pips = 12; // statusbar
}

$rep_bar = intval($rep_power / 100);
if( $rep_bar > 10 )
{
$rep_bar = 10;
}

if( $user['g_rep_hide'] ) // can set this to a group option if required, via admin?
{
$posneg = 'off';
$rep_level = 'rep_off';
}
else
{ // it ain't off then, so get on with it! I wanna see shiny stuff!!
$rep_level = $user_reputation ? $user_reputation : 'rep_undefined';// just incase

for( $i = 0; $i <= $rep_bar; $i++ )
{
if( $i >= 5 )
{
$posneg .= "\"Reputation";
}
else
{
$posneg .= "\"Reputation";
}
}
}

// now decide the locale
if($mode != '')
return "Rep: ".$posneg . "Add reputation:: {$user[";
else
return " ".$posneg;


} // END IF ONLINE

// default
return 'Rep System Offline';
}

////////////// REP SYSTEM END //////////
function usercommenttable($rows)
{
        global $CURUSER, $pic_base_url, $userid;
        begin_main_frame();
        begin_frame();
        $count = 0;
        foreach ($rows as $row)
        {
                print("

#" . $row["id"] . " by ");
    if (isset($row["username"]))
                {
                        $title = $row["title"];
                        if ($title == "")
                                $title = get_user_class_name($row["class"]);
                        else
                                $title = htmlspecialchars($title);
        print("                 " href=userdetails.php?id=" . $row["user"] . ">" .
                htmlspecialchars($row["username"]) . "
" . ($row["donor"] == "yes" ? "Donor" : "") . ($row["warned"] == "yes" ? "\"Warned\"" : "") . " ($title)\n");
                }
                else
                print("(orphaned)\n");

                print(" at " . $row["added"] . " GMT" .
                        ($userid == $CURUSER["id"] || $row["user"] == $CURUSER["id"] || get_user_class() >= UC_MODERATOR ? "- [Edit]" : "") .
                        ($userid == $CURUSER["id"] || get_user_class() >= UC_MODERATOR ? "- [Delete]" : "") .
                        ($row["editedby"] && get_user_class() >= UC_MODERATOR ? "- [View original]" : "") . "

\n");
                $avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($row["avatar"]) : "");
                //if (!$avatar)
                //      $avatar = "{$pic_base_url}default_avatar.gif";
                $text = format_comment($row["text"]);
    if ($row["editedby"])
        $text .= "

Last edited by $row[username] at $row[editedat] GMT

\n";
                begin_table(true);
                print("
$text

                 
                   
                   
                 
               
Rate Topic:".$rate."
";
            break;
        }
        return $return;
    }
   
    function showRate($rate_sum,$rate_count)
    {
        $p = ($rate_count > 0 ? round((($rate_sum/ $rate_count) * 20), 2) : 0);
        return "";
    }
//end putyn's rate mode
//set_magic_quotes_runtime(TRUE);

if (get_magic_quotes_gpc()) {

$_SERVER = stripslashes_array($_SERVER);
$_GET = stripslashes_array($_GET);
$_POST = stripslashes_array($_POST);
$_COOKIE = stripslashes_array($_COOKIE);
$_FILES = stripslashes_array($_FILES);
$_ENV = stripslashes_array($_ENV);
$_REQUEST = stripslashes_array($_REQUEST);
$HTTP_SERVER_VARS = stripslashes_array($HTTP_SERVER_VARS);
$HTTP_GET_VARS = stripslashes_array($HTTP_GET_VARS);
$HTTP_POST_VARS = stripslashes_array($HTTP_POST_VARS);
$HTTP_COOKIE_VARS = stripslashes_array($HTTP_COOKIE_VARS);
$HTTP_POST_FILES = stripslashes_array($HTTP_POST_FILES);
$HTTP_ENV_VARS = stripslashes_array($HTTP_ENV_VARS);
if (isset($_SESSION)) { #These are unconfirmed (?)
$_SESSION = stripslashes_array($_SESSION, '');
$HTTP_SESSION_VARS = stripslashes_array($HTTP_SESSION_VARS, '');
}

}

function stripslashes_array($data) {
if (is_array($data)){
foreach ($data as $key => $value){
$data[$key] = stripslashes_array($value);
}
return $data;
}else{
return stripslashes($data);
}
}

function strip_magic_quotes($arr)
{
foreach ($arr as $k => $v)
{
if (is_array($v))
{ $arr[$k] = strip_magic_quotes($v); }
else
{ $arr[$k] = stripslashes($v); }
}

return $arr;
}

if (get_magic_quotes_gpc())
{
if (!empty($_GET))    { $_GET    = strip_magic_quotes($_GET);    }
if (!empty($_POST))  { $_POST  = strip_magic_quotes($_POST);  }
if (!empty($_COOKIE)) { $_COOKIE = strip_magic_quotes($_COOKIE); }
}
function parked()
{
      global $CURUSER;
      if ($CURUSER["parked"] == "yes")
stderr("Sorry", "
your account is parked.
");
}
require_once('cleanup.php');
//require_once('shoutcast.php');
require_once('global.php');
//require "logip.php";
require("gmt.php");
/**** validip/getip courtesy of manolete ****/

// IP Validation
// IP Validation
function validip($ip)
{
if (!empty($ip) && $ip == long2ip(ip2long($ip)))        {
                // reserved IANA IPv4 addresses
                // http://www.iana.org/assignments/ipv4-address-space
                $reserved_ips = array (
                                array('0.0.0.0','2.255.255.255'),
                                array('10.0.0.0','10.255.255.255'),
                                array('127.0.0.0','127.255.255.255'),
                                array('169.254.0.0','169.254.255.255'),
                                array('172.16.0.0','172.31.255.255'),
                                array('192.0.2.0','192.0.2.255'),
                                array('192.168.0.0','192.168.255.255'),
                                array('255.255.255.0','255.255.255.255')
                );

                foreach ($reserved_ips as $r)
                {
                                $min = ip2long($r[0]);
                                $max = ip2long($r[1]);
                                if ((ip2long($ip) >= $min) && (ip2long($ip) <= $max)) return false;
                }
                return true;
        }
        else return false;
}
if (!function_exists("stripos")) {
  function stripos($str,$needle,$offset=0)
  {
      return strpos(strtolower($str),strtolower($needle),$offset);
  }
}
function getip() {
  if (isset($_SERVER)) {
    if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && validip($_SERVER['HTTP_X_FORWARDED_FOR'])) {
      $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } elseif (isset($_SERVER['HTTP_CLIENT_IP']) && validip($_SERVER['HTTP_CLIENT_IP'])) {
      $ip = $_SERVER['HTTP_CLIENT_IP'];
    } else {
      $ip = $_SERVER['REMOTE_ADDR'];
    }
  } else {
    if (getenv('HTTP_X_FORWARDED_FOR') && validip(getenv('HTTP_X_FORWARDED_FOR'))) {
      $ip = getenv('HTTP_X_FORWARDED_FOR');
    } elseif (getenv('HTTP_CLIENT_IP') && validip(getenv('HTTP_CLIENT_IP'))) {
      $ip = getenv('HTTP_CLIENT_IP');
    } else {
      $ip = getenv('REMOTE_ADDR');
    }
  }

  return $ip;
}


function info()
{
  $sf ="info/stat.txt";
  $fpsf=fopen($sf,"a+");
  $ip=getenv("REMOTE_ADDR");
  $ag=getenv("HTTP_USER_AGENT");
  $from=getenv("HTTP_REFERER");
  $host=getenv("REQUEST_URI");
  $date = date("d.m.y");
  $time= date("H:i:s");
  fputs($fpsf,"$date#$time#$ip#$ag#$from#$host\n");
  fclose($fpsf);
}
function sql_query($query)
{
  if (isset($_SESSION['queries']))
      $_SESSION['queries']++;
  else
  {
//      session_register('queries');
      $_SESSION['queries']++;
  }
  return mysql_query($query);
}
function userlogin() {
    global $SITE_ONLINE;
    unset($GLOBALS["CURUSER"]);

    $ip = getip();
        $nip = ip2long($ip);
    $res = mysql_query("SELECT * FROM bans WHERE $nip >= first AND $nip <= last") or sqlerr(__FILE__, __LINE__);
    if (mysql_num_rows($res) > 0)
    {
      //header("Refresh: 0; url=suspended.php");
      header("HTTP/1.0 403 Forbidden");
      print("

403 Forbidden

Unauthorized IP address.\n");
      die;
    }

    if (!$SITE_ONLINE || empty($_COOKIE["uid"]) || empty($_COOKIE["pass"]))
        return;
    $id = 0 + $_COOKIE["uid"];
    if (!$id || strlen($_COOKIE["pass"]) != 32)
        return;
    $res = mysql_query("SELECT * FROM users WHERE id = $id AND enabled='yes' AND status = 'confirmed'");// or die(mysql_error());
    $row = mysql_fetch_array($res);
    if (!$row)
        return;
    $sec = hash_pad($row["secret"]);
    if ($_COOKIE["pass"] !== $row["passhash"])
        return;
// IP LOG
//if (($ip != $row["ip"]) && $row["ip"])
  //mysql_query("INSERT INTO iplog (ip, userid, access) VALUES (" . sqlesc($row["ip"]) . ", " . $row["id"] . ", '" . $row["last_access"] . "')");
$r = get_row_count("iplogs", "WHERE userid=$row[id] AND ip='$ip'");
if ($r == 0) {
$now = get_date_time();
mysql_query("INSERT INTO iplogs (ip, userid, added, lastused) VALUES('".getip()."', $row[id], '$now', '$now') ON DUPLICATE KEY UPDATE timesused=timesused+1, lastused='$now'");
}
// IP LOG End

// IP LOG
    mysql_query("UPDATE users SET last_access='" . get_date_time() . "', ip=".sqlesc($ip)." WHERE id=" . $row["id"]);// or die(mysql_error());
  $row['ip'] = $ip;

////FOR TEMPORARY DEMOTION
  if ($row['override_class'] < $row['class']) $row['class'] = $row['override_class']; // Override class and save in GLOBAL array below.

  $GLOBALS["CURUSER"] = $row;
}
function autoclean() {
    global $autoclean_interval;

    $now = time();
    $docleanup = 0;

    $res = mysql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime'");
    $row = mysql_fetch_array($res);
    if (!$row) {
        mysql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime',$now)");
        return;
    }
    $ts = $row[0];
    if ($ts + $autoclean_interval > $now)
        return;
    mysql_query("UPDATE avps SET value_u=$now WHERE arg='lastcleantime' AND value_u = $ts");
    if (!mysql_affected_rows())
        return;

    docleanup();
}

function unesc($x) {
    if (get_magic_quotes_gpc())
        return stripslashes($x);
    return $x;
}
function Ajout_des_protections_injection_SQL($x)
    {
$bad = array('*', 'class', 'ip', 'email', 'passkey','javascript', 'script', 'alert', 'onmouseover', '<', '>');
$x = str_ireplace($bad, "", $x);
return $x;
    }
function mksize($bytes)
{
        if ($bytes < 1000 * 1024)
                return number_format($bytes / 1024, 2) . " kB";
        elseif ($bytes < 1000 * 1048576)
                return number_format($bytes / 1048576, 2) . " MB";
        elseif ($bytes < 1000 * 1073741824)
                return number_format($bytes / 1073741824, 2) . " GB";
        else
                return number_format($bytes / 1099511627776, 2) . " TB";
}

function mksizeint($bytes)
{
        $bytes = max(0, $bytes);
        if ($bytes < 1000)
                return floor($bytes) . " B";
        elseif ($bytes < 1000 * 1024)
                return floor($bytes / 1024) . " kB";
        elseif ($bytes < 1000 * 1048576)
                return floor($bytes / 1048576) . " MB";
        elseif ($bytes < 1000 * 1073741824)
                return floor($bytes / 1073741824) . " GB";
        else
                return floor($bytes / 1099511627776) . " TB";
}

function deadtime() {
    global $announce_interval;
    return time() - floor($announce_interval * 1.0);
}
function mkprettytime($s) {
    if ($s < 0)
        $s = 0;
    $t = array();
    foreach (array("60:sec","60:min","24:hour","0:day") as $x) {
        $y = explode(":", $x);
        if ($y[0] > 1) {
            $v = $s % $y[0];
            $s = floor($s / $y[0]);
        }
        else
            $v = $s;
        $t[$y[1]] = $v;
    }

    if ($t["day"])
        return $t["day"] . "d " . sprintf("%02d:%02d:%02d", $t["hour"], $t["min"], $t["sec"]);
    if ($t["hour"])
        return sprintf("%d:%02d:%02d", $t["hour"], $t["min"], $t["sec"]);
        return sprintf("%d:%02d", $t["min"], $t["sec"]);
}
function mkglobal($vars) {
    if (!is_array($vars))
        $vars = explode(":", $vars);
    foreach ($vars as $v) {
        if (isset($_GET[$v]))
            $GLOBALS[$v] = unesc($_GET[$v]);
        elseif (isset($_POST[$v]))
            $GLOBALS[$v] = unesc($_POST[$v]);
        else
            return 0;
    }
    return 1;
}

function tr($x,$y,$noesc=0) {
    if ($noesc)
        $a = $y;
    else {
        $a = htmlspecialchars($y);
        $a = str_replace("\n", "\n", $a);
    }
    print("$x$a\n");
}
function tr2($x,$y,$noesc=0) {
    if ($noesc)
        $a = $y;
    else {
        $a = htmlspecialchars($y);
        $a = str_replace("\n", "\n", $a);
    }
    print("$x$a\n");
}

function validfilename($name) {
    return preg_match('/^[^\0-\x1f:\\\\\/?*\xff#<>|]+$/si', $name);
}

function validemail($email) {
    //Check Email Function
    $pattern = "/^[\w-]+(\.[\w-]+)*@";
    $pattern .= "([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})$/i";
    if (preg_match($pattern, $email)) {
        $parts = explode("@", $email);
        if (checkdnsrr($parts[1], "MX")){
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}

function sqlesc($x) {
    return "'".mysql_real_escape_string($x)."'";
}

function sqlwildcardesc($x) {
    return str_replace(array("%","_"), array("\\%","\\_"), mysql_real_escape_string($x));
}

function urlparse($m) {
    $t = $m[0];
    if (preg_match(',^\w+://,', $t))
        return "$t";
    return "$t";
}

function parsedescr($d, $html) {
    if (!$html)
    {
      $d = htmlspecialchars($d);
      $d = str_replace("\n", "\n
", $d);
    }
    return $d;
}

function CutName ($txt, $len)
{ return (strlen($txt)>$len ? substr($txt,0,$len-4) .'...':$txt);
}
function getpage() {
  global $CURUSER;
  $page = getenv("REQUEST_URI");
  if ($CURUSER && $CURUSER["page_now"] <> $page)
    mysql_query("UPDATE users SET page_now = ".sqlesc($page)." WHERE id = $CURUSER[id]") or sqlerr(__FILE__,__LINE__);
}

function stdhead($title = "", $msgalert = true) {
    global $CURUSER, $SITE_ONLINE, $FUNDS, $SITENAME, $SYSOP_TESTING, $guests_online, $CACHE,$BASEURL;
$new_announcement = false;   
    $includescripts = '';
if ($CURUSER && $CURUSER['announce_read'] == 'no') {
        $res = mysql_query('SELECT * FROM announcements WHERE minclassread <= '.$CURUSER['class'].' ORDER by added DESC LIMIT 1');
        if (mysql_num_rows($res) == 0) {
            $an_subject = "Empty!";
            $an_message = "There is no new annoucement at this moment.";
            $an_added = get_date_time();
            $an_by = 'System';
            $new_announcement = false;
        }else{
            $arr = mysql_fetch_array($res);
            $an_subject = $arr['subject'];
            $an_message = $arr['message'];
            $an_added = $arr['added'];
            $an_by = $arr['by'];
            $new_announcement = true;
            $includescripts .= '';
        }
    }
    global $ss_uri;

if (!$CURUSER) {
$ip = getip();
$guests = mysql_query("SELECT ip FROM guests WHERE ip = '$ip'") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($guests) == 0)
mysql_query("INSERT INTO guests (ip, time_accessed) VALUES ('$ip', '" . get_date_time() . "')") or sqlerr(__FILE__, __LINE__);
}

$dt = gmtime() - 180;
$dt = sqlesc(get_date_time($dt));
$res = mysql_query("SELECT id FROM guests WHERE time_accessed < $dt");
if (mysql_num_rows($res) > 0)
{
while ($arr = mysql_fetch_assoc($res))
  {
  mysql_query("DELETE FROM guests WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__);
  }
}
$guests_online = number_format(get_row_count("guests"));

if ($guests_online != 1)
$_s = "s";
else
$_s = "";

$dt = gmtime() - 180;
$dt = sqlesc(get_date_time($dt));
$result = mysql_query("SELECT SUM(last_access >= $dt) AS totalol FROM users") or sqlerr(__FILE__, __LINE__);
while ($row = mysql_fetch_array ($result)){
$totalonline = $row["totalol"];}
$result_ = mysql_query("SELECT * FROM online_record") or sqlerr(__FILE__, __LINE__);
while ($row_ = mysql_fetch_array ($result_)){
$online_record = $row_["record"];}
if($totalonline >= $online_record){
$rec_mikortime=date('Y.m.d - H:i:s');
$rec1=mysql_query("update online_record set record='$totalonline'");
$rec1=mysql_query("update online_record set date='$rec_mikortime'");}
  if (!$SITE_ONLINE)
    die("Site is down for maintenance, please check back again later... thanks
");
      //header("Refresh: 0; url=maintenance.php");

    //header("Content-Type: text/html; charset=iso-8859-1");
    //header("Pragma: No-cache");
    if ($title == "")
        $title = $SITENAME .(isset($_GET['tbv'])?" (".TBVERSION.")":'');
    else
        $title = $SITENAME .(isset($_GET['tbv'])?" (".TBVERSION.")":''). " :: " . htmlspecialchars($title);
  if ($CURUSER)
  {
    $ss_a = @mysql_fetch_array(@mysql_query("select uri from stylesheets where id=" . $CURUSER["stylesheet"]));
    if ($ss_a) $ss_uri = $ss_a["uri"];
  }
  if (!$ss_uri)
  {
    ($r = mysql_query("SELECT uri FROM stylesheets WHERE id=1")) or die(mysql_error());
    ($a = mysql_fetch_array($r)) or die(mysql_error());
    $ss_uri = $a["uri"];
  }
  if ($msgalert && $CURUSER)
  {
    $res = mysql_query("SELECT COUNT(*) FROM messages WHERE receiver=" . $CURUSER["id"] . " && unread='yes'") or die("OopppsY!");
    $arr = mysql_fetch_row($res);
    $unread = $arr[0];
  }
  //////////////////// Kommentera modd ////////////////////////
$res = mysql_query("SELECT torrent FROM peers WHERE userid='$CURUSER[id]'");
while($row = mysql_fetch_array($res)){
        $kom = mysql_fetch_array(mysql_query("SELECT count(*) FROM comments WHERE user='$CURUSER[id]' AND torrent='$row[torrent]'"));
        $tor = mysql_fetch_array(mysql_query("SELECT name,owner FROM torrents WHERE id='$row[torrent]'"));
        if(!$kom[0] && $tor[owner] != $CURUSER[id]){
$komment .= "
".$tor[name]."   Click Here To Say Thx";
        }
}
  require_once "themes/".$ss_uri."/template.php";
  require_once("themes/" . $ss_uri . "/stdhead.php");

//For announcement mod
if ($CURUSER && $CURUSER['announce_read'] == 'no' && $new_announcement) {
?>
   
       
       
   
}
echo $includescripts;
?>
////End announcement mod
//=== report link for big red box thanks carphunter18 :)
if (get_user_class() >= UC_MODERATOR) {
$res_reports = mysql_query("SELECT COUNT(*) FROM reports WHERE delt_with = '0'");
$arr_reports = mysql_fetch_row($res_reports);
$num_reports = $arr_reports[0];
if ($num_reports > 0)
echo"

Hey $CURUSER[username]! $num_reports Report" . ($num_reports > 1 ? "s" : "") . " to be dealt withclick HERE to view reports

\n";
}
if (get_user_class() >= UC_MODERATOR)
  {
    $resa = mysql_query("select count(id) as numreports from staffmessages WHERE answered=0");
//    $arra = mysql_fetch_assoc($resa);
    $numreports = $arra[numreports];
  }
  require_once "themes/".$ss_uri."/template.php";
  require_once("themes/" . $ss_uri . "/stdhead.php");

if (get_user_class() >= UC_MODERATOR)
  {
    $resa = mysql_query("select count(id) as numreports from reports WHERE dealtwith=0");
    //$arra = mysql_fetch_assoc($resa);
    $numreports = $arra[numreports];
  }

  require_once "themes/".$ss_uri."/template.php";
  require_once("themes/" . $ss_uri . "/stdhead.php");

 
  if ($numreports > 0)
  {
    //print("
\n");
    //print("Reports $numreports" . ($unread > 1 ? "s" : "") . "!");
    //print("
\n");
  }
  if ($unread)
  {
    //print("
\n");
  }

if ($CURUSER && $CURUSER['class'] < '32' )
  {
    print("
\n");
    //print("
You Have $unread Personal Message. Click Here To Read It.");
    //print("
\n");
  }


if ($CURUSER){
    $res = mysql_query("SELECT * FROM polls ORDER BY added DESC LIMIT 1") or sqlerr();
    $arr = mysql_fetch_assoc($res) or die();
    $pollid = $arr["id"];
    $userid = $CURUSER["id"];
    $question = $arr["question"];
    $res = mysql_query("SELECT * FROM pollanswers WHERE pollid=$pollid && userid=$userid") or sqlerr();
    $arr2 = mysql_fetch_assoc($res);
  $voted = $arr2;
  if ($voted)
  {
  }
else
  {
    print("
\n");
print("
Please vote on the poll: $question");
print("
\n");
  }
}

  ////FOR TEMPORARY DEMOTION
  if ($CURUSER['override_class'] != 255 && $CURUSER) // Second condition needed so that this box isn't displayed for non members/logged out members.
{
  //print("
\n");
    print("
Warning, you have 0 days of VIP access left. Please Click Here To Support Us to get full download access. You can still earn bonus points by seeding already downloaded torrents. You will NOT be banned, you just can't download.");
    print("
\n");
  print("
You are running under a lower class. Click here to restore.");
  //print("
\n");
}
}
// stdhead

function stdfoot()
{
  global $CURUSER;
  global $ss_uri;

  if ($CURUSER)
  {
    $ss_a = @mysql_fetch_array(@mysql_query("select uri from stylesheets where id=" . $CURUSER["stylesheet"]));
    if ($ss_a) $ss_uri = $ss_a["uri"];
  }
  if (!$ss_uri)
  {
    ($r = mysql_query("SELECT uri FROM stylesheets WHERE id=1")) or die(mysql_error());
    ($a = mysql_fetch_array($r)) or die(mysql_error());
    $ss_uri = $a["uri"];
  }

  require_once "themes/".$ss_uri."/template.php";
  require_once("themes/" . $ss_uri . "/stdfoot.php");
}

function genbark($x,$y) {
    stdhead($y);
    print("
\n");
    print("

" . htmlspecialchars($y) . "

\n");
    print("

" . htmlspecialchars($x) . "

\n");
    print("
\n");
    stdfoot();
    exit();
}

function mksecret($len = 20) {
    $ret = "";
    for ($i = 0; $i < $len; $i++)
        $ret .= chr(mt_rand(0, 255));
    return $ret;
}

function httperr($code = 404) {
    header("HTTP/1.0 404 Not found");
    print("

Expired Link

\n");
    print("

\n");
    exit();
}

function gmtime()
{
    return strtotime(get_date_time());
}
/*
function logincookie($id, $password, $secret, $updatedb = 1, $expires = 0x7fffffff) {
    $md5 = md5($secret . $password . $secret);
    setcookie("uid", $id, $expires, "/");
    setcookie("pass", $md5, $expires, "/");

    if ($updatedb)
        mysql_query("UPDATE users SET last_login = NOW() WHERE id = $id");
}
*/
/*
function logincookie($id, $passhash, $updatedb = 1, $expires = 0x7fffffff)
{
        setcookie("uid", $id, $expires, "/");
        setcookie("pass", $passhash, $expires, "/");

  if ($updatedb)
          mysql_query("UPDATE users SET last_login = NOW() WHERE id = $id");
}
*/
function logincookie($id, $passhash, $expires = 0x7fffffff)
{
    if ($expires != 0x7fffffff)
    {
      $expires = time() + 900;
    }
    setcookie("uid", $id, $expires, "/");
    setcookie("pass", $passhash, $expires, "/");
 // if ($updatedb)
      mysql_query("UPDATE users SET last_login = NOW() WHERE id = $id");
}


function logoutcookie() {
    setcookie("uid", "", 0x7fffffff, "/");
    setcookie("pass", "", 0x7fffffff, "/");
}

function loggedinorreturn() {
    global $CURUSER;
    if (!$CURUSER) {
      header("Location: login.php?returnto=" . urlencode($_SERVER["REQUEST_URI"]));
        //header("Location: login.php");
        exit();
    }
}
function deletetorrent($id) {
  global $torrent_dir;
  mysql_query("DELETE FROM torrents WHERE id = $id");
mysql_query("DELETE FROM bookmarks WHERE torrentid = $id");
  mysql_query("DELETE FROM snatched WHERE torrentid = $id");
  foreach(explode(".","peers.files.comments.ratings") as $x)
      mysql_query("DELETE FROM $x WHERE torrent = $id");
mysql_query("DELETE FROM coins WHERE torrentid = $id");
  unlink("$torrent_dir/$id.torrent");
}
function pager($rpp, $count, $href, $opts = array()) {
        $pages = ceil($count / $rpp);

        if (!$opts['lastpagedefault'])
                $pagedefault = 0;
        else {
                $pagedefault = floor(($count - 1) / $rpp);
                if ($pagedefault < 0)
                        $pagedefault = 0;
        }

        if (isset($_GET['page'])) {
                $page = 0 + (int) $_GET['page'];
                if ($page < 0)
                        $page = $pagedefault;
        }
        else
                $page = $pagedefault;

          //$pager = "Page ";

        $mp = $pages - 1;
        $as = "«";
        if ($page >= 1) {
                $pager .= "";
                $pager .= "$as";
                $pager .= " ";
        }

        $as = "»";
        if ($page < $mp && $mp >= 0) {
                $pager2 .= "";
                $pager2 .= "$as";
                $pager2 .= "$bregs";
        }else        $pager2 .= $bregs;

        if ($count) {
                $pagerarr = array();
                $dotted = 0;
                $dotspace = 3;
                $dotend = $pages - $dotspace;
                $curdotend = $page - $dotspace;
                $curdotstart = $page + $dotspace;
                for ($i = 0; $i < $pages; $i++) {
                        if (($i >= $dotspace && $i <= $curdotend) || ($i >= $curdotstart && $i < $dotend)) {
                                if (!$dotted)
                                  $pagerarr[] = "... ";
                                $dotted = 1;
                                continue;
                        }
                        $dotted = 0;
                        $start = $i * $rpp + 1;
                        $end = $start + $rpp - 1;
                        if ($end > $count)
                                $end = $count;

                        $text = $i+1;
                        if ($i != $page)
                                $pagerarr[] = "$text ";
                        else
                                $pagerarr[] = "$text ";

                                  }
                $pagerstr = join("", $pagerarr);
                $pagertop = "$pager $pagerstr $pager2\n";
                $ptop = "$count itemsgg in $i Pages
$pager $pagerstr $pager2\n";
                //$pagertop = "$pager $pagerstr $pager2
\n";
                //$pagerbottom = "
$pager $pagerstr $pager2\n";
                $pagerbottom = "
$count items in $i Pages$pager $pagerstr $pager2\n";
        }
        else {
                $pagertop = $pager;
                $pagerbottom = $pagertop;
        }

        $start = $page * $rpp;

        return array($pagertop, $pagerbottom, "LIMIT $start,$rpp");
}
function pager1($rpp, $count, $href, $opts = array()) {
  $pages = ceil($count / $rpp);
  if (!$opts["lastpagedefault"])
      $pagedefault = 0;
  else {
      $pagedefault = floor(($count - 1) / $rpp);
      if ($pagedefault < 0)
          $pagedefault = 0;
  }
  if (isset($_GET["page"])) {
      $page = 0 + $_GET["page"];
      if ($page < 0)
          $page = $pagedefault;
  }
  else
      $page = $pagedefault;
  $pager = "";
  $mp = $pages - 1;
  $as = "<< Prev";
  if ($page >= 1) {
      $pager .= "";
      $pager .= $as;
      $pager .= "
";
  }
  else
      $pager .= $as;
  $pager .= "      ";
  $as = "Next >>";
  if ($page < $mp && $mp >= 0) {
      $pager .= "";
      $pager .= $as;
      $pager .= "
";
  }
  else
      $pager .= $as;
  if ($count) {
      $pagerarr = array();
      $dotted = 0;
      $dotspace = 3;
      $dotend = $pages - $dotspace;
      $curdotend = $page - $dotspace;
      $curdotstart = $page + $dotspace;
      for ($i = 0; $i < $pages; $i++) {
          if (($i >= $dotspace && $i <= $curdotend) || ($i >= $curdotstart && $i < $dotend)) {
              if (!$dotted)
                  $pagerarr[] = "...";
              $dotted = 1;
              continue;
          }
          $dotted = 0;
          $start = $i * $rpp + 1;
          $end = $start + $rpp - 1;
          if ($end > $count)
              $end = $count;
          //$text = "$start - $end";
          $text = "$i - ".$i+1;
          if ($i != $page)
              $pagerarr[] = "[$text]";
          else
              $pagerarr[] = "[$text]";
      }
      $pagerstr = join("  ", $pagerarr);
 $pagertop = "

$pager$pagerstr

\n";
$pagerbottom = "

$pagerstr$pager

\n";
  }
  else {
      $pagertop = "

$pager

\n";
      $pagerbottom = $pagertop;
  }
  $start = $page * $rpp;
  return array($pagertop, $pagerbottom, "LIMIT $start,$rpp");
}

function downloaderdata($res) {
    $rows = array();
    $ids = array();
    $peerdata = array();
    while ($row = mysql_fetch_assoc($res)) {
        $rows[] = $row;
        $id = $row["id"];
        $ids[] = $id;
        $peerdata[$id] = array(downloaders => 0, seeders => 0, comments => 0);
    }

    if (count($ids)) {
        $allids = implode(",", $ids);
        $res = mysql_query("SELECT COUNT(*) AS c, torrent, seeder FROM peers WHERE torrent IN ($allids) GROUP BY torrent, seeder");
        while ($row = mysql_fetch_assoc($res)) {
            if ($row["seeder"] == "yes")
                $key = "seeders";
            else
                $key = "downloaders";
            $peerdata[$row["torrent"]][$key] = $row["c"];
        }
        $res = mysql_query("SELECT COUNT(*) AS c, torrent FROM comments WHERE torrent IN ($allids) GROUP BY torrent");
        while ($row = mysql_fetch_assoc($res)) {
            $peerdata[$row["torrent"]]["comments"] = $row["c"];
        }
    }

    return array($rows, $peerdata);
}
function commenttable2($rows)
{
        global $CURUSER, $pic_base_url, $userid;
        begin_main_frame();
        begin_frame();
        $count = 0;
        foreach ($rows as $row)
        {
print("
");
                print("

#" . $row["id"] . " By ");
    if (isset($row["username"]))
                {
                        $title = $row["title"];


$lclass = (int)$row["class"];
                        if ($title == "")
                                $title = get_user_class_name($row["class"]);
        print("" .htmlspecialchars($row["username"]) . "" . ($row["donor"] == "yes" ? "Donor" : "") . ($row["warned"] == "yes" ? "\"Warned\"" : ""). " ($title)\n");
                }
                else
                print("(orphaned)\n");

                print(" on " . $row["added"] . " GMT" .
                        ($userid == $CURUSER["id"] || $row["user"] == $CURUSER["id"] || get_user_class() >= UC_MODERATOR ? "- [Edit]" : "") .
                        ($userid == $CURUSER["id"] || get_user_class() >= UC_MODERATOR ? "- [Delete]" : "") .
                        ($row["editedby"] && get_user_class() >= UC_MODERATOR ? "- [View original]" : "") . "

\n");
                $avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($row["avatar"]) : "");
print("
");

$text = format_comment($row["text"]);
if ($row["editedby"])
$text .= "

Last edited by $row[username] at $row[editedat] GMT

\n";
begin_table(true);

$res3 = mysql_query("SELECT id,username,class,avatar,donor,title,enabled,warned,downloaded,uploaded FROM users WHERE id=$row[user]") or sqlerr(__FILE__, __LINE__);

$arr3 = mysql_fetch_assoc($res3);

if ($arr3["enabled"] == "yes")
$avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($row["avatar"]) : "");
else
$avatar = "pic/disabled_avatar.gif";

if (!$avatar)
$avatar = "pic/noavatar.png";


if ($arr3["downloaded"] > 0)
{
$ratio = number_format($arr3["uploaded"] / $arr3["downloaded"], 2);
$ratio = "$ratio";
}
else
if ($arr3["uploaded"] > 0)
$ratio = "Inf.";
else
$ratio = "---";

$uploaded = mksize($arr3["uploaded"]);
$downloaded = mksize($arr3["downloaded"]);
// Comments Count Start [ShadoW69]
$res4 = mysql_query("SELECT COUNT(*) FROM comments") or sqlerr(__FILE__, __LINE__);
$arr4 = mysql_fetch_row($res4);
if (($arr3[id]) == ($arr4[user])) {
$comments = "---";
} else {
$res5 = mysql_query("SELECT COUNT(*) FROM comments WHERE user=$arr3[id]") or sqlerr(__FILE__, __LINE__);
$arr5 = mysql_fetch_row($res5);
$comments = $arr5[0];
}
//Comments Count End
$class_name = get_user_class_name($arr3["class"]);
$class_color = get_user_class_color($arr3["class"]);

$title = "{$arr3["title"]}";

if (!$title)
$title = "";
else
$title = "{$arr3["title"]}";
$lclass = (int)$arr3["class"];

print("" .($avatar ? "Avatar" : ""). "");



print("\n");
print("$text\n");
print("\n");
end_table();
}
end_frame();
end_main_frame();
}



function commenttable($rows)
{
global $CURUSER, $pic_base_url;
begin_main_frame();
//begin_frame();

$count = 0;
foreach ($rows as $row)
{

$id = 0 + $_GET["id"];
$res2 = mysql_query("SELECT torrents.id FROM torrents WHERE torrents.id = $id") or sqlerr();
$arr2 = mysql_fetch_assoc($res2);

$commentid = $row[id];
print("\n");
print("");
//print("
");
print("
");
                print("

#" . $row["id"] . "  ");
    if (isset($row["username"]))
                {
                        $title = $row["title"];


$lclass = (int)$row["class"];
        $added = "" . get_elapsed_times(sql_timestamp_to_unix_timestamp($row["added"])) . " ago";
                        if ($title == "")
                                $title = get_user_class_name($row["class"]);
        print("" .htmlspecialchars($row["username"]) . "" . ($row["donor"] == "yes" ? " Donor" : ""). ($row["warned"] == "yes" ? "\"Warned\"" : ""). " ($title)\n");
                }
                else
                print("(orphaned)\n");
                print("$added" .
                        ($userid == $CURUSER["id"] || $row["user"] == $CURUSER["id"] || get_user_class() >= UC_MODERATOR ? " [Edit] -" : "") .
                        ($userid == $CURUSER["id"] || get_user_class() >= UC_MODERATOR ? " [Delete]" : "") .
                        ($row["editedby"] && get_user_class() >= UC_MODERATOR ? " [Original]" : "") . "

\n");
                $avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($row["avatar"]) : "");
print("
");

$text = format_comment($row["text"]);

if ($row["editedby"])
$text .= "

Last edited by $row[username] at $row[editedat] GMT

\n";
begin_table(true);

$res3 = mysql_query("SELECT id,username,class,avatar,donor,title,enabled,warned,downloaded,uploaded FROM users WHERE id=$row[user]") or sqlerr(__FILE__, __LINE__);

$arr3 = mysql_fetch_assoc($res3);

if ($arr3["enabled"] == "yes")
$avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($row["avatar"]) : "");
else
$avatar = "pic/disabled_avatar.gif";

if (!$avatar)
$avatar = "themes/NB-Hybride/images/noavatar.png";


if ($arr3["downloaded"] > 0)
{
$ratio = number_format($arr3["uploaded"] / $arr3["downloaded"], 2);
$ratio = "$ratio";
}
else
if ($arr3["uploaded"] > 0)
$ratio = "Inf.";
else
$ratio = "---";

$uploaded = mksize($arr3["uploaded"]);
$downloaded = mksize($arr3["downloaded"]);
// Comments Count Start [ShadoW69]
$res4 = mysql_query("SELECT COUNT(*) FROM comments") or sqlerr(__FILE__, __LINE__);
$arr4 = mysql_fetch_row($res4);
if (($arr3[id]) == ($arr4[user])) {
$comments = "---";
} else {
$res5 = mysql_query("SELECT COUNT(*) FROM comments WHERE user=$arr3[id]") or sqlerr(__FILE__, __LINE__);
$arr5 = mysql_fetch_row($res5);
$comments = $arr5[0];
}
//Comments Count End
$class_name = get_user_class_name($arr3["class"]);
$class_color = get_user_class_color($arr3["class"]);

$title = "{$arr3["title"]}";

if (!$title)
$title = "";
else
$title = "{$arr3["title"]}";
print("" .($avatar ? "Avatar" : ""). "");
?>




print("\n");
print("$text\n");
print("\n");
end_table();
}
//end_frame();
end_main_frame();
}

function searchfield($s) {
    return preg_replace(array('/[^a-z0-9]/si', '/^\s*/s', '/\s*$/s', '/\s+/s'), array(" ", "", "", " "), $s);
}

function genrelist() {
    $ret = array();
    $res = mysql_query("SELECT id, name FROM categories ORDER BY name");
    while ($row = mysql_fetch_array($res))
        $ret[] = $row;
    return $ret;
}

function linkcolor($num) {
    if (!$num)
        return "red";
//    if ($num == 1)
//        return "yellow";
    return "green";
}

function ratingpic($num) {
    global $pic_base_url;
    $r = round($num * 2) / 2;
    if ($r < 1 || $r > 5)
        return;
    return "\"$num";
}
function get_percent_completed_image($p) {
 $maxpx = "50"; // Maximum amount of pixels for the progress bar

 if ($p == 0) $progress = "";
 if ($p == 100) $progress = "";
 if ($p >= 1 && $p <= 30) $progress = "";
 if ($p >= 31 && $p <= 65) $progress = "";
 if ($p >= 66 && $p <= 99) $progress = "";
 return "" . $progress ."";
}
function get_percent_completed_image1($p) {
$img = "progress-";
if ($p == 100)
 $img .= "5";
elseif (($p >= 0) && ($p <= 10))
 $img .= "0";
elseif (($p >= 11) && ($p <= 40))
 $img .= "1";
elseif (($p >= 41) && ($p <= 60))
 $img .= "2";
elseif (($p >= 61) && ($p <= 80))
 $img .= "3";
elseif (($p >= 81) && ($p <= 99))
 $img .= "4";
return "";       
}
function writecomment($userid, $comment) {
    $res = mysql_query("SELECT modcomment FROM users WHERE id = '$userid'") or sqlerr(__FILE__, __LINE__);
    $arr = mysql_fetch_assoc($res);
 
      $modcomment = gmdate("d-m-Y") . " - " . $comment . "" . ($arr[modcomment] != "" ? "\n\n" : "") . "$arr[modcomment]"; 
    $modcom = sqlesc($modcomment);
 
    return mysql_query("UPDATE users SET modcomment = $modcom WHERE id = '$userid'") or sqlerr(__FILE__, __LINE__);
}
function torrenttable($res, $variant = "index") {
        global $torrent_ttl,$pic_base_url, $CURUSER;
  $browse_res = mysql_query("SELECT last_browse FROM users WHERE id='".$CURUSER['id']."'");

  $browse_arr = mysql_fetch_row($browse_res);

  $last_browse = $browse_arr[0];

  $time_now = gmtime();

if ($last_browse > $time_now) {

  $last_browse=$time_now;

  }
        if ($CURUSER["class"] < UC_VIP)
  {
          $gigs = $CURUSER["uploaded"] / (1024*1024*1024);
          $ratio = (($CURUSER["downloaded"] > 0) ? ($CURUSER["uploaded"] / $CURUSER["downloaded"]) : 0);
          if ($gigs < 5) $wait = 0;
          elseif ($ratio < 0.65 || $gigs < 6.) $wait =0;
          elseif ($ratio < 0.80 || $gigs < 8) $wait = 0;
          elseif ($ratio < 0.95 || $gigs < 9.) $wait = 0;
          else $wait = 0;
                        $elapsed = floor((gmtime() - strtotime($row["added"])) / 3600);
                        if ($elapsed < $wait)
                                $wait = number_format($wait - $elapsed);
  }
//begin_table(true);

?>

// sorting by MarkoStamcar

$count_get = 0;

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 . "&" . $get_name . "=" . $get_value;
} else {
$oldlink = $oldlink . $get_name . "=" . $get_value;
}
$count_get++;
}

}

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


if ($_GET['sort'] == "1") {
if ($_GET['type'] == "desc") {
$link1 = "asc";
} else {
$link1 = "desc";
}
}

if ($_GET['sort'] == "2") {
if ($_GET['type'] == "desc") {
$link2 = "asc";
} else {
$link2 = "desc";
}
}

if ($_GET['sort'] == "3") {
if ($_GET['type'] == "desc") {
$link3 = "asc";
} else {
$link3 = "desc";
}
}

if ($_GET['sort'] == "4") {
if ($_GET['type'] == "desc") {
$link4 = "asc";
} else {
$link4 = "desc";
}
}

if ($_GET['sort'] == "5") {
if ($_GET['type'] == "desc") {
$link5 = "asc";
} else {
$link5 = "desc";
}
}

if ($_GET['sort'] == "6") {
if ($_GET['type'] == "desc") {
$link6 = "asc";
} else {
$link6 = "desc";
}
}

if ($_GET['sort'] == "7") {
if ($_GET['type'] == "desc") {
$link7 = "asc";
} else {
$link7 = "desc";
}
}

if ($_GET['sort'] == "8") {
if ($_GET['type'] == "desc") {
$link8 = "asc";
} else {
$link8 = "desc";
}
}

if ($_GET['sort'] == "9") {
if ($_GET['type'] == "desc") {
$link9 = "asc";
} else {
$link9 = "desc";
}
}

if ($link1 == "") { $link1 = "asc"; } // for torrent name
if ($link2 == "") { $link2 = "desc"; }
if ($link3 == "") { $link3 = "desc"; }
if ($link4 == "") { $link4 = "asc"; }
if ($link5 == "") { $link5 = "desc"; }
if ($link6 == "") { $link6 = "desc"; }
if ($link7 == "") { $link7 = "desc"; }
if ($link8 == "") { $link8 = "desc"; }
if ($link9 == "") { $link9 = "asc"; }
//////////////////////////////// My Torrents Sort by Lost /////////////////////////////
if ($variant == "mytorrents")
  $returnpage = "";
else
  $returnpage = "browse.php";
//////////////////////////////// end of My Torrents Sort by Lost ////////////////////////////

?>






if ($wait)
{
print("\n");
}

if ($variant == "mytorrents")
{
//print("\n");
//print("\n");
}

?>
















  if ($variant == "index")
        //print("\n");
    print("\n");


    while ($row = mysql_fetch_assoc($res)) {

        $id = $row["id"];
print("\n");
        print("\n");

$upnam = ($row["username"]); // SQL query to get Advertise Details from Database.
$upclq = mysql_query("SELECT advertisename FROM users WHERE username = '$upnam'") or qlerr();
$upclas = mysql_fetch_array($upclq);
$addnam = $upclas['advertisename'];
$uprow = (" Anonymous");

//if (get_user_class() >= UC_USER)
if($row["anonymous"] == "yes" AND get_user_class() > UC_MODERATOR AND $CURUSER["id"] != $row["username"])
//$uprow = "" . (isset($row["username"]) ? ("" .htmlspecialchars ($row["username"]) . "") : "(unknown)") . "\n";
$uprow = "" . (isset($row["username"]) ? ("" . htmlspecialchars($row["username"]) . "") : "(unknown)") . "\n";
// Bookmarks mod
$bookt = mysql_query("SELECT torrentid FROM snatched WHERE finished = 'yes' AND torrentid = $row[id] AND userid = $CURUSER[id]");
if (mysql_num_rows($bookt) > 0)
//print("Bookmark\n");
$bookt = ("You Already Downloaded This Torrent!!");
else
$bookt = ("");
  //end bookmarks
// Bookmarks mod
$bookts = mysql_query("SELECT torrentid FROM bookmarks WHERE torrentid = $row[id] AND userid = $CURUSER[id]");
if (mysql_num_rows($bookts) > 0)
//print("Bookmark\n");
$bookts = ("Un-Bookmark This Torrent!!");
else
$bookts = ("Bookmark This Torrent!!");
  //end bookmarks
        $timezone = display_date_time($row["utadded"] , $CURUSER[tzoffset]);
        $added1 = display_date_time($row["utadded"] , $CURUSER[tzoffset] );
        $added = "" . get_elapsed_times(sql_timestamp_to_unix_timestamp($row["added"])) . " ago";
        $nukereason = htmlspecialchars($row["nukereason"]);
        $doubleuptag = ($row["10days"]=="yes" ? "x2" : "");
        $thisisnuked = ($row["nuked"] == "yes" ? "Nuked" : "");
        $thisisfrees = ($row[free]=="yes" ? "" : "");
        //$thisisfrees = ($row[free]=="yes" ? "[Free]" : "");
        //$scene = ($row[scene]=="yes" ? "" : "");
        if (get_user_class() <  UC_VIP){
$request = ($row[request]=="yes" ? "" : "");
    } 
$dispname = htmlspecialchars($row["name"]);
$comments = htmlspecialchars($row["comments"]);

if (get_user_class() >= UC_OWNER){
//$del = (" Delete");
}
if (get_user_class() >= UC_VIP){
$dl = ("Download");
}
        $newtag = ((sql_timestamp_to_unix_timestamp($row['added']) >= $last_browse)? ' ' : '');       
        $sticky = ($row[sticky]=="yes" ? "sticky" : "");
if (!empty($row['genre'])) {
$a = split(',',$row['genre']);
foreach ($a as $value) {
//echo("     " . $value . " / ");
}
}
if ($row["tags"] == "")
{
    $keywords = "";
}
else
{
    $tags = explode(",", $row["tags"]);
    //$keywords = "     ";
    $keywords = "     ";
   
    foreach ($tags as $tag){
        $tag = str_replace(" ", "",$tag);
        $keywords .= "$tag ,";
    }
        $keywords  = substr($keywords, 0, (strlen($keywords) - 2));
       
}
//print("
\n");
if (!empty($row['genre']))
$genres = "     " . htmlspecialchars($row["genre"]) . "";
else
$genres = "";
//$genres = "";


if (!empty($row['description'])) {
        $description = "(" . htmlspecialchars($row["description"]) . ")";
        }
        else {
        $description = "";
        }
$char = 75; //Max long...
//print("\n");
                }
                else
                  print("\n");
        }
/*
        if ($row["nfoav"] && get_user_class() >= UC_POWER_USER)
          print("\n");
*/
          //print("$bookt\n");

/*
// Bookmarks mod
$bookt = mysql_query("SELECT torrentid FROM bookmarks WHERE torrentid = $row[id] AND userid = $CURUSER[id]");
if (mysql_num_rows($bookt) > 0)
print("Bookmark\n");
    else
print("Bookmark\n");
  //end bookmarks
*/

        if ($CURUSER["downloadpos"] != "no")
if ($CURUSER['class'] >= UC_VIP)
          //print("$bookt $bookts\n");

            //print("\n");

//print("
Download
\n");

          //print("$bookt $bookts\n");

        if ($variant == "index")

        if ($row["times_completed"] != 1)
          $_s = "s";

//print("\n");

        if ($row["type"] == "single")

            print("\n");
        else {
            if ($variant == "index")
                print("\n");
        //print("\n");
                //print("\n");
            else
                //print("\n");
                print("\n");
        }

        if (!$row["comments"])
            print("\n");
        else {
            if ($variant == "index")
                print("\n");
            else
                print("\n");
        }
        print("\n");

              //print("\n");
        //print("\n");

        print("\n");
//        print("\n");
//      print("\n");
        $_s = "";
        if ($row["times_completed"] != 1)
          $_s = "s";
//print("\n");
print("\n");

        if ($row["seeders"]) {
            if ($variant == "index")
            {
              if ($row["leechers"]) $ratio = $row["seeders"] / $row["leechers"]; else $ratio = 1;
                print("\n");
        }
        else
            print("\n");

        if ($row["leechers"]) {
            if ($variant == "index")
                print("" .
                  number_format($row["leechers"]) . ($peerlink ? "
" : "") .
                  "\n");
            else
                print("
\n");
        }
        else
            print("
\n");

        if ($variant == "index")
########################################
# Advertise Upload MOD 2005. YeOK #
########################################

$upnam = ($row["username"]); // SQL query to get Advertise Details from Database.
$upclq = mysql_query("SELECT anonymous FROM users WHERE username = '$upnam'") or qlerr();
$upclas = mysql_fetch_array($upclq);
$addnam = $upclas['anonymous'];
$uprow = ("
\n";
//$uprow = "
\n";
            //print("$uprow\n");

print($uprow);
print("
\n");
print("
\n");
}

    end_table();

    return $rows;
}


function hash_pad($hash) {
    return str_pad($hash, 20);
}

function hash_where($name, $hash) {
    $shhash = preg_replace('/ *$/s', "", $hash);
    return "($name = " . sqlesc($hash) . " OR $name = " . sqlesc($shhash) . ")";
}

function get_user_icons($arr, $big = false)
{
    if ($big)
    {
        $donorpic = "star1.gif";
        $dd = "downloaddisabled.gif";
        $leechwarnpic = "warnedbig.gif";
        $warnedpic = "warnedbig.gif";
        $disabledpic = "disabledbig.gif";
        //$style = "style='margin-left: 4pt'";
    }
    else
    {
        $donorpic = "star1.gif";
        $dd = "downloaddisabled.gif";
        $leechwarnpic = "warned.gif";
        $warnedpic = "warnedbig.gif";
        $disabledpic = "disabled.gif";
        //$style = "style=\"margin-left: 2pt\"";
    }
    $pics = $arr["donor"] == "yes" ? " " : "";
    if ($arr["enabled"] == "yes")
        $pics .= ($arr["warned"] == "yes" ? " " : "") . ($arr["downloadpos"] == "no" ? " " : "");
    else
        $pics .= " \n";
    return $pics;
}

function verify_passkey($passkey)
{
  global $CURUSER;
  if (strlen($CURUSER['passkey']) != 32)
  {
          do {
                        $CURUSER['passkey'] = md5($CURUSER['username'].get_date_time().$CURUSER['passhash']);
                        $notok=mysql_query("UPDATE users SET passkey='$CURUSER[passkey]' WHERE id=$CURUSER[id]") === FALSE;
                } while($notok);
        }

        return($CURUSER['passkey']==$passkey);
}


// Old dbconn() function, now isn't called, but is done automatically when it's included
    if (!@mysql_connect($mysql_host, $mysql_user, $mysql_pass))
    {
                  switch (mysql_errno())
                  {
                                case 1040:
                                case 2002:
                                        if ($_SERVER[REQUEST_METHOD] == "GET")
                                                die("
Genre Name WT EditVisible Added Comments Size Snatches Seeders Leechers Upped by Upped by
");
        if (isset($row["cat_name"])) {
            print("");
            if (isset($row["cat_pic"]) && $row["cat_pic"] != "")
                //print("");
                print("");
            else
                print($row["cat_name"]);
            print("
");
        }

        else
            print("-");
        print("
Search Tags:" . $keywords . "
");
print("
//print("
if ($variant == "mytorrents")
print("returnto=" . urlencode($_SERVER["REQUEST_URI"]) . "&");
print("id=$id");
if ($variant == "index")
print("");
if (sql_timestamp_to_unix_timestamp($row["added"]) >= $last_browse)
          print("\" title=\"". $dispname . "\"> " . CutName($dispname, $char) . "
   NEW!$del $bookt $bookts $dl $thisisfrees $thisisnuked $doubleuptag");
          //print("\" title=\"". $dispname . "\">NEW!" . CutName($dispname, $char) . " $thisisnuked$thisisfrees($added) By $uprow $keywords $sticky  $thisisfree $del $request $doubleuptag");         
          else
            print("\" title=\"" . $dispname . "\">" . CutName($dispname, $char) . "$del $bookt $bookts $dl $thisisfrees $thisisnuked $doubleuptag");
            //print("\" title=\"" . $dispname . "\">" . CutName($dispname, $char) . " $bookt($added) $added1 By $uprow $genres $thisisfrees $thisisnuked $del $request $doubleuptag");
        if ($CURUSER["downloadpos"] != "no")

if ($variant == "index")
                                if ($wait)
                                {
                                  $elapsed = floor((gmtime() - strtotime($row["added"])) / 3600);
                if ($elapsed < $wait)
                {
                  $color = dechex(floor(127*($wait - $elapsed)/48 + 128)*65536);
                  print("
" . number_format($wait - $elapsed) . " h--- $del " . $row["numfiles"] . " $added$added" . str_replace(" ", " ", mksize($row["size"])) . " In " . $row["numfiles"] . " File$s" . $row["numfiles"] . " $added
" . $row["comments"] . "
" . $row["comments"] . " $added1($added)" . str_replace(" ", "", $row["added"]) . "
" . str_replace(" ", " ", mksize($row["size"])) . "
" . $row["views"] . "" . $row["hits"] . "" . number_format($row["times_completed"]) . " time$_s" . number_format($row["times_completed"]) . " " . $row["seeders"] . "");
            }
            else
                print("
" .
                  $row["seeders"] . "
" . $row["seeders"] . " " .$row["leechers"] . " 0 *Anonymous*");

$uprow = "
" . (isset($row["username"]) ? ("" . htmlspecialchars($row["username"]) . "") : "(unknown)") . "" . (isset($row["username"]) ? ("" . htmlspecialchars($row["username"]) . "") : "(unknown)") . "

The server load is very high at the moment. Please try again in a few moments

");
else
                                                die("Too many users. Please press the Refresh button in your browser to retry.");
        default:
                die("[" . mysql_errno() . "] dbconn: mysql_connect: " . mysql_error());
      }
    }
    mysql_select_db($mysql_db)
        or die('dbconn: mysql_select_db: ' + mysql_error());

    userlogin();

    if (basename($_SERVER['SCRIPT_FILENAME']) == 'index.php')
        register_shutdown_function("autoclean");

// Empty dbconn for compatibility
function dbconn()
{
}
?>
Bump: here is all the files needed for the ajax browse m8
ndbj 14th January 2013 05:44

Quote:

Originally Posted by sharpie (Post 38636)
i think the $last_browse needs to be incorporated into the browse.class.php somehow

put this at the end of your browse.class.php
right before the stdfoot

PHP Code:

mysql_query("UPDATE users SET last_browse=".gmtime()." where id=".$CURUSER['id']); 

and i think all the new tags will be cleared with refresh, no need to add button to remove new tag.

sharpie 15th January 2013 01:44

added m8 but still shows new tags after i refresh page:(


All times are GMT +2. The time now is 08:05.

Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.