/* ===================================================================================== 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.='
'; 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.='
'; $out.=''; $out.=sf_filter_title_display($topic->topic_name).''; $out.=__(' in ', "sforum"); $out.=''.sf_get_forum_name($thisforum->forum_slug).''; $out.='
Posted by '.$poster . ', ' .sf_date('d', $post->post_date); $out.='
'; $out.='
'; 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.='
'; $out.='
'; } } else { $out.='
'; $out.='

'.__("No Topics to Display", "sforum").'

'."\n"; $out.='
'; } $out.='
'; echo($out); return; }