diff --git a/css/admin.css b/css/admin.css index c8d4768f1..6bd6b4453 100644 --- a/css/admin.css +++ b/css/admin.css @@ -454,13 +454,6 @@ body #post-head-content p.wp-clearfix:nth-child(1) { .options-menu li:hover a p{ color:#fff; } -@media only screen and (max-width: 782px) { - .page-option-action summary{ - padding: 10px 15px; - font-size: 14px; - white-space: nowrap; - } -} /* new style */ .oo-poststuff .custom-input-field { @@ -682,6 +675,52 @@ body #post-head-content p.wp-clearfix:nth-child(1) { cursor: pointer; } +.delete-google-recaptcha-keys-button.button { + border: 1px solid #ff0000; + color: #ff0000; + margin-top: 20px; +} + +.delete-google-recaptcha-keys-button.button:hover, +.delete-google-recaptcha-keys-button.button:focus { + border: 1px solid #ff0000; + color: #ffffff; + background-color: #ff0000; +} + +.oo-google-recaptcha-key { + max-width: 380px; + position: relative; +} + +.oo-google-recaptcha-key > button.button { + position: absolute; + top: 0; + right: 10px; + background: none; + border: 1px solid transparent; + box-shadow: none; + width: 40px; + height: 30px; + min-width: 40px; +} + +.oo-google-recaptcha-key > button.button:hover { + background: none; + border: 1px solid transparent; + transform: scale(1.2); +} + +.oo-google-recaptcha-key > button.button:focus { + background: none; + border: 1px solid transparent; + box-shadow: none; +} + +.oo-google-recaptcha-key > button > span { + margin-top: 5px; +} + @media only screen and (max-width: 1365px) { .block-publish .postbox-header { display: none; @@ -743,3 +782,20 @@ body #post-head-content p.wp-clearfix:nth-child(1) { margin: 0 !important; } } + +@media only screen and (max-width: 782px) { + .page-option-action summary{ + padding: 10px 15px; + font-size: 14px; + white-space: nowrap; + } + + .oo-google-recaptcha-key { + max-width: none; + width: 100%; + } + + .oo-google-recaptcha-key > button > span { + margin-top: 10px; + } +} diff --git a/dist/onoffice-handle-notification-actions.min.js b/dist/onoffice-handle-notification-actions.min.js index 6252cb142..f68478bba 100644 --- a/dist/onoffice-handle-notification-actions.min.js +++ b/dist/onoffice-handle-notification-actions.min.js @@ -1 +1 @@ -jQuery(document).ready((function($){$(document).on("click",".duplicate-check-notify .notice-dismiss",(function(event){event.preventDefault();var data={action:"update_duplicate_check_warning_option"};jQuery.post(duplicate_check_option_vars.ajaxurl,data)}));$(document).on("click",".active-plugin-seo .notice-dismiss",(function(event){event.preventDefault();var data={action:"update_active_plugin_seo_option"};jQuery.post(warning_active_plugin_vars.ajaxurl,data)}))})); \ No newline at end of file +jQuery(document).ready((function($){$(document).on("click",".duplicate-check-notify .notice-dismiss",(function(event){event.preventDefault();var data={action:"update_duplicate_check_warning_option"};jQuery.post(duplicate_check_option_vars.ajaxurl,data)}));$(document).on("click",".active-plugin-seo .notice-dismiss",(function(event){event.preventDefault();var data={action:"update_active_plugin_seo_option"};jQuery.post(warning_active_plugin_vars.ajaxurl,data)}));$(document).on("click",".delete-google-recaptcha-keys-button",(function(event){let notification=confirm_dialog_google_recaptcha_keys.notification;if(confirm(notification)){event.preventDefault();const data={action:"delete_google_recaptcha_keys"};jQuery.post(delete_google_recaptcha_keys.ajaxurl,data);$('input[name="onoffice-settings-captcha-sitekey"]').val("");$('input[name="onoffice-settings-captcha-secretkey"]').val("")}else{event.preventDefault()}}))})); \ No newline at end of file diff --git a/dist/onoffice-handle-visibility-google-recaptcha-keys.min.js b/dist/onoffice-handle-visibility-google-recaptcha-keys.min.js new file mode 100644 index 000000000..ef25b3d99 --- /dev/null +++ b/dist/onoffice-handle-visibility-google-recaptcha-keys.min.js @@ -0,0 +1 @@ +jQuery(document).ready((function($){function showOrHideGoogleRecaptchaKey(inputSelector,toggleSelector){const inputElement=$(inputSelector);const toggleElement=$(toggleSelector);if(inputElement.attr("type")==="password"){inputElement.attr("type","text");toggleElement.removeClass("dashicons-visibility").addClass("dashicons-hidden")}else if(inputElement.attr("type")==="text"){inputElement.attr("type","password");toggleElement.removeClass("dashicons-hidden").addClass("dashicons-visibility")}}$(".oo-icon-eye-secret-key").on("click",(function(){showOrHideGoogleRecaptchaKey('input[name="onoffice-settings-captcha-secretkey"]',".oo-icon-eye-secret-key")}));$(".oo-icon-eye-site-key").on("click",(function(){showOrHideGoogleRecaptchaKey('input[name="onoffice-settings-captcha-sitekey"]',".oo-icon-eye-site-key")}))})); \ No newline at end of file diff --git a/js/onoffice-handle-notification-actions.js b/js/onoffice-handle-notification-actions.js index f827f576d..341a9736d 100644 --- a/js/onoffice-handle-notification-actions.js +++ b/js/onoffice-handle-notification-actions.js @@ -15,4 +15,20 @@ jQuery(document).ready(function ($) { jQuery.post(warning_active_plugin_vars.ajaxurl, data); }); + + $(document).on('click', '.delete-google-recaptcha-keys-button', function (event) { + let notification = confirm_dialog_google_recaptcha_keys.notification; + if (confirm(notification)) { + event.preventDefault(); + const data = { + 'action': 'delete_google_recaptcha_keys' + }; + + jQuery.post(delete_google_recaptcha_keys.ajaxurl, data); + $('input[name="onoffice-settings-captcha-sitekey"]').val(''); + $('input[name="onoffice-settings-captcha-secretkey"]').val(''); + } else { + event.preventDefault(); + } + }); }); \ No newline at end of file diff --git a/js/onoffice-handle-visibility-google-recaptcha-keys.js b/js/onoffice-handle-visibility-google-recaptcha-keys.js new file mode 100644 index 000000000..232fd72d8 --- /dev/null +++ b/js/onoffice-handle-visibility-google-recaptcha-keys.js @@ -0,0 +1,22 @@ +jQuery(document).ready(function ($) { + function showOrHideGoogleRecaptchaKey(inputSelector, toggleSelector) { + const inputElement = $(inputSelector); + const toggleElement = $(toggleSelector); + + if (inputElement.attr('type') === 'password') { + inputElement.attr('type', 'text'); + toggleElement.removeClass('dashicons-visibility').addClass('dashicons-hidden'); + } else if (inputElement.attr('type') === 'text') { + inputElement.attr('type', 'password'); + toggleElement.removeClass('dashicons-hidden').addClass('dashicons-visibility'); + } + } + + $('.oo-icon-eye-secret-key').on('click', function () { + showOrHideGoogleRecaptchaKey('input[name="onoffice-settings-captcha-secretkey"]', '.oo-icon-eye-secret-key'); + }); + + $('.oo-icon-eye-site-key').on('click', function () { + showOrHideGoogleRecaptchaKey('input[name="onoffice-settings-captcha-sitekey"]', '.oo-icon-eye-site-key'); + }); +}); \ No newline at end of file diff --git a/plugin.php b/plugin.php index 51226f5ac..4728fd33c 100644 --- a/plugin.php +++ b/plugin.php @@ -411,8 +411,18 @@ function update_status_close_action_button_option() echo true; wp_die(); } + +function delete_google_recaptcha_keys() +{ + update_option('onoffice-settings-captcha-sitekey', ''); + update_option('onoffice-settings-captcha-secretkey', ''); + echo true; + wp_die(); +} + add_action('wp_ajax_update_active_plugin_seo_option', 'update_status_close_action_button_option'); add_action('wp_ajax_update_duplicate_check_warning_option', 'update_duplicate_check_warning_option'); +add_action('wp_ajax_delete_google_recaptcha_keys', 'delete_google_recaptcha_keys'); add_action('wp', function () { if (!get_option('add-detail-posts-to-rewrite-rules')) { diff --git a/plugin/Controller/AdminViewController.php b/plugin/Controller/AdminViewController.php index b7ef2246b..6171dc573 100644 --- a/plugin/Controller/AdminViewController.php +++ b/plugin/Controller/AdminViewController.php @@ -328,12 +328,23 @@ public function enqueue_css() public function enqueueExtraJs($hook) { + $confirmDialogGoogleRecaptcha = [ + 'notification' => __('Would you like to permanently delete the site key and the secret key?', 'onoffice-for-wp-websites'), + ]; wp_register_script('handle-notification-actions', plugins_url('dist/onoffice-handle-notification-actions.min.js', ONOFFICE_PLUGIN_DIR . '/index.php'), array('jquery')); wp_localize_script('handle-notification-actions', 'duplicate_check_option_vars', ['ajaxurl' => admin_url('admin-ajax.php')]); wp_localize_script('handle-notification-actions', 'warning_active_plugin_vars', ['ajaxurl' => admin_url('admin-ajax.php')]); wp_enqueue_script('handle-notification-actions'); + if (__String::getNew($hook)->contains($this->_pageSlug.'-settings')) { + wp_register_script('handle-visibility-google-recaptcha-keys', plugins_url('dist/onoffice-handle-visibility-google-recaptcha-keys.min.js', ONOFFICE_PLUGIN_DIR . '/index.php'), + array('jquery')); + wp_localize_script('handle-notification-actions', 'delete_google_recaptcha_keys', ['ajaxurl' => admin_url('admin-ajax.php')]); + wp_localize_script('handle-notification-actions', 'confirm_dialog_google_recaptcha_keys', $confirmDialogGoogleRecaptcha); + wp_enqueue_script('handle-visibility-google-recaptcha-keys'); + } + if (__String::getNew($hook)->contains('onoffice')) { $pObject = $this->getObjectByHook($hook); if ($pObject !== null && method_exists($pObject, 'doExtraEnqueues')) { diff --git a/plugin/Gui/AdminPageApiSettings.php b/plugin/Gui/AdminPageApiSettings.php index 082ea2f6f..59f40ed66 100644 --- a/plugin/Gui/AdminPageApiSettings.php +++ b/plugin/Gui/AdminPageApiSettings.php @@ -164,9 +164,11 @@ private function addFormModelGoogleCaptcha() ('onoffice-settings', 'captcha-sitekey', $labelSiteKey, 'string'); $optionNameKey = $pInputModelCaptchaSiteKey->getIdentifier(); $pInputModelCaptchaSiteKey->setValue(get_option($optionNameKey)); + $pInputModelCaptchaSiteKey->setHtmlType(InputModelOption::HTML_GOOGLE_RECAPTCHA_ACCOUNT); $pInputModelCaptchaPageSecret = new InputModelOption ('onoffice-settings', 'captcha-secretkey', $labelSecretKey, 'string'); $pInputModelCaptchaPageSecret->setIsPassword(true); + $pInputModelCaptchaPageSecret->setHtmlType(InputModelOption::HTML_GOOGLE_RECAPTCHA_ACCOUNT); $optionNameSecret = $pInputModelCaptchaPageSecret->getIdentifier(); $pInputModelCaptchaPageSecret->setSanitizeCallback(function($password) use ($optionNameSecret) { return $this->checkPassword($password, $optionNameSecret); diff --git a/plugin/Model/InputModelBase.php b/plugin/Model/InputModelBase.php index d1dd7212e..aff394768 100644 --- a/plugin/Model/InputModelBase.php +++ b/plugin/Model/InputModelBase.php @@ -80,6 +80,9 @@ abstract class InputModelBase /** */ const HTML_SEARCH_FIELD_FOR_FIELD_LISTS = 'searchFieldForFieldLists'; + /** */ + const HTML_GOOGLE_RECAPTCHA_ACCOUNT = 'googleRecaptchaAccount'; + /** @var string */ private $_name = null; diff --git a/plugin/Renderer/InputFieldGoogleRecaptchaAccountRenderer.php b/plugin/Renderer/InputFieldGoogleRecaptchaAccountRenderer.php new file mode 100644 index 000000000..db09f446c --- /dev/null +++ b/plugin/Renderer/InputFieldGoogleRecaptchaAccountRenderer.php @@ -0,0 +1,78 @@ +. + * + */ + +namespace onOffice\WPlugin\Renderer; + +use Exception; + +/** + * + */ +class InputFieldGoogleRecaptchaAccountRenderer extends InputFieldRenderer +{ + /** + * + * @param string $type + * @param string $name + * @param string $value + * + * @throws Exception + */ + + public function __construct($type, $name, $value = null) + { + if (!in_array($type, array('googleRecaptchaAccount'))) { + throw new Exception('wrong type!'); + } + parent::__construct($type, $name, $value); + } + + + /** + * + */ + + public function render() + { + $iconShowPassword = ''; + $showDeleteGoogleRecaptchaKeysButton = false; + if ($this->getName() === 'onoffice-settings-captcha-secretkey') { + $iconShowPassword = ''; + $showDeleteGoogleRecaptchaKeysButton = true; + } elseif ($this->getName() === 'onoffice-settings-captcha-sitekey') { + $iconShowPassword = ''; + } + echo '
'; + echo 'renderAdditionalAttributes() + . '>' . $iconShowPassword; + echo '
'; + + if ($showDeleteGoogleRecaptchaKeysButton) { + echo ''; + } + } +} \ No newline at end of file diff --git a/plugin/Renderer/InputModelRenderer.php b/plugin/Renderer/InputModelRenderer.php index faa390bfe..d2929664c 100644 --- a/plugin/Renderer/InputModelRenderer.php +++ b/plugin/Renderer/InputModelRenderer.php @@ -270,6 +270,12 @@ private function createInputField(InputModelBase $pInputModel, FormModel $pFormM $pInstance->setCheckedValues($pInputModel->getValue()); $pInstance->setOoModule($pFormModel->getOoModule()); break; + + case InputModelOption::HTML_GOOGLE_RECAPTCHA_ACCOUNT: + $pInstance = new InputFieldGoogleRecaptchaAccountRenderer('googleRecaptchaAccount', $elementName); + $pInstance->addAdditionalAttribute('size', '50'); + $pInstance->setValue($pInputModel->getValue()); + break; } if ($pInstance !== null) { diff --git a/tests/TestClassAdminViewController.php b/tests/TestClassAdminViewController.php index e923194dd..323e20657 100644 --- a/tests/TestClassAdminViewController.php +++ b/tests/TestClassAdminViewController.php @@ -30,6 +30,7 @@ use onOffice\WPlugin\Controller\AdminViewController; use onOffice\WPlugin\Fieldnames; use onOffice\WPlugin\Gui\AdminPageAjax; +use onOffice\WPlugin\Gui\AdminPageApiSettings; use onOffice\WPlugin\Gui\AdminPageEstate; use onOffice\WPlugin\Gui\AdminPageEstateDetail; use onOffice\WPlugin\Record\RecordManagerReadForm; @@ -335,4 +336,22 @@ public function testDisplayEmptyResultException() $pAdminViewController->displayAPIError(); $this->expectOutputString('

The onOffice plugin has an unexpected problem when trying to reach the onOffice API.

Please check the onOffice server status to see if there are known problems. Otherwise, report the problem using the support form.

'); } + + /** + * @depends testOnInit + * @param AdminViewController $pAdminViewController + * @throws Exception + * @global array $wp_filter + */ + public function testEnqueueExtraJsWithHandleRecaptcha(AdminViewController $pAdminViewController) + { + global $wp_filter; + $wp_filter['admin_page_onoffice-settings'] = new \WP_Hook; + /* @var $pWpHook WP_Hook */ + $pWpHook = $wp_filter['admin_page_onoffice-settings']; + $adminPage = new AdminPageApiSettings('admin_page_onoffice-settings'); + $pWpHook->callbacks = [[['function' => [$adminPage]]]]; + $pAdminViewController->enqueueExtraJs("admin_page_onoffice-settings"); + $this->assertEquals(['handle-notification-actions', 'handle-visibility-google-recaptcha-keys'], wp_scripts()->queue); + } } diff --git a/tests/TestClassInputFieldGoogleRecaptchaAccountRenderer.php b/tests/TestClassInputFieldGoogleRecaptchaAccountRenderer.php new file mode 100644 index 000000000..a6f3eb183 --- /dev/null +++ b/tests/TestClassInputFieldGoogleRecaptchaAccountRenderer.php @@ -0,0 +1,66 @@ +. + * + */ + +declare (strict_types=1); + +namespace onOffice\tests; + +use onOffice\WPlugin\Renderer\InputFieldGoogleRecaptchaAccountRenderer; +use WP_UnitTestCase; + +/** + * + * @url http://www.onoffice.de + * @copyright 2003-2023, onOffice(R) GmbH + * + */ + +class TestClassInputFieldGoogleRecaptchaAccountRenderer + extends WP_UnitTestCase +{ + /** + * + */ + public function testRenderInputSecretKey() + { + $pSubject = new InputFieldGoogleRecaptchaAccountRenderer('googleRecaptchaAccount', 'onoffice-settings-captcha-secretkey', ''); + ob_start(); + $pSubject->render(); + $output = ob_get_clean(); + $this->assertEquals('
', $output); + } + + /** + * + */ + public function testRenderInputSiteKey() + { + $pSubject = new InputFieldGoogleRecaptchaAccountRenderer('googleRecaptchaAccount', 'onoffice-settings-captcha-sitekey', ''); + ob_start(); + $pSubject->render(); + $output = ob_get_clean(); + $this->assertEquals('
', $output); + } +} \ No newline at end of file