Пример #1
0
 /**
  * @param bool $check_visibility
  */
 private function _set_topic_visibility($check_visibility)
 {
     if ($check_visibility) {
         $this->store['sql_array']['WHERE'][] = 't.topic_time <= ' . time();
         $this->store['sql_array']['WHERE'][] = $this->content_visibility->get_global_visibility_sql('topic', $this->ex_fid_ary, 't.');
     }
 }
 /**
  * @param array $topic_data
  * @param array $post_data
  */
 protected function _show_topics(array &$topic_data, array &$post_data)
 {
     for ($i = 0, $size = sizeof($topic_data); $i < $size; $i++) {
         $row =& $topic_data[$i];
         $forum_id = $row['forum_id'];
         $topic_id = $row['topic_id'];
         $tpl_ary = array('FORUM_TITLE' => $row['forum_name'], 'TOPIC_TITLE' => truncate_string(censor_text($row['topic_title']), $this->settings['topic_title_limit'], 255, false, '...'), 'TOPIC_AUTHOR' => get_username_string('full', $row[$this->fields['user_id']], $row[$this->fields['username']], $row[$this->fields['user_colour']]), 'TOPIC_PREVIEW' => $this->_get_preview(array_pop($post_data[$topic_id])), 'TOPIC_POST_TIME' => $this->user->format_date($row[$this->fields['time']]), 'ATTACH_ICON_IMG' => $this->_get_attachment_icon($forum_id, $row['topic_attachment']), 'REPLIES' => $this->content_visibility->get_count('topic_posts', $row, $forum_id) - 1, 'VIEWS' => $row['topic_views'], 'S_UNREAD_TOPIC' => $this->_is_unread_topic($forum_id, $topic_id, $row['topic_last_post_time']), 'U_VIEWTOPIC' => append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "f={$forum_id}&amp;t={$topic_id}"), 'U_VIEWFORUM' => append_sid($this->phpbb_root_path . 'viewforum.' . $this->php_ext, "f={$forum_id}"));
         $this->ptemplate->assign_block_vars('topicrow', $tpl_ary);
         unset($topic_data[$i], $post_data[$topic_id]);
     }
 }
Пример #3
0
    /**
     * @param string $exclude_words
     * @return array
     */
    private function _get_words_sql($exclude_words)
    {
        $sql_where = $this->_exclude_words_sql($exclude_words);
        return array('SELECT' => 'l.word_text, l.word_count', 'FROM' => array(SEARCH_WORDLIST_TABLE => 'l', SEARCH_WORDMATCH_TABLE => 'm', TOPICS_TABLE => 't', POSTS_TABLE => 'p'), 'WHERE' => 'l.word_common <> 1
				AND l.word_count > 0
				AND m.word_id = l.word_id
				AND m.post_id = p.post_id
				AND t.topic_id = p.topic_id
				AND t.topic_time <= ' . time() . '
				AND ' . $this->content_visibility->get_global_visibility_sql('topic', array_keys($this->auth->acl_getf('!f_read', true)), 't.') . $sql_where, 'GROUP_BY' => 'l.word_text, l.word_count', 'ORDER_BY' => 'l.word_count DESC');
    }
Пример #4
0
 /**
  * @param array $post_ids
  * @param string $topic_first_or_last_post
  * @return array
  */
 private function _get_post_data_where(array $post_ids, $topic_first_or_last_post)
 {
     $sql_where = array();
     if (sizeof($post_ids)) {
         $sql_where[] = $this->db->sql_in_set('p.post_id', $post_ids);
     } else {
         if (sizeof($this->store['topic'])) {
             $this->_limit_posts_by_topic($sql_where, $topic_first_or_last_post);
         }
     }
     $sql_where[] = $this->content_visibility->get_global_visibility_sql('post', $this->ex_fid_ary, 'p.');
     return $sql_where;
 }
Пример #5
0
 /**
  * @param array $post_ids
  * @param string $topic_first_or_last_post
  * @return array
  */
 private function _get_post_data_where(array $post_ids, $topic_first_or_last_post)
 {
     $sql_where = array();
     if (sizeof($this->store['topic'])) {
         $sql_where[] = $this->db->sql_in_set('topic_id', array_keys($this->store['topic']));
         if ($topic_first_or_last_post) {
             $post_ids = array_merge($post_ids, $this->get_topic_post_ids($topic_first_or_last_post));
             $sql_where[] = $this->db->sql_in_set('post_id', $post_ids);
         }
     }
     $sql_where[] = $this->content_visibility->get_global_visibility_sql('post', $this->ex_fid_ary, 'p.');
     return $sql_where;
 }
Пример #6
0
 /**
  *
  * @param array $topic_row a db topic row
  */
 public function __construct(array $topic_row, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\content_visibility $phpbb_content_visibility, $phpbb_root_path, $php_ext)
 {
     $this->user = $user;
     $this->auth = $auth;
     $this->phpbb_root_path = $phpbb_root_path;
     $this->php_ext = $php_ext;
     $this->topic_row = $topic_row;
     if ($topic_row['topic_status'] == ITEM_MOVED) {
         $this->topic_id = $topic_row['topic_moved_id'];
     } else {
         $this->topic_id = $topic_row['topic_id'];
     }
     $this->forum_id = (int) $this->topic_row['forum_id'];
     $this->view_topic_url_params = 'f=' . $this->forum_id . '&amp;t=' . $this->topic_id;
     $this->view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", $this->view_topic_url_params);
     $this->newest_post_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", $this->view_topic_url_params . '&amp;view=unread') . '#unread';
     $this->last_post_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", $this->view_topic_url_params . '&amp;p=' . $topic_row['topic_last_post_id']) . '#p' . $topic_row['topic_last_post_id'];
     $this->replies = $phpbb_content_visibility->get_count('topic_posts', $topic_row, $this->forum_id) - 1;
     // Get folder img, topic status/type related information
     topic_status($topic_row, $this->replies, $this->unread_topic(), $this->folder_img, $this->folder_alt, $this->topic_type);
     $this->topic_unapproved = ($topic_row['topic_visibility'] == ITEM_UNAPPROVED || $topic_row['topic_visibility'] == ITEM_REAPPROVE) && $auth->acl_get('m_approve', $this->forum_id);
     $this->posts_unapproved = $topic_row['topic_visibility'] == ITEM_APPROVED && $topic_row['topic_posts_unapproved'] && $auth->acl_get('m_approve', $this->forum_id);
     $this->topic_deleted = $topic_row['topic_visibility'] == ITEM_DELETED;
 }
Пример #7
0
 /**
  * Forum check
  *
  * @param object $event The event object
  * @return null
  * @access public
  */
 public function viewtopic_get_post_data($event)
 {
     $topic_data = $event['topic_data'];
     $sql_ary = $event['sql_ary'];
     $post_list = $event['post_list'];
     $s_sfpo = !empty($topic_data['sfpo_guest_enable']) && $this->user->data['user_id'] == ANONYMOUS;
     if ($s_sfpo) {
         $this->user->add_lang_ext('rmcgirr83/sfpo', 'common');
         $post_list = array((int) $topic_data['topic_first_post_id']);
         $sql_ary['WHERE'] = $this->db->sql_in_set('p.post_id', $post_list) . ' AND u.user_id = p.poster_id';
         $topic_replies = $this->content_visibility->get_count('topic_posts', $topic_data, $event['forum_id']) - 1;
         $redirect = '&amp;redirect=' . urlencode(str_replace('&amp;', '&', build_url(array('_f_'))));
         $this->template->assign_vars(array('S_SFPO' => true, 'SFPO_MESSAGE' => $topic_replies ? $this->user->lang('SFPO_MSG_REPLY', $topic_replies) : '', 'U_SFPO_LOGIN' => append_sid("{$this->root_path}ucp.{$this->php_ext}", 'mode=login' . $redirect)));
     }
     $event['post_list'] = $post_list;
     $event['sql_ary'] = $sql_ary;
 }
Пример #8
0
    /**
     * Do not post the message if there are some new ones
     *
     * @param object $event The event object
     * @return null
     * @access public
     */
    public function detect_new_posts($event)
    {
        // Ajax submit
        if ($this->config['qr_ajax_submit'] && $this->request->is_ajax() && $this->request->is_set_post('qr')) {
            include_once $this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext;
            $error = $event['error'];
            $post_data = $event['post_data'];
            $forum_id = (int) $post_data['forum_id'];
            $topic_id = (int) $post_data['topic_id'];
            // $topic_cur_post_id = (int) $post_data['topic_cur_post_id'];
            $current_post = $this->request->variable('qr_cur_post_id', 0);
            $lastclick = $this->request->variable('lastclick', time());
            if (sizeof($error)) {
                $json_response = new \phpbb\json_response();
                $json_response->send(array('error' => true, 'MESSAGE_TITLE' => $this->user->lang['INFORMATION'], 'MESSAGE_TEXT' => implode('<br />', $error)));
            } else {
                if ($lastclick < $post_data['topic_last_post_time'] && $post_data['forum_flags'] & FORUM_FLAG_POST_REVIEW) {
                    $sql = 'SELECT post_id
						FROM ' . POSTS_TABLE . '
						WHERE topic_id = ' . $topic_id . '
							AND ' . $this->phpbb_content_visibility->get_visibility_sql('post', $forum_id, '') . '
							AND post_time > ' . (int) $lastclick . '
							ORDER BY post_time ASC';
                    $result = $this->db->sql_query_limit($sql, 1);
                    $post_id_next = (int) $this->db->sql_fetchfield('post_id');
                    $this->db->sql_freeresult($result);
                    $error_text = $this->user->lang['POST_REVIEW_EXPLAIN'];
                    $url_next_post = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "f={$forum_id}&amp;t={$topic_id}&amp;p={$post_id_next}");
                    // #p$post_id_next
                    $json_response = new \phpbb\json_response();
                    $json_response->send(array('error' => true, 'merged' => $post_id_next === $current_post ? 'merged' : 'not_merged', 'MESSAGE_TITLE' => $this->user->lang['INFORMATION'], 'MESSAGE_TEXT' => $error_text, 'NEXT_URL' => $url_next_post));
                } else {
                    if ($post_data['topic_cur_post_id'] && $post_data['topic_cur_post_id'] != $post_data['topic_last_post_id']) {
                        // Send new post number as a response.
                        // @todo Add the possibility to reload the page.
                        $json_response = new \phpbb\json_response();
                        $json_response->send(array('post_update' => true, 'post_id' => $post_data['topic_last_post_id']));
                    }
                }
            }
        }
        // This is needed for BBCode QR_BBPOST.
        $this->user->add_lang_ext('tatiana5/quickreply', 'quickreply');
    }
Пример #9
0
 public function view_stat($top_id)
 {
     $sql_array = array('SELECT' => 'r.*', 'FROM' => array(RATING_TABLE => 'r'), 'WHERE' => 'r.top_id = ' . (int) $top_id);
     $sql_array['SELECT'] .= ', t.forum_id, t.topic_title, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, p.post_text';
     $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TABLE => 't'), 'ON' => 'r.topic_id = t.topic_id');
     $sql_array['LEFT_JOIN'][] = array('FROM' => array(POSTS_TABLE => 'p'), 'ON' => 't.topic_first_post_id = p.post_id');
     $sql = $this->db->sql_build_query('SELECT', $sql_array);
     $result = $this->db->sql_query($sql);
     if (!($row = $this->db->sql_fetchrow($result))) {
         trigger_error('Not Platform');
     }
     $this->db->sql_freeresult($result);
     $top_domain = $this->gethost($row['top_url']);
     // Limit chars
     $top_desc = $row['post_text'];
     strip_bbcode($top_desc);
     $top_desc = str_replace(array($row['top_url'], $top_domain), '', $top_desc);
     $this->template->assign_vars(array('TOP_NAME' => $row['topic_title'] ? $row['topic_title'] : $top_domain, 'TOP_URL' => $this->helper->route("bb3top_rating_out", array('top_id' => $row['top_id'])), 'TOP_COMMENT' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 't=' . $row['topic_id']), 'TOP_REPLIES' => $this->content_visibility->get_count('topic_posts', $row, $row['forum_id']) - 1, 'TOP_DESC' => $top_desc, 'TOP_DOMAIN' => $top_domain, 'TOP_TYPE' => $row['top_type'], 'TOP_ONLINE' => $row['top_online'], 'TOP_HITS' => $row['top_hits'], 'TOP_HOSTS' => $row['top_hosts'], 'TOP_IN' => $row['top_in'], 'TOP_OUT' => $row['top_out'], 'TOP_HITS_ALL' => $row['top_hits_all'], 'TOP_HOSTS_ALL' => $row['top_hosts_all'], 'TOP_IN_ALL' => $row['top_in_all'], 'TOP_OUT_ALL' => $row['top_out_all'], 'TOP_HITS_BEFORE' => $row['top_hits_before'], 'TOP_HOSTS_BEFORE' => $row['top_hosts_before'], 'TOP_IN_BEFORE' => $row['top_in_before'], 'TOP_OUT_BEFORE' => $row['top_out_before']));
     global $phpbb_dispatcher;
     extract($phpbb_dispatcher->trigger_event('bb3top.rating_modify_stat_row', compact(array('row'))));
     return $row;
 }
Пример #10
0
    public function display_recent_topics($tpl_loopname = 'recent_topics', $spec_forum_id = 0, $include_subforums = true)
    {
        $this->user->add_lang_ext('paybas/recenttopics', 'recenttopics');
        /**
         * Set some internal needed variables
         */
        $topics_per_page = $this->config['rt_number'];
        $num_pages = $this->config['rt_page_number'];
        $min_topic_level = $this->config['rt_min_topic_level'];
        $excluded_topics = $this->config['rt_anti_topics'];
        $display_parent_forums = $this->config['rt_parents'];
        $unread_only = $this->config['rt_unreadonly'];
        $sort_topics = $this->config['rt_sort_start_time'] ? 'topic_time' : 'topic_last_post_time';
        $persistent_display = $this->config['rt_persistent_display'];
        if ($persistent_display) {
            $this->template->assign_vars(array(strtoupper($tpl_loopname) . '_DISPLAY' => true));
        }
        $start = $this->request->variable($tpl_loopname . '_start', 0);
        $excluded_topic_ids = explode(', ', $excluded_topics);
        $total_limit = $topics_per_page * $num_pages;
        if (!function_exists('display_forums')) {
            include $this->root_path . 'includes/functions_display.' . $this->phpEx;
        }
        /**
         * Get the forums we take our topics from
         */
        // Get the allowed forums
        $forum_ary = array();
        $forum_read_ary = $this->auth->acl_getf('f_read');
        foreach ($forum_read_ary as $forum_id => $allowed) {
            if ($allowed['f_read']) {
                $forum_ary[] = (int) $forum_id;
            }
        }
        $forum_ids = array_unique($forum_ary);
        if (!sizeof($forum_ids)) {
            // No forums with f_read
            return;
        }
        $spec_forum_ary = array();
        if ($spec_forum_id) {
            // Only take a special-forum
            if (!$include_subforums) {
                if (!in_array($spec_forum_id, $forum_ids)) {
                    return;
                }
                $forum_ids = array();
                $sql = 'SELECT 1 as display_forum
					FROM ' . FORUMS_TABLE . '
					WHERE forum_id = ' . intval($spec_forum_id) . '
						AND forum_recent_topics = 1';
                $result = $this->db->sql_query_limit($sql, 1);
                $display_forum = (bool) $this->db->sql_fetchfield('display_forum');
                $this->db->sql_freeresult($result);
                if ($display_forum) {
                    $forum_ids = array($spec_forum_id);
                }
            } else {
                // ... and it's subforums
                $sql = 'SELECT f2.forum_id
					FROM ' . FORUMS_TABLE . ' f1
					LEFT JOIN ' . FORUMS_TABLE . " f2\n\t\t\t\t\t\tON (f2.left_id BETWEEN f1.left_id AND f1.right_id\n\t\t\t\t\t\t\tAND f2.forum_recent_topics = 1)\n\t\t\t\t\tWHERE f1.forum_id = {$spec_forum_id}\n\t\t\t\t\t\tAND f1.forum_recent_topics = 1\n\t\t\t\t\tORDER BY f2.left_id DESC";
                $result = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $spec_forum_ary[] = $row['forum_id'];
                }
                $this->db->sql_freeresult($result);
                $forum_ids = array_intersect($forum_ids, $spec_forum_ary);
                if (!sizeof($forum_ids)) {
                    return;
                }
            }
        } else {
            $sql = 'SELECT forum_id
				FROM ' . FORUMS_TABLE . '
				WHERE ' . $this->db->sql_in_set('forum_id', $forum_ids) . '
					AND forum_recent_topics = 1';
            $result = $this->db->sql_query($sql);
            $forum_ids = array();
            while ($row = $this->db->sql_fetchrow($result)) {
                $forum_ids[] = $row['forum_id'];
            }
            $this->db->sql_freeresult($result);
        }
        // No forums with f_read or recent topics enabled
        if (!sizeof($forum_ids)) {
            return;
        }
        // Remove duplicated ids
        $forum_ids = array_unique($forum_ids);
        $forums = $topic_list = array();
        $topics_count = 0;
        $obtain_icons = false;
        // Either use the phpBB core function to get unread topics, or the custom function for default behavior
        if ($unread_only && $this->user->data['user_id'] != ANONYMOUS) {
            // Get unread topics
            $sql_extra = ' AND ' . $this->db->sql_in_set('t.topic_id', $excluded_topic_ids, true);
            $sql_extra .= ' AND ' . $this->content_visibility->get_forums_visibility_sql('topic', $forum_ids, $table_alias = 't.');
            $unread_topics = get_unread_topics(false, $sql_extra, '', $total_limit);
            foreach ($unread_topics as $topic_id => $mark_time) {
                $topics_count++;
                if ($topics_count > $start && $topics_count <= $start + $topics_per_page) {
                    $topic_list[] = $topic_id;
                }
            }
        } else {
            // Get the allowed topics
            $sql_array = array('SELECT' => 't.forum_id, t.topic_id, t.topic_type, t.icon_id, tt.mark_time, ft.mark_time as f_mark_time', 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $this->user->data['user_id']), array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $this->user->data['user_id'])), 'WHERE' => $this->db->sql_in_set('t.topic_id', $excluded_topic_ids, true) . '
					AND t.topic_status <> ' . ITEM_MOVED . '
					AND ' . $this->content_visibility->get_forums_visibility_sql('topic', $forum_ids, $table_alias = 't.'), 'ORDER_BY' => 't.' . $sort_topics . ' DESC');
            // Check if we want all topics, or only stickies/announcements/globals
            if ($min_topic_level > 0) {
                $sql_array['WHERE'] .= ' AND t.topic_type >= ' . $min_topic_level;
            }
            /**
             * Event to modify the SQL query before the allowed topics list data is retrieved
             *
             * @event paybas.recenttopics.sql_pull_topics_list
             * @var    array    sql_array        The SQL array
             * @since 2.0.4
             */
            $vars = array('sql_array');
            extract($this->dispatcher->trigger_event('paybas.recenttopics.sql_pull_topics_list', compact($vars)));
            $sql = $this->db->sql_build_query('SELECT', $sql_array);
            $result = $this->db->sql_query_limit($sql, $total_limit);
            while ($row = $this->db->sql_fetchrow($result)) {
                $topics_count++;
                if ($topics_count > $start && $topics_count <= $start + $topics_per_page) {
                    $topic_list[] = $row['topic_id'];
                    $rowset[$row['topic_id']] = $row;
                    if (!isset($forums[$row['forum_id']]) && $this->user->data['is_registered'] && $this->config['load_db_lastread']) {
                        $forums[$row['forum_id']]['mark_time'] = $row['f_mark_time'];
                    }
                    $forums[$row['forum_id']]['topic_list'][] = $row['topic_id'];
                    $forums[$row['forum_id']]['rowset'][$row['topic_id']] =& $rowset[$row['topic_id']];
                    if ($row['icon_id'] && $this->auth->acl_get('f_icons', $row['forum_id'])) {
                        $obtain_icons = true;
                    }
                }
            }
            $this->db->sql_freeresult($result);
        }
        // No topics to display
        if (!sizeof($topic_list)) {
            return;
        }
        // Grab icons
        if ($obtain_icons) {
            $icons = $this->cache->obtain_icons();
        } else {
            $icons = array();
        }
        // Borrowed from search.php
        foreach ($forums as $forum_id => $forum) {
            if ($this->user->data['is_registered'] && $this->config['load_db_lastread']) {
                $topic_tracking_info[$forum_id] = get_topic_tracking($forum_id, $forum['topic_list'], $forum['rowset'], array($forum_id => $forum['mark_time']), $forum_id ? false : $forum['topic_list']);
            } else {
                if ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) {
                    $tracking_topics = $this->request->variable($this->config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);
                    $tracking_topics = $tracking_topics ? tracking_unserialize($tracking_topics) : array();
                    $topic_tracking_info[$forum_id] = get_complete_topic_tracking($forum_id, $forum['topic_list'], $forum_id ? false : $forum['topic_list']);
                    if (!$this->user->data['is_registered']) {
                        $this->user->data['user_lastmark'] = isset($tracking_topics['l']) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $this->config['board_startdate']) : 0;
                    }
                }
            }
        }
        // Now only pull the data of the requested topics
        $sql_array = array('SELECT' => 't.*, tp.topic_posted, f.forum_name', 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 't.topic_id = tp.topic_id AND tp.user_id = ' . $this->user->data['user_id']), array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id')), 'WHERE' => $this->db->sql_in_set('t.topic_id', $topic_list), 'ORDER_BY' => 't.' . $sort_topics . ' DESC');
        if ($display_parent_forums) {
            $sql_array['SELECT'] .= ', f.parent_id, f.forum_parents, f.left_id, f.right_id';
        }
        /**
         * Event to modify the SQL query before the topics data is retrieved
         *
         * @event paybas.recenttopics.sql_pull_topics_data
         * @var    array    sql_array        The SQL array
         * @since 2.0.0
         */
        $vars = array('sql_array');
        extract($this->dispatcher->trigger_event('paybas.recenttopics.sql_pull_topics_data', compact($vars)));
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query_limit($sql, $topics_per_page);
        $rowset = $topic_icons = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            $rowset[] = $row;
        }
        $this->db->sql_freeresult($result);
        // No topics returned by the DB
        if (!sizeof($rowset)) {
            return;
        }
        /**
         * Event to modify the topics list data before we start the display loop
         *
         * @event paybas.recenttopics.modify_topics_list
         * @var    array    topic_list        Array of all the topic IDs
         * @var    array    rowset            The full topics list array
         * @since 2.0.1
         */
        $vars = array('topic_list', 'rowset');
        extract($this->dispatcher->trigger_event('paybas.recenttopics.modify_topics_list', compact($vars)));
        foreach ($rowset as $row) {
            $topic_id = $row['topic_id'];
            $forum_id = $row['forum_id'];
            $s_type_switch_test = $row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL ? 1 : 0;
            //$replies = ($this->auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
            $replies = $this->content_visibility->get_count('topic_posts', $row, $forum_id) - 1;
            if ($unread_only) {
                topic_status($row, $replies, true, $folder_img, $folder_alt, $topic_type);
                $unread_topic = true;
            } else {
                topic_status($row, $replies, isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']] ? true : false, $folder_img, $folder_alt, $topic_type);
                $unread_topic = isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']] ? true : false;
            }
            $view_topic_url = append_sid("{$this->root_path}viewtopic.{$this->phpEx}", 'f=' . $forum_id . '&amp;t=' . $topic_id);
            $view_forum_url = append_sid("{$this->root_path}viewforum.{$this->phpEx}", 'f=' . $forum_id);
            $topic_unapproved = $row['topic_visibility'] == ITEM_UNAPPROVED && $this->auth->acl_get('m_approve', $forum_id);
            $posts_unapproved = $row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $this->auth->acl_get('m_approve', $forum_id);
            $u_mcp_queue = $topic_unapproved || $posts_unapproved ? append_sid("{$this->root_path}mcp.{$this->phpEx}", 'i=queue&amp;mode=' . ($topic_unapproved ? 'approve_details' : 'unapproved_posts') . "&amp;t={$topic_id}", true, $this->user->session_id) : '';
            $s_type_switch = $row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL ? 1 : 0;
            if (!empty($icons[$row['icon_id']])) {
                $topic_icons[] = $topic_id;
            }
            // Get folder img, topic status/type related information
            $folder_img = $folder_alt = $topic_type = '';
            topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
            $tpl_ary = array('FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'FIRST_POST_TIME' => $this->user->format_date($row['topic_time']), 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']), 'LAST_POST_TIME' => $this->user->format_date($row['topic_last_post_time']), 'LAST_VIEW_TIME' => $this->user->format_date($row['topic_last_view_time']), 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'REPLIES' => $replies, 'VIEWS' => $row['topic_views'], 'TOPIC_TITLE' => censor_text($row['topic_title']), 'FORUM_NAME' => $row['forum_name'], 'TOPIC_TYPE' => $topic_type, 'TOPIC_IMG_STYLE' => $folder_img, 'TOPIC_FOLDER_IMG' => $this->user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_ALT' => $this->user->lang[$folder_alt], 'TOPIC_ICON_IMG' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['img'] : '', 'TOPIC_ICON_IMG_WIDTH' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_HEIGHT' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['height'] : '', 'ATTACH_ICON_IMG' => $this->auth->acl_get('u_download') && $this->auth->acl_get('f_download', $forum_id) && $row['topic_attachment'] ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : '', 'UNAPPROVED_IMG' => $topic_unapproved || $posts_unapproved ? $this->user->img('icon_topic_unapproved', $topic_unapproved ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', 'REPORTED_IMG' => $row['topic_reported'] && $this->auth->acl_get('m_report', $forum_id) ? $this->user->img('icon_topic_reported', 'TOPIC_REPORTED') : '', 'S_HAS_POLL' => $row['poll_start'] ? true : false, 'S_TOPIC_TYPE' => $row['topic_type'], 'S_USER_POSTED' => isset($row['topic_posted']) && $row['topic_posted'] ? true : false, 'S_UNREAD_TOPIC' => $unread_topic, 'S_TOPIC_REPORTED' => $row['topic_reported'] && $this->auth->acl_get('m_report', $forum_id) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_POST_ANNOUNCE' => $row['topic_type'] == POST_ANNOUNCE ? true : false, 'S_POST_GLOBAL' => $row['topic_type'] == POST_GLOBAL ? true : false, 'S_POST_STICKY' => $row['topic_type'] == POST_STICKY ? true : false, 'S_TOPIC_LOCKED' => $row['topic_status'] == ITEM_LOCKED ? true : false, 'S_TOPIC_MOVED' => $row['topic_status'] == ITEM_MOVED ? true : false, 'S_TOPIC_TYPE_SWITCH' => $s_type_switch == $s_type_switch_test ? -1 : $s_type_switch_test, 'U_NEWEST_POST' => $view_topic_url . '&amp;view=unread#unread', 'U_LAST_POST' => $view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'], 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'U_VIEW_TOPIC' => $view_topic_url, 'U_VIEW_FORUM' => $view_forum_url, 'U_MCP_REPORT' => append_sid("{$this->root_path}mcp.{$this->phpEx}", 'i=reports&amp;mode=reports&amp;f=' . $forum_id . '&amp;t=' . $topic_id, true, $this->user->session_id), 'U_MCP_QUEUE' => $u_mcp_queue);
            /**
             * Modify the topic data before it is assigned to the template
             *
             * @event paybas.recenttopics.modify_tpl_ary
             * @var    array    row            Array with topic data
             * @var    array    tpl_ary        Template block array with topic data
             * @since 2.0.0
             */
            $vars = array('row', 'tpl_ary');
            extract($this->dispatcher->trigger_event('paybas.recenttopics.modify_tpl_ary', compact($vars)));
            $this->template->assign_block_vars($tpl_loopname, $tpl_ary);
            $this->pagination->generate_template_pagination($view_topic_url, $tpl_loopname . '.pagination', 'start', $replies + 1, $this->config['posts_per_page'], 1, true, true);
            if ($display_parent_forums) {
                $forum_parents = get_forum_parents($row);
                foreach ($forum_parents as $parent_id => $data) {
                    $this->template->assign_block_vars($tpl_loopname . '.parent_forums', array('FORUM_ID' => $parent_id, 'FORUM_NAME' => $data[0], 'U_VIEW_FORUM' => append_sid("{$this->root_path}viewforum.{$this->phpEx}", 'f=' . $parent_id)));
                }
            }
        }
        // Get URL-parameters for pagination
        $url_params = explode('&', $this->user->page['query_string']);
        $append_params = false;
        foreach ($url_params as $param) {
            if (!$param) {
                continue;
            }
            if (strpos($param, '=') === false) {
                // Fix MSSTI Advanced BBCode MOD
                $append_params[$param] = '1';
                continue;
            }
            list($name, $value) = explode('=', $param);
            if ($name != $tpl_loopname . '_start') {
                $append_params[$name] = $value;
            }
        }
        $pagination_url = append_sid($this->root_path . $this->user->page['page_name'], $append_params);
        $this->pagination->generate_template_pagination($pagination_url, 'rt_pagination', $tpl_loopname . '_start', $topics_count, $topics_per_page, $start);
        $this->template->assign_vars(array('RT_SORT_START_TIME' => $sort_topics === 'topic_time' ? true : false, 'S_TOPIC_ICONS' => sizeof($topic_icons) ? true : false, 'NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'LAST_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'POLL_IMG' => $this->user->img('icon_topic_poll', 'TOPIC_POLL'), strtoupper($tpl_loopname) . '_DISPLAY' => true));
    }
Пример #11
0
    /**
     * Get similar topics by matching topic titles
     *
     * NOTE: Currently requires MySQL due to the use of FULLTEXT indexes
     * and MATCH and AGAINST and UNIX_TIMESTAMP. MySQL FULLTEXT has built-in
     * English ignore words. We use phpBB's ignore words for non-English
     * languages. We also remove any admin-defined special ignore words.
     *
     * @param	array	$topic_data	Array with topic data
     * @return 	null
     * @access	public
     */
    public function display_similar_topics($topic_data)
    {
        $topic_title = $this->clean_topic_title($topic_data['topic_title']);
        // If the cleaned up topic_title is empty, no need to continue
        if (empty($topic_title)) {
            return;
        }
        // Similar Topics query
        $sql_array = array('SELECT' => "f.forum_id, f.forum_name, t.*,\n\t\t\t\tMATCH (t.topic_title) AGAINST ('" . $this->db->sql_escape($topic_title) . "') AS score", 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id')), 'WHERE' => "MATCH (t.topic_title) AGAINST ('" . $this->db->sql_escape($topic_title) . "') >= 0.5\n\t\t\t\tAND t.topic_status <> " . ITEM_MOVED . '
				AND t.topic_visibility = ' . ITEM_APPROVED . '
				AND t.topic_time > (UNIX_TIMESTAMP() - ' . $this->config['similar_topics_time'] . ')
				AND t.topic_id <> ' . (int) $topic_data['topic_id']);
        // Add topic tracking data to the query (only if query caching is off)
        if ($this->user->data['is_registered'] && $this->config['load_db_lastread'] && !$this->config['similar_topics_cache']) {
            $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $this->user->data['user_id']);
            $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = f.forum_id AND ft.user_id = ' . $this->user->data['user_id']);
            $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as f_mark_time';
        } else {
            if ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) {
                // Cookie based tracking copied from search.php
                $tracking_topics = $this->request->variable($this->config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);
                $tracking_topics = $tracking_topics ? tracking_unserialize($tracking_topics) : array();
            }
        }
        // We need to exclude passworded forums so we do not leak the topic title
        $passworded_forums = $this->user->get_passworded_forums();
        // See if the admin set this forum to only search a specific group of other forums, and include them
        if (!empty($topic_data['similar_topic_forums'])) {
            // Remove any passworded forums from this group of forums we will be searching
            $included_forums = array_diff(explode(',', $topic_data['similar_topic_forums']), $passworded_forums);
            // if there's nothing left to display (user has no access to the forums we want to search)
            if (empty($included_forums)) {
                return;
            }
            $sql_array['WHERE'] .= ' AND ' . $this->db->sql_in_set('f.forum_id', $included_forums);
        } else {
            if (!empty($this->config['similar_topics_ignore'])) {
                // Add passworded forums to the exlude array
                $excluded_forums = array_unique(array_merge(explode(',', $this->config['similar_topics_ignore']), $passworded_forums));
                $sql_array['WHERE'] .= ' AND ' . $this->db->sql_in_set('f.forum_id', $excluded_forums, true);
            } else {
                if (!empty($passworded_forums)) {
                    $sql_array['WHERE'] .= ' AND ' . $this->db->sql_in_set('f.forum_id', $passworded_forums, true);
                }
            }
        }
        /**
         * Event to modify the sql_array for similar topics
         *
         * @event vse.similartopics.get_topic_data
         * @var	array	sql_array	SQL array to get similar topics data
         * @since 1.3.0
         */
        $vars = array('sql_array');
        extract($this->dispatcher->trigger_event('vse.similartopics.get_topic_data', compact($vars)));
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query_limit($sql, $this->config['similar_topics_limit'], 0, $this->config['similar_topics_cache']);
        // Grab icons
        $icons = $this->cache->obtain_icons();
        $rowset = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            $similar_forum_id = (int) $row['forum_id'];
            $similar_topic_id = (int) $row['topic_id'];
            $rowset[$similar_topic_id] = $row;
            if ($this->auth->acl_get('f_read', $similar_forum_id)) {
                // Get topic tracking info
                if ($this->user->data['is_registered'] && $this->config['load_db_lastread'] && !$this->config['similar_topics_cache']) {
                    $topic_tracking_info = get_topic_tracking($similar_forum_id, $similar_topic_id, $rowset, array($similar_forum_id => $row['f_mark_time']));
                } else {
                    if ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) {
                        $topic_tracking_info = get_complete_topic_tracking($similar_forum_id, $similar_topic_id);
                        if (!$this->user->data['is_registered']) {
                            $this->user->data['user_lastmark'] = isset($tracking_topics['l']) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $this->config['board_startdate']) : 0;
                        }
                    }
                }
                // Replies
                $replies = $this->content_visibility->get_count('topic_posts', $row, $similar_forum_id) - 1;
                // Get folder img, topic status/type related information
                $folder_img = $folder_alt = $topic_type = '';
                $unread_topic = isset($topic_tracking_info[$similar_topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$similar_topic_id] ? true : false;
                topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
                $topic_unapproved = $row['topic_visibility'] == ITEM_UNAPPROVED && $this->auth->acl_get('m_approve', $similar_forum_id) ? true : false;
                $posts_unapproved = $row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $this->auth->acl_get('m_approve', $similar_forum_id) ? true : false;
                //$topic_deleted = $row['topic_visibility'] == ITEM_DELETED;
                $u_mcp_queue = $topic_unapproved || $posts_unapproved ? append_sid("{$this->root_path}mcp.{$this->php_ext}", 'i=queue&amp;mode=' . ($topic_unapproved ? 'approve_details' : 'unapproved_posts') . "&amp;t={$similar_topic_id}", true, $this->user->session_id) : '';
                //$u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? append_sid("{$this->root_path}mcp.{$this->php_ext}", "i=queue&amp;mode=deleted_topics&amp;t=$similar_topic_id", true, $this->user->session_id) : $u_mcp_queue;
                $base_url = append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'f=' . $similar_forum_id . '&amp;t=' . $similar_topic_id);
                $topic_row = array('TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'FIRST_POST_TIME' => $this->user->format_date($row['topic_time']), 'LAST_POST_TIME' => $this->user->format_date($row['topic_last_post_time']), 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'TOPIC_REPLIES' => $replies, 'TOPIC_VIEWS' => $row['topic_views'], 'TOPIC_TITLE' => $row['topic_title'], 'FORUM_TITLE' => $row['forum_name'], 'TOPIC_IMG_STYLE' => $folder_img, 'TOPIC_FOLDER_IMG' => $this->user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_ALT' => $this->user->lang($folder_alt), 'TOPIC_ICON_IMG' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['img'] : '', 'TOPIC_ICON_IMG_WIDTH' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_HEIGHT' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['height'] : '', 'ATTACH_ICON_IMG' => $this->auth->acl_get('u_download') && $this->auth->acl_get('f_download', $similar_forum_id) && $row['topic_attachment'] ? $this->user->img('icon_topic_attach', $this->user->lang('TOTAL_ATTACHMENTS')) : '', 'UNAPPROVED_IMG' => $topic_unapproved || $posts_unapproved ? $this->user->img('icon_topic_unapproved', $topic_unapproved ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', 'S_UNREAD_TOPIC' => $unread_topic, 'S_TOPIC_REPORTED' => !empty($row['topic_reported']) && $this->auth->acl_get('m_report', $similar_forum_id) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_HAS_POLL' => $row['poll_start'] ? true : false, 'U_NEWEST_POST' => append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'f=' . $similar_forum_id . '&amp;t=' . $similar_topic_id . '&amp;view=unread') . '#unread', 'U_LAST_POST' => append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'f=' . $similar_forum_id . '&amp;t=' . $similar_topic_id . '&amp;p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'], 'U_VIEW_TOPIC' => append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'f=' . $similar_forum_id . '&amp;t=' . $similar_topic_id), 'U_VIEW_FORUM' => append_sid("{$this->root_path}viewforum.{$this->php_ext}", 'f=' . $similar_forum_id), 'U_MCP_REPORT' => append_sid("{$this->root_path}mcp.{$this->php_ext}", 'i=reports&amp;mode=reports&amp;f=' . $similar_forum_id . '&amp;t=' . $similar_topic_id, true, $this->user->session_id), 'U_MCP_QUEUE' => $u_mcp_queue);
                /**
                 * Event to modify the similar topics template block
                 *
                 * @event vse.similartopics.modify_topicrow
                 * @var	array	row			Array with similar topic data
                 * @var	array	topic_row	Template block array
                 * @since 1.3.0
                 */
                $vars = array('row', 'topic_row');
                extract($this->dispatcher->trigger_event('vse.similartopics.modify_topicrow', compact($vars)));
                $this->template->assign_block_vars('similar', $topic_row);
                $this->pagination->generate_template_pagination($base_url, 'similar.pagination', 'start', $replies + 1, $this->config['posts_per_page'], 1, true, true);
            }
        }
        $this->db->sql_freeresult($result);
        $this->user->add_lang_ext('vse/similartopics', 'similar_topics');
        $this->template->assign_vars(array('L_SIMILAR_TOPICS' => $this->user->lang('SIMILAR_TOPICS'), 'NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'LAST_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'REPORTED_IMG' => $this->user->img('icon_topic_reported', 'TOPIC_REPORTED'), 'POLL_IMG' => $this->user->img('icon_topic_poll', 'TOPIC_POLL')));
    }
Пример #12
0
    public function topposts_of_period($tpl_loopname = 'post_of_the_day', $period = 'month')
    {
        switch ($period) {
            case 'day':
                $howmany = $this->config['post_of_the_day_how_many_today'];
                $period_time = SECONDS_PER_DAY;
                $slack_time = SECONDS_PER_HOUR;
                $cache_time = SECONDS_PER_MINUTE;
                $period_name = 'LIKES_TODAY';
                break;
            case 'week':
                $howmany = $this->config['post_of_the_day_how_many_this_week'];
                $period_time = SECONDS_PER_DAY * 7;
                $slack_time = SECONDS_PER_HOUR * 12;
                $cache_time = SECONDS_PER_MINUTE;
                $period_name = 'LIKES_THIS_WEEK';
                break;
            case 'month':
                $howmany = $this->config['post_of_the_day_how_many_this_month'];
                $period_time = SECONDS_PER_DAY * 31;
                $slack_time = SECONDS_PER_HOUR * 12;
                $cache_time = SECONDS_PER_MINUTE;
                $period_name = 'LIKES_THIS_MONTH';
                break;
            case 'year':
                $howmany = $this->config['post_of_the_day_how_many_this_year'];
                $period_time = SECONDS_PER_DAY * 366;
                $slack_time = SECONDS_PER_HOUR * 12;
                $cache_time = SECONDS_PER_MINUTE;
                $period_name = 'LIKES_THIS_YEAR';
                break;
        }
        if ($howmany == 0) {
            return;
        }
        $forum_ary = array();
        $forum_read_ary = $this->auth->acl_getf('f_read');
        foreach ($forum_read_ary as $forum_id => $allowed) {
            if ($allowed['f_read']) {
                $forum_ary[] = (int) $forum_id;
            }
        }
        $forum_ary = array_unique($forum_ary);
        if (sizeof($forum_ary)) {
            // calculate the timestamp that we are interested in
            $time_threshold = time() - $period_time;
            // floor to an even hour to improve sql caching performance
            $time_threshold = $time_threshold - $time_threshold % $slack_time;
            /**
             * Select post_ids
             */
            // find all the visible, liked posts in the given period
            $sql = 'SELECT ' . USERS_TABLE . '.user_id, ' . USERS_TABLE . '.username, ' . USERS_TABLE . '.user_colour, ' . TOPICS_TABLE . '.topic_title, ' . TOPICS_TABLE . '.forum_id, ' . TOPICS_TABLE . '.topic_id, ' . POSTS_TABLE . '.post_id, ' . POSTS_TABLE . '.post_time, ' . TOPICS_TABLE . '.topic_last_poster_name, ' . TOPICS_TABLE . '.topic_type, ' . FORUMS_TABLE . '.forum_name, sum_likes 
                    FROM ( 
                        SELECT post_id AS post, COUNT(*) AS sum_likes
                        FROM ' . POSTS_LIKES_TABLE . ' 
                        WHERE ' . POSTS_LIKES_TABLE . '.timestamp > ' . $time_threshold . '
                        GROUP BY post_id 
                        ORDER BY sum_likes DESC
                ) AS liked_posts
                LEFT JOIN ' . POSTS_TABLE . ' ON post = post_id
                LEFT JOIN ' . TOPICS_TABLE . ' ON ' . POSTS_TABLE . '.topic_id = ' . TOPICS_TABLE . '.topic_id
                LEFT JOIN ' . USERS_TABLE . ' ON ' . POSTS_TABLE . '.poster_id = ' . USERS_TABLE . '.user_id
                LEFT JOIN ' . FORUMS_TABLE . ' ON ' . TOPICS_TABLE . '.forum_id = ' . FORUMS_TABLE . '.forum_id
				WHERE  ' . $this->content_visibility->get_forums_visibility_sql('post', $forum_ary, POSTS_TABLE . '.') . '
				AND topic_status <> ' . ITEM_MOVED . '
                ORDER BY sum_likes DESC, post_time DESC';
            // cache the query for one minute
            $result = $this->db->sql_query_limit($sql, $howmany, 0, $cache_time);
            $forums = $ga_topic_ids = $topic_ids = array();
            while ($row = $this->db->sql_fetchrow($result)) {
                $topic_ids[] = $row['topic_id'];
                if ($row['topic_type'] == POST_GLOBAL) {
                    $ga_topic_ids[] = $row['topic_id'];
                } else {
                    $forums[$row['forum_id']][] = $row['topic_id'];
                }
            }
            // Get topic tracking
            $topic_tracking_info = array();
            foreach ($forums as $forum_id => $topic_id) {
                $topic_tracking_info[$forum_id] = get_complete_topic_tracking($forum_id, $topic_id, $ga_topic_ids);
            }
            $this->db->sql_rowseek(0, $result);
            while ($row = $this->db->sql_fetchrow($result)) {
                $topic_id = $row['topic_id'];
                $forum_id = $row['forum_id'];
                $forum_name = $row['forum_name'];
                $post_unread = isset($topic_tracking_info[$forum_id][$topic_id]) && $row['post_time'] > $topic_tracking_info[$forum_id][$topic_id] ? true : false;
                $view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id'] . '&amp;p=' . $row['post_id'] . '#p' . $row['post_id']);
                $forum_name_url = append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $row['forum_id']);
                $topic_title = censor_text($row['topic_title']);
                if (utf8_strlen($topic_title) >= 60) {
                    $topic_title = utf8_strlen($topic_title) > 60 + 3 ? utf8_substr($topic_title, 0, 60) . '...' : $topic_title;
                }
                $is_guest = $row['user_id'] == ANONYMOUS ? true : false;
                $tpl_ary = array('U_TOPIC' => $view_topic_url, 'U_FORUM' => $forum_name_url, 'S_UNREAD' => $post_unread ? true : false, 'USERNAME_FULL' => $is_guest || !$this->auth->acl_get('u_viewprofile') ? $this->user->lang['POST_BY_AUTHOR'] . ' ' . get_username_string('no_profile', $row['user_id'], $row['username'], $row['user_colour'], $row['topic_last_poster_name']) : $this->user->lang['POST_BY_AUTHOR'] . ' ' . get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'POST_TIME' => $this->user->format_date($row['post_time']), 'TOPIC_TITLE' => $topic_title, 'FORUM_NAME' => $forum_name, 'POST_LIKES_IN_PERIOD' => $this->user->lang($period_name, $row['sum_likes']));
                /**
                 * Modify the topic data before it is assigned to the template
                 *
                 * @event v12mike.postoftheday.modify_tpl_ary
                 * @var	array	row			Array with topic data
                 * @var	array	tpl_ary		Template block array with topic data
                 * @since 1.0.0
                 */
                $vars = array('row', 'tpl_ary');
                extract($this->dispatcher->trigger_event('v12mike.postoftheday.modify_tpl_ary', compact($vars)));
                $this->template->assign_block_vars($tpl_loopname, $tpl_ary);
            }
            $this->db->sql_freeresult($result);
        } else {
            $this->template->assign_block_vars($tpl_loopname, array('NO_TOPIC_TITLE' => $this->user->lang['NO_TOPIC_EXIST']));
        }
    }
Пример #13
0
    public function toptopics($tpl_loopname = 'top_five_topic')
    {
        $howmany = $this->howmany();
        $forum_ary = array();
        $forum_read_ary = $this->auth->acl_getf('f_read');
        foreach ($forum_read_ary as $forum_id => $allowed) {
            if ($allowed['f_read']) {
                $forum_ary[] = (int) $forum_id;
            }
        }
        $forum_ary = array_unique($forum_ary);
        if (sizeof($forum_ary)) {
            /**
             * Select topic_ids
             */
            $sql = 'SELECT forum_id, topic_id, topic_type
				FROM ' . TOPICS_TABLE . '
				WHERE ' . $this->content_visibility->get_forums_visibility_sql('topic', $forum_ary) . '
				AND topic_status <> ' . ITEM_MOVED . '
				ORDER BY topic_last_post_time DESC';
            $result = $this->db->sql_query_limit($sql, $howmany);
            $forums = $ga_topic_ids = $topic_ids = array();
            while ($row = $this->db->sql_fetchrow($result)) {
                $topic_ids[] = $row['topic_id'];
                if ($row['topic_type'] == POST_GLOBAL) {
                    $ga_topic_ids[] = $row['topic_id'];
                } else {
                    $forums[$row['forum_id']][] = $row['topic_id'];
                }
            }
            $this->db->sql_freeresult($result);
            // Get topic tracking
            $topic_tracking_info = array();
            foreach ($forums as $forum_id => $topic_id) {
                $topic_tracking_info[$forum_id] = get_complete_topic_tracking($forum_id, $topic_id, $ga_topic_ids);
            }
            /*
             * must have topic_ids.
             * A user can have forums and not have topic_ids before installing this extension
             */
            if (sizeof($topic_ids)) {
                // grab all posts that meet criteria and auths
                $sql_array = array('SELECT' => 'u.user_id, u.username, u.user_colour, t.topic_title, t.forum_id, t.topic_id, t.topic_first_post_id, t.topic_last_post_id, t.topic_last_post_time, t.topic_last_poster_name, f.forum_name', 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 't.topic_last_poster_id = u.user_id'), array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 't.forum_id = f.forum_id')), 'WHERE' => $this->db->sql_in_set('t.topic_id', $topic_ids), 'ORDER_BY' => 't.topic_last_post_time DESC');
                /**
                 * Event to modify the SQL query before the topics data is retrieved
                 *
                 * @event rmcgirr83.topfive.sql_pull_topics_data
                 * @var	array	sql_array		The SQL array
                 * @since 1.0.0
                 */
                $vars = array('sql_array');
                extract($this->dispatcher->trigger_event('rmcgirr83.topfive.sql_pull_topics_data', compact($vars)));
                // cache the query for one minute
                $result = $this->db->sql_query_limit($this->db->sql_build_query('SELECT', $sql_array), $howmany, 0, 60);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $topic_id = $row['topic_id'];
                    $forum_id = $row['forum_id'];
                    $forum_name = $row['forum_name'];
                    $post_unread = isset($topic_tracking_info[$forum_id][$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$topic_id] ? true : false;
                    $view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $row['forum_id'] . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id']);
                    $forum_name_url = append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $row['forum_id']);
                    $topic_title = censor_text($row['topic_title']);
                    $topic_title = truncate_string($topic_title, 60, 255, false, $this->user->lang['ELLIPSIS']);
                    $is_guest = $row['user_id'] == ANONYMOUS ? true : false;
                    $tpl_ary = array('U_TOPIC' => $view_topic_url, 'U_FORUM' => $forum_name_url, 'S_UNREAD' => $post_unread ? true : false, 'USERNAME_FULL' => $is_guest || !$this->auth->acl_get('u_viewprofile') ? $this->user->lang['POST_BY_AUTHOR'] . ' ' . get_username_string('no_profile', $row['user_id'], $row['username'], $row['user_colour'], $row['topic_last_poster_name']) : $this->user->lang['POST_BY_AUTHOR'] . ' ' . get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'LAST_TOPIC_TIME' => $this->user->format_date($row['topic_last_post_time']), 'TOPIC_TITLE' => $topic_title, 'FORUM_NAME' => $forum_name);
                    /**
                     * Modify the topic data before it is assigned to the template
                     *
                     * @event rmcgirr83.topfive.modify_tpl_ary
                     * @var	array	row			Array with topic data
                     * @var	array	tpl_ary		Template block array with topic data
                     * @since 1.0.0
                     */
                    $vars = array('row', 'tpl_ary');
                    extract($this->dispatcher->trigger_event('rmcgirr83.topfive.modify_tpl_ary', compact($vars)));
                    $this->template->assign_block_vars($tpl_loopname, $tpl_ary);
                }
                $this->db->sql_freeresult($result);
            } else {
                $this->template->assign_block_vars($tpl_loopname, array('NO_TOPIC_TITLE' => $this->user->lang['NO_TOPIC_EXIST']));
            }
        } else {
            $this->template->assign_block_vars($tpl_loopname, array('NO_TOPIC_TITLE' => $this->user->lang['NO_TOPIC_EXIST']));
        }
    }