News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Latest Topics instead of Latest posts at info center for SMF 2.0

Started by taradxxx, September 25, 2016, 01:42:07 AM

Previous topic - Next topic

taradxxx

i find smf 1.1 in http://www.simplemachines.org/community/index.php?topic=111245.0
someone help on 2.0.*
In Sources/Recent.php

// Find the ten most recent posts.
function RecentPosts()
{
global $txt, $scripturl, $user_info, $context, $modSettings, $sourcedir, $board, $smcFunc;

loadTemplate('Recent');
$context['page_title'] = $txt['recent_posts'];

if (isset($_REQUEST['start']) && $_REQUEST['start'] > 95)
$_REQUEST['start'] = 95;

$query_parameters = array();
if (!empty($_REQUEST['c']) && empty($board))
{
$_REQUEST['c'] = explode(',', $_REQUEST['c']);
foreach ($_REQUEST['c'] as $i => $c)
$_REQUEST['c'][$i] = (int) $c;

if (count($_REQUEST['c']) == 1)
{
$request = $smcFunc['db_query']('', '
SELECT name
FROM {db_prefix}categories
WHERE id_cat = {int:id_cat}
LIMIT 1',
array(
'id_cat' => $_REQUEST['c'][0],
)
);
list ($name) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

if (empty($name))
fatal_lang_error('no_access', false);

$context['linktree'][] = array(
'url' => $scripturl . '#c' . (int) $_REQUEST['c'],
'name' => $name
);
}

$request = $smcFunc['db_query']('', '
SELECT b.id_board, b.num_posts
FROM {db_prefix}boards AS b
WHERE b.id_cat IN ({array_int:category_list})
AND {query_see_board}',
array(
'category_list' => $_REQUEST['c'],
)
);
$total_cat_posts = 0;
$boards = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$boards[] = $row['id_board'];
$total_cat_posts += $row['num_posts'];
}
$smcFunc['db_free_result']($request);

if (empty($boards))
fatal_lang_error('error_no_boards_selected');

$query_this_board = 'b.id_board IN ({array_int:boards})';
$query_parameters['boards'] = $boards;

// If this category has a significant number of posts in it...
if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15)
{
$query_this_board .= '
AND m.id_msg >= {int:max_id_msg}';
$query_parameters['max_id_msg'] = max(0, $modSettings['maxMsgID'] - 400 - $_REQUEST['start'] * 7);
}

$context['page_index'] = constructPageIndex($scripturl . '?action=recent;c=' . implode(',', $_REQUEST['c']), $_REQUEST['start'], min(100, $total_cat_posts), 10, false);
}
elseif (!empty($_REQUEST['boards']))
{
$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
foreach ($_REQUEST['boards'] as $i => $b)
$_REQUEST['boards'][$i] = (int) $b;

$request = $smcFunc['db_query']('', '
SELECT b.id_board, b.num_posts
FROM {db_prefix}boards AS b
WHERE b.id_board IN ({array_int:board_list})
AND {query_see_board}
LIMIT {int:limit}',
array(
'board_list' => $_REQUEST['boards'],
'limit' => count($_REQUEST['boards']),
)
);
$total_posts = 0;
$boards = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$boards[] = $row['id_board'];
$total_posts += $row['num_posts'];
}
$smcFunc['db_free_result']($request);

if (empty($boards))
fatal_lang_error('error_no_boards_selected');

$query_this_board = 'b.id_board IN ({array_int:boards})';
$query_parameters['boards'] = $boards;

// If these boards have a significant number of posts in them...
if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12)
{
$query_this_board .= '
AND m.id_msg >= {int:max_id_msg}';
$query_parameters['max_id_msg'] = max(0, $modSettings['maxMsgID'] - 500 - $_REQUEST['start'] * 9);
}

$context['page_index'] = constructPageIndex($scripturl . '?action=recent;boards=' . implode(',', $_REQUEST['boards']), $_REQUEST['start'], min(100, $total_posts), 10, false);
}
elseif (!empty($board))
{
$request = $smcFunc['db_query']('', '
SELECT num_posts
FROM {db_prefix}boards
WHERE id_board = {int:current_board}
LIMIT 1',
array(
'current_board' => $board,
)
);
list ($total_posts) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

$query_this_board = 'b.id_board = {int:board}';
$query_parameters['board'] = $board;

// If this board has a significant number of posts in it...
if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10)
{
$query_this_board .= '
AND m.id_msg >= {int:max_id_msg}';
$query_parameters['max_id_msg'] = max(0, $modSettings['maxMsgID'] - 600 - $_REQUEST['start'] * 10);
}

$context['page_index'] = constructPageIndex($scripturl . '?action=recent;board=' . $board . '.%1$d', $_REQUEST['start'], min(100, $total_posts), 10, true);
}
else
{
$query_this_board = '{query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
AND b.id_board != {int:recycle_board}' : ''). '
AND m.id_msg >= {int:max_id_msg}';
$query_parameters['max_id_msg'] = max(0, $modSettings['maxMsgID'] - 100 - $_REQUEST['start'] * 6);
$query_parameters['recycle_board'] = $modSettings['recycle_board'];

// !!! This isn't accurate because we ignore the recycle bin.
$context['page_index'] = constructPageIndex($scripturl . '?action=recent', $_REQUEST['start'], min(100, $modSettings['totalMessages']), 10, false);
}

$context['linktree'][] = array(
'url' => $scripturl . '?action=recent' . (empty($board) ? (empty($_REQUEST['c']) ? '' : ';c=' . (int) $_REQUEST['c']) : ';board=' . $board . '.0'),
'name' => $context['page_title']
);

$key = 'recent-' . $user_info['id'] . '-' . md5(serialize(array_diff_key($query_parameters, array('max_id_msg' => 0)))) . '-' . (int) $_REQUEST['start'];
if (empty($modSettings['cache_enable']) || ($messages = cache_get_data($key, 120)) == null)
{
$done = false;
while (!$done)
{
// Find the 10 most recent messages they can *view*.
// !!!SLOW This query is really slow still, probably?
$request = $smcFunc['db_query']('', '
SELECT m.id_msg
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
WHERE ' . $query_this_board . '
AND m.approved = {int:is_approved}
ORDER BY m.id_msg DESC
LIMIT {int:offset}, {int:limit}',
array_merge($query_parameters, array(
'is_approved' => 1,
'offset' => $_REQUEST['start'],
'limit' => 10,
))
);
// If we don't have 10 results, try again with an unoptimized version covering all rows, and cache the result.
if (isset($query_parameters['max_id_msg']) && $smcFunc['db_num_rows']($request) < 10)
{
$smcFunc['db_free_result']($request);
$query_this_board = str_replace('AND m.id_msg >= {int:max_id_msg}', '', $query_this_board);
$cache_results = true;
unset($query_parameters['max_id_msg']);
}
else
$done = true;
}
$messages = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$messages[] = $row['id_msg'];
$smcFunc['db_free_result']($request);
if (!empty($cache_results))
cache_put_data($key, $messages, 120);
}

// Nothing here... Or at least, nothing you can see...
if (empty($messages))
{
$context['posts'] = array();
return;
}

// Get all the most recent posts.
$request = $smcFunc['db_query']('', '
SELECT
m.id_msg, m.subject, m.smileys_enabled, m.poster_time, m.body, m.id_topic, t.id_board, b.id_cat,
b.name AS bname, c.name AS cname, t.num_replies, m.id_member, m2.id_member AS id_first_member,
IFNULL(mem2.real_name, m2.poster_name) AS first_poster_name, t.id_first_msg,
IFNULL(mem.real_name, m.poster_name) AS poster_name, t.id_last_msg
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
INNER JOIN {db_prefix}messages AS m2 ON (m2.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = m2.id_member)
WHERE m.id_msg IN ({array_int:message_list})
ORDER BY m.id_msg DESC
LIMIT ' . count($messages),
array(
'message_list' => $messages,
)
);
$counter = $_REQUEST['start'] + 1;
$context['posts'] = array();
$board_ids = array('own' => array(), 'any' => array());
while ($row = $smcFunc['db_fetch_assoc']($request))
{
// Censor everything.
censorText($row['body']);
censorText($row['subject']);

// BBC-atize the message.
$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);

// And build the array.
$context['posts'][$row['id_msg']] = array(
'id' => $row['id_msg'],
'counter' => $counter++,
'alternate' => $counter % 2,
'category' => array(
'id' => $row['id_cat'],
'name' => $row['cname'],
'href' => $scripturl . '#c' . $row['id_cat'],
'link' => '<a href="' . $scripturl . '#c' . $row['id_cat'] . '">' . $row['cname'] . '</a>'
),
'board' => array(
'id' => $row['id_board'],
'name' => $row['bname'],
'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['bname'] . '</a>'
),
'topic' => $row['id_topic'],
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '" rel="nofollow">' . $row['subject'] . '</a>',
'start' => $row['num_replies'],
'subject' => $row['subject'],
'time' => timeformat($row['poster_time']),
'timestamp' => forum_time(true, $row['poster_time']),
'first_poster' => array(
'id' => $row['id_first_member'],
'name' => $row['first_poster_name'],
'href' => empty($row['id_first_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_first_member'],
'link' => empty($row['id_first_member']) ? $row['first_poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_first_member'] . '">' . $row['first_poster_name'] . '</a>'
),
'poster' => array(
'id' => $row['id_member'],
'name' => $row['poster_name'],
'href' => empty($row['id_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>'
),
'message' => $row['body'],
'can_reply' => false,
'can_mark_notify' => false,
'can_delete' => false,
'delete_possible' => ($row['id_first_msg'] != $row['id_msg'] || $row['id_last_msg'] == $row['id_msg']) && (empty($modSettings['edit_disable_time']) || $row['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()),
);

if ($user_info['id'] == $row['id_first_member'])
$board_ids['own'][$row['id_board']][] = $row['id_msg'];
$board_ids['any'][$row['id_board']][] = $row['id_msg'];
}
$smcFunc['db_free_result']($request);

// There might be - and are - different permissions between any and own.
$permissions = array(
'own' => array(
'post_reply_own' => 'can_reply',
'delete_own' => 'can_delete',
),
'any' => array(
'post_reply_any' => 'can_reply',
'mark_any_notify' => 'can_mark_notify',
'delete_any' => 'can_delete',
)
);

// Now go through all the permissions, looking for boards they can do it on.
foreach ($permissions as $type => $list)
{
foreach ($list as $permission => $allowed)
{
// They can do it on these boards...
$boards = boardsAllowedTo($permission);

// If 0 is the only thing in the array, they can do it everywhere!
if (!empty($boards) && $boards[0] == 0)
$boards = array_keys($board_ids[$type]);

// Go through the boards, and look for posts they can do this on.
foreach ($boards as $board_id)
{
// Hmm, they have permission, but there are no topics from that board on this page.
if (!isset($board_ids[$type][$board_id]))
continue;

// Okay, looks like they can do it for these posts.
foreach ($board_ids[$type][$board_id] as $counter)
if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id'])
$context['posts'][$counter][$allowed] = true;
}
}
}

$quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']));
foreach ($context['posts'] as $counter => $dummy)
{
// Some posts - the first posts - can't just be deleted.
$context['posts'][$counter]['can_delete'] &= $context['posts'][$counter]['delete_possible'];

// And some cannot be quoted...
$context['posts'][$counter]['can_quote'] = $context['posts'][$counter]['can_reply'] && $quote_enabled;
}
}

need show only TOPIC
thank you

Advertisement: