예제 #1
0
function socialit_hide_show_do()
{
    if (bb_is_topic() && $_GET['socialit_hide_show'] == "1" && isset($_GET['shs_opt']) && isset($_GET['tid']) && bb_current_user_can('moderate')) {
        $topic = get_topic($_GET['tid']);
        if (bb_verify_nonce($_GET['_wpnonce'], 'socialit_hide_show_' . $topic->topic_id)) {
            if ($_GET['shs_opt'] == "2") {
                bb_update_topicmeta($topic->topic_id, 'hide_socialit', 'true');
            } else {
                bb_delete_topicmeta($topic->topic_id, 'hide_socialit');
            }
        } else {
            _e('Sorry, but that could not be done.', 'socialit');
            exit;
        }
        wp_redirect(get_topic_link($topic->topic_id));
    }
}
예제 #2
0
function best_answer_init()
{
    global $best_answer, $topic, $bb_current_user, $posts, $page;
    if (!empty($best_answer['forums']) && !isset($best_answer['forums'][$topic->forum_id])) {
        return;
    }
    add_action('best_answer', 'best_answer');
    add_action('best-answer', 'best_answer');
    add_filter('best_answer_class', 'best_answer_class');
    if ($best_answer['automatic']) {
        add_filter('post_author_title', 'best_answer_filter', 300);
        add_filter('post_author_title_link', 'best_answer_filter', 300);
    }
    if (!empty($bb_current_user->ID) && $bb_current_user->ID == $topic->topic_poster || bb_current_user_can('moderate')) {
        $best_answer['can_edit'] = true;
    } else {
        $best_answer['can_edit'] = false;
    }
    if (empty($topic->best_answer)) {
        $topic->best_answer = array();
    } elseif (!is_array($topic->best_answer)) {
        (array) ($topic->best_answer = explode(',', $topic->best_answer));
    }
    $topic->best_answer = array_flip($topic->best_answer);
    // speedup by using post id as key
    if (!empty($topic->topic_id) && !empty($_GET['best_answer']) && $best_answer['can_edit']) {
        $value = intval($_GET['best_answer']);
        if (isset($topic->best_answer[$value])) {
            unset($topic->best_answer[$value]);
        } else {
            if ($best_answer['max'] == 1) {
                $topic->best_answer = array();
            }
            $topic->best_answer[$value] = $value;
        }
        if (empty($topic->best_answer)) {
            bb_delete_topicmeta($topic->topic_id, 'best_answer');
        } else {
            bb_update_topicmeta($topic->topic_id, 'best_answer', implode(',', array_flip($topic->best_answer)));
        }
        wp_redirect(get_post_link($value));
        exit;
    }
    $best_answer[$topic->topic_id] = $topic->best_answer;
    $best_answer['count'] = count($topic->best_answer);
    if ($best_answer['display_first'] && !empty($best_answer[$topic->topic_id])) {
        // move best answer(s) to top of topic
        if ($page == 1) {
            $question = $posts[0];
            unset($posts[0]);
        }
        foreach ($posts as $key => $bb_post) {
            if ($bb_post->post_status == 0 && isset($best_answer[$topic->topic_id][$bb_post->post_id])) {
                unset($posts[$key]);
            }
        }
        if ($page == 1) {
            foreach ($best_answer[$topic->topic_id] as $post_id => $ignore) {
                $best = bb_get_post($post_id);
                if ($best->post_status == 0) {
                    array_unshift($posts, $best);
                } else {
                    unset($best_answer[$topic->topic_id][$post_id]);
                }
            }
            array_unshift($posts, $question);
        }
    }
}