rendered paste body/* =====================================================================================
sf_latest_posts_truncate($limit=5, $trunhars=300, $pad="...")
displays the quicklinks dropdowns for forum list and recent topics list and trims content length if needed.
parameters:
$limit How many items to show in the list number 5
$trunchars How many charectors to find truncate point (will leave complete words) number 300
$pad If content needs trimming, this will be added to the end of it. string "..."
===================================================================================*/
function sf_latest_posts_truncate($limit=5, $trunchars=300, $pad="...")
{
global $wpdb, $current_user, $sfvars;
$limit = sf_esc_int($limit);
if (empty($limit)) return;
sf_initialise_globals($sfvars['forumid']);
$out = '';
$where = " WHERE ".SFPOSTS.".post_status = 0";
# limit to viewable forums based on permissions
if (!$current_user->forumadmin)
{
$allforums = sf_get_forum_memberships($current_user->ID);
if ($allforums)
{
$forum_ids = '';
foreach ($allforums as $thisforum)
{
if (sf_can_view_forum($thisforum->forum_id))
{
$forum_ids[] = $thisforum->forum_id;
}
}
} else {
return '';
}
# create where clause based on forums that current user can view
if ($forum_ids != '')
{
$where .= " AND forum_id IN (" . implode(",", $forum_ids) . ") = 1";
} else {
return '';
}
}
$posts = $wpdb->get_results(
"SELECT post_id, topic_id, forum_id, post_content, post_index, ".sf_zone_datetime('post_date').",
".SFPOSTS.".user_id, guest_name, ".SFMEMBERS.".display_name FROM ".SFPOSTS."
LEFT JOIN ".SFMEMBERS." ON ".SFPOSTS.".user_id = ".SFMEMBERS.".user_id
".$where."
ORDER BY post_date DESC
LIMIT ".$limit);
$out.='<div class="sf-latest">';
if ($posts) {
foreach ($posts as $post)
{
$thisforum = sf_get_forum_record($post->forum_id);
$poster = sf_build_name_display($post->user_id, sf_filter_name_display($post->display_name));
if (empty($poster)) $poster = sf_filter_name_display($post->guest_name);
$topic = sf_get_topic_record($post->topic_id);
$out.='<div class="sf-latest-header">';
$out.='<a href="'.sf_build_url($thisforum->forum_slug, $topic->topic_slug, 0, $post->post_id, $post->post_index).'">';
$out.=sf_filter_title_display($topic->topic_name).'</a>';
$out.=__(' in ', "sforum");
$out.='<a href="'.sf_build_url($thisforum->forum_slug, '', 1, 0).'">'.sf_get_forum_name($thisforum->forum_slug).'</a>';
$out.='<br />Posted by '.$poster . ', ' .sf_date('d', $post->post_date);
$out.='</div>';
$out.='<div class="sf-latest-content">';
if($current_user->moderator == false && $status == 1)
{
$content = __("Post Awaiting Approval by Forum Administrator", "sforum");
} else {
$content = addslashes($post->post_content);
$content = sf_filter_save_nohtml($content);
$content = htmlspecialchars($content, ENT_QUOTES, 'UTF-8');
$content = str_replace('&', '&', $content);
if(strlen($content) > $trunchars)
{
$content = substr($content, 0, $trunchars);
if(false !== ($breakpoint = strrpos($content, ' ')))
{
$content = substr($content, 0, $breakpoint) . $pad;
}
}
}
$out.=$content;
$out.='</div>';
$out.='<br />';
}
} else {
$out.='<div class="sf-latest-header">';
$out.='<p>'.__("No Topics to Display", "sforum").'</p>'."\n";
$out.='</div>';
}
$out.='</div>';
echo($out);
return;
}