Skip to:
Content

BuddyPress.org

Changeset 11287


Ignore:
Timestamp:
12/11/2016 04:16:02 PM (4 years ago)
Author:
djpaul
Message:

xprofile: add support for auto linking semicolon-separated field values.

Fixes #5872

Props jreeve, tw2113

Location:
trunk
Files:
2 edited

Legend:

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

    r10740 r11287  
    350350    }
    351351
    352     if ( !strpos( $field_value, ',' ) && ( count( explode( ' ', $field_value ) ) > 5 ) ) {
     352    if ( strpos( $field_value, ',' ) === false && strpos( $field_value, ';' ) === false && ( count( explode( ' ', $field_value ) ) > 5 ) ) {
    353353        return $field_value;
    354354    }
    355355
    356     $values = explode( ',', $field_value );
    357 
    358     if ( !empty( $values ) ) {
     356    if ( strpos( $field_value, ',' ) !== false ) {
     357        $list_type = 'comma';
     358        $values    = explode( ',', $field_value ); // Comma-separated lists.
     359    } else {
     360        $list_type = 'semicolon';
     361        $values = explode( ';', $field_value ); // Semicolon-separated lists.
     362    }
     363
     364    if ( ! empty( $values ) ) {
    359365        foreach ( (array) $values as $value ) {
    360366            $value = trim( $value );
     
    380386        }
    381387
    382         $values = implode( ', ', $new_values );
     388        if ( 'comma' === $list_type ) {
     389            $values = implode( ', ', $new_values );
     390        } else {
     391            $values = implode( '; ', $new_values );
     392        }
    383393    }
    384394
  • trunk/tests/phpunit/testcases/xprofile/functions.php

    r10460 r11287  
    10431043        $profile_template = $reset_profile_template;
    10441044    }
     1045
     1046    /**
     1047     * @group xprofile_filter_link_profile_data
     1048     */
     1049    public function test_field_comma_seperated_values_are_autolinked() {
     1050        $field_group_id = $this->factory->xprofile_group->create();
     1051        $field_id = $this->factory->xprofile_field->create( array( 'field_group_id' => $this->field_group_id ) );
     1052        $GLOBALS['field'] = new BP_XProfile_Field( $this->field_id );
     1053        $GLOBALS['field']->do_autolink = true;
     1054
     1055        $output = xprofile_filter_link_profile_data( 'Hello world this is a test; with, some, words', 'textbox' );
     1056        $regex = '#^Hello world this is a test; with, <a href="([^"]+)" rel="nofollow">some</a>, <a href="([^"]+)" rel="nofollow">words</a>$#i';
     1057
     1058        $this->assertRegExp( $regex, $output );
     1059        unset( $GLOBALS['field'] );
     1060    }
     1061
     1062    /**
     1063     * @group xprofile_filter_link_profile_data
     1064     */
     1065    public function test_field_semicolon_seperated_values_are_autolinked() {
     1066        $field_group_id = $this->factory->xprofile_group->create();
     1067        $field_id = $this->factory->xprofile_field->create( array( 'field_group_id' => $this->field_group_id ) );
     1068        $GLOBALS['field'] = new BP_XProfile_Field( $this->field_id );
     1069        $GLOBALS['field']->do_autolink = true;
     1070
     1071        $output = xprofile_filter_link_profile_data( 'Hello world this is a test with; some; words', 'textbox' );
     1072        $regex = '#^Hello world this is a test with; <a href="([^"]+)" rel="nofollow">some</a>; <a href="([^"]+)" rel="nofollow">words</a>$#i';
     1073
     1074        $this->assertRegExp( $regex, $output );
     1075        unset( $GLOBALS['field'] );
     1076    }
    10451077}
Note: See TracChangeset for help on using the changeset viewer.