PluginProbe ʕ •ᴥ•ʔ
reCaptcha by BestWebSoft / 1.19
reCaptcha by BestWebSoft v1.19
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
880 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.19
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 $content .= '<style type="text/css" media="screen">
560 #gglcptch_error {
561 color: #F00;
562 }
563 </style>
564 <script type="text/javascript">
565 var ajaxurl = "' . admin_url( 'admin-ajax.php' ) . '",
566 gglcptch_error_msg = "' . __( 'Error: You have entered an incorrect CAPTCHA value.', 'google_captcha' ) . '";
567 </script>';
568 $content .= '<div class="g-recaptcha" data-sitekey="' . $publickey . '" data-theme="' . $gglcptch_options['theme_v2'] . '"></div>
569 <script type="text/javascript" src="https://www.google.com/recaptcha/api.js"></script>
570 <noscript>
571 <div style="width: 302px;">
572 <div style="width: 302px; height: 422px; position: relative;">
573 <div style="width: 302px; height: 422px; position: absolute;">
574 <iframe src="https://www.google.com/recaptcha/api/fallback?k=' . $publickey . '" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"></iframe>
575 </div>
576 </div>
577 <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;">
578 <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>
579 </div>
580 </div>
581 </noscript>';
582 } else {
583 require_once( 'lib/recaptchalib.php' );
584 $content .= sprintf(
585 '<style type="text/css" media="screen">
586 #recaptcha_response_field {
587 max-height: 35px;
588 }
589 #gglcptch_error {
590 color: #F00;
591 }
592 .gglcptch table#recaptcha_table {
593 table-layout: auto;
594 }
595 </style>
596 <script type="text/javascript">
597 var RecaptchaOptions = { theme : "%s" },
598 ajaxurl = "%s",
599 gglcptch_error_msg = "%s";
600 </script>',
601 $gglcptch_options['theme'],
602 admin_url( 'admin-ajax.php' ),
603 __( 'Error: You have entered an incorrect CAPTCHA value.', 'google_captcha' )
604 );
605 if ( is_ssl() )
606 $content .= gglcptch_recaptcha_get_html( $publickey, '', true );
607 else
608 $content .= gglcptch_recaptcha_get_html( $publickey );
609 }
610 $content .= '</div>';
611 $gglcptch_count++;
612 return $content;
613 }
614 }
615
616 /* Add google captcha to the login form */
617 if ( ! function_exists( 'gglcptch_login_display' ) ) {
618 function gglcptch_login_display() {
619 global $gglcptch_options;
620 if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) {
621 $from_width = 302;
622 } else {
623 $from_width = 320;
624 if ( 'clean' == $gglcptch_options['theme'] )
625 $from_width = 450;
626 } ?>
627 <style type="text/css" media="screen">
628 #loginform,
629 #lostpasswordform,
630 #registerform {
631 width: <?php echo $from_width; ?>px !important;
632 }
633 .message {
634 width: <?php echo $from_width + 20; ?>px !important;
635 }
636 #loginform .gglcptch {
637 margin-bottom: 10px;
638 }
639 </style>
640 <?php echo gglcptch_display();
641 return true;
642 }
643 }
644
645 /* Check google captcha in login form */
646 if ( ! function_exists( 'gglcptch_login_check' ) ) {
647 function gglcptch_login_check( $user ) {
648 global $gglcptch_options, $gglcptch_allow_url_fopen;
649
650 if ( ! $gglcptch_allow_url_fopen && isset( $gglcptch_options['recaptcha_version'] ) && $gglcptch_options['recaptcha_version'] == 'v2' ) {
651 return $user;
652 }
653
654 $publickey = $gglcptch_options['public_key'];
655 $privatekey = $gglcptch_options['private_key'];
656
657 if ( ! $privatekey || ! $publickey ) {
658 return $user;
659 }
660
661 if ( isset( $_REQUEST['g-recaptcha-response'] ) && isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) {
662 require_once( 'lib_v2/recaptchalib.php' );
663 $reCaptcha = new gglcptch_ReCaptcha( $privatekey );
664 $gglcptch_g_recaptcha_response = isset( $_POST["g-recaptcha-response"] ) ? $_POST["g-recaptcha-response"] : '';
665 $resp = $reCaptcha->verifyResponse( $_SERVER["REMOTE_ADDR"], $gglcptch_g_recaptcha_response );
666
667 if ( $resp != null && $resp->success )
668 return $user;
669 else {
670 wp_clear_auth_cookie();
671 $error = new WP_Error();
672 $error->add( 'gglcptch_error', '<strong>' . __( 'Error', 'google_captcha' ) . '</strong>: ' . __( 'You have entered an incorrect CAPTCHA value.', 'google_captcha' ) );
673 return $error;
674 }
675 } elseif ( isset( $_POST['recaptcha_challenge_field'] ) && isset( $_POST['recaptcha_response_field'] ) ) {
676 require_once( 'lib/recaptchalib.php' );
677 $gglcptch_recaptcha_challenge_field = isset( $_POST['recaptcha_challenge_field'] ) ? $_POST['recaptcha_challenge_field'] : '';
678 $gglcptch_recaptcha_response_field = isset( $_POST['recaptcha_response_field'] ) ? $_POST['recaptcha_response_field'] : '';
679 $resp = gglcptch_recaptcha_check_answer( $privatekey, $_SERVER['REMOTE_ADDR'], $gglcptch_recaptcha_challenge_field, $gglcptch_recaptcha_response_field );
680
681 if ( ! $resp->is_valid ) {
682 wp_clear_auth_cookie();
683 $error = new WP_Error();
684 $error->add( 'gglcptch_error', '<strong>' . __( 'Error', 'google_captcha' ) . '</strong>: ' . __( 'You have entered an incorrect CAPTCHA value.', 'google_captcha' ) );
685 return $error;
686 } else {
687 return $user;
688 }
689 } else {
690 if ( isset( $_REQUEST['log'] ) && isset( $_REQUEST['pwd'] ) ) {
691 /* captcha was not found in _REQUEST */
692 $error = new WP_Error();
693 $error->add( 'gglcptch_error', '<strong>' . __( 'Error', 'google_captcha' ) . '</strong>: ' . __( 'You have entered an incorrect CAPTCHA value.', 'google_captcha' ) );
694 return $error;
695 } else {
696 /* it is not a submit */
697 return $user;
698 }
699 }
700 }
701 }
702
703 /* Add google captcha to the comment form */
704 if ( ! function_exists( 'gglcptch_commentform_display' ) ) {
705 function gglcptch_commentform_display() {
706 if ( gglcptch_check_role() )
707 return;
708 echo gglcptch_display();
709 return true;
710 }
711 }
712
713 /* Check google captcha in lostpassword form */
714 if ( ! function_exists( 'gglcptch_lostpassword_check' ) ) {
715 function gglcptch_lostpassword_check() {
716 global $gglcptch_options, $gglcptch_allow_url_fopen;
717
718 if ( ! $gglcptch_allow_url_fopen && isset( $gglcptch_options['recaptcha_version'] ) && $gglcptch_options['recaptcha_version'] == 'v2' ) {
719 return;
720 }
721
722 $publickey = $gglcptch_options['public_key'];
723 $privatekey = $gglcptch_options['private_key'];
724
725 if ( ! $privatekey || ! $publickey )
726 return;
727
728 if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) {
729 require_once( 'lib_v2/recaptchalib.php' );
730 $reCaptcha = new gglcptch_ReCaptcha( $privatekey );
731 $gglcptch_g_recaptcha_response = isset( $_POST["g-recaptcha-response"] ) ? $_POST["g-recaptcha-response"] : '';
732 $resp = $reCaptcha->verifyResponse( $_SERVER["REMOTE_ADDR"], $gglcptch_g_recaptcha_response );
733
734 if ( $resp != null && $resp->success )
735 return;
736 else
737 wp_die( __( 'Error: You have entered an incorrect CAPTCHA value. Click the BACK button on your browser, and try again.', 'google_captcha' ) );
738 } else {
739 require_once( 'lib/recaptchalib.php' );
740 $gglcptch_recaptcha_challenge_field = isset( $_POST['recaptcha_challenge_field'] ) ? $_POST['recaptcha_challenge_field'] : '';
741 $gglcptch_recaptcha_response_field = isset( $_POST['recaptcha_response_field'] ) ? $_POST['recaptcha_response_field'] : '';
742 $resp = gglcptch_recaptcha_check_answer( $privatekey, $_SERVER['REMOTE_ADDR'], $gglcptch_recaptcha_challenge_field, $gglcptch_recaptcha_response_field );
743 if ( ! $resp->is_valid ) {
744 wp_die( __( 'Error: You have entered an incorrect CAPTCHA value. Click the BACK button on your browser, and try again.', 'google_captcha' ) );
745 } else
746 return;
747 }
748 }
749 }
750
751 /* display google captcha in Contact form */
752 if ( ! function_exists( 'gglcptch_cf_display' ) ) {
753 function gglcptch_cf_display() {
754 return gglcptch_display();
755 }
756 }
757
758 if ( ! function_exists( 'gglcptch_action_links' ) ) {
759 function gglcptch_action_links( $links, $file ) {
760 if ( ! is_network_admin() ) {
761 static $this_plugin;
762 if ( ! $this_plugin )
763 $this_plugin = plugin_basename(__FILE__);
764
765 if ( $file == $this_plugin ) {
766 $settings_link = '<a href="admin.php?page=google-captcha.php">' . __( 'Settings', 'google_captcha' ) . '</a>';
767 array_unshift( $links, $settings_link );
768 }
769 }
770 return $links;
771 }
772 }
773
774 if ( ! function_exists( 'gglcptch_links' ) ) {
775 function gglcptch_links( $links, $file ) {
776 $base = plugin_basename( __FILE__ );
777 if ( $file == $base ) {
778 if ( ! is_network_admin() )
779 $links[] = '<a href="admin.php?page=google_captcha.php">' . __( 'Settings', 'google_captcha' ) . '</a>';
780 $links[] = '<a href="http://wordpress.org/plugins/google-captcha/faq/" target="_blank">' . __( 'FAQ', 'google_captcha' ) . '</a>';
781 $links[] = '<a href="http://support.bestwebsoft.com">' . __( 'Support', 'google_captcha' ) . '</a>';
782 }
783 return $links;
784 }
785 }
786
787 if ( ! function_exists ( 'gglcptch_plugin_banner' ) ) {
788 function gglcptch_plugin_banner() {
789 global $hook_suffix, $gglcptch_plugin_info;
790 if ( 'plugins.php' == $hook_suffix ) {
791 global $gglstmp_plugin_info;
792 bws_plugin_banner( $gglcptch_plugin_info, 'gglcptch', 'google-captcha', '676d9558f9786ab41d7de35335cf5c4d', '109', '//ps.w.org/google-captcha/assets/icon-128x128.png' );
793 }
794 }
795 }
796
797 /* Check Google Captcha in shortcode and contact form */
798 if ( ! function_exists( 'gglcptch_captcha_check' ) ) {
799 function gglcptch_captcha_check() {
800 $gglcptch_options = get_option( 'gglcptch_options' );
801 $privatekey = $gglcptch_options['private_key'];
802
803 if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v2' == $gglcptch_options['recaptcha_version'] ) {
804 require_once( 'lib_v2/recaptchalib.php' );
805 $reCaptcha = new gglcptch_ReCaptcha( $privatekey );
806 $gglcptch_g_recaptcha_response = isset( $_POST["g-recaptcha-response"] ) ? $_POST["g-recaptcha-response"] : '';
807 $resp = $reCaptcha->verifyResponse( $_SERVER["REMOTE_ADDR"], $gglcptch_g_recaptcha_response );
808
809 if ( $resp != null && $resp->success )
810 echo "success";
811 else
812 echo "error";
813 } else {
814 require_once( 'lib/recaptchalib.php' );
815 $gglcptch_recaptcha_challenge_field = isset( $_POST['recaptcha_challenge_field'] ) ? $_POST['recaptcha_challenge_field'] : '';
816 $gglcptch_recaptcha_response_field = isset( $_POST['recaptcha_response_field'] ) ? $_POST['recaptcha_response_field'] : '';
817 $resp = gglcptch_recaptcha_check_answer( $privatekey, $_SERVER['REMOTE_ADDR'], $gglcptch_recaptcha_challenge_field, $gglcptch_recaptcha_response_field );
818 if ( ! $resp->is_valid )
819 echo "error";
820 else
821 echo "success";
822 }
823 die();
824 }
825 }
826
827 /* Check JS enabled for comment form */
828 if ( ! function_exists( 'gglcptch_commentform_check' ) ) {
829 function gglcptch_commentform_check() {
830 if ( isset( $_POST['gglcptch_test_enable_js_field'] ) ) {
831 if ( wp_verify_nonce( $_POST['gglcptch_test_enable_js_field'], 'gglcptch_recaptcha_nonce' ) )
832 return;
833 else {
834 if ( gglcptch_check_role() )
835 return;
836 gglcptch_lostpassword_check();
837 }
838 } else {
839 if ( gglcptch_check_role() )
840 return;
841 gglcptch_lostpassword_check();
842 }
843 }
844 }
845
846 if ( ! function_exists( 'gglcptch_delete_options' ) ) {
847 function gglcptch_delete_options() {
848 global $wpdb;
849 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
850 $old_blog = $wpdb->blogid;
851 /* Get all blog ids */
852 $blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" );
853 foreach ( $blogids as $blog_id ) {
854 switch_to_blog( $blog_id );
855 delete_option( 'gglcptch_options' );
856 }
857 switch_to_blog( $old_blog );
858 } else {
859 delete_option( 'gglcptch_options' );
860 }
861 }
862 }
863
864 add_action( 'admin_menu', 'google_capthca_admin_menu' );
865 add_action( 'init', 'gglcptch_init' );
866 add_action( 'admin_init', 'gglcptch_admin_init' );
867 add_action( 'admin_enqueue_scripts', 'gglcptch_add_style' );
868 add_action( 'wp_enqueue_scripts', 'gglcptch_add_script' );
869
870 add_shortcode( 'bws_google_captcha', 'gglcptch_display' );
871
872 add_filter( 'plugin_action_links', 'gglcptch_action_links', 10, 2 );
873 add_filter( 'plugin_row_meta', 'gglcptch_links', 10, 2 );
874
875 add_action( 'admin_notices', 'gglcptch_plugin_banner' );
876
877 add_action( 'wp_ajax_gglcptch_captcha_check', 'gglcptch_captcha_check' );
878 add_action( 'wp_ajax_nopriv_gglcptch_captcha_check', 'gglcptch_captcha_check' );
879
880 register_uninstall_hook( __FILE__, 'gglcptch_delete_options' );