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