diff --git a/_public.php b/_public.php index eaf7fff..47283ca 100644 --- a/_public.php +++ b/_public.php @@ -13,10 +13,12 @@ class rest extends dcUrlHandlers return; } - //To do make headers optionals - header('Access-Control-Allow-Origin: *'); - header('Access-Control-Allow-Methods: GET, POST'); - header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); + //coors headers + if($core->blog->settings->rest->rest_send_cors_headers){ + header('Access-Control-Allow-Origin: *'); + header('Access-Control-Allow-Methods: GET, POST'); + header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); + } diff --git a/index.php b/index.php index dc4f640..dc026c7 100644 --- a/index.php +++ b/index.php @@ -9,9 +9,9 @@ $apiKey = new ApiKey; $core->blog->settings->addNamespace('rest'); if (is_null($core->blog->settings->rest->rest_active)) { try { - // Default state is active if the comments are configured to allow wiki syntax $core->blog->settings->rest->put('rest_active',false,'boolean',true); $core->blog->settings->rest->put('rest_is_open',false,'boolean',true); + $core->blog->settings->rest->put('rest_send_cors_headers',true,'boolean',true); $core->blog->triggerBlog(); http::redirect($p_url); } @@ -22,6 +22,7 @@ if (is_null($core->blog->settings->rest->rest_active)) { // Getting current parameters $active = (boolean)$core->blog->settings->rest->rest_active; $openApi = (boolean)$core->blog->settings->rest->rest_is_open; +$sendHeaders =(boolean)$core->blog->settings->rest->rest_send_cors_headers; //Sousmission Formulaire parametres if ((!empty($_POST['saveconfig'])) && ($core->auth->isSuperAdmin())) { @@ -34,6 +35,9 @@ if ((!empty($_POST['saveconfig'])) && ($core->auth->isSuperAdmin())) { $openApi = (empty($_POST['open'])) ? false : true; $core->blog->settings->rest->put('rest_is_open',$openApi,'boolean'); + $sendHeaders = (empty($_POST['sendHeaders'])) ? false : true; + $core->blog->settings->rest->put('rest_send_cors_headers',$sendHeaders,'boolean'); + dcPage::addSuccessNotice(__('Configuration successfully updated.')); http::redirect($p_url); }catch (Exception $e) @@ -47,7 +51,7 @@ if(!empty($_POST['resetApiKey'])){ $apiKey -> new_key($core->auth->userID()); dcPage::addSuccessNotice(__('Your new key is').' '.$apiKey->key); } -//is user admin isSuperAdmin + ?> @@ -58,9 +62,12 @@ if(!empty($_POST['resetApiKey'])){

get_dc_admin_form($core->auth->userID()); ?> -auth->isSuperAdmin()): ?> +auth->isSuperAdmin()): +?> -

Rest API configuration

+

@@ -73,11 +80,17 @@ if(!empty($_POST['resetApiKey'])){

formNonce(); ?> +

+ + +

- + \ No newline at end of file diff --git a/locales/fr/main.po b/locales/fr/main.po new file mode 100644 index 0000000..7cd89e0 --- /dev/null +++ b/locales/fr/main.po @@ -0,0 +1,8 @@ +msgid "Enable REST API" +msgstr "Activer l'API REST" + +msgid "Your API key" +msgstr "Votre clef" + +msgid "Rest API configuration" +msgstr "Configuration de l'API" \ No newline at end of file