Changeset 2227728
- Timestamp:
- 01/15/2020 11:42:49 AM (6 years ago)
- Location:
- easy-country-spam-blocker
- Files:
-
- 36 added
- 6 edited
-
tags/1.1.1 (added)
-
tags/1.1.1/LICENSE.txt (added)
-
tags/1.1.1/README.txt (added)
-
tags/1.1.1/admin (added)
-
tags/1.1.1/admin/class-mi-ecsb-admin.php (added)
-
tags/1.1.1/admin/css (added)
-
tags/1.1.1/admin/css/mi-ecsb-admin.css (added)
-
tags/1.1.1/admin/index.php (added)
-
tags/1.1.1/admin/js (added)
-
tags/1.1.1/admin/js/mi-ecsb-admin.js (added)
-
tags/1.1.1/admin/partials (added)
-
tags/1.1.1/admin/partials/mi-ecsb-admin-display.php (added)
-
tags/1.1.1/includes (added)
-
tags/1.1.1/includes/class-mi-ecsb-activator.php (added)
-
tags/1.1.1/includes/class-mi-ecsb-deactivator.php (added)
-
tags/1.1.1/includes/class-mi-ecsb-form-actions.php (added)
-
tags/1.1.1/includes/class-mi-ecsb-helper.php (added)
-
tags/1.1.1/includes/class-mi-ecsb-i18n.php (added)
-
tags/1.1.1/includes/class-mi-ecsb-loader.php (added)
-
tags/1.1.1/includes/class-mi-ecsb-redirect.php (added)
-
tags/1.1.1/includes/class-mi-ecsb.php (added)
-
tags/1.1.1/includes/index.php (added)
-
tags/1.1.1/index.php (added)
-
tags/1.1.1/languages (added)
-
tags/1.1.1/languages/mi-ecsb.pot (added)
-
tags/1.1.1/mi-ecsb.php (added)
-
tags/1.1.1/public (added)
-
tags/1.1.1/public/class-mi-ecsb-public.php (added)
-
tags/1.1.1/public/css (added)
-
tags/1.1.1/public/css/mi-ecsb-public.css (added)
-
tags/1.1.1/public/index.php (added)
-
tags/1.1.1/public/js (added)
-
tags/1.1.1/public/js/mi-ecsb-public.js (added)
-
tags/1.1.1/public/partials (added)
-
tags/1.1.1/public/partials/mi-ecsb-public-display.php (added)
-
tags/1.1.1/uninstall.php (added)
-
trunk/README.txt (modified) (1 diff)
-
trunk/admin/css/mi-ecsb-admin.css (modified) (1 diff)
-
trunk/admin/js/mi-ecsb-admin.js (modified) (2 diffs)
-
trunk/admin/partials/mi-ecsb-admin-display.php (modified) (2 diffs)
-
trunk/includes/class-mi-ecsb-redirect.php (modified) (1 diff)
-
trunk/mi-ecsb.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
easy-country-spam-blocker/trunk/README.txt
r2221863 r2227728 62 62 == Changelog == 63 63 64 = 1.1.1 = 65 * Improved settings view 66 * Fixed misc. bugs 67 64 68 = 1.1.0 = 65 69 * Added ability to choose whitelisted countries -
easy-country-spam-blocker/trunk/admin/css/mi-ecsb-admin.css
r2221863 r2227728 3 3 * included in this file. 4 4 */ 5 6 .ecsb-left, 7 .ecsb-right { 8 width: 50%; 9 display: inline-block; 10 } 11 12 .ecsb-left { 13 float: left; 14 } 15 16 .ecsb-right { 17 float: right; 18 } 5 19 6 20 .ecsb-admin-page { -
easy-country-spam-blocker/trunk/admin/js/mi-ecsb-admin.js
r2221863 r2227728 30 30 if((target.checked == null || target.checked == undefined) || (target.value == null || target.value == undefined)) { 31 31 return; 32 } 33 34 if(target.id === 'usa-toggle') { 35 e.preventDefault(); 36 target.checked = true; 32 37 } 33 38 … … 48 53 }); 49 54 50 // Add an event to the submit event. 51 form.addEventListener('submit', function(e) 52 { 53 // Override the default form behavior. 54 e.preventDefault(); 55 56 // Set the request data. 57 let formData = 58 { 59 action: form.action.value, 60 isEnabled: jQuery(form.isEnabled).prop('checked'), 61 countries: countries, 62 redirectUrl: form.redirectUrl.value, 63 urlProtocol: form.url_protocol.value + '://' 64 }; 65 66 // Sanitize the URL. 67 formData.redirectUrl = formData.redirectUrl.replace(/[^-A-Za-z0-9+&@#/%?=~_|!:,.;\(\)]/, ''); 68 69 // Strip away any URL protocols from the redirect URL. 70 formData.redirectUrl = formData.redirectUrl.replace(/(^\w+:|^)\/\//, ''); 71 72 // Add the user selected URL protocol to the URL. 73 formData.redirectUrl = formData.urlProtocol + formData.redirectUrl; 74 75 // Remove any whitespace from the URL. 76 formData.redirectUrl = formData.redirectUrl.replace(/\s+/, ''); 77 78 // If the input does end with a domain extension, do not continue. 79 if(formData.redirectUrl.indexOf('.') === -1) 80 { 81 displayErrorNotice(ECSBAdmin.InvalidURLMsg); 82 return; 83 } 84 85 // Update redirect URL. 86 jQuery.ajax( 87 { 88 type: 'POST', 89 url: ECSBAdmin.AjaxURL, 90 data: formData, 91 success: function(urlSaveResponse) 92 { 93 console.log(urlSaveResponse); 94 95 if(urlSaveResponse.data === null || urlSaveResponse.data === undefined) 55 // Add an event to the save button. 56 jQuery('.save-button').each((index, obj) => { 57 obj.addEventListener('click', (e) => { 58 // Override the default form behavior. 59 e.preventDefault(); 60 61 // Set the request data. 62 let formData = 63 { 64 action: form.action.value, 65 isEnabled: jQuery(form.isEnabled).prop('checked'), 66 countries: countries, 67 redirectUrl: form.redirectUrl.value, 68 urlProtocol: form.url_protocol.value + '://' 69 }; 70 71 // Sanitize the URL. 72 formData.redirectUrl = formData.redirectUrl.replace(/[^-A-Za-z0-9+&@#/%?=~_|!:,.;\(\)]/, ''); 73 74 // Strip away any URL protocols from the redirect URL. 75 formData.redirectUrl = formData.redirectUrl.replace(/(^\w+:|^)\/\//, ''); 76 77 // Add the user selected URL protocol to the URL. 78 formData.redirectUrl = formData.urlProtocol + formData.redirectUrl; 79 80 // Remove any whitespace from the URL. 81 formData.redirectUrl = formData.redirectUrl.replace(/\s+/, ''); 82 83 // If the input does end with a domain extension, do not continue. 84 if(formData.redirectUrl.indexOf('.') === -1) 85 { 86 displayErrorNotice(ECSBAdmin.InvalidURLMsg); 87 return; 88 } 89 90 // Update redirect URL. 91 jQuery.ajax( 92 { 93 type: 'POST', 94 url: ECSBAdmin.AjaxURL, 95 data: formData, 96 success: function(urlSaveResponse) 97 { 98 console.log(urlSaveResponse); 99 100 if(urlSaveResponse.data === null || urlSaveResponse.data === undefined) 101 { 102 displayErrorNotice(ECSBAdmin.UnknownErrorMsg); 103 return; 104 } 105 106 if(urlSaveResponse.data.exit_code === null || urlSaveResponse.data.exit_code === undefined) 107 { 108 displayErrorNotice(ECSBAdmin.UnknownErrorMsg); 109 return; 110 } 111 112 // There was an error. 113 if(urlSaveResponse.data.exit_code !== 0) 114 { 115 displayErrorNotice( 116 urlSaveResponse.data.msg === null || urlSaveResponse.data.msg === undefined ? 117 ECSBAdmin.ErrorCodeMsg + ' ' + urlSaveResponse.data.exit_code : 118 ECSBAdmin.ErrorCodeMsg + ' ' + urlSaveResponse.data.exit_code + ' - ' + urlSaveResponse.data.msg 119 ); 120 121 return; 122 } 123 124 // Display success! 125 if(urlSaveResponse.data.msg !== null && urlSaveResponse.data.msg !== undefined) 126 { 127 displaySuccessNotice(urlSaveResponse.data.msg); 128 } 129 else 130 { 131 displayErrorNotice(ECSBAdmin.UnkownSuccessMsg); 132 } 133 }, 134 error: function(urlSaveResponse) 96 135 { 97 136 displayErrorNotice(ECSBAdmin.UnknownErrorMsg); 98 return; 99 } 100 101 if(urlSaveResponse.data.exit_code === null || urlSaveResponse.data.exit_code === undefined) 102 { 103 displayErrorNotice(ECSBAdmin.UnknownErrorMsg); 104 return; 105 } 106 107 // There was an error. 108 if(urlSaveResponse.data.exit_code !== 0) 109 { 110 displayErrorNotice( 111 urlSaveResponse.data.msg === null || urlSaveResponse.data.msg === undefined ? 112 ECSBAdmin.ErrorCodeMsg + ' ' + urlSaveResponse.data.exit_code : 113 ECSBAdmin.ErrorCodeMsg + ' ' + urlSaveResponse.data.exit_code + ' - ' + urlSaveResponse.data.msg 114 ); 115 116 return; 117 } 118 119 // Display success! 120 if(urlSaveResponse.data.msg !== null && urlSaveResponse.data.msg !== undefined) 121 { 122 displaySuccessNotice(urlSaveResponse.data.msg); 123 } 124 else 125 { 126 displayErrorNotice(ECSBAdmin.UnkownSuccessMsg); 127 } 128 }, 129 error: function(urlSaveResponse) 130 { 131 displayErrorNotice(ECSBAdmin.UnknownErrorMsg); 132 } 137 } 138 }); 133 139 }); 134 140 }); -
easy-country-spam-blocker/trunk/admin/partials/mi-ecsb-admin-display.php
r2221863 r2227728 14 14 15 15 // Try to get the redirect URL from the database. 16 $is_enabled = EasyCountrySpamBlocker_Helper::get_wp_option( 'mi-ecsb_is_enabled', false );16 $is_enabled = EasyCountrySpamBlocker_Helper::get_wp_option( 'mi-ecsb_is_enabled', true ); 17 17 $countries = EasyCountrySpamBlocker_Helper::get_wp_option( 'mi-ecsb_countries', [] ); 18 18 $redirect_url = EasyCountrySpamBlocker_Helper::get_url(); … … 36 36 <p><?php _e( 'Easy Country Spam Blocker is a simple plugin that blocks all non-US traffic from a site. Choose a redirection URL below and click "Save."', 'mi-ecsb' ); ?></p> 37 37 38 <!-- Settings Section 1 --> 39 <div class="section"> 40 <div class="content"> 41 <form id="ecsb-settings-form" class="ecsb-settings-form" method="post"> 42 <div class="ecsb-field"> 43 <label class="ecsb-field-label" for="is_enabled"> 44 <?php _e( 'ECSB Enabled?', 'mi-ecsb' ); ?> 45 </label> 38 <div id="ecsb-notices"></div> 46 39 47 <label class="switch"> 48 <input name="isEnabled" type="checkbox" <?php if( $is_enabled ) echo 'checked'; ?>> 49 <span class="slider round"></span> 50 </label> 51 </div> 52 53 <div class="ecsb-field marginless-bottom"> 54 <p class="ecsb-explanation"> 55 <?php _e( 'What URL do you want to redirect non-US visitors to?', 'mi-ecsb' ); ?> 56 </p> 57 </div> 58 59 <div class="ecsb-field url-select-container"> 60 <?php for($i = 0; $i < 1; $i++): ?> 61 <div class="url-select-item"> 62 <div class="url-protocol-dropdown"> 63 <button class="url-protocol-button" data-url-protocol="<?php echo esc_attr( $url_protocol ); ?>"> 64 <?php echo strtoupper( esc_html( $url_protocol ) ); ?> 65 </button> 66 67 <ul class="url-protocol-options initial"> 68 <?php for($k = 0; $k < count( EasyCountrySpamBlocker_Helper::get_allowed_url_protocols() ); $k++): ?> 69 <li class="url-protocol-option" data-url-protocol="<?php echo esc_attr( EasyCountrySpamBlocker_Helper::get_allowed_url_protocols()[ $k ] ); ?>"> 70 <?php echo strtoupper( esc_html( EasyCountrySpamBlocker_Helper::get_allowed_url_protocols()[ $k ] ) ); ?> 71 </li> 72 <?php endfor; ?> 73 </ul> 40 <div class="ecsb-left"> 41 <!-- Settings Section 1 --> 42 <div class="section"> 43 <div class="content"> 44 <form id="ecsb-settings-form" class="ecsb-settings-form" method="post"> 45 <div class="ecsb-field"> 46 <label class="ecsb-field-label" for="is_enabled"> 47 <?php _e( 'ECSB Enabled?', 'mi-ecsb' ); ?> 48 </label> 49 50 <label class="switch"> 51 <input name="isEnabled" type="checkbox" <?php if( $is_enabled ) echo 'checked'; ?>> 52 <span class="slider round"></span> 53 </label> 54 </div> 55 56 <div class="ecsb-field marginless-bottom"> 57 <p class="ecsb-explanation"> 58 <?php _e( 'What URL do you want to redirect non-US visitors to?', 'mi-ecsb' ); ?> 59 </p> 60 </div> 61 62 <div class="ecsb-field url-select-container"> 63 <?php for($i = 0; $i < 1; $i++): ?> 64 <div class="url-select-item"> 65 <div class="url-protocol-dropdown"> 66 <button class="url-protocol-button" data-url-protocol="<?php echo esc_attr( $url_protocol ); ?>"> 67 <?php echo strtoupper( esc_html( $url_protocol ) ); ?> 68 </button> 69 70 <ul class="url-protocol-options initial"> 71 <?php for($k = 0; $k < count( EasyCountrySpamBlocker_Helper::get_allowed_url_protocols() ); $k++): ?> 72 <li class="url-protocol-option" data-url-protocol="<?php echo esc_attr( EasyCountrySpamBlocker_Helper::get_allowed_url_protocols()[ $k ] ); ?>"> 73 <?php echo strtoupper( esc_html( EasyCountrySpamBlocker_Helper::get_allowed_url_protocols()[ $k ] ) ); ?> 74 </li> 75 <?php endfor; ?> 76 </ul> 77 </div> 78 79 <input class="url-text" name="redirectUrl" type="text" value="<?php echo EasyCountrySpamBlocker_Helper::strip_url_protocol( esc_url( $redirect_url ) ); ?>"> 74 80 </div> 81 <?php endfor; ?> 75 82 76 <input class="url-text" name="redirectUrl" type="text" value="<?php echo EasyCountrySpamBlocker_Helper::strip_url_protocol( esc_url( $redirect_url ) ); ?>"> 77 </div> 78 <?php endfor; ?> 83 <input type="hidden" name="url_protocol" value="<?php echo esc_attr( $url_protocol ); ?>"> 84 </div> 85 86 <div class="ecsb-field"> 87 <input type="hidden" name="action" value="ecsb_settings"> 88 </div> 89 90 <div class="ecsb-field"> 91 <input class="button button-primary button-large save-button" type="submit" value="<?php echo _e( 'Save', 'mi-ecsb' ); ?>"> 92 </div> 93 </form> 94 </div> 95 </div> 79 96 80 <input type="hidden" name="url_protocol" value="<?php echo esc_attr( $url_protocol ); ?>"> 81 </div> 82 83 <div class="ecsb-field"> 84 <input type="hidden" name="action" value="ecsb_settings"> 85 </div> 86 87 <div class="ecsb-field"> 88 <input class="button button-primary button-large" type="submit" value="<?php echo _e( 'Save', 'mi-ecsb' ); ?>"> 89 </div> 90 </form> 97 <!-- Question Section --> 98 <div style="background-color: white; padding: 10px; margin-top: 10px; margin-right: 10px;"> 99 <h2><?php _e( 'Questions?', 'mi-ecsb' ); ?></h2> 100 <p><?php _e( 'If you are having issues with Easy Country Spam Blocker or just have a general question to ask,<br>feel free to reach out anytime!', 'mi-ecsb' ); ?></p> 101 <a class="button button-primary button-large" href="https://www.mediuminteractive.com/contact/" target="_blank" rel="nofollow"><?php _e( 'Contact Us', 'mi-ecsb' ); ?></a> 102 </div> 103 104 <div style="background-color: white; padding: 10px; margin-top: 10px; margin-right: 10px;"> 105 <h2><?php _e( 'Quickstart', 'mi-ecsb' ); ?> 106 <ul style="list-style-type: circle; margin-left: 25px; font-weight: normal; font-size: 1rem;"> 107 <li> 108 <?php _e( 'Install & Activate', 'mi-ecsb' ); ?> 109 </li> 110 <li> 111 <?php _e( 'Enable whitelisted countries' ); ?> 112 </li> 113 <li> 114 <?php _e( 'Set redirect URL above', 'mi-ecsb' ); ?> 115 </li> 116 <li> 117 <?php _e( 'Choose either HTTP or HTTPS', 'mi-ecsb' ); ?> 118 </li> 119 <li> 120 <?php _e( 'Click "Save"', 'mi-ecsb' ); ?> 121 </li> 122 <li> 123 <?php _e( 'Done!', 'mi-ecsb' ); ?> 124 </li> 125 </ul> 91 126 </div> 92 127 </div> 93 128 94 <div id="ecsb-notices"></div> 129 <div class="ecsb-right"> 130 <!-- Settings Section 2 --> 131 <div class="section"> 132 <div class="content"> 133 <h2 style="color: white"><?php _e( 'Whitelisted Countries', 'mi-ecsb' ); ?></h2> 134 <div class="ecsb-field"> 135 <input class="button button-primary button-large save-button" type="submit" value="<?php echo _e( 'Save', 'mi-ecsb' ); ?>"> 136 </div> 95 137 96 <!-- Settings Section 2 --> 97 <div class="section"> 98 <div class="content"> 99 <h2 style="color: white"><?php _e( 'Whitelisted Countries', 'mi-ecsb' ); ?></h2> 138 <?php foreach( EasyCountrySpamBlocker_Helper::get_countries() as $key => $value ): ?> 139 <div class="country" style="width: 100%; display: block; overflow: hidden;"> 140 <div style="display: inline-block: width: 5%; float: left;"> 141 <?php if( strtolower( $value ) === 'us' ) { ?> 142 <input id="usa-toggle" class="country-toggle" value="<?php echo $value; ?>" type="checkbox" checked /> 143 <?php } else { ?> 144 <input class="country-toggle" value="<?php echo $value; ?>" type="checkbox" <?php if( in_array( $value, $countries ) ) echo 'checked'; ?> /> 145 <?php } ?> 146 </div> 100 147 101 <?php foreach( EasyCountrySpamBlocker_Helper::get_countries() as $key => $value ): ?> 102 <div class="country" style="overflow: hidden;"> 103 <div style="display: inline-block; width: 95%; float: left;"> 104 <?php _e( $key, 'mi-ecsb' ); ?> 148 <div style="display: inline-block; width: 95%; float: right;"> 149 <?php if( strtolower( $value ) === 'us' ) { ?> 150 <?php _e( $key, 'mi-ecsb' ); ?> <strong><?php _e( '(ALWAYS ENABLED)', 'mi-ecsb' ); ?></strong> 151 <?php } else { ?> 152 <?php _e( $key, 'mi-ecsb' ); ?> 153 <?php } ?> 154 </div> 105 155 </div> 156 <?php endforeach; ?> 106 157 107 <div style="display: inline-block; width: 5%; float: right;"> 108 <input class="country-toggle" value="<?php echo $value; ?>" type="checkbox" <?php if( in_array( $value, $countries ) ) echo 'checked'; ?> /> 109 </div> 158 <div class="ecsb-field"> 159 <input class="button button-primary button-large save-button" type="submit" value="<?php echo _e( 'Save', 'mi-ecsb' ); ?>"> 110 160 </div> 111 < ?php endforeach; ?>161 </div> 112 162 </div> 113 163 </div> 114 115 <!-- Question Section -->116 <div style="background-color: white; padding: 10px; margin-top: 10px;">117 <h2><?php _e( 'Questions?', 'mi-ecsb' ); ?></h2>118 <p><?php _e( 'If you are having issues with Easy Country Spam Blocker or just have a general question to ask,<br>feel free to reach out anytime!', 'mi-ecsb' ); ?></p>119 <a class="button button-primary button-large" href="https://www.mediuminteractive.com/contact/" target="_blank" rel="nofollow"><?php _e( 'Contact Us', 'mi-ecsb' ); ?></a>120 </div>121 122 <div style="background-color: white; padding: 10px; margin-top: 10px">123 <h2><?php _e( 'Quickstart', 'mi-ecsb' ); ?>124 <ul style="list-style-type: circle; margin-left: 25px; font-weight: normal; font-size: 1rem;">125 <li>126 <?php _e( 'Install & Activate', 'mi-ecsb' ); ?>127 </li>128 <li>129 <?php _e( 'Enable whitelisted countries' ); ?>130 </li>131 <li>132 <?php _e( 'Set redirect URL above', 'mi-ecsb' ); ?>133 </li>134 <li>135 <?php _e( 'Choose either HTTP or HTTPS', 'mi-ecsb' ); ?>136 </li>137 <li>138 <?php _e( 'Click "Save"', 'mi-ecsb' ); ?>139 </li>140 <li>141 <?php _e( 'Done!', 'mi-ecsb' ); ?>142 </li>143 </ul>144 </div>145 164 </div> -
easy-country-spam-blocker/trunk/includes/class-mi-ecsb-redirect.php
r2221863 r2227728 117 117 } 118 118 119 // Loop through supported countries. 120 for($i = 0; $i < count( $supported_countries ); $i++ ) { 121 // If the retrieved country code is equal to the current supported country code, redirect. 122 if( strtolower( $countryCode ) !== strtolower( $supported_countries[ $i ] ) ) 123 { 124 // Redirect the visitor and give a "403 Forbidden" status code. 125 http_response_code( 403 ); 126 header( 'Location: ' . EasyCountrySpamBlocker_Helper::get_url() ); 127 exit(); 128 } 119 // If the retrieved country code is not in the list of supported countries, redirect. 120 if( !in_array( strtoupper( $countryCode ), $supported_countries ) ) { 121 // Redirect the visitor and give a "403 Forbidden" status code. 122 http_response_code( 403 ); 123 header( 'Location: ' . EasyCountrySpamBlocker_Helper::get_url() ); 124 exit(); 129 125 } 130 126 } -
easy-country-spam-blocker/trunk/mi-ecsb.php
r2221863 r2227728 16 16 * Plugin Name: Easy Country Spam Blocker 17 17 * Description: Easily block non-US visitors out of your site with a custom redirect URL. 18 * Version: 1.1. 018 * Version: 1.1.1 19 19 * Author: Medium Interactive, LLC 20 20 * Author URI: https://mediuminteractive.com/ … … 32 32 * Current plugin version. Use SemVer - https://semver.org 33 33 */ 34 define( 'EASYCOUNTRYSPAMBLOCKER_VERSION', '1.1. 0' );34 define( 'EASYCOUNTRYSPAMBLOCKER_VERSION', '1.1.1' ); 35 35 define( 'EASYCOUNTRYSPAMBLOCKER_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); 36 36 define( 'EASYCOUNTRYSPAMBLOCKER_BASE_PATH', plugin_dir_path( __FILE__ ) );
Note: See TracChangeset
for help on using the changeset viewer.