Skip to:
Content

BuddyPress.org

Ticket #5630: 5630.patch

File 5630.patch, 3.2 KB (added by boonebgorges, 9 years ago)
  • src/bp-xprofile/bp-xprofile-classes.php

    diff --git src/bp-xprofile/bp-xprofile-classes.php src/bp-xprofile/bp-xprofile-classes.php
    index 522bb45..2c9504c 100644
    class BP_XProfile_Field_Type_Datebox extends BP_XProfile_Field_Type { 
    16911691         * @since BuddyPress (2.0.0)
    16921692         */
    16931693        public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {}
     1694
     1695        /**
     1696         * Apply formatting specific to a Date field.
     1697         */
     1698        public function display_filter( $field_value ) {
     1699                // If Unix timestamp
     1700                if ( is_numeric( $field_value ) ) {
     1701                        $field_value = bp_format_time( $field_value, true, false );
     1702
     1703                // If MySQL timestamp
     1704                } else {
     1705                        $field_value = bp_format_time( strtotime( $field_value ), true, false );
     1706                }
     1707
     1708                return $field_value;
     1709        }
    16941710}
    16951711
    16961712/**
    abstract class BP_XProfile_Field_Type { 
    28472863                <?php
    28482864        }
    28492865
    2850 
    28512866        /**
    28522867         * Internal protected/private helper methods past this point.
    28532868         */
  • src/bp-xprofile/bp-xprofile-filters.php

    diff --git src/bp-xprofile/bp-xprofile-filters.php src/bp-xprofile/bp-xprofile-filters.php
    index c049194..f79756c 100644
    add_filter( 'xprofile_get_field_data', 'stripslashes' ); 
    4949
    5050add_filter( 'bp_get_the_profile_field_value',           'xprofile_filter_format_field_value', 1, 2 );
    5151add_filter( 'bp_get_the_site_member_profile_data',      'xprofile_filter_format_field_value', 1, 2 );
     52add_filter( 'bp_get_the_profile_field_value',           'xprofile_filter_format_field_value_by_type', 5, 2 );
    5253add_filter( 'bp_get_the_profile_field_value',           'xprofile_filter_link_profile_data',  9, 2 );
    5354
    5455add_filter( 'xprofile_data_value_before_save',          'xprofile_sanitize_data_value_before_save', 1, 2 );
    function xprofile_filter_format_field_value( $field_value, $field_type = '' ) { 
    134135        if ( !isset( $field_value ) || empty( $field_value ) )
    135136                return false;
    136137
    137         if ( 'datebox' == $field_type ) {
     138        if ( 'datebox' != $field_type ) {
     139                $field_value = str_replace(']]>', ']]&gt;', $field_value );
     140        }
    138141
    139                 // If Unix timestamp
    140                 if ( is_numeric( $field_value ) ) {
    141                         $field_value = bp_format_time( $field_value, true, false );
     142        return stripslashes( $field_value );
     143}
    142144
    143                 // If MySQL timestamp
    144                 } else {
    145                         $field_value = bp_format_time( strtotime( $field_value ), true, false );
     145/**
     146 * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes.
     147 */
     148function xprofile_filter_format_field_value_by_type( $field_value, $field_type = '' ) {
     149        foreach ( bp_xprofile_get_field_types() as $type => $class ) {
     150                if ( $type !== $field_type ) {
     151                        continue;
    146152                }
    147153
    148         } else {
    149                 $field_value = str_replace(']]>', ']]&gt;', $field_value );
     154                $class_reflection = new ReflectionClass( $class );
     155
     156                try {
     157                        $format_method = $class_reflection->getMethod( 'display_filter' );
     158                        $field_value = call_user_func( array( $format_method->class, $format_method->name ), $field_value );
     159                } catch ( Exception $e ) {
     160                        return $field_value;
     161                }
    150162        }
    151163
    152         return stripslashes( $field_value );
     164        return $field_value;
     165
    153166}
    154167
    155168function xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) {