| 1 |
<?php |
|---|
| 2 |
function get_slr_color($ratio) {</span> |
|---|
| 3 |
<span class="code-keyword"> if ( $ratio == 'Inf.' || $ratio == '---' ) { |
|---|
| 4 |
return ''; |
|---|
| 5 |
} |
|---|
| 6 |
$n = 0.375; |
|---|
| 7 |
$color = 16; |
|---|
| 8 |
for ($i=0.025; $i<=$n; $i+=0.025) { |
|---|
| 9 |
$color-=1; |
|---|
| 10 |
$s = dechex($color); |
|---|
| 11 |
if ($ratio < $i) { |
|---|
| 12 |
return '#' . $s . $s . '0000'; |
|---|
| 13 |
} |
|---|
| 14 |
|
|---|
| 15 |
} |
|---|
| 16 |
return ''; |
|---|
| 17 |
} |
|---|
| 18 |
|
|---|
| 19 |
function torrenttable($ary, $bookmarks = false) { |
|---|
| 20 |
global $userdata, $lang, $config, $template, $images, $cats, $theme, $root_path; |
|---|
| 21 |
global $seo; |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
if ( !sizeof($ary) ) { |
|---|
| 25 |
return; |
|---|
| 26 |
} |
|---|
| 27 |
|
|---|
| 28 |
$count_get = $i = $wait = 0; |
|---|
| 29 |
$sort = request_var('sort', ''); |
|---|
| 30 |
$sort_type = request_var('type', ''); |
|---|
| 31 |
$search = request_var('search', ''); |
|---|
| 32 |
$oldlink = ''; |
|---|
| 33 |
$highlight = ( $search ? '&highlight=' . urlencode($search) : '' ); |
|---|
| 34 |
|
|---|
| 35 |
foreach ($_GET as $get_name => $get_value) { |
|---|
| 36 |
if ( $get_name != 'sort' && $get_name != 'type' && !empty($get_value) ) { |
|---|
| 37 |
if ($count_get > 0) { |
|---|
| 38 |
$oldlink = $oldlink . '&' . $get_name . '=' . trim(htmlspecialchars($get_value)); |
|---|
| 39 |
} |
|---|
| 40 |
else { |
|---|
| 41 |
$oldlink = $oldlink . $get_name . '=' . trim(htmlspecialchars($get_value)); |
|---|
| 42 |
} |
|---|
| 43 |
$count_get++; |
|---|
| 44 |
} |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
if ( $count_get > 0 ) { |
|---|
| 48 |
$oldlink = $oldlink . '&'; |
|---|
| 49 |
} |
|---|
| 50 |
$u_sort = $root_path . ( $bookmarks ? 'bookmarks' : 'browse' ) . '.php'; |
|---|
| 51 |
for( $i = 1; $i < 12; $i++ ) { |
|---|
| 52 |
$sort = $oldlink . 'sort=' . $i . '&type=' . ( $sort_type == 'desc' ? 'asc' : 'desc' ); |
|---|
| 53 |
|
|---|
| 54 |
$template->assign_vars(array( |
|---|
| 55 |
'U_SORT_' . "$i" => append_sid($u_sort, $sort) |
|---|
| 56 |
)); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
if ( $userdata['class'] < UC_VIP && $userdata['session_logged_in'] ) { |
|---|
| 60 |
$gigs = $userdata['downloaded'] / ( 1024*1024*1024 ); |
|---|
| 61 |
$ratio = ( ( $userdata['downloaded'] > 0 ) ? ( $userdata['uploaded'] / $userdata['downloaded'] ) : 1 ); |
|---|
| 62 |
if ( $ratio < 0.5 || $gigs < 5 ) { |
|---|
| 63 |
$wait = 48; |
|---|
| 64 |
} |
|---|
| 65 |
elseif ( $ratio < 0.65 || $gigs < 6.5 ) { |
|---|
| 66 |
$wait = 24; |
|---|
| 67 |
} |
|---|
| 68 |
elseif ( $ratio < 0.8 || $gigs < 8 ) { |
|---|
| 69 |
$wait = 12; |
|---|
| 70 |
} |
|---|
| 71 |
elseif ( $ratio < 0.95 || $gigs < 9.5 ) { |
|---|
| 72 |
$wait = 6; |
|---|
| 73 |
} |
|---|
| 74 |
else { |
|---|
| 75 |
$wait = 0; |
|---|
| 76 |
} |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
$moderator = $userdata['class'] >= UC_MODERATOR; |
|---|
| 80 |
|
|---|
| 81 |
if ( $bookmarks ) { |
|---|
| 82 |
$s_form_action = $root_path . 'bookmarks.php'; |
|---|
| 83 |
} |
|---|
| 84 |
elseif ( !$bookmarks && $moderator ) { |
|---|
| 85 |
$s_form_action = $root_path . 'modtask.php?action=mass_torrent_actions'; |
|---|
| 86 |
} |
|---|
| 87 |
else { |
|---|
| 88 |
$s_form_action = ''; |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
$torrent_actions = array('free', 'free_silver', 'free_bronze', 'unfree', 'move', 'ban', 'unban', 'hide', 'unhide', 'moderate', 'unmoderate', 'delete', 'disable_comments', 'enable_comments'); |
|---|
| 92 |
$torrent_action_options = ''; |
|---|
| 93 |
foreach ( $torrent_actions AS $_null => $action ) { |
|---|
| 94 |
$name = ( isset($lang['torrent_action_' . $action]) ? $lang['torrent_action_' . $action] : $action ); |
|---|
| 95 |
$torrent_action_options .= '<option value="' . $action . '">' . $name . '</option>'; |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
$template->assign_vars(array( |
|---|
| 99 |
'L_TTL' => ( $config['ttl'] ) ? $lang['ttl'] : '', |
|---|
| 100 |
'L_WAIT' => ( $config['waittime'] && $wait) ? $lang['wait'] : '', |
|---|
| 101 |
|
|---|
| 102 |
'S_FORM_ACTION' => append_sid($s_form_action), |
|---|
| 103 |
'BOOKMARKS' => ( $bookmarks ? true : false ), |
|---|
| 104 |
'CAN_MODERATE' => ( $bookmarks ? false : $moderator ), |
|---|
| 105 |
'TORRENT_ACTION_OPTIONS' => $torrent_action_options, |
|---|
| 106 |
|
|---|
| 107 |
'THEME_HIDDEN_TORRENT_COLOR' => $theme['hidden_torrent_color'], |
|---|
| 108 |
)); |
|---|
| 109 |
|
|---|
| 110 |
$prev_added_day = 0; |
|---|
| 111 |
|
|---|
| 112 |
for ( $i = 0; $i < sizeof($ary); ++ $i ) { |
|---|
| 113 |
$cat_id = $ary[$i]['category']; |
|---|
| 114 |
$cat_parent_id = ( isset($cats[$cats[$cat_id]['cat_parent']]['cat_id']) ? $cats[$cats[$cat_id]['cat_parent']]['cat_id'] : 0 ); |
|---|
| 115 |
|
|---|
| 116 |
$id = $ary[$i]['fid']; |
|---|
| 117 |
$dispname = $ary[$i]['name']; |
|---|
| 118 |
$dispname = censor_text($dispname); |
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
$seo->set_torrent_url($id, $ary[$i]['name'], $cat_id); |
|---|
| 122 |
$seo->set_user_url($ary[$i]['username'], $ary[$i]['owner']); |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
$dispname = ( $highlight ? highlight_text($search, $dispname) : $dispname ); |
|---|
| 126 |
|
|---|
| 127 |
$rating = ratingpic($ary[$i]['numratings'], $ary[$i]['ratingsum']); |
|---|
| 128 |
|
|---|
| 129 |
if ( isset($config['ttl']) && ($config['ttl'] > 0) ) { |
|---|
| 130 |
$ttl = floor(( ($config['ttl'] * 60 * 60 * 24) - (time() - $ary[$i]['ctime'])) / 3600); |
|---|
| 131 |
$ttl .= ($ttl == 1) ? ' ' . $lang['hour'] : ' ' . $lang['hours']; |
|---|
| 132 |
} |
|---|
| 133 |
if ( $wait && $config['waittime'] ) { |
|---|
| 134 |
$elapsed = floor((time() - $ary[$i]['ctime']) / 3600); |
|---|
| 135 |
if ( $elapsed < $wait ) { |
|---|
| 136 |
$color = dechex(floor(127*($wait - $elapsed)/48 + 128)*65536); |
|---|
| 137 |
$waitime = '<span style="color:' . $color . ';">' . ( $wait - $elapsed ) . ' ' . ( ( $wait - $elapsed ) == 1? '<br />' . $lang['hour'] : '<br />' . $lang['hours']) . '</span>'; |
|---|
| 138 |
} |
|---|
| 139 |
else { |
|---|
| 140 |
$waitime = '---'; |
|---|
| 141 |
} |
|---|
| 142 |
} |
|---|
| 143 |
|
|---|
| 144 |
if ( $ary[$i]['seeders'] ) { |
|---|
| 145 |
$ratio = ( $ary[$i]['leechers'] ? $ary[$i]['seeders'] / $ary[$i]['leechers'] : 1 ); |
|---|
| 146 |
$slr_color = get_slr_color($ratio); |
|---|
| 147 |
} |
|---|
| 148 |
else { |
|---|
| 149 |
$slr_color = 'FF0000'; |
|---|
| 150 |
} |
|---|
| 151 |
$username = parse_username($ary[$i]); |
|---|
| 152 |
|
|---|
| 153 |
$tor_last_read = get_tracking(TYPE_TORRENT, $id); |
|---|
| 154 |
|
|---|
| 155 |
$moderated = ( $ary[$i]['moderated'] ? true : false ); |
|---|
| 156 |
|
|---|
| 157 |
$cat_name_display = ''; |
|---|
| 158 |
if ( $cat_parent_id ) { |
|---|
| 159 |
$cat_name_display .= '<a href="' . append_sid($root_path . 'browse.php?cat=' . $cat_parent_id) . '">' . $cats[$cats[$cat_id]['cat_parent']]['cat_name'] . '</a> -> '; |
|---|
| 160 |
} |
|---|
| 161 |
$cat_name_display .= '<a href="' . append_sid($root_path . 'browse.php?cat=' . $cat_id) . '">' . $cats[$cat_id]['cat_name'] . '</a>'; |
|---|
| 162 |
|
|---|
| 163 |
if ( $prev_added_day <> create_date($ary[$i]['ctime'], 'Y-m-d') ) { |
|---|
| 164 |
$added_day = create_date($ary[$i]['ctime'], 'Y-m-d'); |
|---|
| 165 |
} |
|---|
| 166 |
else { |
|---|
| 167 |
$added_day = ''; |
|---|
| 168 |
} |
|---|
| 169 |
$prev_added_day = create_date($ary[$i]['ctime'], 'Y-m-d'); |
|---|
| 170 |
|
|---|
| 171 |
$template->assign_block_vars('torrents_table', array( |
|---|
| 172 |
'U_CATEGORY' => append_sid($root_path . 'browse.php?cat=' . $cat_id), |
|---|
| 173 |
'U_DETAILS' => append_sid($root_path . 'details.php?id=' . $id . $highlight), |
|---|
| 174 |
'U_DETAILS_FILELIST' => append_sid($root_path . 'details.php?id=' . $id . '&view=filelist#filelist'), |
|---|
| 175 |
'U_DOWNLOAD' => append_sid($root_path . 'details.php?id=' . $id . '&action=download'), |
|---|
| 176 |
'U_ADD_BOOKMARK' => append_sid($root_path . 'bookmarks.php?torrent=' . $id), |
|---|
| 177 |
'U_COMMENTS' => append_sid($root_path . 'details.php?id=' . $id . '&view=comments#startcomments'), |
|---|
| 178 |
'U_SNATCHED' => append_sid($root_path . 'details.php?id=' . $id . '&view=snatchedlist#snatched'), |
|---|
| 179 |
'U_PEERLIST' => append_sid($root_path . 'details.php?id=' . $id . '&view=peerlist'), |
|---|
| 180 |
'U_OWNER' => append_sid($root_path . 'userdetails.php?id=' . $ary[$i]['owner']), |
|---|
| 181 |
'DISPNAME' => $dispname, |
|---|
| 182 |
'MODERATED' => $moderated, |
|---|
| 183 |
'TORRENT_FREE_ICON' => get_free_icon($ary[$i]['free']), |
|---|
| 184 |
'TORRENT_HIDDEN' => $ary[$i]['hidden'], |
|---|
| 185 |
'TORRENT_BANNED' => $ary[$i]['banned'], |
|---|
| 186 |
'TORRENT_COMMENTS' => $ary[$i]['comments'], |
|---|
| 187 |
'TORRENT_COMPLETED' => $ary[$i]['completed'], |
|---|
| 188 |
'TORRENT_SEEDERS' => $ary[$i]['seeders'], |
|---|
| 189 |
'TORRENT_LEECHERS' => $ary[$i]['leechers'], |
|---|
| 190 |
'SLR_COLOR' => $slr_color, |
|---|
| 191 |
'NEW' => ( $ary[$i]['ctime'] >= $tor_last_read ? true : false ), |
|---|
| 192 |
'ADDED' => create_date($ary[$i]['ctime']), |
|---|
| 193 |
'ADDED_DAY' => $added_day, |
|---|
| 194 |
'CAT_PIC' => $cats[$cat_id]['cat_pic'], |
|---|
| 195 |
'CAT_NAME' => $cats[$cat_id]['cat_name'], |
|---|
| 196 |
'CAT_NAME_DISPLAY' => $cat_name_display, |
|---|
| 197 |
'NUMFILES' => $ary[$i]['numfiles'], |
|---|
| 198 |
'RATING' => $rating, |
|---|
| 199 |
'TTL' => ( isset($ttl) ? $ttl : '' ), |
|---|
| 200 |
'WAITTIME' => ( isset($waitime) ? $waitime : '' ), |
|---|
| 201 |
'SIZE' => mksize($ary[$i]['size']), |
|---|
| 202 |
'USERNAME' => ( $ary[$i]['privacy'] == PRIVACY_LEVEL_HIGH && $userdata['class'] < UC_MODERATOR && $ary[$i]['owner'] <> $userdata['uid'] ? '<i>' . $lang['anonymous'] . '</i>' : $username ), |
|---|
| 203 |
|
|---|
| 204 |
'ID' => $ary[$i]['fid'], |
|---|
| 205 |
'BOOKMARK_ID' => ( $bookmarks ? $ary[$i]['bookmarkid'] : '' ) |
|---|
| 206 |
)); |
|---|
| 207 |
} |
|---|
| 208 |
} |
|---|
| 209 |
?> |
|---|