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