/**
 * Cache collapse API data from the database for the current user.
 * If the collapse cookie has been set, grab the changes and re-save
 * the token, or touch it otherwise.
 * @return void
 */
function collapse_cache_token()
{
    global $g_collapse_cache_token;
    if (!auth_is_user_authenticated() || current_user_is_anonymous()) {
        $g_collapse_cache_token = array();
        return;
    }
    if (isset($g_collapse_cache_token)) {
        return;
    }
    $t_token = token_get_value(TOKEN_COLLAPSE);
    if (!is_null($t_token)) {
        $t_data = json_decode($t_token, true);
    } else {
        $t_data = array();
        $t_data['filter'] = false;
    }
    $g_collapse_cache_token = $t_data;
    $t_cookie = gpc_get_cookie('MANTIS_collapse_settings', '');
    if (false !== $t_cookie && !is_blank($t_cookie)) {
        $t_update = false;
        $t_data = explode('|', $t_cookie);
        foreach ($t_data as $t_pair) {
            $t_pair = explode(':', $t_pair);
            if (false !== $t_pair && count($t_pair) == 2) {
                $g_collapse_cache_token[$t_pair[0]] = true == $t_pair[1];
                $t_update = true;
            }
        }
        if (!$t_update) {
            $t_token = token_get(TOKEN_COLLAPSE);
            $t_update = $t_token !== null;
        }
        if ($t_update) {
            $t_value = json_encode($g_collapse_cache_token);
            token_set(TOKEN_COLLAPSE, $t_value, TOKEN_EXPIRY_COLLAPSE);
        } elseif (token_exists($t_token['id'])) {
            token_touch($t_token['id']);
        }
        gpc_clear_cookie('MANTIS_collapse_settings');
    }
}
Exemple #2
0
function token_ensure_exists($p_token_id)
{
    if (!token_exists($p_token_id)) {
        trigger_error(ERROR_GENERIC, ERROR);
    }
    return true;
}
/**
 * Make sure a token exists.
 * @param integer Token ID
 * @return boolean True if token exists
 */
function token_ensure_exists($p_token_id)
{
    if (!token_exists($p_token_id)) {
        trigger_error(ERROR_TOKEN_NOT_FOUND, ERROR);
    }
    return true;
}