/** * Hook the Folders functionality into Docs. * * @since 1.9 */ public function setup_hooks() { // Generate tax_query syntax for folder queries. add_filter('bp_docs_tax_query', 'bp_docs_folder_tax_query', 10, 2); // Filter capabilities for folders. add_filter('bp_docs_map_meta_caps', 'bp_docs_folders_map_meta_caps', 10, 4); // Validate folder selection when saving a Doc. add_filter('bp_docs_before_save_folder_selection', 'bp_docs_validate_group_folder_selection_on_doc_save', 10, 2); // Single Doc breadcrumbs. add_action('bp_docs_doc_breadcrumbs', 'bp_docs_folder_single_breadcrumb', 10, 2); // Show folder info on a single Doc. add_action('bp_docs_single_doc_meta', 'bp_docs_display_folder_meta'); // Add Folders meta box to Edit screen. add_action('bp_docs_before_tags_meta_box', 'bp_docs_folders_meta_box'); // Process new folder selections after save. add_action('bp_docs_after_save', 'bp_docs_save_folder_selection'); // Screen controllers. add_action('bp_actions', 'bp_docs_process_folder_edit_cb'); add_action('bp_actions', 'bp_docs_process_folder_create_cb'); add_action('bp_actions', 'bp_docs_process_folder_delete_cb'); // AJAX callbacks. add_action('wp_ajax_bp_docs_update_folders', 'bp_docs_update_folders_cb'); add_action('wp_ajax_bp_docs_update_parent_folders', 'bp_docs_update_parent_folders_cb'); add_action('wp_ajax_bp_docs_update_folder_type', 'bp_docs_update_folder_type_cb'); add_action('wp_ajax_bp_docs_update_folder_type_for_group', 'bp_docs_update_folder_type_for_group_cb'); add_action('wp_ajax_bp_docs_process_folder_drop', 'bp_docs_process_folder_drop_cb'); // AJAX template calls add_action('wp_ajax_bp_docs_get_folder_content', 'bp_docs_get_folder_content_cb'); add_action('wp_ajax_nopriv_bp_docs_get_folder_content', 'bp_docs_get_folder_content_cb'); // Folders UI is limited to the Group context for now. Change at your own risk. if (!bp_docs_enable_folders_for_current_context()) { return; } // Directory breadcrumbs. add_filter('bp_docs_directory_breadcrumb', 'bp_docs_folders_directory_breadcrumb', 6); // Add folder info to directory filter message. add_filter('bp_docs_get_current_filters', 'bp_docs_folder_current_filters'); // Ensure folder filters are maintained during directory filters. add_action('bp_docs_directory_filter_attachments_form', 'bp_docs_folders_directory_filter_form_argument'); add_action('bp_docs_directory_filter_search_form', 'bp_docs_folders_directory_filter_form_argument'); // Add current folder info to info message. add_filter('bp_docs_info_header_message', 'bp_docs_folder_info_header_message', 10, 2); // Set up conditional filtering of tag links. add_action('bp_docs_directory_filter_taxonomy_before', 'bp_docs_folders_directory_filter_taxonomy_hooker'); add_action('bp_docs_directory_filter_taxonomy_after', 'bp_docs_folders_directory_filter_taxonomy_unhooker'); // Modify Create links to be folder-sensitive. add_filter('bp_docs_get_create_link', 'bp_docs_folders_create_link'); // Determine whether the directory view is filtered by a folder request. add_filter('bp_docs_is_directory_view_filtered', 'bp_docs_is_directory_view_filtered_by_folder', 10, 2); }
<table class="doctable"> <tbody> <?php if (bp_docs_enable_folders_for_current_context()) { ?> <?php if (bp_docs_include_folders_in_loop_view()) { ?> <?php foreach (bp_docs_get_folders() as $folder) { $folder_title = esc_html($folder->post_title); $folder_id = $folder->ID; $folder_url = esc_url(bp_docs_get_folder_url($folder_id)); ?> <tr class="folder-row"> <?php /* Just to keep things even */ ?> <?php if (bp_docs_enable_attachments()) { ?> <td class="attachment-clip-cell"> <?php bp_docs_attachment_icon(); ?> </td> <?php } ?> <td class="folder-row-name" colspan=10>
/** * 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(); }