<?php
/*
=================================================================
Bullet Energy - by White-Master 
-----------------------------------------------------------------
http://white-master.ru/
-----------------------------------------------------------------
Copyright (c) 2011 White-Master
=================================================================
Данный код защищен авторскими правами
=================================================================
Файл: last_post.php
=================================================================
*/
$option = array();
$option['viewCache'] = unserialize(@file_get_contents(ENGINE_DIR . '/bullet_energy/cache/system/sys_cashe_group_' . $member_id['user_group'] . '.tmp'));
$option['treeCache'] = unserialize(@file_get_contents(ENGINE_DIR . '/bullet_energy/cache/system/tree_permanent.tmp'));
if (!$option['viewCache']['parse'] or !$option['treeCache'] or $do == 'forum') {
  return '';
}
$db->query("SELECT 
              id, 
              id_parent, 
              title, 
              reply_count, 
              view_count,
              autor_id,
              autor, 
              last_reply_info
            FROM " . PREFIX . "_be_topic 
            WHERE 
              id_parent = {$option['viewCache']['parse']}
            LIMIT 5");
if (!$db->num_rows()) {
  return '';
}
$tpl->load_template('last_topic_content.tpl');
$row = array();
while ($row = $db->get_row()) {
  $row['ajaxAutor'] = "onclick=\"ShowProfile('" . urlencode($row['autor']) . "', '{$config['http_home_url']}/user/" . urlencode($row['autor']) . "/', '" . $row['autor_id'] . "'); return false;\"";
  $row['ajaxAutor'] = $config['allow_alt_url'] == 'yes' ? "<a {$row['ajaxAutor']} href=\"{$config['http_home_url']}user/" . urlencode($row['autor']) . "/\">" : "<a {$row['ajaxAutor']} href=\"{$config['http_home_url']}?subaction=userinfo&amp;user=" . urlencode($row['autor']) . "\">";
  $row['last_reply_info'] = unserialize($row['last_reply_info']);
  $row['ajax'] = "onclick=\"ShowProfile('" . urlencode($row['last_reply_info'][0]) . "', '{$config['http_home_url']}/user/" . urlencode($row['last_reply_info'][0]) . "/', '" . $row['last_reply_info'][5] . "'); return false;\"";
  $row['ajax'] = $config['allow_alt_url'] == 'yes' ? "<a {$row['ajax']} href=\"{$config['http_home_url']}user/" . urlencode($row['last_reply_info'][0]) . "/\">" : "<a {$row['ajax']} href=\"{$config['http_home_url']}?subaction=userinfo&amp;user=" . urlencode($row['last_reply_info'][0]) . "\">";
  $tpl->set('[linck]', $config['allow_alt_url'] == 'yes' ? "<a href=\"{$config['http_home_url']}forum/showtopic-{$row['id']}\">" : "<a href=\"{$config['http_home_url']}?do=forum&amp;action=showtopic&amp;id={$row['id']}\">");
  $tpl->set('[/linck]', '</a>');
  $tpl->set('[topicAutor]', $row['ajaxAutor']);
  $tpl->set('[/topicAutor]', '</a>');
  $tpl->set('{topicAutorName}', $row['autor']);
  $tpl->set('[lastMessageLinck]', '<a href="' . $row['last_reply_info'][3] . '">');
  $tpl->set('[/lastMessageLinck]', '</a>');
  $tpl->set('[popupUserCard]', $row['ajax']);
  $tpl->set('[/popupUserCard]', '</a>');
  $tpl->set('{title}', stripcslashes($row['title']));
  $tpl->set('{replyCount}', $row['reply_count']);
  $tpl->set('[profile]', $config['allow_alt_url'] == 'yes' ? "<a href=\"{$config['http_home_url']}user/" . urlencode($row['last_reply_info'][0]) . "/\">" : "<a href=\"{$config['http_home_url']}?subaction=userinfo&amp;user=" . urlencode($row['last_reply_info'][0]) . "\">");
  $tpl->set('[/profile]', '</a>');
  $tpl->set('{viewCount}', $row['view_count']);
  if (date('Ymd', $row['last_reply_info'][1]) == date('Ymd', $_TIME)) {
    $tpl->set('{lastMessageDate}', 'Сегодня' . langdate(", H:i", $row['last_reply_info'][1]));
  } elseif (date('Ymd', $row['last_reply_info'][1]) == date('Ymd', ($_TIME - 86400))) {
    $tpl->set('{lastMessageDate}', 'Вчера' . langdate(", H:i", $row['last_reply_info'][1]));
  } else {
    $tpl->set('{lastMessageDate}', langdate($config['timestamp_active'], $row['last_reply_info'][1]));
  }
  $row['linckTree'] = $config['allow_alt_url'] == 'yes' ? "<a href=\"{$config['http_home_url']}forum/categories-{$option['treeCache'][$row['id_parent']]['tree_id']}\">{$option['treeCache'][$row['id_parent']]['tree_title']}</a>" : "<a href=\"{$config['http_home_url']}?do=forum&amp;action=categories&amp;id={$option['treeCache'][$row['id_parent']]['tree_id']}\">{$option['treeCache'][$row['id_parent']]['tree_title']}</a>";
  $tpl->set('{lastAutorName}', $row['last_reply_info'][0]);
  $tpl->set('{infoTopic}', 'Тема в разделе:' . $row['linckTree']);
  $tpl->set('{lastAutorAvatarLinck}', $row['last_reply_info'][4] ? $config['http_home_url'] . 'uploads/fotos/' . $row['last_reply_info'][4] : $config['http_home_url'] . 'templates/' . $config['skin'] . '/bullet_energy/images/noavatar.png');
  $tpl->compile('last_topic_content');
}
$tpl->load_template('last_topic_box.tpl');
$tpl->set('{contentListLast}', $tpl->result['last_topic_content']);
$tpl->compile('last_topic_box');

?>