Esempio n. 1
0
/**
 * Process subscription checkbox submission.
 *
 * Get ID of and new subscription status and pass values to
 * bb_user_subscribe_checkbox_update function
 *
 * @since 1.1
 *
 * @param int $post_id ID of new/edited post
 */
function bb_user_subscribe_checkbox_update($post_id)
{
    if (!bb_is_user_logged_in()) {
        return false;
    }
    $post = bb_get_post($post_id);
    $topic_id = (int) $post->topic_id;
    $subscribed = bb_is_user_subscribed(array('topic_id' => $topic_id, 'user_id' => $post->poster_id)) ? true : false;
    $check = $_REQUEST['subscription_checkbox'];
    do_action('bb_user_subscribe_checkbox_update', $post_id, $topic_id, $subscribe, $check);
    if ('subscribe' == $check && !$subscribed) {
        bb_subscription_management($topic_id, 'add');
    } elseif (!$check && $subscribed) {
        bb_subscription_management($topic_id, 'remove');
    }
}
<?php

if (!isset($_GET['doit']) || 'bb-subscribe' != $_GET['doit']) {
    // sanity check
    bb_die(__('What are you trying to do, exactly?'));
}
if (!bb_is_subscriptions_active()) {
    bb_die(__('You can not subscribe to topics.'));
}
if (!isset($_GET['topic_id'])) {
    bb_die(__('Missing topic ID!'));
}
bb_auth('logged_in');
$topic_id = (int) $_GET['topic_id'];
$topic = get_topic($topic_id);
if (!$topic) {
    bb_die(__('Topic not found! What are you subscribing to?'));
}
bb_check_admin_referer('toggle-subscribe_' . $topic_id);
// Okay, we should be covered now
if (in_array($_GET['and'], array('add', 'remove'))) {
    bb_subscription_management($topic->topic_id, $_GET['and']);
}
nxt_redirect(get_topic_link($topic_id, 1));
exit;