This commit is contained in:
2024-05-20 15:37:46 +03:00
commit 00b7dbd0b7
10404 changed files with 3285853 additions and 0 deletions

View File

@ -0,0 +1,538 @@
<?php
/**
* WP Captcha
* https://getwpcaptcha.com/
* (c) WebFactory Ltd, 2022 - 2023, www.webfactoryltd.com
*/
class WPCaptcha_Admin extends WPCaptcha
{
/**
* Enqueue Admin Scripts
*
* @since 5.0
*
* @return null
*/
static function admin_enqueue_scripts($hook)
{
if ('settings_page_wpcaptcha' == $hook) {
wp_enqueue_style('wpcaptcha-admin', WPCAPTCHA_PLUGIN_URL . 'css/wpcaptcha.css', array(), self::$version);
wp_enqueue_style('wpcaptcha-dataTables', WPCAPTCHA_PLUGIN_URL . 'css/jquery.dataTables.min.css', array(), self::$version);
wp_enqueue_style('wpcaptcha-sweetalert', WPCAPTCHA_PLUGIN_URL . 'css/sweetalert2.min.css', array(), self::$version);
wp_enqueue_style('wpcaptcha-tooltipster', WPCAPTCHA_PLUGIN_URL . 'css/tooltipster.bundle.min.css', array(), self::$version);
wp_enqueue_style('wp-color-picker');
wp_enqueue_style('wp-jquery-ui-dialog');
wp_enqueue_script('jquery-ui-tabs');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-position');
wp_enqueue_script('jquery-effects-core');
wp_enqueue_script('jquery-effects-blind');
wp_enqueue_script('jquery-ui-dialog');
wp_enqueue_script('wpcaptcha-tooltipster', WPCAPTCHA_PLUGIN_URL . 'js/tooltipster.bundle.min.js', array('jquery'), self::$version, true);
wp_enqueue_script('wpcaptcha-dataTables', WPCAPTCHA_PLUGIN_URL . 'js/jquery.dataTables.min.js', array(), self::$version, true);
wp_enqueue_script('wpcaptcha-chart', WPCAPTCHA_PLUGIN_URL . 'js/chart.min.js', array(), self::$version, true);
wp_enqueue_script('wpcaptcha-moment', WPCAPTCHA_PLUGIN_URL . 'js/moment.min.js', array(), self::$version, true);
wp_enqueue_script('wpcaptcha-sweetalert', WPCAPTCHA_PLUGIN_URL . 'js/sweetalert2.min.js', array(), self::$version, true);
wp_enqueue_script('wp-color-picker');
wp_enqueue_media();
$js_localize = array(
'undocumented_error' => __('An undocumented error has occurred. Please refresh the page and try again.', 'advanced-google-recaptcha'),
'documented_error' => __('An error has occurred.', 'advanced-google-recaptcha'),
'plugin_name' => __('WP Captcha', 'advanced-google-recaptcha'),
'plugin_url' => WPCAPTCHA_PLUGIN_URL,
'icon_url' => WPCAPTCHA_PLUGIN_URL . 'images/wp-captcha-loader.gif',
'settings_url' => admin_url('options-general.php?page=wpcaptcha'),
'version' => self::$version,
'site' => get_home_url(),
'url' => WPCAPTCHA_PLUGIN_URL,
'cancel_button' => __('Cancel', 'advanced-google-recaptcha'),
'ok_button' => __('OK', 'advanced-google-recaptcha'),
'run_tool_nonce' => wp_create_nonce('wpcaptcha_run_tool'),
'stats_unavailable' => 'Stats will be available once enough data is collected.',
'stats_locks' => WPCaptcha_Stats::get_stats('locks'),
'stats_fails' => WPCaptcha_Stats::get_stats('fails'),
'wp301_install_url' => add_query_arg(array('action' => 'wpcaptcha_install_wp301', '_wpnonce' => wp_create_nonce('install_wp301'), 'rnd' => rand()), admin_url('admin.php')),
);
$js_localize['chart_colors'] = array('#4285f4', '#ff5429', '#ff7d5c', '#ffac97');
wp_enqueue_script('wpcaptcha-admin', WPCAPTCHA_PLUGIN_URL . 'js/wpcaptcha.js', array('jquery'), self::$version, true);
wp_localize_script('wpcaptcha-admin', 'wpcaptcha_vars', $js_localize);
// fix for aggressive plugins that include their CSS or JS on all pages
wp_dequeue_style('uiStyleSheet');
wp_dequeue_style('wpcufpnAdmin');
wp_dequeue_style('unifStyleSheet');
wp_dequeue_style('wpcufpn_codemirror');
wp_dequeue_style('wpcufpn_codemirrorTheme');
wp_dequeue_style('collapse-admin-css');
wp_dequeue_style('jquery-ui-css');
wp_dequeue_style('tribe-common-admin');
wp_dequeue_style('file-manager__jquery-ui-css');
wp_dequeue_style('file-manager__jquery-ui-css-theme');
wp_dequeue_style('wpmegmaps-jqueryui');
wp_dequeue_style('wp-botwatch-css');
wp_dequeue_style('njt-filebird-admin');
wp_dequeue_style('ihc_jquery-ui.min.css');
wp_dequeue_style('badgeos-juqery-autocomplete-css');
wp_dequeue_style('mainwp');
wp_dequeue_style('mainwp-responsive-layouts');
wp_dequeue_style('jquery-ui-style');
wp_dequeue_style('additional_style');
wp_dequeue_style('wobd-jqueryui-style');
wp_dequeue_style('wpdp-style3');
wp_dequeue_style('jquery_smoothness_ui');
wp_dequeue_style('uap_main_admin_style');
wp_dequeue_style('uap_font_awesome');
wp_dequeue_style('uap_jquery-ui.min.css');
wp_dequeue_style('wqm-select2-style');
wp_deregister_script('wqm-select2-script');
WPCaptcha_Utility::dismiss_pointer_ajax();
}
$pointers = get_option(WPCAPTCHA_POINTERS_KEY);
if ('settings_page_wpcaptcha' != $hook) {
if ($pointers) {
$pointers['run_tool_nonce'] = wp_create_nonce('wpcaptcha_run_tool');
wp_enqueue_script('wp-pointer');
wp_enqueue_style('wp-pointer');
wp_localize_script('wp-pointer', 'wpcaptcha_pointers', $pointers);
}
if ($pointers) {
wp_enqueue_script('wpcaptcha-pointers', WPCAPTCHA_PLUGIN_URL . 'js/wpcaptcha-pointers.js', array('jquery'), self::$version, true);
}
}
} // admin_enqueue_scripts
static function admin_notices()
{
$notices = get_option(WPCAPTCHA_NOTICES_KEY);
if (is_array($notices)) {
foreach ($notices as $id => $notice) {
WPCaptcha_Utility::wp_kses_wf('<div class="notice-' . $notice['type'] . ' notice is-dismissible"><p>' . $notice['text'] . '<button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button></p></div>');
if ($notice['once'] == true) {
unset($notices[$id]);
update_option(WPCAPTCHA_NOTICES_KEY, $notices);
}
}
}
} // notices
static function add_notice($id = false, $text = '', $type = 'warning', $show_once = false)
{
if ($id) {
$notices = get_option(WPCAPTCHA_NOTICES_KEY, array());
$notices[$id] = array('text' => $text, 'type' => $type, 'once' => $show_once);
update_option(WPCAPTCHA_NOTICES_KEY, $notices);
}
}
/**
* Admin menu entry
*
* @since 5.0
*
* @return null
*/
static function admin_menu()
{
add_options_page(
__('Advanced Google reCAPTCHA', 'advanced-google-recaptcha'),
__('Advanced Google reCAPTCHA', 'advanced-google-recaptcha'),
'manage_options',
'wpcaptcha',
array(__CLASS__, 'main_page')
);
} // admin_menu
/**
* Add settings link to plugins page
*
* @since 5.0
*
* @return null
*/
static function plugin_action_links($links)
{
$settings_link = '<a href="' . admin_url('options-general.php?page=wpcaptcha') . '" title="WP Captcha Settings">' . __('Settings', 'advanced-google-recaptcha') . '</a>';
$pro_link = '<a href="' . admin_url('options-general.php?page=wpcaptcha#open-pro-dialog') . '" title="Get more protection with WP Captcha PRO"><b>' . __('Get EXTRA protection', 'advanced-google-recaptcha') . '</b></a>';
array_unshift($links, $settings_link);
array_unshift($links, $pro_link);
return $links;
} // plugin_action_links
/**
* Add links to plugin's description in plugins table
*
* @since 5.0
*
* @return null
*/
static function plugin_meta_links($links, $file)
{
if ($file !== 'advanced-google-recaptcha/advanced-google-recaptcha.php') {
return $links;
}
$support_link = '<a href="https://getwpcaptcha.com/support/" title="' . __('Get help', 'advanced-google-recaptcha') . '">' . __('Support', 'advanced-google-recaptcha') . '</a>';
$links[] = $support_link;
return $links;
} // plugin_meta_links
/**
* Admin footer text
*
* @since 5.0
*
* @return null
*/
static function admin_footer_text($text)
{
if (!self::is_plugin_page()) {
return $text;
}
$text = '<i class="wpcaptcha-footer">WP Captcha v' . self::$version . ' <a href="' . self::generate_web_link('admin_footer') . '" title="Visit WP Captcha page for more info" target="_blank">WebFactory Ltd</a>. Please <a target="_blank" href="https://wordpress.org/support/plugin/advanced-google-recaptcha/reviews/#new-post" title="Rate the plugin">rate the plugin <span>★★★★★</span></a> to help us spread the word. Thank you 🙌 from the WebFactory team!</i>';
return $text;
} // admin_footer_text
/**
* Helper function for generating UTM tagged links
*
* @param string $placement Optional. UTM content param.
* @param string $page Optional. Page to link to.
* @param array $params Optional. Extra URL params.
* @param string $anchor Optional. URL anchor part.
*
* @return string
*/
static function generate_web_link($placement = '', $page = '/', $params = array(), $anchor = '')
{
$base_url = 'https://getwpcaptcha.com';
if ('/' != $page) {
$page = '/' . trim($page, '/') . '/';
}
if ($page == '//') {
$page = '/';
}
$parts = array_merge(array('utm_source' => 'advanced-google-recaptcha', 'utm_medium' => 'plugin', 'utm_content' => $placement, 'utm_campaign' => 'wpcaptcha-v' . self::$version), $params);
if (!empty($anchor)) {
$anchor = '#' . trim($anchor, '#');
}
$out = $base_url . $page . '?' . http_build_query($parts, '', '&amp;') . $anchor;
return $out;
} // generate_web_link
/**
* Test if we're on plugin's page
*
* @since 5.0
*
* @return null
*/
static function is_plugin_page()
{
$current_screen = get_current_screen();
if ($current_screen->id == 'settings_page_wpcaptcha') {
return true;
} else {
return false;
}
} // is_plugin_page
/**
* Settings Page HTML
*
* @since 5.0
*
* @return null
*/
static function main_page()
{
if (!current_user_can('manage_options')) {
wp_die('You do not have sufficient permissions to access this page.');
}
$options = WPCaptcha_Setup::get_options();
// auto remove welcome pointer when options are opened
$pointers = get_option(WPCAPTCHA_POINTERS_KEY);
if (isset($pointers['welcome'])) {
unset($pointers['welcome']);
update_option(WPCAPTCHA_POINTERS_KEY, $pointers);
}
echo '<div class="wrap">';
echo '<div class="wpcaptcha-header">
<div class="wp-captcha-logo">
<img src="' . esc_url(WPCAPTCHA_PLUGIN_URL) . '/images/wp-captcha-logo.png" alt="WP Captcha" height="60" title="WP Captcha">
</div>';
echo '<a data-tab="firewall" data-tab2="general" title="Click to open Firewall Settings" class="tooltip change_tab wpcaptcha-header-status wpcaptcha-header-status-' . ($options['firewall_block_bots'] == 1 ? 'enabled' : 'disabled') . '" style="width: 142px;">';
echo '<span class="dashicons dashicons-yes"></span>';
echo '<div class="option">Firewall</span></div>';
if ($options['firewall_block_bots'] == 'disabled') {
echo '<div class="status">Disabled</div>';
} else {
echo '<div class="status">Enabled</div>';
}
echo '</a>';
echo '<a data-tab="login_form" data-tab2="login_basic" title="Click to open Login Protection settings" class="tooltip change_tab wpcaptcha-header-status wpcaptcha-header-status-' . ($options['login_protection'] == 1 ? 'enabled' : 'disabled') . '">';
echo '<span class="dashicons dashicons-yes"></span>';
echo '<div class="option">Login Protection</span></div>';
if ($options['login_protection'] == 'disabled') {
echo '<div class="status">Disabled</div>';
} else {
echo '<div class="status">Enabled</div>';
}
echo '</a>';
echo '<a data-tab="captcha" data-tab2="captcha" title="Click to open Captcha settings" class="tooltip change_tab wpcaptcha-header-status wpcaptcha-header-status-' . ($options['captcha'] == 'disabled' ? 'disabled' : 'enabled') . '" style="width: 142px;">';
echo '<span class="dashicons dashicons-yes"></span>';
echo '<div class="option">Captcha</span></div>';
if ($options['captcha'] == 'disabled') {
echo '<div class="status">Disabled</div>';
} else {
echo '<div class="status">Enabled</div>';
}
echo '</a>';
echo '</div>';
echo '<h1></h1>';
echo '<form method="post" action="options.php" enctype="multipart/form-data" id="wpcaptcha_form">';
settings_fields(WPCAPTCHA_OPTIONS_KEY);
$tabs = array();
$tabs[] = array('id' => 'wpcaptcha_captcha', 'icon' => 'wpcaptcha-icon wpcaptcha-make-group', 'class' => '', 'label' => __('Captcha', 'advanced-google-recaptcha'), 'callback' => array('WPCaptcha_Tab_Captcha', 'display'));
$tabs[] = array('id' => 'wpcaptcha_activity', 'icon' => 'wpcaptcha-icon wpcaptcha-log', 'class' => '', 'label' => __('Activity', 'advanced-google-recaptcha'), 'callback' => array('WPCaptcha_Tab_Activity', 'display'));
$tabs[] = array('id' => 'wpcaptcha_login_form', 'icon' => 'wpcaptcha-icon wpcaptcha-enter', 'class' => '', 'label' => __('Login Protection', 'advanced-google-recaptcha'), 'callback' => array('WPCaptcha_Tab_Login_Form', 'display'));
$tabs[] = array('id' => 'wpcaptcha_firewall', 'icon' => 'wpcaptcha-icon wpcaptcha-check', 'class' => '', 'label' => __('Firewall', 'advanced-google-recaptcha'), 'callback' => array('WPCaptcha_Tab_Firewall', 'display'));
$tabs[] = array('id' => 'wpcaptcha_geoip', 'icon' => 'wpcaptcha-icon wpcaptcha-globe', 'class' => '', 'label' => __('Country Blocking', 'advanced-google-recaptcha'), 'callback' => array('WPCaptcha_Tab_GeoIP', 'display'));
$tabs[] = array('id' => 'wpcaptcha_design', 'icon' => 'wpcaptcha-icon wpcaptcha-settings', 'class' => '', 'label' => __('Design', 'advanced-google-recaptcha'), 'callback' => array('WPCaptcha_Tab_Design', 'display'));
$tabs[] = array('id' => 'wpcaptcha_temp_access', 'icon' => 'wpcaptcha-icon wpcaptcha-hour-glass', 'class' => '', 'label' => __('Temp Access', 'advanced-google-recaptcha'), 'callback' => array('WPCaptcha_Tab_Temporary_Access', 'display'));
$tabs[] = array('id' => 'wpcaptcha_pro', 'class' => 'open-upsell nav-tab-pro', 'icon' => '<span class="dashicons dashicons-star-filled"></span>', 'label' => __('PRO', 'advanced-google-recaptcha'), 'callback' => '');
$tabs = apply_filters('wpcaptcha_tabs', $tabs);
echo '<div id="wpcaptcha_tabs_wrapper" class="ui-tabs">';
echo '<div id="wpcaptcha_tabs" class="ui-tabs" style="display: none;">';
echo '<ul class="wpcaptcha-main-tab">';
foreach ($tabs as $tab) {
echo '<li><a ' . (!empty($tab['callback']) ? 'href="#' . esc_attr($tab['id']) . '"' : '') . 'class="' . esc_attr($tab['class']) . '">';
if (strpos($tab['icon'], 'dashicon')) {
WPCaptcha_Utility::wp_kses_wf($tab['icon']);
} else {
echo '<span class="icon"><i class="' . esc_attr($tab['icon']) . '"></i></span>';
}
echo '<span class="label">' . esc_attr($tab['label']) . '</span></a></li>';
}
echo '</ul>';
foreach ($tabs as $tab) {
if (is_callable($tab['callback'])) {
echo '<div style="display: none;" id="' . esc_attr($tab['id']) . '">';
call_user_func($tab['callback']);
echo '</div>';
}
} // foreach
echo '</div>';
echo '</div>';
echo '<div id="wpcaptcha_tabs_sidebar" style="display:none;">';
echo '<div class="sidebar-box pro-ad-box">
<p class="text-center"><a href="#" data-pro-feature="sidebar-box-logo" class="open-pro-dialog">
<img src="' . esc_url(WPCAPTCHA_PLUGIN_URL . '/images/wp-captcha-logo.png') . '" alt="WP Captcha PRO" title="WP Captcha PRO"></a><br><b>PRO version is here! Grab the launch discount.</b></p>
<ul class="plain-list">
<li>7 Types of Captcha + GDPR Compatibility</li>
<li>Login Page Customization - Visual &amp; URL</li>
<li>Advanced Login Page Protection</li>
<li>Email Based Two Factor Authentication (2FA)</li>
<li>Advanced Firewall + Cloud Blacklists</li>
<li>Country Blocking (whitelist &amp; blacklist)</li>
<li>Temporary Access Links</li>
<li>Recovery URL - You Can Never Get Locked Out</li>
<li>Licenses &amp; Sites Manager (remote SaaS dashboard)</li>
<li>White-label Mode</li>
<li>Complete Codeless Plugin Rebranding</li>
<li>Email support from plugin developers</li>
</ul>
<p class="text-center"><a href="#" class="open-pro-dialog button button-buy" data-pro-feature="sidebar-box">Get PRO Now</a></p>
</div>';
if (!defined('EPS_REDIRECT_VERSION') && !defined('WF301_PLUGIN_FILE')) {
echo '<div class="sidebar-box pro-ad-box box-301">
<h3 class="textcenter"><b>Problems with redirects?<br>Moving content around or changing posts\' URL?<br>Old URLs giving you problems?<br><br><u>Improve your SEO &amp; manage all redirects in one place!</u></b></h3>
<p class="text-center"><a href="#" class="install-wp301">
<img src="' . esc_url(WPCAPTCHA_PLUGIN_URL . '/images/wp-301-logo.png') . '" alt="WP 301 Redirects" title="WP 301 Redirects"></a></p>
<p class="text-center"><a href="#" class="button button-buy install-wp301">Install and activate the <u>free</u> WP 301 Redirects plugin</a></p>
<p><a href="https://wordpress.org/plugins/eps-301-redirects/" target="_blank">WP 301 Redirects</a> is a free WP plugin maintained by the same team as this WP Captcha plugin. It has <b>+250,000 users, 5-star rating</b>, and is hosted on the official WP repository.</p>
</div>';
}
echo '<div class="sidebar-box" style="margin-top: 35px;">
<p>Please <a href="https://wordpress.org/support/plugin/advanced-google-recaptcha/reviews/#new-post" target="_blank">rate the plugin ★★★★★</a> to <b>keep it up-to-date &amp; maintained</b>. It only takes a second to rate. Thank you! 👋</p>
</div>';
echo '</div>';
echo '</form>';
echo ' <div id="wpcaptcha-pro-dialog" style="display: none;" title="WP Captcha PRO is here!"><span class="ui-helper-hidden-accessible"><input type="text"/></span>
<div class="center logo"><a href="https://getwpcaptcha.com/?ref=wpcaptcha-free-pricing-table" target="_blank"><img src="' . esc_url(WPCAPTCHA_PLUGIN_URL . '/images/wp-captcha-logo.png') . '" alt="WP Captcha PRO" title="WP Captcha PRO"></a><br>
<span>Grab the limited PRO <b>Launch Discount</b></span>
</div>
<table id="wpcaptcha-pro-table">
<tr>
<td class="center">Personal License</td>
<td class="center">Team License</td>
<td class="center">Agency License</td>
</tr>
<tr class="prices">
<td class="center"><span><del>$59</del> $49</span> <b>/year</b></td>
<td class="center"><span><del>$119</del> $99</span> <b>/year</b></td>
<td class="center"><span><del>$149</del> $119</span> <b>/year</b></td>
</tr>
<tr>
<td><span class="dashicons dashicons-yes"></span><b>1 Site License</b> ($49 per site)</td>
<td><span class="dashicons dashicons-yes"></span><b>5 Sites License</b> ($20 per site)</td>
<td><span class="dashicons dashicons-yes"></span><b>100 Sites License</b> ($1.2 per site)</td>
</tr>
<tr>
<td><span class="dashicons dashicons-yes"></span>All Plugin Features</td>
<td><span class="dashicons dashicons-yes"></span>All Plugin Features</td>
<td><span class="dashicons dashicons-yes"></span>All Plugin Features</td>
</tr>
<tr>
<td><span class="dashicons dashicons-yes"></span>7 Types of Captcha</td>
<td><span class="dashicons dashicons-yes"></span>7 Types of Captcha</td>
<td><span class="dashicons dashicons-yes"></span>7 Types of Captcha</td>
</tr>
<tr>
<td><span class="dashicons dashicons-yes"></span>Advanced Firewall + Cloud Blacklists</td>
<td><span class="dashicons dashicons-yes"></span>Advanced Firewall + Cloud Blacklists</td>
<td><span class="dashicons dashicons-yes"></span>Advanced Firewall + Cloud Blacklists</td>
</tr>
<tr>
<td><span class="dashicons dashicons-yes"></span>Login Page Customization</td>
<td><span class="dashicons dashicons-yes"></span>Login Page Customization</td>
<td><span class="dashicons dashicons-yes"></span>Login Page Customization</td>
</tr>
<tr>
<td><span class="dashicons dashicons-yes"></span>Email Based 2FA</td>
<td><span class="dashicons dashicons-yes"></span>Email Based 2FA</td>
<td><span class="dashicons dashicons-yes"></span>Email Based 2FA</td>
</tr>
<tr>
<td><span class="dashicons dashicons-yes"></span>Temporary Access Links</td>
<td><span class="dashicons dashicons-yes"></span>Temporary Access Links</td>
<td><span class="dashicons dashicons-yes"></span>Temporary Access Links</td>
</tr>
<tr>
<td><span class="dashicons dashicons-yes"></span>Country Blocking</td>
<td><span class="dashicons dashicons-yes"></span>Country Blocking</td>
<td><span class="dashicons dashicons-yes"></span>Country Blocking</td>
</tr>
<tr>
<td><span class="dashicons dashicons-yes"></span>SaaS Dashboard</td>
<td><span class="dashicons dashicons-yes"></span>SaaS Dashboard</td>
<td><span class="dashicons dashicons-yes"></span>SaaS Dashboard</td>
</tr>
<tr>
<td><span class="dashicons dashicons-no"></span>White-label Mode</td>
<td><span class="dashicons dashicons-yes"></span>White-label Mode</td>
<td><span class="dashicons dashicons-yes"></span>White-label Mode</td>
</tr>
<tr>
<td><span class="dashicons dashicons-no"></span>Full Plugin Rebranding</td>
<td><span class="dashicons dashicons-no"></span>Full Plugin Rebranding</td>
<td><span class="dashicons dashicons-yes"></span>Full Plugin Rebranding</td>
</tr>
<tr>
<td><a class="button button-buy" data-href-org="https://getwpcaptcha.com/buy/?product=personal-yearly-launch&ref=pricing-table" href="https://getwpcaptcha.com/buy/?product=personal-yearly-launch&ref=pricing-table" target="_blank"><del>$59</del> $49 <small>/y</small><br>BUY NOW</a>
<br>or <a class="button-buy" data-href-org="https://getwpcaptcha.com/buy/?product=personal-ltd-launch&ref=pricing-table" href="https://getwpcaptcha.com/buy/?product=personal-ltd-launch&ref=pricing-table" target="_blank">only <del>$99</del> $79 for a lifetime license</a></td>
<td><a class="button button-buy" data-href-org="https://getwpcaptcha.com/buy/?product=team-yearly-launch&ref=pricing-table" href="https://getwpcaptcha.com/buy/?product=team-yearly-launch&ref=pricing-table" target="_blank"><del>$119</del> $99 <small>/y</small><br>BUY NOW</a></td>
<td><a class="button button-buy" data-href-org="https://getwpcaptcha.com/buy/?product=agency-yearly-launch&ref=pricing-table" href="https://getwpcaptcha.com/buy/?product=agency-yearly-launch&ref=pricing-table" target="_blank"><del>$149</del> $119 <small>/y</small><br>BUY NOW</a></td>
</tr>
</table>
<div class="center footer"><b>100% No-Risk Money Back Guarantee!</b> If you don\'t like the plugin over the next 7 days, we will happily refund 100% of your money. No questions asked! Payments are processed by our merchant of records - <a href="https://paddle.com/" target="_blank">Paddle</a>.</div>
</div>';
echo '</div>'; // wrap
} // options_page
/**
* Reset pointers
*
* @since 5.0
*
* @return null
*/
static function reset_pointers()
{
$pointers = array();
$pointers['welcome'] = array('target' => '#menu-settings', 'edge' => 'left', 'align' => 'right', 'content' => 'Thank you for installing the <b style="font-weight: 800; font-variant: small-caps;">Advanced Google reCAPTCHA</b> plugin! Please open <a href="' . admin_url('options-general.php?page=wpcaptcha') . '">Settings - Advanced Google reCaptcha</a> to set up your captcha and website protection settings.');
update_option(WPCAPTCHA_POINTERS_KEY, $pointers);
} // reset_pointers
/**
* Settings footer submit button HTML
*
* @since 5.0
*
* @return null
*/
static function footer_save_button()
{
echo '<p class="submit">';
echo '<button class="button button-primary button-large">' . __('Save Changes', 'advanced-google-recaptcha') . ' <i class="wpcaptcha-icon wpcaptcha-checkmark"></i></button>';
echo '</p>';
} // footer_save_button
} // class

View File

@ -0,0 +1,408 @@
<?php
/**
* WP Captcha
* https://getwpcaptcha.com/
* (c) WebFactory Ltd, 2022 - 2023, www.webfactoryltd.com
*/
class WPCaptcha_AJAX extends WPCaptcha
{
/**
* Run one tool via AJAX call
*
* @return null
*/
static function ajax_run_tool()
{
global $wpdb, $current_user;
check_ajax_referer('wpcaptcha_run_tool');
set_time_limit(300);
$tool = trim(@$_REQUEST['tool']);
$options = WPCaptcha_Setup::get_options();
$update['last_options_edit'] = current_time('mysql', true);
update_option(WPCAPTCHA_OPTIONS_KEY, array_merge($options, $update));
if ($tool == 'activity_logs') {
self::get_activity_logs();
} else if ($tool == 'locks_logs') {
self::get_locks_logs();
} else if ($tool == 'recovery_url') {
if ($_POST['reset'] == 'true') {
sleep(1);
$options['global_unblock_key'] = 'll' . md5(time() . rand(10000, 9999));
update_option(WPCAPTCHA_OPTIONS_KEY, array_merge($options, $update));
}
wp_send_json_success(array('url' => '<a href="' . site_url('/?wpcaptcha_unblock=' . $options['global_unblock_key']) . '">' . site_url('/?wpcaptcha_unblock=' . $options['global_unblock_key']) . '</a>'));
} else if ($tool == 'empty_log') {
self::empty_log(sanitize_text_field($_POST['log']));
wp_send_json_success();
} else if ($tool == 'unlock_accesslock') {
$wpdb->update(
$wpdb->wpcatcha_accesslocks,
array(
'unlocked' => 1
),
array(
'accesslock_ID' => intval($_POST['lock_id'])
)
);
wp_send_json_success(array('id' => $_POST['lock_id']));
} else if ($tool == 'delete_lock_log') {
$wpdb->delete(
$wpdb->wpcatcha_accesslocks,
array(
'accesslock_ID' => intval($_POST['lock_id'])
)
);
wp_send_json_success(array('id' => $_POST['lock_id']));
} else if ($tool == 'delete_fail_log') {
$wpdb->delete(
$wpdb->wpcatcha_login_fails,
array(
'login_attempt_ID' => intval($_POST['fail_id'])
)
);
wp_send_json_success(array('id' => $_POST['fail_id']));
} else if ($tool == 'wpcaptcha_dismiss_pointer') {
delete_option(WPCAPTCHA_POINTERS_KEY);
wp_send_json_success();
} else if ($tool == 'verify_captcha') {
$captcha_result = self::verify_captcha($_POST['captcha_type'], $_POST['captcha_site_key'], $_POST['captcha_secret_key'], $_POST['captcha_response']);
if (is_wp_error($captcha_result)) {
wp_send_json_error($captcha_result->get_error_message());
}
wp_send_json_success();
} else {
wp_send_json_error(__('Unknown tool.', 'advanced-google-recaptcha'));
}
die();
} // ajax_run_tool
/**
* Get rule row html
*
* @return string row HTML
*
* @param array $data with rule settings
*/
static function get_date_time($timestamp)
{
$interval = current_time('timestamp') - $timestamp;
return '<span class="wpcaptcha-dt-small">' . self::humanTiming($interval, true) . '</span><br />' . date('Y/m/d', $timestamp) . ' <span class="wpcaptcha-dt-small">' . date('h:i:s A', $timestamp) . '</span>';
}
static function verify_captcha($type, $site_key, $secret_key, $response)
{
if ($type == 'builtin') {
if ($response === $_COOKIE['wpcaptcha_captcha']) {
return true;
} else {
return new WP_Error('wpcaptcha_builtin_captcha_failed', __("<strong>ERROR</strong>: captcha verification failed.<br /><br />Please try again.", 'advanced-google-recaptcha'));
}
} else if ($type == 'recaptchav2') {
if (!isset($response) || empty($response)) {
return new WP_Error('wpcaptcha_recaptchav2_not_submitted', __("reCAPTCHA verification failed ", 'advanced-google-recaptcha'));
} else {
$response = wp_remote_get('https://www.google.com/recaptcha/api/siteverify?secret=' . $secret_key . '&response=' . $response);
$response = json_decode($response['body']);
if ($response->success) {
return true;
} else {
return new WP_Error('wpcaptcha_recaptchav2_failed', __("reCAPTCHA verification failed " . (isset($response->{'error-codes'}) ? ': ' . implode(',', $response->{'error-codes'}) : ''), 'advanced-google-recaptcha'));
}
}
} else if ($type == 'recaptchav3') {
if (!isset($response) || empty($response)) {
return new WP_Error('wpcaptcha_recaptchav3_not_submitted', __("reCAPTCHA verification failed ", 'advanced-google-recaptcha'));
} else {
$response = wp_remote_get('https://www.google.com/recaptcha/api/siteverify?secret=' . $secret_key . '&response=' . $response);
$response = json_decode($response['body']);
if ($response->success) {
return true;
} else {
return new WP_Error('wpcaptcha_recaptchav2_failed', __("reCAPTCHA verification failed " . (isset($response->{'error-codes'}) ? ': ' . implode(',', $response->{'error-codes'}) : ''), 'advanced-google-recaptcha'));
}
}
}
}
/**
* Get human readable timestamp like 2 hours ago
*
* @return int time
*
* @param string timestamp
*/
static function humanTiming($time)
{
$tokens = array(
31536000 => 'year',
2592000 => 'month',
604800 => 'week',
86400 => 'day',
3600 => 'hour',
60 => 'minute',
1 => 'second'
);
if ($time < 1) {
return 'just now';
}
foreach ($tokens as $unit => $text) {
if ($time < $unit) continue;
$numberOfUnits = floor($time / $unit);
return $numberOfUnits . ' ' . $text . (($numberOfUnits > 1) ? 's' : '') . ' ago';
}
}
static function empty_log($log)
{
global $wpdb;
if ($log == 'fails') {
$wpdb->query('TRUNCATE TABLE ' . $wpdb->wpcatcha_login_fails);
} else {
$wpdb->query('TRUNCATE TABLE ' . $wpdb->wpcatcha_accesslocks);
}
}
/**
* Fetch activity logs and output JSON for datatables
*
* @return null
*/
static function get_locks_logs()
{
global $wpdb;
$aColumns = array('accesslock_ID', 'unlocked', 'accesslock_date', 'release_date', 'reason', 'accesslock_IP');
$sIndexColumn = "accesslock_ID";
// paging
$sLimit = '';
if (isset($_GET['iDisplayStart']) && $_GET['iDisplayLength'] != '-1') {
$sLimit = "LIMIT " . intval($_GET['iDisplayStart']) . ", " .
intval($_GET['iDisplayLength']);
} // paging
// ordering
$sOrder = '';
if (isset($_GET['iSortCol_0'])) {
$sOrder = "ORDER BY ";
for ($i = 0; $i < intval($_GET['iSortingCols']); $i++) {
if ($_GET['bSortable_' . intval($_GET['iSortCol_' . $i])] == "true") {
$sOrder .= $aColumns[intval($_GET['iSortCol_' . $i])] . " "
. ($_GET['sSortDir_' . $i] == 'desc'?'desc':'asc') . ", ";
}
}
$sOrder = substr_replace($sOrder, '', -2);
if ($sOrder == "ORDER BY") {
$sOrder = '';
}
} // ordering
// filtering
$sWhere = '';
if (isset($_GET['sSearch']) && $_GET['sSearch'] != '') {
$sWhere = "WHERE (";
for ($i = 0; $i < count($aColumns); $i++) {
$sWhere .= $aColumns[$i] . " LIKE '%" . esc_sql($_GET['sSearch']) . "%' OR ";
}
$sWhere = substr_replace($sWhere, '', -3);
$sWhere .= ')';
} // filtering
// individual column filtering
for ($i = 0; $i < count($aColumns); $i++) {
if (isset($_GET['bSearchable_' . $i]) && $_GET['bSearchable_' . $i] == "true" && $_GET['sSearch_' . $i] != '') {
if ($sWhere == '') {
$sWhere = "WHERE ";
} else {
$sWhere .= " AND ";
}
$sWhere .= $aColumns[$i] . " LIKE '%" . esc_sql($_GET['sSearch_' . $i]) . "%' ";
}
} // individual columns
// build query
$wpdb->sQuery = "SELECT SQL_CALC_FOUND_ROWS " . str_replace(" , ", " ", implode(", ", $aColumns)) . " FROM " . $wpdb->wpcatcha_accesslocks . " $sWhere $sOrder $sLimit";
$rResult = $wpdb->get_results($wpdb->sQuery);
// data set length after filtering
$wpdb->sQuery = "SELECT FOUND_ROWS()";
$iFilteredTotal = $wpdb->get_var($wpdb->sQuery);
// total data set length
$wpdb->sQuery = "SELECT COUNT(" . $sIndexColumn . ") FROM " . $wpdb->wpcatcha_accesslocks;
$iTotal = $wpdb->get_var($wpdb->sQuery);
// construct output
$output = array(
"sEcho" => intval(@$_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array()
);
foreach ($rResult as $aRow) {
$row = array();
$row['DT_RowId'] = $aRow->accesslock_ID;
if (strtotime($aRow->release_date) < time()) {
$row['DT_RowClass'] = 'lock_expired';
}
for ($i = 0; $i < count($aColumns); $i++) {
if ($aColumns[$i] == 'unlocked') {
$unblocked = $aRow->{$aColumns[$i]};
if ($unblocked == 0 && strtotime($aRow->release_date) > time()) {
$row[] = '<div class="tooltip unlock_accesslock" data-lock-id="' . $aRow->accesslock_ID . '" title="Unlock"><i class="wpcaptcha-icon wpcaptcha-lock"></i></div>';
} else {
$row[] = '<div class="tooltip unlocked_accesslock" title="Unlock"><i class="wpcaptcha-icon wpcaptcha-unlock"></i></div>';
}
} else if ($aColumns[$i] == 'accesslock_date') {
$row[] = self::get_date_time(strtotime($aRow->{$aColumns[$i]}));
} else if ($aColumns[$i] == 'reason') {
$row[] = $aRow->{$aColumns[$i]};
} else if ($aColumns[$i] == 'accesslock_IP') {
$row[] = '<a href="#" class="open-pro-dialog pro-feature" data-pro-feature="access-log-user-location">Available in PRO</a>';
$row[] = '<a href="#" class="open-pro-dialog pro-feature" data-pro-feature="access-log-user-agent">Available in PRO</a>';
}
}
$row[] = '<div data-lock-id="' . $aRow->accesslock_ID . '" class="tooltip delete_lock_entry" title="Delete Access Lock?" data-msg-success="Access Lock deleted" data-btn-confirm="Delete Access Lock" data-title="Delete Access Lock?" data-wait-msg="Deleting. Please wait." data-name="" title="Delete this Access Lock"><i class="wpcaptcha-icon wpcaptcha-trash"></i></div>';
$output['aaData'][] = $row;
} // foreach row
// json encoded output
@ob_end_clean();
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
echo json_encode($output);
die();
}
/**
* Fetch activity logs and output JSON for datatables
*
* @return null
*/
static function get_activity_logs()
{
global $wpdb;
$options = WPCaptcha_Setup::get_options();
$aColumns = array('login_attempt_ID', 'login_attempt_date', 'failed_user', 'failed_pass', 'login_attempt_IP', 'reason');
$sIndexColumn = "login_attempt_ID";
// paging
$sLimit = '';
if (isset($_GET['iDisplayStart']) && $_GET['iDisplayLength'] != '-1') {
$sLimit = "LIMIT " . intval($_GET['iDisplayStart']) . ", " .
intval($_GET['iDisplayLength']);
} // paging
// ordering
$sOrder = '';
if (isset($_GET['iSortCol_0'])) {
$sOrder = "ORDER BY ";
for ($i = 0; $i < intval($_GET['iSortingCols']); $i++) {
if ($_GET['bSortable_' . intval($_GET['iSortCol_' . $i])] == "true") {
$sOrder .= $aColumns[intval($_GET['iSortCol_' . $i])] . " "
. ($_GET['sSortDir_' . $i] == 'desc'?'desc':'asc') . ", ";
}
}
$sOrder = substr_replace($sOrder, '', -2);
if ($sOrder == "ORDER BY") {
$sOrder = '';
}
} // ordering
// filtering
$sWhere = '';
if (isset($_GET['sSearch']) && $_GET['sSearch'] != '') {
$sWhere = "WHERE (";
for ($i = 0; $i < count($aColumns); $i++) {
$sWhere .= $aColumns[$i] . " LIKE '%" . esc_sql($_GET['sSearch']) . "%' OR ";
}
$sWhere = substr_replace($sWhere, '', -3);
$sWhere .= ')';
} // filtering
// individual column filtering
for ($i = 0; $i < count($aColumns); $i++) {
if (isset($_GET['bSearchable_' . $i]) && $_GET['bSearchable_' . $i] == "true" && $_GET['sSearch_' . $i] != '') {
if ($sWhere == '') {
$sWhere = "WHERE ";
} else {
$sWhere .= " AND ";
}
$sWhere .= $aColumns[$i] . " LIKE '%" . esc_sql($_GET['sSearch_' . $i]) . "%' ";
}
} // individual columns
// build query
$wpdb->sQuery = "SELECT SQL_CALC_FOUND_ROWS " . str_replace(" , ", " ", implode(", ", $aColumns)) .
" FROM " . $wpdb->wpcatcha_login_fails . " $sWhere $sOrder $sLimit";
$rResult = $wpdb->get_results($wpdb->sQuery);
// data set length after filtering
$wpdb->sQuery = "SELECT FOUND_ROWS()";
$iFilteredTotal = $wpdb->get_var($wpdb->sQuery);
// total data set length
$wpdb->sQuery = "SELECT COUNT(" . $sIndexColumn . ") FROM " . $wpdb->wpcatcha_login_fails;
$iTotal = $wpdb->get_var($wpdb->sQuery);
// construct output
$output = array(
"sEcho" => intval(@$_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array()
);
foreach ($rResult as $aRow) {
$row = array();
$row['DT_RowId'] = $aRow->login_attempt_ID;
for ($i = 0; $i < count($aColumns); $i++) {
if ($aColumns[$i] == 'login_attempt_date') {
$row[] = self::get_date_time(strtotime($aRow->{$aColumns[$i]}));
} elseif ($aColumns[$i] == 'failed_user') {
$failed_login = '';
$failed_login .= '<strong>User:</strong> ' . htmlspecialchars($aRow->failed_user) . '<br />';
if ($options['log_passwords'] == 1) {
$failed_login .= '<strong>Pass:</strong> ' . htmlspecialchars($aRow->failed_pass) . '<br />';
}
$row[] = $failed_login;
} else if ($aColumns[$i] == 'login_attempt_IP') {
$row[] = '<a href="#" class="open-pro-dialog pro-feature" data-pro-feature="fail-log-user-location">Available in PRO</a>';
$row[] = '<a href="#" class="open-pro-dialog pro-feature" data-pro-feature="fail-log-user-agent">Available in PRO</a>';
} elseif ($aColumns[$i] == 'reason') {
$row[] = WPCaptcha_Functions::pretty_fail_errors($aRow->{$aColumns[$i]});
}
}
$row[] = '<div data-failed-id="' . $aRow->login_attempt_ID . '" class="tooltip delete_failed_entry" title="Delete failed login attempt log entry" data-msg-success="Failed login attempt log entry deleted" data-btn-confirm="Delete failed login attempt log entry" data-title="Delete failed login attempt log entry" data-wait-msg="Deleting. Please wait." data-name="" title="Delete this failed login attempt log entry"><i class="wpcaptcha-icon wpcaptcha-trash"></i></div>';
$output['aaData'][] = $row;
} // foreach row
// json encoded output
@ob_end_clean();
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
echo json_encode($output);
die();
}
} // class

View File

@ -0,0 +1,109 @@
<?php
/**
* WP Captcha
* https://getwpcaptcha.com/
* (c) WebFactory Ltd, 2022 - 2023, www.webfactoryltd.com
*/
class WPCaptcha_Captcha {
// convert HEX(HTML) color notation to RGB
static function hex2rgb($color) {
if ($color[0] == '#') {
$color = substr($color, 1);
}
if (strlen($color) == 6) {
list($r, $g, $b) = array($color[0].$color[1],
$color[2].$color[3],
$color[4].$color[5]);
} elseif (strlen($color) == 3) {
list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
} else {
return array(255, 255, 255);
}
$r = hexdec($r);
$g = hexdec($g);
$b = hexdec($b);
return array($r, $g, $b);
} // html2rgb
// output captcha image
static function generate() {
$a = rand(0, (int) 10);
$b = rand(0, (int) 10);
$color = @$_GET['color'];
$color = urldecode($color);
if(isset($_GET['id'])){
$captcha_cookie_name = 'wpcaptcha_captcha_' . intval($_GET['id']);
} else{
$captcha_cookie_name = 'wpcaptcha_captcha';
}
if ($a > $b) {
$out = "$a - $b";
$captcha_value = $a - $b;
} else {
$out = "$a + $b";
$captcha_value = $a + $b;
}
setcookie($captcha_cookie_name, $captcha_value, time() + 60 * 5, '/');
$font = 5;
$width = ImageFontWidth($font) * strlen($out);
$height = ImageFontHeight($font);
$im = ImageCreate($width, $height);
$x = imagesx($im) - $width ;
$y = imagesy($im) - $height;
$white = imagecolorallocate ($im, 255, 255, 255);
$gray = imagecolorallocate ($im, 66, 66, 66);
$black = imagecolorallocate ($im, 0, 0, 0);
$trans_color = $white; //transparent color
if ($color) {
$color = self::hex2rgb($color);
$new_color = imagecolorallocate ($im, $color[0], $color[1], $color[2]);
imagefill($im, 1, 1, $new_color);
} else {
imagecolortransparent($im, $trans_color);
}
imagestring ($im, $font, $x, $y, $out, $black);
// always add noise
if (1 == 1) {
$color_min = 100;
$color_max = 200;
$rand1 = imagecolorallocate ($im, rand($color_min,$color_max), rand($color_min,$color_max), rand($color_min,$color_max));
$rand2 = imagecolorallocate ($im, rand($color_min,$color_max), rand($color_min,$color_max), rand($color_min,$color_max));
$rand3 = imagecolorallocate ($im, rand($color_min,$color_max), rand($color_min,$color_max), rand($color_min,$color_max));
$rand4 = imagecolorallocate ($im, rand($color_min,$color_max), rand($color_min,$color_max), rand($color_min,$color_max));
$rand5 = imagecolorallocate ($im, rand($color_min,$color_max), rand($color_min,$color_max), rand($color_min,$color_max));
$style = array($rand1, $rand2, $rand3, $rand4, $rand5);
imagesetstyle($im, $style);
imageline($im, rand(0, $width), 0, rand(0, $width), $height, IMG_COLOR_STYLED);
imageline($im, rand(0, $width), 0, rand(0, $width), $height, IMG_COLOR_STYLED);
imageline($im, rand(0, $width), 0, rand(0, $width), $height, IMG_COLOR_STYLED);
imageline($im, rand(0, $width), 0, rand(0, $width), $height, IMG_COLOR_STYLED);
imageline($im, rand(0, $width), 0, rand(0, $width), $height, IMG_COLOR_STYLED);
}
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Content-type: image/gif');
imagegif($im);
die();
} // create
} // WPCaptcha_Captcha
if (isset($_GET['wpcaptcha-generate-image'])) {
WPCaptcha_Captcha::generate();
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,720 @@
<?php
/**
* WP Captcha
* https://getwpcaptcha.com/
* (c) WebFactory Ltd, 2022 - 2023, www.webfactoryltd.com
*/
class WPCaptcha_Setup extends WPCaptcha
{
static $wp_filesystem;
/**
* Actions to run on load, but init would be too early as not all classes are initialized
*
* @return null
*/
static function load_actions()
{
self::register_custom_tables();
} // admin_actions
static function setup_wp_filesystem()
{
global $wp_filesystem;
if (empty($wp_filesystem)) {
require_once ABSPATH . '/wp-admin/includes/file.php';
WP_Filesystem();
}
self::$wp_filesystem = $wp_filesystem;
return self::$wp_filesystem;
} // setup_wp_filesystem
/**
* Check if user has the minimal WP version required by WP Captcha
*
* @since 5.0
*
* @return bool
*
*/
static function check_wp_version($min_version)
{
if (!version_compare(get_bloginfo('version'), $min_version, '>=')) {
add_action('admin_notices', array(__CLASS__, 'notice_min_wp_version'));
return false;
} else {
return true;
}
} // check_wp_version
/**
* Check if user has the minimal PHP version required by WP Captcha
*
* @since 5.0
*
* @return bool
*
*/
static function check_php_version($min_version)
{
if (!version_compare(phpversion(), $min_version, '>=')) {
add_action('admin_notices', array(__CLASS__, 'notice_min_php_version'));
return false;
} else {
return true;
}
} // check_wp_version
/**
* Display error message if WP version is too low
*
* @since 5.0
*
* @return null
*
*/
static function notice_min_wp_version()
{
WPCaptcha_Utility::wp_kses_wf('<div class="error"><p>' . sprintf(__('WP Captcha plugin <b>requires WordPress version 4.6</b> or higher to function properly. You are using WordPress version %s. Please <a href="%s">update it</a>.', 'advanced-google-recaptcha'), get_bloginfo('version'), admin_url('update-core.php')) . '</p></div>');
} // notice_min_wp_version_error
/**
* Display error message if PHP version is too low
*
* @since 5.0
*
* @return null
*
*/
static function notice_min_php_version()
{
WPCaptcha_Utility::wp_kses_wf('<div class="error"><p>' . sprintf(__('WP Captcha plugin <b>requires PHP version 5.6.20</b> or higher to function properly. You are using PHP version %s. Please <a href="%s" target="_blank">update it</a>.', 'advanced-google-recaptcha'), phpversion(), 'https://wordpress.org/support/update-php/') . '</p></div>');
} // notice_min_wp_version_error
/**
* activate doesn't get fired on upgrades so we have to compensate
*
* @since 5.0
*
* @return null
*
*/
public static function maybe_upgrade()
{
$meta = self::get_meta();
if (empty($meta['database_ver']) || $meta['database_ver'] < self::$version) {
self::create_custom_tables();
}
// Copy options from free
$options = get_option(WPCAPTCHA_OPTIONS_KEY);
if (false === $options) {
$free_options = get_option("agr_options");
if (false !== $free_options && isset($free_options['enable_login'])) {
$options['captcha'] = $free_options['captcha_type'] == 'v3'?'recaptchav3':'recaptchav2';
$options['captcha_site_key'] = $free_options['site_key'];
$options['captcha_secret_key'] = $free_options['secret_key'];
$options['captcha_show_login'] = $free_options['enable_login'];
$options['captcha_show_wp_registration'] = $free_options['enable_register'];
$options['captcha_show_wp_lost_password'] = $free_options['enable_lost_password'];
$options['captcha_show_wp_comment'] = $free_options['enable_comment_form'];
$options['captcha_show_woo_registration'] = $free_options['enable_woo_register'];
$options['captcha_show_woo_checkout'] = $free_options['enable_woo_checkout'];
$options['captcha_show_edd_registration'] = $free_options['enable_edd_register'];
$options['captcha_show_bp_registration'] = $free_options['enable_bp_register'];
update_option(WPCAPTCHA_OPTIONS_KEY, $options);
///delete_option("agr_options");
}
}
} // maybe_upgrade
/**
* Get plugin options
*
* @since 5.0
*
* @return array options
*
*/
static function get_options()
{
$options = get_option(WPCAPTCHA_OPTIONS_KEY, array());
if (!is_array($options)) {
$options = array();
}
$options = array_merge(self::default_options(), $options);
return $options;
} // get_options
/**
* Register all settings
*
* @since 5.0
*
* @return false
*
*/
static function register_settings()
{
register_setting(WPCAPTCHA_OPTIONS_KEY, WPCAPTCHA_OPTIONS_KEY, array(__CLASS__, 'sanitize_settings'));
} // register_settings
/**
* Set default options
*
* @since 5.0
*
* @return null
*
*/
static function default_options()
{
$defaults = array(
'login_protection' => 0,
'max_login_retries' => 3,
'retries_within' => 5,
'lockout_length' => 60,
'lockout_invalid_usernames' => 1,
'mask_login_errors' => 0,
'show_credit_link' => 0,
'anonymous_logging' => 0,
'block_bots' => 0,
'log_passwords' => 0,
'instant_block_nonusers' => 0,
'cookie_lifetime' => 14,
'country_blocking_mode' => 'none',
'country_blocking_countries' => '',
'block_undetermined_countries' => 0,
'captcha' => 'disabled',
'captcha_secret_key' => '',
'captcha_site_key' => '',
'captcha_show_login' => 1,
'captcha_show_wp_registration' => 1,
'captcha_show_wp_lost_password' => 1,
'captcha_show_wp_comment' => 1,
'captcha_show_woo_registration' => 0,
'captcha_show_woo_checkout' => 0,
'captcha_show_edd_registration' => 0,
'captcha_show_bp_registration' => 0,
'login_url' => '',
'login_redirect_url' => '',
'global_block' => 0,
'country_global_block' => 0,
'uninstall_delete' => 0,
'block_message' => 'We\'re sorry, but your IP has been blocked due to too many recent failed login attempts.',
'block_message_country' => 'We\'re sorry, but access from your location is not allowed.',
'global_unblock_key' => 'll' . md5(time() . rand(10000, 9999)),
'whitelist' => array(),
'firewall_block_bots' => 0,
'firewall_directory_traversal' => 0,
'design_enable' => 0,
'design_template' => 'orange',
'design_background_color' => '',
'design_background_image' => '',
'design_logo' => '',
'design_logo_url' => '',
'design_logo_width' => '',
'design_logo_height' => '',
'design_logo_margin_bottom' => '',
'design_text_color' => '#3c434a',
'design_link_color' => '#2271b1',
'design_link_hover_color' => '#135e96',
'design_form_border_color' => '#FFFFFF',
'design_form_border_width' => 1,
'design_form_width' => '',
'design_form_width' => '',
'design_form_height' => '',
'design_form_padding' => 26,
'design_form_border_radius' => 2,
'design_form_background_color' => '',
'design_form_background_image' => '',
'design_label_font_size' => 14,
'design_label_text_color' => '#3c434a',
'design_field_font_size' => 13,
'design_field_text_color' => '#3c434a',
'design_field_border_color' => '#8c8f94',
'design_field_border_width' => 1,
'design_field_border_radius' => 2,
'design_field_background_color' => '#ffffff',
'design_button_font_size' => 14,
'design_button_text_color' => '',
'design_button_border_color' => '#2271b1',
'design_button_border_width' => 0,
'design_button_border_radius' => 2,
'design_button_background_color' => '#2271b1',
'design_button_hover_text_color' => '',
'design_button_hover_border_color' => '',
'design_button_hover_background_color' => '',
'design_custom_css' => ''
);
return $defaults;
} // default_options
/**
* Sanitize settings on save
*
* @since 5.0
*
* @return array updated options
*
*/
static function sanitize_settings($options)
{
$old_options = self::get_options();
if (isset($options['captcha_verified']) && $options['captcha_verified'] != 1 && $options['captcha'] != 'disabled') {
$options['captcha'] = $old_options['captcha'];
$options['captcha_site_key'] = $old_options['captcha_site_key'];
$options['captcha_secret_key'] = $old_options['captcha_secret_key'];
}
if (isset($options['captcha']) && ($options['captcha'] == 'disabled' || $options['captcha'] == 'builtin')) {
$options['captcha_site_key'] = '';
$options['captcha_secret_key'] = '';
}
if (isset($_POST['submit'])) {
foreach ($options as $key => $value) {
switch ($key) {
case 'lockout_invalid_usernames':
case 'mask_login_errors':
case 'show_credit_link':
$options[$key] = trim($value);
break;
case 'max_login_retries':
case 'retries_within':
case 'lockout_length':
$options[$key] = (int) $value;
break;
} // switch
} // foreach
}
if (!isset($options['login_protection'])) {
$options['login_protection'] = 0;
}
if (!isset($options['lockout_invalid_usernames'])) {
$options['lockout_invalid_usernames'] = 0;
}
if (!isset($options['mask_login_errors'])) {
$options['mask_login_errors'] = 0;
}
if (!isset($options['anonymous_logging'])) {
$options['anonymous_logging'] = 0;
}
if (!isset($options['block_bots'])) {
$options['block_bots'] = 0;
}
if (!isset($options['instant_block_nonusers'])) {
$options['instant_block_nonusers'] = 0;
}
if (!isset($options['country_blocking_mode'])) {
$options['country_blocking_mode'] = 0;
}
if (!isset($options['block_undetermined_countries'])) {
$options['block_undetermined_countries'] = 0;
}
if (!isset($options['global_block'])) {
$options['global_block'] = 0;
}
if (!isset($options['country_global_block'])) {
$options['country_global_block'] = 0;
}
if (!isset($options['uninstall_delete'])) {
$options['uninstall_delete'] = 0;
}
if (!isset($options['show_credit_link'])) {
$options['show_credit_link'] = 0;
}
if (!isset($options['firewall_block_bots'])) {
$options['firewall_block_bots'] = 0;
}
if (!isset($options['firewall_directory_traversal'])) {
$options['firewall_directory_traversal'] = 0;
}
if (!isset($options['log_passwords'])) {
$options['log_passwords'] = 0;
}
if (!isset($options['captcha_show_login'])) {
$options['captcha_show_login'] = 0;
}
if (!isset($options['captcha_show_wp_registration'])) {
$options['captcha_show_wp_registration'] = 0;
}
if (!isset($options['captcha_show_wp_lost_password'])) {
$options['captcha_show_wp_lost_password'] = 0;
}
if (!isset($options['captcha_show_wp_comment'])) {
$options['captcha_show_wp_comment'] = 0;
}
if (!isset($options['captcha_show_woo_registration'])) {
$options['captcha_show_woo_registration'] = 0;
}
if (!isset($options['captcha_show_woo_checkout'])) {
$options['captcha_show_woo_checkout'] = 0;
}
if (!isset($options['design_enable'])) {
$options['design_enable'] = 0;
}
if (!isset($options['captcha_show_edd_registration'])) {
$options['captcha_show_edd_registration'] = 0;
}
if (!isset($options['captcha_show_bp_registration'])) {
$options['captcha_show_bp_registration'] = 0;
}
if (isset($_POST['wpcaptcha_import_file'])) {
$mimes = array(
'text/plain',
'text/anytext',
'application/txt'
);
if (!in_array($_FILES['wpcaptcha_import_file']['type'], $mimes)) {
WPCaptcha_Utility::display_notice(
sprintf(
"WARNING: Not a valid CSV file - the Mime Type '%s' is wrong! No settings have been imported.",
$_FILES['wpcaptcha_import_file']['type']
),
"error"
);
} else if (($handle = fopen($_FILES['wpcaptcha_import_file']['tmp_name'], "r")) !== false) {
$options_json = json_decode(fread($handle, 8192), ARRAY_A);
if (is_array($options_json) && array_key_exists('max_login_retries', $options_json) && array_key_exists('retries_within', $options_json) && array_key_exists('lockout_length', $options_json)) {
$options = $options_json;
WPCaptcha_Utility::display_notice("Settings have been imported.", "success");
} else {
WPCaptcha_Utility::display_notice("Invalid import file! No settings have been imported.", "error");
}
} else {
WPCaptcha_Utility::display_notice("Invalid import file! No settings have been imported.", "error");
}
}
if ($old_options['firewall_block_bots'] != $options['firewall_block_bots'] || $old_options['firewall_directory_traversal'] != $options['firewall_directory_traversal']) {
self::firewall_setup($options);
}
WPCaptcha_Utility::clear_3rdparty_cache();
$options['last_options_edit'] = current_time('mysql', true);
return array_merge($old_options, $options);
} // sanitize_settings
/**
* Get plugin metadata
*
* @since 5.0
*
* @return array meta
*
*/
static function get_meta()
{
$meta = get_option(WPCAPTCHA_META_KEY, array());
if (!is_array($meta) || empty($meta)) {
$meta['first_version'] = self::get_plugin_version();
$meta['first_install'] = current_time('timestamp');
update_option(WPCAPTCHA_META_KEY, $meta);
}
return $meta;
} // get_meta
static function update_meta($key, $value)
{
$meta = get_option(WPCAPTCHA_META_KEY, array());
$meta[$key] = $value;
update_option(WPCAPTCHA_META_KEY, $meta);
} // update_meta
/**
* Register custom tables
*
* @since 5.0
*
* @return null
*
*/
static function register_custom_tables()
{
global $wpdb;
$wpdb->wpcatcha_login_fails = $wpdb->prefix . 'wpc_login_fails';
$wpdb->wpcatcha_accesslocks = $wpdb->prefix . 'wpc_accesslocks';
} // register_custom_tables
/**
* Create custom tables
*
* @since 5.0
*
* @return null
*
*/
static function create_custom_tables()
{
global $wpdb;
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
self::register_custom_tables();
$wpcaptcha_login_fails = "CREATE TABLE " . $wpdb->wpcatcha_login_fails . " (
`login_attempt_ID` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) NOT NULL,
`login_attempt_date` datetime NOT NULL default '0000-00-00 00:00:00',
`login_attempt_IP` varchar(100) NOT NULL default '',
`failed_user` varchar(200) NOT NULL default '',
`failed_pass` varchar(200) NOT NULL default '',
`reason` varchar(200) NULL,
PRIMARY KEY (`login_attempt_ID`)
);";
dbDelta($wpcaptcha_login_fails);
$wpcaptcha_accesslocks = "CREATE TABLE " . $wpdb->wpcatcha_accesslocks . " (
`accesslock_ID` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) NOT NULL,
`accesslock_date` datetime NOT NULL default '0000-00-00 00:00:00',
`release_date` datetime NOT NULL default '0000-00-00 00:00:00',
`accesslock_IP` varchar(100) NOT NULL default '',
`reason` varchar(200) NULL,
`unlocked` smallint(20) NOT NULL default '0',
PRIMARY KEY (`accesslock_ID`)
);";
dbDelta($wpcaptcha_accesslocks);
self::update_meta('database_ver', self::$version);
} // create_custom_tables
static function firewall_setup($options = false)
{
self::setup_wp_filesystem();
self::firewall_remove_rules();
if (false === $options) {
$options = get_option(WPCAPTCHA_OPTIONS_KEY, array());
}
$htaccess = self::$wp_filesystem->get_contents(WPCaptcha_Utility::get_home_path() . '.htaccess');
$firewall_rules = [];
$firewall_rules[] = '# BEGIN WP Captcha Firewall';
if ($options['firewall_block_bots']) {
$firewall_rules[] = '<IfModule mod_rewrite.c>';
$firewall_rules[] = 'RewriteCond %{HTTP_USER_AGENT} (ahrefs|alexibot|majestic|mj12bot|rogerbot) [NC,OR]';
$firewall_rules[] = 'RewriteCond %{HTTP_USER_AGENT} (econtext|eolasbot|eventures|liebaofast|nominet|oppo\sa33) [NC,OR]';
$firewall_rules[] = 'RewriteCond %{HTTP_USER_AGENT} (ahrefs|alexibot|majestic|mj12bot|rogerbot) [NC,OR]';
$firewall_rules[] = 'RewriteCond %{HTTP_USER_AGENT} (econtext|eolasbot|eventures|liebaofast|nominet|oppo\sa33) [NC,OR]';
$firewall_rules[] = 'RewriteCond %{HTTP_USER_AGENT} (acapbot|acoonbot|asterias|attackbot|backdorbot|becomebot|binlar|blackwidow|blekkobot|blexbot|blowfish|bullseye|bunnys|butterfly|careerbot|casper|checkpriv|cheesebot|cherrypick|chinaclaw|choppy|clshttp|cmsworld|copernic|copyrightcheck|cosmos|crescent|cy_cho|datacha|demon|diavol|discobot|dittospyder|dotbot|dotnetdotcom|dumbot|emailcollector|emailsiphon|emailwolf|extract|eyenetie|feedfinder|flaming|flashget|flicky|foobot|g00g1e|getright|gigabot|go-ahead-got|gozilla|grabnet|grafula|harvest|heritrix|httrack|icarus6j|jetbot|jetcar|jikespider|kmccrew|leechftp|libweb|linkextractor|linkscan|linkwalker|loader|masscan|miner|mechanize|morfeus|moveoverbot|netmechanic|netspider|nicerspro|nikto|ninja|nutch|octopus|pagegrabber|petalbot|planetwork|postrank|proximic|purebot|pycurl|python|queryn|queryseeker|radian6|radiation|realdownload|scooter|seekerspider|semalt|siclab|sindice|sistrix|sitebot|siteexplorer|sitesnagger|skygrid|smartdownload|snoopy|sosospider|spankbot|spbot|sqlmap|stackrambler|stripper|sucker|surftbot|sux0r|suzukacz|suzuran|takeout|teleport|telesoft|true_robots|turingos|turnit|vampire|vikspider|voideye|webleacher|webreaper|webstripper|webvac|webviewer|webwhacker|winhttp|wwwoffle|woxbot|xaldon|xxxyy|yamanalab|yioopbot|youda|zeus|zmeu|zune|zyborg) [NC]';
$firewall_rules[] = 'RewriteCond %{REMOTE_HOST} (163data|amazonaws|colocrossing|crimea|g00g1e|justhost|kanagawa|loopia|masterhost|onlinehome|poneytel|sprintdatacenter|reverse.softlayer|safenet|ttnet|woodpecker|wowrack) [NC]';
$firewall_rules[] = 'RewriteCond %{HTTP_REFERER} (semalt\.com|todaperfeita) [NC,OR]';
$firewall_rules[] = 'RewriteCond %{HTTP_REFERER} (blue\spill|cocaine|ejaculat|erectile|erections|hoodia|huronriveracres|impotence|levitra|libido|lipitor|phentermin|pro[sz]ac|sandyauer|tramadol|troyhamby|ultram|unicauca|valium|viagra|vicodin|xanax|ypxaieo) [NC]';
$firewall_rules[] = 'RewriteRule .* - [F,L]';
$firewall_rules[] = '</IfModule>';
}
if ($options['firewall_directory_traversal']) {
$firewall_rules[] = '<IfModule mod_rewrite.c>';
$firewall_rules[] = 'RewriteCond %{QUERY_STRING} (((/|%2f){3,3})|((\.|%2e){3,3})|((\.|%2e){2,2})(/|%2f|%u2215)) [NC,OR]';
$firewall_rules[] = 'RewriteCond %{QUERY_STRING} (/|%2f)(:|%3a)(/|%2f) [NC,OR]';
$firewall_rules[] = 'RewriteCond %{QUERY_STRING} (/|%2f)(\*|%2a)(\*|%2a)(/|%2f) [NC,OR]';
$firewall_rules[] = 'RewriteCond %{QUERY_STRING} (absolute_|base|root_)(dir|path)(=|%3d)(ftp|https?) [NC,OR]';
$firewall_rules[] = 'RewriteCond %{QUERY_STRING} (/|%2f)(=|%3d|$&|_mm|cgi(\.|-)|inurl(:|%3a)(/|%2f)|(mod|path)(=|%3d)(\.|%2e)) [NC,OR]';
$firewall_rules[] = 'RewriteCond %{REQUEST_URI} (\^|`|<|>|\\\\|\|) [NC,OR]';
$firewall_rules[] = 'RewriteCond %{REQUEST_URI} ([a-z0-9]{2000,}) [NC]';
$firewall_rules[] = 'RewriteRule .* - [F,L]';
$firewall_rules[] = '</IfModule>';
}
$firewall_rules[] = '# END WP Captcha Firewall';
$htaccess = implode(PHP_EOL, $firewall_rules) . PHP_EOL . $htaccess;
if (count($firewall_rules) > 2) {
$firewall_test = self::firewall_test_htaccess($htaccess);
if (is_wp_error($firewall_test)) {
WPCaptcha_Utility::display_notice(
$firewall_test->get_error_message(),
"error"
);
} else {
self::$wp_filesystem->put_contents(WPCaptcha_Utility::get_home_path() . '.htaccess', $htaccess);
}
}
}
static function firewall_test_htaccess($new_content)
{
$uploads_directory = wp_upload_dir();
$test_id = rand(1000, 9999);
$htaccess_test_folder = $uploads_directory['basedir'] . '/htaccess-test-' . $test_id . '/';
$htaccess_test_url = $uploads_directory['baseurl'] . '/htaccess-test-' . $test_id . '/';
// Create test directory and files
if (!self::$wp_filesystem->is_dir($htaccess_test_folder)) {
if (true !== self::$wp_filesystem->mkdir($htaccess_test_folder, 0777)) {
return new WP_Error('firewall_failed', 'Failed to create test directory. Please check that your uploads folder is writable.', false);
}
}
if (true !== self::$wp_filesystem->put_contents($htaccess_test_folder . 'index.html', 'htaccess-test-' . $test_id)) {
return new WP_Error('firewall_failed', 'Failed to create test files. Please check that your uploads folder is writable.', false);
}
if (true !== self::$wp_filesystem->put_contents($htaccess_test_folder . '.htaccess', $new_content)) {
return new WP_Error('firewall_failed', 'Failed to create test directory and files. Please check that your uploads folder is writeable.', false);
}
// Retrieve test file over http
$response = wp_remote_get($htaccess_test_url . 'index.html', array('sslverify' => false, 'redirection' => 0));
$response_code = wp_remote_retrieve_response_code($response);
// Remove Test Directory
self::$wp_filesystem->delete($htaccess_test_folder . '.htaccess');
self::$wp_filesystem->delete($htaccess_test_folder . 'index.html');
self::$wp_filesystem->rmdir($htaccess_test_folder);
// Check if test file content is what we expect
if ((in_array($response_code, range(200, 299)) && !is_wp_error($response) && wp_remote_retrieve_body($response) == 'htaccess-test-' . $test_id) || (in_array($response_code, range(300, 399)) && !is_wp_error($response))) {
return true;
} else {
return new WP_Error('firewall_failed', 'Unfortunately it looks like installing these firewall rules could cause your entire site, including the admin, to become inaccessible. Fix the errors before saving', false);
}
}
static function firewall_remove_rules()
{
if (self::$wp_filesystem->is_writable(WPCaptcha_Utility::get_home_path() . '.htaccess')) {
$htaccess_rules = self::$wp_filesystem->get_contents(WPCaptcha_Utility::get_home_path() . '.htaccess');
if ($htaccess_rules) {
$htaccess_rules = explode(PHP_EOL, $htaccess_rules);
$found = false;
$new_content = '';
foreach ($htaccess_rules as $htaccess_rule) {
if ($htaccess_rule == '# BEGIN WP Captcha Firewall') {
$found = true;
}
if (!$found) {
$new_content .= $htaccess_rule . PHP_EOL;
}
if ($htaccess_rule == '# END WP Captcha Firewall') {
$found = false;
}
}
$new_content = trim($new_content, PHP_EOL);
$f = @fopen(WPCaptcha_Utility::get_home_path() . '.htaccess', 'w');
self::$wp_filesystem->put_contents(WPCaptcha_Utility::get_home_path() . '.htaccess', $new_content);
return true;
}
}
return false;
}
/**
* Actions on plugin activation
*
* @since 5.0
*
* @return null
*
*/
static function activate()
{
self::create_custom_tables();
WPCaptcha_Admin::reset_pointers();
} // activate
/**
* Actions on plugin deactivaiton
*
* @since 5.0
*
* @return null
*
*/
static function deactivate()
{
} // deactivate
/**
* Actions on plugin uninstall
*
* @since 5.0
*
* @return null
*/
static function uninstall()
{
global $wpdb;
$options = get_option(WPCAPTCHA_OPTIONS_KEY, array());
if ($options['uninstall_delete'] == '1') {
delete_option(WPCAPTCHA_OPTIONS_KEY);
delete_option(WPCAPTCHA_META_KEY);
delete_option(WPCAPTCHA_POINTERS_KEY);
delete_option(WPCAPTCHA_NOTICES_KEY);
$wpdb->query("DROP TABLE IF EXISTS " . $wpdb->prefix . "wpc_login_fails");
$wpdb->query("DROP TABLE IF EXISTS " . $wpdb->prefix . "wpc_accesslocks");
}
} // uninstall
} // class

View File

@ -0,0 +1,63 @@
<?php
/**
* WP Captcha
* https://getwpcaptcha.com/
* (c) WebFactory Ltd, 2022 - 2023, www.webfactoryltd.com
*/
class WPCaptcha_Stats extends WPCaptcha
{
static public $stats_cutoff = 1;
/**
* Get statistics
*
* @since 5.0
*
* @param string $type locks|fails
* @param int $ndays period for statistics
* @return bool
*/
static function get_stats($type = "locks", $ndays = 60)
{
global $wpdb;
$days = array();
for ($i = $ndays; $i >= 0; $i--){
$days[date("Y-m-d", strtotime('-' . $i . ' days'))] = 0;
}
if ($type == 'locks') {
$results = $wpdb->get_results("SELECT COUNT(*) as count,DATE_FORMAT(accesslock_date, '%Y-%m-%d') AS date FROM " . $wpdb->wpcatcha_accesslocks . " GROUP BY DATE_FORMAT(accesslock_date, '%Y%m%d')");
} else {
$results = $wpdb->get_results("SELECT COUNT(*) as count,DATE_FORMAT(login_attempt_date, '%Y-%m-%d') AS date FROM " . $wpdb->wpcatcha_login_fails . " GROUP BY DATE_FORMAT(login_attempt_date, '%Y%m%d')");
}
$total = 0;
foreach ($results as $day) {
if(array_key_exists($day->date, $days)){
$days[$day->date] = $day->count;
$total += $day->count;
}
}
if ($total < self::$stats_cutoff) {
$stats['days'] = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
$stats['count'] = array(3, 4, 67, 76, 45, 32, 134, 6, 65, 65, 56, 123, 156, 156, 123, 156, 67, 88, 54, 178);
$stats['total'] = $total;
return $stats;
}
$stats = array('days' => array(), 'count' => array(), 'total' => 0);
foreach ($days as $day => $count) {
$stats['days'][] = $day;
$stats['count'][] = $count;
$stats['total'] += $count;
}
$stats['period'] = $ndays;
return $stats;
} // get_stats
} // class

View File

@ -0,0 +1,594 @@
<?php
/**
* WP Captcha
* https://getwpcaptcha.com/
* (c) WebFactory Ltd, 2022 - 2023, www.webfactoryltd.com
*/
use WFMaxMind\Db\Reader;
class WPCaptcha_Utility extends WPCaptcha
{
/**
* Display settings notice
*
* @param $redirect
* @return bool
*/
static function display_notice($message, $type = 'error', $code = 'advanced-google-recaptcha')
{
global $wp_settings_errors;
$wp_settings_errors[] = array(
'setting' => WPCAPTCHA_OPTIONS_KEY,
'code' => $code,
'message' => $message,
'type' => $type
);
set_transient('settings_errors', $wp_settings_errors);
} // display_notice
/**
* Empty cache in various 3rd party plugins
*
* @since 5.0
*
* @return null
*
*/
static function clear_3rdparty_cache()
{
if (function_exists('w3tc_pgcache_flush')) {
w3tc_pgcache_flush();
}
if (function_exists('wp_cache_clean_cache')) {
global $file_prefix;
wp_cache_clean_cache($file_prefix);
}
if (function_exists('wp_cache_clear_cache')) {
wp_cache_clear_cache();
}
if (class_exists('Endurance_Page_Cache')) {
$epc = new Endurance_Page_Cache;
$epc->purge_all();
}
if (method_exists('SG_CachePress_Supercacher', 'purge_cache')) {
SG_CachePress_Supercacher::purge_cache(true);
}
if (class_exists('SiteGround_Optimizer\Supercacher\Supercacher')) {
SiteGround_Optimizer\Supercacher\Supercacher::purge_cache();
}
} // empty_3rdparty_cache
/**
* Dismiss pointer
*
* @since 5.0
*
* @return null
*
*/
static function dismiss_pointer_ajax()
{
delete_option(WPCAPTCHA_POINTERS_KEY);
}
/**
* checkbox helper function
*
* @since 5.0
*
* @return string checked HTML
*
*/
static function checked($value, $current, $echo = false)
{
$out = '';
if (!is_array($current)) {
$current = (array) $current;
}
if (in_array($value, $current)) {
$out = ' checked="checked" ';
}
if ($echo) {
WPCaptcha_Utility::wp_kses_wf($out);
} else {
return $out;
}
} // checked
/**
* Create toggle switch
*
* @since 5.0
*
* @return string Switch HTML
*
*/
static function create_toggle_switch($name, $options = array(), $output = true, $class = '')
{
$default_options = array('value' => '1', 'saved_value' => '', 'option_key' => $name);
$options = array_merge($default_options, $options);
$out = "\n";
$out .= '<div class="toggle-wrapper">';
$out .= '<input class="' . $class . '" type="checkbox" id="' . $name . '" ' . self::checked($options['value'], $options['saved_value']) . ' type="checkbox" value="' . $options['value'] . '" name="' . $options['option_key'] . '">';
$out .= '<label for="' . $name . '" class="toggle"><span class="toggle_handler"></span></label>';
$out .= '</div>';
if ($output) {
WPCaptcha_Utility::wp_kses_wf($out);
} else {
return $out;
}
} // create_toggle_switch
/**
* Get user IP
*
* @since 5.0
*
* @return string userip
*
*/
static function getUserIP($force_clear = false)
{
$options = WPCaptcha_Setup::get_options();
$ip = '';
if (!empty($_SERVER['REMOTE_ADDR'])) {
$ip = $_SERVER['REMOTE_ADDR'];
}
if ($options['anonymous_logging'] == '1' && !$force_clear) {
$ip = md5($ip);
}
return $ip;
} // getUserIP
/**
* Create select options for select
*
* @since 5.0
*
* @param array $options options
* @param string $selected selected value
* @param bool $output echo, if false return html as string
* @return string html with options
*/
static function create_select_options($options, $selected = null, $output = true)
{
$out = "\n";
foreach ($options as $tmp) {
if ((is_array($selected) && in_array($tmp['val'], $selected)) || $selected == $tmp['val']) {
$out .= "<option selected=\"selected\" value=\"{$tmp['val']}\" " . (isset($tmp['class']) ? "class=\"{$tmp['class']}\"" : "") . ">{$tmp['label']}&nbsp;</option>\n";
} else {
$out .= "<option value=\"{$tmp['val']}\" " . (isset($tmp['class']) ? "class=\"{$tmp['class']}\"" : "") . ">{$tmp['label']}&nbsp;</option>\n";
}
}
if ($output) {
WPCaptcha_Utility::wp_kses_wf($out);
} else {
return $out;
}
} // create_select_options
static function create_radio_group($name, $options, $selected = null, $output = true)
{
$out = "\n";
foreach ($options as $tmp) {
if ($selected == $tmp['val']) {
$out .= "<label for=\"{$name}_{$tmp['val']}\" class=\"radio_wrapper\"><input id=\"{$name}_{$tmp['val']}\" name=\"{$name}\" type=\"radio\" checked=\"checked\" value=\"{$tmp['val']}\">{$tmp['label']}&nbsp;</option></label>\n";
} else {
$out .= "<label for=\"{$name}_{$tmp['val']}\" class=\"radio_wrapper\"><input id=\"{$name}_{$tmp['val']}\" name=\"{$name}\" type=\"radio\" value=\"{$tmp['val']}\">{$tmp['label']}&nbsp;</option></label>\n";
}
}
if ($output) {
WPCaptcha_Utility::wp_kses_wf($out);
} else {
return $out;
}
}
/**
* Parse user agent to add device icon and clean text
*
* @since 5.0
*
* @param string $user_agent
* @return string $user_agent
*/
static function parse_user_agent($user_agent = false)
{
if (!$user_agent) {
$user_agent = array();
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
$user_agent[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
}
$user_agent = new WhichBrowser\Parser($user_agent);
$user_agent_string = '';
if ($user_agent->isType('mobile')) {
$user_agent_string .= '<i class="tooltip fas fa-mobile-alt" title="Phone"></i>';
} else if ($user_agent->isType('tablet')) {
$user_agent_string .= '<i class="tooltip fas fa-tablet-alt" title="Table"></i>';
} else if ($user_agent->isType('desktop')) {
$user_agent_string .= '<i class="tooltip fas fa-desktop" title="Desktop"></i>';
} else {
$user_agent_string .= '<i class="tooltip fas fa-robot" title="Bot"></i>';
}
if (isset($user_agent->browser) && isset($user_agent->browser->version)) {
$browser_version = explode('.', $user_agent->browser->version->toString());
} else {
$browser_version = array('unknown');
}
if ($user_agent->os) {
$os = $user_agent->os->toString();
} else {
$os = 'unknown';
}
if (isset($user_agent->browser) && isset($user_agent->browser->name)) {
$browser_name = $user_agent->browser->name;
} else {
$browser_name = 'unknown';
}
$user_agent_string .= ' ' . $browser_name . ' ' . $browser_version[0] . ' on ' . $os;
return $user_agent_string;
} // parse_user_agent
static function get_home_path()
{
if (!function_exists('get_home_path')) {
require_once(ABSPATH . 'wp-admin/includes/file.php');
}
return get_home_path();
}
static function wp_kses_wf($html)
{
add_filter('safe_style_css', function ($styles) {
$styles_wf = array(
'text-align',
'margin',
'color',
'float',
'border',
'background',
'background-color',
'border-bottom',
'border-bottom-color',
'border-bottom-style',
'border-bottom-width',
'border-collapse',
'border-color',
'border-left',
'border-left-color',
'border-left-style',
'border-left-width',
'border-right',
'border-right-color',
'border-right-style',
'border-right-width',
'border-spacing',
'border-style',
'border-top',
'border-top-color',
'border-top-style',
'border-top-width',
'border-width',
'caption-side',
'clear',
'cursor',
'direction',
'font',
'font-family',
'font-size',
'font-style',
'font-variant',
'font-weight',
'height',
'letter-spacing',
'line-height',
'margin-bottom',
'margin-left',
'margin-right',
'margin-top',
'overflow',
'padding',
'padding-bottom',
'padding-left',
'padding-right',
'padding-top',
'text-decoration',
'text-indent',
'vertical-align',
'width',
'display',
);
foreach ($styles_wf as $style_wf) {
$styles[] = $style_wf;
}
return $styles;
});
$allowed_tags = wp_kses_allowed_html('post');
$allowed_tags['input'] = array(
'type' => true,
'style' => true,
'class' => true,
'id' => true,
'checked' => true,
'disabled' => true,
'name' => true,
'size' => true,
'placeholder' => true,
'value' => true,
'data-*' => true,
'size' => true,
'disabled' => true
);
$allowed_tags['textarea'] = array(
'type' => true,
'style' => true,
'class' => true,
'id' => true,
'checked' => true,
'disabled' => true,
'name' => true,
'size' => true,
'placeholder' => true,
'value' => true,
'data-*' => true,
'cols' => true,
'rows' => true,
'disabled' => true,
'autocomplete' => true
);
$allowed_tags['select'] = array(
'type' => true,
'style' => true,
'class' => true,
'id' => true,
'checked' => true,
'disabled' => true,
'name' => true,
'size' => true,
'placeholder' => true,
'value' => true,
'data-*' => true,
'multiple' => true,
'disabled' => true
);
$allowed_tags['option'] = array(
'type' => true,
'style' => true,
'class' => true,
'id' => true,
'checked' => true,
'disabled' => true,
'name' => true,
'size' => true,
'placeholder' => true,
'value' => true,
'selected' => true,
'data-*' => true
);
$allowed_tags['optgroup'] = array(
'type' => true,
'style' => true,
'class' => true,
'id' => true,
'checked' => true,
'disabled' => true,
'name' => true,
'size' => true,
'placeholder' => true,
'value' => true,
'selected' => true,
'data-*' => true,
'label' => true
);
$allowed_tags['a'] = array(
'href' => true,
'data-*' => true,
'class' => true,
'style' => true,
'id' => true,
'target' => true,
'data-*' => true,
'role' => true,
'aria-controls' => true,
'aria-selected' => true,
'disabled' => true
);
$allowed_tags['div'] = array(
'style' => true,
'class' => true,
'id' => true,
'data-*' => true,
'role' => true,
'aria-labelledby' => true,
'value' => true,
'aria-modal' => true,
'tabindex' => true
);
$allowed_tags['li'] = array(
'style' => true,
'class' => true,
'id' => true,
'data-*' => true,
'role' => true,
'aria-labelledby' => true,
'value' => true,
'aria-modal' => true,
'tabindex' => true
);
$allowed_tags['span'] = array(
'style' => true,
'class' => true,
'id' => true,
'data-*' => true,
'aria-hidden' => true
);
$allowed_tags['style'] = array(
'class' => true,
'id' => true,
'type' => true,
'style' => true
);
$allowed_tags['fieldset'] = array(
'class' => true,
'id' => true,
'type' => true,
'style' => true
);
$allowed_tags['link'] = array(
'class' => true,
'id' => true,
'type' => true,
'rel' => true,
'href' => true,
'media' => true,
'style' => true
);
$allowed_tags['form'] = array(
'style' => true,
'class' => true,
'id' => true,
'method' => true,
'action' => true,
'data-*' => true,
'style' => true
);
$allowed_tags['script'] = array(
'class' => true,
'id' => true,
'type' => true,
'src' => true,
'style' => true
);
$allowed_tags['table'] = array(
'class' => true,
'id' => true,
'type' => true,
'cellpadding' => true,
'cellspacing' => true,
'border' => true,
'style' => true
);
$allowed_tags['canvas'] = array(
'class' => true,
'id' => true,
'style' => true
);
echo wp_kses($html, $allowed_tags);
add_filter('safe_style_css', function ($styles) {
$styles_wf = array(
'text-align',
'margin',
'color',
'float',
'border',
'background',
'background-color',
'border-bottom',
'border-bottom-color',
'border-bottom-style',
'border-bottom-width',
'border-collapse',
'border-color',
'border-left',
'border-left-color',
'border-left-style',
'border-left-width',
'border-right',
'border-right-color',
'border-right-style',
'border-right-width',
'border-spacing',
'border-style',
'border-top',
'border-top-color',
'border-top-style',
'border-top-width',
'border-width',
'caption-side',
'clear',
'cursor',
'direction',
'font',
'font-family',
'font-size',
'font-style',
'font-variant',
'font-weight',
'height',
'letter-spacing',
'line-height',
'margin-bottom',
'margin-left',
'margin-right',
'margin-top',
'overflow',
'padding',
'padding-bottom',
'padding-left',
'padding-right',
'padding-top',
'text-decoration',
'text-indent',
'vertical-align',
'width'
);
foreach ($styles_wf as $style_wf) {
if (($key = array_search($style_wf, $styles)) !== false) {
unset($styles[$key]);
}
}
return $styles;
});
}
} // class