Skip to:
Content

BuddyPress.org

Changeset 8632


Ignore:
Timestamp:
07/16/2014 10:33:58 PM (12 years ago)
Author:
johnjamesjacoby
Message:

Introduce URL field type:

  • New field class extending BP_XProfile_Field_Type for URLs
  • Clean-up existing BP_XProfile_Field_Type extensions (formatting, bp_parse_args() VS array_merge(), whitespace, brackets, etc...)
  • More to do here, specifically regarding output and display_filter() methodology.

Props boonebgorges, williamsba1, sooskriszta. See #5501, #5630.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-classes.php

    r8554 r8632  
    487487                                                        <div id="titlediv">
    488488                                                                <div id="titlewrap">
    489                                                                         <label class="screen-reader-text" id="title-prompt-text" for=​"title">​<?php _e( 'Field Group Title', 'buddypress') ?></label>
    490                                                                         <input type="text" name="group_name" id="title" value="<?php echo esc_attr( $this->name ); ?>" placeholder="<?php esc_attr_e( 'Field Group Title', 'buddypress' ); ?>" />
     489                                                                        <label class="screen-reader-text" id="title-prompt-text" for="title"><?php esc_html_e( 'Field Group Title', 'buddypress') ?></label>
     490                                                                        <input type="text" name="group_name" autocomplete="off" id="title" value="<?php echo esc_attr( $this->name ); ?>" />
    491491                                                                </div>
    492492                                                        </div>
     
    14561456}
    14571457
     1458/** Field Types ***************************************************************/
     1459
    14581460/**
    14591461 * Datebox xprofile field type.
     
    14741476                $this->name     = _x( 'Date Selector', 'xprofile field type', 'buddypress' );
    14751477
    1476                 $this->set_format( '/^\d{4}-\d{1,2}-\d{1,2} 00:00:00$/', 'replace' );  // "Y-m-d 00:00:00"
     1478                $this->set_format( '/^\d{4}-\d{1,2}-\d{1,2} 00:00:00$/', 'replace' ); // "Y-m-d 00:00:00"
     1479
    14771480                do_action( 'bp_xprofile_field_type_datebox', $this );
    14781481        }
     
    14871490         */
    14881491        public function edit_field_html( array $raw_properties = array() ) {
    1489                 $user_id = bp_displayed_user_id();
    1490 
    1491                 // user_id is a special optional parameter that we pass to {@link bp_the_profile_field_options()}.
     1492
     1493                // user_id is a special optional parameter that we pass to
     1494                // {@link bp_the_profile_field_options()}.
    14921495                if ( isset( $raw_properties['user_id'] ) ) {
    14931496                        $user_id = (int) $raw_properties['user_id'];
    14941497                        unset( $raw_properties['user_id'] );
    1495                 }
    1496 
    1497                 $day_html = $this->get_edit_field_html_elements( array_merge(
    1498                         array(
    1499                                 'id'   => bp_get_the_profile_field_input_name() . '_day',
    1500                                 'name' => bp_get_the_profile_field_input_name() . '_day',
    1501                         ),
    1502                         $raw_properties
     1498                } else {
     1499                        $user_id = bp_displayed_user_id();
     1500                }
     1501
     1502                $day_r = bp_parse_args( $raw_properties, array(
     1503                        'id'   => bp_get_the_profile_field_input_name() . '_day',
     1504                        'name' => bp_get_the_profile_field_input_name() . '_day'
    15031505                ) );
    15041506
    1505                 $month_html = $this->get_edit_field_html_elements( array_merge(
    1506                         array(
    1507                                 'id'   => bp_get_the_profile_field_input_name() . '_month',
    1508                                 'name' => bp_get_the_profile_field_input_name() . '_month',
    1509                         ),
    1510                         $raw_properties
     1507                $month_r = bp_parse_args( $raw_properties, array(
     1508                        'id'   => bp_get_the_profile_field_input_name() . '_month',
     1509                        'name' => bp_get_the_profile_field_input_name() . '_month'
    15111510                ) );
    15121511
    1513                 $year_html = $this->get_edit_field_html_elements( array_merge(
    1514                         array(
    1515                                 'id'   => bp_get_the_profile_field_input_name() . '_year',
    1516                                 'name' => bp_get_the_profile_field_input_name() . '_year',
    1517                         ),
    1518                         $raw_properties
    1519                 ) );
    1520         ?>
     1512                $year_r = bp_parse_args( $raw_properties, array(
     1513                        'id'   => bp_get_the_profile_field_input_name() . '_year',
     1514                        'name' => bp_get_the_profile_field_input_name() . '_year'
     1515                ) ); ?>
     1516
    15211517                <div class="datebox">
    15221518
     
    15241520                        <?php do_action( bp_get_the_profile_field_errors_action() ); ?>
    15251521
    1526                         <select <?php echo $day_html; ?>>
    1527                                 <?php bp_the_profile_field_options( array( 'type' => 'day', 'user_id' => $user_id ) ); ?>
     1522                        <select <?php echo $this->get_edit_field_html_elements( $day_r ); ?>>
     1523                                <?php bp_the_profile_field_options( array(
     1524                                        'type'    => 'day',
     1525                                        'user_id' => $user_id
     1526                                ) ); ?>
    15281527                        </select>
    15291528
    1530                         <select <?php echo $month_html; ?>>
    1531                                 <?php bp_the_profile_field_options( array( 'type' => 'month', 'user_id' => $user_id ) ); ?>
     1529                        <select <?php echo $this->get_edit_field_html_elements( $month_r ); ?>>
     1530                                <?php bp_the_profile_field_options( array(
     1531                                        'type'    => 'month',
     1532                                        'user_id' => $user_id
     1533                                ) ); ?>
    15321534                        </select>
    15331535
    1534                         <select <?php echo $year_html; ?>>
    1535                                 <?php bp_the_profile_field_options( array( 'type' => 'year', 'user_id' => $user_id ) ); ?>
     1536                        <select <?php echo $this->get_edit_field_html_elements( $year_r ); ?>>
     1537                                <?php bp_the_profile_field_options( array(
     1538                                        'type'    => 'year',
     1539                                        'user_id' => $user_id
     1540                                ) ); ?>
    15361541                        </select>
    15371542
     
    15551560         */
    15561561        public function edit_field_options_html( array $args = array() ) {
    1557                 $options = $this->field_obj->get_children();
    1558                 $date    = BP_XProfile_ProfileData::get_value_byid( $this->field_obj->id, $args['user_id'] );
    1559 
     1562
     1563                $date  = BP_XProfile_ProfileData::get_value_byid( $this->field_obj->id, $args['user_id'] );
    15601564                $day   = 0;
    15611565                $month = 0;
     
    15801584                }
    15811585
    1582                 // Check for updated posted values, and errors preventing them from being saved first time.
     1586                // Check for updated posted values, and errors preventing them from
     1587                // being saved first time.
    15831588                if ( ! empty( $_POST['field_' . $this->field_obj->id . '_day'] ) ) {
    15841589                        $new_day = (int) $_POST['field_' . $this->field_obj->id . '_day'];
     
    16101615
    16111616                                $months = array(
    1612                                         __( 'January', 'buddypress' ),
    1613                                         __( 'February', 'buddypress' ),
    1614                                         __( 'March', 'buddypress' ),
    1615                                         __( 'April', 'buddypress' ),
    1616                                         __( 'May', 'buddypress' ),
    1617                                         __( 'June', 'buddypress' ),
    1618                                         __( 'July', 'buddypress' ),
    1619                                         __( 'August', 'buddypress' ),
     1617                                        __( 'January',   'buddypress' ),
     1618                                        __( 'February',  'buddypress' ),
     1619                                        __( 'March',     'buddypress' ),
     1620                                        __( 'April',     'buddypress' ),
     1621                                        __( 'May',       'buddypress' ),
     1622                                        __( 'June',      'buddypress' ),
     1623                                        __( 'July',      'buddypress' ),
     1624                                        __( 'August',    'buddypress' ),
    16201625                                        __( 'September', 'buddypress' ),
    1621                                         __( 'October', 'buddypress' ),
    1622                                         __( 'November', 'buddypress' ),
    1623                                         __( 'December', 'buddypress' )
     1626                                        __( 'October',   'buddypress' ),
     1627                                        __( 'November',  'buddypress' ),
     1628                                        __( 'December',  'buddypress' )
    16241629                                );
    16251630
     
    16521657         */
    16531658        public function admin_field_html( array $raw_properties = array() ) {
    1654                 $day_html = $this->get_edit_field_html_elements( array_merge(
    1655                         array(
    1656                                 'id'   => bp_get_the_profile_field_input_name() . '_day',
    1657                                 'name' => bp_get_the_profile_field_input_name() . '_day',
    1658                         ),
    1659                         $raw_properties
     1659
     1660                $day_r = bp_parse_args( $raw_properties, array(
     1661                        'id'   => bp_get_the_profile_field_input_name() . '_day',
     1662                        'name' => bp_get_the_profile_field_input_name() . '_day'
    16601663                ) );
    16611664
    1662                 $month_html = $this->get_edit_field_html_elements( array_merge(
    1663                         array(
    1664                                 'id'   => bp_get_the_profile_field_input_name() . '_month',
    1665                                 'name' => bp_get_the_profile_field_input_name() . '_month',
    1666                         ),
    1667                         $raw_properties
     1665                $month_r = bp_parse_args( $raw_properties, array(
     1666                        'id'   => bp_get_the_profile_field_input_name() . '_month',
     1667                        'name' => bp_get_the_profile_field_input_name() . '_month'
    16681668                ) );
    16691669
    1670                 $year_html = $this->get_edit_field_html_elements( array_merge(
    1671                         array(
    1672                                 'id'   => bp_get_the_profile_field_input_name() . '_year',
    1673                                 'name' => bp_get_the_profile_field_input_name() . '_year',
    1674                         ),
    1675                         $raw_properties
    1676                 ) );
    1677         ?>
    1678                 <select <?php echo $day_html; ?>>
    1679                         <?php bp_the_profile_field_options( 'type=day' ); ?>
     1670                $year_r = bp_parse_args( $raw_properties, array(
     1671                        'id'   => bp_get_the_profile_field_input_name() . '_year',
     1672                        'name' => bp_get_the_profile_field_input_name() . '_year'
     1673                ) ); ?>
     1674
     1675                <select <?php echo $this->get_edit_field_html_elements( $day_r ); ?>>
     1676                        <?php bp_the_profile_field_options( array( 'type' => 'day' ) ); ?>
    16801677                </select>
    16811678
    1682                 <select <?php echo $month_html; ?>>
    1683                         <?php bp_the_profile_field_options( 'type=month' ); ?>
     1679                <select <?php echo $this->get_edit_field_html_elements( $month_r ); ?>>
     1680                        <?php bp_the_profile_field_options( array( 'type' => 'month' ) ); ?>
    16841681                </select>
    16851682
    1686                 <select <?php echo $year_html; ?>>
    1687                         <?php bp_the_profile_field_options( 'type=year' ); ?>
     1683                <select <?php echo $this->get_edit_field_html_elements( $year_r ); ?>>
     1684                        <?php bp_the_profile_field_options( array( 'type' => 'year' ) ); ?>
    16881685                </select>
     1686
    16891687        <?php
    16901688        }
     
    17101708         */
    17111709        public static function display_filter( $field_value ) {
     1710
    17121711                // If Unix timestamp
    1713                 if ( is_numeric( $field_value ) ) {
    1714                         $field_value = bp_format_time( $field_value, true, false );
    1715 
    1716                 // If MySQL timestamp
    1717                 } else {
    1718                         $field_value = bp_format_time( strtotime( $field_value ), true, false );
    1719                 }
    1720 
    1721                 return $field_value;
     1712                if ( ! is_numeric( $field_value ) ) {
     1713                        $field_value = strtotime( $field_value );
     1714                }
     1715
     1716                return bp_format_time( $field_value, true, false );
    17221717        }
    17231718}
     
    17581753         */
    17591754        public function edit_field_html( array $raw_properties = array() ) {
    1760                 $user_id = bp_displayed_user_id();
    1761 
    1762                 // user_id is a special optional parameter that we pass to {@link bp_the_profile_field_options()}.
     1755
     1756                // user_id is a special optional parameter that we pass to
     1757                // {@link bp_the_profile_field_options()}.
    17631758                if ( isset( $raw_properties['user_id'] ) ) {
    17641759                        $user_id = (int) $raw_properties['user_id'];
    17651760                        unset( $raw_properties['user_id'] );
    1766                 }
    1767         ?>
     1761                } else {
     1762                        $user_id = bp_displayed_user_id();
     1763                } ?>
     1764
    17681765                <div class="checkbox">
    1769 
    1770                         <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php esc_html_e( '(required)', 'buddypress' ); ?><?php endif; ?></label>
     1766                        <label for="<?php bp_the_profile_field_input_name(); ?>">
     1767                                <?php bp_the_profile_field_name(); ?>
     1768                                <?php if ( bp_get_the_profile_field_is_required() ) : ?>
     1769                                        <?php esc_html_e( '(required)', 'buddypress' ); ?>
     1770                                <?php endif; ?>
     1771                        </label>
     1772
    17711773                        <?php do_action( bp_get_the_profile_field_errors_action() ); ?>
    1772                         <?php bp_the_profile_field_options( "user_id={$user_id}" ); ?>
     1774
     1775                        <?php bp_the_profile_field_options( array(
     1776                                'user_id' => $user_id
     1777                        ) ); ?>
    17731778
    17741779                </div>
     1780
    17751781                <?php
    17761782        }
     
    17971803                $html = '';
    17981804
    1799                 // Check for updated posted values, but errors preventing them from being saved first time
     1805                // Check for updated posted values, but errors preventing them from
     1806                // being saved first time
    18001807                if ( isset( $_POST['field_' . $this->field_obj->id] ) && $option_values != maybe_serialize( $_POST['field_' . $this->field_obj->id] ) ) {
    18011808                        if ( ! empty( $_POST['field_' . $this->field_obj->id] ) ) {
     
    18101817                        for ( $j = 0, $count_values = count( $option_values ); $j < $count_values; ++$j ) {
    18111818
    1812                                 // Run the allowed option name through the before_save filter, so we'll be sure to get a match
     1819                                // Run the allowed option name through the before_save filter,
     1820                                // so we'll be sure to get a match
    18131821                                $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
    18141822
     
    18191827                        }
    18201828
    1821                         // If the user has not yet supplied a value for this field, check to see whether there is a default value available
     1829                        // If the user has not yet supplied a value for this field, check to
     1830                        // see whether there is a default value available
    18221831                        if ( ! is_array( $option_values ) && empty( $option_values ) && empty( $selected ) && ! empty( $options[$k]->is_default_option ) ) {
    18231832                                $selected = ' checked="checked"';
     
    18961905         */
    18971906        public function edit_field_html( array $raw_properties = array() ) {
    1898                 $user_id = bp_displayed_user_id();
    1899 
    1900                 // user_id is a special optional parameter that we pass to {@link bp_the_profile_field_options()}.
     1907
     1908                // user_id is a special optional parameter that we pass to
     1909                // {@link bp_the_profile_field_options()}.
    19011910                if ( isset( $raw_properties['user_id'] ) ) {
    19021911                        $user_id = (int) $raw_properties['user_id'];
    19031912                        unset( $raw_properties['user_id'] );
    1904                 }
    1905         ?>
     1913                } else {
     1914                        $user_id = bp_displayed_user_id();
     1915                } ?>
     1916
    19061917                <div class="radio">
    19071918
    1908                         <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php esc_html_e( '(required)', 'buddypress' ); ?><?php endif; ?></label>
     1919                        <label for="<?php bp_the_profile_field_input_name(); ?>">
     1920                                <?php bp_the_profile_field_name(); ?>
     1921                                <?php if ( bp_get_the_profile_field_is_required() ) : ?>
     1922                                        <?php esc_html_e( '(required)', 'buddypress' ); ?>
     1923                                <?php endif; ?>
     1924                        </label>
     1925
    19091926                        <?php do_action( bp_get_the_profile_field_errors_action() ); ?>
    1910                         <?php bp_the_profile_field_options( "user_id={$user_id}" );
     1927
     1928                        <?php bp_the_profile_field_options( array( 'user_id' => $user_id ) );
    19111929
    19121930                        if ( ! bp_get_the_profile_field_is_required() ) : ?>
    1913                                 <a class="clear-value" href="javascript:clear( '<?php echo esc_js( bp_get_the_profile_field_input_name() ); ?>' );"><?php esc_html_e( 'Clear', 'buddypress' ); ?></a>
     1931
     1932                                <a class="clear-value" href="javascript:clear( '<?php echo esc_js( bp_get_the_profile_field_input_name() ); ?>' );">
     1933                                        <?php esc_html_e( 'Clear', 'buddypress' ); ?>
     1934                                </a>
     1935
    19141936                        <?php endif; ?>
    19151937
    19161938                </div>
     1939
    19171940                <?php
    19181941        }
     
    19401963                for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) {
    19411964
    1942                         // Check for updated posted values, but errors preventing them from being saved first time
     1965                        // Check for updated posted values, but errors preventing them from
     1966                        // being saved first time
    19431967                        if ( isset( $_POST['field_' . $this->field_obj->id] ) && $option_value != $_POST['field_' . $this->field_obj->id] ) {
    19441968                                if ( ! empty( $_POST['field_' . $this->field_obj->id] ) ) {
     
    19471971                        }
    19481972
    1949                         // Run the allowed option name through the before_save filter, so we'll be sure to get a match
     1973                        // Run the allowed option name through the before_save filter, so
     1974                        // we'll be sure to get a match
    19501975                        $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
    19511976                        $selected        = '';
     
    19792004                bp_the_profile_field_options();
    19802005
    1981                 if ( ! bp_get_the_profile_field_is_required() ) : ?>
    1982                         <a class="clear-value" href="javascript:clear( '<?php echo esc_js( bp_get_the_profile_field_input_name() ); ?>' );"><?php esc_html_e( 'Clear', 'buddypress' ); ?></a>
    1983                 <?php endif; ?>
    1984         <?php
     2006                if ( bp_get_the_profile_field_is_required() ) {
     2007                        return;
     2008                } ?>
     2009
     2010                <a class="clear-value" href="javascript:clear( '<?php echo esc_js( bp_get_the_profile_field_input_name() ); ?>' );">
     2011                        <?php esc_html_e( 'Clear', 'buddypress' ); ?>
     2012                </a>
     2013
     2014                <?php
    19852015        }
    19862016
     
    20342064         */
    20352065        public function edit_field_html( array $raw_properties = array() ) {
    2036                 $user_id = bp_displayed_user_id();
    2037 
    2038                 // user_id is a special optional parameter that we pass to {@link bp_the_profile_field_options()}.
     2066
     2067                // user_id is a special optional parameter that we pass to
     2068                // {@link bp_the_profile_field_options()}.
    20392069                if ( isset( $raw_properties['user_id'] ) ) {
    20402070                        $user_id = (int) $raw_properties['user_id'];
    20412071                        unset( $raw_properties['user_id'] );
    2042                 }
    2043 
    2044                 $html = $this->get_edit_field_html_elements( array_merge(
    2045                         array(
    2046                                 'multiple' => 'multiple',
    2047                                 'id'       => bp_get_the_profile_field_input_name() . '[]',
    2048                                 'name'     => bp_get_the_profile_field_input_name() . '[]',
    2049                         ),
    2050                         $raw_properties
    2051                 ) );
    2052         ?>
     2072                } else {
     2073                        $user_id = bp_displayed_user_id();
     2074                }
     2075
     2076                $r = bp_parse_args( $raw_properties, array(
     2077                        'multiple' => 'multiple',
     2078                        'id'       => bp_get_the_profile_field_input_name() . '[]',
     2079                        'name'     => bp_get_the_profile_field_input_name() . '[]',
     2080                ) ); ?>
     2081
    20532082                <label for="<?php bp_the_profile_field_input_name(); ?>[]"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></label>
     2083
    20542084                <?php do_action( bp_get_the_profile_field_errors_action() ); ?>
    2055                 <select <?php echo $html; ?>>
    2056                         <?php bp_the_profile_field_options( "user_id={$user_id}" ); ?>
     2085
     2086                <select <?php echo $this->get_edit_field_html_elements( $r ); ?>>
     2087                        <?php bp_the_profile_field_options( array(
     2088                                'user_id' => $user_id
     2089                        ) ); ?>
    20572090                </select>
    20582091
    20592092                <?php if ( ! bp_get_the_profile_field_is_required() ) : ?>
    2060                         <a class="clear-value" href="javascript:clear( '<?php echo esc_js( bp_get_the_profile_field_input_name() ); ?>[]' );"><?php esc_html_e( 'Clear', 'buddypress' ); ?></a>
     2093
     2094                        <a class="clear-value" href="javascript:clear( '<?php echo esc_js( bp_get_the_profile_field_input_name() ); ?>[]' );">
     2095                                <?php esc_html_e( 'Clear', 'buddypress' ); ?>
     2096                        </a>
     2097
    20612098                <?php endif; ?>
    20622099        <?php
     
    20912128                        $selected = '';
    20922129
    2093                         // Check for updated posted values, but errors preventing them from being saved first time
     2130                        // Check for updated posted values, but errors preventing them from
     2131                        // being saved first time
    20942132                        foreach( $option_values as $i => $option_value ) {
    20952133                                if ( isset( $_POST['field_' . $this->field_obj->id] ) && $_POST['field_' . $this->field_obj->id][$i] != $option_value ) {
     
    21002138                        }
    21012139
    2102                         // Run the allowed option name through the before_save filter, so we'll be sure to get a match
     2140                        // Run the allowed option name through the before_save filter, so
     2141                        // we'll be sure to get a match
    21032142                        $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
    21042143
     
    21282167         */
    21292168        public function admin_field_html( array $raw_properties = array() ) {
    2130                 $html = $this->get_edit_field_html_elements( array_merge(
    2131                         array( 'multiple' => 'multiple' ),
    2132                         $raw_properties
    2133                 ) );
    2134         ?>
    2135                 <select <?php echo $html; ?>>
     2169                $r = bp_parse_args( $raw_properties, array(
     2170                        'multiple' => 'multiple'
     2171                ) ); ?>
     2172
     2173                <select <?php echo $this->get_edit_field_html_elements( $r ); ?>>
    21362174                        <?php bp_the_profile_field_options(); ?>
    21372175                </select>
    2138         <?php
     2176
     2177                <?php
    21392178        }
    21402179
     
    21862225         */
    21872226        public function edit_field_html( array $raw_properties = array() ) {
    2188                 $user_id = bp_displayed_user_id();
    2189 
    2190                 // user_id is a special optional parameter that we pass to {@link bp_the_profile_field_options()}.
     2227
     2228                // user_id is a special optional parameter that we pass to
     2229                // {@link bp_the_profile_field_options()}.
    21912230                if ( isset( $raw_properties['user_id'] ) ) {
    21922231                        $user_id = (int) $raw_properties['user_id'];
    21932232                        unset( $raw_properties['user_id'] );
    2194                 }
    2195 
    2196                 $html = $this->get_edit_field_html_elements( $raw_properties );
    2197         ?>
    2198                 <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php esc_html_e( '(required)', 'buddypress' ); ?><?php endif; ?></label>
     2233                } else {
     2234                        $user_id = bp_displayed_user_id();
     2235                } ?>
     2236
     2237                <label for="<?php bp_the_profile_field_input_name(); ?>">
     2238                        <?php bp_the_profile_field_name(); ?>
     2239                        <?php if ( bp_get_the_profile_field_is_required() ) : ?>
     2240                                <?php esc_html_e( '(required)', 'buddypress' ); ?>
     2241                        <?php endif; ?>
     2242                </label>
     2243
    21992244                <?php do_action( bp_get_the_profile_field_errors_action() ); ?>
    2200                 <select <?php echo $html; ?>>
    2201                         <?php bp_the_profile_field_options( "user_id={$user_id}" ); ?>
     2245
     2246                <select <?php echo $this->get_edit_field_html_elements( $raw_properties ); ?>>
     2247                        <?php bp_the_profile_field_options( array( 'user_id' => $user_id ) ); ?>
    22022248                </select>
    2203         <?php
     2249
     2250                <?php
    22042251        }
    22052252
     
    22222269
    22232270                $options = $this->field_obj->get_children();
    2224                 $html     = '<option value="">' . /* translators: no option picked in select box */ esc_html__( '----', 'buddypress' ) . '</option>';
     2271                $html    = '<option value="">' . /* translators: no option picked in select box */ esc_html__( '----', 'buddypress' ) . '</option>';
    22252272
    22262273                if ( empty( $original_option_values ) && !empty( $_POST['field_' . $this->field_obj->id] ) ) {
     
    22322279                        $selected = '';
    22332280
    2234                         // Check for updated posted values, but errors preventing them from being saved first time
     2281                        // Check for updated posted values, but errors preventing them from
     2282                        // being saved first time
    22352283                        foreach( $option_values as $i => $option_value ) {
    22362284                                if ( isset( $_POST['field_' . $this->field_obj->id] ) && $_POST['field_' . $this->field_obj->id] != $option_value ) {
     
    22412289                        }
    22422290
    2243                         // Run the allowed option name through the before_save filter, so we'll be sure to get a match
     2291                        // Run the allowed option name through the before_save filter, so
     2292                        // we'll be sure to get a match
    22442293                        $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
    22452294
     
    22692318         */
    22702319        public function admin_field_html( array $raw_properties = array() ) {
    2271                 $html = $this->get_edit_field_html_elements( $raw_properties );
    2272         ?>
    2273                 <select <?php echo $html; ?>>
     2320                ?>
     2321
     2322                <select <?php echo $this->get_edit_field_html_elements( $raw_properties ); ?>>
    22742323                        <?php bp_the_profile_field_options(); ?>
    22752324                </select>
    2276         <?php
     2325
     2326                <?php
    22772327        }
    22782328
     
    23232373        public function edit_field_html( array $raw_properties = array() ) {
    23242374
    2325                 // user_id is a special optional parameter that certain other fields types pass to {@link bp_the_profile_field_options()}.
     2375                // user_id is a special optional parameter that certain other fields
     2376                // types pass to {@link bp_the_profile_field_options()}.
    23262377                if ( isset( $raw_properties['user_id'] ) ) {
    23272378                        unset( $raw_properties['user_id'] );
    23282379                }
    23292380
    2330                 $html = $this->get_edit_field_html_elements( array_merge(
    2331                         array(
    2332                                 'cols' => 40,
    2333                                 'rows' => 5,
    2334                         ),
    2335                         $raw_properties
    2336                 ) );
    2337         ?>
    2338                 <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php esc_html_e( '(required)', 'buddypress' ); ?><?php endif; ?></label>
     2381                $r = bp_parse_args( $raw_properties, array(
     2382                        'cols' => 40,
     2383                        'rows' => 5,
     2384                ) ); ?>
     2385
     2386                <label for="<?php bp_the_profile_field_input_name(); ?>">
     2387                        <?php bp_the_profile_field_name(); ?>
     2388                        <?php if ( bp_get_the_profile_field_is_required() ) : ?>
     2389                                <?php esc_html_e( '(required)', 'buddypress' ); ?>
     2390                        <?php endif; ?>
     2391                </label>
     2392
    23392393                <?php do_action( bp_get_the_profile_field_errors_action() ); ?>
    2340                 <textarea <?php echo $html; ?>><?php bp_the_profile_field_edit_value(); ?></textarea>
    2341         <?php
     2394
     2395                <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>>
     2396                        <?php bp_the_profile_field_edit_value(); ?>
     2397                </textarea>
     2398
     2399                <?php
    23422400        }
    23432401
     
    23512409         */
    23522410        public function admin_field_html( array $raw_properties = array() ) {
    2353                 $html = $this->get_edit_field_html_elements( array_merge(
    2354                         array(
    2355                                 'cols' => 40,
    2356                                 'rows' => 5,
    2357                         ),
    2358                         $raw_properties
    2359                 ) );
    2360         ?>
    2361                 <textarea <?php echo $html; ?>></textarea>
    2362         <?php
     2411                $r = bp_parse_args( $raw_properties, array(
     2412                        'cols' => 40,
     2413                        'rows' => 5,
     2414                ) ); ?>
     2415
     2416                <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>></textarea>
     2417
     2418                <?php
    23632419        }
    23642420
     
    24062462        public function edit_field_html( array $raw_properties = array() ) {
    24072463
    2408                 // user_id is a special optional parameter that certain other fields types pass to {@link bp_the_profile_field_options()}.
     2464                // user_id is a special optional parameter that certain other fields
     2465                // types pass to {@link bp_the_profile_field_options()}.
    24092466                if ( isset( $raw_properties['user_id'] ) ) {
    24102467                        unset( $raw_properties['user_id'] );
    24112468                }
    24122469
    2413                 $html = $this->get_edit_field_html_elements( array_merge(
    2414                         array(
    2415                                 'type'  => 'text',
    2416                                 'value' => bp_get_the_profile_field_edit_value(),
    2417                         ),
    2418                         $raw_properties
    2419                 ) );
    2420         ?>
    2421                 <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php esc_html_e( '(required)', 'buddypress' ); ?><?php endif; ?></label>
     2470                $r = bp_parse_args( $raw_properties, array(
     2471                        'type'  => 'text',
     2472                        'value' => bp_get_the_profile_field_edit_value(),
     2473                ) ); ?>
     2474
     2475                <label for="<?php bp_the_profile_field_input_name(); ?>">
     2476                        <?php bp_the_profile_field_name(); ?>
     2477                        <?php if ( bp_get_the_profile_field_is_required() ) : ?>
     2478                                <?php esc_html_e( '(required)', 'buddypress' ); ?>
     2479                        <?php endif; ?>
     2480                </label>
     2481
    24222482                <?php do_action( bp_get_the_profile_field_errors_action() ); ?>
    2423                 <input <?php echo $html; ?>>
    2424         <?php
     2483
     2484                <input <?php echo $this->get_edit_field_html_elements( $r ); ?>>
     2485
     2486                <?php
    24252487        }
    24262488
     
    24342496         */
    24352497        public function admin_field_html( array $raw_properties = array() ) {
    2436                 $html = $this->get_edit_field_html_elements( array_merge(
    2437                         array( 'type' => 'text' ),
    2438                         $raw_properties
    2439                 ) );
    2440         ?>
    2441                 <input <?php echo $html; ?>>
    2442         <?php
     2498
     2499                $r = bp_parse_args( $raw_properties, array(
     2500                        'type' => 'text'
     2501                ) ); ?>
     2502
     2503                <input <?php echo $this->get_edit_field_html_elements( $r ); ?>>
     2504
     2505                <?php
    24432506        }
    24442507
     
    24862549        public function edit_field_html( array $raw_properties = array() ) {
    24872550
    2488                 // user_id is a special optional parameter that certain other fields types pass to {@link bp_the_profile_field_options()}.
     2551                // user_id is a special optional parameter that certain other fields
     2552                // types pass to {@link bp_the_profile_field_options()}.
    24892553                if ( isset( $raw_properties['user_id'] ) ) {
    24902554                        unset( $raw_properties['user_id'] );
    24912555                }
    24922556
    2493                 $html = $this->get_edit_field_html_elements( array_merge(
    2494                         array(
    2495                                 'type'  => 'number',
    2496                                 'value' =>  bp_get_the_profile_field_edit_value(),
    2497                         ),
    2498                         $raw_properties
    2499                 ) );
    2500         ?>
    2501                 <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php esc_html_e( '(required)', 'buddypress' ); ?><?php endif; ?></label>
     2557                $r = bp_parse_args( $raw_properties, array(
     2558                        'type'  => 'number',
     2559                        'value' =>  bp_get_the_profile_field_edit_value()
     2560                ) ); ?>
     2561
     2562                <label for="<?php bp_the_profile_field_input_name(); ?>">
     2563                        <?php bp_the_profile_field_name(); ?>
     2564                        <?php if ( bp_get_the_profile_field_is_required() ) : ?>
     2565                                <?php esc_html_e( '(required)', 'buddypress' ); ?>
     2566                        <?php endif; ?>
     2567                </label>
     2568
    25022569                <?php do_action( bp_get_the_profile_field_errors_action() ); ?>
    2503                 <input <?php echo $html; ?>>
    2504         <?php
     2570
     2571                <input <?php echo $this->get_edit_field_html_elements( $r ); ?>>
     2572
     2573                <?php
    25052574        }
    25062575
     
    25142583         */
    25152584        public function admin_field_html( array $raw_properties = array() ) {
    2516                 $html = $this->get_edit_field_html_elements( array_merge(
    2517                         array( 'type' => 'number' ),
    2518                         $raw_properties
    2519                 ) );
    2520         ?>
    2521                 <input <?php echo $html; ?>>
     2585                $r = bp_parse_args( $raw_properties, array(
     2586                        'type' => 'number'
     2587                ) ); ?>
     2588
     2589                <input <?php echo $this->get_edit_field_html_elements( $r ); ?>>
    25222590        <?php
    25232591        }
     
    25322600         */
    25332601        public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {}
     2602}
     2603
     2604/**
     2605 * URL xprofile field type.
     2606 *
     2607 * @since BuddyPress (2.1.0)
     2608 */
     2609class BP_XProfile_Field_Type_URL extends BP_XProfile_Field_Type {
     2610
     2611        /**
     2612         * Constructor for the URL field type
     2613         *
     2614         * @since BuddyPress (2.1.0)
     2615         */
     2616        public function __construct() {
     2617                parent::__construct();
     2618
     2619                $this->category = _x( 'Single Fields', 'xprofile field type category', 'buddypress' );
     2620                $this->name     = _x( 'URL', 'xprofile field type', 'buddypress' );
     2621
     2622                $this->set_format( '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS', 'replace' );
     2623
     2624                do_action( 'bp_xprofile_field_type_url', $this );
     2625        }
     2626
     2627        /**
     2628         * Output the edit field HTML for this field type.
     2629         *
     2630         * Must be used inside the {@link bp_profile_fields()} template loop.
     2631         *
     2632         * @param array $raw_properties Optional key/value array of
     2633         *        {@link http://dev.w3.org/html5/markup/input.number.html permitted attributes}
     2634         *        that you want to add.
     2635         * @since BuddyPress (2.1.0)
     2636         */
     2637        public function edit_field_html( array $raw_properties = array() ) {
     2638
     2639                // `user_id` is a special optional parameter that certain other
     2640                // fields types pass to {@link bp_the_profile_field_options()}.
     2641                if ( isset( $raw_properties['user_id'] ) ) {
     2642                        unset( $raw_properties['user_id'] );
     2643                }
     2644
     2645                $r = bp_parse_args( $raw_properties, array(
     2646                        'type'  => 'url',
     2647                        'value' =>  esc_url( bp_get_the_profile_field_edit_value() ),
     2648                ) ); ?>
     2649
     2650                <label for="<?php bp_the_profile_field_input_name(); ?>">
     2651                        <?php bp_the_profile_field_name(); ?>
     2652                        <?php if ( bp_get_the_profile_field_is_required() ) : ?>
     2653                                <?php esc_html_e( '(required)', 'buddypress' ); ?>
     2654                        <?php endif; ?>
     2655                </label>
     2656
     2657                <input <?php echo $this->get_edit_field_html_elements( $r ); ?>>
     2658
     2659                <?php
     2660        }
     2661
     2662        /**
     2663         * Output HTML for this field type on the wp-admin Profile Fields screen.
     2664         *
     2665         * Must be used inside the {@link bp_profile_fields()} template loop.
     2666         *
     2667         * @param array $raw_properties Optional key/value array of permitted
     2668         *        attributes that you want to add.
     2669         * @since BuddyPress (2.1.0)
     2670         */
     2671        public function admin_field_html( array $raw_properties = array() ) {
     2672
     2673                $r = bp_parse_args( $raw_properties, array(
     2674                        'type' => 'url'
     2675                ) ); ?>
     2676
     2677                <input <?php echo $this->get_edit_field_html_elements( $r ); ?>>
     2678
     2679                <?php
     2680        }
     2681
     2682        /**
     2683         * This method usually outputs HTML for this field type's children options
     2684         * on the wp-admin Profile Fields "Add Field" and "Edit Field" screens, but
     2685         * for this field type, we don't want it, so it's stubbed out.
     2686         *
     2687         * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
     2688         * @param string $control_type Optional. HTML input type used to render the current field's child options.
     2689         * @since BuddyPress (2.1.0)
     2690         */
     2691        public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {}
     2692       
     2693        /**
     2694         * Format Date values for display.
     2695         *
     2696         * @since BuddyPress (2.1.0)
     2697         *
     2698         * @param string $field_value The date value, as saved in the database.
     2699         *        Typically, this is a MySQL-formatted date string (Y-m-d H:i:s).
     2700         * @return string Date formatted by bp_format_time().
     2701         */
     2702        public static function display_filter( $field_value ) {
     2703                $link      = strip_tags( $field_value );
     2704                $no_scheme = preg_replace( '#^https?://#', '', rtrim( $link, '/' ) );
     2705                $url_text  = str_replace( $link, $no_scheme, $field_value );
     2706                $retval    = '<a href="' . esc_url( $field_value ) . '" rel="nofollow">' . esc_html( $url_text ) . '</a>';
     2707                return $field_value;
     2708        }
    25342709}
    25352710
     
    27182893
    27192894                // Handle field types with accepts_null_value set if $values is an empty array
    2720                 if ( ! $validated && is_array( $values ) && empty( $values ) && $this->accepts_null_value ) {
     2895                if ( ( false === $validated ) && is_array( $values ) && empty( $values ) && $this->accepts_null_value ) {
    27212896                        $validated = true;
    27222897                }
    27232898
    27242899                // If there's a whitelist set, also check the $value.
    2725                 if ( $validated && ! empty( $values ) && ! empty( $this->validation_whitelist ) ) {
    2726 
     2900                if ( ( true === $validated ) && ! empty( $values ) && ! empty( $this->validation_whitelist ) ) {
    27272901                        foreach ( (array) $values as $value ) {
    27282902                                $validated = in_array( $value, $this->validation_whitelist, true );
     
    28062980
    28072981                                <?php
     2982                               
     2983                                // Does option have children?
    28082984                                $options = $current_field->get_children( true );
    28092985
    2810                                 // If no children options exists for this field, check in $_POST for a submitted form (e.g. on the "new field" screen).
    2811                                 if ( ! $options ) {
     2986                                // If no children options exists for this field, check in $_POST
     2987                                // for a submitted form (e.g. on the "new field" screen).
     2988                                if ( empty( $options ) ) {
    28122989
    28132990                                        $options = array();
     
    28363013
    28373014                                        // If there are still no children options set, this must be the "new field" screen, so add one new/empty option.
    2838                                         if ( ! $options ) {
     3015                                        if ( empty( $options ) ) {
    28393016                                                $options[] = (object) array(
    28403017                                                        'id'                => -1,
     
    28933070        }
    28943071
    2895         /**
    2896          * Internal protected/private helper methods past this point.
    2897          */
     3072        /** Protected *************************************************************/
    28983073
    28993074        /**
     
    29093084        protected function get_edit_field_html_elements( array $properties = array() ) {
    29103085
    2911                 $properties = array_merge( array(
     3086                $r = bp_parse_args( $properties, array(
    29123087                        'id'   => bp_get_the_profile_field_input_name(),
    29133088                        'name' => bp_get_the_profile_field_input_name(),
    2914                 ), $properties );
     3089                ) );
    29153090
    29163091                if ( bp_get_the_profile_field_is_required() ) {
    2917                         $properties['aria-required'] = 'true';
    2918                 }
    2919 
    2920                 $html       = '';
    2921                 $properties = (array) apply_filters( 'bp_xprofile_field_edit_html_elements', $properties, get_class( $this ) );
    2922 
    2923                 foreach ( $properties as $name => $value ) {
     3092                        $r['aria-required'] = 'true';
     3093                }
     3094
     3095                $html = '';
     3096                $r    = (array) apply_filters( 'bp_xprofile_field_edit_html_elements', $r, get_class( $this ) );
     3097
     3098                foreach ( $r as $name => $value ) {
    29243099                        $html .= sprintf( '%s="%s" ', sanitize_key( $name ), esc_attr( $value ) );
    29253100                }
Note: See TracChangeset for help on using the changeset viewer.