gde_validate_file

Test for valid shortcode syntax, other file errors.

Description

(string) gde_validate_file( $file, $force ); 

Returns (string)

Error message (if any)

Parameters (2)

0. $file
The file.
1. $force
The force.

Usage

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

Defined (1)

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

/functions.php  
  1. function gde_validate_file( $file = NULL, $force ) { 
  2.  
  3. //errormessages 
  4. $nofile = __('File not specified, check shortcode syntax', 'google-document-embedder'); 
  5. $badlink = __('Requested URL is invalid', 'google-document-embedder'); 
  6. $badtype = __('Unsupported File Type', 'google-document-embedder') . " (%e)"; 
  7. $unktype = __('Unable to determine file type from URL', 'google-document-embedder'); 
  8. $notfound = __('Error retrieving file - if necessary turn offerrorchecking', 'google-document-embedder') . " (%e)"; 
  9.  
  10. if ( ! $file ) { 
  11. return $nofile; 
  12.  
  13. $result = gde_valid_url( $file ); 
  14. if ( $result === false ) { 
  15. // validation skipped due to service failure 
  16. return -1; 
  17. } elseif ( $force == "1" || $force == "yes" ) { 
  18. if ( is_array( $result ) ) { 
  19. return $result; 
  20. } else { 
  21. // couldn't get file size due to service failure 
  22. return -1; 
  23. } elseif ( ! $result ) { 
  24. // can't validate 
  25. return -1; 
  26. } else { 
  27. if ( isset( $result['code'] ) && $result['code'] != 200 ) { 
  28. if ( ! gde_valid_link( $file ) ) { 
  29. return $badlink; 
  30. } else { 
  31. $err = $result['code'] . ":" . $result['message']; 
  32. $notfound = str_replace( "%e", $err, $notfound ); 
  33.  
  34. return $notfound; 
  35. } else { 
  36. if ( ! gde_valid_type( $file ) ) { 
  37. $fn = basename( $file ); 
  38. $fnp = gde_split_filename( $fn ); 
  39. $type = $fnp[1]; 
  40.  
  41. if ( $type == '' ) { 
  42. return $unktype; 
  43. $badtype = str_replace( "%e", $type, $badtype ); 
  44.  
  45. return $badtype; 
  46. } else { 
  47. return $result;