Skip to content

Commit

Permalink
Support loading serialized v5..v8 filters
Browse files Browse the repository at this point in the history
  • Loading branch information
cproensa authored and atrol committed Mar 4, 2018
1 parent 5259868 commit d613a30
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions core/filter_api.php
Expand Up @@ -992,25 +992,29 @@ function filter_deserialize( $p_serialized_filter ) {
# in this case, the filter version field inside the array is to be used
# and if not present, set the current filter version

# check to see if new cookie is needed
# check fitler version mark
$t_setting_arr = explode( '#', $p_serialized_filter, 2 );
if( ( $t_setting_arr[0] == 'v1' ) || ( $t_setting_arr[0] == 'v2' ) || ( $t_setting_arr[0] == 'v3' ) || ( $t_setting_arr[0] == 'v4' ) ) {
$t_version_string = $t_setting_arr[0];
if( in_array( $t_version_string, array( 'v1', 'v2', 'v3', 'v4' ) ) ) {
# these versions can't be salvaged, they are too old to update
return false;
} elseif( in_array( $t_version_string, array( 'v5', 'v6', 'v7', 'v8' ) ) ) {
# filters from v5 onwards should cope with changing filter indices dynamically
$t_filter_array = unserialize( $t_setting_arr[1] );
} else {
# filters from v9 onwards are stored as json
$t_filter_array = json_decode( $t_setting_arr[1], /* assoc array */ true );
}

# filters from v5 onwards should cope with changing filter indices dynamically

# Decode json string. If an error happens, eg, invalid format, returns false.
if( isset( $t_setting_arr[1] ) ) {
$t_filter_array = json_decode( $t_setting_arr[1], true );
} else {
# If the unserialez data is not an array, the some error happened, eg, invalid format
if( !is_array( $t_filter_array ) ) {
return false;
}

# Set the filter version that was loaded in the array
$t_filter_array['_version'] = $t_setting_arr[0];

# If upgrade in filter content is needed, it will be done in filter_ensure_valid_filter()
return filter_ensure_valid_filter( $t_filter_array );
}

Expand Down

0 comments on commit d613a30

Please sign in to comment.