nextgen_esc_url

The NextGEN Gallery nextgen esc url function.

Description

nextgen_esc_url( $url, (constant) $protocols = null, (string) $_context = 'display' ); 

Parameters (3)

0. $url
The url.
1. $protocols — Optional. (constant) => null
The protocols.
2. $context (string)
The context.

Usage

  1. if ( !function_exists( 'nextgen_esc_url' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextgen-gallery/nggallery.php'; 
  3.  
  4. // The url. 
  5. $url = null; 
  6.  
  7. // The protocols. 
  8. $protocols = null; 
  9.  
  10. // The context. 
  11. $context = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = nextgen_esc_url($url, $protocols, $context); 
  15.  

Defined (1)

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

/nggallery.php  
  1. function nextgen_esc_url( $url, $protocols = null, $_context = 'display' ) { 
  2. $original_url = $url; 
  3.  
  4. if ( '' == $url ) 
  5. return $url; 
  6. $url = preg_replace('|[^a-z0-9 \\-~+_.?#=!&;, /:%@$\|*\'()\\x80-\\xff]|i', '', $url); 
  7. $strip = array('%0d', '%0a', '%0D', '%0A'); 
  8. $url = _deep_replace($strip, $url); 
  9. $url = str_replace(';//', '://', $url); 
  10. /** If the URL doesn't appear to contain a scheme, we 
  11. * presume it needs http:// appended (unless a relative 
  12. * link starting with /, # or ? or a php file). 
  13. */ 
  14.  
  15. if ( strpos($url, ':') === false && ! in_array( $url[0], array( '/', '#', '?' ) ) && 
  16. ! preg_match('/^[a-z0-9-]+?\.php/i', $url) ) 
  17. $url = 'http://' . $url; 
  18.  
  19. // Replace ampersands and single quotes only when displaying. 
  20. if ( 'display' == $_context ) { 
  21. $url = wp_kses_normalize_entities( $url ); 
  22. $url = str_replace( '&', '&', $url ); 
  23. $url = str_replace( "'", ''', $url ); 
  24. $url = str_replace( ' ', '%20', $url ); 
  25.  
  26. if ( '/' === $url[0] ) { 
  27. $good_protocol_url = $url; 
  28. } else { 
  29. if ( ! is_array( $protocols ) ) 
  30. $protocols = wp_allowed_protocols(); 
  31. $good_protocol_url = wp_kses_bad_protocol( $url, $protocols ); 
  32. if ( strtolower( $good_protocol_url ) != strtolower( $url ) ) 
  33. return ''; 
  34.  
  35. return apply_filters('clean_url', $good_protocol_url, $original_url, $_context);