/** * On group Doc directories, modify the pagination base so that pagination * works within the directory. * * @since 1.9.0 */ public function filter_bp_docs_page_links_base_url($base_url, $wp_rewrite_pag_base) { if (bp_is_group()) { $base_url = user_trailingslashit(trailingslashit(bp_get_group_permalink() . bp_docs_get_docs_slug()) . $wp_rewrite_pag_base . '/%#%/'); } else { if (bp_docs_is_mygroups_directory()) { $base_url = user_trailingslashit(trailingslashit(bp_docs_get_mygroups_link()) . $wp_rewrite_pag_base . '/%#%/'); } } return $base_url; }
/** * 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_group()) { $d_group_id = bp_get_current_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 = 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')); } 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, '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(); }
/** * Are we looking at something that needs docs theme compatability? * * @since 1.3 */ public function is_docs() { $is_docs = bp_docs_is_docs_component(); if (bp_is_active('groups') && bp_is_group() && bp_is_current_action(buddypress()->bp_docs->slug)) { $is_docs = true; } // Bail if not looking at the docs component if (!$is_docs) { return; } add_filter('bp_get_template_stack', array($this, 'add_plugin_templates_to_stack')); add_filter('bp_get_buddypress_template', array($this, 'query_templates')); add_filter('bp_use_theme_compat_with_current_theme', 'bp_docs_do_theme_compat'); if (bp_docs_is_global_directory() || bp_docs_is_mygroups_directory()) { bp_update_is_directory(true, 'docs'); do_action('bp_docs_screen_index'); add_action('bp_template_include_reset_dummy_post_data', array($this, 'directory_dummy_post')); add_filter('bp_replace_the_content', array($this, 'directory_content')); } else { if (bp_docs_is_existing_doc()) { if (bp_docs_is_doc_history()) { $this->single_content_template = 'docs/single/history'; add_filter('bp_force_comment_status', '__return_false'); } else { if (bp_docs_is_doc_edit()) { $this->single_content_template = 'docs/single/edit'; add_filter('bp_force_comment_status', '__return_false'); } else { $this->single_content_template = 'docs/single/index'; add_filter('bp_docs_allow_comment_section', '__return_false'); // Necessary as of BP 1.9.2 remove_action('bp_replace_the_content', 'bp_theme_compat_toggle_is_page', 9999); } } add_action('bp_template_include_reset_dummy_post_data', array($this, 'single_dummy_post')); add_filter('bp_replace_the_content', array($this, 'single_content')); } else { if (bp_docs_is_doc_create()) { add_action('bp_template_include_reset_dummy_post_data', array($this, 'create_dummy_post')); add_filter('bp_replace_the_content', array($this, 'create_content')); } } } }
/** * Loads JavaScript * * @package BuddyPress Docs * @since 1.0-beta */ function enqueue_scripts() { wp_register_script('bp-docs-js', plugins_url(BP_DOCS_PLUGIN_SLUG . '/includes/js/bp-docs.js'), array('jquery')); // This is for edit/create scripts if (bp_docs_is_doc_edit() || bp_docs_is_doc_create() || !empty($this->query->current_view) && ('edit' == $this->query->current_view || 'create' == $this->query->current_view)) { require_once ABSPATH . '/wp-admin/includes/post.php'; wp_enqueue_script('common'); wp_enqueue_script('jquery-color'); wp_enqueue_script('editor'); wp_enqueue_script('utils'); wp_register_script('bp-docs-idle-js', plugins_url(BP_DOCS_PLUGIN_SLUG . '/includes/js/idle.js'), array('jquery', 'bp-docs-js')); wp_enqueue_script('bp-docs-idle-js'); wp_register_script('jquery-colorbox', plugins_url(BP_DOCS_PLUGIN_SLUG . '/lib/js/colorbox/jquery.colorbox-min.js'), array('jquery')); wp_enqueue_script('jquery-colorbox'); // Edit mode requires bp-docs-js to be dependent on TinyMCE, so we must // reregister bp-docs-js with the correct dependencies wp_deregister_script('bp-docs-js'); wp_register_script('bp-docs-js', plugins_url(BP_DOCS_PLUGIN_SLUG . '/includes/js/bp-docs.js'), array('jquery', 'editor', 'heartbeat')); wp_register_script('word-counter', site_url() . '/wp-admin/js/word-count.js', array('jquery')); wp_enqueue_script('bp-docs-edit-validation', plugins_url(BP_DOCS_PLUGIN_SLUG . '/includes/js/edit-validation.js'), array('jquery', 'bp-docs-js')); } // Only load our JS on the right sorts of pages. Generous to account for // different item types if (in_array(bp_docs_get_docs_slug(), $this->slugstocheck) || bp_docs_is_single_doc() || bp_docs_is_global_directory() || bp_docs_is_mygroups_directory() || bp_docs_is_doc_create()) { wp_enqueue_script('bp-docs-js'); wp_enqueue_script('comment-reply'); $strings = array('upload_title' => __('Upload File', 'bp-docs'), 'upload_button' => __('OK', 'bp-docs'), 'still_working' => __('Still working?', 'bp-docs'), 'and_x_more' => __('and %d more', 'bp-docs'), 'failed_submission' => !empty(buddypress()->bp_docs->submitted_data) ? 1 : 0); if (bp_docs_is_doc_edit()) { $strings['pulse'] = bp_docs_heartbeat_pulse(); } wp_localize_script('bp-docs-js', 'bp_docs', $strings); } }
/** * 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(); }