##############################################################
## MOD Title: Net News on sidebar for Torrentpier II
## MOD Author: Elder admin@free-torrents.org
## USED CODE FROM:  RoadTrain(Last added, top torrents, top users Mod ), Meithar (original code TorrentPier R775 )
## MOD Adapted for Torrentpier II: krumax < admin@krumax.org > http://krumax.org
## MOD Version: 0.2
## :      t.ru,    (    )
## Installation Level: Easy
## Installation Time: 10 Minutes
## Files To Edit: index.php, config,php,
## includes/datastore/build_cat_forums.php, 
## includes/common.php
## templates/default/page_header.tpl
## Included Files: none
## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2
##############################################################
## For security purposes, please check: http://torrentpier.info/
## for the latest version of this MOD. Although MODs are checked
## before being allowed in the MODs Database there is no guarantee
## that there are no security problems within the MOD. No support
## will be given for MODs not found within the MODs Database which
## can be found at http://torrentpier.info/ http://torrentpier.info/viewtopic.php?f=8&t=3052
##############################################################
## MOD History:
## 2009-08-06 - Version 0.1.0
## - initial release
## 2009-10-04 - Version 0.2.0
## - New feature - news from subforums
##
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################

# 
#-----[ OPEN ]---------------------------------
# 
config.php

#
#-----[ FIND ]---------------------------------
#
$bb_cfg['advert_html_path']            = $bb_cfg['html_path'] .'advert.html';  #
#
#-----[ AFTER, ADD ]---------------------------------
#
// net news
$bb_cfg['show_latest_net_news']     = true; # show/hide block on sidebar
$bb_cfg['latest_net_news_count']    = xx; # xx - news count on sidebar 
$bb_cfg['latest_net_news_forum_id'] = 'XXX,YYY,ZZZ'; # XXX,YYY,ZZZ - forum_id(s) like 11,23,14 

# 
#-----[ OPEN ]---------------------------------
# 
index.php

#
#-----[ FIND ]---------------------------------
#
// Init userdata
$user->session_start();

#
#-----[ BEFORE, ADD ]---------------------------------
#
//Enqueue latest net news
if ($bb_cfg['latest_net_news_count'])
{
	$datastore->enqueue('latest_net_news');
}

#
#-----[ FIND ]---------------------------------
#
if ($bb_cfg['birthday']['check_day'] && $bb_cfg['birthday']['enabled'])
{

# 
#-----[ BEFORE, ADD ]---------------------------------
#
//
// BEGIN latest net news.
//
if($bb_cfg['show_latest_net_news']) 
{

if (!$latest_net_news = $datastore->get('latest_net_news'))
	{
		$datastore->update('latest_net_news');
		$latest_net_news = $datastore->get('latest_net_news');
	}

	$template -> assign_vars(array(
		'LASTEST_NET_NEWS' => true,
    ));
	
	foreach ($latest_net_news as $latest_net)
	{
		$template -> assign_block_vars('LatestNetNews',array(
			'TITLE' => $latest_net['topic_title'],
			'TOPIC_ID' => $latest_net['topic_id'],
		)) ;
	}
}
//
// END latest net news
//

# 
#-----[ OPEN ]---------------------------------
# 
includes/datastore/build_cat_forums.php

# 
#-----[ FIND ]---------------------------------
#
	$this->store('latest_news', $data);
}

# 
#-----[ AFTER, ADD ]---------------------------------
#
	//Store LatestNetNews

if ($bb_cfg['show_latest_net_news'] AND $net_news_forum_ids= $bb_cfg['latest_net_news_forum_id'])
{
	$net_news_count = max($bb_cfg['latest_net_news_count'], 1);

	$data = DB()->fetch_rowset("
		SELECT topic_id, topic_title, forum_id
		FROM ". BB_TOPICS ."
		WHERE forum_id IN ($net_news_forum_ids)
		ORDER BY topic_time DESC
		LIMIT $net_news_count
	");

	$this->store('latest_net_news', $data);
}

# 
#-----[ OPEN ]---------------------------------
# 
templates/default/page_header.tpl

# 
#-----[ FIND ]---------------------------------
#
<?php if (!empty($bb_cfg['sidebar1_static_content_path'])) include($bb_cfg['sidebar1_static_content_path']); ?>

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

<div class="spacer">&nbsp;</div>
<!-- IF LASTEST_NET_NEWS -->
<table cellpadding="3" cellspacing="0" border="0" class="attachtable">
<tr class="cat_title"><td><b>??????? ? ????</b></td></tr>
<!-- BEGIN LatestNetNews -->
<tr>
<td class="f_titles" style="border-bottom: 1px solid #C3CBD1;">
<div><a href="viewtopic.php?t={LatestNetNews.TOPIC_ID}" style="font-size:11px">{LatestNetNews.TITLE}</a></div>
</td>
</tr>
<!-- END LatestNetNews -->
</table>
<!-- ENDIF -->
<div class="spacer">&nbsp;</div>

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

# 
#-----[ FIND ]---------------------------------
#
'latest_news'            => 'build_cat_forums.php',

# 
#-----[ AFTER, ADD ]---------------------------------
#
'latest_net_news'        => 'build_cat_forums',

#
#-----[ SAVE/CLOSE ALL FILES ]---------------------------------
#
# EoM
