Skip to:
Content

BuddyPress.org

Ticket #5625: 5625.03.patch

File 5625.03.patch, 10.7 KB (added by boonebgorges, 12 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 5fb8e50..9768b71 100644
    class BP_XProfile_Field_Type_Textarea extends BP_XProfile_Field_Type {  
    24402440         * @since BuddyPress (2.0.0)
    24412441         */
    24422442        public function __construct() {
     2443
    24432444                parent::__construct();
    24442445
    24452446                $this->category = _x( 'Single Fields', 'xprofile field type category', 'buddypress' );
    24462447                $this->name     = _x( 'Multi-line Text Area', 'xprofile field type', 'buddypress' );
     2448                $this->type     = 'textarea';
    24472449
    24482450                $this->set_format( '/^.*$/m', 'replace' );
     2451
     2452                // Create custom filters that mirror 'the_content' for formatting output
     2453                add_filter( 'bp_xprofile_field_type_textarea_content', 'wptexturize'        );
     2454                add_filter( 'bp_xprofile_field_type_textarea_content', 'convert_smilies'    );
     2455                add_filter( 'bp_xprofile_field_type_textarea_content', 'convert_chars'      );
     2456                add_filter( 'bp_xprofile_field_type_textarea_content', 'wpautop'            );
     2457                add_filter( 'bp_xprofile_field_type_textarea_content', 'shortcode_unautop'  );
     2458
     2459                // Override and augment allowed tags
     2460                add_filter( 'xprofile_allowed_tags', array( $this, 'allowed_tags' ), 30, 2 );
     2461
     2462                // Parse the edit value
     2463                add_filter( 'bp_get_the_profile_field_edit_value', array( $this, 'get_field_value' ), 30, 3 );
     2464
     2465                // Filter for those who use xprofile_get_field_data instead of get_field_value
     2466                add_filter( 'xprofile_get_field_data', array( $this, 'get_field_data' ), 15, 3 );
     2467
    24492468                do_action( 'bp_xprofile_field_type_textarea', $this );
     2469
    24502470        }
    24512471
    24522472        /**
    … … class BP_XProfile_Field_Type_Textarea extends BP_XProfile_Field_Type {  
    24652485                        unset( $raw_properties['user_id'] );
    24662486                }
    24672487
    2468                 $r = bp_parse_args( $raw_properties, array(
    2469                         'cols' => 40,
    2470                         'rows' => 5,
    2471                 ) ); ?>
     2488                $richtext_enabled = bp_xprofile_is_richtext_enabled_for_field(); ?>
    24722489
    24732490                <label for="<?php bp_the_profile_field_input_name(); ?>">
    24742491                        <?php bp_the_profile_field_name(); ?>
    … … class BP_XProfile_Field_Type_Textarea extends BP_XProfile_Field_Type {  
    24772494                        <?php endif; ?>
    24782495                </label>
    24792496
    2480                 <?php do_action( bp_get_the_profile_field_errors_action() ); ?>
     2497                <?php do_action( bp_get_the_profile_field_errors_action() );
    24812498
    2482                 <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>><?php bp_the_profile_field_edit_value(); ?></textarea>
     2499                if ( ! $richtext_enabled ) {
     2500                        $r = wp_parse_args( $raw_properties, array(
     2501                                'cols' => 40,
     2502                                'rows' => 5,
     2503                        ) );
    24832504
    2484                 <?php
     2505                        ?>
     2506
     2507                        <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>><?php bp_the_profile_field_edit_value(); ?></textarea>
     2508
     2509                        <?php
     2510
     2511                } else {
     2512                        $editor_args = apply_filters( 'bp_xprofile_field_type_textarea_editor_args', array(
     2513                                'teeny'         => true,
     2514                                'media_buttons' => false,
     2515                                'quicktags'     => true,
     2516                        ) );
     2517
     2518                        // Create the editor
     2519                        wp_editor(
     2520                                bp_get_the_profile_field_edit_value(),
     2521                                bp_get_the_profile_field_input_name(),
     2522                                $editor_args
     2523                        );
     2524                }
    24852525        }
    24862526
    24872527        /**
    … … class BP_XProfile_Field_Type_Textarea extends BP_XProfile_Field_Type {  
    24932533         * @since BuddyPress (2.0.0)
    24942534         */
    24952535        public function admin_field_html( array $raw_properties = array() ) {
    2496                 $r = bp_parse_args( $raw_properties, array(
    2497                         'cols' => 40,
    2498                         'rows' => 5,
    2499                 ) ); ?>
    25002536
    2501                 <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>></textarea>
     2537                $richtext_enabled = bp_xprofile_is_richtext_enabled_for_field();
    25022538
    2503                 <?php
     2539                if ( ! $richtext_enabled ) {
     2540
     2541                        $r = wp_parse_args( $raw_properties, array(
     2542                                'cols' => 40,
     2543                                'rows' => 5,
     2544                        ) );
     2545
     2546                        ?>
     2547
     2548                        <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>></textarea>
     2549
     2550                        <?php
     2551
     2552                } else {
     2553
     2554                        $editor_args = apply_filters( 'bp_xprofile_field_type_textarea_editor_args', array(
     2555                                'teeny'         => true,
     2556                                'media_buttons' => false,
     2557                                'quicktags'     => true,
     2558                        ) );
     2559
     2560                        // Create the editor
     2561                        wp_editor(
     2562                                '',
     2563                                'xprofile_textarea_' . bp_get_the_profile_field_id(),
     2564                                $editor_args
     2565                        );
     2566                }
    25042567        }
    25052568
    25062569        /**
    25072570         * This method usually outputs HTML for this field type's children options on the wp-admin Profile Fields
    2508          * "Add Field" and "Edit Field" screens, but for this field type, we don't want it, so it's stubbed out.
    25092571         *
    25102572         * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
    25112573         * @param string $control_type Optional. HTML input type used to render the current field's child options.
    25122574         * @since BuddyPress (2.0.0)
    25132575         */
    25142576        public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {}
     2577
     2578        /**
     2579         * Format Visual Editor content for display.
     2580         *
     2581         * @since BuddyPress (2.1.0)
     2582         *
     2583         * @param string $field_value The Visual Editor content, as saved in the database.
     2584         * @return string Formatted HTML.
     2585         */
     2586        public static function display_filter( $field_value ) {
     2587
     2588                $richtext_enabled = bp_xprofile_is_richtext_enabled_for_field();
     2589
     2590                if ( $richtext_enabled ) {
     2591
     2592                        /**
     2593                         * This is a bit of a hack because formatted text looks strange with the
     2594                         * 'xprofile_filter_link_profile_data' filter applied. If instead, we parse
     2595                         * this field type in read mode after all BuddyPress filters have been applied
     2596                         * we can avoid this. Moreover, this method is called outside the scope of $this,
     2597                         * so we have to directly reference the name of this class in the filter
     2598                         */
     2599                        add_filter( 'bp_get_the_profile_field_value', array( 'BP_XProfile_Field_Type_Textarea', 'get_field_value' ), 30, 3 );
     2600
     2601                }
     2602
     2603                // return the data as received and format in get_field_value() below
     2604                return $field_value;
     2605
     2606        }
     2607
     2608        /**
     2609         * Show our field type in read mode
     2610         *
     2611         * @param string $value
     2612         * @param string $type
     2613         * @param integer $id
     2614         * @return string
     2615         */
     2616        public function get_field_value( $value = '', $type = '', $id = '' ) {
     2617
     2618                // is it our field type?
     2619                if ( $type == 'textarea' ) {
     2620
     2621                        global $field;
     2622
     2623                        // sanity check
     2624                        if ( ! is_object( $field ) ) return $value;
     2625
     2626                        // get enabled and default to enabled if not yet present
     2627                        $richtext_enabled = bp_xprofile_get_meta( $field->id, 'field', 'richtext_enabled', true );
     2628                        if ( $richtext_enabled === false ) $richtext_enabled = 1;
     2629                        $richtext_enabled = ( $richtext_enabled == 1 ) ? true : false;
     2630
     2631                        if ( $richtext_enabled ) {
     2632
     2633                                // we want the raw data, unfiltered
     2634                                $value = $field->data->value;
     2635
     2636                                // apply content filter
     2637                                $value = apply_filters( 'bp_xprofile_field_type_textarea_content', stripslashes( $value ) );
     2638
     2639                                return apply_filters( 'bp_xprofile_field_type_textarea_value', $value );
     2640
     2641                        }
     2642
     2643                }
     2644
     2645                // fallback
     2646                return $value;
     2647
     2648        }
     2649
     2650        /**
     2651         * Filter for those who use xprofile_get_field_data instead of get_field_value
     2652         *
     2653         * @param string $value
     2654         * @param integer $field_id
     2655         * @param integer $user_id
     2656         * @return string
     2657         */
     2658        public function get_field_data( $value = '', $field_id = '', $user_id = '' ) {
     2659
     2660                // check we get a field ID
     2661                if ( $field_id === '' ) return $value;
     2662
     2663                // get field object
     2664                $field = new BP_XProfile_Field( $field_id );
     2665
     2666                // is it ours?
     2667                if ( $field->type == $this->type ) {
     2668
     2669                        // get enabled and default to enabled if not yet present
     2670                        $richtext_enabled = bp_xprofile_get_meta( $field->id, 'field', 'richtext_enabled', true );
     2671                        if ( $richtext_enabled === false ) $richtext_enabled = 1;
     2672                        $richtext_enabled = ( $richtext_enabled == 1 ) ? true : false;
     2673
     2674                        if ( $richtext_enabled ) {
     2675
     2676                                // apply content filter
     2677                                $value = apply_filters( 'bp_xprofile_field_type_textarea_content', stripslashes( $value ) );
     2678
     2679                                // return filtered value
     2680                                return apply_filters( 'bp_xprofile_field_type_textarea_value', $value );
     2681
     2682                        }
     2683
     2684                }
     2685
     2686                // fallback
     2687                return $value;
     2688
     2689        }
     2690
     2691        /**
     2692         * Callback to allow tags that teeny TinyMCE enables
     2693         *
     2694         * @since BuddyPress (2.2.0)
     2695         *
     2696         * @param array $allowedtags The array of allowed tags
     2697         * @param object $data_obj The xProfile data object (BP 2.1+)
     2698         * @return array $allowedtags The modified array of allowed tags
     2699         */
     2700        public function allowed_tags( $allowedtags, $data_obj = null ) {
     2701
     2702                // test if BP has sent the data object
     2703                if ( ! is_null( $data_obj ) ) {
     2704
     2705                        // get field from data object
     2706                        $field = new BP_XProfile_Field( $data_obj->field_id );
     2707
     2708                        // if this isn't our field, skip amending allowed tags
     2709                        if ( $field->type != $this->type ) return $allowedtags;
     2710
     2711                        // get enabled and default to enabled if not yet present
     2712                        $richtext_enabled = bp_xprofile_get_meta( $field->id, 'field', 'richtext_enabled', true );
     2713                        if ( $richtext_enabled === false ) $richtext_enabled = 1;
     2714                        $richtext_enabled = ( $richtext_enabled == 1 ) ? true : false;
     2715
     2716                        // bail if not rich text
     2717                        if ( ! $richtext_enabled )  return $allowedtags;
     2718
     2719                }
     2720
     2721                // default tags we need to enable the teeny TinyMCE editor markup
     2722                $richtext_tags = array(
     2723                        'img'    => array( 'id' => 1, 'class' => 1, 'src' => 1, 'alt' => 1, 'width' => 1, 'height' => 1 ),
     2724                        'ul'     => array( 'id' => 1, 'class' => 1 ),
     2725                        'ol'     => array( 'id' => 1, 'class' => 1 ),
     2726                        'li'     => array( 'id' => 1, 'class' => 1 ),
     2727                        'span'   => array( 'style' => 1 ),
     2728                        'p'      => array( 'style' => 1 ),
     2729                );
     2730
     2731                $allowedtags = array_merge( $allowedtags, $richtext_tags );
     2732
     2733                return apply_filters( 'bp_xprofile_field_type_textarea_allowedtags', $allowedtags, $data_obj );
     2734
     2735        }
     2736
    25152737}
    25162738
    25172739/**
  • src/bp-xprofile/bp-xprofile-functions.php

    diff --git src/bp-xprofile/bp-xprofile-functions.php src/bp-xprofile/bp-xprofile-functions.php
    index f6f2dee..cf98978 100644
    function bp_xprofile_fullname_field_name() {  
    967967}
    968968
    969969/**
     970 * Is rich text enabled for this profile field?
     971 *
     972 * @since BuddyPress (2.2.0)
     973 *
     974 * @param int $field_id Optional. Default: current field ID.
     975 * @return bool
     976 */
     977function bp_xprofile_is_richtext_enabled_for_field( $field_id = null ) {
     978        if ( ! $field_id ) {
     979                $field_id = bp_get_the_profile_field_id();
     980        }
     981
     982        return apply_filters( 'bp_xprofile_is_richtext_enabled_for_field', true, $field_id );
     983}
     984
     985/**
    970986 * Get visibility levels out of the $bp global
    971987 *
    972988 * @return array
  • src/bp-xprofile/bp-xprofile-template.php

    diff --git src/bp-xprofile/bp-xprofile-template.php src/bp-xprofile/bp-xprofile-template.php
    index 5c9e53f..a9b070c 100644
    function bp_the_profile_field_id() {  
    359359}
    360360        function bp_get_the_profile_field_id() {
    361361                global $field;
    362                 return apply_filters( 'bp_get_the_profile_field_id', $field->id );
     362
     363                $field_id = 0;
     364                if ( ! empty( $field->id ) ) {
     365                        $field_id = $field->id;
     366                }
     367
     368                return apply_filters( 'bp_get_the_profile_field_id', $field_id );
    363369        }
    364370
    365371function bp_the_profile_field_name() {