/***
* @copyright (c) 2007 - 2008 www.gosudar.com.ru
* (c) 2004 - 2005 Project Minerva
* (c) 2001 - 2006 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
***/
if ( !defined('IN_R3BORN') )
{
die('Hacking attempt');
}
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_TRAIDER);
init_userprefs($userdata);
//
// End session management
//
if ( !$userdata['session_logged_in'] )
{
redirect(append_sid("login.$phpEx?redirect=" . buildModuleURL('trader'), true));
}
include($mvModule_root_path . 'functions.php');
include($mvModule_root_path . 'news.php');
$keywords = '' ;
$cat = '' ;
$mode = (string)$_GET['mode'] ;
if (isset($_POST['keywords']))
{
$keywords = (string)$_POST['keywords'] ;
}
if (isset($_POST['category']))
{
$cat = (string)$_POST['category'] ;
}
if (isset($_GET['page']))
{
$page = (int)$_GET['page'] ;
}
//header
if ($mode != "ajax")
{
$page_title = "Трекер Trader";
page_header($page_title);
$template->set_filenames(array(
'body' => 'trader_body.tpl')
);
}
else
{
$template->set_filenames(array(
'body' => 'trader_body_ajax.tpl')
);
}
// we display the search box
$search_category = '';
foreach ($categories as $value)
{
$search_category .=''.$value.' ';
}
// Now build content
$content = '';
// if not exists already, we create it
if (!file_exists($mvModule_root_path . 'data/torrents.dat'))
{
touch($mvModule_root_path . 'data/torrents.dat');
}
$source = fopen($mvModule_root_path . 'data/torrents.dat','r');
flock($source, LOCK_EX) ;
$cnt = 0;
$total = 0;
while ($info = fscanf ($source, "%s %s %s %ld %d %s %s %d %d %d %d\n")) {
if (!file_exists($mvModule_root_path . 'data/'.$info_hash.'.lock'))
{
$total++;
}
}
rewind($source);
list($quotient,$reste) = euclidivision($total,$torrents_per_page);
if ($page == "")
{
$page = 0;
}
// we process the search form and display the results
while ($info = fscanf ($source, "%s %s %s %ld %d %s %s %d %d %d %d\n")) {
list ($info_hash, $filename, $name,$size,$numfiles,$descr,$category,$seeders,$leechers,$completed,$hits) = $info;
// has the torrent been banned from server ?
if (file_exists($mvModule_root_path . 'data/'.$info_hash.'.lock'))
{
continue;
}
$totseeders += $seeders;
$totleechers += $leechers;
$category = " ";
$newname = substr($name, 0, 35);
if ($newname != $name)
{
$name = $newname . "...";
}
else
{
$name = $newname;
}
$health = ' ';
if ($cnt >= $page*$torrents_per_page && $cnt < ($page+1)*$torrents_per_page)
{
// user entered a word to search and changed the default category
if ($keywords != "" && ($cat != "" && $cat != $lang['TR_search_all_category']) )
{
if (eregi($cat,$category) && (eregi($keywords,$name) || eregi($keywords,$filename) || eregi($keywords,$descr)))
{
//echo "1";
$content .=
'
'.$name.' ( )
';
$cnt++;
}
}
// user just changed the default category
else if ($keywords == "" && ($cat != "" && $cat != "All Categories") )
{
if (eregi($cat,$category))
{
//echo "2";
$content .=
'
'.$name.' ( )
';
}
}
// user set category to "All Categories" but is looking for a special torrent
else if ( $keywords != "" && ($cat == "" || $cat == "All Categories"))
{
if ( (eregi($keywords,$name) || eregi($keywords,$filename) || eregi($keywords,$descr)))
{
//echo "3";
$content .=
'
'.$name.' ( )
'. LOADING_PLEASE_WAIT .'
';
}
}
// user is not doing a search
else
{
//echo "4";
$content .=
'
'.$name.' ( )
';
}
}
$cnt++;
$i = $cnt;
$row_class = ( !($i % 2) ) ? 'row1' : 'row2';
$template->assign_block_vars('torrents', array(
'CLASS' => $row_class,
'TR_CATEGORY' => $category,
'TR_SIZE' => tt_filesize($size),
'TR_SEEDERS' => $seeders,
'TR_LEECHERS' => $leechers,
'TR_HEALTH' => $health,
'TR_NAME' => $name,
'TR_HASH' => $info_hash,
//'U_TR_HASH' => append_sid('details.'.$phpEx.'?info_hash=' . $info_hash),
'U_TR_HASH' => ( $ajax_browse ) ? "javascript:sndAjaxReq('" .append_sid('details.'.$phpEx.'?info_hash=' . $info_hash) . "');" : append_sid('details.'.$phpEx.'?info_hash=' . $info_hash),
) //end array
);
}
flock($source, LOCK_UN);
fclose($source);
// no result was found
if ($cnt == 0)
{
$template->assign_block_vars('switch_no_torrents', array());
}
$content .=' ';
if ($quotient > 0)
{
$content .= ''.INDEX_PAGE.': ';
if ($reste==0)
$lim = $quotient-1;
else $lim = $quotient;
if ($page > 0)
$content .= '
';
if ($page > 1)
$content .= '
';
for ($i=0;$i<=$lim;$i++)
{
if ($i == $page)
$content .= '
'.($i+1).' ';
else $content .= '
'.($i+1).' ';
}
if ($page < $lim-1)
$content .= '
';
if ($page < $lim)
$content .= '
';
$content .= '
';
}
$content .='
';
//stats
if (!isset($totseeders))
$totseeders = 0;
if (!isset($totleechers))
$totleechers = 0;
//$content .= ''.sprintf(INDEX_TRACKING,$cnt,$totseeders + $totleechers,$totseeders,$totleechers).'
';
//Torrents News
if (isset($news_array))
{
foreach ($new_array as $new)
{
$news .= "".$new['title']." (Posted on ".$new['date']." by ".$new['author']." )";
$news .= " ".$new['content'].' ';
$template->assign_block_vars('news_torrents', array(
'CLASS' => $row_class,
'TR_NEWS_TITLE' => $new['title'],
'TR_NEWS_DATE' => $new['date'],
'TR_NEWS_AUTHOR' => $new['author'],
'TR_NEWS_CONTENT' => $new['content'],
//'TR_HEALTH' => $health,
//'TR_NAME' => $name,
//'TR_HASH' => $info_hash,
//'U_TR_HASH' => append_sid('details.'.$phpEx.'?info_hash=' . $info_hash),
) //end array
);
}
}
//main_box($mainbox_title,$news.$content);
$template->assign_vars(array(
'TR_TITLE' => $title,
'TR_CONTENT' => $content,
'L_TR_TITLE' => $lang['TR_title'],
'L_TR_INDEX' => $lang['TR_index'],
'U_TR_INDEX' => ( $ajax_browse ) ? "javascript:sndAjaxReq('index.php?module=trader');" : "index.php?module=trader",
'L_TR_UPLOAD' => $lang['TR_upload'],
'U_TR_UPLOAD' => ( $ajax_browse ) ? "javascript:sndAjaxReq('index.php?module=trader&file=upload');" : "index.php?module=trader&file=upload",
'L_TR_FAQ' => $lang['TR_faq'],
'U_TR_FAQ' => ( $ajax_browse ) ? "javascript:sndAjaxReq('index.php?module=trader&file=faq');" : "index.php?module=trader&file=faq",
'L_SEARCH' => $lang['Search'],
'L_NO_RESULTS' => $lang['TR_noresults'],
'L_TR_SEARCH_KEYWORDS' => $lang['TR_search_keywords'],
'L_TR_SEARCH_CATEGORY' => $lang['TR_search_category'],
'L_TR_SEARCH_ALL_CATEGORIES' => $lang['TR_search_all_category'],
'TR_SEARCH_CATEGORY' => $search_category,
'TR_KEYWORDS' => $keywords,
'L_TR_TYPE' => $lang['TR_type'],
'L_TR_NAME' => $lang['TR_name'],
'L_TR_SIZE' => $lang['TR_size'],
'L_TR_SEEDERS' => $lang['TR_seeders'],
'L_TR_LEECHERS' => $lang['TR_leechers'],
'L_TR_HEALTH' => $lang['TR_health'],
'L_TR_PLEASE_WAIT' => $lang['TR_please_wait'],
'L_TR_MORE' => $lang['TR_more'],
'U_TR_RELOAD' => append_sid('trader.'.$phpEx),
'TR_STATS_FOOTER' => sprintf($lang['TR_tracking'],$cnt,$totseeders + $totleechers,$totseeders,$totleechers),
)
);
if ($mode == "ajax")
{
header('Content-type: text/html; charset=UTF-8');
echo "title|Торрент|inside|";
}
$template->pparse('body');
if ($mode != "ajax")
{
page_footer();
}
?>