WCML_File

The WooCommerce Multilingual WCML File class.

Defined (1)

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

/inc/currencies/currency-switcher/class-wcml-file.php  
  1. class WCML_File { 
  2. /** @var WPML_WP_API $wp_api */ 
  3. private $wp_api; 
  4.  
  5. /** 
  6. * @param WPML_WP_API|null $wp_api 
  7. */ 
  8. public function __construct( WPML_WP_API $wp_api = null ) { 
  9. if ( ! $wp_api ) { 
  10. $wp_api = new WPML_WP_API(); 
  11.  
  12. $this->wp_api = $wp_api; 
  13.  
  14. /** 
  15. * @param string $path 
  16. * @return string 
  17. */ 
  18. public function fix_dir_separator( $path ) { 
  19. $directory_separator = $this->wp_api->constant( 'DIRECTORY_SEPARATOR' ); 
  20. return ( '\\' === $directory_separator ) ? str_replace( '/', '\\', $path ) : str_replace( '\\', '/', $path ); 
  21.  
  22. /** 
  23. * @param string $path 
  24. * @return string 
  25. */ 
  26. public function get_uri_from_path( $path ) { 
  27. $base = null; 
  28.  
  29. if ( $this->wp_api->constant( 'WP_CONTENT_DIR' ) && $this->wp_api->constant( 'WP_CONTENT_URL' ) ) { 
  30. $base_path = $this->fix_dir_separator( $this->wp_api->constant( 'WP_CONTENT_DIR' ) ); 
  31.  
  32. if ( 0 === strpos( $path, $base_path ) ) { 
  33. $base = array( 
  34. 'path' => $base_path,  
  35. 'uri' => $this->wp_api->constant( 'WP_CONTENT_URL' ),  
  36. ); 
  37.  
  38. if ( ! $base ) { 
  39. $base = array( 
  40. 'path' => $this->wp_api->constant( 'ABSPATH' ),  
  41. 'uri' => site_url(),  
  42. ); 
  43.  
  44. $relative_path = substr( $path, strlen( $base['path'] ) ); 
  45. $relative_path = str_replace( array( '/', '\\' ), '/', $relative_path ); 
  46. $relative_path = ltrim( $relative_path, '/' ); 
  47. return trailingslashit( $base['uri'] ) . $relative_path;