Skip to:
Content

BuddyPress.org

Ticket #5630: 5630.02.patch

File 5630.02.patch, 3.6 KB (added by boonebgorges, 10 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..df705c5 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
     2866        /**
     2867         * Allow field types to modify the appearance of their values.
     2868         *
     2869         * By default, this is a pass-through method that does nothing. Only
     2870         * override in your own field type if you need to provide custom
     2871         * filtering for output values.
     2872         *
     2873         * @since BuddyPress (2.1.0)
     2874         *
     2875         * @param mixed $field_value Field value.
     2876         * @return mixed
     2877         */
     2878        public function display_filter( $field_value ) {
     2879                return $field_value;
     2880        }
    28502881
    28512882        /**
    28522883         * Internal protected/private helper methods past this point.
  • 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..e648b66 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 *
     148 * @since BuddyPress (2.1.0)
     149 *
     150 * @param mixed $field_value Field value.
     151 * @param string $field_type Field type.
     152 * @return mixed
     153 */
     154function xprofile_filter_format_field_value_by_type( $field_value, $field_type = '' ) {
     155        foreach ( bp_xprofile_get_field_types() as $type => $class ) {
     156                if ( $type !== $field_type ) {
     157                        continue;
    146158                }
    147159
    148         } else {
    149                 $field_value = str_replace(']]>', ']]&gt;', $field_value );
     160                if ( method_exists( array( $class, 'display_filter' ) ) ) {
     161                        $field_value = call_user_func( array( $class, 'display_filter' ), $field_value );
     162                }
    150163        }
    151164
    152         return stripslashes( $field_value );
     165        return $field_value;
    153166}
    154167
    155168function xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) {