$post_query, 'FROM' => array( POSTS_TABLE => 'p', TOPICS_TABLE => 't', ), 'LEFT_JOIN' => array( array( 'FROM' => array(USERS_TABLE => 'u'), 'ON' => 'u.user_id = p.poster_id', ), ), 'WHERE' => '(' . $db->sql_in_set('t.forum_id', $forum_ids) . ' AND p.post_id = t.topic_first_post_id AND t.topic_approved = 1)', 'ORDER_BY' => $sort_order, ); $sql = $db->sql_build_query('SELECT', $post_sql_ary); $result = $db->sql_query_limit($sql, $limit, $offset); #Set an array with the posts $posts = array(); while ($post = $db->sql_fetchrow($result)){ #Getting the Attachments if($allow_attachments && $post['post_attachment']){ unset($attachment_urls, $attachment_ids, $attachment_names,$attachment_downloads, $attachment_comments, $attachment_filesize, $num_of_attachment_ids); $attachments_sql_ary = array( 'SELECT' => 'a.attach_id, a.real_filename, a.download_count, a.attach_comment, a.filesize', 'FROM' => array( ATTACHMENTS_TABLE => 'a', ), 'WHERE' => '(a.post_msg_id = ' . $post['post_id'] . ' AND a.in_message = 0)', 'ORDER_BY' => 'a.attach_id DESC', ); $attachments_sql = $db->sql_build_query('SELECT', $attachments_sql_ary); $attachments_result = $db->sql_query($attachments_sql); while ($row = $db->sql_fetchrow($attachments_result)){ $attachment_ids[] = $row['attach_id']; $attachment_names[] = $row['real_filename']; $attachment_downloads[] = $row['download_count']; $attachment_comments[] = $row['attach_comment']; $attachment_filesize[] = $row['filesize']; } $db->sql_freeresult($attachments_result); $num_of_attachment_ids = count($attachment_ids); for($i=key($attachment_ids);$i<$num_of_attachment_ids;$i++){ $attachment_urls[$i] = $phpbb_root_path . 'download/file.' . $phpEx . '?id=' . $attachment_ids[$i]; } } #Getting the Breadcrumbs unset($breadcrumb_ids); if($post['forum_id'] > 0){ $breadcrumb_ids_sql_ary = array( 'SELECT' => 'f.forum_id, f.forum_name', 'FROM' => array( FORUMS_TABLE => 'f', ), 'WHERE' => '(f.left_id <= (SELECT left_id FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $post['forum_id'] . ') AND f.right_id >= (SELECT right_id FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $post['forum_id'] . '))', ); $bread_crumb_ids_sql = $db->sql_build_query('SELECT', $breadcrumb_ids_sql_ary); $bread_crumb_ids_result = $db->sql_query($bread_crumb_ids_sql); while ($row = $db->sql_fetchrow($bread_crumb_ids_result)){ $breadcrumb_ids[$row['forum_name']] = $row['forum_id']; } $db->sql_freeresult($bread_crumb_ids_result); } $posts[] = array( # FOR POSTS 'forum_id' => $post['forum_id'], 'post_id' => $post['post_id'], 'post_time' => $post['post_time'], 'post_text' => $post['post_text'], #PARSING 'bbcode_bitfield' => $post['bbcode_bitfield'], 'bbcode_uid' => $post['bbcode_uid'], 'enable_bbcode' => $post['enable_bbcode'], 'enable_smilies' => $post['enable_smilies'], 'enable_magic_url' => $post['enable_magic_url'], #TOPIC DETAILS 'topic_id' => $post['topic_id'], 'topic_title' => $post['topic_title'], 'topic_views' => $post['topic_views'], 'topic_replies_real' => $post['topic_replies_real'], 'topic_type' => $post['topic_type'], 'topic_first_post_id' => $post['topic_first_post_id'], 'topic_last_post_time' => $post['topic_last_post_time'], #ATTACHMENTS 'allow_attachments' => $allow_attachments, 'is_there_attachments' => $post['post_attachment'], 'attachments' => $attachment_urls, 'attachment_names' => $attachment_names, 'attachment_downloads' => $attachment_downloads, 'attachment_comments' => $attachment_comments, 'attachment_filesize' => $attachment_filesize, 'num_of_attachments' => $num_of_attachment_ids, #BREADCRUMBS 'breadcrumb_ids' => $breadcrumb_ids, #FOR USER 'user_id' => $post['user_id'], 'topic_first_poster_name' => $post['topic_first_poster_name'], 'user_colour' => $post['user_colour'], #AVATAR 'allow_avatar' => $allow_avatar, 'user_avatar' => $post['user_avatar'], 'user_avatar_type' => $post['user_avatar_type'], 'user_avatar_width' => $post['user_avatar_width'], 'user_avatar_height' => $post['user_avatar_height'], #RANKS 'allow_ranks' => $allow_ranks, 'user_rank_id' => $post['user_rank'], 'user_posts' => $post['user_posts'], #SIGNATURES 'allow_sigs' => $allow_sigs, 'user_sig' => $post['user_sig'], 'user_sig_bbcode_uid' => $post['user_sig_bbcode_uid'], 'user_sig_bbcode_bitfield' => $post['user_sig_bbcode_bitfield'], #FOR PAGINATION 'total_forum_ids' => $forum_ids, ); } $db->sql_freeresult($result); // Return it return $posts; } ?>