PluginProbe ʕ •ᴥ•ʔ
reCaptcha by BestWebSoft / 1.18
reCaptcha by BestWebSoft v1.18
1.79 1.80 1.82 1.83 1.84 1.85 1.86 1.87 trunk 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.18 1.19 1.20 1.21 1.22 1.23 1.24 1.25 1.26 1.27 1.28 1.29 1.30 1.31 1.32 1.33 1.34 1.35 1.36 1.37 1.38 1.39 1.40 1.41 1.42 1.43 1.44 1.45 1.46 1.47 1.48 1.49 1.50 1.51 1.52 1.53 1.54 1.55 1.56 1.57 1.58 1.59 1.60 1.61 1.62 1.63 1.64 1.65 1.66 1.67 1.68 1.70 1.71 1.72 1.73 1.74 1.75 1.78
google-captcha / google-captcha.php
google-captcha Last commit date
bws_menu 10 years ago css 10 years ago js 10 years ago languages 10 years ago lib 10 years ago lib_v2 10 years ago google-captcha.php 10 years ago readme.txt 10 years ago screenshot-1.png 10 years ago screenshot-2.png 10 years ago screenshot-3.png 10 years ago screenshot-4.png 10 years ago screenshot-5.png 10 years ago screenshot-6.png 10 years ago screenshot-7.png 10 years ago
google-captcha.php
882 lines
1 <?php
2 /*
3 Plugin Name: Google Captcha (reCAPTCHA) by BestWebSoft
4 Plugin URI: http://bestwebsoft.com/products/
5 Description: Plugin Google Captcha intended to prove that the visitor is a human being and not a spam robot.
6 Author: BestWebSoft
7 Version: 1.18
8 Author URI: http://bestwebsoft.com/
9 License: GPLv3 or later
10 */
11
12 /* © Copyright 2015 BestWebSoft ( http://support.bestwebsoft.com )
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License, version 2, as
16 published by the Free Software Foundation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27
28 /* Add menu page */
29 if ( ! function_exists( 'google_capthca_admin_menu' ) ) {
30 function google_capthca_admin_menu() {
31 bws_add_general_menu( plugin_basename( __FILE__ ) );
32 add_submenu_page( 'bws_plugins', __( 'Google Captcha Settings', 'google_captcha' ), 'Google Captcha', 'manage_options', 'google-captcha.php', 'gglcptch_settings_page' );
33 }
34 }
35
36 if ( ! function_exists( 'gglcptch_init' ) ) {
37 function gglcptch_init() {
38 global $gglcptch_options, $gglcptch_allow_url_fopen, $gglcptch_plugin_info;
39
40 load_plugin_textdomain( 'google_captcha', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
41
42 require_once( dirname( __FILE__ ) . '/bws_menu/bws_functions.php' );
43
44 if ( empty( $gglcptch_plugin_info ) ) {
45 if ( ! function_exists( 'get_plugin_data' ) )
46 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
47 $gglcptch_plugin_info = get_plugin_data( __FILE__ );
48 }
49
50 /* Function check if plugin is compatible with current WP version */
51 bws_wp_version_check( plugin_basename( __FILE__ ), $gglcptch_plugin_info, '3.1' );
52
53 /* Get options from the database */
54 $gglcptch_options = get_option( 'gglcptch_options' );
55
56 /* Get option from the php.ini */
57 $gglcptch_allow_url_fopen = ( ini_get( 'allow_url_fopen' ) != 1 ) ? false : true;
58
59 /* Add hooks */
60 if ( '1' == $gglcptch_options['login_form'] ) {
61 add_action( 'login_form', 'gglcptch_login_display' );
62 add_action( 'authenticate', 'gglcptch_login_check', 21, 1 );
63 }
64
65 if ( '1' == $gglcptch_options['comments_form'] ) {
66 add_action( 'comment_form_after_fields', 'gglcptch_commentform_display' );
67 add_action( 'comment_form_logged_in_after', 'gglcptch_commentform_display' );
68 add_action( 'pre_comment_on_post', 'gglcptch_commentform_check' );
69 }
70
71 if ( '1' == $gglcptch_options['reset_pwd_form'] ) {
72 add_action( 'lostpassword_form', 'gglcptch_login_display' );
73 add_action( 'lostpassword_post', 'gglcptch_lostpassword_check' );
74 }
75
76 if ( '1' == $gglcptch_options['registration_form'] ) {
77 add_action( 'register_form', 'gglcptch_login_display' );
78 add_action( 'register_post', 'gglcptch_lostpassword_check' );
79 /* for multisite */
80 add_action( 'signup_extra_fields', 'gglcptch_login_display' );
81 }
82
83 if ( '1' == $gglcptch_options['contact_form'] ) {
84 add_filter( 'cntctfrm_display_captcha', 'gglcptch_cf_display' );
85 add_filter( 'cntctfrmpr_display_captcha', 'gglcptch_cf_display' );
86 }
87 }
88 }
89
90 if ( ! function_exists( 'gglcptch_admin_init' ) ) {
91 function gglcptch_admin_init() {
92 global $bws_plugin_info, $gglcptch_plugin_info;
93
94 if ( ! isset( $bws_plugin_info ) || empty( $bws_plugin_info ) )
95 $bws_plugin_info = array( 'id' => '109', 'version' => $gglcptch_plugin_info["Version"] );
96
97 /* Call register settings function */
98 if ( isset( $_GET['page'] ) && "google-captcha.php" == $_GET['page'] )
99 register_gglcptch_settings();
100 }
101 }
102
103 /* Add google captcha styles */
104 if ( ! function_exists( 'gglcptch_add_style' ) ) {
105 function gglcptch_add_style() {
106 if ( isset( $_REQUEST['page'] ) && 'google-captcha.php' == $_REQUEST['page'] ) {
107 wp_enqueue_style( 'gglcptch_stylesheet', plugins_url( 'css/style.css', __FILE__ ) );
108 wp_enqueue_script( 'gglcptch_admin_script', plugins_url( 'js/admin_script.js', __FILE__ ), array( 'jquery' ) );
109 }
110 }
111 }
112
113 /* Add google captcha scripts */
114 if ( ! function_exists( 'gglcptch_add_script' ) ) {
115 function gglcptch_add_script() {
116 wp_enqueue_script( 'gglcptch_script', plugins_url( 'js/script.js', __FILE__ ), array( 'jquery' ) );
117 wp_localize_script( 'gglcptch_script', 'gglcptch_vars', array( 'nonce' => wp_create_nonce( 'gglcptch_recaptcha_nonce' ) ) );
118 }
119 }
120 /* Google catpcha settings */
121 if ( ! function_exists( 'register_gglcptch_settings' ) ) {
122 function register_gglcptch_settings() {
123 global $gglcptch_options, $bws_plugin_info, $gglcptch_plugin_info, $gglcptch_allow_url_fopen, $gglcptch_default_options;
124
125 $gglcptch_default_options = array(
126 'public_key' => '',
127 'private_key' => '',
128 'login_form' => '1',
129 'registration_form' => '1',
130 'reset_pwd_form' => '1',
131 'comments_form' => '1',
132 'contact_form' => '0',
133 'theme' => 'red',
134 'theme_v2' => 'light',
135 'recaptcha_version' => ( $gglcptch_allow_url_fopen ) ? 'v2' : 'v1',
136 'plugin_option_version' => $gglcptch_plugin_info["Version"]
137 );
138
139 foreach ( get_editable_roles() as $role => $fields ) {
140 $gglcptch_default_options[ $role ] = '0';
141 }
142
143 /* Install the option defaults */
144 if ( ! get_option( 'gglcptch_options' ) )
145 add_option( 'gglcptch_options', $gglcptch_default_options );
146 /* Get options from the database */
147 $gglcptch_options = get_option( 'gglcptch_options' );
148
149 /* Array merge incase this version has added new options */
150 if ( ! isset( $gglcptch_options['plugin_option_version'] ) || $gglcptch_options['plugin_option_version'] != $gglcptch_plugin_info["Version"] ) {
151 $gglcptch_options = array_merge( $gglcptch_default_options, $gglcptch_options );
152 $gglcptch_options['plugin_option_version'] = $gglcptch_plugin_info["Version"];
153 update_option( 'gglcptch_options', $gglcptch_options );
154 }
155 }
156 }
157
158 /* Display settings page */
159 if ( ! function_exists( 'gglcptch_settings_page' ) ) {
160 function gglcptch_settings_page() {
161 global $gglcptch_options, $gglcptch_plugin_info, $wp_version, $gglcptch_allow_url_fopen, $gglcptch_default_options;
162
163 $plugin_basename = plugin_basename( __FILE__ );
164 $message = $error = '';
165
166 if ( ! isset( $_GET['action'] ) ) {
167 $gglcptch_languages = array(
168 'ar' => 'Arabic',
169 'bn' => 'Bengali',
170 'bg' => 'Bulgarian',
171 'ca' => 'Catalan',
172 'zh-CN' => 'Chinese (Simplified)',
173 'zh-TW' => 'Chinese (Traditional)',
174 'hr' => 'Croatian',
175 'cs' => 'Czech',
176 'da' => 'Danish',
177 'nl' => 'Dutch',
178 'en-GB' => 'English (UK)',
179 'en' => 'English (US)',
180 'et' => 'Estonian',
181 'fil' => 'Filipino',
182 'fi' => 'Finnish',
183 'fr' => 'French',
184 'fr-CA' => 'French (Canadian)',
185 'de' => 'German',
186 'gu' => 'Gujarati',
187 'de-AT' => 'German (Austria)',
188 'de-CH' => 'German (Switzerland)',
189 'el' => 'Greek',
190 'iw' => 'Hebrew',
191 'hi' => 'Hindi',
192 'hu' => 'Hungarain',
193 'id' => 'Indonesian',
194 'it' => 'Italian',
195 'ja' => 'Japanese',
196 'kn' => 'Kannada',
197 'ko' => 'Korean',
198 'lv' => 'Latvian',
199 'lt' => 'Lithuanian',
200 'ms' => 'Malay',
201 'ml' => 'Malayalam',
202 'mr' => 'Marathi',
203 'no' => 'Norwegian',
204 'fa' => 'Persian',
205 'pl' => 'Polish',
206 'pt' => 'Portuguese',
207 'pt-BR' => 'Portuguese (Brazil)',
208 'pt-PT' => 'Portuguese (Portugal)',
209 'ro' => 'Romanian',
210 'ru' => 'Russian',
211 'sr' => 'Serbian',
212 'sk' => 'Slovak',
213 'sl' => 'Slovenian',
214 'es' => 'Spanish',
215 'es-419' => 'Spanish (Latin America)',
216 'sv' => 'Swedish',
217 'ta' => 'Tamil',
218 'te' => 'Telugu',
219 'th' => 'Thai',
220 'tr' => 'Turkish',
221 'uk' => 'Ukrainian',
222 'ur' => 'Urdu',
223 'vi' => 'Vietnamese'
224 );
225
226 $gglcptch_sizes_v2 = array(
227 'normal' => __( 'Normal', 'google_captcha' ),
228 'compact' => __( 'Compact', 'google_captcha' )
229 );
230
231 /* Private and public keys */
232 $gglcptch_keys = array(
233 'public' => array(
234 'display_name' => __( 'Site key', 'google_captcha' ),
235 'form_name' => 'gglcptch_public_key',
236 'error_msg' => '',
237 ),
238 'private' => array(
239 'display_name' => __( 'Secret Key', 'google_captcha' ),
240 'form_name' => 'gglcptch_private_key',
241 'error_msg' => '',
242 ),
243 );
244
245 /* Checked forms */
246 $gglcptch_forms = array(
247 array( 'login_form', __( 'Login form', 'google_captcha' ) ),
248 array( 'registration_form', __( 'Registration form', 'google_captcha' ) ),
249 array( 'reset_pwd_form', __( 'Reset password form', 'google_captcha' ) ),
250 array( 'comments_form', __( 'Comments form', 'google_captcha' ) ),
251 );
252
253 /* Google captcha themes */
254 $gglcptch_themes = array(
255 array( 'red', 'Red' ),
256 array( 'white', 'White' ),
257 array( 'blackglass', 'Blackglass' ),
258 array( 'clean', 'Clean' ),
259 );
260
261 /* Save data for settings page */
262 if ( isset( $_POST['gglcptch_save_changes'] ) && check_admin_referer( plugin_basename( __FILE__ ), 'gglcptch_nonce_name' ) ) {
263 if ( ! $_POST['gglcptch_public_key'] || '' == $_POST['gglcptch_public_key'] ) {
264 $gglcptch_keys['public']['error_msg'] = __( 'Enter site key', 'google_captcha' );
265 $error = __( "WARNING: The captcha will not display while you don't fill key fields.", 'google_captcha' );
266 } else
267 $gglcptch_keys['public']['error_msg'] = '';
268
269 if ( ! $_POST['gglcptch_private_key'] || '' == $_POST['gglcptch_private_key'] ) {
270 $gglcptch_keys['private']['error_msg'] = __( 'Enter secret key', 'google_captcha' );
271 $error = __( "WARNING: The captcha will not display while you don't fill key fields.", 'google_captcha' );
272 } else
273 $gglcptch_keys['private']['error_msg'] = '';
274
275 $gglcptch_options['public_key'] = trim( stripslashes( esc_html( $_POST['gglcptch_public_key'] ) ) );
276 $gglcptch_options['private_key'] = trim( stripslashes( esc_html( $_POST['gglcptch_private_key'] ) ) );
277 $gglcptch_options['login_form'] = isset( $_POST['gglcptch_login_form'] ) ? 1 : 0;
278 $gglcptch_options['registration_form'] = isset( $_POST['gglcptch_registration_form'] ) ? 1 : 0;
279 $gglcptch_options['reset_pwd_form'] = isset( $_POST['gglcptch_reset_pwd_form'] ) ? 1 : 0;
280 $gglcptch_options['comments_form'] = isset( $_POST['gglcptch_comments_form'] ) ? 1 : 0;
281 $gglcptch_options['contact_form'] = isset( $_POST['gglcptch_contact_form'] ) ? 1 : 0;
282 $gglcptch_options['recaptcha_version'] = $_POST['gglcptch_recaptcha_version'];
283 $gglcptch_options['theme'] = $_POST['gglcptch_theme'];
284 $gglcptch_options['theme_v2'] = $_POST['gglcptch_theme_v2'];
285
286 foreach ( get_editable_roles() as $role => $fields ) {
287 $gglcptch_options[ $role ] = isset( $_POST[ 'gglcptch_' . $role ] ) ? 1 : 0;
288 }
289
290 update_option( 'gglcptch_options', $gglcptch_options );
291 $message = __( 'Settings saved', 'google_captcha' );
292 }
293
294 if ( isset( $_REQUEST['bws_restore_confirm'] ) && check_admin_referer( $plugin_basename, 'bws_settings_nonce_name' ) ) {
295 $gglcptch_options = $gglcptch_default_options;
296 update_option( 'gglcptch_options', $gglcptch_options );
297 $message = __( 'All plugin settings were restored.', 'google_captcha' );
298 }
299 }
300 /* GO PRO */
301 if ( isset( $_GET['action'] ) && 'go_pro' == $_GET['action'] ) {
302 $go_pro_result = bws_go_pro_tab_check( $plugin_basename );
303 if ( ! empty( $go_pro_result['error'] ) ) {
304 $error = $go_pro_result['error'];
305 }
306 } ?>
307 <div class="wrap">
308 <h2><?php _e( 'Google Captcha Settings', 'google_captcha' ); ?></h2>
309 <h2 class="nav-tab-wrapper">
310 <a class="nav-tab<?php if ( ! isset( $_GET['action'] ) ) echo ' nav-tab-active'; ?>" href="admin.php?page=google-captcha.php"><?php _e( 'Settings', 'google_captcha' ); ?></a>
311 <a class="nav-tab" href="http://bestwebsoft.com/products/google-captcha/faq/" target="_blank"><?php _e( 'FAQ', 'google_captcha' ); ?></a>
312 <a class="nav-tab<?php if ( isset( $_GET['action'] ) && 'go_pro' == $_GET['action'] ) echo ' nav-tab-active'; ?> bws_go_pro_tab" href="admin.php?page=google-captcha.php&amp;action=go_pro"><?php _e( 'Go PRO', 'google_captcha' ); ?></a>
313 </h2>
314 <div id="gglcptch_settings_notice" class="updated fade" style="display:none"><p><strong><?php _e( "Notice:", 'google_captcha' ); ?></strong> <?php _e( "The plugin's settings have been changed. In order to save them please don't forget to click the 'Save Changes' button.", 'google_captcha' ); ?></p></div>
315 <div class="updated fade" <?php if ( "" == $message ) echo 'style="display:none"'; ?>><p><strong><?php echo $message; ?></strong></p></div>
316 <div class="error" <?php if ( "" == $error ) echo 'style="display:none"'; ?>><p><strong><?php echo $error; ?></strong></p></div>
317 <?php if ( ! $gglcptch_allow_url_fopen && $gglcptch_options['recaptcha_version'] == 'v2' ) {
318 printf( '<div class="error"><p><strong>%s</strong> <a href="http://php.net/manual/en/filesystem.configuration.php" target="_blank">%s</a></p></div>',
319 __( 'Google Captcha version 2 will not work correctly, since the option "allow_url_fopen" is disabled in the PHP settings of your hosting.', 'google_captcha' ),
320 __( 'Read more.', 'google_captcha' )
321 );
322 }
323 if ( ! isset( $_GET['action'] ) ) {
324 if ( isset( $_REQUEST['bws_restore_default'] ) && check_admin_referer( $plugin_basename, 'bws_settings_nonce_name' ) ) {
325 bws_form_restore_default_confirm( $plugin_basename );
326 } else { ?>
327 <p><?php _e( 'If you would like to add the Google Captcha to your own form, just copy and paste this shortcode to your post or page:', 'google_captcha' ); ?> [bws_google_captcha]</p>
328 <form id="gglcptch_settings_form" method="post" action="admin.php?page=google-captcha.php">
329 <h3><?php _e( 'Authentication', 'google_captcha' ); ?></h3>
330 <p><?php printf( __( 'Before you are able to do something, you must to register %s here %s', 'google_captcha' ), '<a target="_blank" href="https://www.google.com/recaptcha/admin#list">','</a>.' ); ?></p>
331 <p><?php _e( 'Enter site key and secret key, that you get after registration.', 'google_captcha' ); ?></p>
332 <table id="gglcptch-keys" class="form-table">
333 <?php foreach ( $gglcptch_keys as $key => $fields ) : ?>
334 <tr valign="top">
335 <th scope="row"><?php echo $fields['display_name']; ?></th>
336 <td>
337 <input type="text" name="<?php echo $fields['form_name']; ?>" value="<?php echo $gglcptch_options[ $key . '_key' ] ?>" maxlength="200" />
338 <label class="gglcptch_error_msg"><?php echo $fields['error_msg']; ?></label>
339 </td>
340 </tr>
341 <?php endforeach; ?>
342 </table>
343 <h3><?php _e( 'Options', 'google_captcha' ); ?></h3>
344 <table class="form-table">
345 <tr valign="top">
346 <th scope="row"><?php _e( 'Enable reCAPTCHA for', 'google_captcha' ); ?></th>
347 <td>
348 <?php foreach ( $gglcptch_forms as $form ) : ?>
349 <label><input type="checkbox" name="<?php echo 'gglcptch_' . $form[0]; ?>" value=<?php echo $form[0]; if ( '1' == $gglcptch_options[ $form[0] ] ) echo ' checked'; ?>> <?php echo $form[1]; ?></label><br />
350 <?php endforeach;
351 $gglcptch_all_plugins = get_plugins();
352 $gglcptch_cntctfrm_installed = ( isset( $gglcptch_all_plugins['contact-form-plugin/contact_form.php'] ) || isset( $gglcptch_all_plugins['contact-form-pro/contact_form_pro.php'] ) ) ? true : false;
353 $gglcptch_cntctfrm_activated = ( is_plugin_active( 'contact-form-plugin/contact_form.php' ) || is_plugin_active( 'contact-form-pro/contact_form_pro.php' ) ) ? true : false;
354 if ( $gglcptch_cntctfrm_installed ) :
355 if ( $gglcptch_cntctfrm_activated ) : ?>
356 <label><input type="checkbox" name="gglcptch_contact_form" value="contact_form"<?php if ( '1' == $gglcptch_options['contact_form'] ) echo ' checked'; ?>> <?php _e( 'Contact form', 'google_captcha' ); ?></label>
357 <span class="gglcptch_span">(<?php _e( 'powered by', 'google_captcha' ); ?> <a href="http://bestwebsoft.com/products/">bestwebsoft.com</a>)</span><br />
358 <?php else : ?>
359 <label><input type="checkbox" disabled name="gglcptch_contact_form" value="contact_form"<?php if ( '1' == $gglcptch_options['contact_form'] ) echo ' checked'; ?>> <?php _e( 'Contact form', 'google_captcha' ); ?></label>
360 <span class="gglcptch_span">(<?php _e( 'powered by', 'google_captcha' ); ?> <a href="http://bestwebsoft.com/products/">bestwebsoft.com</a>) <a href="<?php echo bloginfo("url"); ?>/wp-admin/plugins.php"><?php _e( 'Activate contact form', 'google_captcha' ); ?></a></span><br />
361 <?php endif;
362 else : ?>
363 <label><input type="checkbox" disabled name="gglcptch_contact_form" value="contact_form"<?php if ( '1' == $gglcptch_options['contact_form'] ) echo ' checked'; ?>> <?php _e( 'Contact form', 'google_captcha' ); ?></label>
364 <span class="gglcptch_span">(<?php _e( 'powered by', 'google_captcha' ); ?> <a href="http://bestwebsoft.com/products/">bestwebsoft.com</a>) <a href="http://bestwebsoft.com/products/contact-form/?k=d70b58e1739ab4857d675fed2213cedc&pn=75&v=<?php echo $gglcptch_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>"><?php _e( 'Download contact form', 'google_captcha' ); ?></a></span><br />
365 <?php endif; ?>
366 </td>
367 </tr>
368 <tr valign="top">
369 <th scope="row"><?php _e( 'Hide reCAPTCHA for', 'google_captcha' ); ?></th>
370 <td>
371 <?php foreach ( get_editable_roles() as $role => $fields) : ?>
372 <label><input type="checkbox" name="<?php echo 'gglcptch_' . $role; ?>" value=<?php echo $role; if ( isset( $gglcptch_options[ $role ] ) && '1' == $gglcptch_options[ $role ] ) echo ' checked'; ?>> <?php echo $fields['name']; ?></label><br/>
373 <?php endforeach; ?>
374 </td>
375 </tr>
376 </table>
377 <div class="bws_pro_version_bloc">
378 <div class="bws_pro_version_table_bloc">
379 <div class="bws_table_bg"></div>
380 <table class="form-table bws_pro_version">
381 <tr valign="top">
382 <th scope="row"><?php _e( 'reCAPTCHA language', 'google_captcha' ); ?></th>
383 <td>
384 <select id="gglcptch_language" name="gglcptch_language">
385 <?php foreach ( $gglcptch_languages as $code => $name ) {
386 printf(
387 '<option value="%s"%s>%s</option>',
388 $code,
389 $code == 'en' ? ' selected="selected"' : '',
390 $name
391 );
392 } ?>
393 </select>
394 <div style="margin: 5px 0 0;">
395 <?php $all_plugins = get_plugins();
396 $gglcptch_multilanguage = $gglcptch_use_multilanguage = $gglcptch_multilanguage_message = '';
397 if ( array_key_exists( 'multilanguage/multilanguage.php', $all_plugins ) || array_key_exists( 'multilanguage-pro/multilanguage-pro.php', $all_plugins ) ) {
398 if ( is_plugin_active( 'multilanguage/multilanguage.php' ) || is_plugin_active( 'multilanguage-pro/multilanguage-pro.php' ) ) {
399 $gglcptch_use_multilanguage = ( $gglcptch_options["use_multilanguage_locale"] == 1 ) ? 'checked="checked"' : '';
400 } else {
401 $gglcptch_multilanguage = 'disabled="disabled"';
402 $gglcptch_multilanguage_message = sprintf( '<a href="plugins.php">%s Multilanguage</a>', __( 'Activate', 'google_captcha' ) );
403 }
404 } else {
405 $gglcptch_multilanguage = 'disabled="disabled"';
406 $gglcptch_multilanguage_message = sprintf( '<a href="http://bestwebsoft.com/products/multilanguage/?k=390f8e0d92066f2b73a14429d02dcee7&pn=281&v=%s&wp_v=%s">%s Multilanguage</a>', $gglcptch_plugin_info["Version"], $wp_version, __( 'Download', 'google_captcha' ) );
407 } ?>
408 <input id="gglcptch_use_multilanguage_locale" type="checkbox" name="gglcptch_use_multilanguage_locale" value="1" <?php printf( '%s %s', $gglcptch_use_multilanguage, $gglcptch_multilanguage ) ?> />
409 <label for="gglcptch_use_multilanguage_locale"><?php _e( 'Use the current site language', 'google_captcha' ); ?></label>&nbsp;<span class="bws_info">(<?php _e( 'Using', 'google_captcha' ); ?> Multilanguage by BestWebSoft) <?php echo $gglcptch_multilanguage_message; ?></span>
410 </div>
411 </td>
412 </tr>
413 </table>
414 </div>
415 <div class="bws_pro_version_tooltip">
416 <div class="bws_info">
417 <?php _e( 'Unlock premium options by upgrading to Pro version', 'google_captcha' ); ?>
418 </div>
419 <a class="bws_button" href="http://bestwebsoft.com/products/google-captcha/?k=b850d949ccc1239cab0da315c3c822ab&pn=109&v=<?php echo $gglcptch_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="Google Captcha Pro (reCAPTCHA)">
420 <?php _e( 'Learn More', 'google_captcha' ); ?>
421 </a>
422 <div class="clear"></div>
423 </div>
424 </div>
425 <table class="form-table">
426 <tr valign="top">
427 <th scope="row"><?php _e( 'reCAPTCHA version', 'google_captcha' ); ?></th>
428 <td>
429 <label><input type="radio" name="gglcptch_recaptcha_version" value="v1"<?php if ( 'v1' == $gglcptch_options['recaptcha_version'] ) echo ' checked="checked"'; ?>> <?php _e( 'version', 'google_captcha' ); ?> 1</label><br/>
430 <label><input type="radio" name="gglcptch_recaptcha_version" value="v2"<?php if ( 'v2' == $gglcptch_options['recaptcha_version'] ) echo ' checked="checked"'; ?>> <?php _e( 'version', 'google_captcha' ); ?> 2</label>
431 </td>
432 </tr>
433 <tr class="gglcptch_theme_v1" valign="top">
434 <th scope="row">
435 <?php _e( 'reCAPTCHA theme', 'google_captcha' ); ?>
436 <br/><span class="gglcptch_span">(<?php _e( 'for version', 'google_captcha' ); ?> 1)</span>
437 </th>
438 <td>
439 <select name="gglcptch_theme">
440 <?php foreach ( $gglcptch_themes as $theme ) : ?>
441 <option value=<?php echo $theme[0]; if ( $theme[0] == $gglcptch_options['theme'] ) echo ' selected'; ?>> <?php echo $theme[1]; ?></option>
442 <?php endforeach; ?>
443 </select>
444 </td>
445 </tr>
446 <tr class="gglcptch_theme_v2" valign="top">
447 <th scope="row">
448 <?php _e( 'reCAPTCHA theme', 'google_captcha' ); ?>
449 <br/><span class="gglcptch_span">(<?php _e( 'for version', 'google_captcha' ); ?> 2)</span>
450 </th>
451 <td>
452 <select name="gglcptch_theme_v2">
453 <option value="light" <?php if ( 'light' == $gglcptch_options['theme_v2'] ) echo ' selected'; ?>>light</option>
454 <option value="dark" <?php if ( 'dark' == $gglcptch_options['theme_v2'] ) echo ' selected'; ?>>dark</option>
455 </select>
456 </td>
457 </tr>
458 </table>
459 <div class="gglcptch_theme_v2 bws_pro_version_bloc">
460 <div class="bws_pro_version_table_bloc">
461 <div class="bws_table_bg"></div>
462 <table class="form-table bws_pro_version">
463 <tr valign="top">
464 <th scope="row">
465 <?php _e( 'reCAPTCHA size', 'google_captcha' ); ?>
466 <br/><span class="gglcptch_span">(<?php _e( 'for version', 'google_captcha' ); ?> 2)</span>
467 </th>
468 <td>
469 <?php foreach ( $gglcptch_sizes_v2 as $value => $name ) {
470 printf(
471 '<div class="gglcptch_size_v2"><label><input type="radio" name="gglcptch_size_v2" value="%s"%s> %s</label></div>',
472 $value,
473 $name == 'Normal' ? ' checked="checked"' : '',
474 $name
475 );
476 } ?>
477 </td>
478 </tr>
479 </table>
480 </div>
481 <div class="bws_pro_version_tooltip">
482 <div class="bws_info">
483 <?php _e( 'Unlock premium options by upgrading to Pro version', 'google_captcha' ); ?>
484 </div>
485 <a class="bws_button" href="http://bestwebsoft.com/products/google-captcha/?k=b850d949ccc1239cab0da315c3c822ab&pn=109&v=<?php echo $gglcptch_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="Google Captcha Pro (reCAPTCHA)">
486 <?php _e( 'Learn More', 'google_captcha' ); ?>
487 </a>
488 <div class="clear"></div>
489 </div>
490 </div>
491 <p class="submit">
492 <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'google_captcha' ); ?>" name="gglcptch_save_changes" />
493 </p>
494 <?php wp_nonce_field( plugin_basename( __FILE__ ), 'gglcptch_nonce_name' ); ?>
495 </form>
496 <?php bws_form_restore_default_settings( $plugin_basename );
497 }
498 bws_plugin_reviews_block( $gglcptch_plugin_info['Name'], 'google-captcha' );
499 } elseif ( 'go_pro' == $_GET['action'] ) {
500 bws_go_pro_tab( $gglcptch_plugin_info, $plugin_basename, 'google-captcha.php', 'google-captcha-pro.php', 'google-captcha-pro/google-captcha-pro.php', 'google-captcha', 'b850d949ccc1239cab0da315c3c822ab', '109', isset( $go_pro_result['pro_plugin_is_activated'] ) );
501 } ?>
502 </div>
503 <?php }
504 }
505
506 /* Checking current user role */
507 if ( ! function_exists( 'gglcptch_check_role' ) ) {
508 function gglcptch_check_role() {
509 global $current_user, $gglcptch_options;
510 if ( ! is_user_logged_in() )
511 return false;
512 if ( ! empty( $current_user->roles[0] ) ) {
513 $role = $current_user->roles[0];
514 if ( '1' == $gglcptch_options[ $role ] )
515 return true;
516 else
517 return false;
518 } else
519 return false;
520 }
521 }
522
523 /* Display google captcha via shortcode */
524 if ( ! function_exists( 'gglcptch_display' ) ) {
525 function gglcptch_display( $content = false ) {
526 if ( gglcptch_check_role() )
527 return;
528 global $gglcptch_options, $gglcptch_count, $gglcptch_allow_url_fopen;
529 if ( empty( $gglcptch_count ) ) {
530 $gglcptch_count = 1;
531 }
532 if ( $gglcptch_count > 1 ) {
533 return $content;
534 }
535 if ( ! $gglcptch_allow_url_fopen && isset( $gglcptch_options['recaptcha_version'] ) && $gglcptch_options['recaptcha_version'] == 'v2' ) {
536 $content .= '<div class="gglcptch allow_url_fopen_off"></div>';
537 $gglcptch_count++;
538 return $content;
539 }
540 $publickey = $gglcptch_options['public_key'];
541 $privatekey = $gglcptch_options['private_key'];
542 $content .= '<div class="gglcptch">';
543 if ( ! $privatekey || ! $publickey ) {
544 if ( current_user_can( 'manage_options' ) ) {
545 $content .= sprintf(
546 '<strong>%s <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s <a target="_blank" href="%s">%s</a>.</strong>',
547 __( 'To use Google Captcha you must get the keys from', 'google_captcha' ),
548 __ ( 'here', 'google_captcha' ),
549 __ ( 'and enter them on the', 'google_captcha' ),
550 admin_url( '/admin.php?page=google-captcha.php' ),
551 __( 'plugin setting page', 'google_captcha' )
552 );
553 }
554 $content .= '</div>';
555 $gglcptch_count++;
556 return $content;
557 }
558 if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) {
559 require_once( 'lib_v2/src/autoload.php' );
560 $reCaptcha = new \ReCaptcha\ReCaptcha( $privatekey );
561 $content .= '<style type="text/css" media="screen">
562 #gglcptch_error {
563 color: #F00;
564 }
565 </style>
566 <script type="text/javascript">
567 var ajaxurl = "' . admin_url( 'admin-ajax.php' ) . '",
568 gglcptch_error_msg = "' . __( 'Error: You have entered an incorrect CAPTCHA value.', 'google_captcha' ) . '";
569 </script>';
570 $content .= '<div class="g-recaptcha" data-sitekey="' . $publickey . '" data-theme="' . $gglcptch_options['theme_v2'] . '"></div>
571 <script type="text/javascript" src="https://www.google.com/recaptcha/api.js"></script>
572 <noscript>
573 <div style="width: 302px;">
574 <div style="width: 302px; height: 422px; position: relative;">
575 <div style="width: 302px; height: 422px; position: absolute;">
576 <iframe src="https://www.google.com/recaptcha/api/fallback?k=' . $publickey . '" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"></iframe>
577 </div>
578 </div>
579 <div style="border-style: none; bottom: 12px; left: 25px; margin: 0px; padding: 0px; right: 25px; background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px; height: 60px; width: 300px;">
580 <textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px; height: 40px; border: 1px solid #c1c1c1; margin: 10px 25px !important; padding: 0px; resize: none; "></textarea>
581 </div>
582 </div>
583 </noscript>';
584 } else {
585 require_once( 'lib/recaptchalib.php' );
586 $content .= sprintf(
587 '<style type="text/css" media="screen">
588 #recaptcha_response_field {
589 max-height: 35px;
590 }
591 #gglcptch_error {
592 color: #F00;
593 }
594 .gglcptch table#recaptcha_table {
595 table-layout: auto;
596 }
597 </style>
598 <script type="text/javascript">
599 var RecaptchaOptions = { theme : "%s" },
600 ajaxurl = "%s",
601 gglcptch_error_msg = "%s";
602 </script>',
603 $gglcptch_options['theme'],
604 admin_url( 'admin-ajax.php' ),
605 __( 'Error: You have entered an incorrect CAPTCHA value.', 'google_captcha' )
606 );
607 if ( is_ssl() )
608 $content .= gglcptch_recaptcha_get_html( $publickey, '', true );
609 else
610 $content .= gglcptch_recaptcha_get_html( $publickey );
611 }
612 $content .= '</div>';
613 $gglcptch_count++;
614 return $content;
615 }
616 }
617
618 /* Add google captcha to the login form */
619 if ( ! function_exists( 'gglcptch_login_display' ) ) {
620 function gglcptch_login_display() {
621 global $gglcptch_options;
622 if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) {
623 $from_width = 302;
624 } else {
625 $from_width = 320;
626 if ( 'clean' == $gglcptch_options['theme'] )
627 $from_width = 450;
628 } ?>
629 <style type="text/css" media="screen">
630 #loginform,
631 #lostpasswordform,
632 #registerform {
633 width: <?php echo $from_width; ?>px !important;
634 }
635 .message {
636 width: <?php echo $from_width + 20; ?>px !important;
637 }
638 #loginform .gglcptch {
639 margin-bottom: 10px;
640 }
641 </style>
642 <?php echo gglcptch_display();
643 return true;
644 }
645 }
646
647 /* Check google captcha in login form */
648 if ( ! function_exists( 'gglcptch_login_check' ) ) {
649 function gglcptch_login_check( $user ) {
650 global $gglcptch_options, $gglcptch_allow_url_fopen;
651
652 if ( ! $gglcptch_allow_url_fopen && isset( $gglcptch_options['recaptcha_version'] ) && $gglcptch_options['recaptcha_version'] == 'v2' ) {
653 return $user;
654 }
655
656 $publickey = $gglcptch_options['public_key'];
657 $privatekey = $gglcptch_options['private_key'];
658
659 if ( ! $privatekey || ! $publickey ) {
660 return $user;
661 }
662
663 if ( isset( $_REQUEST['g-recaptcha-response'] ) && isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) {
664 require_once( 'lib_v2/src/autoload.php' );
665 $reCaptcha = new \ReCaptcha\ReCaptcha( $privatekey );
666 $gglcptch_g_recaptcha_response = isset( $_POST["g-recaptcha-response"] ) ? $_POST["g-recaptcha-response"] : '';
667 $resp = $reCaptcha->verify( $gglcptch_g_recaptcha_response, $_SERVER['REMOTE_ADDR'] );
668
669 if ( $resp != null && $resp->isSuccess() )
670 return $user;
671 else {
672 wp_clear_auth_cookie();
673 $error = new WP_Error();
674 $error->add( 'gglcptch_error', '<strong>' . __( 'Error', 'google_captcha' ) . '</strong>: ' . __( 'You have entered an incorrect CAPTCHA value.', 'google_captcha' ) );
675 return $error;
676 }
677 } elseif ( isset( $_POST['recaptcha_challenge_field'] ) && isset( $_POST['recaptcha_response_field'] ) ) {
678 require_once( 'lib/recaptchalib.php' );
679 $gglcptch_recaptcha_challenge_field = isset( $_POST['recaptcha_challenge_field'] ) ? $_POST['recaptcha_challenge_field'] : '';
680 $gglcptch_recaptcha_response_field = isset( $_POST['recaptcha_response_field'] ) ? $_POST['recaptcha_response_field'] : '';
681 $resp = gglcptch_recaptcha_check_answer( $privatekey, $_SERVER['REMOTE_ADDR'], $gglcptch_recaptcha_challenge_field, $gglcptch_recaptcha_response_field );
682
683 if ( ! $resp->is_valid ) {
684 wp_clear_auth_cookie();
685 $error = new WP_Error();
686 $error->add( 'gglcptch_error', '<strong>' . __( 'Error', 'google_captcha' ) . '</strong>: ' . __( 'You have entered an incorrect CAPTCHA value.', 'google_captcha' ) );
687 return $error;
688 } else {
689 return $user;
690 }
691 } else {
692 if ( isset( $_REQUEST['log'] ) && isset( $_REQUEST['pwd'] ) ) {
693 /* captcha was not found in _REQUEST */
694 $error = new WP_Error();
695 $error->add( 'gglcptch_error', '<strong>' . __( 'Error', 'google_captcha' ) . '</strong>: ' . __( 'You have entered an incorrect CAPTCHA value.', 'google_captcha' ) );
696 return $error;
697 } else {
698 /* it is not a submit */
699 return $user;
700 }
701 }
702 }
703 }
704
705 /* Add google captcha to the comment form */
706 if ( ! function_exists( 'gglcptch_commentform_display' ) ) {
707 function gglcptch_commentform_display() {
708 if ( gglcptch_check_role() )
709 return;
710 echo gglcptch_display();
711 return true;
712 }
713 }
714
715 /* Check google captcha in lostpassword form */
716 if ( ! function_exists( 'gglcptch_lostpassword_check' ) ) {
717 function gglcptch_lostpassword_check() {
718 global $gglcptch_options, $gglcptch_allow_url_fopen;
719
720 if ( ! $gglcptch_allow_url_fopen && isset( $gglcptch_options['recaptcha_version'] ) && $gglcptch_options['recaptcha_version'] == 'v2' ) {
721 return;
722 }
723
724 $publickey = $gglcptch_options['public_key'];
725 $privatekey = $gglcptch_options['private_key'];
726
727 if ( ! $privatekey || ! $publickey )
728 return;
729
730 if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) {
731 require_once( 'lib_v2/src/autoload.php' );
732 $reCaptcha = new \ReCaptcha\ReCaptcha( $privatekey );
733 $gglcptch_g_recaptcha_response = isset( $_POST["g-recaptcha-response"] ) ? $_POST["g-recaptcha-response"] : '';
734 $resp = $reCaptcha->verify( $gglcptch_g_recaptcha_response, $_SERVER['REMOTE_ADDR'] );
735
736 if ( $resp != null && $resp->isSuccess() )
737 return;
738 else
739 wp_die( __( 'Error: You have entered an incorrect CAPTCHA value. Click the BACK button on your browser, and try again.', 'google_captcha' ) );
740 } else {
741 require_once( 'lib/recaptchalib.php' );
742 $gglcptch_recaptcha_challenge_field = isset( $_POST['recaptcha_challenge_field'] ) ? $_POST['recaptcha_challenge_field'] : '';
743 $gglcptch_recaptcha_response_field = isset( $_POST['recaptcha_response_field'] ) ? $_POST['recaptcha_response_field'] : '';
744 $resp = gglcptch_recaptcha_check_answer( $privatekey, $_SERVER['REMOTE_ADDR'], $gglcptch_recaptcha_challenge_field, $gglcptch_recaptcha_response_field );
745 if ( ! $resp->is_valid ) {
746 wp_die( __( 'Error: You have entered an incorrect CAPTCHA value. Click the BACK button on your browser, and try again.', 'google_captcha' ) );
747 } else
748 return;
749 }
750 }
751 }
752
753 /* display google captcha in Contact form */
754 if ( ! function_exists( 'gglcptch_cf_display' ) ) {
755 function gglcptch_cf_display() {
756 return gglcptch_display();
757 }
758 }
759
760 if ( ! function_exists( 'gglcptch_action_links' ) ) {
761 function gglcptch_action_links( $links, $file ) {
762 if ( ! is_network_admin() ) {
763 static $this_plugin;
764 if ( ! $this_plugin )
765 $this_plugin = plugin_basename(__FILE__);
766
767 if ( $file == $this_plugin ) {
768 $settings_link = '<a href="admin.php?page=google-captcha.php">' . __( 'Settings', 'google_captcha' ) . '</a>';
769 array_unshift( $links, $settings_link );
770 }
771 }
772 return $links;
773 }
774 }
775
776 if ( ! function_exists( 'gglcptch_links' ) ) {
777 function gglcptch_links( $links, $file ) {
778 $base = plugin_basename( __FILE__ );
779 if ( $file == $base ) {
780 if ( ! is_network_admin() )
781 $links[] = '<a href="admin.php?page=google_captcha.php">' . __( 'Settings', 'google_captcha' ) . '</a>';
782 $links[] = '<a href="http://wordpress.org/plugins/google-captcha/faq/" target="_blank">' . __( 'FAQ', 'google_captcha' ) . '</a>';
783 $links[] = '<a href="http://support.bestwebsoft.com">' . __( 'Support', 'google_captcha' ) . '</a>';
784 }
785 return $links;
786 }
787 }
788
789 if ( ! function_exists ( 'gglcptch_plugin_banner' ) ) {
790 function gglcptch_plugin_banner() {
791 global $hook_suffix, $gglcptch_plugin_info;
792 if ( 'plugins.php' == $hook_suffix ) {
793 global $gglstmp_plugin_info;
794 bws_plugin_banner( $gglcptch_plugin_info, 'gglcptch', 'google-captcha', '676d9558f9786ab41d7de35335cf5c4d', '109', '//ps.w.org/google-captcha/assets/icon-128x128.png' );
795 }
796 }
797 }
798
799 /* Check Google Captcha in shortcode and contact form */
800 if ( ! function_exists( 'gglcptch_captcha_check' ) ) {
801 function gglcptch_captcha_check() {
802 $gglcptch_options = get_option( 'gglcptch_options' );
803 $privatekey = $gglcptch_options['private_key'];
804
805 if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) {
806 require_once( 'lib_v2/src/autoload.php' );
807 $reCaptcha = new \ReCaptcha\ReCaptcha( $privatekey );
808 $gglcptch_g_recaptcha_response = isset( $_POST["g-recaptcha-response"] ) ? $_POST["g-recaptcha-response"] : '';
809 $resp = $reCaptcha->verify( $gglcptch_g_recaptcha_response, $_SERVER['REMOTE_ADDR'] );
810
811 if ( $resp != null && $resp->isSuccess() )
812 echo "success";
813 else
814 echo "error";
815 } else {
816 require_once( 'lib/recaptchalib.php' );
817 $gglcptch_recaptcha_challenge_field = isset( $_POST['recaptcha_challenge_field'] ) ? $_POST['recaptcha_challenge_field'] : '';
818 $gglcptch_recaptcha_response_field = isset( $_POST['recaptcha_response_field'] ) ? $_POST['recaptcha_response_field'] : '';
819 $resp = gglcptch_recaptcha_check_answer( $privatekey, $_SERVER['REMOTE_ADDR'], $gglcptch_recaptcha_challenge_field, $gglcptch_recaptcha_response_field );
820 if ( ! $resp->is_valid )
821 echo "error";
822 else
823 echo "success";
824 }
825 die();
826 }
827 }
828
829 /* Check JS enabled for comment form */
830 if ( ! function_exists( 'gglcptch_commentform_check' ) ) {
831 function gglcptch_commentform_check() {
832 if ( isset( $_POST['gglcptch_test_enable_js_field'] ) ) {
833 if ( wp_verify_nonce( $_POST['gglcptch_test_enable_js_field'], 'gglcptch_recaptcha_nonce' ) )
834 return;
835 else {
836 if ( gglcptch_check_role() )
837 return;
838 gglcptch_lostpassword_check();
839 }
840 } else {
841 if ( gglcptch_check_role() )
842 return;
843 gglcptch_lostpassword_check();
844 }
845 }
846 }
847
848 if ( ! function_exists( 'gglcptch_delete_options' ) ) {
849 function gglcptch_delete_options() {
850 global $wpdb;
851 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
852 $old_blog = $wpdb->blogid;
853 /* Get all blog ids */
854 $blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" );
855 foreach ( $blogids as $blog_id ) {
856 switch_to_blog( $blog_id );
857 delete_option( 'gglcptch_options' );
858 }
859 switch_to_blog( $old_blog );
860 } else {
861 delete_option( 'gglcptch_options' );
862 }
863 }
864 }
865
866 add_action( 'admin_menu', 'google_capthca_admin_menu' );
867 add_action( 'init', 'gglcptch_init' );
868 add_action( 'admin_init', 'gglcptch_admin_init' );
869 add_action( 'admin_enqueue_scripts', 'gglcptch_add_style' );
870 add_action( 'wp_enqueue_scripts', 'gglcptch_add_script' );
871
872 add_shortcode( 'bws_google_captcha', 'gglcptch_display' );
873
874 add_filter( 'plugin_action_links', 'gglcptch_action_links', 10, 2 );
875 add_filter( 'plugin_row_meta', 'gglcptch_links', 10, 2 );
876
877 add_action( 'admin_notices', 'gglcptch_plugin_banner' );
878
879 add_action( 'wp_ajax_gglcptch_captcha_check', 'gglcptch_captcha_check' );
880 add_action( 'wp_ajax_nopriv_gglcptch_captcha_check', 'gglcptch_captcha_check' );
881
882 register_uninstall_hook( __FILE__, 'gglcptch_delete_options' );