fs_canonize_query_string

The NextGEN Gallery fs canonize query string function.

Description

(string) fs_canonize_query_string( (array) array $params, (array) array &$ignore_params, (bool) $params_prefix = false ); 

Returns (string)

Parameters (3)

0. $params (array) => array $params
The params.
1. $ignore_params (array) => array &$ignore_params
The ignore params.
2. $params_prefix — Optional. (bool) => false
The params prefix.

Usage

  1. if ( !function_exists( 'fs_canonize_query_string' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextgen-gallery/freemius/includes/fs-core-functions.php'; 
  3.  
  4. // The params. 
  5. $params = array(); 
  6.  
  7. // The ignore params. 
  8. $ignore_params = array(); 
  9.  
  10. // The params prefix. 
  11. $params_prefix = false; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = fs_canonize_query_string($params, $ignore_params, $params_prefix); 
  15.  

Defined (1)

The function is defined in the following location(s).

/freemius/includes/fs-core-functions.php  
  1. function fs_canonize_query_string( array $params, array &$ignore_params, $params_prefix = false ) { 
  2. if ( ! is_array( $params ) || 0 === count( $params ) ) { 
  3. return ''; 
  4.  
  5. // Url encode both keys and values 
  6. $keys = fs_urlencode_rfc3986( array_keys( $params ) ); 
  7. $values = fs_urlencode_rfc3986( array_values( $params ) ); 
  8. $params = array_combine( $keys, $values ); 
  9.  
  10. // Parameters are sorted by name, using lexicographical byte value ordering. 
  11. // Ref: Spec: 9.1.1 (1) 
  12. uksort( $params, 'strcmp' ); 
  13.  
  14. $pairs = array(); 
  15. foreach ( $params as $parameter => $value ) { 
  16. $lower_param = strtolower( $parameter ); 
  17.  
  18. // Skip ignore params. 
  19. if ( in_array( $lower_param, $ignore_params ) || 
  20. ( false !== $params_prefix && fs_starts_with( $lower_param, $params_prefix ) ) 
  21. ) { 
  22. continue; 
  23.  
  24. if ( is_array( $value ) ) { 
  25. // If two or more parameters share the same name, they are sorted by their value 
  26. // Ref: Spec: 9.1.1 (1) 
  27. natsort( $value ); 
  28. foreach ( $value as $duplicate_value ) { 
  29. $pairs[] = $lower_param . '=' . $duplicate_value; 
  30. } else { 
  31. $pairs[] = $lower_param . '=' . $value; 
  32.  
  33. if ( 0 === count( $pairs ) ) { 
  34. return ''; 
  35.  
  36. return implode( "&", $pairs );