/**
 * Add group information to individual Doc breadcrumbs.
 *
 * Hooked very late to ensure it's the first item on the list.
 *
 * @since 1.9.0
 *
 * @param array $crumbs
 * @return array
 */
function bp_docs_group_single_breadcrumb($crumbs, $doc = null)
{
    $group_id = null;
    if (is_a($doc, 'WP_Post')) {
        $group_id = bp_docs_get_associated_group_id($doc->ID);
    } else {
        if (bp_docs_is_existing_doc()) {
            $group_id = bp_docs_get_associated_group_id(get_queried_object_id());
        }
    }
    if ($group_id) {
        $group = groups_get_group(array('group_id' => $group_id));
    }
    if (empty($group->name)) {
        return $crumbs;
    }
    // Ensure that the user has access to the group before adding t othe
    // breadcrumb
    $user_has_access = true;
    if ('public' !== $group->status) {
        $user_has_access = current_user_can('bp_moderate') || groups_is_user_member(bp_loggedin_user_id(), $group->id);
    }
    if ($user_has_access) {
        $group_crumbs = array(sprintf('<a href="%s">%s&#8217;s Docs</a>', bp_get_group_permalink($group) . bp_docs_get_slug() . '/', esc_html($group->name)));
        $crumbs = array_merge($group_crumbs, $crumbs);
    } else {
        // If the user doesn't have access to the associated group,
        // don't show the group folder breadcrumb either
        $doc_crumb = array_pop($crumbs);
        $crumbs = array($doc_crumb);
    }
    return $crumbs;
}
function bp_docs_slug()
{
    echo bp_docs_get_slug();
}
 /**
  * checks, whether the current page contains buddypress docs contents
  *
  * @static
  * @since   0.1
  * @access  public
  *
  * @returns bool
  */
 static function is_bp_doc_page()
 {
     $dirs = explode('/', $_SERVER['REQUEST_URI']);
     $slug = isset($dirs[1]) ? $dirs[1] : '';
     if ($slug == bp_docs_get_slug()) {
         return true;
     }
     if (!bp_is_group() && !bp_is_my_profile() && get_post_type() == 'bp_doc' && !is_archive()) {
         return true;
     }
     return false;
 }
Пример #4
0
/**
 * Is this the BP Docs component?
 */
function bp_docs_is_docs_component()
{
    $retval = false;
    $p = get_queried_object();
    if (is_post_type_archive(bp_docs_get_post_type_name())) {
        $retval = true;
    } else {
        if (isset($p->post_type) && bp_docs_get_post_type_name() == $p->post_type) {
            $retval = true;
        } else {
            if (bp_is_current_component(bp_docs_get_slug())) {
                // This covers cases where we're looking at the Docs component of a user
                $retval = true;
            }
        }
    }
    return $retval;
}
Пример #5
0
 /**
  * Posts an activity item when a comment is posted to a doc
  *
  * @package BuddyPress Docs
  * @since 1.0-beta
  *
  * @param obj $query The id of the comment that's just been saved
  * @return int $activity_id The id number of the activity created
  */
 function post_comment_activity($comment_id)
 {
     global $bp;
     if (!bp_is_active('activity')) {
         return false;
     }
     if (empty($comment_id)) {
         return false;
     }
     $comment = get_comment($comment_id);
     $doc = !empty($comment->comment_post_ID) ? get_post($comment->comment_post_ID) : false;
     if (empty($doc)) {
         return false;
     }
     // Only continue if this is a BP Docs post
     if ($doc->post_type != bp_docs_get_post_type_name()) {
         return;
     }
     $doc_id = !empty($doc->ID) ? $doc->ID : false;
     if (!$doc_id) {
         return false;
     }
     // Make sure that BP doesn't record this comment with its native functions
     remove_action('comment_post', 'bp_blogs_record_comment', 10, 2);
     // Until better individual activity item privacy controls are available in BP,
     // comments will only be shown in the activity stream if "Who can read comments on
     // this doc?" is set to "Anyone", "Logged-in Users" or "Group members"
     $doc_settings = get_post_meta($doc_id, 'bp_docs_settings', true);
     if (!empty($doc_settings['read_comments']) && !in_array($doc_settings['read_comments'], array('anyone', 'loggedin', 'group-members'))) {
         return false;
     }
     // See if we're associated with a group
     $group_id = bp_docs_get_associated_group_id($doc_id);
     if ($group_id) {
         $component = 'groups';
         $item = $group_id;
     } else {
         $component = bp_docs_get_slug();
         $item = 0;
     }
     // Set the action. Filterable so that other integration pieces can alter it
     $action = '';
     $commenter = get_user_by('email', $comment->comment_author_email);
     $commenter_id = !empty($commenter->ID) ? $commenter->ID : false;
     // Since BP Docs only allows member comments, the following should never happen
     if (!$commenter_id) {
         return false;
     }
     $user_link = bp_core_get_userlink($commenter_id);
     $doc_url = bp_docs_get_doc_link($doc_id);
     $comment_url = $doc_url . '#comment-' . $comment->comment_ID;
     $comment_link = '<a href="' . $comment_url . '">' . $doc->post_title . '</a>';
     $action = sprintf(__('%1$s commented on the doc %2$s', 'bp-docs'), $user_link, $comment_link);
     $action = apply_filters('bp_docs_comment_activity_action', $action, $user_link, $comment_link, $component, $item);
     // Set the type, to be used in activity filtering
     $type = 'bp_doc_comment';
     $hide_sitewide = bp_docs_hide_sitewide_for_doc($doc_id);
     $args = array('user_id' => $commenter_id, 'action' => $action, 'content' => $comment->comment_content, 'primary_link' => $comment_url, 'component' => $component, 'type' => $type, 'item_id' => $item, 'secondary_item_id' => $comment_id, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => apply_filters('bp_docs_hide_sitewide', $hide_sitewide, $comment, $doc, $item, $component));
     do_action('bp_docs_before_comment_activity_save', $args);
     $activity_id = bp_activity_add(apply_filters('bp_docs_comment_activity_args', $args));
     do_action('bp_docs_after_comment_activity_save', $activity_id, $args);
     return $activity_id;
 }
Пример #6
0
 /**
  * When looking at a single doc, this adds the appropriate subnav item.
  *
  * Other navigation items are added in BP_Docs_Component. We add this item here because it's
  * not until later in the load order when we can be certain whether we're viewing a
  * single Doc.
  *
  * @since 1.2
  */
 function setup_single_doc_subnav()
 {
     global $bp;
     if (bp_is_user() && !empty($bp->bp_docs->current_view) && in_array($bp->bp_docs->current_view, array('single', 'edit', 'history', 'delete'))) {
         $doc = bp_docs_get_current_doc();
         if (!empty($doc)) {
             bp_core_new_subnav_item(array('name' => $doc->post_title, 'slug' => $doc->post_name, 'parent_url' => trailingslashit(bp_loggedin_user_domain() . bp_docs_get_slug()), 'parent_slug' => bp_docs_get_slug(), 'screen_function' => array($bp->bp_docs, 'template_loader'), 'position' => 30, 'user_has_access' => true));
         }
     }
 }
/**
 * Add user information to individual Doc breadcrumbs.
 *
 * Hooked very late to ensure it's the first item on the list.
 *
 * @since 1.9.0
 *
 * @param array $crumbs
 * @return array
 */
function bp_docs_user_single_breadcrumb($crumbs, $doc = null)
{
    if (is_a($doc, 'WP_Post')) {
        $doc_id = $doc->ID;
    } else {
        if (bp_docs_is_existing_doc()) {
            $doc_id = get_queried_object_id();
        }
    }
    if (bp_docs_enable_folders() && !empty($doc_id)) {
        $folder_id = bp_docs_get_doc_folder($doc_id);
        if ($folder_id) {
            $user_id = bp_docs_get_folder_user($folder_id);
        }
    }
    if (!empty($user_id)) {
        $user_crumbs = array(sprintf('<a href="%s">%s&#8217;s Docs</a>', bp_core_get_user_domain($user_id) . bp_docs_get_slug() . '/', bp_core_get_user_displayname($user_id)));
        $crumbs = array_merge($user_crumbs, $crumbs);
    }
    return $crumbs;
}
Пример #8
0
 function flush_rewrite_rules()
 {
     if (!is_admin()) {
         return;
     }
     if (!is_super_admin()) {
         return;
     }
     global $wp_rewrite;
     // Check to see whether our rules have been registered yet, by
     // finding a Docs rule and then comparing it to the registered rules
     foreach ($wp_rewrite->extra_rules_top as $rewrite => $rule) {
         if (0 === strpos($rewrite, bp_docs_get_slug())) {
             $test_rule = $rule;
         }
     }
     $registered_rules = get_option('rewrite_rules');
     if (is_array($registered_rules) && !in_array($test_rule, $registered_rules)) {
         flush_rewrite_rules();
     }
 }