first commit
This commit is contained in:
159
wp-content/plugins/bbpress/includes/common/ajax.php
Normal file
159
wp-content/plugins/bbpress/includes/common/ajax.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* bbPress Common AJAX Functions
|
||||
*
|
||||
* Common AJAX functions are ones that are used to setup and/or use during
|
||||
* bbPress specific, theme-side AJAX requests.
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage Ajax
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Output the URL to use for theme-side bbPress AJAX requests
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4543)
|
||||
*/
|
||||
function bbp_ajax_url() {
|
||||
echo esc_url( bbp_get_ajax_url() );
|
||||
}
|
||||
/**
|
||||
* Return the URL to use for theme-side bbPress AJAX requests
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4543)
|
||||
*
|
||||
* @global WP $wp
|
||||
* @return string
|
||||
*/
|
||||
function bbp_get_ajax_url() {
|
||||
global $wp;
|
||||
|
||||
$ssl = bbp_get_url_scheme();
|
||||
$url = trailingslashit( $wp->request );
|
||||
$base_url = home_url( $url, $ssl );
|
||||
$ajaxurl = add_query_arg( array( 'bbp-ajax' => 'true' ), $base_url );
|
||||
|
||||
// Filter & return
|
||||
return apply_filters( 'bbp_get_ajax_url', $ajaxurl );
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this a bbPress AJAX request?
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4543)
|
||||
*
|
||||
* @return bool Looking for bbp-ajax
|
||||
*/
|
||||
function bbp_is_ajax() {
|
||||
return (bool) ( ( isset( $_GET['bbp-ajax'] ) || isset( $_POST['bbp-ajax'] ) ) && ! empty( $_REQUEST['action'] ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Hooked to the 'bbp_template_redirect' action, this is also the custom
|
||||
* theme-side AJAX handler.
|
||||
*
|
||||
* This is largely taken from admin-ajax.php, but adapted specifically for
|
||||
* theme-side bbPress-only AJAX requests.
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4543)
|
||||
*
|
||||
* @param string $action Sanitized action from bbp_post_request/bbp_get_request
|
||||
*
|
||||
* @return If not a bbPress AJAX request
|
||||
*/
|
||||
function bbp_do_ajax( $action = '' ) {
|
||||
|
||||
// Bail if not a bbPress specific AJAX request
|
||||
if ( ! bbp_is_ajax() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set WordPress core AJAX constant for back-compat
|
||||
if ( ! defined( 'DOING_AJAX' ) ) {
|
||||
define( 'DOING_AJAX', true );
|
||||
}
|
||||
|
||||
// Setup AJAX headers
|
||||
bbp_ajax_headers();
|
||||
|
||||
// Compat for targeted action hooks (without $action param)
|
||||
$action = empty( $action )
|
||||
? sanitize_key( $_REQUEST['action'] ) // isset checked by bbp_is_ajax()
|
||||
: $action;
|
||||
|
||||
// Setup action key
|
||||
$key = "bbp_ajax_{$action}";
|
||||
|
||||
// Bail if no action is registered
|
||||
if ( empty( $action ) || ! has_action( $key ) ) {
|
||||
wp_die( '0', 400 );
|
||||
}
|
||||
|
||||
// Everything is 200 OK.
|
||||
bbp_set_200();
|
||||
|
||||
// Execute custom bbPress AJAX action
|
||||
do_action( $key );
|
||||
|
||||
// All done
|
||||
wp_die( '0' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Send headers for AJAX specific requests
|
||||
*
|
||||
* This was abstracted from bbp_do_ajax() for use in custom theme-side AJAX
|
||||
* implementations.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6757)
|
||||
*/
|
||||
function bbp_ajax_headers() {
|
||||
|
||||
// Set the header content type
|
||||
@header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
|
||||
@header( 'X-Robots-Tag: noindex' );
|
||||
|
||||
// Disable content sniffing in browsers that support it
|
||||
send_nosniff_header();
|
||||
|
||||
// Disable browser caching for all AJAX requests
|
||||
nocache_headers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to return JSON response for bbPress AJAX calls
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4542)
|
||||
*
|
||||
* @param bool $success
|
||||
* @param string $content
|
||||
* @param array $extras
|
||||
*/
|
||||
function bbp_ajax_response( $success = false, $content = '', $status = -1, $extras = array() ) {
|
||||
|
||||
// Set status to 200 if setting response as successful
|
||||
if ( ( true === $success ) && ( -1 === $status ) ) {
|
||||
$status = 200;
|
||||
}
|
||||
|
||||
// Setup the response array
|
||||
$response = array(
|
||||
'success' => $success,
|
||||
'status' => $status,
|
||||
'content' => $content
|
||||
);
|
||||
|
||||
// Merge extra response parameters in
|
||||
if ( ! empty( $extras ) && is_array( $extras ) ) {
|
||||
$response = array_merge( $response, $extras );
|
||||
}
|
||||
|
||||
// Send back the JSON
|
||||
@header( 'Content-type: application/json' );
|
||||
echo json_encode( $response );
|
||||
die();
|
||||
}
|
||||
511
wp-content/plugins/bbpress/includes/common/classes.php
Normal file
511
wp-content/plugins/bbpress/includes/common/classes.php
Normal file
@@ -0,0 +1,511 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* bbPress Classes
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage Classes
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
if ( ! class_exists( 'BBP_Component' ) ) :
|
||||
/**
|
||||
* bbPress Component Class
|
||||
*
|
||||
* The bbPress component class is responsible for simplifying the creation
|
||||
* of components that share similar behaviors and routines. It is used
|
||||
* internally by bbPress to create forums, topics and replies, but can be
|
||||
* extended to create other really neat things.
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage Classes
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2688)
|
||||
*/
|
||||
class BBP_Component {
|
||||
|
||||
/**
|
||||
* @var string Unique name (for internal identification)
|
||||
* @internal
|
||||
*/
|
||||
var $name;
|
||||
|
||||
/**
|
||||
* @var Unique ID (normally for custom post type)
|
||||
*/
|
||||
var $id;
|
||||
|
||||
/**
|
||||
* @var string Unique slug (used in query string and permalinks)
|
||||
*/
|
||||
var $slug;
|
||||
|
||||
/**
|
||||
* @var WP_Query The loop for this component
|
||||
*/
|
||||
var $query;
|
||||
|
||||
/**
|
||||
* @var string The current ID of the queried object
|
||||
*/
|
||||
var $current_id;
|
||||
|
||||
|
||||
/** Methods ***************************************************************/
|
||||
|
||||
/**
|
||||
* bbPress Component loader
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2700)
|
||||
*
|
||||
* @param array $args Required. Supports these args:
|
||||
* - name: Unique name (for internal identification)
|
||||
* - id: Unique ID (normally for custom post type)
|
||||
* - slug: Unique slug (used in query string and permalinks)
|
||||
* - query: The loop for this component (WP_Query)
|
||||
* - current_id: The current ID of the queried object
|
||||
*/
|
||||
public function __construct( $args = array() ) {
|
||||
if ( empty( $args ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->setup_globals( $args );
|
||||
$this->includes();
|
||||
$this->setup_actions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Component global variables
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2700)
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function setup_globals( $args = array() ) {
|
||||
$this->name = $args['name'];
|
||||
$this->id = apply_filters( 'bbp_' . $this->name . '_id', $args['id'] );
|
||||
$this->slug = apply_filters( 'bbp_' . $this->name . '_slug', $args['slug'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Include required files
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2700)
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function includes() {
|
||||
do_action( 'bbp_' . $this->name . 'includes' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the actions
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2700)
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function setup_actions() {
|
||||
add_action( 'bbp_register_post_types', array( $this, 'register_post_types' ), 10, 2 ); // Register post types
|
||||
add_action( 'bbp_register_taxonomies', array( $this, 'register_taxonomies' ), 10, 2 ); // Register taxonomies
|
||||
add_action( 'bbp_add_rewrite_tags', array( $this, 'add_rewrite_tags' ), 10, 2 ); // Add the rewrite tags
|
||||
add_action( 'bbp_generate_rewrite_rules', array( $this, 'generate_rewrite_rules' ), 10, 2 ); // Generate rewrite rules
|
||||
|
||||
// Additional actions can be attached here
|
||||
do_action( 'bbp_' . $this->name . 'setup_actions' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the component post types
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2700)
|
||||
*/
|
||||
public function register_post_types() {
|
||||
do_action( 'bbp_' . $this->name . '_register_post_types' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register component specific taxonomies
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2700)
|
||||
*/
|
||||
public function register_taxonomies() {
|
||||
do_action( 'bbp_' . $this->name . '_register_taxonomies' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add any additional rewrite tags
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2700)
|
||||
*/
|
||||
public function add_rewrite_tags() {
|
||||
do_action( 'bbp_' . $this->name . '_add_rewrite_tags' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate any additional rewrite rules
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2700)
|
||||
*/
|
||||
public function generate_rewrite_rules( $wp_rewrite ) {
|
||||
do_action_ref_array( 'bbp_' . $this->name . '_generate_rewrite_rules', $wp_rewrite );
|
||||
}
|
||||
}
|
||||
endif; // BBP_Component
|
||||
|
||||
if ( class_exists( 'Walker' ) ) :
|
||||
/**
|
||||
* Create HTML dropdown list of bbPress forums/topics.
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage Classes
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2746)
|
||||
*/
|
||||
class BBP_Walker_Dropdown extends Walker {
|
||||
|
||||
/**
|
||||
* @see Walker::$tree_type
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2746)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $tree_type = 'forum';
|
||||
|
||||
/**
|
||||
* @see Walker::$db_fields
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2746)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $db_fields = array(
|
||||
'parent' => 'post_parent',
|
||||
'id' => 'ID'
|
||||
);
|
||||
|
||||
/** Methods ***************************************************************/
|
||||
|
||||
/**
|
||||
* Set the tree_type
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2746)
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->tree_type = bbp_get_forum_post_type();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Walker::start_el()
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2746)
|
||||
*
|
||||
* @param string $output Passed by reference. Used to append additional
|
||||
* content.
|
||||
* @param object $object Post data object.
|
||||
* @param int $depth Depth of post in reference to parent posts. Used
|
||||
* for padding.
|
||||
* @param array $args Uses 'selected' argument for selected post to set
|
||||
* selected HTML attribute for option element.
|
||||
* @param int $current_object_id
|
||||
*/
|
||||
public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
|
||||
$pad = str_repeat( ' ', (int) $depth * 3 );
|
||||
$output .= '<option class="level-' . (int) $depth . '"';
|
||||
|
||||
// Disable the <option> if:
|
||||
// - we're told to do so
|
||||
// - the post type is a forum
|
||||
// - the forum is a category
|
||||
// - forum is closed
|
||||
if ( ( true === $args['disable_categories'] )
|
||||
&& ( bbp_get_forum_post_type() === $object->post_type )
|
||||
&& ( bbp_is_forum_category( $object->ID )
|
||||
|| ( ! current_user_can( 'edit_forum', $object->ID ) && bbp_is_forum_closed( $object->ID )
|
||||
)
|
||||
) ) {
|
||||
$output .= ' disabled="disabled" value=""';
|
||||
} else {
|
||||
$output .= ' value="' . (int) $object->ID .'"' . selected( $args['selected'], $object->ID, false );
|
||||
}
|
||||
|
||||
$output .= '>';
|
||||
$title = apply_filters( 'bbp_walker_dropdown_post_title', $object->post_title, $output, $object, $depth, $args );
|
||||
$output .= $pad . esc_html( $title );
|
||||
$output .= "</option>\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create hierarchical list of bbPress replies.
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage Classes
|
||||
*
|
||||
* @since 2.4.0 bbPress (r4944)
|
||||
*/
|
||||
class BBP_Walker_Reply extends Walker {
|
||||
|
||||
/**
|
||||
* @see Walker::$tree_type
|
||||
*
|
||||
* @since 2.4.0 bbPress (r4944)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $tree_type = 'reply';
|
||||
|
||||
/**
|
||||
* @see Walker::$db_fields
|
||||
*
|
||||
* @since 2.4.0 bbPress (r4944)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $db_fields = array(
|
||||
'parent' => 'reply_to',
|
||||
'id' => 'ID'
|
||||
);
|
||||
|
||||
/**
|
||||
* Confirm the tree_type
|
||||
*
|
||||
* @since 2.6.0 bbPress (r5389)
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->tree_type = bbp_get_reply_post_type();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Walker::start_lvl()
|
||||
*
|
||||
* @since 2.4.0 bbPress (r4944)
|
||||
*
|
||||
* @param string $output Passed by reference. Used to append additional content
|
||||
* @param int $depth Depth of reply
|
||||
* @param array $args Uses 'style' argument for type of HTML list
|
||||
*/
|
||||
public function start_lvl( &$output = '', $depth = 0, $args = array() ) {
|
||||
bbpress()->reply_query->reply_depth = (int) $depth + 1;
|
||||
|
||||
switch ( $args['style'] ) {
|
||||
case 'div':
|
||||
break;
|
||||
case 'ol':
|
||||
$output .= "<ol class='bbp-threaded-replies'>\n";
|
||||
break;
|
||||
case 'ul':
|
||||
default:
|
||||
$output .= "<ul class='bbp-threaded-replies'>\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Walker::end_lvl()
|
||||
*
|
||||
* @since 2.4.0 bbPress (r4944)
|
||||
*
|
||||
* @param string $output Passed by reference. Used to append additional content
|
||||
* @param int $depth Depth of reply
|
||||
* @param array $args Will only append content if style argument value is 'ol' or 'ul'
|
||||
*/
|
||||
public function end_lvl( &$output = '', $depth = 0, $args = array() ) {
|
||||
bbpress()->reply_query->reply_depth = (int) $depth + 1;
|
||||
|
||||
switch ( $args['style'] ) {
|
||||
case 'div':
|
||||
break;
|
||||
case 'ol':
|
||||
$output .= "</ol>\n";
|
||||
break;
|
||||
case 'ul':
|
||||
default:
|
||||
$output .= "</ul>\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.4.0 bbPress (r4944)
|
||||
*/
|
||||
public function display_element( $element = false, &$children_elements = array(), $max_depth = 0, $depth = 0, $args = array(), &$output = '' ) {
|
||||
|
||||
if ( empty( $element ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get element's id
|
||||
$id_field = $this->db_fields['id'];
|
||||
$id = $element->$id_field;
|
||||
|
||||
// Display element
|
||||
parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
|
||||
|
||||
// If we're at the max depth and the current element still has children, loop over those
|
||||
// and display them at this level to prevent them being orphaned to the end of the list.
|
||||
if ( ( $max_depth <= (int) $depth + 1 ) && isset( $children_elements[ $id ] ) ) {
|
||||
foreach ( $children_elements[ $id ] as $child ) {
|
||||
$this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );
|
||||
}
|
||||
unset( $children_elements[ $id ] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Walker:start_el()
|
||||
*
|
||||
* @since 2.4.0 bbPress (r4944)
|
||||
*/
|
||||
public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
|
||||
|
||||
// Set up reply
|
||||
$depth++;
|
||||
bbpress()->reply_query->reply_depth = (int) $depth;
|
||||
bbpress()->reply_query->post = $object;
|
||||
bbpress()->current_reply_id = $object->ID;
|
||||
|
||||
// Check for a callback and use it if specified
|
||||
if ( ! empty( $args['callback'] ) ) {
|
||||
ob_start();
|
||||
call_user_func( $args['callback'], $object, $args, $depth );
|
||||
$output .= ob_get_clean();
|
||||
return;
|
||||
}
|
||||
|
||||
// Style for div or list element
|
||||
if ( ! empty( $args['style'] ) && ( 'div' === $args['style'] ) ) {
|
||||
$output .= "<div>\n";
|
||||
} else {
|
||||
$output .= "<li>\n";
|
||||
}
|
||||
|
||||
$output .= bbp_buffer_template_part( 'loop', 'single-reply', false );
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.4.0 bbPress (r4944)
|
||||
*/
|
||||
public function end_el( &$output = '', $object = false, $depth = 0, $args = array() ) {
|
||||
|
||||
// Check for a callback and use it if specified
|
||||
if ( ! empty( $args['end-callback'] ) ) {
|
||||
ob_start();
|
||||
call_user_func( $args['end-callback'], $object, $args, $depth );
|
||||
$output .= ob_get_clean();
|
||||
return;
|
||||
}
|
||||
|
||||
// Style for div or list element
|
||||
if ( ! empty( $args['style'] ) && ( 'div' === $args['style'] ) ) {
|
||||
$output .= "</div>\n";
|
||||
} else {
|
||||
$output .= "</li>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create HTML dropdown list of bbPress replies.
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage Classes
|
||||
*
|
||||
* @since 2.6.0 bbPress (r5389)
|
||||
*/
|
||||
class BBP_Walker_Reply_Dropdown extends Walker {
|
||||
|
||||
/**
|
||||
* @see Walker::$tree_type
|
||||
*
|
||||
* @since 2.6.0 bbPress (r5389)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $tree_type = 'reply';
|
||||
|
||||
/**
|
||||
* @see Walker::$db_fields
|
||||
*
|
||||
* @since 2.6.0 bbPress (r5389)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $db_fields = array(
|
||||
'parent' => 'reply_to',
|
||||
'id' => 'ID'
|
||||
);
|
||||
|
||||
/** Methods ***************************************************************/
|
||||
|
||||
/**
|
||||
* Confirm the tree_type
|
||||
*
|
||||
* @since 2.6.0 bbPress (r5389)
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->tree_type = bbp_get_reply_post_type();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Walker::start_el()
|
||||
*
|
||||
* @since 2.6.0 bbPress (r5389)
|
||||
*
|
||||
* @param string $output Passed by reference. Used to append additional
|
||||
* content.
|
||||
*
|
||||
* @param object $object Post data object.
|
||||
*
|
||||
* @param int $depth Depth of post in reference to parent posts. Used
|
||||
* for padding.
|
||||
*
|
||||
* @param array $args Uses 'selected' argument for selected post to set
|
||||
* selected HTML attribute for option element.
|
||||
*
|
||||
* @param int $current_object_id Not Used
|
||||
*/
|
||||
public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
|
||||
|
||||
// Set up reply
|
||||
$depth++;
|
||||
|
||||
// Get the reply ID
|
||||
if ( isset( $args['exclude'][0] ) ) {
|
||||
$reply_id = (int) $args['exclude'][0];
|
||||
} else {
|
||||
$reply_id = bbp_get_reply_id();
|
||||
}
|
||||
|
||||
// Get ancestors to determine which items to disable
|
||||
$ancestors = bbp_get_reply_ancestors( $object->ID );
|
||||
array_push( $ancestors, $object->ID );
|
||||
|
||||
// Determine the indentation
|
||||
$pad = str_repeat( ' ', (int) $depth * 3 );
|
||||
|
||||
// Determine reply title (either post_title, or excerpt of post_content)
|
||||
$title = ! empty( $object->post_title ) ? $object->post_title : wp_html_excerpt( $object->post_content, 10 );
|
||||
$title = sprintf( esc_html__( '%1$s - %2$s', 'bbpress' ), (int) $object->ID, $title );
|
||||
$title = apply_filters( 'bbp_walker_dropdown_post_title', $title, $output, $object, $depth, $args );
|
||||
|
||||
// Attributes
|
||||
$class = 'level-' . (int) $depth;
|
||||
$value = (int) $object->ID;
|
||||
|
||||
// Start an output buffer to make late escaping easier
|
||||
ob_start(); ?>
|
||||
|
||||
<option class="<?php echo esc_attr( $class ); ?>" value="<?php echo esc_attr( $value ); ?>"<?php selected( $args['selected'], $object->ID ); ?> <?php disabled( in_array( $reply_id, $ancestors ), true ); ?>><?php echo $pad . esc_html( $title ); ?></option>
|
||||
|
||||
<?php
|
||||
|
||||
// Append the output buffer to the $output variable
|
||||
$output .= ob_get_clean();
|
||||
}
|
||||
}
|
||||
endif; // class_exists check
|
||||
963
wp-content/plugins/bbpress/includes/common/engagements.php
Normal file
963
wp-content/plugins/bbpress/includes/common/engagements.php
Normal file
@@ -0,0 +1,963 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* bbPress Common Engagements
|
||||
*
|
||||
* This file contains the common classes and functions for interacting with the
|
||||
* bbPress engagements API. See `includes/users/engagements.php` for more.
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage Common
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Return the strategy used for storing user engagements
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6722)
|
||||
*
|
||||
* @param string $rel_key The key used to index this relationship
|
||||
* @param string $rel_type The type of meta to look in
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function bbp_user_engagements_interface( $rel_key = '', $rel_type = 'post' ) {
|
||||
return apply_filters( 'bbp_user_engagements_interface', bbpress()->engagements, $rel_key, $rel_type );
|
||||
}
|
||||
|
||||
/**
|
||||
* Base strategy class for interfacing with User Engagements, which other
|
||||
* classes will extend.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6722)
|
||||
*/
|
||||
class BBP_User_Engagements_Base {
|
||||
|
||||
/**
|
||||
* Type of strategy being used.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6737)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type = '';
|
||||
|
||||
/**
|
||||
* Add a user id to an object
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6722)
|
||||
*
|
||||
* @param int $object_id The object id
|
||||
* @param int $user_id The user id
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
* @param bool $unique Whether meta key should be unique to the object
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function add_user_to_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post', $unique = false ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a user id from an object
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6722)
|
||||
*
|
||||
* @param int $object_id The object id
|
||||
* @param int $user_id The user id
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function remove_user_from_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a user id from all objects
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6722)
|
||||
*
|
||||
* @param int $user_id The user id
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function remove_user_from_all_objects( $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an object from all users
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6722)
|
||||
*
|
||||
* @param int $object_id The object id
|
||||
* @param int $user_id The user id
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function remove_object_from_all_users( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all users from all objects
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6722)
|
||||
*
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function remove_all_users_from_all_objects( $meta_key = '', $meta_type = 'post' ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get users of an object
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6722)
|
||||
*
|
||||
* @param int $object_id The object id
|
||||
* @param string $meta_key The key used to index this relationship
|
||||
* @param string $meta_type The type of meta to look in
|
||||
*
|
||||
* @return array Returns ids of users
|
||||
*/
|
||||
public function get_users_for_object( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the part of the query responsible for JOINing objects to relationships.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6737)
|
||||
*
|
||||
* @param array $args
|
||||
* @param string $meta_key
|
||||
* @param string $meta_type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_query( $args = array(), $context_key = '', $meta_key = '', $meta_type = 'post' ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Meta strategy for interfacing with User Engagements
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6722)
|
||||
*/
|
||||
class BBP_User_Engagements_Meta extends BBP_User_Engagements_Base {
|
||||
|
||||
/**
|
||||
* Type of strategy being used.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6737)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'meta';
|
||||
|
||||
/**
|
||||
* Add a user id to an object
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6722)
|
||||
*
|
||||
* @param int $object_id The object id
|
||||
* @param int $user_id The user id
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
* @param bool $unique Whether meta key should be unique to the object
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function add_user_to_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post', $unique = false ) {
|
||||
return add_metadata( $meta_type, $object_id, $meta_key, $user_id, $unique );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a user id from an object
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6722)
|
||||
*
|
||||
* @param int $object_id The object id
|
||||
* @param int $user_id The user id
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function remove_user_from_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
|
||||
return delete_metadata( $meta_type, $object_id, $meta_key, $user_id, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a user id from all objects
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6722)
|
||||
*
|
||||
* @param int $user_id The user id
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function remove_user_from_all_objects( $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
|
||||
return delete_metadata( $meta_type, null, $meta_key, $user_id, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an object from all users
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6722)
|
||||
*
|
||||
* @param int $object_id The object id
|
||||
* @param int $user_id The user id
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function remove_object_from_all_users( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {
|
||||
return delete_metadata( $meta_type, $object_id, $meta_key, null, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all users from all objects
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6722)
|
||||
*
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function remove_all_users_from_all_objects( $meta_key = '', $meta_type = 'post' ) {
|
||||
return delete_metadata( $meta_type, null, $meta_key, null, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get users of an object
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6722)
|
||||
*
|
||||
* @param int $object_id The object id
|
||||
* @param string $meta_key The key used to index this relationship
|
||||
* @param string $meta_type The type of meta to look in
|
||||
*
|
||||
* @return array Returns ids of users
|
||||
*/
|
||||
public function get_users_for_object( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {
|
||||
return wp_parse_id_list( get_metadata( $meta_type, $object_id, $meta_key, false ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the part of the query responsible for JOINing objects to relationships.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6737)
|
||||
*
|
||||
* @param array $args
|
||||
* @param string $meta_key
|
||||
* @param string $meta_type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_query( $args = array(), $context_key = '', $meta_key = '', $meta_type = 'post' ) {
|
||||
|
||||
// Backwards compat for pre-2.6.0
|
||||
if ( is_numeric( $args ) ) {
|
||||
$args = array(
|
||||
'meta_query' => array( array(
|
||||
'key' => $meta_key,
|
||||
'value' => bbp_get_user_id( $args, false, false ),
|
||||
'compare' => 'NUMERIC'
|
||||
) )
|
||||
);
|
||||
}
|
||||
|
||||
// Default arguments
|
||||
$defaults = array(
|
||||
'meta_query' => array( array(
|
||||
'key' => $meta_key,
|
||||
'value' => bbp_get_displayed_user_id(),
|
||||
'compare' => 'NUMERIC'
|
||||
) )
|
||||
);
|
||||
|
||||
// Parse arguments
|
||||
return bbp_parse_args( $args, $defaults, $context_key );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Term strategy for interfacing with User Engagements
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6737)
|
||||
*/
|
||||
class BBP_User_Engagements_Term extends BBP_User_Engagements_Base {
|
||||
|
||||
/**
|
||||
* Type of strategy being used.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6737)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'term';
|
||||
|
||||
/**
|
||||
* Register an engagement taxonomy just-in-time for immediate use
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6737)
|
||||
*
|
||||
* @param string $tax_key
|
||||
* @param string $object_type
|
||||
*/
|
||||
private function jit_taxonomy( $tax_key = '', $object_type = 'user' ) {
|
||||
|
||||
// Bail if taxonomy already exists
|
||||
if ( taxonomy_exists( $tax_key ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Register the taxonomy
|
||||
register_taxonomy( $tax_key, 'bbp_' . $object_type, array(
|
||||
'labels' => array(),
|
||||
'description' => '',
|
||||
'public' => false,
|
||||
'publicly_queryable' => false,
|
||||
'hierarchical' => false,
|
||||
'show_ui' => false,
|
||||
'show_in_menu' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'show_tagcloud' => false,
|
||||
'show_in_quick_edit' => false,
|
||||
'show_admin_column' => false,
|
||||
'meta_box_cb' => false,
|
||||
'capabilities' => array(),
|
||||
'rewrite' => false,
|
||||
'query_var' => '',
|
||||
'update_count_callback' => '',
|
||||
'show_in_rest' => false,
|
||||
'rest_base' => false,
|
||||
'rest_controller_class' => false,
|
||||
'_builtin' => false
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a user id to an object
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6737)
|
||||
*
|
||||
* @param int $object_id The object id
|
||||
* @param int $user_id The user id
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
* @param bool $unique Whether meta key should be unique to the object
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function add_user_to_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post', $unique = false ) {
|
||||
$user_key = "{$meta_key}_user_id_{$user_id}";
|
||||
$tax_key = "{$meta_key}_{$meta_type}";
|
||||
$this->jit_taxonomy( $tax_key );
|
||||
|
||||
return wp_add_object_terms( $object_id, $user_key, $tax_key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a user id from an object
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6737)
|
||||
*
|
||||
* @param int $object_id The object id
|
||||
* @param int $user_id The user id
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function remove_user_from_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
|
||||
$user_key = "{$meta_key}_user_id_{$user_id}";
|
||||
$tax_key = "{$meta_key}_{$meta_type}";
|
||||
$this->jit_taxonomy( $tax_key );
|
||||
|
||||
return wp_remove_object_terms( $object_id, $user_key, $tax_key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a user id from all objects
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6737)
|
||||
*
|
||||
* @param int $user_id The user id
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function remove_user_from_all_objects( $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
|
||||
$user_key = "{$meta_key}_user_id_{$user_id}";
|
||||
$tax_key = "{$meta_key}_{$meta_type}";
|
||||
$this->jit_taxonomy( $tax_key );
|
||||
$term = get_term_by( 'slug', $user_key, $tax_key );
|
||||
|
||||
return wp_delete_term( $term->term_id, $tax_key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an object from all users
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6737)
|
||||
*
|
||||
* @param int $object_id The object id
|
||||
* @param int $user_id The user id
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function remove_object_from_all_users( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {
|
||||
return wp_delete_object_term_relationships( $object_id, get_object_taxonomies( 'bbp_user' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all users from all objects
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6737)
|
||||
*
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function remove_all_users_from_all_objects( $meta_key = '', $meta_type = 'post' ) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Get users of an object
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6737)
|
||||
*
|
||||
* @param int $object_id The object id
|
||||
* @param string $meta_key The key used to index this relationship
|
||||
* @param string $meta_type The type of meta to look in
|
||||
*
|
||||
* @return array Returns ids of users
|
||||
*/
|
||||
public function get_users_for_object( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {
|
||||
$user_key = "{$meta_key}_user_id_";
|
||||
$tax_key = "{$meta_key}_{$meta_type}";
|
||||
$this->jit_taxonomy( $tax_key );
|
||||
|
||||
// Get terms
|
||||
$terms = get_terms( array(
|
||||
'object_ids' => $object_id,
|
||||
'taxonomy' => $tax_key
|
||||
) );
|
||||
|
||||
// Slug part to replace
|
||||
$user_ids = array();
|
||||
|
||||
// Loop through terms and get the user ID
|
||||
foreach ( $terms as $term ) {
|
||||
$user_ids[] = str_replace( $user_key, '', $term->slug );
|
||||
}
|
||||
|
||||
// Parse & return
|
||||
return wp_parse_id_list( $user_ids );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the part of the query responsible for JOINing objects to relationships.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6737)
|
||||
*
|
||||
* @param array $args
|
||||
* @param string $meta_key
|
||||
* @param string $meta_type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_query( $args = array(), $context_key = '', $meta_key = '', $meta_type = 'post' ) {
|
||||
$tax_key = "{$meta_key}_{$meta_type}";
|
||||
$user_key = "{$meta_key}_user_id_";
|
||||
|
||||
// Make sure the taxonomy is registered
|
||||
$this->jit_taxonomy( $tax_key );
|
||||
|
||||
// Backwards compat for pre-2.6.0
|
||||
if ( is_numeric( $args ) ) {
|
||||
$args = array(
|
||||
'tax_query' => array( array(
|
||||
'taxonomy' => $tax_key,
|
||||
'terms' => $user_key . bbp_get_user_id( $args, false, false ),
|
||||
'field' => 'slug'
|
||||
) )
|
||||
);
|
||||
}
|
||||
|
||||
// Default arguments
|
||||
$defaults = array(
|
||||
'tax_query' => array( array(
|
||||
'taxonomy' => $tax_key,
|
||||
'terms' => $user_key . bbp_get_displayed_user_id(),
|
||||
'field' => 'slug'
|
||||
) )
|
||||
);
|
||||
|
||||
// Parse arguments
|
||||
return bbp_parse_args( $args, $defaults, $context_key );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* User strategy for interfacing with User Engagements
|
||||
*
|
||||
* This strategy largely exists for backwards compatibility with bbPress 2.5,
|
||||
* or installations that have not upgraded their databases to 2.6 or above.
|
||||
*
|
||||
* Note: this strategy is going to be a bit less tidy than the others, because
|
||||
* it needs to do weird things to maintain the 2.5 status-quo. Do not use this
|
||||
* strategy as an example when building your own.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6844)
|
||||
*/
|
||||
class BBP_User_Engagements_User extends BBP_User_Engagements_Base {
|
||||
|
||||
/**
|
||||
* Type of strategy being used.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6844)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'user';
|
||||
|
||||
/**
|
||||
* Private function to map 2.6 meta keys to 2.5 user-option keys.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6844)
|
||||
*
|
||||
* @param string $meta_key
|
||||
* @param int $object_id
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_user_option_key( $meta_key = '', $object_id = 0, $prefix = false ) {
|
||||
switch ( $meta_key ) {
|
||||
|
||||
// Favorites
|
||||
case '_bbp_favorite' :
|
||||
$key = '_bbp_favorites';
|
||||
break;
|
||||
|
||||
// Subscriptions
|
||||
case '_bbp_subscription' :
|
||||
|
||||
// Maybe guess at post type
|
||||
$post_type = ! empty( $object_id )
|
||||
? get_post_type( $object_id )
|
||||
: bbp_get_topic_post_type();
|
||||
|
||||
// Forums & Topics used different keys :/
|
||||
$key = ( bbp_get_forum_post_type() === $post_type )
|
||||
? '_bbp_forum_subscriptions'
|
||||
: '_bbp_subscriptions';
|
||||
|
||||
break;
|
||||
|
||||
// Unknown, so pluralize
|
||||
default :
|
||||
$key = "{$meta_key}s";
|
||||
break;
|
||||
}
|
||||
|
||||
// Maybe prefix the key (for use in raw database queries)
|
||||
if ( true === $prefix ) {
|
||||
$key = bbp_db()->get_blog_prefix() . $key;
|
||||
}
|
||||
|
||||
// Return the old (pluralized) user option key
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private function to get a 2.5 compatible cache key.
|
||||
*
|
||||
* This method exists to provide backwards compatibility with bbPress 2.5,
|
||||
* which had caching surrounding the FIND_IN_SET usermeta queries.
|
||||
*
|
||||
* @since 2.6.3 bbPress (r6991)
|
||||
*
|
||||
* @param string $meta_key
|
||||
* @param int $object_id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_cache_key( $meta_key = '', $object_id = 0 ) {
|
||||
|
||||
// No negative numbers in cache keys (zero is weird, but not disallowed)
|
||||
$object_id = absint( $object_id );
|
||||
|
||||
// Maybe guess at post type
|
||||
$post_type = ! empty( $object_id )
|
||||
? get_post_type( $object_id )
|
||||
: bbp_get_topic_post_type();
|
||||
|
||||
switch ( $meta_key ) {
|
||||
|
||||
// Favorites
|
||||
case '_bbp_favorite' :
|
||||
$key = 'bbp_get_topic_favoriters_';
|
||||
break;
|
||||
|
||||
// Subscriptions
|
||||
case '_bbp_subscription' :
|
||||
|
||||
// Forums & Topics used different keys :/
|
||||
$key = ( bbp_get_forum_post_type() === $post_type )
|
||||
? 'bbp_get_forum_subscribers_'
|
||||
: 'bbp_get_topic_subscribers_';
|
||||
|
||||
break;
|
||||
|
||||
// Unknown, so pluralize
|
||||
default :
|
||||
$nounize = rtrim( $meta_key, 'e' );
|
||||
$key = "bbp_get_{$post_type}_{$nounize}ers_";
|
||||
break;
|
||||
}
|
||||
|
||||
// Return the old (pluralized) user option key with object ID appended
|
||||
return "{$key}{$object_id}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user engagement cache for a given meta key and object ID.
|
||||
*
|
||||
* This method exists to provide backwards compatibility with bbPress 2.5,
|
||||
* which had caching surrounding the FIND_IN_SET queries in usermeta.
|
||||
*
|
||||
* @since 2.6.3 bbPress (r6991)
|
||||
*
|
||||
* @param string $meta_key
|
||||
* @param int $object_id
|
||||
*
|
||||
* @return mixed Results from cache get
|
||||
*/
|
||||
private function cache_get( $meta_key = '', $object_id = 0 ) {
|
||||
$cache_key = $this->get_cache_key( $meta_key, $object_id );
|
||||
|
||||
return wp_cache_get( $cache_key, 'bbpress_engagements' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user engagement cache for a given meta key and object ID.
|
||||
*
|
||||
* This method exists to provide backwards compatibility with bbPress 2.5,
|
||||
* which had caching surrounding the FIND_IN_SET queries in usermeta.
|
||||
*
|
||||
* @since 2.6.3 bbPress (r6991)
|
||||
*
|
||||
* @param string $meta_key
|
||||
* @param int $object_id
|
||||
*
|
||||
* @return mixed Results from cache set
|
||||
*/
|
||||
private function cache_set( $meta_key = '', $object_id = 0, $user_ids = array() ) {
|
||||
$cache_key = $this->get_cache_key( $meta_key, $object_id );
|
||||
$user_ids = $this->parse_comma_list( $user_ids );
|
||||
|
||||
return wp_cache_set( $cache_key, $user_ids, 'bbpress_engagements' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the user engagement cache for a given meta key and object ID.
|
||||
*
|
||||
* This method exists to provide backwards compatibility with bbPress 2.5,
|
||||
* which had caching surrounding the FIND_IN_SET queries in usermeta.
|
||||
*
|
||||
* @since 2.6.3 bbPress (r6991)
|
||||
*
|
||||
* @param string $meta_key
|
||||
* @param int $object_id
|
||||
*
|
||||
* @return mixed Results from cache delete
|
||||
*/
|
||||
private function cache_delete( $meta_key = '', $object_id = 0 ) {
|
||||
$cache_key = $this->get_cache_key( $meta_key, $object_id );
|
||||
|
||||
return wp_cache_delete( $cache_key, 'bbpress_engagements' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a comma-separated string into an array of integers
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6844)
|
||||
*
|
||||
* @param string $results
|
||||
* @return array
|
||||
*/
|
||||
private function parse_comma_list( $results = '' ) {
|
||||
return array_filter( wp_parse_id_list( $results ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a user id to an object
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6844)
|
||||
*
|
||||
* @param int $object_id The object id
|
||||
* @param int $user_id The user id
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
* @param bool $unique Whether meta key should be unique to the object
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function add_user_to_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post', $unique = false ) {
|
||||
$retval = false;
|
||||
$option_key = $this->get_user_option_key( $meta_key, $object_id );
|
||||
$object_ids = $this->parse_comma_list( get_user_option( $option_key, $user_id ) );
|
||||
$exists = array_search( $object_id, $object_ids );
|
||||
|
||||
// Not already added, so add it
|
||||
if ( false === $exists ) {
|
||||
$object_ids[] = $object_id;
|
||||
$object_ids = implode( ',', $this->parse_comma_list( $object_ids ) );
|
||||
$retval = update_user_option( $user_id, $option_key, $object_ids );
|
||||
|
||||
// Delete cache if successful (accounts for int & true)
|
||||
if ( false !== $retval ) {
|
||||
$this->cache_delete( $meta_key, $object_id );
|
||||
}
|
||||
}
|
||||
|
||||
// Return true if added, or false if not
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a user id from an object
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6844)
|
||||
*
|
||||
* @param int $object_id The object id
|
||||
* @param int $user_id The user id
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function remove_user_from_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
|
||||
$retval = false;
|
||||
$option_key = $this->get_user_option_key( $meta_key, $object_id );
|
||||
$object_ids = $this->parse_comma_list( get_user_option( $option_key, $user_id ) );
|
||||
$exists = array_search( $object_id, $object_ids );
|
||||
|
||||
// Exists, so remove it
|
||||
if ( false !== $exists ) {
|
||||
unset( $object_ids[ $exists ] );
|
||||
|
||||
$object_ids = implode( ',', $this->parse_comma_list( $object_ids ) );
|
||||
$retval = ! empty( $object_ids )
|
||||
? update_user_option( $user_id, $option_key, $object_ids )
|
||||
: delete_user_option( $user_id, $option_key );
|
||||
|
||||
// Delete cache if successful (accounts for int & true)
|
||||
if ( false !== $retval ) {
|
||||
$this->cache_delete( $meta_key, $object_id );
|
||||
}
|
||||
}
|
||||
|
||||
// Return true if removed, or false if not
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a user id from all objects
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6844)
|
||||
*
|
||||
* @param int $user_id The user id
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function remove_user_from_all_objects( $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
|
||||
|
||||
// Get the key
|
||||
$option_key = $this->get_user_option_key( $meta_key );
|
||||
|
||||
// Get the option
|
||||
$object_ids = $this->parse_comma_list( get_user_option( $option_key, $user_id ) );
|
||||
|
||||
// Attempt to delete the user option
|
||||
$retval = delete_user_option( $user_id, $option_key );
|
||||
|
||||
// Try to delete caches, but only if everything else succeeded
|
||||
if ( ! empty( $retval ) && ! empty( $object_ids ) ) {
|
||||
foreach ( $object_ids as $object_id ) {
|
||||
$this->cache_delete( $meta_key, $object_id );
|
||||
}
|
||||
}
|
||||
|
||||
// Return true if user was removed, or false if not
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an object from all users
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6844)
|
||||
*
|
||||
* @param int $object_id The object id
|
||||
* @param int $user_id The user id
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function remove_object_from_all_users( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {
|
||||
|
||||
// Query for users
|
||||
$user_ids = $this->get_users_for_object( $object_id, $meta_key, $meta_type );
|
||||
$u_count = count( $user_ids );
|
||||
|
||||
// Count number of removals
|
||||
$removed = array();
|
||||
$r_count = 0;
|
||||
|
||||
// Users have engaged, so remove them
|
||||
if ( ! empty( $u_count ) ) {
|
||||
|
||||
// Loop through users and remove them from the object
|
||||
foreach ( $user_ids as $user_id ) {
|
||||
$removed[] = $this->remove_user_from_object( $object_id, $user_id, $meta_key, $meta_type );
|
||||
}
|
||||
|
||||
// Count the removed users
|
||||
$r_count = count( $removed );
|
||||
}
|
||||
|
||||
// Return true if successfully removed from all users
|
||||
return ( $r_count === $u_count );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all users from all objects
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6844)
|
||||
*
|
||||
* @param string $meta_key The relationship key
|
||||
* @param string $meta_type The relationship type (usually 'post')
|
||||
*
|
||||
* @return bool Returns true on success, false on failure
|
||||
*/
|
||||
public function remove_all_users_from_all_objects( $meta_key = '', $meta_type = 'post' ) {
|
||||
|
||||
// Query for users
|
||||
$option_key = $this->get_user_option_key( $meta_key, 0, true );
|
||||
$bbp_db = bbp_db();
|
||||
$user_ids = $bbp_db->get_col( "SELECT user_id FROM {$bbp_db->usermeta} WHERE meta_key = '{$option_key}'" );
|
||||
$u_count = count( $user_ids );
|
||||
|
||||
// Count number of removals
|
||||
$removed = array();
|
||||
$r_count = 0;
|
||||
|
||||
// Users have engaged, so remove them
|
||||
if ( ! empty( $u_count ) ) {
|
||||
|
||||
// Loop through users and remove their user options
|
||||
foreach ( $user_ids as $user_id ) {
|
||||
$removed[] = $this->remove_user_from_all_objects( $user_id, $meta_key );
|
||||
}
|
||||
|
||||
// Count the removed users
|
||||
$r_count = count( $removed );
|
||||
}
|
||||
|
||||
// Return true if successfully removed from all users
|
||||
return ( $r_count === $u_count );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get users of an object
|
||||
*
|
||||
* The database queries in this function were cached in bbPress versions
|
||||
* older than 2.6, but no longer are to avoid cache pollution.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6844)
|
||||
*
|
||||
* @param int $object_id The object id
|
||||
* @param string $meta_key The key used to index this relationship
|
||||
* @param string $meta_type The type of meta to look in
|
||||
*
|
||||
* @return array Returns ids of users
|
||||
*/
|
||||
public function get_users_for_object( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {
|
||||
|
||||
// Try to get user IDs from cache
|
||||
$user_ids = $this->cache_get( $meta_key, $object_id );
|
||||
|
||||
// Cache is empty, so hit the database
|
||||
if ( false === $user_ids ) {
|
||||
$option_key = $this->get_user_option_key( $meta_key, $object_id, true );
|
||||
$bbp_db = bbp_db();
|
||||
$user_ids = $bbp_db->get_col( "SELECT user_id FROM {$bbp_db->usermeta} WHERE meta_key = '{$option_key}' and FIND_IN_SET('{$object_id}', meta_value) > 0" );
|
||||
|
||||
// Always cache results (even if empty, to prevent multiple misses)
|
||||
$this->cache_set( $meta_key, $object_id, $user_ids );
|
||||
}
|
||||
|
||||
// Return parsed IDs
|
||||
return $this->parse_comma_list( $user_ids );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the part of the query responsible for JOINing objects to relationships.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6844)
|
||||
*
|
||||
* @param array $args
|
||||
* @param string $meta_key
|
||||
* @param string $meta_type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_query( $args = array(), $context_key = '', $meta_key = '', $meta_type = 'post' ) {
|
||||
$user_id = bbp_get_user_id( $args, true, true );
|
||||
$option_key = $this->get_user_option_key( $meta_key );
|
||||
$object_ids = $this->parse_comma_list( get_user_option( $option_key, $user_id ) );
|
||||
|
||||
// Maybe trick WP_Query into ".ID IN (0)" to return no results
|
||||
if ( empty( $object_ids ) ) {
|
||||
$object_ids = array( 0 );
|
||||
}
|
||||
|
||||
// Maybe include these post IDs
|
||||
$args = array(
|
||||
'post__in' => $object_ids
|
||||
);
|
||||
|
||||
// Parse arguments
|
||||
return bbp_parse_args( $args, array(), $context_key );
|
||||
}
|
||||
}
|
||||
784
wp-content/plugins/bbpress/includes/common/formatting.php
Normal file
784
wp-content/plugins/bbpress/includes/common/formatting.php
Normal file
@@ -0,0 +1,784 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* bbPress Formatting
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage Formatting
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/** Kses **********************************************************************/
|
||||
|
||||
/**
|
||||
* Custom allowed tags for forum topics and replies
|
||||
*
|
||||
* Allows all users to post links, quotes, code, formatting, lists, and images
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4603)
|
||||
*
|
||||
* @return array Associative array of allowed tags and attributes
|
||||
*/
|
||||
function bbp_kses_allowed_tags() {
|
||||
|
||||
// Filter & return
|
||||
return (array) apply_filters( 'bbp_kses_allowed_tags', array(
|
||||
|
||||
// Links
|
||||
'a' => array(
|
||||
'href' => true,
|
||||
'title' => true,
|
||||
'rel' => true,
|
||||
'target' => true
|
||||
),
|
||||
|
||||
// Quotes
|
||||
'blockquote' => array(
|
||||
'cite' => true
|
||||
),
|
||||
|
||||
// Code
|
||||
'code' => array(),
|
||||
'pre' => array(
|
||||
'class' => true
|
||||
),
|
||||
|
||||
// Formatting
|
||||
'em' => array(),
|
||||
'strong' => array(),
|
||||
'del' => array(
|
||||
'datetime' => true,
|
||||
'cite' => true
|
||||
),
|
||||
'ins' => array(
|
||||
'datetime' => true,
|
||||
'cite' => true
|
||||
),
|
||||
|
||||
// Lists
|
||||
'ul' => array(),
|
||||
'ol' => array(
|
||||
'start' => true,
|
||||
),
|
||||
'li' => array(),
|
||||
|
||||
// Images
|
||||
'img' => array(
|
||||
'src' => true,
|
||||
'border' => true,
|
||||
'alt' => true,
|
||||
'height' => true,
|
||||
'width' => true,
|
||||
)
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom kses filter for forum topics and replies, for filtering incoming data
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4603)
|
||||
*
|
||||
* @param string $data Content to filter, expected to be escaped with slashes
|
||||
* @return string Filtered content
|
||||
*/
|
||||
function bbp_filter_kses( $data = '' ) {
|
||||
return wp_slash( wp_kses( wp_unslash( $data ), bbp_kses_allowed_tags() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom kses filter for forum topics and replies, for raw data
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4603)
|
||||
*
|
||||
* @param string $data Content to filter, expected to not be escaped
|
||||
* @return string Filtered content
|
||||
*/
|
||||
function bbp_kses_data( $data = '' ) {
|
||||
return wp_kses( $data , bbp_kses_allowed_tags() );
|
||||
}
|
||||
|
||||
/** Formatting ****************************************************************/
|
||||
|
||||
/**
|
||||
* Filter the topic or reply content and output code and pre tags
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4641)
|
||||
*
|
||||
* @param string $content Topic and reply content
|
||||
* @return string Partially encoded content
|
||||
*/
|
||||
function bbp_code_trick( $content = '' ) {
|
||||
$content = str_replace( array( "\r\n", "\r" ), "\n", $content );
|
||||
$content = preg_replace_callback( "|(`)(.*?)`|", 'bbp_encode_callback', $content );
|
||||
$content = preg_replace_callback( "!(^|\n)`(.*?)`!s", 'bbp_encode_callback', $content );
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* When editing a topic or reply, reverse the code trick so the textarea
|
||||
* contains the correct editable content.
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4641)
|
||||
*
|
||||
* @param string $content Topic and reply content
|
||||
* @return string Partially encoded content
|
||||
*/
|
||||
function bbp_code_trick_reverse( $content = '' ) {
|
||||
|
||||
// Setup variables
|
||||
$openers = array( '<p>', '<br />' );
|
||||
$content = preg_replace_callback( "!(<pre><code>|<code>)(.*?)(</code></pre>|</code>)!s", 'bbp_decode_callback', $content );
|
||||
|
||||
// Do the do
|
||||
$content = str_replace( $openers, '', $content );
|
||||
$content = str_replace( '</p>', "\n", $content );
|
||||
$content = str_replace( '<coded_br />', '<br />', $content );
|
||||
$content = str_replace( '<coded_p>', '<p>', $content );
|
||||
$content = str_replace( '</coded_p>', '</p>', $content );
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the content and encode any bad HTML tags
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4641)
|
||||
*
|
||||
* @param string $content Topic and reply content
|
||||
* @return string Partially encoded content
|
||||
*/
|
||||
function bbp_encode_bad( $content = '' ) {
|
||||
|
||||
// Setup variables
|
||||
$content = _wp_specialchars( $content, ENT_NOQUOTES );
|
||||
$content = preg_split( '@(`[^`]*`)@m', $content, -1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE );
|
||||
$allowed = bbp_kses_allowed_tags();
|
||||
$empty = array(
|
||||
'br' => true,
|
||||
'hr' => true,
|
||||
'img' => true,
|
||||
'input' => true,
|
||||
'param' => true,
|
||||
'area' => true,
|
||||
'col' => true,
|
||||
'embed' => true
|
||||
);
|
||||
|
||||
// Loop through allowed tags and compare for empty and normal tags
|
||||
foreach ( $allowed as $tag => $args ) {
|
||||
$preg = $args ? "{$tag}(?:\s.*?)?" : $tag;
|
||||
|
||||
// Which walker to use based on the tag and arguments
|
||||
if ( isset( $empty[ $tag ] ) ) {
|
||||
array_walk( $content, 'bbp_encode_empty_callback', $preg );
|
||||
} else {
|
||||
array_walk( $content, 'bbp_encode_normal_callback', $preg );
|
||||
}
|
||||
}
|
||||
|
||||
// Return the joined content array
|
||||
return implode( '', $content );
|
||||
}
|
||||
|
||||
/** Code Callbacks ************************************************************/
|
||||
|
||||
/**
|
||||
* Callback to encode the tags in topic or reply content
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4641)
|
||||
*
|
||||
* @param array $matches
|
||||
* @return string
|
||||
*/
|
||||
function bbp_encode_callback( $matches = array() ) {
|
||||
|
||||
// Trim inline code, not pre blocks (to prevent removing indentation)
|
||||
if ( "`" === $matches[1] ) {
|
||||
$content = trim( $matches[2] );
|
||||
} else {
|
||||
$content = $matches[2];
|
||||
}
|
||||
|
||||
// Do some replacing
|
||||
$content = htmlspecialchars( $content, ENT_QUOTES );
|
||||
$content = str_replace( array( "\r\n", "\r" ), "\n", $content );
|
||||
$content = preg_replace( "|\n\n\n+|", "\n\n", $content );
|
||||
$content = str_replace( '&amp;', '&', $content );
|
||||
$content = str_replace( '&lt;', '<', $content );
|
||||
$content = str_replace( '&gt;', '>', $content );
|
||||
|
||||
// Wrap in code tags
|
||||
$content = '<code>' . $content . '</code>';
|
||||
|
||||
// Wrap blocks in pre tags
|
||||
if ( "`" !== $matches[1] ) {
|
||||
$content = "\n<pre>" . $content . "</pre>\n";
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to decode the tags in topic or reply content
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4641)
|
||||
*
|
||||
* @param array $matches
|
||||
* @todo Experiment with _wp_specialchars()
|
||||
* @return string
|
||||
*/
|
||||
function bbp_decode_callback( $matches = array() ) {
|
||||
|
||||
// Setup variables
|
||||
$trans_table = array_flip( get_html_translation_table( HTML_ENTITIES ) );
|
||||
$amps = array( '&','&', '&' );
|
||||
$single = array( ''',''' );
|
||||
$content = $matches[2];
|
||||
$content = strtr( $content, $trans_table );
|
||||
|
||||
// Do the do
|
||||
$content = str_replace( '<br />', '<coded_br />', $content );
|
||||
$content = str_replace( '<p>', '<coded_p>', $content );
|
||||
$content = str_replace( '</p>', '</coded_p>', $content );
|
||||
$content = str_replace( $amps, '&', $content );
|
||||
$content = str_replace( $single, "'", $content );
|
||||
|
||||
// Return content wrapped in code tags
|
||||
return '`' . $content . '`';
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to replace empty HTML tags in a content string
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4641)
|
||||
*
|
||||
* @internal Used by bbp_encode_bad()
|
||||
* @param string $content
|
||||
* @param string $key Not used
|
||||
* @param string $preg
|
||||
*/
|
||||
function bbp_encode_empty_callback( &$content = '', $key = '', $preg = '' ) {
|
||||
if ( strpos( $content, '`' ) !== 0 ) {
|
||||
$content = preg_replace( "|<({$preg})\s*?/*?>|i", '<$1 />', $content );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to replace normal HTML tags in a content string
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4641)
|
||||
*
|
||||
* @internal Used by bbp_encode_bad()
|
||||
*
|
||||
* @param string $content
|
||||
* @param string $key
|
||||
* @param string $preg
|
||||
*/
|
||||
function bbp_encode_normal_callback( &$content = '', $key = '', $preg = '') {
|
||||
if ( strpos( $content, '`' ) !== 0 ) {
|
||||
$content = preg_replace( "|<(/?{$preg})>|i", '<$1>', $content );
|
||||
}
|
||||
}
|
||||
|
||||
/** No Follow *****************************************************************/
|
||||
|
||||
/**
|
||||
* Catches links so rel=nofollow can be added (on output, not save)
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4865)
|
||||
*
|
||||
* @param string $text Post text
|
||||
* @return string $text Text with rel=nofollow added to any links
|
||||
*/
|
||||
function bbp_rel_nofollow( $text = '' ) {
|
||||
return preg_replace_callback( '|<a (.+?)>|i', 'bbp_rel_nofollow_callback', $text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds rel=nofollow to a link
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4865)
|
||||
*
|
||||
* @param array $matches
|
||||
* @return string $text Link with rel=nofollow added
|
||||
*/
|
||||
function bbp_rel_nofollow_callback( $matches = array() ) {
|
||||
$text = $matches[1];
|
||||
$atts = shortcode_parse_atts( $matches[1] );
|
||||
$rel = 'nofollow';
|
||||
$home_url = home_url();
|
||||
|
||||
// Bail on links that match the current domain
|
||||
if ( preg_match( '%href=["\'](' . preg_quote( set_url_scheme( $home_url, 'http' ) ) . ')%i', $text ) ||
|
||||
preg_match( '%href=["\'](' . preg_quote( set_url_scheme( $home_url, 'https' ) ) . ')%i', $text )
|
||||
) {
|
||||
return "<a {$text}>";
|
||||
}
|
||||
|
||||
// Avoid collisions with existing "rel" attribute
|
||||
if ( ! empty( $atts['rel'] ) ) {
|
||||
$parts = array_map( 'trim', explode( ' ', $atts['rel'] ) );
|
||||
if ( false === array_search( 'nofollow', $parts ) ) {
|
||||
$parts[] = 'nofollow';
|
||||
}
|
||||
|
||||
$rel = implode( ' ', $parts );
|
||||
unset( $atts['rel'] );
|
||||
|
||||
$html = '';
|
||||
foreach ( $atts as $name => $value ) {
|
||||
$html .= "{$name}=\"{$value}\" ";
|
||||
}
|
||||
|
||||
$text = trim( $html );
|
||||
}
|
||||
|
||||
return "<a {$text} rel=\"{$rel}\">";
|
||||
}
|
||||
|
||||
/** Make Clickable ************************************************************/
|
||||
|
||||
/**
|
||||
* Convert plaintext URI to HTML links.
|
||||
*
|
||||
* Converts URI, www and ftp, and email addresses. Finishes by fixing links
|
||||
* within links.
|
||||
*
|
||||
* This custom version of WordPress's make_clickable() skips links inside of
|
||||
* pre and code tags.
|
||||
*
|
||||
* @since 2.4.0 bbPress (r4941)
|
||||
*
|
||||
* @param string $text Content to convert URIs.
|
||||
* @return string Content with converted URIs.
|
||||
*/
|
||||
function bbp_make_clickable( $text = '' ) {
|
||||
$r = '';
|
||||
$textarr = preg_split( '/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // split out HTML tags
|
||||
$nested_code_pre = 0; // Keep track of how many levels link is nested inside <pre> or <code>
|
||||
|
||||
foreach ( $textarr as $piece ) {
|
||||
|
||||
if ( preg_match( '|^<code[\s>]|i', $piece ) || preg_match( '|^<pre[\s>]|i', $piece ) || preg_match( '|^<script[\s>]|i', $piece ) || preg_match( '|^<style[\s>]|i', $piece ) ) {
|
||||
$nested_code_pre++;
|
||||
} elseif ( $nested_code_pre && ( '</code>' === strtolower( $piece ) || '</pre>' === strtolower( $piece ) || '</script>' === strtolower( $piece ) || '</style>' === strtolower( $piece ) ) ) {
|
||||
$nested_code_pre--;
|
||||
}
|
||||
|
||||
if ( $nested_code_pre || empty( $piece ) || ( $piece[0] === '<' && ! preg_match( '|^<\s*[\w]{1,20}+://|', $piece ) ) ) {
|
||||
$r .= $piece;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Long strings might contain expensive edge cases ...
|
||||
if ( 10000 < strlen( $piece ) ) {
|
||||
// ... break it up
|
||||
foreach ( _split_str_by_whitespace( $piece, 2100 ) as $chunk ) { // 2100: Extra room for scheme and leading and trailing paretheses
|
||||
if ( 2101 < strlen( $chunk ) ) {
|
||||
$r .= $chunk; // Too big, no whitespace: bail.
|
||||
} else {
|
||||
$r .= bbp_make_clickable( $chunk );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$ret = " {$piece} "; // Pad with whitespace to simplify the regexes
|
||||
$ret = apply_filters( 'bbp_make_clickable', $ret, $text );
|
||||
$ret = substr( $ret, 1, -1 ); // Remove our whitespace padding.
|
||||
$r .= $ret;
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup of accidental links within links
|
||||
return preg_replace( '#(<a([ \r\n\t]+[^>]+?>|>))<a [^>]+?>([^>]+?)</a>([^<]*)</a>#i', "$1$3$4</a>", $r );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make URLs clickable in content areas
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6014)
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
function bbp_make_urls_clickable( $text = '' ) {
|
||||
$url_clickable = '~
|
||||
([\\s(<.,;:!?]) # 1: Leading whitespace, or punctuation
|
||||
( # 2: URL
|
||||
[\\w]{1,20}+:// # Scheme and hier-part prefix
|
||||
(?=\S{1,2000}\s) # Limit to URLs less than about 2000 characters long
|
||||
[\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]*+ # Non-punctuation URL character
|
||||
(?: # Unroll the Loop: Only allow puctuation URL character if followed by a non-punctuation URL character
|
||||
[\'.,;:!?)] # Punctuation URL character
|
||||
[\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]++ # Non-punctuation URL character
|
||||
)*
|
||||
)
|
||||
(\)?) # 3: Trailing closing parenthesis (for parethesis balancing post processing)
|
||||
~xS';
|
||||
|
||||
// The regex is a non-anchored pattern and does not have a single fixed starting character.
|
||||
// Tell PCRE to spend more time optimizing since, when used on a page load, it will probably be used several times.
|
||||
return preg_replace_callback( $url_clickable, '_make_url_clickable_cb', $text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make FTP clickable in content areas
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6014)
|
||||
*
|
||||
* @see make_clickable()
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
function bbp_make_ftps_clickable( $text = '' ) {
|
||||
return preg_replace_callback( '#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make emails clickable in content areas
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6014)
|
||||
*
|
||||
* @see make_clickable()
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
function bbp_make_emails_clickable( $text = '' ) {
|
||||
return preg_replace_callback( '#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make mentions clickable in content areas
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6014)
|
||||
*
|
||||
* @see make_clickable()
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
function bbp_make_mentions_clickable( $text = '' ) {
|
||||
return preg_replace_callback( '#([\s>])@([0-9a-zA-Z-_]+)#i', 'bbp_make_mentions_clickable_callback', $text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to convert mention matches to HTML A tag.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6014)
|
||||
*
|
||||
* @param array $matches Regular expression matches in the current text blob.
|
||||
*
|
||||
* @return string Original text if no user exists, or link to user profile.
|
||||
*/
|
||||
function bbp_make_mentions_clickable_callback( $matches = array() ) {
|
||||
|
||||
// Bail if the match is empty malformed
|
||||
if ( empty( $matches[2] ) || ! is_string( $matches[2] ) ) {
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
// Get user; bail if not found
|
||||
$user = get_user_by( 'slug', $matches[2] );
|
||||
if ( empty( $user ) || bbp_is_user_inactive( $user->ID ) ) {
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
// Default anchor classes
|
||||
$classes = array(
|
||||
'bbp-user-mention',
|
||||
'bbp-user-id-' . absint( $user->ID )
|
||||
);
|
||||
|
||||
// Filter classes
|
||||
$classes = (array) apply_filters( 'bbp_make_mentions_clickable_classes', $classes, $user );
|
||||
|
||||
// Escape & implode if not empty, otherwise an empty string
|
||||
$class_str = ! empty( $classes )
|
||||
? implode( ' ', array_map( 'sanitize_html_class', $classes ) )
|
||||
: '';
|
||||
|
||||
// Setup as a variable to avoid a potentially empty class attribute
|
||||
$class = ! empty( $class_str )
|
||||
? ' class="' . esc_attr( $class_str ) . '"'
|
||||
: '';
|
||||
|
||||
// Create the link to the user's profile
|
||||
$html = '<a href="%1$s"' . $class . '>%2$s</a>';
|
||||
$url = bbp_get_user_profile_url( $user->ID );
|
||||
$anchor = sprintf( $html, esc_url( $url ), esc_html( $matches[0] ) );
|
||||
|
||||
// Prevent this link from being followed by bots
|
||||
$link = bbp_rel_nofollow( $anchor );
|
||||
|
||||
// Concatenate the matches into the return value
|
||||
$retval = $matches[1] . $link;
|
||||
|
||||
// Return the link
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/** Numbers *******************************************************************/
|
||||
|
||||
/**
|
||||
* Never let a numeric value be less than zero.
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6300)
|
||||
*
|
||||
* @param int $number
|
||||
*/
|
||||
function bbp_number_not_negative( $number = 0 ) {
|
||||
|
||||
// Protect against formatted strings
|
||||
if ( is_string( $number ) ) {
|
||||
$number = strip_tags( $number ); // No HTML
|
||||
$number = preg_replace( '/[^0-9-]/', '', $number ); // No number-format
|
||||
|
||||
// Protect against objects, arrays, scalars, etc...
|
||||
} elseif ( ! is_numeric( $number ) ) {
|
||||
$number = 0;
|
||||
}
|
||||
|
||||
// Make the number an integer
|
||||
$int = intval( $number );
|
||||
|
||||
// Pick the maximum value, never less than zero
|
||||
$not_less_than_zero = max( 0, $int );
|
||||
|
||||
// Filter & return
|
||||
return (int) apply_filters( 'bbp_number_not_negative', $not_less_than_zero, $int, $number );
|
||||
}
|
||||
|
||||
/**
|
||||
* A bbPress specific method of formatting numeric values
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2486)
|
||||
*
|
||||
* @param string $number Number to format
|
||||
* @param string $decimals Optional. Display decimals
|
||||
*
|
||||
* @return string Formatted string
|
||||
*/
|
||||
function bbp_number_format( $number = 0, $decimals = false, $dec_point = '.', $thousands_sep = ',' ) {
|
||||
|
||||
// If empty, set $number to (int) 0
|
||||
if ( ! is_numeric( $number ) ) {
|
||||
$number = 0;
|
||||
}
|
||||
|
||||
// Filter & return
|
||||
return apply_filters( 'bbp_number_format', number_format( $number, $decimals, $dec_point, $thousands_sep ), $number, $decimals, $dec_point, $thousands_sep );
|
||||
}
|
||||
|
||||
/**
|
||||
* A bbPress specific method of formatting numeric values
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3857)
|
||||
*
|
||||
* @param string $number Number to format
|
||||
* @param string $decimals Optional. Display decimals
|
||||
*
|
||||
* @return string Formatted string
|
||||
*/
|
||||
function bbp_number_format_i18n( $number = 0, $decimals = false ) {
|
||||
|
||||
// If empty, set $number to (int) 0
|
||||
if ( ! is_numeric( $number ) ) {
|
||||
$number = 0;
|
||||
}
|
||||
|
||||
// Filter & return
|
||||
return apply_filters( 'bbp_number_format_i18n', number_format_i18n( $number, $decimals ), $number, $decimals );
|
||||
}
|
||||
|
||||
/** Dates *********************************************************************/
|
||||
|
||||
/**
|
||||
* Convert time supplied from database query into specified date format.
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2544)
|
||||
*
|
||||
* @param string $time Time to convert
|
||||
* @param string $d Optional. Default is 'U'. Either 'G', 'U', or php date
|
||||
* format
|
||||
* @param bool $translate Optional. Default is false. Whether to translate the
|
||||
*
|
||||
* @return string Returns timestamp
|
||||
*/
|
||||
function bbp_convert_date( $time, $d = 'U', $translate = false ) {
|
||||
$new_time = mysql2date( $d, $time, $translate );
|
||||
|
||||
// Filter & return
|
||||
return apply_filters( 'bbp_convert_date', $new_time, $d, $translate, $time );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output formatted time to display human readable time difference.
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2544)
|
||||
*
|
||||
* @param string $older_date Unix timestamp from which the difference begins.
|
||||
* @param string $newer_date Optional. Unix timestamp from which the
|
||||
* difference ends. False for current time.
|
||||
* @param int $gmt Optional. Whether to use GMT timezone. Default is false.
|
||||
*/
|
||||
function bbp_time_since( $older_date, $newer_date = false, $gmt = false ) {
|
||||
echo bbp_get_time_since( $older_date, $newer_date, $gmt );
|
||||
}
|
||||
/**
|
||||
* Return formatted time to display human readable time difference.
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2544)
|
||||
*
|
||||
* @param string $older_date Unix timestamp from which the difference begins.
|
||||
* @param string $newer_date Optional. Unix timestamp from which the
|
||||
* difference ends. False for current time.
|
||||
* @param int $gmt Optional. Whether to use GMT timezone. Default is false.
|
||||
*
|
||||
* @return string Formatted time
|
||||
*/
|
||||
function bbp_get_time_since( $older_date, $newer_date = false, $gmt = false ) {
|
||||
|
||||
// Setup the strings
|
||||
$unknown_text = apply_filters( 'bbp_core_time_since_unknown_text', esc_html__( 'sometime', 'bbpress' ) );
|
||||
$right_now_text = apply_filters( 'bbp_core_time_since_right_now_text', esc_html__( 'right now', 'bbpress' ) );
|
||||
$ago_text = apply_filters( 'bbp_core_time_since_ago_text', esc_html__( '%s ago', 'bbpress' ) );
|
||||
|
||||
// array of time period chunks
|
||||
$chunks = array(
|
||||
array( YEAR_IN_SECONDS, _n_noop( '%s year', '%s years', 'bbpress' ) ),
|
||||
array( MONTH_IN_SECONDS, _n_noop( '%s month', '%s months', 'bbpress' ) ),
|
||||
array( WEEK_IN_SECONDS, _n_noop( '%s week', '%s weeks', 'bbpress' ) ),
|
||||
array( DAY_IN_SECONDS, _n_noop( '%s day', '%s days', 'bbpress' ) ),
|
||||
array( HOUR_IN_SECONDS, _n_noop( '%s hour', '%s hours', 'bbpress' ) ),
|
||||
array( MINUTE_IN_SECONDS, _n_noop( '%s minute', '%s minutes', 'bbpress' ) ),
|
||||
array( 1, _n_noop( '%s second', '%s seconds', 'bbpress' ) ),
|
||||
);
|
||||
|
||||
// Attempt to parse non-numeric older date
|
||||
if ( ! empty( $older_date ) && ! is_numeric( $older_date ) ) {
|
||||
$time_chunks = explode( ':', str_replace( ' ', ':', $older_date ) );
|
||||
$date_chunks = explode( '-', str_replace( ' ', '-', $older_date ) );
|
||||
$older_date = gmmktime( (int) $time_chunks[1], (int) $time_chunks[2], (int) $time_chunks[3], (int) $date_chunks[1], (int) $date_chunks[2], (int) $date_chunks[0] );
|
||||
}
|
||||
|
||||
// Attempt to parse non-numeric newer date
|
||||
if ( ! empty( $newer_date ) && ! is_numeric( $newer_date ) ) {
|
||||
$time_chunks = explode( ':', str_replace( ' ', ':', $newer_date ) );
|
||||
$date_chunks = explode( '-', str_replace( ' ', '-', $newer_date ) );
|
||||
$newer_date = gmmktime( (int) $time_chunks[1], (int) $time_chunks[2], (int) $time_chunks[3], (int) $date_chunks[1], (int) $date_chunks[2], (int) $date_chunks[0] );
|
||||
}
|
||||
|
||||
// Set newer date to current time
|
||||
if ( empty( $newer_date ) ) {
|
||||
$newer_date = strtotime( current_time( 'mysql', $gmt ) );
|
||||
}
|
||||
|
||||
// Cast both dates to ints to avoid notices & errors with invalid values
|
||||
$newer_date = intval( $newer_date );
|
||||
$older_date = intval( $older_date );
|
||||
|
||||
// Difference in seconds
|
||||
$since = intval( $newer_date - $older_date );
|
||||
|
||||
// Something went wrong with date calculation and we ended up with a negative date.
|
||||
if ( 0 > $since ) {
|
||||
$output = $unknown_text;
|
||||
|
||||
// We only want to output two chunks of time here, eg:
|
||||
// x years, xx months
|
||||
// x days, xx hours
|
||||
// so there's only two bits of calculation below:
|
||||
} else {
|
||||
|
||||
// Default count values
|
||||
$count = 0;
|
||||
$count2 = 0;
|
||||
|
||||
// Step one: the first chunk
|
||||
for ( $i = 0, $j = count( $chunks ); $i < $j; ++$i ) {
|
||||
$seconds = $chunks[ $i ][0];
|
||||
|
||||
// Finding the biggest chunk (if the chunk fits, break)
|
||||
$count = floor( $since / $seconds );
|
||||
if ( 0 != $count ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If $i iterates all the way to $j, then the event happened 0 seconds ago
|
||||
if ( ! isset( $chunks[ $i ] ) ) {
|
||||
$output = $right_now_text;
|
||||
|
||||
} else {
|
||||
|
||||
// Set output var
|
||||
$output = sprintf( translate_nooped_plural( $chunks[ $i ][1], $count, 'bbpress' ), bbp_number_format_i18n( $count ) );
|
||||
|
||||
// Step two: the second chunk
|
||||
if ( $i + 2 < $j ) {
|
||||
$seconds2 = $chunks[ $i + 1 ][0];
|
||||
$count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 );
|
||||
|
||||
// Add to output var
|
||||
if ( 0 != $count2 ) {
|
||||
$output .= _x( ',', 'Separator in time since', 'bbpress' ) . ' ';
|
||||
$output .= sprintf( translate_nooped_plural( $chunks[ $i + 1 ][1], $count2, 'bbpress' ), bbp_number_format_i18n( $count2 ) );
|
||||
}
|
||||
}
|
||||
|
||||
// Empty counts, so fallback to right now
|
||||
if ( empty( $count ) && empty( $count2 ) ) {
|
||||
$output = $right_now_text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Append 'ago' to the end of time-since if not 'right now'
|
||||
if ( $output != $right_now_text ) {
|
||||
$output = sprintf( $ago_text, $output );
|
||||
}
|
||||
|
||||
// Filter & return
|
||||
return apply_filters( 'bbp_get_time_since', $output, $older_date, $newer_date );
|
||||
}
|
||||
|
||||
/** Revisions *****************************************************************/
|
||||
|
||||
/**
|
||||
* Formats the reason for editing the topic/reply.
|
||||
*
|
||||
* Does these things:
|
||||
* - Trimming
|
||||
* - Removing periods from the end of the string
|
||||
* - Trimming again
|
||||
*
|
||||
* @since 2.0.0 bbPress (r2782)
|
||||
*
|
||||
* @param string $reason Optional. User submitted reason for editing.
|
||||
* @return string Status of topic
|
||||
*/
|
||||
function bbp_format_revision_reason( $reason = '' ) {
|
||||
$reason = (string) $reason;
|
||||
|
||||
// Bail if reason is empty
|
||||
if ( empty( $reason ) ) {
|
||||
return $reason;
|
||||
}
|
||||
|
||||
// Trimming
|
||||
$reason = trim( $reason );
|
||||
|
||||
// We add our own full stop.
|
||||
while ( substr( $reason, -1 ) === '.' ) {
|
||||
$reason = substr( $reason, 0, -1 );
|
||||
}
|
||||
|
||||
// Trim again
|
||||
$reason = trim( $reason );
|
||||
|
||||
return $reason;
|
||||
}
|
||||
2635
wp-content/plugins/bbpress/includes/common/functions.php
Normal file
2635
wp-content/plugins/bbpress/includes/common/functions.php
Normal file
File diff suppressed because it is too large
Load Diff
5
wp-content/plugins/bbpress/includes/common/index.php
Normal file
5
wp-content/plugins/bbpress/includes/common/index.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Do not modify the files in this folder.
|
||||
*/
|
||||
57
wp-content/plugins/bbpress/includes/common/locale.php
Normal file
57
wp-content/plugins/bbpress/includes/common/locale.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* bbPress Localization
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage Localization
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Translates role name.
|
||||
*
|
||||
* Since the role names are in the database and not in the source there
|
||||
* are dummy gettext calls to get them into the POT file and this function
|
||||
* properly translates them back.
|
||||
*
|
||||
* The before_last_bar() call is needed, because older installs keep the roles
|
||||
* using the old context format: 'Role name|User role' and just skipping the
|
||||
* content after the last bar is easier than fixing them in the DB. New installs
|
||||
* won't suffer from that problem.
|
||||
*
|
||||
* @see translate_user_role()
|
||||
*
|
||||
* @since 2.6.0 bbPress
|
||||
*
|
||||
* @param string $name The role name.
|
||||
* @return string Translated role name on success, original name on failure.
|
||||
*/
|
||||
function bbp_translate_user_role( $name ) {
|
||||
return translate_with_gettext_context( before_last_bar( $name ), 'User role', 'bbpress' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy gettext calls to get strings in the catalog.
|
||||
*
|
||||
* @since 2.6.0 bbPress
|
||||
*/
|
||||
function bbp_dummy_role_names() {
|
||||
|
||||
/* translators: user role */
|
||||
_x( 'Keymaster', 'User role', 'bbpress' );
|
||||
|
||||
/* translators: user role */
|
||||
_x( 'Moderator', 'User role', 'bbpress' );
|
||||
|
||||
/* translators: user role */
|
||||
_x( 'Participant', 'User role', 'bbpress' );
|
||||
|
||||
/* translators: user role */
|
||||
_x( 'Spectator', 'User role', 'bbpress' );
|
||||
|
||||
/* translators: user role */
|
||||
_x( 'Blocked', 'User role', 'bbpress' );
|
||||
}
|
||||
82
wp-content/plugins/bbpress/includes/common/locks.php
Normal file
82
wp-content/plugins/bbpress/includes/common/locks.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* bbPress Locking
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage Common
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Check to see if the post is currently being edited by another user.
|
||||
*
|
||||
* @see wp_check_post_lock()
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6340)
|
||||
*
|
||||
* @param int $post_id ID of the post to check for editing
|
||||
* @return integer False: not locked or locked by current user. Int: user ID of user with lock.
|
||||
*/
|
||||
function bbp_check_post_lock( $post_id = 0 ) {
|
||||
|
||||
// Bail if no post
|
||||
if ( !$post = get_post( $post_id ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Bail if no lock
|
||||
if ( !$lock = get_post_meta( $post->ID, '_edit_lock', true ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get lock
|
||||
$lock = explode( ':', $lock );
|
||||
$time = $lock[0];
|
||||
$user = (int) isset( $lock[1] )
|
||||
? $lock[1]
|
||||
: get_post_meta( $post->ID, '_edit_last', true );
|
||||
|
||||
// Filter editing window duration
|
||||
$time_window = apply_filters( 'bbp_check_post_lock_window', 3 * MINUTE_IN_SECONDS );
|
||||
|
||||
// Return user who is or last edited
|
||||
if ( ! empty( $time ) && ( $time > ( time() - $time_window ) ) && ( $user !== bbp_get_current_user_id() ) ) {
|
||||
return (int) $user;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the post as currently being edited by the current user
|
||||
*
|
||||
* @since 2.6.0 bbPress (r6340)
|
||||
*
|
||||
* @param int $post_id ID of the post to being edited
|
||||
* @return bool|array Returns false if the post doesn't exist of there is no current user, or
|
||||
* an array of the lock time and the user ID.
|
||||
*/
|
||||
function bbp_set_post_lock( $post_id = 0 ) {
|
||||
|
||||
// Bail if no post
|
||||
if ( !$post = get_post( $post_id ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Bail if no user
|
||||
if ( 0 == ( $user_id = get_current_user_id() ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get time & lock value
|
||||
$now = time();
|
||||
$lock = "{$now}:{$user_id}";
|
||||
|
||||
// Set lock value
|
||||
update_post_meta( $post->ID, '_edit_lock', $lock );
|
||||
|
||||
return array( $now, $user_id );
|
||||
}
|
||||
858
wp-content/plugins/bbpress/includes/common/shortcodes.php
Normal file
858
wp-content/plugins/bbpress/includes/common/shortcodes.php
Normal file
@@ -0,0 +1,858 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* bbPress Shortcodes
|
||||
*
|
||||
* @package bbPress
|
||||
* @subpackage Shortcodes
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
if ( ! class_exists( 'BBP_Shortcodes' ) ) :
|
||||
/**
|
||||
* bbPress Shortcode Class
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3031)
|
||||
*/
|
||||
class BBP_Shortcodes {
|
||||
|
||||
/** Vars ******************************************************************/
|
||||
|
||||
/**
|
||||
* @var array Shortcode => function
|
||||
*/
|
||||
public $codes = array();
|
||||
|
||||
/** Functions *************************************************************/
|
||||
|
||||
/**
|
||||
* Add the register_shortcodes action to bbp_init
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3031)
|
||||
*
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->setup_globals();
|
||||
$this->add_shortcodes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcode globals
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3143)
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function setup_globals() {
|
||||
|
||||
// Setup the shortcodes
|
||||
$this->codes = apply_filters( 'bbp_shortcodes', array(
|
||||
|
||||
/** Forums ********************************************************/
|
||||
|
||||
'bbp-forum-index' => array( $this, 'display_forum_index' ), // Forum Index
|
||||
'bbp-forum-form' => array( $this, 'display_forum_form' ), // Topic form
|
||||
'bbp-single-forum' => array( $this, 'display_forum' ), // Specific forum - pass an 'id' attribute
|
||||
|
||||
/** Topics ********************************************************/
|
||||
|
||||
'bbp-topic-index' => array( $this, 'display_topic_index' ), // Topic index
|
||||
'bbp-topic-form' => array( $this, 'display_topic_form' ), // Topic form
|
||||
'bbp-single-topic' => array( $this, 'display_topic' ), // Specific topic - pass an 'id' attribute
|
||||
|
||||
/** Topic Tags ****************************************************/
|
||||
|
||||
'bbp-topic-tags' => array( $this, 'display_topic_tags' ), // All topic tags in a cloud
|
||||
'bbp-single-tag' => array( $this, 'display_topics_of_tag' ), // Topics of Tag
|
||||
|
||||
/** Replies *******************************************************/
|
||||
|
||||
'bbp-reply-form' => array( $this, 'display_reply_form' ), // Reply form
|
||||
'bbp-single-reply' => array( $this, 'display_reply' ), // Specific reply - pass an 'id' attribute
|
||||
|
||||
/** Views *********************************************************/
|
||||
|
||||
'bbp-single-view' => array( $this, 'display_view' ), // Single view
|
||||
|
||||
/** Search ********************************************************/
|
||||
|
||||
'bbp-search-form' => array( $this, 'display_search_form' ), // Search form
|
||||
'bbp-search' => array( $this, 'display_search' ), // Search
|
||||
|
||||
/** Account *******************************************************/
|
||||
|
||||
'bbp-login' => array( $this, 'display_login' ), // Login
|
||||
'bbp-register' => array( $this, 'display_register' ), // Register
|
||||
'bbp-lost-pass' => array( $this, 'display_lost_pass' ), // Lost Password
|
||||
|
||||
/** Others *******************************************************/
|
||||
|
||||
'bbp-stats' => array( $this, 'display_stats' ), // Stats
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the bbPress shortcodes
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3031)
|
||||
*/
|
||||
private function add_shortcodes() {
|
||||
foreach ( (array) $this->codes as $code => $function ) {
|
||||
add_shortcode( $code, $function );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset some globals in the $bbp object that hold query related info
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3034)
|
||||
*/
|
||||
private function unset_globals() {
|
||||
$bbp = bbpress();
|
||||
|
||||
// Unset global queries
|
||||
$bbp->forum_query = new WP_Query();
|
||||
$bbp->topic_query = new WP_Query();
|
||||
$bbp->reply_query = new WP_Query();
|
||||
$bbp->search_query = new WP_Query();
|
||||
|
||||
// Unset global ID's
|
||||
$bbp->current_view_id = 0;
|
||||
$bbp->current_forum_id = 0;
|
||||
$bbp->current_topic_id = 0;
|
||||
$bbp->current_reply_id = 0;
|
||||
$bbp->current_topic_tag_id = 0;
|
||||
|
||||
// Reset the post data
|
||||
wp_reset_postdata();
|
||||
}
|
||||
|
||||
/** Output Buffers ********************************************************/
|
||||
|
||||
/**
|
||||
* Start an output buffer.
|
||||
*
|
||||
* This is used to put the contents of the shortcode into a variable rather
|
||||
* than outputting the HTML at run-time. This allows shortcodes to appear
|
||||
* in the correct location in the_content() instead of when it's created.
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3079)
|
||||
*
|
||||
* @param string $query_name
|
||||
*/
|
||||
private function start( $query_name = '' ) {
|
||||
|
||||
// Set query name
|
||||
bbp_set_query_name( $query_name );
|
||||
|
||||
// Start output buffer
|
||||
ob_start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the contents of the output buffer and flush its contents.
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3079)
|
||||
*
|
||||
* @return string Contents of output buffer.
|
||||
*/
|
||||
private function end() {
|
||||
|
||||
// Unset globals
|
||||
$this->unset_globals();
|
||||
|
||||
// Get the query name, for filter
|
||||
$query_name = bbp_get_query_name();
|
||||
|
||||
// Reset the query name
|
||||
bbp_reset_query_name();
|
||||
|
||||
// Return and flush the output buffer
|
||||
$output = ob_get_clean();
|
||||
|
||||
// Filter & return
|
||||
return apply_filters( 'bbp_display_shortcode', $output, $query_name );
|
||||
}
|
||||
|
||||
/** Forum shortcodes ******************************************************/
|
||||
|
||||
/**
|
||||
* Display an index of all visible root level forums in an output buffer
|
||||
* and return to ensure that post/page contents are displayed first.
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3031)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function display_forum_index() {
|
||||
|
||||
// Unset globals
|
||||
$this->unset_globals();
|
||||
|
||||
// Start output buffer
|
||||
$this->start( 'bbp_forum_archive' );
|
||||
|
||||
bbp_get_template_part( 'content', 'archive-forum' );
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the contents of a specific forum ID in an output buffer
|
||||
* and return to ensure that post/page contents are displayed first.
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3031)
|
||||
*
|
||||
* @param array $attr
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public function display_forum( $attr, $content = '' ) {
|
||||
|
||||
// Sanity check required info
|
||||
if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Set passed attribute to $forum_id for clarity
|
||||
$forum_id = bbpress()->current_forum_id = $attr['id'];
|
||||
|
||||
// Bail if ID passed is not a forum
|
||||
if ( ! bbp_is_forum( $forum_id ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Start output buffer
|
||||
$this->start( 'bbp_single_forum' );
|
||||
|
||||
// Check forum caps
|
||||
if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
|
||||
bbp_get_template_part( 'content', 'single-forum' );
|
||||
|
||||
// Forum is private and user does not have caps
|
||||
} elseif ( bbp_is_forum_private( $forum_id, false ) ) {
|
||||
bbp_get_template_part( 'feedback', 'no-access' );
|
||||
}
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the forum form in an output buffer and return to ensure
|
||||
* post/page contents are displayed first.
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3566)
|
||||
*/
|
||||
public function display_forum_form() {
|
||||
|
||||
// Start output buffer
|
||||
$this->start( 'bbp_forum_form' );
|
||||
|
||||
// Output templates
|
||||
bbp_get_template_part( 'form', 'forum' );
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/** Topic shortcodes ******************************************************/
|
||||
|
||||
/**
|
||||
* Display an index of all visible root level topics in an output buffer
|
||||
* and return to ensure that post/page contents are displayed first.
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3031)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function display_topic_index() {
|
||||
|
||||
// Unset globals
|
||||
$this->unset_globals();
|
||||
|
||||
// Filter the query
|
||||
if ( ! bbp_is_topic_archive() ) {
|
||||
add_filter( 'bbp_before_has_topics_parse_args', array( $this, 'display_topic_index_query' ) );
|
||||
}
|
||||
|
||||
// Start output buffer
|
||||
$this->start( 'bbp_topic_archive' );
|
||||
|
||||
// Output template
|
||||
bbp_get_template_part( 'content', 'archive-topic' );
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the contents of a specific topic ID in an output buffer
|
||||
* and return to ensure that post/page contents are displayed first.
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3031)
|
||||
*
|
||||
* @param array $attr
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public function display_topic( $attr, $content = '' ) {
|
||||
|
||||
// Sanity check required info
|
||||
if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Unset globals
|
||||
$this->unset_globals();
|
||||
|
||||
// Set passed attribute to $forum_id for clarity
|
||||
$topic_id = bbpress()->current_topic_id = $attr['id'];
|
||||
$forum_id = bbp_get_topic_forum_id( $topic_id );
|
||||
|
||||
// Bail if ID passed is not a topic
|
||||
if ( ! bbp_is_topic( $topic_id ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Reset the queries if not in theme compat
|
||||
if ( ! bbp_is_theme_compat_active() ) {
|
||||
|
||||
$bbp = bbpress();
|
||||
|
||||
// Reset necessary forum_query attributes for topics loop to function
|
||||
$bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
|
||||
$bbp->forum_query->in_the_loop = true;
|
||||
$bbp->forum_query->post = get_post( $forum_id );
|
||||
|
||||
// Reset necessary topic_query attributes for topics loop to function
|
||||
$bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type();
|
||||
$bbp->topic_query->in_the_loop = true;
|
||||
$bbp->topic_query->post = get_post( $topic_id );
|
||||
}
|
||||
|
||||
// Start output buffer
|
||||
$this->start( 'bbp_single_topic' );
|
||||
|
||||
// Check forum caps
|
||||
if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
|
||||
bbp_get_template_part( 'content', 'single-topic' );
|
||||
|
||||
// Forum is private and user does not have caps
|
||||
} elseif ( bbp_is_forum_private( $forum_id, false ) ) {
|
||||
bbp_get_template_part( 'feedback', 'no-access' );
|
||||
}
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the topic form in an output buffer and return to ensure
|
||||
* post/page contents are displayed first.
|
||||
*
|
||||
* Supports 'forum_id' attribute to display the topic form for a particular
|
||||
* forum. This currently has styling issues from not being wrapped in
|
||||
* <div id="bbpress-forums" class="bbpress-wrapper"></div> which will need to be sorted out later.
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3031)
|
||||
*
|
||||
* @param array $attr
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public function display_topic_form( $attr = array(), $content = '' ) {
|
||||
|
||||
// Sanity check supplied info
|
||||
if ( ! empty( $content ) || ( ! empty( $attr['forum_id'] ) && ( ! is_numeric( $attr['forum_id'] ) || ! bbp_is_forum( $attr['forum_id'] ) ) ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Unset globals
|
||||
$this->unset_globals();
|
||||
|
||||
// If forum id is set, use the 'bbp_single_forum' query name
|
||||
if ( ! empty( $attr['forum_id'] ) ) {
|
||||
|
||||
// Set the global current_forum_id for future requests
|
||||
bbpress()->current_forum_id = $forum_id = bbp_get_forum_id( $attr['forum_id'] );
|
||||
|
||||
// Start output buffer
|
||||
$this->start( 'bbp_single_forum' );
|
||||
|
||||
// No forum id was passed
|
||||
} else {
|
||||
|
||||
// Set the $forum_id variable to satisfy checks below
|
||||
$forum_id = 0;
|
||||
|
||||
// Start output buffer
|
||||
$this->start( 'bbp_topic_form' );
|
||||
}
|
||||
|
||||
// If the forum id is set, check forum caps else display normal topic form
|
||||
if ( empty( $forum_id ) || bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
|
||||
bbp_get_template_part( 'form', 'topic' );
|
||||
|
||||
// Forum is private and user does not have caps
|
||||
} elseif ( bbp_is_forum_private( $forum_id, false ) ) {
|
||||
bbp_get_template_part( 'feedback', 'no-access' );
|
||||
}
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/** Replies ***************************************************************/
|
||||
|
||||
/**
|
||||
* Display the contents of a specific reply ID in an output buffer
|
||||
* and return to ensure that post/page contents are displayed first.
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3031)
|
||||
*
|
||||
* @param array $attr
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public function display_reply( $attr, $content = '' ) {
|
||||
|
||||
// Sanity check required info
|
||||
if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Unset globals
|
||||
$this->unset_globals();
|
||||
|
||||
// Set passed attribute to $reply_id for clarity
|
||||
$reply_id = bbpress()->current_reply_id = $attr['id'];
|
||||
$forum_id = bbp_get_reply_forum_id( $reply_id );
|
||||
|
||||
// Bail if ID passed is not a reply
|
||||
if ( ! bbp_is_reply( $reply_id ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Reset the queries if not in theme compat
|
||||
if ( ! bbp_is_theme_compat_active() ) {
|
||||
|
||||
$bbp = bbpress();
|
||||
|
||||
// Reset necessary forum_query attributes for reply loop to function
|
||||
$bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
|
||||
$bbp->forum_query->in_the_loop = true;
|
||||
$bbp->forum_query->post = get_post( $forum_id );
|
||||
|
||||
// Reset necessary reply_query attributes for reply loop to function
|
||||
$bbp->reply_query->query_vars['post_type'] = bbp_get_reply_post_type();
|
||||
$bbp->reply_query->in_the_loop = true;
|
||||
$bbp->reply_query->post = get_post( $reply_id );
|
||||
}
|
||||
|
||||
// Start output buffer
|
||||
$this->start( 'bbp_single_reply' );
|
||||
|
||||
// Check forum caps
|
||||
if ( bbp_user_can_view_forum( array( 'forum_id' => $forum_id ) ) ) {
|
||||
bbp_get_template_part( 'content', 'single-reply' );
|
||||
|
||||
// Forum is private and user does not have caps
|
||||
} elseif ( bbp_is_forum_private( $forum_id, false ) ) {
|
||||
bbp_get_template_part( 'feedback', 'no-access' );
|
||||
}
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the reply form in an output buffer and return to ensure
|
||||
* post/page contents are displayed first.
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3031)
|
||||
*/
|
||||
public function display_reply_form() {
|
||||
|
||||
// Start output buffer
|
||||
$this->start( 'bbp_reply_form' );
|
||||
|
||||
// Output templates
|
||||
bbp_get_template_part( 'form', 'reply' );
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/** Topic Tags ************************************************************/
|
||||
|
||||
/**
|
||||
* Display a tag cloud of all topic tags in an output buffer and return to
|
||||
* ensure that post/page contents are displayed first.
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3110)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function display_topic_tags() {
|
||||
|
||||
// Unset globals
|
||||
$this->unset_globals();
|
||||
|
||||
// Start output buffer
|
||||
$this->start( 'bbp_topic_tags' );
|
||||
|
||||
// Output the topic tags
|
||||
wp_tag_cloud( array(
|
||||
'smallest' => 9,
|
||||
'largest' => 38,
|
||||
'number' => 80,
|
||||
'taxonomy' => bbp_get_topic_tag_tax_id()
|
||||
) );
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the contents of a specific topic tag in an output buffer
|
||||
* and return to ensure that post/page contents are displayed first.
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3110)
|
||||
*
|
||||
* @param array $attr
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public function display_topics_of_tag( $attr, $content = '' ) {
|
||||
|
||||
// Sanity check required info
|
||||
if ( ! empty( $content ) || ( empty( $attr['id'] ) || ! is_numeric( $attr['id'] ) ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Unset globals
|
||||
$this->unset_globals();
|
||||
|
||||
// Filter the query
|
||||
if ( ! bbp_is_topic_tag() ) {
|
||||
add_filter( 'bbp_before_has_topics_parse_args', array( $this, 'display_topics_of_tag_query' ) );
|
||||
}
|
||||
|
||||
// Start output buffer
|
||||
$this->start( 'bbp_topic_tag' );
|
||||
|
||||
// Set passed attribute to $ag_id for clarity
|
||||
bbpress()->current_topic_tag_id = $tag_id = $attr['id'];
|
||||
|
||||
// Output template
|
||||
bbp_get_template_part( 'content', 'archive-topic' );
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the contents of a specific topic tag in an output buffer
|
||||
* and return to ensure that post/page contents are displayed first.
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3346)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function display_topic_tag_form() {
|
||||
|
||||
// Unset globals
|
||||
$this->unset_globals();
|
||||
|
||||
// Start output buffer
|
||||
$this->start( 'bbp_topic_tag_edit' );
|
||||
|
||||
// Output template
|
||||
bbp_get_template_part( 'content', 'topic-tag-edit' );
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/** Views *****************************************************************/
|
||||
|
||||
/**
|
||||
* Display the contents of a specific view in an output buffer and return to
|
||||
* ensure that post/page contents are displayed first.
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3031)
|
||||
*
|
||||
* @param array $attr
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public function display_view( $attr, $content = '' ) {
|
||||
|
||||
// Sanity check required info
|
||||
if ( empty( $attr['id'] ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Set passed attribute to $view_id for clarity
|
||||
$view_id = $attr['id'];
|
||||
|
||||
// Start output buffer
|
||||
$this->start( 'bbp_single_view' );
|
||||
|
||||
// Unset globals
|
||||
$this->unset_globals();
|
||||
|
||||
// Set the current view ID
|
||||
bbpress()->current_view_id = $view_id;
|
||||
|
||||
// Load the view
|
||||
bbp_view_query( $view_id );
|
||||
|
||||
// Output template
|
||||
bbp_get_template_part( 'content', 'single-view' );
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/** Search ****************************************************************/
|
||||
|
||||
/**
|
||||
* Display the search form in an output buffer and return to ensure
|
||||
* post/page contents are displayed first.
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4585)
|
||||
*/
|
||||
public function display_search_form() {
|
||||
|
||||
// Bail if search is disabled
|
||||
if ( ! bbp_allow_search() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Start output buffer
|
||||
$this->start( 'bbp_search_form' );
|
||||
|
||||
// Output templates
|
||||
bbp_get_template_part( 'form', 'search' );
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the contents of search results in an output buffer and return to
|
||||
* ensure that post/page contents are displayed first.
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4579)
|
||||
*
|
||||
* @param array $attr
|
||||
* @param string $content
|
||||
*/
|
||||
public function display_search( $attr, $content = '' ) {
|
||||
|
||||
// Sanity check required info
|
||||
if ( ! empty( $content ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Bail if search is disabled
|
||||
if ( ! bbp_allow_search() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Trim search attribute if it's set
|
||||
if ( isset( $attr['search'] ) ) {
|
||||
$attr['search'] = trim( $attr['search'] );
|
||||
}
|
||||
|
||||
// Set passed attribute to $search_terms for clarity
|
||||
$search_terms = empty( $attr['search'] )
|
||||
? bbp_get_search_terms()
|
||||
: $attr['search'];
|
||||
|
||||
// Get the rewrite ID (one time, to avoid repeated calls)
|
||||
$rewrite_id = bbp_get_search_rewrite_id();
|
||||
|
||||
// Unset globals
|
||||
$this->unset_globals();
|
||||
|
||||
// Set terms for query
|
||||
set_query_var( $rewrite_id, $search_terms );
|
||||
|
||||
// Start output buffer
|
||||
$this->start( $rewrite_id );
|
||||
|
||||
// Output template
|
||||
bbp_get_template_part( 'content', 'search' );
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/** Account ***************************************************************/
|
||||
|
||||
/**
|
||||
* Display a login form
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3302)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function display_login() {
|
||||
|
||||
// Unset globals
|
||||
$this->unset_globals();
|
||||
|
||||
// Start output buffer
|
||||
$this->start( 'bbp_login' );
|
||||
|
||||
// Output templates
|
||||
if ( ! is_user_logged_in() ) {
|
||||
bbp_get_template_part( 'form', 'user-login' );
|
||||
} else {
|
||||
bbp_get_template_part( 'feedback', 'logged-in' );
|
||||
}
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a register form
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3302)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function display_register() {
|
||||
|
||||
// Unset globals
|
||||
$this->unset_globals();
|
||||
|
||||
// Start output buffer
|
||||
$this->start( 'bbp_register' );
|
||||
|
||||
// Output templates
|
||||
if ( ! is_user_logged_in() ) {
|
||||
bbp_get_template_part( 'form', 'user-register' );
|
||||
} else {
|
||||
bbp_get_template_part( 'feedback', 'logged-in' );
|
||||
}
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a lost password form
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3302)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function display_lost_pass() {
|
||||
|
||||
// Unset globals
|
||||
$this->unset_globals();
|
||||
|
||||
// Start output buffer
|
||||
$this->start( 'bbp_lost_pass' );
|
||||
|
||||
// Output templates
|
||||
if ( ! is_user_logged_in() ) {
|
||||
bbp_get_template_part( 'form', 'user-lost-pass' );
|
||||
} else {
|
||||
bbp_get_template_part( 'feedback', 'logged-in' );
|
||||
}
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/** Other *****************************************************************/
|
||||
|
||||
/**
|
||||
* Display forum statistics
|
||||
*
|
||||
* @since 2.3.0 bbPress (r4509)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function display_stats() {
|
||||
|
||||
// Unset globals
|
||||
$this->unset_globals();
|
||||
|
||||
// Start output buffer
|
||||
$this->start();
|
||||
|
||||
// Output statistics
|
||||
bbp_get_template_part( 'content', 'statistics' );
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a breadcrumb
|
||||
*
|
||||
* @since 2.0.0 bbPress (r3302)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function display_breadcrumb() {
|
||||
|
||||
// Unset globals
|
||||
$this->unset_globals();
|
||||
|
||||
// Start output buffer
|
||||
$this->start();
|
||||
|
||||
// Output breadcrumb
|
||||
bbp_breadcrumb();
|
||||
|
||||
// Return contents of output buffer
|
||||
return $this->end();
|
||||
}
|
||||
|
||||
/** Query Filters *********************************************************/
|
||||
|
||||
/**
|
||||
* Filter the query for the topic index
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3637)
|
||||
*
|
||||
* @param array $args
|
||||
* @return array
|
||||
*/
|
||||
public function display_topic_index_query( $args = array() ) {
|
||||
$args['author'] = 0;
|
||||
$args['show_stickies'] = true;
|
||||
$args['order'] = 'DESC';
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query for topic tags
|
||||
*
|
||||
* @since 2.1.0 bbPress (r3637)
|
||||
*
|
||||
* @param array $args
|
||||
* @return array
|
||||
*/
|
||||
public function display_topics_of_tag_query( $args = array() ) {
|
||||
$args['tax_query'] = array( array(
|
||||
'taxonomy' => bbp_get_topic_tag_tax_id(),
|
||||
'field' => 'id',
|
||||
'terms' => bbpress()->current_topic_tag_id
|
||||
) );
|
||||
|
||||
return $args;
|
||||
}
|
||||
}
|
||||
endif;
|
||||
2820
wp-content/plugins/bbpress/includes/common/template.php
Normal file
2820
wp-content/plugins/bbpress/includes/common/template.php
Normal file
File diff suppressed because it is too large
Load Diff
1241
wp-content/plugins/bbpress/includes/common/widgets.php
Normal file
1241
wp-content/plugins/bbpress/includes/common/widgets.php
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user