Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Load news posts into $context['news_posts']
- function loadNewsPosts($start = null, $limit = null, $category = null, $length = null)
- {
- global $context, $smcFunc, $modSettings, $settings, $txt, $scripturl, $boardurl;
- // A bit of basic validation
- $start = (int) $start;
- $limit = (int) $limit;
- $category = (int) $category;
- $length = (int) $length;
- if (empty($limit))
- $limit = 15;
- // Load all the boards along with category names
- $request = $smcFunc['db_query']('', '
- SELECT b.id_board, c.name, c.id_cat
- FROM {db_prefix}boards AS b
- LEFT JOIN {db_prefix}categories AS c ON (b.id_cat = c.id_cat)
- WHERE' . (empty($category) ? '' : ' c.id_cat = {int:cat} AND') . ' b.id_board != {int:recycle}',
- array(
- 'cat' => $category,
- 'recycle' => $modSettings['recycle_board']//$modSettings['recycle_enabled'] ? $modSettings['recycle_board'] : 0,
- )
- );
- $boards = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- $boards[] = $row['id_board'];
- $cats[$row['id_board']] = array($row['id_cat'], $row['name']);
- }
- $smcFunc['db_free_result']($request);
- // Now grab all the topic ids
- $request = $smcFunc['db_query']('', '
- SELECT id_first_msg
- FROM {db_prefix}topics AS t
- INNER JOIN {db_prefix}news AS n ON (t.id_topic = n.id_topic)
- ' . (empty($boards) ? '' : 'WHERE
- id_board IN ({array_int:boards})') . '
- ORDER BY id_first_msg DESC
- LIMIT ' . $start . ', ' . $limit,
- array(
- 'boards' => $boards,
- )
- );
- $posts = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- $posts[] = $row['id_first_msg'];
- $smcFunc['db_free_result']($request);
- // Now query each post with newest first
- $context['news_posts'] = array();
- if (!empty($posts))
- {
- $request = $smcFunc['db_query']('', '
- SELECT
- m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
- t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked, m.id_board,
- n.shortest, n.short, n.pic
- FROM {db_prefix}topics AS t
- INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
- INNER JOIN {db_prefix}news AS n ON (n.id_topic = t.id_topic)
- LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
- WHERE t.id_first_msg IN ({array_int:posts})
- ORDER BY m.poster_time DESC',
- array(
- 'posts' => $posts,
- )
- );
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
- // If we want to limit the length of the post by char.
- unset($shortbody);
- if (!empty($length) && $smcFunc['strlen']($row['body']) > $length)
- {
- $shortbody = $smcFunc['substr']($row['body'], 0, $length);
- // The first space or line break. (<br />, etc.)
- $cutoff = max(strrpos($shortbody, ' '), strrpos($shortbody, '<'));
- if ($cutoff !== false)
- $shortbody = $smcFunc['substr']($shortbody, 0, $cutoff);
- $shortbody .= '...';
- }
- $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
- if (!empty($shortbody))
- $shortbody = parse_bbc($shortbody, $row['smileys_enabled'], $row['id_msg']);
- // Check that this message icon is there...
- if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
- $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';
- censorText($row['subject']);
- censorText($row['body']);
- $context['news_posts'][] = array(
- 'id' => $row['id_topic'],
- 'id_cat' => $cats[$row['id_board']][0],
- 'cat' => $cats[$row['id_board']][1],
- 'message_id' => $row['id_msg'],
- 'icon' => '<img class="icon" src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
- 'subject' => $row['subject'],
- 'time' => timeformat($row['poster_time']),
- 'timestamp' => forum_time(true, $row['poster_time']),
- 'shortest' => $row['shortest'],
- 'short' => $row['short'],
- 'pic' => $boardurl . '/NewsImages/' . $row['pic'],
- 'body' => $row['body'],
- 'shortbody' => empty($shortbody) ? $row['body'] : $shortbody,
- 'shortened' => !empty($shortbody),
- 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
- 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['num_replies'] . ' ' . ($row['num_replies'] == 1 ? 'Comment' : 'Comments') . '</a>',
- 'replies' => $row['num_replies'],
- 'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'],
- 'comment_link' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'] . '">Write Comment</a>',
- 'new_comment' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . '">Write Comment</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']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name']
- ),
- 'locked' => !empty($row['locked']),
- 'is_last' => false
- );
- }
- $smcFunc['db_free_result']($request);
- $context['news_posts'][count($context['news_posts']) - 1]['is_last'] = true;
- }
- return $context['news_posts'];
- }
- ?>
Add Comment
Please, Sign In to add comment