From 5328b528cbbfa6317bd943bef8b8b9c4faadb50d Mon Sep 17 00:00:00 2001 From: ViorelEremia Date: Mon, 23 Apr 2018 11:24:41 +0300 Subject: [PATCH 1/4] Issue #3320, Issue #2494 - Theme settings max input vars --- .../backend/class-fw-settings-form-theme.php | 50 +++++++++++++++++++ framework/static/js/fw-form-helpers.js | 12 +++-- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/framework/core/components/backend/class-fw-settings-form-theme.php b/framework/core/components/backend/class-fw-settings-form-theme.php index 4844239e..64039137 100644 --- a/framework/core/components/backend/class-fw-settings-form-theme.php +++ b/framework/core/components/backend/class-fw-settings-form-theme.php @@ -11,6 +11,13 @@ protected function _init() { ->set_is_side_tabs( fw()->theme->get_config('settings_form_side_tabs') ) ->set_string( 'title', __('Theme Settings', 'fw') ); + if ( isset( $_POST['fw_theme_settings_form'] ) ) { + $this->parse_str( $_POST['fw_theme_settings_form'], $parsed ); + unset( $_POST['fw_theme_settings_form'] ); + + $_POST = array_merge( $_POST, $parsed ); + } + { add_action('admin_init', array($this, '_action_get_title_from_menu')); add_action('admin_menu', array($this, '_action_admin_menu')); @@ -215,4 +222,47 @@ public function _action_admin_enqueue_scripts() } } } + + // The same than parse_str without max_input_vars limitation + private function parse_str( $string, &$result ) + { + if ( $string==='') { + return false; + } + + $result = array(); + // find the pairs "name=value" + $pairs = explode( '&', $string ); + + foreach ( $pairs as $pair ) { + // use the original parse_str() on each element + parse_str( $pair, $params ); + $k = key( $params ); + + if ( ! isset( $result[ $k ] ) ) { + $result += $params; + } else { + $result[ $k ] = $this->array_merge_recursive_distinct( $result[ $k ], $params[ $k ] ); + } + } + + return true; + } + + // better recursive array merge function listed on the array_merge_recursive PHP page in the comments + private function array_merge_recursive_distinct( array &$array1, array &$array2 ) + { + $merged = $array1; + + foreach ( $array2 as $key => &$value ) { + + if ( is_array( $value ) && isset( $merged[ $key ] ) && is_array( $merged[ $key ] ) ){ + $merged[ $key ] = $this->array_merge_recursive_distinct( $merged[ $key ], $value ); + } else { + $merged[ $key ] = $value; + } + } + + return $merged; + } } \ No newline at end of file diff --git a/framework/static/js/fw-form-helpers.js b/framework/static/js/fw-form-helpers.js index 226fb589..bc06c6c5 100644 --- a/framework/static/js/fw-form-helpers.js +++ b/framework/static/js/fw-form-helpers.js @@ -150,14 +150,16 @@ var fwForm = { opts.afterSubmitDelay(elements); } + var data = $form.serialize() + ( $submitButton.length ? '&' + $submitButton.attr( 'name' ) + '=' + $submitButton.attr( 'value' ) : '' ); + + if ( $form.attr( 'data-fw-form-id' ) === 'fw-settings-form:theme-settings' ) { + data = {'fw_theme_settings_form': data}; + } + jQuery.ajax({ type: "POST", url: opts.ajaxUrl, - data: $form.serialize() + ( - $submitButton.length - ? '&'+ $submitButton.attr('name') +'='+ $submitButton.attr('value') - : '' - ), + data: data, dataType: 'json' }).done(function(r){ isBusy = false; From 7b4e60f62414d75901ca911a16d4bb13e1af7e71 Mon Sep 17 00:00:00 2001 From: ViorelEremia Date: Wed, 25 Apr 2018 16:10:14 +0300 Subject: [PATCH 2/4] Better version --- .../core/components/backend/class-fw-settings-form-theme.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/framework/core/components/backend/class-fw-settings-form-theme.php b/framework/core/components/backend/class-fw-settings-form-theme.php index 64039137..799d45c9 100644 --- a/framework/core/components/backend/class-fw-settings-form-theme.php +++ b/framework/core/components/backend/class-fw-settings-form-theme.php @@ -14,7 +14,6 @@ protected function _init() { if ( isset( $_POST['fw_theme_settings_form'] ) ) { $this->parse_str( $_POST['fw_theme_settings_form'], $parsed ); unset( $_POST['fw_theme_settings_form'] ); - $_POST = array_merge( $_POST, $parsed ); } @@ -230,6 +229,8 @@ private function parse_str( $string, &$result ) return false; } + parse_str( $string, $fuck ); + $result = array(); // find the pairs "name=value" $pairs = explode( '&', $string ); @@ -257,7 +258,7 @@ private function array_merge_recursive_distinct( array &$array1, array &$array2 foreach ( $array2 as $key => &$value ) { if ( is_array( $value ) && isset( $merged[ $key ] ) && is_array( $merged[ $key ] ) ){ - $merged[ $key ] = $this->array_merge_recursive_distinct( $merged[ $key ], $value ); + $merged[ $key ] = array_merge_recursive( $merged[ $key ], $value ); } else { $merged[ $key ] = $value; } From 3dd1ec4e13597ff466f0386ab5885a688101e157 Mon Sep 17 00:00:00 2001 From: ViorelEremia Date: Mon, 7 May 2018 15:15:28 +0300 Subject: [PATCH 3/4] slassh all json quotes --- .../core/components/backend/class-fw-settings-form-theme.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/framework/core/components/backend/class-fw-settings-form-theme.php b/framework/core/components/backend/class-fw-settings-form-theme.php index 799d45c9..61409739 100644 --- a/framework/core/components/backend/class-fw-settings-form-theme.php +++ b/framework/core/components/backend/class-fw-settings-form-theme.php @@ -238,6 +238,8 @@ private function parse_str( $string, &$result ) foreach ( $pairs as $pair ) { // use the original parse_str() on each element parse_str( $pair, $params ); + $params = wp_slash( $params ); + $k = key( $params ); if ( ! isset( $result[ $k ] ) ) { From ee9c237428523ad3690b6e307d7bc0e93d5fbb0c Mon Sep 17 00:00:00 2001 From: ViorelEremia Date: Tue, 8 May 2018 15:56:56 +0300 Subject: [PATCH 4/4] slash only double quotes --- .../backend/class-fw-settings-form-theme.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/framework/core/components/backend/class-fw-settings-form-theme.php b/framework/core/components/backend/class-fw-settings-form-theme.php index 61409739..acfe36f4 100644 --- a/framework/core/components/backend/class-fw-settings-form-theme.php +++ b/framework/core/components/backend/class-fw-settings-form-theme.php @@ -238,7 +238,7 @@ private function parse_str( $string, &$result ) foreach ( $pairs as $pair ) { // use the original parse_str() on each element parse_str( $pair, $params ); - $params = wp_slash( $params ); + $params = $this->wp_slash( $params ); $k = key( $params ); @@ -252,6 +252,22 @@ private function parse_str( $string, &$result ) return true; } + function wp_slash( $value ) { + if ( is_array( $value ) ) { + foreach ( $value as $k => $v ) { + if ( is_array( $v ) ) { + $value[ $k ] = $this->wp_slash( $v ); + } else { + $value[ $k ] = str_replace( "\\\\'", "'", addslashes( $v ) ); + } + } + } else { + $value = str_replace( "\\\\'", "'", addslashes( $value ) ); + } + + return $value; + } + // better recursive array merge function listed on the array_merge_recursive PHP page in the comments private function array_merge_recursive_distinct( array &$array1, array &$array2 ) {