PageRenderTime 63ms CodeModel.GetById 2ms app.highlight 53ms RepoModel.GetById 1ms app.codeStats 1ms

/upload/attach_mod/displaying_torrent.php

http://torrentpier2.googlecode.com/
PHP | 603 lines | 513 code | 77 blank | 13 comment | 153 complexity | 39563be5d22b417fdd08b231af559444 MD5 | raw file
  1<?php
  2
  3if (!defined('IN_FORUM')) die(basename(__FILE__));
  4
  5global $bb_cfg, $t_data, $poster_id, $is_auth, $dl_link_css, $dl_status_css, $lang, $images;
  6
  7$change_peers_bgr_over = true;
  8$bgr_class_1    = 'row1';
  9$bgr_class_2    = 'row2';
 10$bgr_class_over = 'row3';
 11
 12$show_peers_limit          = 300;
 13$max_peers_before_overflow = 20;
 14$peers_overflow_div_height = '400px';
 15$peers_div_style_normal    = 'padding: 3px;';
 16$peers_div_style_overflow  = "padding: 6px; height: $peers_overflow_div_height; overflow: auto; border: 1px inset;";
 17$s_last_seed_date_format   = 'Y-m-d';
 18$upload_image              = '<img src="'. $images['icon_dn'] .'" alt="'. $lang['DL_TORRENT'] .'" border="0" />';
 19
 20$peers_cnt = $seed_count = 0;
 21$seeders = $leechers = '';
 22$tor_info = array();
 23
 24$template->assign_vars(array(
 25	'SEED_COUNT'      => false,
 26	'LEECH_COUNT'     => false,
 27	'TOR_SPEED_UP'    => false,
 28	'TOR_SPEED_DOWN'  => false,
 29	'SHOW_RATIO_WARN' => false,
 30));
 31
 32// Define show peers mode (count only || user names with complete % || full details)
 33$cfg_sp_mode = $bb_cfg['bt_show_peers_mode'];
 34$get_sp_mode = (isset($_GET['spmode'])) ? $_GET['spmode'] : '';
 35
 36$s_mode = 'count';
 37
 38if ($cfg_sp_mode == SHOW_PEERS_NAMES)
 39{
 40	$s_mode = 'names';
 41}
 42else if ($cfg_sp_mode == SHOW_PEERS_FULL)
 43{
 44	$s_mode = 'full';
 45}
 46
 47if ($bb_cfg['bt_allow_spmode_change'])
 48{
 49	if ($get_sp_mode == 'names')
 50	{
 51		$s_mode = 'names';
 52	}
 53	else if ($get_sp_mode == 'full')
 54	{
 55		$s_mode = 'full';
 56	}
 57}
 58
 59$bt_topic_id    = $t_data['topic_id'];
 60$bt_user_id     = $userdata['user_id'];
 61$attach_id      = $attachments['_'. $post_id][$i]['attach_id'];
 62$tracker_status = $attachments['_'. $post_id][$i]['tracker_status'];
 63$download_count = $attachments['_'. $post_id][$i]['download_count'];
 64$tor_file_size  = humn_size($attachments['_'. $post_id][$i]['filesize']);
 65$tor_file_time  = bb_date($attachments['_'. $post_id][$i]['filetime']);
 66
 67$tor_reged = (bool) $tracker_status;
 68$show_peers = (bool) $bb_cfg['bt_show_peers'];
 69
 70$locked = ($t_data['forum_status'] == FORUM_LOCKED || $t_data['topic_status'] == TOPIC_LOCKED);
 71$tor_auth = ($bt_user_id != GUEST_UID && (($bt_user_id == $poster_id && !$locked) || $is_auth['auth_mod']));
 72
 73$tor_auth_reg = ($tor_auth && $t_data['allow_reg_tracker'] && $post_id == $t_data['topic_first_post_id']);
 74$tor_auth_del = ($tor_auth && $tor_reged);
 75
 76$tracker_link  = ($tor_reged) ? $lang['BT_REG_YES'] : $lang['BT_REG_NO'];
 77
 78$download_link = "download.php?id=$attach_id";
 79$description   = ($comment) ? $comment : preg_replace("#.torrent$#i", '', $display_name);
 80
 81if ($tor_auth_reg || $tor_auth_del)
 82{
 83	$reg_tor_url   = '<a class="txtb" href="#" onclick="ajax.exec({ action: \'change_torrent\', attach_id : '. $attach_id .', type: \'reg\'}); return false;">'. $lang['BT_REG_ON_TRACKER'] .'</a>';
 84	$unreg_tor_url = '<a class="txtb" href="#" onclick="ajax.exec({ action: \'change_torrent\', attach_id : '. $attach_id .', type: \'unreg\'}); return false;">'. $lang['BT_UNREG_FROM_TRACKER'] .'</a>';
 85
 86	$tracker_link = ($tor_reged) ? $unreg_tor_url : $reg_tor_url;
 87}
 88
 89if ($bb_cfg['torrent_name_style'])
 90{
 91	$display_name = '['.$bb_cfg['server_name'].'].t' . $bt_topic_id . '.torrent';
 92}
 93
 94if (!$tor_reged)
 95{
 96	$template->assign_block_vars('postrow.attach.tor_not_reged', array(
 97		'DOWNLOAD_NAME'   => $display_name,
 98		'TRACKER_LINK'    => $tracker_link,
 99		'ATTACH_ID'       => $attach_id,
100
101		'S_UPLOAD_IMAGE'  => $upload_image,
102		'U_DOWNLOAD_LINK' => $download_link,
103		'FILESIZE'        => $tor_file_size,
104
105		'DOWNLOAD_COUNT'  => sprintf($lang['DOWNLOAD_NUMBER'], $download_count),
106		'POSTED_TIME'     => $tor_file_time,
107	));
108
109	if ($comment)
110	{
111		$template->assign_block_vars('postrow.attach.tor_not_reged.comment', array('COMMENT' => $comment));
112	}
113}
114else
115{
116	$sql = "SELECT bt.*, u.user_id, u.username, u.user_rank
117		FROM ". BB_BT_TORRENTS ." bt
118		LEFT JOIN ". BB_USERS  ." u ON(bt.checked_user_id = u.user_id)
119		WHERE bt.attach_id = $attach_id";
120
121	if (!$result = DB()->sql_query($sql))
122	{
123		 message_die(GENERAL_ERROR, 'Could not obtain torrent information', '', __LINE__, __FILE__, $sql);
124	}
125	$tor_info = DB()->sql_fetchrow($result);
126	DB()->sql_freeresult($result);
127}
128
129if ($tor_reged && !$tor_info)
130{
131	DB()->query("UPDATE ". BB_ATTACHMENTS_DESC ." SET tracker_status = 0 WHERE attach_id = $attach_id");
132
133	bb_die('Torrent status fixed');
134}
135
136if ($tor_auth)
137{
138	$template->assign_vars(array(
139		'TOR_CONTROLS'  => true,
140		'TOR_ATTACH_ID' => $attach_id,
141	));
142
143	if ($t_data['self_moderated'] || $is_auth['auth_mod'])
144	{
145		$template->assign_vars(array('AUTH_MOVE' => true));
146	}
147}
148
149if ($tor_reged && $tor_info)
150{
151	$tor_size = ($tor_info['size']) ? $tor_info['size'] : 0;
152	$tor_id   = $tor_info['topic_id'];
153	$tor_type = $tor_info['tor_type'];
154
155	// Magnet link
156	$passkey = DB()->fetch_row("SELECT auth_key FROM ". BB_BT_USERS ." WHERE user_id = ". (int) $bt_user_id ." LIMIT 1");
157	$tor_magnet = create_magnet($tor_info['info_hash'], $passkey['auth_key'], $userdata['session_logged_in']);
158
159	// ratio limits
160	$min_ratio_dl = $bb_cfg['bt_min_ratio_allow_dl_tor'];
161	$min_ratio_warn = $bb_cfg['bt_min_ratio_warning'];
162	$dl_allowed = true;
163	$user_ratio = 0;
164
165	if (($min_ratio_dl || $min_ratio_warn) && $bt_user_id != $poster_id)
166	{
167		$sql = "SELECT u.*, dl.user_status
168			FROM ". BB_BT_USERS ." u
169			LEFT JOIN ". BB_BT_DLSTATUS ." dl ON dl.user_id = $bt_user_id AND dl.topic_id = $bt_topic_id
170			WHERE u.user_id = $bt_user_id
171			LIMIT 1";
172	}
173	else
174	{
175		$sql = "SELECT user_status
176			FROM ". BB_BT_DLSTATUS ."
177			WHERE user_id = $bt_user_id
178				AND topic_id = $bt_topic_id
179			LIMIT 1";
180	}
181
182	$bt_userdata = DB()->fetch_row($sql);
183
184	$user_status = isset($bt_userdata['user_status']) ? $bt_userdata['user_status'] : null;
185
186	if (($min_ratio_dl || $min_ratio_warn) && $user_status != DL_STATUS_COMPLETE && $bt_user_id != $poster_id && $tor_type != TOR_TYPE_GOLD)
187	{
188		if (($user_ratio = get_bt_ratio($bt_userdata)) !== null)
189		{
190			$dl_allowed = ($user_ratio > $min_ratio_dl);
191		}
192
193		if ((isset($user_ratio) && isset($min_ratio_warn) && $user_ratio < $min_ratio_warn && TR_RATING_LIMITS) || ($bt_userdata['u_down_total'] < MIN_DL_FOR_RATIO))
194		{
195			$template->assign_vars(array(
196				'SHOW_RATIO_WARN'  => true,
197				'RATIO_WARN_MSG'   => sprintf($lang['BT_RATIO_WARNING_MSG'], $min_ratio_dl, $bb_cfg['ratio_url_help']),
198			));
199		}
200	}
201
202	if (!$dl_allowed)
203	{
204		$template->assign_block_vars('postrow.attach.tor_reged', array());
205		$template->assign_vars(array(
206			'TOR_BLOCKED'     => true,
207			'TOR_BLOCKED_MSG' => sprintf($lang['BT_LOW_RATIO_FOR_DL'], round($user_ratio, 2), "search.php?dlu=$bt_user_id&amp;dlc=1"),
208		));
209	}
210	else
211	{
212		$template->assign_block_vars('postrow.attach.tor_reged', array(
213			'DOWNLOAD_NAME'   => $display_name,
214			'TRACKER_LINK'    => $tracker_link,
215			'ATTACH_ID'       => $attach_id,
216			'TOR_SILVER_GOLD' => $tor_type,
217
218			// torrent status mod
219			'TOR_FROZEN'      => (!IS_AM) ? (isset($bb_cfg['tor_frozen'][$tor_info['tor_status']]) && !(isset($bb_cfg['tor_frozen_author_download'][$tor_info['tor_status']]) && $userdata['user_id'] == $tor_info['poster_id'])) ? true : '' : '',
220			'TOR_STATUS_TEXT' => $lang['TOR_STATUS_NAME'][$tor_info['tor_status']],
221			'TOR_STATUS_ICON' => $bb_cfg['tor_icons'][$tor_info['tor_status']],
222			'TOR_STATUS_BY'   => ($tor_info['checked_user_id'] && $is_auth['auth_mod']) ? ('<span title="'. bb_date($tor_info['checked_time'], 'd-M-Y H:i') .'"> &middot; '. profile_url($tor_info) .' &middot; <i>'. delta_time($tor_info['checked_time']) . $lang['TOR_BACK'] .'</i></span>') : '',
223			'TOR_STATUS_SELECT' => build_select('sel_status', array_flip($lang['TOR_STATUS_NAME']), TOR_APPROVED),
224			'TOR_STATUS_REPLY' => $bb_cfg['tor_comment'] && !IS_GUEST && in_array($tor_info['tor_status'], $bb_cfg['tor_reply']) && $userdata['user_id'] == $tor_info['poster_id'] && $t_data['topic_status'] != TOPIC_LOCKED,
225			//end torrent status mod
226
227			'S_UPLOAD_IMAGE'  => $upload_image,
228			'U_DOWNLOAD_LINK' => $download_link,
229			'DL_LINK_CLASS'   => (isset($bt_userdata['user_status'])) ? $dl_link_css[$bt_userdata['user_status']] : 'genmed',
230			'DL_TITLE_CLASS'  => (isset($bt_userdata['user_status'])) ? $dl_status_css[$bt_userdata['user_status']] : 'gen',
231			'FILESIZE'        => $tor_file_size,
232			'MAGNET'          => $tor_magnet,
233			'DOWNLOAD_COUNT'  => sprintf($lang['DOWNLOAD_NUMBER'], $download_count),
234			'REGED_TIME'      => bb_date($tor_info['reg_time']),
235			'REGED_DELTA'     => delta_time($tor_info['reg_time']),
236			'TORRENT_SIZE'    => humn_size($tor_size),
237			'COMPLETED'       => sprintf($lang['DOWNLOAD_NUMBER'], $tor_info['complete_count']),
238		));
239
240		if ($comment)
241		{
242			$template->assign_block_vars('postrow.attach.tor_reged.comment', array('COMMENT' => $comment));
243		}
244	}
245
246	if ($bb_cfg['show_tor_info_in_dl_list'])
247	{
248		$template->assign_vars(array(
249			'SHOW_DL_LIST'          => true,
250			'SHOW_DL_LIST_TOR_INFO' => true,
251
252			'TOR_SIZE'      => humn_size($tor_size),
253			'TOR_LONGEVITY' => delta_time($tor_info['reg_time']),
254			'TOR_COMPLETED' => declension($tor_info['complete_count'], 'times'),
255		));
256	}
257
258	// Show peers
259	if ($show_peers)
260	{
261		// Sorting order in full mode
262		if ($s_mode == 'full')
263		{
264			$full_mode_order = 'tr.remain';
265			$full_mode_sort_dir = 'ASC';
266
267			if (isset($_REQUEST['psortasc']))
268			{
269				$full_mode_sort_dir = 'ASC';
270			}
271			else if (isset($_REQUEST['psortdesc']))
272			{
273				$full_mode_sort_dir = 'DESC';
274			}
275
276			if (isset($_REQUEST['porder']))
277			{
278				$peer_orders = array(
279					'name'  => 'u.username',
280					'ip'    => 'tr.ip',
281					'port'  => 'tr.port',
282					'compl' => 'tr.remain',
283					'cup'   => 'tr.uploaded',
284					'cdown' => 'tr.downloaded',
285					'sup'   => 'tr.speed_up',
286					'sdown' => 'tr.speed_down',
287					'time'  => 'tr.update_time',
288				);
289
290				foreach ($peer_orders as $get_key => $order_by_value)
291				{
292					if ($_REQUEST['porder'] == $get_key)
293					{
294						$full_mode_order = $order_by_value;
295						break;
296					}
297				}
298			}
299		}
300		// SQL for each mode
301		if ($s_mode == 'count')
302		{
303			$sql = "SELECT seeders, leechers, speed_up, speed_down
304				FROM ". BB_BT_TRACKER_SNAP ."
305				WHERE topic_id = $tor_id
306				LIMIT 1";
307		}
308		else if ($s_mode == 'names')
309		{
310			$sql = "SELECT tr.user_id, tr.ip, tr.port, tr.remain, tr.seeder, u.username, u.user_rank
311				FROM ". BB_BT_TRACKER ." tr, ". BB_USERS ." u
312				WHERE tr.topic_id = $tor_id
313					AND u.user_id = tr.user_id
314				GROUP BY tr.ip, tr.user_id, tr.port, tr.seeder
315				ORDER BY u.username
316				LIMIT $show_peers_limit";
317		}
318		else
319		{
320			$sql = "SELECT
321					tr.user_id, tr.ip, tr.port, tr.uploaded, tr.downloaded, tr.remain,
322					tr.seeder, tr.releaser, tr.speed_up, tr.speed_down, tr.update_time,
323					tr.complete_percent, u.username, u.user_rank
324				FROM ". BB_BT_TRACKER ." tr
325				LEFT JOIN ". BB_USERS ." u ON u.user_id = tr.user_id
326				WHERE tr.topic_id = $tor_id
327				GROUP BY tr.ip, tr.user_id, tr.port, tr.seeder
328				ORDER BY $full_mode_order $full_mode_sort_dir
329				LIMIT $show_peers_limit";
330		}
331
332		// Build peers table
333		if ($peers = DB()->fetch_rowset($sql))
334		{
335			$peers_cnt = count($peers);
336
337			$cnt = $tr = $sp_up = $sp_down = $sp_up_tot = $sp_down_tot = array();
338			$cnt['s'] = $tr['s'] = $sp_up['s'] = $sp_down['s'] = $sp_up_tot['s'] = $sp_down_tot['s'] = 0;
339			$cnt['l'] = $tr['l'] = $sp_up['l'] = $sp_down['l'] = $sp_up_tot['l'] = $sp_down_tot['l'] = 0;
340
341			$max_up = $max_down = $max_sp_up = $max_sp_down = array();
342			$max_up['s'] = $max_down['s'] = $max_sp_up['s'] = $max_sp_down['s'] = 0;
343			$max_up['l'] = $max_down['l'] = $max_sp_up['l'] = $max_sp_down['l'] = 0;
344			$max_up_id['s'] = $max_down_id['s'] = $max_sp_up_id['s'] = $max_sp_down_id['s'] = ($peers_cnt + 1);
345			$max_up_id['l'] = $max_down_id['l'] = $max_sp_up_id['l'] = $max_sp_down_id['l'] = ($peers_cnt + 1);
346
347			if ($s_mode == 'full')
348			{
349				foreach ($peers as $pid => $peer)
350				{
351					$x = ($peer['seeder']) ? 's' : 'l';
352					$cnt[$x]++;
353					$sp_up_tot[$x] += $peer['speed_up'];
354					$sp_down_tot[$x] += $peer['speed_down'];
355
356					$guest      = ($peer['user_id'] == GUEST_UID || is_null($peer['username']));
357					$p_max_up   = $peer['uploaded'];
358					$p_max_down = $peer['downloaded'];
359
360					if ($p_max_up > $max_up[$x])
361					{
362						$max_up[$x]	= $p_max_up;
363						$max_up_id[$x] = $pid;
364					}
365					if ($peer['speed_up'] > $max_sp_up[$x])
366					{
367						$max_sp_up[$x] = $peer['speed_up'];
368						$max_sp_up_id[$x] = $pid;
369					}
370					if ($p_max_down > $max_down[$x])
371					{
372						$max_down[$x] = $p_max_down;
373						$max_down_id[$x] = $pid;
374					}
375					if ($peer['speed_down'] > $max_sp_down[$x])
376					{
377						$max_sp_down[$x] = $peer['speed_down'];
378						$max_sp_down_id[$x] = $pid;
379					}
380				}
381				$max_down_id['s'] = $max_sp_down_id['s'] = ($peers_cnt + 1);
382
383				if ($cnt['s'] == 1)
384				{
385					$max_up_id['s'] = $max_sp_up_id['s'] = ($peers_cnt + 1);
386				}
387				if ($cnt['l'] == 1)
388				{
389					$max_up_id['l'] = $max_down_id['l'] = $max_sp_up_id['l'] = $max_sp_down_id['l'] = ($peers_cnt + 1);
390				}
391			}
392
393			if ($s_mode == 'count')
394			{
395				$tmp = array();
396				$tmp[0]['seeder'] = $tmp[0]['username'] = $tmp[1]['username'] = 0;
397				$tmp[1]['seeder'] = 1;
398				$tmp[0]['username'] = (int) @$peers[0]['leechers'];
399				$tmp[1]['username'] = (int) @$peers[0]['seeders'];
400				$tor_speed_up       = (int) @$peers[0]['speed_up'];
401				$tor_speed_down     = (int) @$peers[0]['speed_down'];
402				$peers = $tmp;
403
404				$template->assign_vars(array(
405					'TOR_SPEED_UP'   => ($tor_speed_up)   ? humn_size($tor_speed_up, 0, 'KB') .'/s' : '0 KB/s',
406					'TOR_SPEED_DOWN' => ($tor_speed_down) ? humn_size($tor_speed_down, 0, 'KB') .'/s' : '0 KB/s',
407				));
408			}
409
410			foreach ($peers as $pid => $peer)
411			{
412				$u_prof_href = ($s_mode == 'count') ? '#' : "profile.php?mode=viewprofile&amp;u=". $peer['user_id'] ."#torrent";
413
414				// Full details mode
415				if ($s_mode == 'full')
416				{
417					$ip    = bt_show_ip($peer['ip']);
418					$port  = bt_show_port($peer['port']);
419
420					// peer max/current up/down
421					$p_max_up   = $peer['uploaded'];
422					$p_max_down = $peer['downloaded'];
423					$p_cur_up   = $peer['uploaded'];
424					$p_cur_down = $peer['downloaded'];
425
426					if ($peer['seeder'])
427					{
428						$x = 's';
429						$x_row = 'srow';
430						$x_full = 'sfull';
431
432						if (!defined('SEEDER_EXIST'))
433						{
434							define('SEEDER_EXIST', true);
435							$seed_order_action = "viewtopic.php?". POST_TOPIC_URL ."=$bt_topic_id&amp;spmode=full#seeders";
436
437							$template->assign_block_vars("$x_full", array(
438								'SEED_ORD_ACT'   => $seed_order_action,
439								'SEEDERS_UP_TOT' => humn_size($sp_up_tot[$x], 0, 'KB') .'/s'
440							));
441
442							if ($ip)
443							{
444								$template->assign_block_vars("$x_full.iphead", array());
445							}
446							if ($port !== false)
447							{
448								$template->assign_block_vars("$x_full.porthead", array());
449							}
450						}
451						$compl_perc = ($tor_size) ? round(($p_max_up / $tor_size), 1) : 0;
452					}
453					else
454					{
455						$x = 'l';
456						$x_row = 'lrow';
457						$x_full = 'lfull';
458
459						if (!defined('LEECHER_EXIST'))
460						{
461							define('LEECHER_EXIST', true);
462							$leech_order_action = "viewtopic.php?". POST_TOPIC_URL ."=$bt_topic_id&amp;spmode=full#leechers";
463
464							$template->assign_block_vars("$x_full", array(
465								'LEECH_ORD_ACT'     => $leech_order_action,
466								'LEECHERS_UP_TOT'   => humn_size($sp_up_tot[$x], 0, 'KB') .'/s',
467								'LEECHERS_DOWN_TOT' => humn_size($sp_down_tot[$x], 0, 'KB') .'/s'
468							));
469
470							if ($ip)
471							{
472								$template->assign_block_vars("$x_full.iphead", array());
473							}
474							if ($port !== false)
475							{
476								$template->assign_block_vars("$x_full.porthead", array());
477							}
478						}
479						$compl_size = ($peer['remain'] && $tor_size && $tor_size > $peer['remain']) ? ($tor_size - $peer['remain']) : 0;
480						$compl_perc = ($compl_size) ? floor($compl_size * 100 / $tor_size) : 0;
481					}
482
483					$rel_sign = (!$guest && $peer['releaser']) ? '&nbsp;<b><sup>&reg;</sup></b>' : '';
484					$name     = profile_url($peer). $rel_sign;
485					$up_tot   = ($p_max_up)   ? humn_size($p_max_up)   : '-';
486					$down_tot = ($p_max_down) ? humn_size($p_max_down) : '-';
487					$up_ratio = ($p_max_down) ? round(($p_max_up / $p_max_down), 2) : '';
488					$sp_up    = ($peer['speed_up'])   ? humn_size($peer['speed_up'],   0, 'KB') .'/s' : '-';
489					$sp_down  = ($peer['speed_down']) ? humn_size($peer['speed_down'], 0, 'KB') .'/s' : '-';
490
491					$bgr_class = (!($tr[$x] % 2)) ? $bgr_class_1 : $bgr_class_2;
492					$row_bgr   = ($change_peers_bgr_over) ? " class=\"$bgr_class\" onmouseover=\"this.className='$bgr_class_over';\" onmouseout=\"this.className='$bgr_class';\"" : '';
493					$tr[$x]++;
494
495					$template->assign_block_vars("$x_full.$x_row", array(
496						'ROW_BGR'        => $row_bgr,
497						'NAME'           => ($peer['update_time']) ? $name : "<s>$name</s>",
498						'COMPL_PRC'      => $compl_perc,
499						'UP_TOTAL'       => ($max_up_id[$x] == $pid)      ? "<b>$up_tot</b>"   : $up_tot,
500						'DOWN_TOTAL'     => ($max_down_id[$x] == $pid)    ? "<b>$down_tot</b>" : $down_tot,
501						'SPEED_UP'       => ($max_sp_up_id[$x] == $pid)   ? "<b>$sp_up</b>"    : $sp_up,
502						'SPEED_DOWN'     => ($max_sp_down_id[$x] == $pid) ? "<b>$sp_down</b>"  : $sp_down,
503						'UP_TOTAL_RAW'   => $peer['uploaded'],
504						'DOWN_TOTAL_RAW' => $peer['downloaded'],
505						'SPEED_UP_RAW'   => $peer['speed_up'],
506						'SPEED_DOWN_RAW' => $peer['speed_down'],
507						'UPD_EXP_TIME'   => ($peer['update_time']) ? $lang['DL_UPD'] . bb_date($peer['update_time'], 'd-M-y H:i') .' &middot; '. delta_time($peer['update_time']) . $lang['TOR_BACK']  : $lang['DL_STOPPED'],
508						'TOR_RATIO'      => ($up_ratio) ? $lang['USER_RATIO'] . "UL/DL: $up_ratio" : '',
509					));
510
511					if ($ip)
512					{
513						$template->assign_block_vars("$x_full.$x_row.ip", array('IP' => $ip));
514					}
515					if ($port !== false)
516					{
517						$template->assign_block_vars("$x_full.$x_row.port", array('PORT' => $port));
518					}
519				}
520				// Count only & only names modes
521				else
522				{
523					if ($peer['seeder'])
524					{
525						$seeders .= '<nobr><a href="'. $u_prof_href .'" class="seedmed">'. $peer['username'] .'</a>,</nobr> ';
526						$seed_count = $peer['username'];
527					}
528					else
529					{
530						$compl_size = (@$peer['remain'] && $tor_size && $tor_size > $peer['remain']) ? ($tor_size - $peer['remain']) : 0;
531						$compl_perc = ($compl_size) ? floor($compl_size * 100 / $tor_size) : 0;
532
533						$leechers .= '<nobr><a href="'. $u_prof_href .'" class="leechmed">'. $peer['username'] .'</a>';
534						$leechers .= ($s_mode == 'names') ? ' ['. $compl_perc .'%]' : '';
535						$leechers .= ',</nobr> ';
536						$leech_count = $peer['username'];
537					}
538				}
539			}
540
541			if ($s_mode != 'full' && $seeders)
542			{
543				$seeders[strlen($seeders)-9] = ' ';
544				$template->assign_vars(array(
545					'SEED_LIST'  => $seeders,
546					'SEED_COUNT' => ($seed_count) ? $seed_count : 0,
547				));
548			}
549			if ($s_mode != 'full' && $leechers)
550			{
551				$leechers[strlen($leechers)-9] = ' ';
552				$template->assign_vars(array(
553					'LEECH_LIST'  => $leechers,
554					'LEECH_COUNT' => ($leech_count) ? $leech_count : 0,
555				));
556			}
557		}
558		unset($peers);
559
560		// Show "seeder last seen info"
561		if (($s_mode == 'count' && !$seed_count) || (!$seeders && !defined('SEEDER_EXIST')))
562		{
563			$last_seen_time = ($tor_info['seeder_last_seen']) ? delta_time($tor_info['seeder_last_seen']) : $lang['NEVER'];
564
565			$template->assign_vars(array(
566				'SEEDER_LAST_SEEN' => sprintf($lang['SEEDER_LAST_SEEN'], $last_seen_time),
567			));
568		}
569	}
570
571	$template->assign_block_vars('tor_title', array('U_DOWNLOAD_LINK' => $download_link));
572
573	if ($peers_cnt > $max_peers_before_overflow && $s_mode == 'full')
574	{
575		$template->assign_vars(array('PEERS_DIV_STYLE' => $peers_div_style_overflow));
576		$template->assign_vars(array('PEERS_OVERFLOW' => true));
577	}
578	else
579	{
580		$template->assign_vars(array('PEERS_DIV_STYLE' => $peers_div_style_normal));
581	}
582}
583
584if ($bb_cfg['bt_allow_spmode_change'] && $s_mode != 'full')
585{
586	$template->assign_vars(array(
587		'PEERS_FULL_LINK'  => true,
588		'SPMODE_FULL_HREF' => "viewtopic.php?". POST_TOPIC_URL ."=$bt_topic_id&amp;spmode=full#seeders",
589	));
590}
591
592$template->assign_vars(array(
593	'SHOW_DL_LIST_LINK' => (($bb_cfg['bt_show_dl_list'] || $bb_cfg['allow_dl_list_names_mode']) && $t_data['topic_dl_type'] == TOPIC_DL_TYPE_DL),
594	'SHOW_TOR_ACT'      => ($tor_reged && $show_peers && (!isset($bb_cfg['tor_no_tor_act'][$tor_info['tor_status']]) || IS_AM)),
595	'S_MODE_COUNT'      => ($s_mode == 'count'),
596	'S_MODE_NAMES'      => ($s_mode == 'names'),
597	'S_MODE_FULL'       => ($s_mode == 'full'),
598	'PEER_EXIST'        => ($seeders || $leechers || defined('SEEDER_EXIST') || defined('LEECHER_EXIST')),
599	'SEED_EXIST'        => ($seeders || defined('SEEDER_EXIST')),
600	'LEECH_EXIST'       => ($leechers || defined('LEECHER_EXIST')),
601	'TOR_HELP_LINKS'    => $bb_cfg['tor_help_links'],
602	'CALL_SEED'         => ($bb_cfg['callseed'] && $tor_reged && !isset($bb_cfg['tor_no_tor_act'][$tor_info['tor_status']])),
603));