function do_last_posts()
{
$this->ipsclass->load_language('lang_global');
require_once( ROOT_PATH.'sources/handlers/han_parse_bbcode.php' );
$parser = new parse_bbcode();
$parser->ipsclass =& $this->ipsclass;
$parser->allow_update_caches = 0;
$parser->parse_smilies = 0;
$perpage = (isset($this->ipsclass->input['show']) AND intval($this->ipsclass->input['show']) > 0) ? intval($this->ipsclass->input['show']) : 10;
$perpage = ( $perpage > SSI_MAX_SHOW ) ? SSI_MAX_SHOW : $perpage;
$post_template = $this->load_template('last_posts.html');
$to_echo = '';
$wheretopics = '';
$whereposts = '';
if( count($this->disable_forums) > 0 )
{
$wheretopics .= 't.forum_id NOT IN ('.implode(',', $this->disable_forums).') AND ';
}
if( isset($this->ipsclass->input['f']) && $this->ipsclass->input['f'] ) {
$forums = $this->ipsclass->clean_int_array( explode( ",", $this->ipsclass->input['f'] ) );
if( count($forums) > 0 )
{
$wheretopics .= "t.forum_id IN (".implode(',', $forums).") AND ";
}
}
if( intval($this->ipsclass->input['notopics']) == 1 )
{
$whereposts .= 'p.new_topic!=1 AND ';
}
if( isset($this->ipsclass->input['topic']) AND intval($this->ipsclass->input['topic']) > 0 )
{
$wheretopics .= 't.tid='.intval($this->ipsclass->input['topic']).' AND ';
$one_topic = 1;
}
else
{
$one_topic = 0;
}
if( intval($this->ipsclass->input['onepertopic']) == 1 )
{
$wheretopics .= 'p.post_date = t.last_post AND ';
}
$this->ipsclass->DB->build_query( array( 'select' => 'p.*',
'from' => array( 'posts' => 'p' ),
'where' => $wheretopics.$whereposts.'p.queued=0',
'order' => 'p.post_date DESC',
'limit' => array( 0, $perpage ),
'add_join' => array( 0 => array( 'select' => 'm.members_display_name as member_name, m.id as member_id, m.title as member_title',
'from' => array( 'members' => 'm' ),
'where' => 'm.id=p.author_id',
'type' => 'left' ),
1 => array( 'select' => 'me.avatar_location, me.avatar_size, me.avatar_type',
'from' => array( 'member_extra' => 'me' ),
'where' => 'me.id=p.author_id',
'type' => 'left' ),
2 => array( 'select' => 't.tid, t.title',
'from' => array( 'topics' => 't' ),
'where' => "p.topic_id=t.tid AND t.approved=1 AND t.state != 'closed' AND (t.moved_to is null or t.moved_to = '') AND t.starter_id <> 0",
'type' => 'left' ) )
) );
$sql_result = $this->ipsclass->DB->exec_query();
if ( !$this->ipsclass->DB->get_num_rows($sql_result) )
{
fatal_error("Could not get the information from the database");
}
$newsize = (isset($this->ipsclass->input['asize']) AND intval($this->ipsclass->input['asize']) > 0) ? intval($this->ipsclass->input['asize']) : 0;
$len = (isset($this->ipsclass->input['len']) AND intval($this->ipsclass->input['len']) > 0) ? intval($this->ipsclass->input['len']) : 0;
while( $row = $this->ipsclass->DB->fetch_row($sql_result) )
{
$parser->parse_html = ( $this->ipsclass->cache['forum_cache'][ $row['forum_id'] ]['use_html'] and $this->ipsclass->cache['group_cache'][ $row['mgroup'] ]['g_dohtml'] and $row['post_htmlstate'] ) ? 1 : 0;
$parser->parse_nl2br = $row['post_htmlstate'] == 2 ? 1 : 0;
$parser->parse_wordwrap = $this->ipsclass->vars['post_wordwrap'];
$row['post'] = $parser->pre_display_parse( $row['post'] );
$row['member_name'] = $row['member_name'] ? $row['member_name'] : $row['author_name'];
$row['member_avatar'] = $this->ipsclass->get_avatar( $row['avatar_location'], 1, $row['avatar_size'], $row['avatar_type'] );
if( $newsize )
{
$row['member_avatar'] = preg_replace("#width='(\d+)'#is", "width='$newsize'", $row['member_avatar']);
$row['member_avatar'] = preg_replace("#height='(\d+)'#is", "height='$newsize'", $row['member_avatar']);
}
$row['post'] = $parser->strip_all_tags( $row['post'] );
$row['post'] = preg_replace("#([^\s<>'\"/\.\\-\?&\n\r\%]{80})#i", " \\1"."<br />", $row['post']);
$row['post'] = str_replace( "\n", '<br />', trim($row['post']) );
if( $len and (strlen( $row['post'] ) > $len) )
{
$row['post'] = substr( $row['post'], 0, $len ) . '...';
$row['post'] = preg_replace( "/&(#(\d+;?)?)?\.\.\.$/", '...', $row['post'] );
}
$to_echo .= $this->parse_template( $post_template,
array (
'profile_link' => $this->ipsclass->base_url.'?showuser='.$row['member_id'],
'member_name' => $row['member_name'],
'member_title' => $row['member_title'] ? '<br />'.$row['member_title'] : '',
'post_date' => gmdate('d.m.Y H:i', ($row['post_date'] + $this->ipsclass->offset) ),
'topic_link' => $this->ipsclass->base_url.'?showtopic='.$row['tid'],
'topic_title' => $row['title'],
'forum_link' => $this->ipsclass->base_url.'?showforum='.$row['forum_id'],
'forum_title' => $this->ipsclass->cache['forum_cache'][ $row['forum_id'] ]['name'],
'post' => $row['post'],
'posts' => $row['posts'],
'view_all_link'=> $this->ipsclass->base_url.'?showtopic='.$row['tid'].'&view=findpost&p='.$row['pid'],
'member_avatar'=> $row['member_avatar']
)
);
}
if( $one_topic AND isset($this->ipsclass->input['showtopicinfo']) AND $this->ipsclass->input['showtopicinfo'] )
{
$this->ipsclass->DB->build_query( array( 'select' => 'tid,title,posts,starter_id,starter_name,forum_id',
'from' => 'topics',
'where' => 'tid='.intval($this->ipsclass->input['topic']),
) );
$sql_result = $this->ipsclass->DB->exec_query();
if( $row = $this->ipsclass->DB->fetch_row($sql_result) )
{
if( in_array($row['forum_id'], $this->disable_forums) )
{
fatal_error("You can't access this topic.");
}
$topicinfo_template = $this->load_template('last_posts_topicinfo.html');
$topic_info = $this->parse_template( $topicinfo_template,
array (
'profile_link' => $this->ipsclass->base_url.'?act=Profile&CODE=03&MID='.$row['starter_id'],
'starter_name' => $row['starter_name'],
'topic_link' => $this->ipsclass->base_url.'?act=st&t='.$row['tid'],
'topic_link_last' => $this->ipsclass->base_url.'?act=st&t='.$row['tid'].'&view=getlastpost',
'topic_title' => $row['title'],
'forum_link' => $this->ipsclass->base_url.'?act=sf&f='.$row['forum_id'],
'forum_title' => $this->ipsclass->cache['forum_cache'][ $row['forum_id'] ]['name'],
'posts' => $row['posts'],
)
);
$to_echo = $topic_info.$to_echo;
}
}