Esempio n. 1
0
function api_utils_ensure_pagination_args(&$args)
{
    if ($page = request_int32("page")) {
        $args['page'] = $page;
    }
    if ($per_page = request_int32("per_page")) {
        $args['per_page'] = $per_page;
    }
    if (!$args['page']) {
        $args['page'] = 1;
    }
    if (!$args['per_page']) {
        $args['per_page'] = $GLOBALS['cfg']['api_per_page_default'];
    } else {
        if ($args['per_page'] > $GLOBALS['cfg']['api_per_page_max']) {
            $args['per_page'] = $GLOBALS['cfg']['api_per_page_max'];
        }
    }
    # note the pass by ref
}
$GLOBALS['smarty']->assign_by_ref("permissions", $perms_map);
$ttl_map = api_oauth2_access_tokens_ttl_map();
$GLOBALS['smarty']->assign_by_ref("ttl_map", $ttl_map);
# Handy helper mode to create auth tokens for yourself...
if (request_isset("self")) {
    features_ensure_enabled("api_authenticate_self");
    if ($key_row['user_id'] != $GLOBALS['cfg']['user']['id']) {
        error_403();
    }
    if ($token_row = api_oauth2_access_tokens_get_for_user_and_key($GLOBALS['cfg']['user'], $key_row)) {
        $GLOBALS['smarty']->assign_by_ref("token_row", $token_row);
        $GLOBALS['smarty']->assign("has_token", 1);
    } else {
        if (post_isset("confirm") && crumb_check($crumb_key)) {
            $perms = request_str("perms");
            $ttl = request_int32("ttl");
            if (!api_oauth2_access_tokens_is_valid_permission($perms)) {
                $GLOBALS['smarty']->assign("error", "bad_perms");
            } else {
                $rsp = api_oauth2_access_tokens_create($key_row, $GLOBALS['cfg']['user'], $perms, $ttl);
                $GLOBALS['smarty']->assign_by_ref("token_rsp", $rsp);
            }
        } else {
        }
    }
    $GLOBALS['smarty']->display("page_api_oauth2_authenticate_self.txt");
    exit;
}
# Okay, let's do this
$ok = 1;
$scope = request_str("scope");