Bxcft_Field_Type_File

The BuddyPress Xprofile Custom Fields Type Bxcft Field Type File class.

Defined (1)

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

/classes/Bxcft_Field_Type_File.php  
  1. class Bxcft_Field_Type_File extends BP_XProfile_Field_Type 
  2. public function __construct() { 
  3. parent::__construct(); 
  4.  
  5. $this->name = _x( 'File', 'xprofile field type', 'bxcft' ); 
  6.  
  7. $this->set_format( '/^.+$/', 'replace' ); 
  8. do_action( 'bp_xprofile_field_type_file', $this ); 
  9.  
  10. public function admin_field_html (array $raw_properties = array ()) 
  11. $html = $this->get_edit_field_html_elements( array_merge( 
  12. array( 'type' => 'file' ),  
  13. $raw_properties 
  14. ) ); 
  15. ?> 
  16. <input <?php echo $html; ?>> 
  17. <?php 
  18.  
  19. public function edit_field_html (array $raw_properties = array ()) 
  20. if ( isset( $raw_properties['user_id'] ) ) { 
  21. unset( $raw_properties['user_id'] ); 
  22. $html = $this->get_edit_field_html_elements( array_merge( 
  23. array( 
  24. 'type' => 'file',  
  25. ),  
  26. $raw_properties 
  27. ) ); 
  28.  
  29. $uploads = wp_upload_dir(); 
  30.  
  31. // Label. 
  32. $label = sprintf('<label for="%s">%s%s</label>',  
  33. bp_get_the_profile_field_input_name(),  
  34. bp_get_the_profile_field_name(),  
  35. (bp_get_the_profile_field_is_required()) ? 
  36. esc_html( '(required)', 'buddypress') : ''); 
  37. // Input file. 
  38. $input = sprintf('<input type="hidden" name="%1$s" id="%1$s" value="%2$s" /><input %3$s />',  
  39. bp_get_the_profile_field_input_name(),  
  40. (bp_get_the_profile_field_edit_value() != '' && bp_get_the_profile_field_edit_value() != '-') ? 
  41. bp_get_the_profile_field_edit_value() : '-',  
  42. $html); 
  43. // Actual file. 
  44. if (bp_get_the_profile_field_edit_value() != '' && bp_get_the_profile_field_edit_value() != '-') { 
  45. $actual_file = sprintf('%1$s<label for="%2$s_deletefile"><input type="checkbox" name="%2$s_deletefile" id="%2$s_deletefile" value="1" /> %3$s</label><input type="hidden" name="%2$s_hiddenfile" id="%2$s_hiddenfile" value="%4$s" />',  
  46. apply_filters('bxcft_show_download_file_link', '<a href="' . $uploads['baseurl'] . bp_get_the_profile_field_edit_value() . '" title="' . bp_get_the_profile_field_input_name() . '">' . __('Download file', 'bxcft') . '</a>', bp_get_the_profile_field_type(), bp_get_the_profile_field_id(), bp_get_the_profile_field_edit_value()),  
  47. bp_get_the_profile_field_input_name(),  
  48. __('Check this to delete this file', 'bxcft'),  
  49. bp_get_the_profile_field_edit_value()); 
  50. } elseif (bp_get_profile_field_data(array('field' => bp_get_the_profile_field_id())) != '' && 
  51. bp_get_profile_field_data(array('field' => bp_get_the_profile_field_id())) != '-') { 
  52. $actual_file = sprintf('%1$s<label for="%2$s_deletefile"><input type="checkbox" name="%2$s_deletefile" id="%2$s_deletefile" value="1" /> %3$s</label><input type="hidden" name="%2$s_hiddenfile" id="%2$s_hiddenfile" value="%4$s" />',  
  53. apply_filters('bxcft_show_download_file_link', bp_get_profile_field_data(array('field' => bp_get_the_profile_field_id())), bp_get_the_profile_field_type(), bp_get_the_profile_field_id(), bp_get_the_profile_field_edit_value()),  
  54. bp_get_the_profile_field_input_name(),  
  55. __('Check this to delete this file', 'bxcft'),  
  56. (isset($_POST['field_'.bp_get_the_profile_field_id().'_hiddenfile']))?$_POST['field_'.bp_get_the_profile_field_id().'_hiddenfile']:''); 
  57. } else { 
  58. $actual_file = ''; 
  59.  
  60. echo apply_filters( 'bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required() ); 
  61. do_action( bp_get_the_profile_field_errors_action() ); 
  62. echo apply_filters( 'bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required() ); 
  63. echo apply_filters('bxcft_field_actual_file', $actual_file, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_edit_value()); 
  64. ?> 
  65. <script type="text/javascript"> 
  66. if (jQuery('#profile-edit-form').length > 0) { 
  67. jQuery('#profile-edit-form').attr('enctype', 'multipart/form-data'); 
  68. if (jQuery('#your-profile').length > 0) { 
  69. jQuery('#your-profile').attr('enctype', 'multipart/form-data'); 
  70. <?php if (bp_get_the_profile_field_edit_value() != '' && bp_get_the_profile_field_edit_value() != '-'): ?> 
  71. jQuery('#field_<?php echo bp_get_the_profile_field_id(); ?>_deletefile').change(function() { 
  72. if (jQuery(this).is(':checked') && jQuery('input#field_<?php echo bp_get_the_profile_field_id(); ?>[type=file]').val() === '') { 
  73. jQuery('input#field_<?php echo bp_get_the_profile_field_id(); ?>[type=hidden]').val(''); 
  74. } else { 
  75. jQuery('input#field_<?php echo bp_get_the_profile_field_id(); ?>[type=hidden]').val('<?php echo bp_get_the_profile_field_edit_value(); ?>'); 
  76. }); 
  77. <?php endif; ?> 
  78. jQuery('input#field_<?php echo bp_get_the_profile_field_id(); ?>[type=file]').change(function() { 
  79. if (jQuery(this).val() !== '') { 
  80. jQuery('input#field_<?php echo bp_get_the_profile_field_id(); ?>[type=hidden]').val('-'); 
  81. } else { 
  82. jQuery('input#field_<?php echo bp_get_the_profile_field_id(); ?>[type=hidden]').val(''); 
  83. }); 
  84. </script> 
  85. <?php 
  86.  
  87. public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} 
  88.  
  89. /** 
  90. * Modify the appearance of value. No autolink feature for File type. 
  91. * @param string $value Original value of field 
  92. * @param int $field_id Id of field 
  93. * @return string Value formatted 
  94. */ 
  95. public static function display_filter($field_value, $field_id = '') { 
  96.  
  97. $new_field_value = $field_value; 
  98.  
  99. if (!empty($field_value)) { 
  100. $uploads = wp_upload_dir(); 
  101. if (strpos($field_value, $uploads['baseurl']) === false) { 
  102. $new_field_value = $uploads['baseurl'] . $field_value; 
  103. $new_field_value = sprintf('<a href="%s" rel="nofollow">%s</a>',  
  104. $new_field_value, __('Download file', 'bxcft')); 
  105.  
  106. /** 
  107. * bxcft_file_display_filter 
  108. * Use this filter to modify the appearance of File 
  109. * field value. 
  110. * @param $new_field_value Value of field 
  111. * @param $field_id Id of field. 
  112. * @return Filtered value of field. 
  113. */ 
  114. return apply_filters('bxcft_file_display_filter',  
  115. $new_field_value, $field_id);