/** * Echo the pagination links for the doc list view * * @package BuddyPress Docs * @since 1.0-beta-2 */ function bp_docs_paginate_links() { global $bp, $wp_query, $wp_rewrite; $page_links_total = $bp->bp_docs->doc_query->max_num_pages; $pagination_args = array('base' => add_query_arg('paged', '%#%'), 'format' => '', 'prev_text' => __('«'), 'next_text' => __('»'), 'total' => $page_links_total, 'end_size' => 2); if ($wp_rewrite->using_permalinks()) { $pagination_args['base'] = apply_filters('bp_docs_page_links_base_url', user_trailingslashit(trailingslashit(bp_docs_get_archive_link()) . $wp_rewrite->pagination_base . '/%#%/', 'bp-docs-directory'), $wp_rewrite->pagination_base); } $page_links = paginate_links($pagination_args); echo apply_filters('bp_docs_paginate_links', $page_links); }
/** * Display the proper permalink for Docs * * This function filters 'post_type_link', which in turn powers get_permalink() and related * functions. * * BuddyPress Docs has a completely flat architecture for URLs, where * parent slugs never appear in the URL (as they do in the case of WP * pages). So we reconstruct the link completely. * * @package BuddyPress Docs * @since 1.1.8 * * @param str $link The permalink * @param obj $post The post object * @param bool $leavename * @param bool $sample See get_post_permalink() for an explanation of these two params * @return str $link The filtered permalink */ function filter_permalinks($link, $post, $leavename, $sample) { if (bp_docs_get_post_type_name() == $post->post_type) { $link = trailingslashit(bp_docs_get_archive_link() . $post->post_name); } return html_entity_decode($link); }
/** * Get an archive link for a given tag * * Optional arguments: * - 'tag' The tag linked to. This one is required * - 'type' 'html' returns a link; anything else returns a URL * * @since 1.0-beta * * @param array $args Optional arguments * @return array $filters */ function bp_docs_get_tag_link($args = array()) { global $bp; $defaults = array('tag' => false, 'type' => 'html'); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); if (bp_is_user()) { $current_action = bp_current_action(); $item_docs_url = bp_displayed_user_domain() . bp_docs_get_docs_slug() . '/'; if (empty($current_action) || BP_DOCS_STARTED_SLUG == $current_action) { $item_docs_url = bp_docs_get_displayed_user_docs_started_link(); } elseif (BP_DOCS_EDITED_SLUG == $current_action) { $item_docs_url = bp_docs_get_displayed_user_docs_edited_link(); } } elseif (bp_is_active('groups') && ($current_group = groups_get_current_group())) { /* * Pass the group object to bp_get_group_permalink() so that it works * when $groups_template may not be set, like during AJAX requests. */ $item_docs_url = trailingslashit(bp_get_group_permalink($current_group) . bp_docs_get_docs_slug()); } else { $item_docs_url = bp_docs_get_archive_link(); } $url = apply_filters('bp_docs_get_tag_link_url', add_query_arg('bpd_tag', urlencode($tag), $item_docs_url), $args, $item_docs_url); if ($type != 'html') { return apply_filters('bp_docs_get_tag_link_url', $url, $tag, $type); } $html = '<a href="' . $url . '" title="' . sprintf(__('Docs tagged %s', 'bp-docs'), esc_attr($tag)) . '">' . esc_html($tag) . '</a>'; return apply_filters('bp_docs_get_tag_link', $html, $url, $tag, $type); }
/** * Get an archive link for a given tag * * Optional arguments: * - 'tag' The tag linked to. This one is required * - 'type' 'html' returns a link; anything else returns a URL * * @package BuddyPress Docs * @since 1.0-beta * * @param array $args Optional arguments * @return array $filters */ function bp_docs_get_tag_link($args = array()) { global $bp; $defaults = array('tag' => false, 'type' => 'html'); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); if (bp_is_user() || bp_is_group()) { $item_docs_url = $_SERVER['REQUEST_URI']; } else { $item_docs_url = bp_docs_get_archive_link(); } $url = apply_filters('bp_docs_get_tag_link_url', add_query_arg('bpd_tag', urlencode($tag), $item_docs_url), $args, $item_docs_url); if ($type != 'html') { return apply_filters('bp_docs_get_tag_link_url', $url, $tag, $type); } $html = '<a href="' . $url . '" title="' . sprintf(__('Docs tagged %s', 'bp-docs'), esc_attr($tag)) . '">' . esc_html($tag) . '</a>'; return apply_filters('bp_docs_get_tag_link', $html, $url, $tag, $type); }
/** * Get an archive link for a given tag * * Optional arguments: * - 'tag' The tag linked to. This one is required * - 'type' 'html' returns a link; anything else returns a URL * - 'tags' The selected tags * * @param array $args Optional arguments * @return array $filters */ function bp_docs_get_tag_link_multitag($args = array()) { global $bp; $defaults = array('tag' => false, 'type' => 'html', 'tags' => array()); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); if (bp_is_user()) { $current_action = bp_current_action(); $item_docs_url = bp_displayed_user_domain() . bp_docs_get_docs_slug() . '/'; if (empty($current_action) || BP_DOCS_STARTED_SLUG == $current_action) { $item_docs_url = bp_docs_get_displayed_user_docs_started_link(); } elseif (BP_DOCS_EDITED_SLUG == $current_action) { $item_docs_url = bp_docs_get_displayed_user_docs_edited_link(); } } elseif (bp_is_active('groups') && ($current_group = groups_get_current_group())) { /* * Pass the group object to bp_get_group_permalink() so that it works * when $groups_template may not be set, like during AJAX requests. */ $item_docs_url = trailingslashit(bp_get_group_permalink($current_group) . bp_docs_get_docs_slug()); } else { $item_docs_url = bp_docs_get_archive_link(); } $bdp_tags = $tags; if (in_array($tag, $bdp_tags)) { // Remove because tag is selected $tag_key = array_search($tag, $bdp_tags); if ($tag_key !== FALSE) { unset($bdp_tags[$tag_key]); } } else { $bdp_tags[] = urlencode($tag); } if (!empty($_REQUEST['bool'])) { $item_docs_url = add_query_arg('bool', $_REQUEST['bool'], $item_docs_url); } else { /* * If not exist boolean argument, default add "and" condition */ $item_docs_url = add_query_arg('bool', 'and', $item_docs_url); } $bdp_tags = implode(',', array_filter($bdp_tags)); $url = apply_filters('bp_docs_get_tag_link_url', add_query_arg('bpd_tag', $bdp_tags, $item_docs_url), $args, $item_docs_url); if ($type != 'html') { return apply_filters('bp_docs_get_tag_link_url', $url, $tag, $type); } $html = '<a href="' . $url . '" title="' . sprintf(__('Docs tagged %s', 'bp-docs'), esc_attr($tag)) . '">' . esc_html($tag) . '</a>'; return apply_filters('bp_docs_get_tag_link', $html, $url, $tag, $type); }
/** * Get the link to create a Doc * * @package BuddyPress_Docs * @since 1.2 */ function bp_docs_get_create_link() { return apply_filters('bp_docs_get_create_link', trailingslashit(bp_docs_get_archive_link() . BP_DOCS_CREATE_SLUG)); }