From 64f06a995358a16cfb5ff48603cb031eccf45930 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Tue, 16 Feb 2021 20:44:56 +0000
Subject: [PATCH] Collapse all recaptcha patches into one

---
 composer.patches.json                         |   3 +
 ...captcha-from-dumbly-use-http-schema-.patch |  42 --------
 ...for-the-global-public-and-private-re.patch |  57 ----------
 ...recaptcha-key-where-you-have-an-empt.patch |  45 --------
 ...-recaptcha-validate_user_signup-hook.patch |  25 -----
 ...ha-error-handling-in-show_recaptcha_.patch |  28 -----
 ...-require_once-config.php-from-recapt.patch |  64 -----------
 patches/plugins/wp-recaptcha-bp.patch         | 100 ++++++++++++++++++
 8 files changed, 103 insertions(+), 261 deletions(-)
 delete mode 100644 patches/0149-Patch-to-stop-recaptcha-from-dumbly-use-http-schema-.patch
 delete mode 100644 patches/0164-adding-a-define-for-the-global-public-and-private-re.patch
 delete mode 100644 patches/0168-set-the-correct-recaptcha-key-where-you-have-an-empt.patch
 delete mode 100644 patches/0183-fix-recaptcha-validate_user_signup-hook.patch
 delete mode 100644 patches/0184-Fixed-wp-recaptcha-error-handling-in-show_recaptcha_.patch
 delete mode 100644 patches/0206-removed-obsolete-require_once-config.php-from-recapt.patch
 create mode 100644 patches/plugins/wp-recaptcha-bp.patch

diff --git a/composer.patches.json b/composer.patches.json
index 215a880e..a4c74dc1 100644
--- a/composer.patches.json
+++ b/composer.patches.json
@@ -41,6 +41,9 @@
 	},
         "wpackagist-plugin/wp-piwik": {
             "Disable Piwik global updates": "patches/plugin/wp-piwik.patch"
+        },
+        "wpackagist-plugin/wp-recaptcha-bp": {
+            "Support for global recaptcha keys": "patches/plugin/wp-recaptcha-bp.patch"
         }
     }
 }
diff --git a/patches/0149-Patch-to-stop-recaptcha-from-dumbly-use-http-schema-.patch b/patches/0149-Patch-to-stop-recaptcha-from-dumbly-use-http-schema-.patch
deleted file mode 100644
index d15fc221..00000000
--- a/patches/0149-Patch-to-stop-recaptcha-from-dumbly-use-http-schema-.patch
+++ /dev/null
@@ -1,42 +0,0 @@
-From 9d72bfe515c90800399e0bd209fa386a62fe6393 Mon Sep 17 00:00:00 2001
-From: joe <joe@incal.net>
-Date: Fri, 16 Nov 2012 10:27:17 +0100
-Subject: [PATCH 149/229] Patch to stop recaptcha from dumbly use http://
- schema when we are on https
-
----
- wp-content/plugins/wp-recaptcha-bp/wp-plugin.php | 10 +++++++---
- 1 file changed, 7 insertions(+), 3 deletions(-)
-
-diff --git a/wp-content/plugins/wp-recaptcha-bp/wp-plugin.php b/wp-content/plugins/wp-recaptcha-bp/wp-plugin.php
-index ef05111e..001c8959 100644
---- a/wp-content/plugins/wp-recaptcha-bp/wp-plugin.php
-+++ b/wp-content/plugins/wp-recaptcha-bp/wp-plugin.php
-@@ -59,9 +59,13 @@ if (!class_exists('WPPlugin')) {
- 
-         static function plugins_url() {
-            if (WPPlugin::determine_environment() == Environment::WordPressMU)
--               return site_url() . '/wp-content/mu-plugins';
-+               $url = site_url() . '/wp-content/mu-plugins';
-            else
--               return site_url() . '/wp-content/plugins';
-+               $url =  site_url() . '/wp-content/plugins';
-+           if ($_SERVER['https'] == 'on') {
-+               $url = str_replace('http://', 'https://', $url);
-+           }
-+           return $url;
-         }
- 
-         static function path_to_plugin_directory() {
-@@ -72,7 +76,7 @@ if (!class_exists('WPPlugin')) {
- 
-         static function url_to_plugin_directory() {
-            $current_directory = basename(dirname(__FILE__));
--   
-+
-            return WPPlugin::plugins_url() . "/${current_directory}";
-         }
- 
--- 
-2.17.1
-
diff --git a/patches/0164-adding-a-define-for-the-global-public-and-private-re.patch b/patches/0164-adding-a-define-for-the-global-public-and-private-re.patch
deleted file mode 100644
index aa73ae4e..00000000
--- a/patches/0164-adding-a-define-for-the-global-public-and-private-re.patch
+++ /dev/null
@@ -1,57 +0,0 @@
-From 63979f02406bdd7dd8c4f8cec4964d37c2856b99 Mon Sep 17 00:00:00 2001
-From: Joe <joe@autistici.org>
-Date: Tue, 10 Sep 2013 14:37:53 +0200
-Subject: [PATCH 164/229] adding a define for the global public and private
- recaptcha keys.
-
-- Fix all blogs that have an empty recaptcha key.
-- require configuration for wp-recaptcha (to define the global keys)
----
- wp-content/plugins/wp-recaptcha-bp/recaptcha.php | 13 +++++++------
- 1 file changed, 7 insertions(+), 6 deletions(-)
-
-diff --git a/wp-content/plugins/wp-recaptcha-bp/recaptcha.php b/wp-content/plugins/wp-recaptcha-bp/recaptcha.php
-index 73461902..7c16045e 100644
---- a/wp-content/plugins/wp-recaptcha-bp/recaptcha.php
-+++ b/wp-content/plugins/wp-recaptcha-bp/recaptcha.php
-@@ -11,6 +11,7 @@
-  * @link      http://www.google.com/recaptcha
-  */
- 
-+require_once('config.php');
- require_once('wp-plugin.php');
- 
- if (class_exists('ReCAPTCHAPlugin'))
-@@ -115,8 +116,8 @@ class ReCAPTCHAPlugin extends WPPlugin
-         $option_defaults = array();
-         $old_options = WPPlugin::retrieve_options("recaptcha");
-         if ($old_options) {
--           $option_defaults['site_key'] = $old_options['pubkey'];
--           $option_defaults['secret'] = $old_options['privkey'];
-+           $option_defaults['site_key'] = $old_options['pubkey'] ? $old_options['pubkey'] : GLOBAL_RECAPTCHA_KEY;
-+           $option_defaults['secret'] = $old_options['privkey'] ? $old_options['privkey'] : GLOBAL_RECAPTCHA_PRIVATE_KEY;
- 
-            // styling
-            $option_defaults['recaptcha_language'] = $old_options['re_lang'];
-@@ -126,14 +127,14 @@ class ReCAPTCHAPlugin extends WPPlugin
-         } else {
-            $old_options = WPPlugin::retrieve_options($this->options_name);
-            if ($old_options) {
--               $option_defaults['site_key'] = $old_options['public_key'];
--               $option_defaults['secret'] = $old_options['private_key'];
-+               $option_defaults['site_key'] = $old_options['public_key'] ? $old_options['pubkey'] : GLOBAL_RECAPTCHA_KEY;
-+               $option_defaults['secret'] = $old_options['private_key'] ? $old_options['privkey'] : GLOBAL_RECAPTCHA_PRIVATE_KEY;
-                $option_defaults['comments_theme'] = 'standard';
-                $option_defaults['recaptcha_language'] = $old_options['recaptcha_language'];
-                $option_defaults['no_response_error'] = $old_options['no_response_error'];
-            } else {           
--               $option_defaults['site_key'] = '';
--               $option_defaults['secret'] = '';
-+               $option_defaults['site_key'] = GLOBAL_RECAPTCHA_KEY;
-+               $option_defaults['secret'] = GLOBAL_RECAPTCHA_PRIVATE_KEY;
-                $option_defaults['comments_theme'] = 'standard';
-                $option_defaults['recaptcha_language'] = 'en';
-                $option_defaults['no_response_error'] =
--- 
-2.17.1
-
diff --git a/patches/0168-set-the-correct-recaptcha-key-where-you-have-an-empt.patch b/patches/0168-set-the-correct-recaptcha-key-where-you-have-an-empt.patch
deleted file mode 100644
index 6f95db3e..00000000
--- a/patches/0168-set-the-correct-recaptcha-key-where-you-have-an-empt.patch
+++ /dev/null
@@ -1,45 +0,0 @@
-From 038eb25887261552f68154affc880c510d2acf5d Mon Sep 17 00:00:00 2001
-From: joe <joe@autistici.org>
-Date: Thu, 19 Sep 2013 00:18:18 +0200
-Subject: [PATCH 168/229] set the correct recaptcha key where you have an empty
- one
-
----
- wp-content/plugins/wp-recaptcha-bp/recaptcha.php | 10 +++++++++-
- 1 file changed, 9 insertions(+), 1 deletion(-)
-
-diff --git a/wp-content/plugins/wp-recaptcha-bp/recaptcha.php b/wp-content/plugins/wp-recaptcha-bp/recaptcha.php
-index 7c16045e..a9ea1d6c 100644
---- a/wp-content/plugins/wp-recaptcha-bp/recaptcha.php
-+++ b/wp-content/plugins/wp-recaptcha-bp/recaptcha.php
-@@ -111,8 +111,14 @@ class ReCAPTCHAPlugin extends WPPlugin
- 
-     // set the default options
-     function register_default_options() {
--        if ($this->options)
-+        if ($this->options) {
-+            if ($this->keys_missing()) {
-+                $this->options['site_key'] = GLOBAL_RECAPTCHA_KEY;
-+                $this->options['secret'] = GLOBAL_RECAPTCHA_PRIVATE_KEY;
-+                WPPlugin::add_options($this->options_name, $this->options);
-+            }
-             return;
-+        }
-         $option_defaults = array();
-         $old_options = WPPlugin::retrieve_options("recaptcha");
-         if ($old_options) {
-@@ -172,9 +178,11 @@ class ReCAPTCHAPlugin extends WPPlugin
-     }
- 
-     function missing_keys_notice() {
-+        /*
-         if ($this->keys_missing()) {
-             $this->create_error_notice('reCAPTCHA API Keys are missing.');
-         }
-+        */
-     }
- 
-     function validate_dropdown($array, $key, $value) {
--- 
-2.17.1
-
diff --git a/patches/0183-fix-recaptcha-validate_user_signup-hook.patch b/patches/0183-fix-recaptcha-validate_user_signup-hook.patch
deleted file mode 100644
index 7c1ebb91..00000000
--- a/patches/0183-fix-recaptcha-validate_user_signup-hook.patch
+++ /dev/null
@@ -1,25 +0,0 @@
-From 77926f741d799b195754acbd96291645e6222014 Mon Sep 17 00:00:00 2001
-From: ale <ale@incal.net>
-Date: Sat, 22 Aug 2015 18:42:44 +0100
-Subject: [PATCH 183/229] fix recaptcha validate_user_signup hook
-
----
- wp-content/plugins/wp-recaptcha-bp/recaptcha.php | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/wp-content/plugins/wp-recaptcha-bp/recaptcha.php b/wp-content/plugins/wp-recaptcha-bp/recaptcha.php
-index a9ea1d6c..2cb535b2 100644
---- a/wp-content/plugins/wp-recaptcha-bp/recaptcha.php
-+++ b/wp-content/plugins/wp-recaptcha-bp/recaptcha.php
-@@ -252,7 +252,7 @@ class ReCAPTCHAPlugin extends WPPlugin
-                 $_POST['g-recaptcha-response'] == '') {
-                 $result['errors']->add('blank_captcha',
-                     $this->options['no_response_error']);
--                return $result['errors'];
-+                return $result;
-             }
- 
-             if ($this->_reCaptchaLib == null) {
--- 
-2.17.1
-
diff --git a/patches/0184-Fixed-wp-recaptcha-error-handling-in-show_recaptcha_.patch b/patches/0184-Fixed-wp-recaptcha-error-handling-in-show_recaptcha_.patch
deleted file mode 100644
index 3aed939f..00000000
--- a/patches/0184-Fixed-wp-recaptcha-error-handling-in-show_recaptcha_.patch
+++ /dev/null
@@ -1,28 +0,0 @@
-From d295dee2debd70f13656234f5888275779ae4a1b Mon Sep 17 00:00:00 2001
-From: lechuck <lechuck@autistici.org>
-Date: Sat, 26 Sep 2015 19:28:37 +0100
-Subject: [PATCH 184/229] Fixed wp-recaptcha error handling in
- show_recaptcha_in_registration
-
----
- wp-content/plugins/wp-recaptcha-bp/recaptcha.php | 4 +++-
- 1 file changed, 3 insertions(+), 1 deletion(-)
-
-diff --git a/wp-content/plugins/wp-recaptcha-bp/recaptcha.php b/wp-content/plugins/wp-recaptcha-bp/recaptcha.php
-index 2cb535b2..96d4fee0 100644
---- a/wp-content/plugins/wp-recaptcha-bp/recaptcha.php
-+++ b/wp-content/plugins/wp-recaptcha-bp/recaptcha.php
-@@ -211,7 +211,9 @@ class ReCAPTCHAPlugin extends WPPlugin
- 
-         // if it's for wordpress mu, show the errors
-         if ($this->is_multi_blog()) {
--            $error = $errors->get_error_message('captcha');
-+            if( is_wp_error( $errors ) ) {
-+              $error = $errors->get_error_message('captcha');
-+            }
-             echo '<label for="verification">Verification:</label>';
-             echo ($error ? '<p class="error">' . $error . '</p>' : '');
-             echo $this->get_recaptcha_html();
--- 
-2.17.1
-
diff --git a/patches/0206-removed-obsolete-require_once-config.php-from-recapt.patch b/patches/0206-removed-obsolete-require_once-config.php-from-recapt.patch
deleted file mode 100644
index 642952b7..00000000
--- a/patches/0206-removed-obsolete-require_once-config.php-from-recapt.patch
+++ /dev/null
@@ -1,64 +0,0 @@
-From 54c5277ba96294f6ad3ee970c894896d41d4d537 Mon Sep 17 00:00:00 2001
-From: lucha <lucha@paranoici.org>
-Date: Tue, 28 Nov 2017 19:46:42 -0800
-Subject: [PATCH 206/229] removed obsolete require_once('config.php') from
- recaptcha-bp plugin
-
-the configuration directive has been moved to wp-config.php, so it was
-duplicated. Should solve part of
-https://git.autistici.org/ai/noblogs-wp/issues/13
----
- wp-content/plugins/wp-recaptcha-bp/recaptcha.php | 9 ++++-----
- 1 file changed, 4 insertions(+), 5 deletions(-)
-
-diff --git a/wp-content/plugins/wp-recaptcha-bp/recaptcha.php b/wp-content/plugins/wp-recaptcha-bp/recaptcha.php
-index 96d4fee0..0ba2fab2 100644
---- a/wp-content/plugins/wp-recaptcha-bp/recaptcha.php
-+++ b/wp-content/plugins/wp-recaptcha-bp/recaptcha.php
-@@ -11,7 +11,6 @@
-  * @link      http://www.google.com/recaptcha
-  */
- 
--require_once('config.php');
- require_once('wp-plugin.php');
- 
- if (class_exists('ReCAPTCHAPlugin'))
-@@ -138,7 +137,7 @@ class ReCAPTCHAPlugin extends WPPlugin
-                $option_defaults['comments_theme'] = 'standard';
-                $option_defaults['recaptcha_language'] = $old_options['recaptcha_language'];
-                $option_defaults['no_response_error'] = $old_options['no_response_error'];
--           } else {           
-+           } else {
-                $option_defaults['site_key'] = GLOBAL_RECAPTCHA_KEY;
-                $option_defaults['secret'] = GLOBAL_RECAPTCHA_PRIVATE_KEY;
-                $option_defaults['comments_theme'] = 'standard';
-@@ -302,7 +301,7 @@ class ReCAPTCHAPlugin extends WPPlugin
-             <noscript>
-             <style type='text/css'>#submit {display:none;}</style>
-             <input name="submit" type="submit" id="submit-alt" tabindex="6"
--                value="Submit Comment"/> 
-+                value="Submit Comment"/>
-             </noscript>
- COMMENT_FORM;
- 
-@@ -321,7 +320,7 @@ COMMENT_FORM;
-             document.getElementById('recaptcha-submit-btn-area').appendChild (sub);
-             document.getElementById('submit').tabIndex = 6;
-             if ( typeof _recaptcha_wordpress_savedcomment != 'undefined') {
--                document.getElementById('comment').value = 
-+                document.getElementById('comment').value =
-                     _recaptcha_wordpress_savedcomment;
-             }
-             </script>
-@@ -406,7 +405,7 @@ JS;
-             wp_delete_comment($comment->comment_ID);
-         }
-     }
-- 
-+
-    // add a settings link to the plugin in the plugin list
-     function show_settings_link($links, $file) {
-         if ($file == plugin_basename($this->path_to_plugin_directory() .
--- 
-2.17.1
-
diff --git a/patches/plugins/wp-recaptcha-bp.patch b/patches/plugins/wp-recaptcha-bp.patch
new file mode 100644
index 00000000..0889edca
--- /dev/null
+++ b/patches/plugins/wp-recaptcha-bp.patch
@@ -0,0 +1,100 @@
+diff --git a/wp-content/plugins/wp-recaptcha-bp/recaptcha.php b/wp-content/plugins/wp-recaptcha-bp/recaptcha.php
+index 73461902f..0ba2fab2d 100644
+--- a/wp-content/plugins/wp-recaptcha-bp/recaptcha.php
++++ b/wp-content/plugins/wp-recaptcha-bp/recaptcha.php
+@@ -110,13 +110,19 @@ class ReCAPTCHAPlugin extends WPPlugin
+ 
+     // set the default options
+     function register_default_options() {
+-        if ($this->options)
++        if ($this->options) {
++            if ($this->keys_missing()) {
++                $this->options['site_key'] = GLOBAL_RECAPTCHA_KEY;
++                $this->options['secret'] = GLOBAL_RECAPTCHA_PRIVATE_KEY;
++                WPPlugin::add_options($this->options_name, $this->options);
++            }
+             return;
++        }
+         $option_defaults = array();
+         $old_options = WPPlugin::retrieve_options("recaptcha");
+         if ($old_options) {
+-           $option_defaults['site_key'] = $old_options['pubkey'];
+-           $option_defaults['secret'] = $old_options['privkey'];
++           $option_defaults['site_key'] = $old_options['pubkey'] ? $old_options['pubkey'] : GLOBAL_RECAPTCHA_KEY;
++           $option_defaults['secret'] = $old_options['privkey'] ? $old_options['privkey'] : GLOBAL_RECAPTCHA_PRIVATE_KEY;
+ 
+            // styling
+            $option_defaults['recaptcha_language'] = $old_options['re_lang'];
+@@ -126,14 +132,14 @@ class ReCAPTCHAPlugin extends WPPlugin
+         } else {
+            $old_options = WPPlugin::retrieve_options($this->options_name);
+            if ($old_options) {
+-               $option_defaults['site_key'] = $old_options['public_key'];
+-               $option_defaults['secret'] = $old_options['private_key'];
++               $option_defaults['site_key'] = $old_options['public_key'] ? $old_options['pubkey'] : GLOBAL_RECAPTCHA_KEY;
++               $option_defaults['secret'] = $old_options['private_key'] ? $old_options['privkey'] : GLOBAL_RECAPTCHA_PRIVATE_KEY;
+                $option_defaults['comments_theme'] = 'standard';
+                $option_defaults['recaptcha_language'] = $old_options['recaptcha_language'];
+                $option_defaults['no_response_error'] = $old_options['no_response_error'];
+-           } else {           
+-               $option_defaults['site_key'] = '';
+-               $option_defaults['secret'] = '';
++           } else {
++               $option_defaults['site_key'] = GLOBAL_RECAPTCHA_KEY;
++               $option_defaults['secret'] = GLOBAL_RECAPTCHA_PRIVATE_KEY;
+                $option_defaults['comments_theme'] = 'standard';
+                $option_defaults['recaptcha_language'] = 'en';
+                $option_defaults['no_response_error'] =
+@@ -171,9 +177,11 @@ class ReCAPTCHAPlugin extends WPPlugin
+     }
+ 
+     function missing_keys_notice() {
++        /*
+         if ($this->keys_missing()) {
+             $this->create_error_notice('reCAPTCHA API Keys are missing.');
+         }
++        */
+     }
+ 
+     function validate_dropdown($array, $key, $value) {
+@@ -202,7 +210,9 @@ class ReCAPTCHAPlugin extends WPPlugin
+ 
+         // if it's for wordpress mu, show the errors
+         if ($this->is_multi_blog()) {
+-            $error = $errors->get_error_message('captcha');
++            if( is_wp_error( $errors ) ) {
++              $error = $errors->get_error_message('captcha');
++            }
+             echo '<label for="verification">Verification:</label>';
+             echo ($error ? '<p class="error">' . $error . '</p>' : '');
+             echo $this->get_recaptcha_html();
+@@ -243,7 +253,7 @@ class ReCAPTCHAPlugin extends WPPlugin
+                 $_POST['g-recaptcha-response'] == '') {
+                 $result['errors']->add('blank_captcha',
+                     $this->options['no_response_error']);
+-                return $result['errors'];
++                return $result;
+             }
+ 
+             if ($this->_reCaptchaLib == null) {
+diff --git a/wp-content/plugins/wp-recaptcha-bp/wp-plugin.php b/wp-content/plugins/wp-recaptcha-bp/wp-plugin.php
+index ef05111ee..001c89597 100644
+--- a/wp-content/plugins/wp-recaptcha-bp/wp-plugin.php
++++ b/wp-content/plugins/wp-recaptcha-bp/wp-plugin.php
+@@ -59,9 +59,13 @@ if (!class_exists('WPPlugin')) {
+ 
+         static function plugins_url() {
+            if (WPPlugin::determine_environment() == Environment::WordPressMU)
+-               return site_url() . '/wp-content/mu-plugins';
++               $url = site_url() . '/wp-content/mu-plugins';
+            else
+-               return site_url() . '/wp-content/plugins';
++               $url =  site_url() . '/wp-content/plugins';
++           if ($_SERVER['https'] == 'on') {
++               $url = str_replace('http://', 'https://', $url);
++           }
++           return $url;
+         }
+ 
+         static function path_to_plugin_directory() {
+ 
-- 
GitLab