| 2484 | | <?php |
| | 2523 | <?php |
| | 2524 | |
| | 2525 | } else { |
| | 2526 | |
| | 2527 | // get quicktags and default to off if not yet present |
| | 2528 | $richtext_quicktags = bp_xprofile_get_meta( $field->id, 'field', 'richtext_quicktags', true ); |
| | 2529 | if ( $richtext_quicktags === false ) $richtext_quicktags = 0; |
| | 2530 | $richtext_quicktags = ( $richtext_quicktags == 1 ) ? true : false; |
| | 2531 | |
| | 2532 | // get quicktags and default to off if not yet present |
| | 2533 | $richtext_media = bp_xprofile_get_meta( $field->id, 'field', 'richtext_media', true ); |
| | 2534 | if ( $richtext_media === false ) $richtext_media = 0; |
| | 2535 | $richtext_media = ( $richtext_media == 1 ) ? true : false; |
| | 2536 | |
| | 2537 | ?> |
| | 2538 | <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> |
| | 2539 | <?php do_action( bp_get_the_profile_field_errors_action() ); ?> |
| | 2540 | <?php |
| | 2541 | |
| | 2542 | // define some default buttons for cases where teeny TInyMCE is set to false |
| | 2543 | $buttons = array( |
| | 2544 | 'theme_advanced_buttons1' => 'bold,italic,underline,blockquote,strikethrough,|,link,unlink,|,spellchecker,removeformat,fullscreen', |
| | 2545 | 'theme_advanced_buttons2' => '', |
| | 2546 | 'theme_advanced_buttons3' => '' |
| | 2547 | ); |
| | 2548 | |
| | 2549 | // define our editor |
| | 2550 | wp_editor( |
| | 2551 | |
| | 2552 | bp_get_the_profile_field_edit_value(), |
| | 2553 | bp_get_the_profile_field_input_name(), |
| | 2554 | array( |
| | 2555 | 'media_buttons' => apply_filters( 'bp_xprofile_field_type_textarea_addmedia', $richtext_media ), |
| | 2556 | 'teeny' => apply_filters( 'bp_xprofile_field_type_textarea_teeny', true ), |
| | 2557 | 'quicktags' => apply_filters( 'bp_xprofile_field_type_textarea_quicktags', $richtext_quicktags ), |
| | 2558 | 'tinymce' => apply_filters( 'bp_xprofile_field_type_textarea_buttons', $buttons ) |
| | 2559 | ) |
| | 2560 | |
| | 2561 | ); |
| | 2562 | |
| | 2563 | } |
| | 2564 | |
| 2503 | | <?php |
| | 2599 | <?php |
| | 2600 | |
| | 2601 | } else { |
| | 2602 | |
| | 2603 | // get quicktags and default to off if not yet present |
| | 2604 | $richtext_quicktags = bp_xprofile_get_meta( $field->id, 'field', 'richtext_quicktags', true ); |
| | 2605 | if ( $richtext_quicktags === false ) $richtext_quicktags = 0; |
| | 2606 | $richtext_quicktags = ( $richtext_quicktags == 1 ) ? true : false; |
| | 2607 | |
| | 2608 | // get quicktags and default to off if not yet present |
| | 2609 | $richtext_media = bp_xprofile_get_meta( $field->id, 'field', 'richtext_media', true ); |
| | 2610 | if ( $richtext_media === false ) $richtext_media = 0; |
| | 2611 | $richtext_media = ( $richtext_media == 1 ) ? true : false; |
| | 2612 | |
| | 2613 | // define some default buttons for cases where teeny TInyMCE is set to false |
| | 2614 | $buttons = array( |
| | 2615 | 'theme_advanced_buttons1' => 'bold,italic,underline,blockquote,strikethrough,|,link,unlink,|,spellchecker,removeformat,fullscreen', |
| | 2616 | 'theme_advanced_buttons2' => '', |
| | 2617 | 'theme_advanced_buttons3' => '' |
| | 2618 | ); |
| | 2619 | |
| | 2620 | // define our editor |
| | 2621 | wp_editor( |
| | 2622 | |
| | 2623 | '', |
| | 2624 | 'xprofile_textarea_' . $field->id, |
| | 2625 | array( |
| | 2626 | 'media_buttons' => apply_filters( 'bp_xprofile_field_type_textarea_addmedia', $richtext_media ), |
| | 2627 | 'teeny' => apply_filters( 'bp_xprofile_field_type_textarea_teeny', true ), |
| | 2628 | 'quicktags' => apply_filters( 'bp_xprofile_field_type_textarea_quicktags', $richtext_quicktags ), |
| | 2629 | 'tinymce' => apply_filters( 'bp_xprofile_field_type_textarea_buttons', $buttons ) |
| | 2630 | ) |
| | 2631 | |
| | 2632 | ); |
| | 2633 | |
| | 2634 | } |
| | 2635 | |
| 2514 | | public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} |
| | 2647 | public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) { |
| | 2648 | |
| | 2649 | $type = array_search( get_class( $this ), bp_xprofile_get_field_types() ); |
| | 2650 | if ( false === $type ) { |
| | 2651 | return; |
| | 2652 | } |
| | 2653 | |
| | 2654 | $class = $current_field->type != $type ? 'display: none;' : ''; |
| | 2655 | $current_type_obj = bp_xprofile_create_field_type( $type ); |
| | 2656 | |
| | 2657 | /* |
| | 2658 | print_r( array( |
| | 2659 | 'current_field' => $current_field, |
| | 2660 | 'current_type_obj' => $current_type_obj, |
| | 2661 | ) ); die(); |
| | 2662 | */ |
| | 2663 | |
| | 2664 | // get enabled and default to enabled if not yet present |
| | 2665 | $richtext_enabled = bp_xprofile_get_meta( $current_field->id, 'field', 'richtext_enabled', true ); |
| | 2666 | if ( $richtext_enabled === false ) $richtext_enabled = 1; |
| | 2667 | |
| | 2668 | // get quicktags and default to off if not yet present |
| | 2669 | $richtext_quicktags = bp_xprofile_get_meta( $current_field->id, 'field', 'richtext_quicktags', true ); |
| | 2670 | if ( $richtext_quicktags === false ) $richtext_quicktags = 0; |
| | 2671 | |
| | 2672 | // get quicktags and default to off if not yet present |
| | 2673 | $richtext_media = bp_xprofile_get_meta( $current_field->id, 'field', 'richtext_media', true ); |
| | 2674 | if ( $richtext_media === false ) $richtext_media = 0; |
| | 2675 | |
| | 2676 | ?> |
| | 2677 | |
| | 2678 | <div id="<?php echo esc_attr( $type ); ?>" class="postbox bp-options-box" style="<?php echo esc_attr( $class ); ?> margin-top: 15px;"> |
| | 2679 | <h3><?php esc_html_e( 'Please select options for this Field:', 'buddypress' ); ?></h3> |
| | 2680 | <div class="inside"> |
| | 2681 | <p><label for="<?php echo $current_field->type ?>-enabled"><input id="<?php echo $current_field->type ?>-enabled" name="<?php echo $current_field->type ?>-enabled" value="1" type="checkbox" <?php checked( $richtext_enabled ); ?> /> <?php esc_html_e( 'Use Visual Editor', 'buddypress' ); ?></label></p> |
| | 2682 | <p><label for="<?php echo $current_field->type ?>-quicktags"><input id="<?php echo $current_field->type ?>-quicktags" name="<?php echo $current_field->type ?>-quicktags" value="1" type="checkbox" <?php checked( $richtext_quicktags ); ?> /> <?php esc_html_e( 'Enable Quicktags', 'buddypress' ); ?></label></p> |
| | 2683 | <p><label for="<?php echo $current_field->type ?>-media"><input id="<?php echo $current_field->type ?>-media" name="<?php echo $current_field->type ?>-media" value="1" type="checkbox" <?php checked( $richtext_media ); ?> /> <?php esc_html_e( 'Enable Media Button', 'buddypress' ); ?></label></p> |
| | 2684 | </div> |
| | 2685 | </div> |
| | 2686 | |
| | 2687 | <?php |
| | 2688 | } |
| | 2689 | |
| | 2690 | /** |
| | 2691 | * Save options for this field |
| | 2692 | * |
| | 2693 | * @param object $field |
| | 2694 | * @return void |
| | 2695 | */ |
| | 2696 | public function save_options( $field = null ) { |
| | 2697 | |
| | 2698 | // sanity checks |
| | 2699 | if ( ! is_object( $field ) ) return; |
| | 2700 | if ( $field->type !== $this->type ) return; |
| | 2701 | |
| | 2702 | // get settings |
| | 2703 | $richtext_enabled = isset( $_POST[$field->type . '-enabled'] ) ? 1 : 0; |
| | 2704 | bp_xprofile_update_field_meta( $field->id, 'richtext_enabled', $richtext_enabled ); |
| | 2705 | |
| | 2706 | $richtext_quicktags = isset( $_POST[$field->type . '-quicktags'] ) ? 1 : 0; |
| | 2707 | bp_xprofile_update_field_meta( $field->id, 'richtext_quicktags', $richtext_quicktags ); |
| | 2708 | |
| | 2709 | $richtext_media = isset( $_POST[$field->type . '-media'] ) ? 1 : 0; |
| | 2710 | bp_xprofile_update_field_meta( $field->id, 'richtext_media', $richtext_media ); |
| | 2711 | |
| | 2712 | } |
| | 2713 | |
| | 2714 | /** |
| | 2715 | * Format Visual Editor content for display. |
| | 2716 | * |
| | 2717 | * @since BuddyPress (2.1.0) |
| | 2718 | * |
| | 2719 | * @param string $field_value The Visual Editor content, as saved in the database. |
| | 2720 | * @return string Formatted HTML. |
| | 2721 | */ |
| | 2722 | public static function display_filter( $field_value ) { |
| | 2723 | |
| | 2724 | global $field; |
| | 2725 | |
| | 2726 | // sanity checks |
| | 2727 | if ( ! is_object( $field ) ) return; |
| | 2728 | if ( $field->type !== 'textarea' ) return; |
| | 2729 | |
| | 2730 | // get enabled and default to enabled if not yet present |
| | 2731 | $richtext_enabled = bp_xprofile_get_meta( $field->id, 'field', 'richtext_enabled', true ); |
| | 2732 | if ( $richtext_enabled === false ) $richtext_enabled = 1; |
| | 2733 | $richtext_enabled = ( $richtext_enabled == 1 ) ? true : false; |
| | 2734 | |
| | 2735 | if ( $richtext_enabled ) { |
| | 2736 | |
| | 2737 | /** |
| | 2738 | * This is a bit of a hack because formatted text looks strange with the |
| | 2739 | * 'xprofile_filter_link_profile_data' filter applied. If instead, we parse |
| | 2740 | * this field type in read mode after all BuddyPress filters have been applied |
| | 2741 | * we can avoid this. Moreover, this method is called outside the scope of $this, |
| | 2742 | * so we have to directly reference the name of this class in the filter |
| | 2743 | */ |
| | 2744 | add_filter( 'bp_get_the_profile_field_value', array( 'BP_XProfile_Field_Type_Textarea', 'get_field_value' ), 30, 3 ); |
| | 2745 | |
| | 2746 | } |
| | 2747 | |
| | 2748 | // return the data as received and format in get_field_value() below |
| | 2749 | return $field_value; |
| | 2750 | |
| | 2751 | } |
| | 2752 | |
| | 2753 | /** |
| | 2754 | * Show our field type in read mode |
| | 2755 | * |
| | 2756 | * @param string $value |
| | 2757 | * @param string $type |
| | 2758 | * @param integer $id |
| | 2759 | * @return string |
| | 2760 | */ |
| | 2761 | public function get_field_value( $value = '', $type = '', $id = '' ) { |
| | 2762 | |
| | 2763 | // is it our field type? |
| | 2764 | if ( $type == 'textarea' ) { |
| | 2765 | |
| | 2766 | global $field; |
| | 2767 | |
| | 2768 | // sanity check |
| | 2769 | if ( ! is_object( $field ) ) return $value; |
| | 2770 | |
| | 2771 | // get enabled and default to enabled if not yet present |
| | 2772 | $richtext_enabled = bp_xprofile_get_meta( $field->id, 'field', 'richtext_enabled', true ); |
| | 2773 | if ( $richtext_enabled === false ) $richtext_enabled = 1; |
| | 2774 | $richtext_enabled = ( $richtext_enabled == 1 ) ? true : false; |
| | 2775 | |
| | 2776 | if ( $richtext_enabled ) { |
| | 2777 | |
| | 2778 | // we want the raw data, unfiltered |
| | 2779 | $value = $field->data->value; |
| | 2780 | |
| | 2781 | // apply content filter |
| | 2782 | $value = apply_filters( 'bp_xprofile_field_type_textarea_content', stripslashes( $value ) ); |
| | 2783 | |
| | 2784 | return apply_filters( 'bp_xprofile_field_type_textarea_value', $value ); |
| | 2785 | |
| | 2786 | } |
| | 2787 | |
| | 2788 | } |
| | 2789 | |
| | 2790 | // fallback |
| | 2791 | return $value; |
| | 2792 | |
| | 2793 | } |
| | 2794 | |
| | 2795 | /** |
| | 2796 | * Filter for those who use xprofile_get_field_data instead of get_field_value |
| | 2797 | * |
| | 2798 | * @param string $value |
| | 2799 | * @param integer $field_id |
| | 2800 | * @param integer $user_id |
| | 2801 | * @return string |
| | 2802 | */ |
| | 2803 | public function get_field_data( $value = '', $field_id = '', $user_id = '' ) { |
| | 2804 | |
| | 2805 | // check we get a field ID |
| | 2806 | if ( $field_id === '' ) return $value; |
| | 2807 | |
| | 2808 | // get field object |
| | 2809 | $field = new BP_XProfile_Field( $field_id ); |
| | 2810 | |
| | 2811 | // is it ours? |
| | 2812 | if ( $field->type == $this->type ) { |
| | 2813 | |
| | 2814 | // get enabled and default to enabled if not yet present |
| | 2815 | $richtext_enabled = bp_xprofile_get_meta( $field->id, 'field', 'richtext_enabled', true ); |
| | 2816 | if ( $richtext_enabled === false ) $richtext_enabled = 1; |
| | 2817 | $richtext_enabled = ( $richtext_enabled == 1 ) ? true : false; |
| | 2818 | |
| | 2819 | if ( $richtext_enabled ) { |
| | 2820 | |
| | 2821 | // apply content filter |
| | 2822 | $value = apply_filters( 'bp_xprofile_field_type_textarea_content', stripslashes( $value ) ); |
| | 2823 | |
| | 2824 | // return filtered value |
| | 2825 | return apply_filters( 'bp_xprofile_field_type_textarea_value', $value ); |
| | 2826 | |
| | 2827 | } |
| | 2828 | |
| | 2829 | } |
| | 2830 | |
| | 2831 | // fallback |
| | 2832 | return $value; |
| | 2833 | |
| | 2834 | } |
| | 2835 | |
| | 2836 | /** |
| | 2837 | * Callback to allow tags that teeny TinyMCE enables |
| | 2838 | * |
| | 2839 | * @since BuddyPress (2.2.0) |
| | 2840 | * |
| | 2841 | * @param array $allowedtags The array of allowed tags |
| | 2842 | * @param object $data_obj The xProfile data object (BP 2.1+) |
| | 2843 | * @return array $allowedtags The modified array of allowed tags |
| | 2844 | */ |
| | 2845 | public function allowed_tags( $allowedtags, $data_obj = null ) { |
| | 2846 | |
| | 2847 | // test if BP has sent the data object |
| | 2848 | if ( ! is_null( $data_obj ) ) { |
| | 2849 | |
| | 2850 | // get field from data object |
| | 2851 | $field = new BP_XProfile_Field( $data_obj->field_id ); |
| | 2852 | |
| | 2853 | // if this isn't our field, skip amending allowed tags |
| | 2854 | if ( $field->type != $this->type ) return $allowedtags; |
| | 2855 | |
| | 2856 | // get enabled and default to enabled if not yet present |
| | 2857 | $richtext_enabled = bp_xprofile_get_meta( $field->id, 'field', 'richtext_enabled', true ); |
| | 2858 | if ( $richtext_enabled === false ) $richtext_enabled = 1; |
| | 2859 | $richtext_enabled = ( $richtext_enabled == 1 ) ? true : false; |
| | 2860 | |
| | 2861 | // bail if not rich text |
| | 2862 | if ( ! $richtext_enabled ) return $allowedtags; |
| | 2863 | |
| | 2864 | } |
| | 2865 | |
| | 2866 | // default tags we need to enable the teeny TinyMCE editor markup |
| | 2867 | $richtext_tags = array( |
| | 2868 | 'img' => array( 'id' => 1, 'class' => 1, 'src' => 1, 'alt' => 1, 'width' => 1, 'height' => 1 ), |
| | 2869 | 'ul' => array( 'id' => 1, 'class' => 1 ), |
| | 2870 | 'ol' => array( 'id' => 1, 'class' => 1 ), |
| | 2871 | 'li' => array( 'id' => 1, 'class' => 1 ), |
| | 2872 | 'span' => array( 'style' => 1 ), |
| | 2873 | 'p' => array( 'style' => 1 ), |
| | 2874 | ); |
| | 2875 | |
| | 2876 | $allowedtags = array_merge( $allowedtags, $richtext_tags ); |
| | 2877 | |
| | 2878 | return apply_filters( 'bp_xprofile_field_type_textarea_allowedtags', $allowedtags, $data_obj ); |
| | 2879 | |
| | 2880 | } |
| | 2881 | |