Skip to:
Content

BuddyPress.org

Ticket #5630: 5630.03.patch

File 5630.03.patch, 4.4 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 69a5144..bb0c049 100644
    class BP_XProfile_Field_Type_Datebox extends BP_XProfile_Field_Type { 
    16931693         * @since BuddyPress (2.0.0)
    16941694         */
    16951695        public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {}
     1696
     1697        /**
     1698         * Apply formatting specific to a Date field.
     1699         *
     1700         * @param string $field_value The date value, as saved in the database.
     1701         *        Typically, this is a MySQL-formatted date string (Y-m-d H:i:s).
     1702         * @return string
     1703         */
     1704        public static function display_filter( $field_value ) {
     1705                // If Unix timestamp
     1706                if ( is_numeric( $field_value ) ) {
     1707                        $field_value = bp_format_time( $field_value, true, false );
     1708
     1709                // If MySQL timestamp
     1710                } else {
     1711                        $field_value = bp_format_time( strtotime( $field_value ), true, false );
     1712                }
     1713
     1714                return $field_value;
     1715        }
    16961716}
    16971717
    16981718/**
    abstract class BP_XProfile_Field_Type { 
    28492869                <?php
    28502870        }
    28512871
     2872        /**
     2873         * Allow field types to modify the appearance of their values.
     2874         *
     2875         * By default, this is a pass-through method that does nothing. Only
     2876         * override in your own field type if you need to provide custom
     2877         * filtering for output values.
     2878         *
     2879         * @since BuddyPress (2.1.0)
     2880         *
     2881         * @param mixed $field_value Field value.
     2882         * @return mixed
     2883         */
     2884        public static function display_filter( $field_value ) {
     2885                return $field_value;
     2886        }
    28522887
    28532888        /**
    28542889         * 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..d230332 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( 'xprofile_get_field_data',                  'xprofile_filter_format_field_value_by_field_id', 5, 2 );
     53add_filter( 'bp_get_the_profile_field_value',           'xprofile_filter_format_field_value_by_type', 5, 2 );
    5254add_filter( 'bp_get_the_profile_field_value',           'xprofile_filter_link_profile_data',  9, 2 );
    5355
    5456add_filter( 'xprofile_data_value_before_save',          'xprofile_sanitize_data_value_before_save', 1, 2 );
    function xprofile_filter_format_field_value( $field_value, $field_type = '' ) { 
    134136        if ( !isset( $field_value ) || empty( $field_value ) )
    135137                return false;
    136138
    137         if ( 'datebox' == $field_type ) {
     139        if ( 'datebox' != $field_type ) {
     140                $field_value = str_replace(']]>', ']]&gt;', $field_value );
     141        }
    138142
    139                 // If Unix timestamp
    140                 if ( is_numeric( $field_value ) ) {
    141                         $field_value = bp_format_time( $field_value, true, false );
     143        return stripslashes( $field_value );
     144}
    142145
    143                 // If MySQL timestamp
    144                 } else {
    145                         $field_value = bp_format_time( strtotime( $field_value ), true, false );
     146/**
     147 * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched inside a bp_has_profile() loop.
     148 *
     149 * @since BuddyPress (2.1.0)
     150 *
     151 * @param mixed $field_value Field value.
     152 * @param string $field_type Field type.
     153 * @return mixed
     154 */
     155function xprofile_filter_format_field_value_by_type( $field_value, $field_type = '' ) {
     156        foreach ( bp_xprofile_get_field_types() as $type => $class ) {
     157                if ( $type !== $field_type ) {
     158                        continue;
    146159                }
    147160
    148         } else {
    149                 $field_value = str_replace(']]>', ']]&gt;', $field_value );
     161                if ( method_exists( array( $class, 'display_filter' ) ) ) {
     162                        $field_value = call_user_func( array( $class, 'display_filter' ), $field_value );
     163                }
    150164        }
    151165
    152         return stripslashes( $field_value );
     166        return $field_value;
     167}
     168
     169/**
     170 * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched by xprofile_get_field_data().
     171 *
     172 * @since BuddyPress (2.1.0)
     173 *
     174 * @param mixed $field_value
     175 * @param int $field_id
     176 */
     177function xprofile_filter_format_field_value_by_field_id( $field_value, $field_id ) {
     178        $field = new BP_XProfile_Field( $field_id );
     179        return xprofile_filter_format_field_value_by_type( $field_value, $field->type );
    153180}
    154181
    155182function xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) {