Пример #1
0
/**
 * Output a select box allowing to pick which forum/topic a new
 * topic/reply belongs in.
 *
 * @since bbPress (r2746)
 *
 * @param mixed $args The function supports these args:
 *  - post_type: Post type, defaults to bbp_get_forum_post_type() (bbp_forum)
 *  - selected: Selected ID, to not have any value as selected, pass
 *               anything smaller than 0 (due to the nature of select
 *               box, the first value would of course be selected -
 *               though you can have that as none (pass 'show_none' arg))
 *  - orderby: Defaults to 'menu_order title'
 *  - post_parent: Post parent. Defaults to 0
 *  - post_status: Which all post_statuses to find in? Can be an array
 *                  or CSV of publish, category, closed, private, spam,
 *                  trash (based on post type) - if not set, these are
 *                  automatically determined based on the post_type
 *  - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get
 *                     all posts
 *  - walker: Which walker to use? Defaults to
 *             {@link BBP_Walker_Dropdown}
 *  - select_id: ID of the select box. Defaults to 'bbp_forum_id'
 *  - tab: Tabindex value. False or integer
 *  - options_only: Show only <options>? No <select>?
 *  - show_none: False or something like __( '(No Forum)', 'bbpress' ),
 *                will have value=""
 *  - none_found: False or something like
 *                 __( 'No forums to post to!', 'bbpress' )
 *  - disable_categories: Disable forum categories and closed forums?
 *                         Defaults to true. Only for forums and when
 *                         the category option is displayed.
 * @uses BBP_Walker_Dropdown() As the default walker to generate the
 *                              dropdown
 * @uses current_user_can() To check if the current user can read
 *                           private forums
 * @uses bbp_get_forum_post_type() To get the forum post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses walk_page_dropdown_tree() To generate the dropdown using the
 *                                  walker
 * @uses apply_filters() Calls 'bbp_get_dropdown' with the dropdown
 *                        and args
 * @return string The dropdown
 */
function stachestack_bbp_get_dropdown($args = '')
{
    /** Arguments *********************************************************/
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('post_type' => bbp_get_forum_post_type(), 'post_parent' => null, 'post_status' => null, 'selected' => 0, 'exclude' => array(), 'numberposts' => -1, 'orderby' => 'menu_order title', 'order' => 'ASC', 'walker' => '', 'select_id' => 'bbp_forum_id', 'tab' => bbp_get_tab_index(), 'options_only' => false, 'show_none' => false, 'none_found' => false, 'disable_categories' => true, 'disabled' => ''), 'get_dropdown');
    if (empty($r['walker'])) {
        $r['walker'] = new BBP_Walker_Dropdown();
        $r['walker']->tree_type = $r['post_type'];
    }
    // Force 0
    if (is_numeric($r['selected']) && $r['selected'] < 0) {
        $r['selected'] = 0;
    }
    // Force array
    if (!empty($r['exclude']) && !is_array($r['exclude'])) {
        $r['exclude'] = explode(',', $r['exclude']);
    }
    /** Setup variables ***************************************************/
    $retval = '';
    $posts = get_posts(array('post_type' => $r['post_type'], 'post_status' => $r['post_status'], 'exclude' => $r['exclude'], 'post_parent' => $r['post_parent'], 'numberposts' => $r['numberposts'], 'orderby' => $r['orderby'], 'order' => $r['order'], 'walker' => $r['walker'], 'disable_categories' => $r['disable_categories']));
    /** Drop Down *********************************************************/
    // Items found
    if (!empty($posts)) {
        // Build the opening tag for the select element
        if (empty($r['options_only'])) {
            // Should this select appear disabled?
            $disabled = disabled(isset(bbpress()->options[$r['disabled']]), true, false);
            // Setup the tab index attribute
            $tab = !empty($r['tab']) ? ' tabindex="' . intval($r['tab']) . '"' : '';
            // Build the opening tag
            $retval .= '<select class="form-control" name="' . esc_attr($r['select_id']) . '" id="' . esc_attr($r['select_id']) . '"' . $disabled . $tab . '>' . "\n";
        }
        // Get the options
        $retval .= !empty($r['show_none']) ? "\t<option value=\"\" class=\"level-0\">" . esc_html($r['show_none']) . '</option>' : '';
        $retval .= walk_page_dropdown_tree($posts, 0, $r);
        // Build the closing tag for the select element
        if (empty($r['options_only'])) {
            $retval .= '</select>';
        }
        // No items found - Display feedback if no custom message was passed
    } elseif (empty($r['none_found'])) {
        // Switch the response based on post type
        switch ($r['post_type']) {
            // Topics
            case bbp_get_topic_post_type():
                $retval = __('No topics available', 'bbpress');
                break;
                // Forums
            // Forums
            case bbp_get_forum_post_type():
                $retval = __('No forums available', 'bbpress');
                break;
                // Any other
            // Any other
            default:
                $retval = __('None available', 'bbpress');
                break;
        }
    }
    return apply_filters('bbp_get_dropdown', $retval, $r);
}
Пример #2
0
/**
 * Return a textarea or TinyMCE if enabled
 *
 * @since bbPress (r3586)
 *
 * @param array $args
 *
 * @uses apply_filter() To filter args and output
 * @uses wp_parse_pargs() To compare args
 * @uses bbp_use_wp_editor() To see if WP editor is in use
 * @uses bbp_is_edit() To see if we are editing something
 * @uses wp_editor() To output the WordPress editor
 *
 * @return string HTML from output buffer
 */
function bbp_get_the_content($args = array())
{
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('context' => 'topic', 'before' => '<div class="bbp-the-content-wrapper">', 'after' => '</div>', 'wpautop' => true, 'media_buttons' => false, 'textarea_rows' => '12', 'tabindex' => bbp_get_tab_index(), 'tabfocus_elements' => 'bbp_topic_title,bbp_topic_tags', 'editor_class' => 'bbp-the-content', 'tinymce' => false, 'teeny' => true, 'quicktags' => true, 'dfw' => false), 'get_the_content');
    // If using tinymce, remove our escaping and trust tinymce
    if (bbp_use_wp_editor() && false !== $r['tinymce']) {
        remove_filter('bbp_get_form_forum_content', 'esc_textarea');
        remove_filter('bbp_get_form_topic_content', 'esc_textarea');
        remove_filter('bbp_get_form_reply_content', 'esc_textarea');
    }
    // Assume we are not editing
    $post_content = call_user_func('bbp_get_form_' . $r['context'] . '_content');
    // Start an output buffor
    ob_start();
    // Output something before the editor
    if (!empty($r['before'])) {
        echo $r['before'];
    }
    // Use TinyMCE if available
    if (bbp_use_wp_editor()) {
        // Enable additional TinyMCE plugins before outputting the editor
        add_filter('tiny_mce_plugins', 'bbp_get_tiny_mce_plugins');
        add_filter('teeny_mce_plugins', 'bbp_get_tiny_mce_plugins');
        add_filter('teeny_mce_buttons', 'bbp_get_teeny_mce_buttons');
        add_filter('quicktags_settings', 'bbp_get_quicktags_settings');
        // Output the editor
        wp_editor($post_content, 'bbp_' . $r['context'] . '_content', array('wpautop' => $r['wpautop'], 'media_buttons' => $r['media_buttons'], 'textarea_rows' => $r['textarea_rows'], 'tabindex' => $r['tabindex'], 'tabfocus_elements' => $r['tabfocus_elements'], 'editor_class' => $r['editor_class'], 'tinymce' => $r['tinymce'], 'teeny' => $r['teeny'], 'quicktags' => $r['quicktags'], 'dfw' => $r['dfw']));
        // Remove additional TinyMCE plugins after outputting the editor
        remove_filter('tiny_mce_plugins', 'bbp_get_tiny_mce_plugins');
        remove_filter('teeny_mce_plugins', 'bbp_get_tiny_mce_plugins');
        remove_filter('teeny_mce_buttons', 'bbp_get_teeny_mce_buttons');
        remove_filter('quicktags_settings', 'bbp_get_quicktags_settings');
        /**
         * Fallback to normal textarea.
         *
         * Note that we do not use esc_textarea() here to prevent double
         * escaping the editable output, mucking up existing content.
         */
    } else {
        ?>

			<textarea id="bbp_<?php 
        echo esc_attr($r['context']);
        ?>
_content" class="<?php 
        echo esc_attr($r['editor_class']);
        ?>
" name="bbp_<?php 
        echo esc_attr($r['context']);
        ?>
_content" cols="60" rows="<?php 
        echo esc_attr($r['textarea_rows']);
        ?>
" tabindex="<?php 
        echo esc_attr($r['tabindex']);
        ?>
"><?php 
        echo $post_content;
        ?>
</textarea>

		<?php 
    }
    // Output something after the editor
    if (!empty($r['after'])) {
        echo $r['after'];
    }
    // Put the output into a usable variable
    $output = ob_get_clean();
    return apply_filters('bbp_get_the_content', $output, $args, $post_content);
}
Пример #3
0
/**
 * Return a textarea or TinyMCE if enabled
 *
 * @since bbPress (r3586)
 *
 * @param array $args
 *
 * @uses apply_filter() To filter args and output
 * @uses wp_parse_pargs() To compare args
 * @uses bbp_use_wp_editor() To see if WP editor is in use
 * @uses bbp_is_edit() To see if we are editing something
 * @uses wp_editor() To output the WordPress editor
 *
 * @return string HTML from output buffer 
 */
function bbp_get_the_content($args = array())
{
    // Default arguments
    $defaults = array('context' => 'topic', 'before' => '<div class="bbp-the-content-wrapper">', 'after' => '</div>', 'wpautop' => true, 'media_buttons' => false, 'textarea_rows' => '6', 'tabindex' => bbp_get_tab_index(), 'editor_class' => 'bbp-the-content', 'tinymce' => true, 'quicktags' => true);
    $r = bbp_parse_args($args, $defaults, 'get_the_content');
    extract($r);
    // Assume we are not editing
    $post_content = '';
    // Start an output buffor
    ob_start();
    // Output something before the editor
    if (!empty($before)) {
        echo $before;
    }
    // Get sanitized content
    if (bbp_is_edit()) {
        $post_content = call_user_func('bbp_get_form_' . $context . '_content');
    }
    // Use TinyMCE if available
    if (bbp_use_wp_editor()) {
        $settings = array('wpautop' => $wpautop, 'media_buttons' => $media_buttons, 'textarea_rows' => $textarea_rows, 'tabindex' => $tabindex, 'editor_class' => $editor_class, 'tinymce' => $tinymce, 'quicktags' => $quicktags);
        wp_editor(htmlspecialchars_decode($post_content, ENT_QUOTES), 'bbp_' . $context . '_content', $settings);
        // Fallback to normal textarea
    } else {
        ?>

			<textarea id="bbp_<?php 
        echo $context;
        ?>
_content" class="<?php 
        echo $editor_class;
        ?>
" name="bbp_<?php 
        echo $context;
        ?>
_content" cols="60" rows="<?php 
        echo $textarea_rows;
        ?>
" tabindex="<?php 
        echo $tabindex;
        ?>
"><?php 
        echo $post_content;
        ?>
</textarea>

		<?php 
    }
    // Output something after the editor
    if (!empty($after)) {
        echo $after;
    }
    // Put the output into a usable variable
    $output = ob_get_contents();
    // Flush the output buffer
    ob_end_clean();
    return apply_filters('bbp_get_the_content', $output, $args, $post_content);
}
Пример #4
0
/**
 * Return the forum visibility dropdown
 *
 * @since bbPress (r3563)
 *
 * @param int $forum_id The forum id to use
 * @uses bbp_is_topic_edit() To check if it's the topic edit page
 * @uses bbp_get_forum_visibility() To get the forum visibility
 * @uses apply_filters()
 * @return string HTML select list for selecting forum visibility
 */
function bbp_get_form_forum_visibility_dropdown($args = '')
{
    // Backpat for handling passing of a forum ID
    if (is_int($args)) {
        $forum_id = (int) $args;
        $args = array();
    } else {
        $forum_id = 0;
    }
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('select_id' => 'bbp_forum_visibility', 'tab' => bbp_get_tab_index(), 'forum_id' => $forum_id, 'selected' => false), 'forum_type_select');
    // No specific selected value passed
    if (empty($r['selected'])) {
        // Post value is passed
        if (bbp_is_post_request() && isset($_POST[$r['select_id']])) {
            $r['selected'] = $_POST[$r['select_id']];
            // No Post value was passed
        } else {
            // Edit topic
            if (bbp_is_forum_edit()) {
                $r['forum_id'] = bbp_get_forum_id($r['forum_id']);
                $r['selected'] = bbp_get_forum_visibility($r['forum_id']);
                // New topic
            } else {
                $r['selected'] = bbp_get_public_status_id();
            }
        }
    }
    // Used variables
    $tab = !empty($r['tab']) ? ' tabindex="' . (int) $r['tab'] . '"' : '';
    // Start an output buffer, we'll finish it after the select loop
    ob_start();
    ?>

		<select name="<?php 
    echo esc_attr($r['select_id']);
    ?>
" id="<?php 
    echo esc_attr($r['select_id']);
    ?>
_select"<?php 
    echo $tab;
    ?>
>

			<?php 
    foreach (bbp_get_forum_visibilities() as $key => $label) {
        ?>

				<option value="<?php 
        echo esc_attr($key);
        ?>
"<?php 
        selected($key, $r['selected']);
        ?>
><?php 
        echo esc_html($label);
        ?>
</option>

			<?php 
    }
    ?>

		</select>

		<?php 
    // Return the results
    return apply_filters('bbp_get_form_forum_type_dropdown', ob_get_clean(), $r);
}
Пример #5
0
/**
 * Output the current tab index of a given form
 *
 * Use this function to handle the tab indexing of user facing forms within a
 * template file. Calling this function will automatically increment the global
 * tab index by default.
 *
 * @since 2.0.0 bbPress (r2810)
 *
 * @deprecated 2.6.0 bbPress (r5561)
 *
 * @link https://bbpress.trac.wordpress.org/attachment/ticket/2714 Trac Ticket
 * @param int $auto_increment Optional. Default true. Set to false to prevent
 *                             increment
 */
function bbp_tab_index($auto_increment = true)
{
    echo bbp_get_tab_index($auto_increment);
}
Пример #6
0
/**
 * Reply metabox
 *
 * The metabox that holds all of the additional reply information
 *
 * @since bbPress (r2464)
 *
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses do_action() Calls 'bbp_reply_metabox'
 */
function bbp_reply_metabox()
{
    // Post ID
    $post_id = get_the_ID();
    // Get some meta
    $reply_topic_id = bbp_get_reply_topic_id($post_id);
    $reply_forum_id = bbp_get_reply_forum_id($post_id);
    $reply_to = bbp_get_reply_to($post_id);
    // Allow individual manipulation of reply forum
    if (current_user_can('edit_others_replies') || current_user_can('moderate')) {
        ?>

		<p>
			<strong class="label"><?php 
        esc_html_e('Forum:', 'bbpress');
        ?>
</strong>
			<label class="screen-reader-text" for="bbp_forum_id"><?php 
        esc_html_e('Forum', 'bbpress');
        ?>
</label>
			<?php 
        bbp_dropdown(array('post_type' => bbp_get_forum_post_type(), 'selected' => $reply_forum_id, 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC', 'walker' => '', 'exclude' => '', 'select_id' => 'bbp_forum_id', 'tab' => bbp_get_tab_index(), 'options_only' => false, 'show_none' => __('&mdash; No parent &mdash;', 'bbpress'), 'disable_categories' => current_user_can('edit_forums'), 'disabled' => ''));
        ?>
		</p>

	<?php 
    }
    ?>

	<p>
		<strong class="label"><?php 
    esc_html_e('Topic:', 'bbpress');
    ?>
</strong>
		<label class="screen-reader-text" for="parent_id"><?php 
    esc_html_e('Topic', 'bbpress');
    ?>
</label>
		<input name="parent_id" id="bbp_topic_id" type="text" value="<?php 
    echo esc_attr($reply_topic_id);
    ?>
" />
	</p>

	<p>
		<strong class="label"><?php 
    esc_html_e('Reply To:', 'bbpress');
    ?>
</strong>
		<label class="screen-reader-text" for="bbp_reply_to"><?php 
    esc_html_e('Reply To', 'bbpress');
    ?>
</label>
		<input name="bbp_reply_to" id="bbp_reply_to" type="text" value="<?php 
    echo esc_attr($reply_to);
    ?>
" />
	</p>

	<input name="ping_status" type="hidden" id="ping_status" value="open" />

	<?php 
    wp_nonce_field('bbp_reply_metabox_save', 'bbp_reply_metabox');
    do_action('bbp_reply_metabox', $post_id);
}
Пример #7
0
		<div class="input-group">
			<span class="input-group-addon" id="search-addon"><span class="fa fa-search"></span></span>
			<input type="hidden" name="action" value="bbp-search-request" />
			<input tabindex="<?php 
echo esc_attr(bbp_get_tab_index());
?>
" type="text" name="bbp_search" class="form-control search-field" autocomplete="off" placeholder="<?php 
echo esc_attr_x('Search&hellip;', 'placeholder', 'barcelona');
?>
" title="<?php 
echo esc_attr_x('Search for:', 'label', 'barcelona');
?>
" value="<?php 
echo esc_attr(bbp_get_search_terms());
?>
" aria-describedby="search-addon" />
			<span class="input-group-btn">
				<button tabindex="<?php 
echo esc_attr(bbp_get_tab_index());
?>
" type="submit" class="btn">
					<span class="screen-reader-text btn-search-text"><?php 
echo esc_attr_x('Search', 'submit button', 'default');
?>
</span>
					<span class="btn-search-icon"><span class="fa fa-search"></span></span>
				</button>
			</span>
		</div>
	</div>
</form>
Пример #8
0
/**
 * Displays topic type select box (normal/sticky/super sticky)
 *
 * @since bbPress (r2784)
 *
 * @param $args This function supports these arguments:
 *  - stick_text: Sticky text
 *  - super_text: Super Sticky text
 *  - unstick_text: Unstick (normal) text
 *  - select_id: Select id. Defaults to bbp_stick_topic
 *  - tab: Tabindex
 *  - topic_id: Topic id
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_is_single_topic() To check if we're viewing a single topic
 * @uses bbp_is_topic_edit() To check if it is the topic edit page
 * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky
 * @uses bbp_is_topic_sticky() To check if the topic is a sticky
 */
function bbp_topic_type_select($args = '')
{
    $defaults = array('unstick_text' => __('Normal', 'bbpress'), 'stick_text' => __('Sticky', 'bbpress'), 'super_text' => __('Super Sticky', 'bbpress'), 'select_id' => 'bbp_stick_topic', 'tab' => bbp_get_tab_index(), 'topic_id' => 0);
    $r = bbp_parse_args($args, $defaults, 'topic_type_select');
    extract($r);
    // Edit topic
    if (bbp_is_single_topic() || bbp_is_topic_edit()) {
        // Get current topic id
        $topic_id = bbp_get_topic_id($topic_id);
        // Post value is passed
        if ('post' == strtolower($_SERVER['REQUEST_METHOD']) && isset($_POST[$select_id])) {
            $sticky_current = $_POST[$select_id];
            // Topic is super sticky
        } elseif (bbp_is_topic_super_sticky($topic_id)) {
            $sticky_current = 'super';
            // Topic is sticky or normal
        } else {
            $sticky_current = bbp_is_topic_sticky($topic_id, false) ? 'stick' : 'unstick';
        }
        // New topic
    } else {
        // Post value is passed
        if ('post' == strtolower($_SERVER['REQUEST_METHOD']) && isset($_POST[$select_id])) {
            $sticky_current = $_POST[$select_id];
            // Default to unstick
        } else {
            $sticky_current = 'unstick';
        }
    }
    // Used variables
    $tab = !empty($tab) ? ' tabindex="' . $tab . '"' : '';
    $select_id = esc_attr($select_id);
    $sticky_statuses = array('unstick' => $unstick_text, 'stick' => $stick_text, 'super' => $super_text);
    ?>

	<select name="<?php 
    echo $select_id;
    ?>
" id="<?php 
    echo $select_id;
    ?>
"<?php 
    echo $tab;
    ?>
>

		<?php 
    foreach ($sticky_statuses as $sticky_status => $label) {
        ?>

			<option value="<?php 
        echo $sticky_status;
        ?>
"<?php 
        selected($sticky_current, $sticky_status);
        ?>
><?php 
        echo $label;
        ?>
</option>

		<?php 
    }
    ?>

	</select>

	<?php 
}