Файл: apwa/includes/recent_topics.php
Строк: 208
<?php
/**
*
* @package - recent_topics
* @version $Id: recent_topics.php 1.0.1 2009-01-10 18:59:40 nissin $
* @copyright (c) kevin / saint ( www.board3.de/ ), (c) Ice, (c) nickvergessen ( www.flying-bits.org/ ), (c) redbull254 ( www.digitalfotografie-foren.de ), (c) Christian_N ( www.phpbb-projekt.de )
* @based on: phpBB3 Portal by Sevdin Filiz, www.phpbb3portal.com
* @Modified by Rayden, www.phpbbguru.net
* @Modified by nissin, www.nurlan.info
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
if (!defined('IN_PHPBB'))
{
exit;
}
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
function character_limit(&$title, $limit = 0)
{
$title = censor_text($title);
if ($limit > 0)
{
return (utf8_strlen($title) > $limit + 3) ? truncate_string($title, $limit) . '...' : $title;
}
else
{
return $title;
}
}
$user->setup('mods/recent_topics');
// Announcement text
$announcement_text = '';
$announcement_title = '';
if (intval($config['recent_anno_post']))
{
$sql = 'SELECT p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid, t.topic_title, t.topic_id, t.forum_id
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
WHERE p.topic_id = t.topic_id
AND t.topic_approved = 1
AND t.topic_id = ' . $config['recent_anno_post'] . '
ORDER BY p.post_id ASC';
$result = $db->sql_query_limit($sql, 1);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
// Parse the message and subject
$announcement_text = $row['post_text'];
strip_bbcode($announcement_text);
$announcement_text = character_limit($announcement_text, '151');
$announcement_text = smiley_text($announcement_text);
$announcement_text .= (character_limit($announcement_text, '150')) ? '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id'] . '&p=' . $row['post_id'] . '#' . $row['post_id']) . '">»»</a>' : '';
$announcement_title = censor_text($row['topic_title']);
}
//
// Exclude forums
//
$sql_where = '';
if ($config['recent_exclude_forums'])
{
$exclude_forums = explode(',', $config['recent_exclude_forums']);
foreach ($exclude_forums as $i => $id)
{
if ($id > 0)
{
$sql_where .= ' AND t.forum_id <> ' . trim($id);
}
}
}
// Get a list of forums the user cannot read
$forum_ary = array_unique(array_keys($auth->acl_getf('!f_read', true)));
if (sizeof($forum_ary))
{
$sql_where .= ' AND ' . $db->sql_in_set('t.forum_id', $forum_ary, true);
}
// Determine first forum the user is able to read (must not be a category)
$sql = 'SELECT forum_id
FROM ' . FORUMS_TABLE . '
WHERE forum_type = ' . FORUM_POST;
if (sizeof($forum_ary))
{
$sql .= ' AND ' . $db->sql_in_set('forum_id', $forum_ary, true);
}
$result = $db->sql_query_limit($sql, 1);
$g_forum_id = (int) $db->sql_fetchfield('forum_id');
$db->sql_freeresult($result);
$sql_from = TOPICS_TABLE . ' t';
$sql_select = 't.*';
if ($config['load_db_lastread'] && $user->data['is_registered'])
{
$sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.user_id = ' . $user->data['user_id'] . '
AND t.topic_id = tt.topic_id)
LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . '
AND ft.forum_id = t.forum_id)';
$sql_select .= ', tt.mark_time, ft.mark_time as f_mark_time';
}
if ($config['load_anon_lastread'] || ($user->data['is_registered'] && !$config['load_db_lastread']))
{
$tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : '';
$tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
}
//
// Recent posts
//
$last_post_id = '';
$sql = 'SELECT ' . $sql_select . '
FROM ' . $sql_from . '
WHERE t.topic_status <> ' . ITEM_MOVED . '
AND t.topic_approved = 1
AND ( t.topic_type = ' . POST_NORMAL . ' OR t.topic_type = ' . POST_STICKY . ' )
AND t.topic_moved_id = 0
' . $sql_where . '
ORDER BY t.topic_last_post_time DESC';
$result = $db->sql_query_limit($sql, $config['recent_max_topics']);
$last_post_id = 0;
while( ($row = $db->sql_fetchrow($result)) )
{
$topic_tracking_info = array();
// Get topic tracking info
if ($config['load_db_lastread'] && $user->data['is_registered'])
{
$tmp_topic_data = array($row['topic_id'] => $row);
$topic_tracking_info = get_topic_tracking($row['forum_id'], $row['topic_id'], $tmp_topic_data, array($row['forum_id'] => $row['f_mark_time']));
unset($tmp_topic_data);
}
else if ($config['load_anon_lastread'] || $user->data['is_registered'])
{
$topic_tracking_info = get_complete_topic_tracking($row['forum_id'], $row['topic_id']);
}
$replies = ($auth->acl_get('m_approve', $row['forum_id'])) ? $row['topic_replies_real'] : $row['topic_replies'];
$unread_topic = (isset($topic_tracking_info[$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$row['topic_id']]) ? true : false;
$template->assign_block_vars('recent_posts', array(
'TITLE' => character_limit($row['topic_title'], $config['recent_title_limit']),
'FULL_TITLE' => censor_text($row['topic_title']),
'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']),
'TOPIC_REPLIES' => $replies,
'S_UNREAD_TOPIC'=> $unread_topic,
'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id'] . '&view=unread') . '#unread',
'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id'] . '&p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
));
$last_post_id .= (!empty($last_post_id)) ? ', ' . $row['topic_last_post_id'] : $row['topic_last_post_id'];
}
$db->sql_freeresult($result);
//
// Recent topics
//
$sql = 'SELECT ' . $sql_select . '
FROM ' . $sql_from . '
WHERE t.topic_status <> ' . ITEM_MOVED . '
AND t.topic_last_post_id NOT IN (' . $last_post_id . ')
AND t.topic_approved = 1
AND t.topic_moved_id = 0
' . $sql_where . '
ORDER BY t.topic_time DESC';
$result = $db->sql_query_limit($sql, $config['recent_max_topics']);
while( ($row = $db->sql_fetchrow($result)) )
{
$topic_tracking_info = array();
// Get topic tracking info
if ($config['load_db_lastread'] && $user->data['is_registered'])
{
$tmp_topic_data = array($row['topic_id'] => $row);
$topic_tracking_info = get_topic_tracking($row['forum_id'], $row['topic_id'], $tmp_topic_data, array($row['forum_id'] => $row['f_mark_time']));
unset($tmp_topic_data);
}
else if ($config['load_anon_lastread'] || $user->data['is_registered'])
{
$topic_tracking_info = get_complete_topic_tracking($row['forum_id'], $row['topic_id']);
}
$replies = ($auth->acl_get('m_approve', $row['forum_id'])) ? $row['topic_replies_real'] : $row['topic_replies'];
$unread_topic = (isset($topic_tracking_info[$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$row['topic_id']]) ? true : false;
$template->assign_block_vars('recent_topics', array(
'TITLE' => character_limit($row['topic_title'], $config['recent_title_limit']),
'FULL_TITLE' => censor_text($row['topic_title']),
'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . ( ($row['forum_id'] == 0) ? $g_forum_id : $row['forum_id'] ) . '&t=' . $row['topic_id']),
'TOPIC_REPLIES' => $replies,
'S_UNREAD_TOPIC'=> $unread_topic,
'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . ( ($row['forum_id'] == 0) ? $g_forum_id : $row['forum_id'] ) . '&t=' . $row['topic_id'] . '&view=unread') . '#unread',
'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . ( ($row['forum_id'] == 0) ? $g_forum_id : $row['forum_id'] ) . '&t=' . $row['topic_id'] . '&p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
));
}
$db->sql_freeresult($result);
$template->assign_vars(array(
'S_DISPLAY_RECENT' => true,
'ANNO_TITLE' => $announcement_title,
'ANNO_TEXT' => $announcement_text,
'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
'LATEST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
));
?>