/** * Get posts defined by type and other settings * * @param string $forum_from Forums from which the posts should be retrieved * @param bool $permissions Whether permissions should be taken into account * during retrieval * @param int $number_of_posts Number of posts to get * @param int $text_length Length the text should be shortened to * @param int $time The amount of days ago the posts could have been posted * @param string $type Type of posts to get * @param int $start At which position the query should start * @param bool $invert Whether the permissions should be inverted * * @return array An array containing the posts that were retrieved from the database */ public function get_posts($forum_from, $permissions, $number_of_posts, $text_length, $time, $type, $start = 0, $invert = false) { $posts = array(); $post_time = $this->get_setting_based_data($time == 0, '', 'AND t.topic_time > ' . (time() - $time * 86400)); $forum_from = $this->get_setting_based_data(strpos($forum_from, ',') !== false, explode(',', $forum_from), $this->get_setting_based_data($forum_from != '', array($forum_from), array())); $topic_icons = array(0); $have_icons = 0; $this->global_id = 0; $this->type = $type; $this->reset_constraints(); // Get disallowed forums $disallow_access = $this->modules_helper->get_disallowed_forums($permissions); // Set forums that should be excluded or included if (!$this->set_forum_constraints($forum_from, $disallow_access, $invert)) { return array(); } // Get SQL constraints $this->get_type_constraints(); // Get global forum ID for announcements if (!$this->get_global_id()) { return array(); } $result = $this->run_sql_query($post_time, $number_of_posts, $start); $i = 0; // Fill posts array while ($row = $this->db->sql_fetchrow($result)) { $this->fill_posts_array($row, $text_length, $i, $have_icons, $posts, $topic_icons); ++$i; } $this->db->sql_freeresult($result); $posts['topic_icons'] = $this->get_setting_based_data(max($topic_icons) > 0 && $have_icons, true, false); $posts['topic_count'] = $i; if ($this->global_id < 1) { return array(); } else { return $posts; } }
/** * {@inheritdoc} */ public function get_template_center($module_id) { $news = $this->request->variable('news_' . $module_id, -1); $news = $news > $this->config['board3_number_of_news_' . $module_id] - 1 ? -1 : $news; $this->user->add_lang('viewforum'); $start = $this->request->variable('np_' . $module_id, 0); $start = $start < 0 ? 0 : $start; $total_news = 1; // Fetch news from portal functions.php with check if "read full" is requested. $portal_news_length = $news < 0 && !$this->config['board3_news_style_' . $module_id] ? $this->config['board3_news_length_' . $module_id] : 0; $this->fetch_posts->set_module_id($module_id); $fetch_news = $this->fetch_posts->get_posts($this->config['board3_news_forum_' . $module_id], $this->config['board3_news_permissions_' . $module_id], $this->config['board3_number_of_news_' . $module_id], $portal_news_length, 0, $this->config['board3_show_all_news_' . $module_id] ? 'news_all' : 'news', $start, (bool) $this->config['board3_news_exclude_' . $module_id]); $topic_icons = false; if (!empty($fetch_news['topic_icons'])) { $topic_icons = true; } // Standard news row $news_row = array('S_NEWEST_OR_FIRST' => $this->config['board3_news_show_last_' . $module_id] ? $this->user->lang['JUMP_NEWEST'] : $this->user->lang['JUMP_FIRST'], 'POSTED_BY_TEXT' => $this->config['board3_news_show_last_' . $module_id] ? $this->user->lang['LAST_POST'] : $this->user->lang['POSTED'], 'S_DISPLAY_NEWS_RVS' => $this->config['board3_show_news_replies_views_' . $module_id] ? true : false, 'S_TOPIC_ICONS' => $topic_icons, 'MODULE_ID' => $module_id); // Any news present? If not terminate it here. if (sizeof($fetch_news) == 0) { // Create standard news row $this->template->assign_block_vars('news', $news_row); $this->template->assign_block_vars('news.news_row', array('S_NO_TOPICS' => true, 'S_NOT_LAST' => false)); } else { // Count number of posts for news archive, considering if permission check is dis- or enabled. if ($this->config['board3_news_archive_' . $module_id]) { $permissions = $this->config['board3_news_permissions_' . $module_id]; $forum_from = $this->config['board3_news_forum_' . $module_id]; $forum_from = strpos($forum_from, ',') !== false ? explode(',', $forum_from) : ($forum_from != '' ? array($forum_from) : array()); $str_where = ''; // Get disallowed forums $disallow_access = $this->modules_helper->get_disallowed_forums($permissions); if ($this->config['board3_news_exclude_' . $module_id] == true) { $disallow_access = array_merge($disallow_access, $forum_from); $forum_from = array(); } if (sizeof($forum_from)) { $disallow_access = array_diff($forum_from, $disallow_access); if (!sizeof($disallow_access)) { return array(); } foreach ($disallow_access as $acc_id) { $acc_id = (int) $acc_id; $str_where .= "forum_id = {$acc_id} OR "; } } else { foreach ($disallow_access as $acc_id) { $acc_id = (int) $acc_id; $str_where .= "forum_id <> {$acc_id} AND "; } } $str_where = strlen($str_where) > 0 ? 'AND (' . trim(substr($str_where, 0, -4)) . ')' : ''; $topic_type = $this->config['board3_show_all_news_' . $module_id] ? '(topic_type <> ' . POST_ANNOUNCE . ') AND (topic_type <> ' . POST_GLOBAL . ')' : 'topic_type = ' . POST_NORMAL; $sql = 'SELECT COUNT(topic_id) AS num_topics FROM ' . TOPICS_TABLE . ' WHERE ' . $topic_type . ' AND topic_visibility = ' . ITEM_APPROVED . ' AND topic_moved_id = 0 ' . $str_where; $result = $this->db->sql_query($sql, 300); $total_news = (int) $this->db->sql_fetchfield('num_topics'); $this->db->sql_freeresult($result); } $topic_tracking_info = get_portal_tracking_info($fetch_news); // Create pagination if necessary if ($this->config['board3_news_archive_' . $module_id]) { $pagination = generate_portal_pagination($this->modules_helper->route('board3_portal_controller'), $total_news, $this->config['board3_number_of_news_' . $module_id], $start, $this->config['board3_show_all_news_' . $module_id] ? 'news_all' : 'news', $module_id); } if ($this->config['board3_number_of_news_' . $module_id] != 0 && $this->config['board3_news_archive_' . $module_id]) { $news_row = array_merge($news_row, array('NP_PAGINATION' => !empty($pagination) ? $pagination : '', 'TOTAL_NEWS' => $total_news == 1 ? sprintf($this->user->lang['VIEW_FORUM_TOPICS'][1], $total_news) : sprintf($this->user->lang['VIEW_FORUM_TOPICS'][2], $total_news), 'NP_PAGE_NUMBER' => $this->pagination->on_page($total_news, $this->config['board3_number_of_news_' . $module_id], $start))); } // Create standard news row $this->template->assign_block_vars('news', $news_row); // Show the news overview if ($news < 0) { $count = $fetch_news['topic_count']; for ($i = 0; $i < $count; $i++) { if (isset($fetch_news[$i]['striped']) && $fetch_news[$i]['striped'] == true) { $open_bracket = '[ '; $close_bracket = ' ]'; $read_full = $this->user->lang['READ_FULL']; } else { $open_bracket = ''; $close_bracket = ''; $read_full = ''; } // unread? $forum_id = $fetch_news[$i]['forum_id']; $topic_id = $fetch_news[$i]['topic_id']; $unread_topic = isset($topic_tracking_info[$topic_id]) && $fetch_news[$i]['topic_last_post_time'] > $topic_tracking_info[$topic_id] ? true : false; $read_full_url = $this->request->is_set('np_' . $module_id) ? "np_{$module_id}={$start}&news_{$module_id}={$i}#n_{$module_id}_{$i}" : "news_{$module_id}={$i}#n_{$module_id}_{$i}"; $view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . ($fetch_news[$i]['forum_id'] ? $fetch_news[$i]['forum_id'] : $forum_id) . '&t=' . $topic_id); $replies = $this->auth->acl_get('m_approve', $forum_id) ? $fetch_news[$i]['topic_replies_real'] : $fetch_news[$i]['topic_replies']; switch ($fetch_news[$i]['topic_type']) { case POST_STICKY: $folder = 'sticky_read'; $folder_new = 'sticky_unread'; break; case POST_ANNOUNCE: $folder = 'announce_read'; $folder_new = 'announce_unread'; break; default: $folder = 'topic_read'; $folder_new = 'topic_unread'; if ($this->config['hot_threshold'] && $replies >= $this->config['hot_threshold'] && $fetch_news[$i]['topic_status'] != ITEM_LOCKED) { $folder .= '_hot'; $folder_new .= '_hot'; } break; } if ($fetch_news[$i]['topic_status'] == ITEM_LOCKED) { $folder .= '_locked'; $folder_new .= '_locked'; } if ($fetch_news[$i]['topic_posted']) { $folder .= '_mine'; $folder_new .= '_mine'; } $folder_img = $unread_topic ? $folder_new : $folder; $folder_alt = $unread_topic ? 'NEW_POSTS' : ($fetch_news[$i]['topic_status'] == ITEM_LOCKED ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS'); // Grab icons $icons = $this->cache->obtain_icons(); $this->template->assign_block_vars('news.news_row', array('ATTACH_ICON_IMG' => $fetch_news[$i]['attachment'] && $this->config['allow_attachments'] ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : '', 'FORUM_NAME' => $forum_id ? $fetch_news[$i]['forum_name'] : '', 'TITLE' => $fetch_news[$i]['topic_title'], 'POSTER' => $fetch_news[$i]['username'], 'POSTER_FULL' => $fetch_news[$i]['username_full'], 'USERNAME_FULL_LAST' => $fetch_news[$i]['username_full_last'], 'U_USER_PROFILE' => ($fetch_news[$i]['user_type'] == USER_NORMAL || $fetch_news[$i]['user_type'] == USER_FOUNDER) && $fetch_news[$i]['user_id'] != ANONYMOUS ? append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=viewprofile&u=' . $fetch_news[$i]['user_id']) : '', 'TIME' => $fetch_news[$i]['topic_time'], 'LAST_POST_TIME' => $this->user->format_date($fetch_news[$i]['topic_last_post_time']), 'TEXT' => $fetch_news[$i]['post_text'], 'REPLIES' => $fetch_news[$i]['topic_replies'], 'TOPIC_VIEWS' => $fetch_news[$i]['topic_views'], 'N_ID' => $i, 'TOPIC_FOLDER_IMG' => $this->user->img($folder_img, $folder_alt), 'TOPIC_IMG_STYLE' => $folder_img, 'TOPIC_FOLDER_IMG_SRC' => $this->user->img($folder_img, $folder_alt, false, '', 'src'), 'TOPIC_FOLDER_IMG_ALT' => $this->user->lang[$folder_alt], 'TOPIC_ICON_IMG' => !empty($icons[$fetch_news[$i]['icon_id']]) ? $icons[$fetch_news[$i]['icon_id']]['img'] : '', 'TOPIC_ICON_IMG_WIDTH' => !empty($icons[$fetch_news[$i]['icon_id']]) ? $icons[$fetch_news[$i]['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_HEIGHT' => !empty($icons[$fetch_news[$i]['icon_id']]) ? $icons[$fetch_news[$i]['icon_id']]['height'] : '', 'FOLDER_IMG' => $this->user->img('topic_read', 'NO_NEW_POSTS'), 'U_VIEWFORUM' => append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id']), 'U_LAST_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id'] . '&p=' . $fetch_news[$i]['topic_last_post_id'] . '#p' . $fetch_news[$i]['topic_last_post_id']), 'U_VIEW_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id']), 'U_VIEW_UNREAD' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id'] . '&view=unread#unread'), 'U_POST_COMMENT' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", 'mode=reply&f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id']), 'U_READ_FULL' => $this->modules_helper->route('board3_portal_controller') . '?' . $read_full_url, 'L_READ_FULL' => $read_full, 'OPEN' => $open_bracket, 'CLOSE' => $close_bracket, 'S_NOT_LAST' => $i < sizeof($fetch_news) - 1 ? true : false, 'S_POLL' => $fetch_news[$i]['poll'], 'S_UNREAD_INFO' => $unread_topic, 'S_HAS_ATTACHMENTS' => !empty($fetch_news[$i]['attachments']) ? true : false)); // Assign pagination $this->pagination->generate_template_pagination($view_topic_url, 'news.news_row.pagination', 'start', $fetch_news[$i]['topic_replies'] + 1, $this->config['posts_per_page'], 1); if (!empty($fetch_news[$i]['attachments'])) { foreach ($fetch_news[$i]['attachments'] as $attachment) { $this->template->assign_block_vars('news.news_row.attachment', array('DISPLAY_ATTACHMENT' => $attachment)); } } } } else { $i = $news; $forum_id = $fetch_news[$i]['forum_id']; $topic_id = $fetch_news[$i]['topic_id']; $unread_topic = isset($topic_tracking_info[$topic_id]) && $fetch_news[$i]['topic_last_post_time'] > $topic_tracking_info[$topic_id] ? true : false; $open_bracket = '[ '; $close_bracket = ' ]'; $read_full = $this->user->lang['BACK']; $read_full_url = $this->request->is_set('np_' . $module_id) ? $this->modules_helper->route('board3_portal_controller') . "?np_{$module_id}={$start}#n_{$module_id}_{$i}" : $this->modules_helper->route('board3_portal_controller') . "#n_{$module_id}_{$i}"; $view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . ($fetch_news[$i]['forum_id'] ? $fetch_news[$i]['forum_id'] : $forum_id) . '&t=' . $topic_id); $this->template->assign_block_vars('news.news_row', array('ATTACH_ICON_IMG' => $fetch_news[$i]['attachment'] && $this->config['allow_attachments'] ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : '', 'FORUM_NAME' => $forum_id ? $fetch_news[$i]['forum_name'] : '', 'TITLE' => $fetch_news[$i]['topic_title'], 'POSTER' => $fetch_news[$i]['username'], 'POSTER_FULL' => $fetch_news[$i]['username_full'], 'TIME' => $fetch_news[$i]['topic_time'], 'TEXT' => $fetch_news[$i]['post_text'], 'REPLIES' => $fetch_news[$i]['topic_replies'], 'TOPIC_VIEWS' => $fetch_news[$i]['topic_views'], 'N_ID' => $i, 'U_VIEWFORUM' => append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id']), 'U_LAST_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'p=' . $fetch_news[$i]['topic_last_post_id'] . '#p' . $fetch_news[$i]['topic_last_post_id']), 'U_VIEW_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id']), 'U_POST_COMMENT' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", 'mode=reply&f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id']), 'S_POLL' => $fetch_news[$i]['poll'], 'S_UNREAD_INFO' => $unread_topic, 'U_READ_FULL' => $read_full_url, 'L_READ_FULL' => $read_full, 'OPEN' => $open_bracket, 'CLOSE' => $close_bracket, 'S_HAS_ATTACHMENTS' => !empty($fetch_news[$i]['attachments']) ? true : false)); $this->pagination->generate_template_pagination($view_topic_url, 'news.news_row.pagination', 'start', $fetch_news[$i]['topic_replies'] + 1, $this->config['posts_per_page'], 1); if (!empty($fetch_news[$i]['attachments'])) { foreach ($fetch_news[$i]['attachments'] as $attachment) { $this->template->assign_block_vars('news.news_row.attachment', array('DISPLAY_ATTACHMENT' => $attachment)); } } } } $this->template->assign_vars(array('NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'READ_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'GOTO_PAGE_IMG' => $this->user->img('icon_post_target', 'GOTO_PAGE'))); if ($this->config['board3_news_style_' . $module_id]) { return 'news_compact_center.html'; } else { return 'news_center.html'; } }