Changeset 5060 for trunk/includes/topics/template.php
- Timestamp:
- 08/02/2013 07:20:49 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/topics/template.php
r5045 r5060 2913 2913 * Displays topic type select box (normal/sticky/super sticky) 2914 2914 * 2915 * @since bbPress (r2784) 2915 * @since bbPress (r5059) 2916 * @deprecated since bbPress (r5059) 2916 2917 * 2917 2918 * @param $args This function supports these arguments: 2918 * - stick_text: Sticky text2919 * - super_text: Super Sticky text2920 * - unstick_text: Unstick (normal) text2921 2919 * - select_id: Select id. Defaults to bbp_stick_topic 2922 2920 * - tab: Tabindex 2923 2921 * - topic_id: Topic id 2924 * @uses bbp_get_topic_id() To get the topic id 2925 * @uses bbp_is_single_topic() To check if we're viewing a single topic 2926 * @uses bbp_is_topic_edit() To check if it is the topic edit page 2927 * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky 2928 * @uses bbp_is_topic_sticky() To check if the topic is a sticky 2922 * - selected: Override the selected option 2929 2923 */ 2930 2924 function bbp_topic_type_select( $args = '' ) { 2931 2932 // Parse arguments against default values 2933 $r = bbp_parse_args( $args, array( 2934 'unstick_text' => __( 'Normal', 'bbpress' ), 2935 'stick_text' => __( 'Sticky', 'bbpress' ), 2936 'super_text' => __( 'Super Sticky', 'bbpress' ), 2937 'select_id' => 'bbp_stick_topic', 2938 'tab' => bbp_get_tab_index(), 2939 'topic_id' => 0 2940 ), 'topic_type_select' ); 2941 2942 // Edit topic 2943 if ( bbp_is_single_topic() || bbp_is_topic_edit() ) { 2944 2945 // Get current topic id 2946 $topic_id = bbp_get_topic_id( $r['topic_id'] ); 2947 2948 // Post value is passed 2949 if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) { 2950 $sticky_current = $_POST[ $r['select_id'] ]; 2951 2952 // Topic is super sticky 2953 } elseif ( bbp_is_topic_super_sticky( $topic_id ) ) { 2954 $sticky_current = 'super'; 2955 2956 // Topic is sticky or normal 2957 } else { 2958 $sticky_current = bbp_is_topic_sticky( $topic_id, false ) ? 'stick' : 'unstick'; 2959 } 2960 2961 // New topic 2962 } else { 2963 2964 // Post value is passed 2965 if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) { 2966 $sticky_current = $_POST[ $r['select_id'] ]; 2967 2968 // Default to unstick 2969 } else { 2970 $sticky_current = 'unstick'; 2971 } 2972 } 2973 2974 // Used variables 2975 $tab = !empty( $r['tab'] ) ? ' tabindex="' . $r['tab'] . '"' : ''; 2976 $select_id = esc_attr( $r['select_id'] ); 2977 $sticky_statuses = array_filter( array( 2978 'unstick' => $r['unstick_text'], 2979 'stick' => $r['stick_text'], 2980 'super' => $r['super_text'], 2981 ) ); ?> 2982 2983 <select name="<?php echo $select_id; ?>" id="<?php echo $select_id; ?>"<?php echo $tab; ?>> 2984 2985 <?php foreach ( $sticky_statuses as $sticky_status => $label ) : ?> 2986 2987 <option value="<?php echo esc_attr( $sticky_status ); ?>"<?php selected( $sticky_current, $sticky_status ); ?>><?php echo esc_html( $label ); ?></option> 2988 2989 <?php endforeach; ?> 2990 2991 </select> 2992 2993 <?php 2994 } 2925 echo bbp_get_form_topic_type_dropdown( $args ); 2926 } 2927 2928 /** 2929 * Displays topic type select box (normal/sticky/super sticky) 2930 * 2931 * @since bbPress (r5059) 2932 * 2933 * @param $args This function supports these arguments: 2934 * - select_id: Select id. Defaults to bbp_stick_topic 2935 * - tab: Tabindex 2936 * - topic_id: Topic id 2937 * - selected: Override the selected option 2938 */ 2939 function bbp_form_topic_type_dropdown( $args = '' ) { 2940 echo bbp_get_form_topic_type_dropdown( $args ); 2941 } 2942 /** 2943 * Returns topic type select box (normal/sticky/super sticky) 2944 * 2945 * @since bbPress (r5059) 2946 * 2947 * @param $args This function supports these arguments: 2948 * - select_id: Select id. Defaults to bbp_stick_topic 2949 * - tab: Tabindex 2950 * - topic_id: Topic id 2951 * - selected: Override the selected option 2952 * @uses bbp_get_topic_id() To get the topic id 2953 * @uses bbp_is_single_topic() To check if we're viewing a single topic 2954 * @uses bbp_is_topic_edit() To check if it is the topic edit page 2955 * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky 2956 * @uses bbp_is_topic_sticky() To check if the topic is a sticky 2957 */ 2958 function bbp_get_form_topic_type_dropdown( $args = '' ) { 2959 2960 // Parse arguments against default values 2961 $r = bbp_parse_args( $args, array( 2962 'select_id' => 'bbp_stick_topic', 2963 'tab' => bbp_get_tab_index(), 2964 'topic_id' => 0, 2965 'selected' => false 2966 ), 'topic_type_select' ); 2967 2968 // No specific selected value passed 2969 if ( empty( $r['selected'] ) ) { 2970 2971 // Post value is passed 2972 if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) { 2973 $r['selected'] = $_POST[ $r['select_id'] ]; 2974 2975 // No Post value passed 2976 } else { 2977 2978 // Edit topic 2979 if ( bbp_is_single_topic() || bbp_is_topic_edit() ) { 2980 2981 // Get current topic id 2982 $topic_id = bbp_get_topic_id( $r['topic_id'] ); 2983 2984 // Topic is super sticky 2985 if ( bbp_is_topic_super_sticky( $topic_id ) ) { 2986 $r['selected'] = 'super'; 2987 2988 // Topic is sticky or normal 2989 } else { 2990 $r['selected'] = bbp_is_topic_sticky( $topic_id, false ) ? 'stick' : 'unstick'; 2991 } 2992 } 2993 } 2994 } 2995 2996 // Used variables 2997 $tab = !empty( $r['tab'] ) ? ' tabindex="' . (int) $r['tab'] . '"' : ''; 2998 2999 // Start an output buffer, we'll finish it after the select loop 3000 ob_start(); ?> 3001 3002 <select name="<?php echo esc_attr( $r['select_id'] ); ?>" id="<?php echo esc_attr( $r['select_id'] ); ?>_select"<?php echo $tab; ?>> 3003 3004 <?php foreach ( bbp_get_topic_types() as $key => $label ) : ?> 3005 3006 <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option> 3007 3008 <?php endforeach; ?> 3009 3010 </select> 3011 3012 <?php 3013 3014 // Return the results 3015 return apply_filters( 'bbp_get_form_topic_type_dropdown', ob_get_clean(), $r ); 3016 } 3017 3018 /** 3019 * Output value topic status dropdown 3020 * 3021 * @since bbPress (r5059) 3022 * 3023 * @param int $topic_id The topic id to use 3024 */ 3025 function bbp_form_topic_status_dropdown( $args = '' ) { 3026 echo bbp_get_form_topic_status_dropdown( $args ); 3027 } 3028 /** 3029 * Returns topic status downdown 3030 * 3031 * This dropdown is only intended to be seen by users with the 'moderate' 3032 * capability. Because of this, no additional capablitiy checks are performed 3033 * within this function to check available topic statuses. 3034 * 3035 * @since bbPress (r5059) 3036 * 3037 * @param $args This function supports these arguments: 3038 * - select_id: Select id. Defaults to bbp_open_close_topic 3039 * - tab: Tabindex 3040 * - topic_id: Topic id 3041 * - selected: Override the selected option 3042 */ 3043 function bbp_get_form_topic_status_dropdown( $args = '' ) { 3044 3045 // Parse arguments against default values 3046 $r = bbp_parse_args( $args, array( 3047 'select_id' => 'bbp_topic_status', 3048 'tab' => bbp_get_tab_index(), 3049 'topic_id' => 0, 3050 'selected' => false 3051 ), 'topic_open_close_select' ); 3052 3053 // No specific selected value passed 3054 if ( empty( $r['selected'] ) ) { 3055 3056 // Post value is passed 3057 if ( bbp_is_post_request() && isset( $_POST[ $r['select_id'] ] ) ) { 3058 $r['selected'] = $_POST[ $r['select_id'] ]; 3059 3060 // No Post value was passed 3061 } else { 3062 3063 // Edit topic 3064 if ( bbp_is_topic_edit() ) { 3065 $r['topic_id'] = bbp_get_topic_id( $r['topic_id'] ); 3066 $r['selected'] = bbp_get_topic_status( $r['topic_id'] ); 3067 3068 // New topic 3069 } else { 3070 $r['selected'] = bbp_get_public_status_id(); 3071 } 3072 } 3073 } 3074 3075 // Used variables 3076 $tab = ! empty( $r['tab'] ) ? ' tabindex="' . (int) $r['tab'] . '"' : ''; 3077 3078 // Start an output buffer, we'll finish it after the select loop 3079 ob_start(); ?> 3080 3081 <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ); ?>_select"<?php echo $tab; ?>> 3082 3083 <?php foreach ( bbp_get_topic_statuses( $r['topic_id'] ) as $key => $label ) : ?> 3084 3085 <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option> 3086 3087 <?php endforeach; ?> 3088 3089 </select> 3090 3091 <?php 3092 3093 // Return the results 3094 return apply_filters( 'bbp_get_form_topic_status_dropdown', ob_get_clean(), $r ); 3095 } 2995 3096 2996 3097 /** Single Topic **************************************************************/
Note: See TracChangeset
for help on using the changeset viewer.