Example #1
0
/**
 * Get details of a topic (to show eventually as a row in a forum or results view). This is a helper function, and thus the interface is not very user friendly.
 *
 * @param  array		The DB row of the topic.
 * @param  MEMBER		The member the details are being prepared for.
 * @param  integer	The hot topic definition (taken from the config options).
 * @param  boolean	Whether the viewing member has a post in the topic.
 * @return array		The details.
 */
function ocf_get_topic_array($topic_row, $member_id, $hot_topic_definition, $involved)
{
    $topic = array();
    if (is_null($topic_row['t_cache_first_post']) || $topic_row['t_cache_first_post'] === 0) {
        $topic['first_post'] = new ocp_tempcode();
    } else {
        if (!is_null($topic_row['_trans_post']) && $topic_row['_trans_post'] != '') {
            $topic['first_post'] = new ocp_tempcode();
            if (!$topic['first_post']->from_assembly($topic_row['_trans_post'])) {
                $topic_row['_trans_post'] = NULL;
            }
        }
        if (is_null($topic_row['_trans_post']) || $topic_row['_trans_post'] == '') {
            if (!is_null($topic_row['t_cache_first_post'])) {
                $topic['first_post'] = get_translated_tempcode($topic_row['t_cache_first_post'], $GLOBALS['FORUM_DB']);
            } else {
                $topic['first_post'] = new ocp_tempcode();
            }
        } else {
            $topic['first_post']->singular_bind('ATTACHMENT_DOWNLOADS', make_string_tempcode('?'));
        }
    }
    // Pre-load it, so meta-data isn't altered later
    $bak = $GLOBALS['META_DATA'];
    $topic['first_post'] = get_translated_tempcode($topic_row['t_cache_first_post'], $GLOBALS['FORUM_DB']);
    $topic['first_post']->evaluate();
    $GLOBALS['META_DATA'] = $bak;
    $topic['id'] = $topic_row['id'];
    $topic['num_views'] = $topic_row['t_num_views'];
    $topic['num_posts'] = $topic_row['t_cache_num_posts'];
    $topic['forum_id'] = $topic_row['t_forum_id'];
    $topic['description'] = $topic_row['t_description'];
    $topic['description_link'] = $topic_row['t_description_link'];
    // If it's a spacer post, we need to intercede at this point, and make a better one
    $linked_type = '';
    $linked_id = '';
    $is_spacer_post = substr($topic['first_post']->evaluate(), 0, strlen(do_lang('SPACER_POST_MATCHER'))) == do_lang('SPACER_POST_MATCHER');
    if ($is_spacer_post) {
        $c_prefix = do_lang('COMMENT') . ': #';
        if (substr($topic['description'], 0, strlen($c_prefix)) == $c_prefix && $topic['description_link'] != '') {
            list($linked_type, $linked_id) = explode('_', substr($topic['description'], strlen($c_prefix)), 2);
            $topic['description'] = '';
            require_code('ocf_posts');
            list(, $new_post) = ocf_display_spacer_post($linked_type, $linked_id);
            if (!is_null($new_post)) {
                $topic['first_post'] = $new_post;
            }
        }
    }
    $topic['emoticon'] = $topic_row['t_emoticon'];
    $topic['first_time'] = $topic_row['t_cache_first_time'];
    $topic['first_title'] = $topic_row['t_cache_first_title'];
    if ($topic['first_title'] == '') {
        $topic['first_title'] = do_lang_tempcode('NA');
    }
    if ($is_spacer_post) {
        $topic['first_title'] = do_lang('SPACER_TOPIC_TITLE_WRAP', $topic['first_title']);
    }
    $topic['first_username'] = $topic_row['t_cache_first_username'];
    $topic['first_member_id'] = $topic_row['t_cache_first_member_id'];
    if (is_null($topic['first_member_id'])) {
        require_code('ocf_posts_action2');
        ocf_force_update_topic_cacheing($topic_row['id'], NULL, true, true);
        //$_topic_row=$GLOBALS['FORUM_DB']->query_select('f_topics',array('*'),array('id'=>$topic_row['id']),'',1);
        //$topic_row=$_topic_row[0];
        //$topic['first_member_id']=$GLOBALS['OCF_DRIVER']->get_guest_id();
    }
    if (!is_null($topic_row['t_cache_last_post_id'])) {
        $topic['last_post_id'] = $topic_row['t_cache_last_post_id'];
        $topic['last_time'] = $topic_row['t_cache_last_time'];
        $topic['last_time_string'] = get_timezoned_date($topic_row['t_cache_last_time']);
        $topic['last_title'] = $topic_row['t_cache_last_title'];
        $topic['last_username'] = $topic_row['t_cache_last_username'];
        $topic['last_member_id'] = $topic_row['t_cache_last_member_id'];
    }
    // Modifiers
    $topic['modifiers'] = array();
    $has_read = ocf_has_read_topic($topic['id'], $topic_row['t_cache_last_time'], $member_id, $topic_row['l_time']);
    if (!$has_read) {
        $topic['modifiers'][] = 'unread';
    }
    if ($involved) {
        $topic['modifiers'][] = 'involved';
    }
    if ($topic_row['t_cascading'] == 1) {
        $topic['modifiers'][] = 'announcement';
    }
    if ($topic_row['t_pinned'] == 1) {
        $topic['modifiers'][] = 'pinned';
    }
    if ($topic_row['t_sunk'] == 1) {
        $topic['modifiers'][] = 'sunk';
    }
    if ($topic_row['t_is_open'] == 0) {
        $topic['modifiers'][] = 'closed';
    }
    if ($topic_row['t_validated'] == 0) {
        $topic['modifiers'][] = 'unvalidated';
    }
    if (!is_null($topic_row['t_poll_id'])) {
        $topic['modifiers'][] = 'poll';
    }
    $num_posts = $topic_row['t_cache_num_posts'];
    $start_time = $topic_row['t_cache_first_time'];
    $end_time = $topic_row['t_cache_last_time'];
    $days = floatval($end_time - $start_time) / 60.0 / 60.0 / 24.0;
    if ($days == 0.0) {
        $days = 1.0;
    }
    if ($num_posts >= 8 && intval(round(floatval($num_posts) / $days)) >= $hot_topic_definition) {
        $topic['modifiers'][] = 'hot';
    }
    return $topic;
}
Example #2
0
/**
 * Get a map of details relating to the Private Topics of a certain member.
 *
 * @param  integer	The start row for getting details of topics in the Private Topic forum (i.e. 0 is newest, higher is starting further back in time).
 * @param  ?integer	The maximum number of topics to get detail of (NULL: default).
 * @param  ?MEMBER	The member to get Private Topics of (NULL: current member).
 * @return array		The details.
 */
function ocf_get_personal_topics($start = 0, $max = NULL, $member_id = NULL)
{
    if (is_null($max)) {
        $max = intval(get_option('forum_topics_per_page'));
    }
    if (is_null($member_id)) {
        $member_id = get_member();
    } else {
        if (!has_specific_permission(get_member(), 'view_other_pt') && $member_id != get_member()) {
            access_denied('SPECIFIC_PERMISSION', 'view_other_pt');
        }
    }
    // Find topics
    $where = '(t_pt_from=' . strval($member_id) . ' OR t_pt_to=' . strval($member_id) . ') AND t_forum_id IS NULL';
    $filter = get_param('category', '');
    $where .= ' AND (' . db_string_equal_to('t_pt_from_category', $filter) . ' AND t_pt_from=' . strval($member_id) . ' OR ' . db_string_equal_to('t_pt_to_category', $filter) . ' AND t_pt_to=' . strval($member_id) . ')';
    $query = 'FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE ' . $where;
    $max_rows = 0;
    $union = '';
    if ($filter == do_lang('INVITED_TO_PTS')) {
        global $SITE_INFO;
        if (!(isset($SITE_INFO['mysql_old']) && $SITE_INFO['mysql_old'] == '1' || !isset($SITE_INFO['mysql_old']) && is_file(get_file_base() . '/mysql_old'))) {
            $or_list = '';
            $s_rows = $GLOBALS['FORUM_DB']->query_select('f_special_pt_access', array('s_topic_id'), array('s_member_id' => get_member()));
            foreach ($s_rows as $s_row) {
                if ($or_list != '') {
                    $or_list .= ' OR ';
                }
                $or_list .= 'id=' . strval($s_row['s_topic_id']);
            }
            if ($or_list != '') {
                $query2 = 'FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE ' . $or_list;
                $union = ' UNION SELECT * ' . $query2;
                $max_rows += $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT COUNT(*) ' . $query2);
            }
        }
    }
    $order = get_param('order', 'last_time');
    $order2 = 't_cache_last_time DESC';
    if ($order == 'first_post') {
        $order2 = 't_cache_first_time DESC';
    } elseif ($order == 'title') {
        $order2 = 't_cache_first_title ASC';
    }
    if (get_value('disable_sunk') !== '1') {
        $order2 = 't_sunk ASC,' . $order2;
    }
    $topic_rows = $GLOBALS['FORUM_DB']->query('SELECT * ' . $query . $union . ' ORDER BY t_pinned DESC,' . $order2, $max, $start, false, true);
    $max_rows += $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT COUNT(*) ' . $query);
    $topics = array();
    $hot_topic_definition = intval(get_option('hot_topic_definition'));
    foreach ($topic_rows as $topic_row) {
        $topic = array();
        $topic['id'] = $topic_row['id'];
        $topic['num_views'] = $topic_row['t_num_views'];
        $topic['num_posts'] = $topic_row['t_cache_num_posts'];
        $topic['first_time'] = $topic_row['t_cache_first_time'];
        $topic['first_title'] = $topic_row['t_cache_first_title'];
        $topic['first_post'] = is_null($topic_row['t_cache_first_post']) ? new ocp_tempcode() : get_translated_tempcode($topic_row['t_cache_first_post'], $GLOBALS['FORUM_DB']);
        $topic['first_post']->singular_bind('ATTACHMENT_DOWNLOADS', make_string_tempcode('?'));
        $topic['first_username'] = $topic_row['t_cache_first_username'];
        $topic['first_member_id'] = $topic_row['t_cache_first_member_id'];
        $topic['last_post_id'] = $topic_row['t_cache_last_post_id'];
        $topic['last_time'] = $topic_row['t_cache_last_time'];
        $topic['last_time_string'] = is_null($topic_row['t_cache_last_time']) ? '' : get_timezoned_date($topic_row['t_cache_last_time']);
        $topic['last_title'] = $topic_row['t_cache_last_title'];
        $topic['last_username'] = $topic_row['t_cache_last_username'];
        $topic['last_member_id'] = $topic_row['t_cache_last_member_id'];
        $topic['emoticon'] = $topic_row['t_emoticon'];
        $topic['description'] = $topic_row['t_description'];
        $topic['pt_from'] = $topic_row['t_pt_from'];
        $topic['pt_to'] = $topic_row['t_pt_to'];
        // Modifiers
        $topic['modifiers'] = array();
        $has_read = ocf_has_read_topic($topic['id'], $topic_row['t_cache_last_time'], $member_id);
        if (!$has_read) {
            $topic['modifiers'][] = 'unread';
        }
        if ($topic_row['t_pinned'] == 1) {
            $topic['modifiers'][] = 'pinned';
        }
        if ($topic_row['t_sunk'] == 1) {
            $topic['modifiers'][] = 'sunk';
        }
        if ($topic_row['t_is_open'] == 0) {
            $topic['modifiers'][] = 'closed';
        }
        if (!is_null($topic_row['t_poll_id'])) {
            $topic['modifiers'][] = 'poll';
        }
        $num_posts = $topic_row['t_cache_num_posts'];
        $start_time = $topic_row['t_cache_first_time'];
        $end_time = $topic_row['t_cache_last_time'];
        $days = floatval($end_time - $start_time) / 60.0 / 60.0 / 24.0;
        if ($days == 0.0) {
            $days = 1.0;
        }
        if (intval(round($num_posts / $days)) >= $hot_topic_definition) {
            $topic['modifiers'][] = 'hot';
        }
        $topics[] = $topic;
    }
    $out = array('topics' => $topics, 'max_rows' => $max_rows);
    if (has_specific_permission($member_id, 'moderate_personal_topic') && ($member_id == get_member() || has_specific_permission($member_id, 'multi_delete_topics'))) {
        $out['may_move_topics'] = 1;
        $out['may_delete_topics'] = 1;
        $out['may_change_max'] = 1;
    }
    if (ocf_may_make_personal_topic()) {
        $out['may_post_topic'] = 1;
    }
    return $out;
}