gde_get_short_url

Shorten ("mask") the URL to the embedded file.

Description

(string) gde_get_short_url( $u ); 

Returns (string)

Short url response from API call, or false on error

Parameters (1)

0. $u
The u.

Usage

  1. if ( !function_exists( 'gde_get_short_url' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-doc-embedder/functions.php'; 
  3.  
  4. // The u. 
  5. $u = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = gde_get_short_url($u); 
  9.  

Defined (1)

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

/functions.php  
  1. function gde_get_short_url( $u ) { 
  2. return $u; //bypass this function - breaks in current viewer 
  3.  
  4. $u = urlencode( $u ); 
  5. $service[] = "http://tinyurl.com/api-create.php?url=" . $u; 
  6. $service[] = "http://is.gd/create.php?format=simple&url=" . $u; 
  7.  
  8. foreach ( $service as $url ) { 
  9. $passed = false; 
  10. $response = wp_remote_get( $url ); 
  11. if ( is_wp_error( $response ) || empty ( $response['body'] ) ) { 
  12. continue; 
  13. } else { 
  14. // check for rate limit exceeded or othererrorresponse 
  15. if ( ! gde_valid_link( $response['body'] ) ) { 
  16. continue; 
  17. } else { 
  18. $passed = true; 
  19. break; 
  20.  
  21. if ( $passed ) { 
  22. return $response['body']; 
  23. } else { 
  24. // can't shorten - return original URL 
  25. gde_dx_log("Shorten URL failed: " . urldecode( $u )); 
  26. return urldecode( $u );