CMB2_Type_File_Base

CMB File base field type.

Defined (1)

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

/vendor/wordimpress/maps-builder-core/includes/libraries/metabox/includes/types/CMB2_Type_File_Base.php  
  1. class CMB2_Type_File_Base extends CMB2_Type_Text { 
  2.  
  3. /** 
  4. * Determines if a file has a valid image extension 
  5. * @since 1.0.0 
  6. * @param string $file File url 
  7. * @return bool Whether file has a valid image extension 
  8. */ 
  9. public function is_valid_img_ext( $file, $blah = false ) { 
  10. $file_ext = cmb2_utils()->get_file_ext( $file ); 
  11.  
  12. $valid_types = array( 'jpg', 'jpeg', 'png', 'gif', 'ico', 'icon' ); 
  13.  
  14. /** 
  15. * Which image types are considered valid image file extensions. 
  16. * @since 2.0.9 
  17. * @param array $valid_types The valid image file extensions. 
  18. */ 
  19. $is_valid_types = apply_filters( 'cmb2_valid_img_types', $valid_types ); 
  20. $is_valid = $file_ext && in_array( $file_ext, (array) $is_valid_types ); 
  21.  
  22. /** 
  23. * Filter for determining if a field value has a valid image file-type extension. 
  24. * The dynamic portion of the hook name, $field_id, refers to the field id attribute. 
  25. * @since 2.0.9 
  26. * @param bool $is_valid Whether field value has a valid image file-type extension. 
  27. * @param string $file File url. 
  28. * @param string $file_ext File extension. 
  29. */ 
  30. return (bool) apply_filters( 'cmb2_' . $this->field->id() . '_is_valid_img_ext', $is_valid, $file, $file_ext ); 
  31.  
  32. /** 
  33. * file/file_list image wrap 
  34. * @since 2.0.2 
  35. * @param array $args Array of arguments for output 
  36. * @return string Image wrap output 
  37. */ 
  38. public function img_status_output( $args ) { 
  39. return sprintf( '<%1$s class="img-status">%2$s<p class="cmb2-remove-wrapper"><a href="#" class="cmb2-remove-file-button"%3$s>%4$s</a></p>%5$s</%1$s>',  
  40. $args['tag'],  
  41. $args['image'],  
  42. isset( $args['cached_id'] ) ? ' rel="' . $args['cached_id'] . '"' : '',  
  43. esc_html( $this->_text( 'remove_image_text', __( 'Remove Image', 'cmb2' ) ) ),  
  44. isset( $args['id_input'] ) ? $args['id_input'] : '' 
  45. ); 
  46.  
  47. /** 
  48. * file/file_list file wrap 
  49. * @since 2.0.2 
  50. * @param array $args Array of arguments for output 
  51. * @return string File wrap output 
  52. */ 
  53. public function file_status_output( $args ) { 
  54. return sprintf( '<%1$s class="file-status"><span>%2$s <strong>%3$s</strong></span>   (<a href="%4$s" target="_blank" rel="external">%5$s</a> / <a href="#" class="cmb2-remove-file-button"%6$s>%7$s</a>)%8$s</%1$s>',  
  55. $args['tag'],  
  56. esc_html( $this->_text( 'file_text', __( 'File:', 'cmb2' ) ) ),  
  57. cmb2_utils()->get_file_name_from_path( $args['value'] ),  
  58. $args['value'],  
  59. esc_html( $this->_text( 'file_download_text', __( 'Download', 'cmb2' ) ) ),  
  60. isset( $args['cached_id'] ) ? ' rel="' . $args['cached_id'] . '"' : '',  
  61. esc_html( $this->_text( 'remove_text', __( 'Remove', 'cmb2' ) ) ),  
  62. isset( $args['id_input'] ) ? $args['id_input'] : '' 
  63. ); 
  64.