/**
 *
 *  
 *
 **/
 
#
##---[SQL]----------
#

ALTER TABLE `bb_bt_torrents` ADD `ttube_hash` VARCHAR( 255 ) NOT NULL;
INSERT INTO `bb_config` (`config_name`, `config_value`) VALUES
('tt_api', '81a81abced52283c830e7688f08c267e'),
('tt_height', '350'),
('tt_type', '1'),
('tt_width', '640'),
('tt_zone', '787');

ALTER TABLE `bb_forums` ADD `tt_view` TINYINT( 1 ) NOT NULL DEFAULT '0';

#
##---[OPEN]----------
#
templates/admin/admin_board.tpl

#
##---[FIND]----------
#
	<td><h4>{L_BIRTHDAY_CHECK_DAY}</h4></td>
	<td><input class="post" type="text" size="25" maxlength="100" name="birthday_check_day" value="{BIRTHDAY_CHECK_DAY}" />&nbsp;{L_DAYS}</td>
</tr>

#
##---[AFTER ADD]----------
#
<tr class="row3 med">
	<td class="bold tCenter" colspan="2">{L_TTUBE_FUNCTION}</td>
</tr>
<tr>
	<td><h4>{L_TTUBE_ZONE}</h4></td>
	<td><input class="post" type="text" size="25" maxlength="100" name="tt_zone" value="{TT_ZONE}" /></td>
</tr>
<tr>
	<td><h4>{L_TTUBE_API}</h4></td>
	<td><input class="post" type="text" size="35" maxlength="100" name="tt_api" value="{TT_API}" /></td>
</tr>
<tr>
	<td><h4>{L_TTUBE_OPEN_TYPE}</h4></td>
	<td>
    	<select name="tt_type">
        	<option value="1" {TT_POPUP}>Pretty Photo, PopUp</option>
            <option value="2" {TT_BLANK}>BLANK PAGE</option>
            <option value="3" {TT_FRAME}>IFRAME</option>
        </select>
    </td>
</tr>
<tr>
	<td><h4>{L_TTUBE_WIDTH}</h4></td>
	<td><input class="post" type="text" size="25" maxlength="100" name="tt_width" value="{TT_WIDTH}" /></td>
</tr>

<tr>
	<td><h4>{L_TTUBE_HEIGHT}</h4></td>
	<td><input class="post" type="text" size="25" maxlength="100" name="tt_height" value="{TT_HEIGHT}" /></td>
</tr>

#
##---[OPEN]----------
#
admin_forums.tpl

#
##---[FIND]----------
#
            <select name="forum_display_sort">{S_FORUM_DISPLAY_SORT_LIST}</select>&nbsp;
            <select name="forum_display_order">{S_FORUM_DISPLAY_ORDER_LIST}</select>&nbsp;
        </td>
    </tr>
    
#
##---[AFTER ADD]----------
#
    <tr>
        <td class="row1">{L_TTUBE_FUNCTION}</td>
        <td class="row2">
            <select name="tt_view">
                <option value="1"<!-- IF TT_VIEW --> selected="selected"<!-- ENDIF -->>{L_TTUBE_ENABLE}</option>
                <option value="0"<!-- IF not TT_VIEW --> selected="selected"<!-- ENDIF -->>{L_TTUBE_DISABLE}</option>
            </select>
        </td>
    </tr>

#
##---[OPEN]----------
#

templates/dafault/viewtopic_attach.tpl	Modified

#
##---[FIND]----------
#
            <p><a href="{postrow.attach.tor_reged.U_DOWNLOAD_LINK}"><!-- IF MAGNET_LINKS -->{postrow.attach.tor_reged.MAGNET}<!-- ELSE -->{postrow.attach.tor_reged.S_UPLOAD_IMAGE}<!-- ENDIF --></a></p>
            
#
##---[REPLACE ADD]----------
#

            <!-- IF FORUM_PLAY -->
            <!-- IF TS_POPUP --><a href="player.php?id={postrow.attach.tor_reged.ATTACH_ID}&amp;frame=1&amp;iframe=true&amp;width={TS_WIDTH_P}&amp;height={TS_HEIGHT_P}" rel="prettyPhoto[iframes]"  title="<b>{L_TT_ONLINE_VIEW}:</b> {TS_TOPIC_TITLE}"><img src="images/ts_view.png" alt="{L_TT_ONLINE_VIEW}" width="48" title="{L_TT_ONLINE_VIEW}" /></a><br /><!-- ENDIF -->
            <!-- IF TS_BLANK --><strong><a href="player.php?id={postrow.attach.tor_reged.ATTACH_ID}" title="{L_TT_ONLINE_VIEW}" target="_blank">{L_TT_ONLINE_VIEW}</a></strong><br /><!-- ENDIF -->
			<!-- ELSE -->
            <p><a href="{postrow.attach.tor_reged.U_DOWNLOAD_LINK}"><!-- IF MAGNET_LINKS -->{postrow.attach.tor_reged.MAGNET}<!-- ELSE -->{postrow.attach.tor_reged.S_UPLOAD_IMAGE}<!-- ENDIF --></a></p>
			<!-- ENDIF -->
        
#
##---[FIND]----------
#
<!-- ENDIF -->
<!-- END tor_reged -->

#
##---[BEFORE ADD]----------
#

<!-- IF TS_FRAME --><center><iframe src="player.php?id={postrow.attach.tor_reged.ATTACH_ID}&amp;frame=1" width="{TS_WIDTH}" height="{TS_HEIGHT}" frameborder="1" marginwidth="0" marginheight="0" scrolling="no"></iframe></center><!-- ENDIF -->

#
##---[OPEN]----------
#

templates/dafault/page_header.tpl	Modified

#
##---[ADD]----------
#

<link rel="stylesheet" href="{SITE_URL}misc/js/prettyphoto/css/prettyPhoto.css" type="text/css" media="screen" title="prettyPhoto main stylesheet" charset="utf-8" />
<script src="{SITE_URL}misc/js/prettyphoto/js/jquery.prettyPhoto.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'fast',slideshow:10000});
});
</script>

#
##---[OPEN]----------
#
includes/functions_torrent.php

#
##---[FIND]----------
#
function send_torrent_with_passkey ($filename)

#
##---[BEFORE ADD]----------
#
/**
 * TorrentTUBE
 */
function return_torrent_with_passkey ($filename)
{
	global $attachment, $auth_pages, $userdata, $bb_cfg, $lang;

	if (!$bb_cfg['bt_add_auth_key'] || $attachment['extension'] !== TORRENT_EXT || !$size = @filesize($filename))
	{
		return;
	}

	$post_id = $poster_id = $passkey_val = '';
	$user_id = $userdata['user_id'];
	$attach_id = $attachment['attach_id'];

	if (!$passkey_key = $bb_cfg['passkey_key'])
	{
		message_die(GENERAL_ERROR, 'Could not add passkey (wrong config $bb_cfg[\'passkey_key\'])');
	}

	// Get $post_id & $poster_id
	foreach ($auth_pages as $rid => $row)
	{
		if ($row['attach_id'] == $attach_id)
		{
			$post_id = $row['post_id'];
			$poster_id = $row['user_id_1'];
			break;
		}
	}

	// Redirect guests to login page
	if (IS_GUEST)
	{
		$redirect_url = ($post_id) ? POST_URL . $post_id : 'index.php';
		redirect(LOGIN_URL . $redirect_url);
	}

	if (!$attachment['tracker_status']) message_die(GENERAL_ERROR, $lang['PASSKEY_ERR_TOR_NOT_REG']);
	if ($bt_userdata = get_bt_userdata($user_id)) $passkey_val = $bt_userdata['auth_key'];

	if (!$passkey_val && $userdata['session_logged_in'])
	{
		if ($bb_cfg['bt_gen_passkey_on_reg'])
		{
			if (!$passkey_val = generate_passkey($new_user_id))
			{
				message_die(GENERAL_ERROR, 'Could not insert passkey', '', __LINE__, __FILE__, $sql);
			}
		}
		else
		{
			$mess = sprintf($lang['PASSKEY_ERR_EMPTY'], 'profile.php?mode=editprofile#bittorrent');
			message_die(GENERAL_ERROR, $mess);
		}
	}

	// Ratio limits
	$min_ratio = $bb_cfg['bt_min_ratio_allow_dl_tor'];

	if ($min_ratio && $user_id != $poster_id && ($user_ratio = get_bt_ratio($bt_userdata)) !== null)
	{
		if ($user_ratio < $min_ratio && $post_id)
		{
			$dl = DB()->fetch_row("
				SELECT dl.user_status
				FROM ". BB_POSTS ." p
				LEFT JOIN ". BB_BT_DLSTATUS ." dl ON dl.topic_id = p.topic_id AND dl.user_id = $user_id
				WHERE p.post_id = $post_id
				LIMIT 1
			");

			if (!isset($dl['user_status']) || $dl['user_status'] != DL_STATUS_COMPLETE)
			{
				$mess = sprintf($lang['BT_LOW_RATIO_FOR_DL'], round($user_ratio, 2), "search.php?dlu=$user_id&amp;dlc=1");
				message_die(GENERAL_ERROR, $mess);
			}
		}
	}

	// Seeding torrents limit
	if ($bb_cfg['max_seeding_torrents'] && IS_USER)
	{
		$seeding = DB()->fetch_row("
			SELECT COUNT(DISTINCT topic_id) AS torrents, SUM(speed_up) AS sum_up
			FROM ". BB_BT_TRACKER ."
			WHERE user_id = $user_id
				AND seeder = 1
		");

		if ($seeding && $seeding['torrents'] > $bb_cfg['max_seeding_torrents'] && $bt_userdata['u_up_total'] < 200*1024*1024*1024)
		{
			if ($seeding['sum_up'] < ($seeding['torrents'] * $bb_cfg['min_up_speed_per_torrent']))
			{
				$msg = array();
				$msg[] = date('m-d H:i:s');
				$msg[] = sprintf('%-30s', html_entity_decode($userdata['username'])." ($user_id)");
				$msg[] = sprintf('%-3s', $seeding['torrents']);
				$msg[] = sprintf('%.2f', @$user_ratio);
				$msg[] = sprintf('%-9s', humn_size($bt_userdata['u_up_total'], '', '', ' '));
				$msg[] = humn_size($seeding['sum_up'], '', '', ' ');
				$msg = join(LOG_SEPR, $msg) . LOG_LF;
				bb_log($msg, 'overseed/current');

				redirect($bb_cfg['too_many_seeding_redirect_url']);
			}
		}
	}

	// Announce URL
	$ann_url = $bb_cfg['bt_announce_url'];

	if (!$tor = bdecode_file($filename))
	{
		message_die(GENERAL_ERROR, 'This is not a bencoded file');
	}

	$passkey_url = (!$userdata['session_logged_in'] || isset($_GET['no_passkey'])) ? '' : "?$passkey_key=$passkey_val";

	// Replace original announce url with tracker default
	if ($bb_cfg['bt_replace_ann_url'] || !@$tor['announce'])
	{
		$announce = strval($ann_url . "?$passkey_key=$passkey_val");
	}

	// Delete all additional urls
	if ($bb_cfg['bt_del_addit_ann_urls'])
	{
		unset($tor['announce-list']);
	}

	// Add publisher & topic url
	$publisher = $bb_cfg['bt_add_publisher'];
	$publisher_url = ($post_id) ? make_url(POST_URL . $post_id) : '';

	if ($publisher)
	{
		$tor['publisher'] = strval($publisher);
		unset($tor['publisher.utf-8']);

		if ($publisher_url)
		{
			$tor['publisher-url'] = strval($publisher_url);
			unset($tor['publisher-url.utf-8']);
		}
	}

	// Add comment
	$comment = '';

	$orig_com = (@$tor['comment']) ? $tor['comment'] : '';

	if ($bb_cfg['bt_add_comment'])
	{
		$comment = $bb_cfg['bt_add_comment'];
	}
	else
	{
		$comment = ($publisher_url) ? $publisher_url : '';
	}

	if ($comment = trim($comment))
	{
		$tor['comment'] = strval($comment);
		unset($tor['comment.utf-8']);
	}

	//Azureus DHT disable
	$tor['azureus_properties'] = array('dht_backup_enable' => intval(0));

	// Send torrent
	$output   = bencode($tor);
	$filename = clean_filename(basename($attachment['real_filename']));
	$mimetype = 'application/x-bittorrent;';
	$charset  = (strpos(USER_AGENT, 'pera') && @$lang['CONTENT_ENCODING']) ? "charset={$lang['CONTENT_ENCODING']};" : '';

	return $output;
}


#
##---[OPEN]----------
#
language/lang_russian/lang_admin.php	Modified

#
##---[FIND]----------
#
$lang['REPORTS'] = '';
//
// Reports [END]
//

#
##---[AFTER ADD]----------
#


$lang['TTUBE_FUNCTION'] = "  ";
$lang['TTUBE_ENABLE'] = "";
$lang['TTUBE_DISABLE'] = "";
$lang['TTUBE_ZONE'] = " ";
$lang['TTUBE_API'] = "  API TorrentStream";
$lang['TTUBE_OPEN_TYPE'] = " ";
$lang['TTUBE_WIDTH'] = ' ';
$lang['TTUBE_HEIGHT'] = ' ';

#
##---[OPEN]----------
#
language/lang_russian/lang_main.php


#
##---[ADD]----------
#

// TT
$lang['TT_ONLINE_VIEW'] = ' ';

#
##---[OPEN]----------
#
viewtopic.php	Modified

#
##---[FIND]----------
#
	'U_SEARCH_SELF'       => "search.php?uid={$userdata['user_id']}&t=$topic_id&dm=1",
	
#
##---[AFTER ADD]----------
#

	'FORUM_PLAY' => (!$bb_cfg['tt_api'] || !$bb_cfg['tt_zone']) ? false : ($forum_topic_data['tt_view'] ? true : false),
	'TS_WIDTH' => ($bb_cfg['tt_width'])?$bb_cfg['tt_width']:650,
	'TS_HEIGHT' => ($bb_cfg['tt_height'])?$bb_cfg['tt_height']:352,
	'TS_WIDTH_P' => ($bb_cfg['tt_width'])?$bb_cfg['tt_width']+20:670,
	'TS_HEIGHT_P' => ($bb_cfg['tt_height'])?$bb_cfg['tt_height']+20:372,
	'TS_TOPIC_TITLE' => str_replace("\"", "'", wbr($topic_title)),
	'TS_POPUP'		  => ($bb_cfg['tt_type'] == 1)?true:false,
	'TS_BLANK'		  => ($bb_cfg['tt_type'] == 2)?true:false,
	'TS_FRAME'		  => ($bb_cfg['tt_type'] == 3)?true:false,

#
##---[OPEN]----------
#
admin/admin_board.php	Modified


#
##---[FIND]----------
#
	'NEW_TPLS'     => $new['new_tpls'],
	
#
##---[ADD]----------
#
	'TT_ZONE' => $new['tt_zone'],
	'TT_API' => $new['tt_api'],
	'TT_POPUP' => ($new['tt_type'] == 1) ? 'selected="selected"' : '',
	'TT_BLANK' => ($new['tt_type'] == 2) ? 'selected="selected"' : '',
	'TT_FRAME' => ($new['tt_type'] == 3) ? 'selected="selected"' : '',
	'TT_WIDTH' => $new['tt_width'],
	'TT_HEIGHT' => $new['tt_height'],
	
#
##---[OPEN]----------
#
admin/admin_forums.php

#
##---[FIND]----------
#
				$prune_enabled = ($row['prune_days']) ? HTML_CHECKED : '';
				$prune_days = $row['prune_days'];
				
#
##---[AFTER ADD]----------
#
				
				$tt_view = $row['tt_view'];
				
#
##---[FIND]----------
#
				$prune_enabled = '';
				$prune_days = 0;
				
#
##---[AFTER ADD]----------
#
				
				$tt_view = 0;
				
#
##---[FIND]----------
#
				'DESCRIPTION' => htmlCHR($forumdesc),
				
#
##---[AFTER ADD]----------
#
			
				'TT_VIEW' => $tt_view,
				
#
##---[FIND]----------
#
			$forum_display_order = intval($_POST['forum_display_order']);
			
#
##---[AFTER ADD]----------
#
			$tt_view = (int) $_POST['tt_view'];
			
#
##---[FIND]----------
#
			$columns = ' forum_name,   cat_id,   forum_desc,   forum_order,  forum_status,  prune_days,  forum_parent,  show_on_index,  forum_display_sort,  forum_display_order'. $field_sql;
			$values = "'$forum_name', $cat_id, '$forum_desc', $forum_order, $forum_status, $prune_days, $forum_parent, $show_on_index, $forum_display_sort, $forum_display_order". $value_sql;
			
#
##---[REPLACE]----------
#
			$columns = ' forum_name,   cat_id,   forum_desc,   forum_order,  forum_status,  prune_days,  forum_parent,  show_on_index,  forum_display_sort,  forum_display_order, tt_view'. $field_sql;
			$values = "'$forum_name', $cat_id, '$forum_desc', $forum_order, $forum_status, $prune_days, $forum_parent, $show_on_index, $forum_display_sort, $forum_display_order, $tt_view". $value_sql;
			
#
##---[FIND]----------
#
			$old_cat_id = $forum_data['cat_id'];
			$forum_order = $forum_data['forum_order'];

#
##---[AFTER ADD]----------
#
			
			$tt_view = (int) $_POST['tt_view'];
			
#
##---[FIND]----------
#
					forum_display_sort  = $forum_display_sort
					
#
##---[REPLACE]----------
#
					forum_display_sort  = $forum_display_sort,
					tt_view = $tt_view

#
##---[OPEN]----------
#

admin/admin_bt_forum_cfg.php

#
##---[FIND]----------
#

'allow_porno_topic'            => 0,  // Allowed forums for porno topics

#
##---[AFTER ADD]----------
#

'tt_view'                      => 0,  // online video

#
##---[OPEN]----------
#

admin_bt_forum_cfg.tpl

#
##---[FIND]----------
#

<th colspan="3">{L_BT_SELECT_FORUMS}</th>

#
##---[REPLACE]----------
#

<th colspan="4">{L_BT_SELECT_FORUMS}</th>

#
##---[FIND]----------
#

<td>{L_ALLOW_PORNO_TOPIC}</td>

#
##---[AFTER ADD]----------
#

<td>Online Video</td>

#
##---[FIND]----------
#

<td>{S_ALLOW_PORNO_TOPIC}</td>

#
##---[AFTER ADD]----------
#

<td>{S_TT_VIEW}</td>

#
##---[FIND]----------
#

<td colspan="3" class="small">{L_BT_SELECT_FORUMS_EXPL}</td>

#
##---[REPLACE]----------
#

<td colspan="4" class="small">{L_BT_SELECT_FORUMS_EXPL}</td>

#
##---[EoM]----------
#