/** * Initiates a BuddyPress Docs query * * @since 1.2 */ function bp_docs_has_docs($args = array()) { global $bp, $wp_query; // The if-empty is because, like with WP itself, we use bp_docs_has_docs() both for the // initial 'if' of the loop, as well as for the 'while' iterator. Don't want infinite // queries if (empty($bp->bp_docs->doc_query)) { // Build some intelligent defaults // Default to current group id, if available $d_group_id = bp_is_group() ? bp_get_current_group_id() : array(); // If this is a Started By tab, set the author ID $d_author_id = bp_docs_is_started_by() ? bp_displayed_user_id() : array(); // If this is an Edited By tab, set the edited_by id $d_edited_by_id = bp_docs_is_edited_by() ? bp_displayed_user_id() : array(); // Default to the tags in the URL string, if available $d_tags = isset($_REQUEST['bpd_tag']) ? explode(',', urldecode($_REQUEST['bpd_tag'])) : array(); // Order and orderby arguments $d_orderby = !empty($_GET['orderby']) ? urldecode($_GET['orderby']) : apply_filters('bp_docs_default_sort_order', 'modified'); if (empty($_GET['order'])) { // If no order is explicitly stated, we must provide one. // It'll be different for date fields (should be DESC) if ('modified' == $d_orderby || 'date' == $d_orderby) { $d_order = 'DESC'; } else { $d_order = 'ASC'; } } else { $d_order = $_GET['order']; } // Search $d_search_terms = !empty($_GET['s']) ? urldecode($_GET['s']) : ''; // Parent id $d_parent_id = !empty($_REQUEST['parent_doc']) ? (int) $_REQUEST['parent_doc'] : ''; // Page number, posts per page $d_paged = 1; if (!empty($_GET['paged'])) { $d_paged = absint($_GET['paged']); } else { if (bp_docs_is_global_directory() && is_a($wp_query, 'WP_Query') && 1 < $wp_query->get('paged')) { $d_paged = absint($wp_query->get('paged')); } } $d_posts_per_page = !empty($_GET['posts_per_page']) ? absint($_GET['posts_per_page']) : 10; // doc_slug $d_doc_slug = !empty($bp->bp_docs->query->doc_slug) ? $bp->bp_docs->query->doc_slug : ''; $defaults = array('doc_id' => array(), 'doc_slug' => $d_doc_slug, 'group_id' => $d_group_id, 'parent_id' => $d_parent_id, 'author_id' => $d_author_id, 'edited_by_id' => $d_edited_by_id, 'tags' => $d_tags, 'order' => $d_order, 'orderby' => $d_orderby, 'paged' => $d_paged, 'posts_per_page' => $d_posts_per_page, 'search_terms' => $d_search_terms); $r = wp_parse_args($args, $defaults); $doc_query_builder = new BP_Docs_Query($r); $bp->bp_docs->doc_query = $doc_query_builder->get_wp_query(); } return $bp->bp_docs->doc_query->have_posts(); }
/** * Markup for the Groups <td> on the docs loop * * @since 1.2 */ function groups_td() { global $bp; // Don't show on single group pages // @todo - When multiple group associations are supported, this should be added if (bp_is_group()) { return; } // Don't show on Started or Edited panels, where the info is // presented in the breadcrumb if (bp_docs_is_started_by() || bp_docs_is_edited_by()) { return; } $groups = (array) bp_docs_get_associated_group_id(get_the_ID(), false, true); $groups = array_unique($groups); // just in case ?> <td class="groups-cell"> <?php if (!empty($groups)) { ?> <ul> <?php foreach ($groups as $group_id) { ?> <?php $group = groups_get_group(array('group_id' => $group_id)); // Don't show hidden groups if the // current user is not a member if (isset($group->status) && 'hidden' === $group->status) { // @todo this is slow if (!current_user_can('bp_moderate') && !groups_is_user_member(bp_loggedin_user_id(), $group_id)) { continue; } } $group_permalink = bp_get_group_permalink($group); ?> <li><a href="<?php echo $group_permalink; ?> "> <?php echo bp_core_fetch_avatar(array('item_id' => $group_id, 'object' => 'group', 'type' => 'thumb', 'avatar_dir' => 'group-avatars', 'width' => '30', 'height' => '30', 'title' => $group->name)); ?> <?php echo $group->name; ?> </a></li> <?php } ?> </ul> <?php } ?> </td> <?php }
bp_docs_doc_action_links(); ?> </div> <div class="bp-docs-attachment-drawer" id="bp-docs-attachment-drawer-<?php echo get_the_ID(); ?> "> <?php bp_docs_doc_attachment_drawer(); ?> </div> </td> <?php if (!bp_docs_is_started_by()) { ?> <td class="author-cell"> <a href="<?php echo bp_core_get_user_domain(get_the_author_meta('ID')); ?> " title="<?php echo bp_core_get_user_displayname(get_the_author_meta('ID')); ?> "><?php echo bp_core_get_user_displayname(get_the_author_meta('ID')); ?> </a> </td> <?php }
/** * Initiates a BuddyPress Docs query * * @since 1.2 */ function bp_docs_has_docs($args = array()) { global $bp, $wp_query; // The if-empty is because, like with WP itself, we use bp_docs_has_docs() both for the // initial 'if' of the loop, as well as for the 'while' iterator. Don't want infinite // queries if (empty($bp->bp_docs->doc_query)) { // Build some intelligent defaults // Default to current group id, if available if (bp_is_active('groups') && bp_is_group()) { $d_group_id = bp_get_current_group_id(); } else { if (!empty($_REQUEST['group_id'])) { // This is useful for the AJAX request for folder contents. $d_group_id = $_REQUEST['group_id']; } else { if (bp_docs_is_mygroups_directory()) { $my_groups = groups_get_user_groups(bp_loggedin_user_id()); $d_group_id = !empty($my_groups['total']) ? $my_groups['groups'] : array(0); } else { $d_group_id = null; } } } // If this is a Started By tab, set the author ID $d_author_id = bp_docs_is_started_by() ? bp_displayed_user_id() : array(); // If this is an Edited By tab, set the edited_by id $d_edited_by_id = bp_docs_is_edited_by() ? bp_displayed_user_id() : array(); // Default to the tags in the URL string, if available $d_tags = isset($_REQUEST['bpd_tag']) ? explode(',', urldecode($_REQUEST['bpd_tag'])) : array(); // Order and orderby arguments $d_orderby = !empty($_GET['orderby']) ? urldecode($_GET['orderby']) : apply_filters('bp_docs_default_sort_order', 'modified'); if (empty($_GET['order'])) { // If no order is explicitly stated, we must provide one. // It'll be different for date fields (should be DESC) if ('modified' == $d_orderby || 'date' == $d_orderby) { $d_order = 'DESC'; } else { $d_order = 'ASC'; } } else { $d_order = $_GET['order']; } // Search $d_search_terms = !empty($_GET['s']) ? urldecode($_GET['s']) : ''; // Parent id $d_parent_id = !empty($_REQUEST['parent_doc']) ? (int) $_REQUEST['parent_doc'] : ''; // Folder id $d_folder_id = null; if (!empty($_GET['folder'])) { $d_folder_id = intval($_GET['folder']); } else { if (bp_docs_enable_folders_for_current_context()) { /* * 0 means we exclude docs that are in a folder. * So we only want this to be set in folder-friendly contexts. */ $d_folder_id = 0; } } // Page number, posts per page $d_paged = 1; if (!empty($_GET['paged'])) { $d_paged = absint($_GET['paged']); } else { if (bp_docs_is_global_directory() && is_a($wp_query, 'WP_Query') && 1 < $wp_query->get('paged')) { $d_paged = absint($wp_query->get('paged')); } else { $d_paged = absint($wp_query->get('paged', 1)); } } // Use the calculated posts_per_page number from $wp_query->query_vars. // If that value isn't set, we assume 10 posts per page. $d_posts_per_page = absint($wp_query->get('posts_per_page', 10)); // doc_slug $d_doc_slug = !empty($bp->bp_docs->query->doc_slug) ? $bp->bp_docs->query->doc_slug : ''; $defaults = array('doc_id' => array(), 'doc_slug' => $d_doc_slug, 'group_id' => $d_group_id, 'parent_id' => $d_parent_id, 'folder_id' => $d_folder_id, 'author_id' => $d_author_id, 'edited_by_id' => $d_edited_by_id, 'tags' => $d_tags, 'order' => $d_order, 'orderby' => $d_orderby, 'paged' => $d_paged, 'posts_per_page' => $d_posts_per_page, 'search_terms' => $d_search_terms, 'update_attachment_cache' => false); if (function_exists('bp_parse_args')) { $r = bp_parse_args($args, $defaults, 'bp_docs_has_docs'); } else { $r = wp_parse_args($args, $defaults); } $doc_query_builder = new BP_Docs_Query($r); $bp->bp_docs->doc_query = $doc_query_builder->get_wp_query(); if ($r['update_attachment_cache']) { $doc_ids = wp_list_pluck($bp->bp_docs->doc_query->posts, 'ID'); $att_hash = array_fill_keys($doc_ids, array()); if ($doc_ids) { $attachments = get_posts(array('post_type' => 'attachment', 'post_parent__in' => $doc_ids, 'update_post_term_cache' => false)); foreach ($attachments as $a) { $att_hash[$a->post_parent][] = $a; } foreach ($att_hash as $doc_id => $doc_atts) { wp_cache_set('bp_docs_attachments:' . $doc_id, $doc_atts, 'bp_docs_nonpersistent'); } } } } return $bp->bp_docs->doc_query->have_posts(); }
/** * Gets the list of terms used by a user's docs * * At the moment, this method (and the next one) assumes that you want the terms of the * displayed user. At some point, that should be abstracted a bit. * * @package BuddyPress_Docs * @subpackage Users * @since 1.2 * * @return array $terms */ function get_user_terms($terms = array()) { global $wpdb; if (!bp_is_user()) { return $terms; } $query_args = array('post_type' => bp_docs_get_post_type_name(), 'update_meta_cache' => false, 'update_term_cache' => true, 'showposts' => '-1', 'posts_per_page' => '-1'); if (bp_docs_is_edited_by()) { $query_args['post__in'] = BP_Docs_Query::get_edited_by_post_ids_for_user(bp_displayed_user_id()); $query_args['post_status'] = array('publish'); } else { if (bp_docs_is_started_by()) { $query_args['author'] = bp_displayed_user_id(); $query_args['post_status'] = array('publish', 'trash'); } else { // Just in case $query_args['post__in'] = array(0); } } $user_doc_query = new WP_Query($query_args); $terms = array(); foreach ($user_doc_query->posts as $p) { $p_terms = wp_get_post_terms($p->ID, buddypress()->bp_docs->docs_tag_tax_name); foreach ($p_terms as $p_term) { if (!isset($terms[$p_term->slug])) { $terms[$p_term->slug] = array('name' => $p_term->name, 'posts' => array()); } if (!in_array($p->ID, $terms[$p_term->slug]['posts'])) { $terms[$p_term->slug]['posts'][] = $p->ID; } } } foreach ($terms as &$t) { $t['count'] = count($t['posts']); } if (empty($terms)) { $terms = array(); } return apply_filters('bp_docs_taxonomy_get_user_terms', $terms); }