<?php
define('IN_PHPBB', true);
define('BB_SCRIPT', 'top');
define('BB_ROOT', './');
require(BB_ROOT . 'common.php');
require(INC_DIR . 'bbcode.php');
$user->session_start();
if (IS_ADMIN)
{
if (!$forum_select = $datastore->get('viewtopic_forum_select'))
{
$datastore->update('viewtopic_forum_select');
$forum_select = $datastore->get('viewtopic_forum_select');
}
$forum_select_html = $forum_select['viewtopic_forum_select'];
}
else
{
$not_auth_forums_csv = $user->get_not_auth_forums(AUTH_VIEW);
$forum_select_html = get_forum_select(explode(',', $not_auth_forums_csv), 'forum_id');
}
$template->assign_vars(array(
'SELECT_FORUM' => $forum_select_html,
'PAGE_TITLE' => 'Топ раздач',
));
$forum_id = (isset($_GET['forum_id'])) ? $_GET['forum_id'] : 0;
$forum_in = (isset($_GET['forum_id'])) ? " AND t.forum_id IN (". $forum_id .")" : " AND f.allow_porno_topic = 0";
if (!$topics = CACHE('bb_cache')->get('portal_'. $forum_id))
{
$topics = DB()->fetch_rowset("
SELECT t.topic_title, t.topic_id, tp.post_text
FROM ". BB_TOPICS ." t
LEFT JOIN ". BB_FORUMS ." f ON (t.forum_id = f.forum_id)
LEFT JOIN ". BB_POSTS_TEXT ." tp ON (tp.post_id = t.topic_first_post_id)
LEFT JOIN ". BB_BT_TORRENTS ." tor ON (t.topic_id = tor.topic_id)
WHERE t.topic_dl_type = 1
$forum_in
ORDER BY tor.tor_seeders DESC
LIMIT 50
");
CACHE('bb_cache')->set('portal_'. $forum_id, $topics, 3600);
}
foreach ($topics AS $topics_row)
{
preg_match_all('/\[img=right\](.*?)\[\/img\]/i', $topics_row['post_text'], $poster, PREG_SET_ORDER);
preg_match_all('/\[img=left\](.*?)\[\/img\]/i', $topics_row['post_text'], $poster2, PREG_SET_ORDER);
preg_match_all('/\[img\](.*?)\[\/img\]/i', $topics_row['post_text'], $poster3, PREG_SET_ORDER);
/* Если установлен тег для постера [poster][/poster]
preg_match_all('/\[poster=right\](.*?)\[\/poster\]/i', $topics_row['post_text'], $poster4, PREG_SET_ORDER);
preg_match_all('/\[poster=left\](.*?)\[\/poster\]/i', $topics_row['post_text'], $poster5, PREG_SET_ORDER);
preg_match_all('/\[poster\](.*?)\[\/poster\]/i', $topics_row['post_text'], $poster6, PREG_SET_ORDER);*/
$url = 'images/no-poster.png';
if (isset($poster[0][1])) { $url = $poster[0][1]; }
elseif (isset($poster2[0][1])) { $url = $poster2[0][1]; }
elseif (isset($poster3[0][1])) { $url = $poster3[0][1]; }
/* Если установлен тег для постера [poster][/poster]
elseif (isset($poster4[0][1])) { $url = $poster4[0][1]; }
elseif (isset($poster5[0][1])) { $url = $poster5[0][1]; }
elseif (isset($poster6[0][1])) { $url = $poster6[0][1]; }*/
$template->assign_block_vars('topics', array(
'TOPIC_TITLE' => $topics_row['topic_title'],
'IMAGE' => $url,
'U_VIEW_TOPIC' => TOPIC_URL . $topics_row['topic_id']
));
}
print_page('top.tpl');