/**
 * Returns the on-hover Quick Admin controls which appear for admin users on the Directory pages
 *
 * @since 2.0
 * @global object $bp BuddyPress global settings
 * @return string
 */
function dpa_get_achievements_quickadmin()
{
    global $bp;
    $items = array();
    if (!dpa_is_directory_page()) {
        return apply_filters('dpa_get_achievements_quickadmin', '', $items);
    }
    $url = dpa_get_achievement_slug_permalink();
    if (dpa_permission_can_user_change_picture()) {
        $items[] = sprintf('<a href="%1$s">%2$s</a>', $url . DPA_SLUG_ACHIEVEMENT_CHANGE_PICTURE, __('Change Picture', 'dpa'));
    }
    if (dpa_permission_can_user_delete()) {
        $items[] = sprintf('<a href="%1$s">%2$s</a>', $url . DPA_SLUG_ACHIEVEMENT_DELETE, __('Delete', 'dpa'));
    }
    if (dpa_permission_can_user_edit()) {
        $items[] = sprintf('<a href="%1$s">%2$s</a>', $url . DPA_SLUG_ACHIEVEMENT_EDIT, __('Edit', 'dpa'));
    }
    if (dpa_permission_can_user_grant()) {
        $items[] = sprintf('<a href="%1$s">%2$s</a>', $url . DPA_SLUG_ACHIEVEMENT_GRANT, __('Give', 'dpa'));
    }
    if (!$items) {
        return apply_filters('dpa_get_achievements_quickadmin', '', $items);
    }
    return apply_filters('dpa_get_achievements_quickadmin', '<span>' . implode('</span> | <span>', $items) . '</span>', $items);
}
예제 #2
0
/**
 * Set up navigation and register pages
 *
 * @global object $bp BuddyPress global settings
 * @global bool $is_member_page If we are under anything with a members slug
 * @since 2.0
 * @uses DPA_Achievement
 */
function dpa_setup_nav()
{
    global $bp, $is_member_page;
    $url = dpa_get_achievements_permalink() . '/';
    if (bp_is_current_component($bp->achievements->slug) && ($bp->achievements->current_achievement = new DPA_Achievement(array('type' => 'single', 'slug' => apply_filters('dpa_get_achievement_slug', $bp->current_action))))) {
        if (isset($bp->achievements->current_achievement->is_active) && !$bp->achievements->current_achievement->is_active && !dpa_permission_can_user_edit()) {
            // Require edit permission to view an inactive Achievement's pages
            bp_core_redirect(dpa_get_achievements_permalink());
            return;
        } else {
            if ($bp->achievements->current_achievement->id) {
                $bp->is_single_item = true;
            }
            $bp->is_item_admin = 0;
            if ($bp->loggedin_user->is_super_admin) {
                $bp->is_item_admin = 1;
            }
            // Possibly redundant since BP 1.1, but left for compatibility just in case
        }
    }
    // Add 'Achievements' to the main navigation
    bp_core_new_nav_item(array('name' => sprintf(__('Achievements <span>%s</span>', 'dpa'), dpa_get_total_achievement_count_for_user()), 'slug' => $bp->achievements->slug, 'position' => 80, 'screen_function' => 'dpa_screen_my_achievements', 'default_subnav_slug' => DPA_SLUG_MY_ACHIEVEMENTS, 'item_css_id' => $bp->achievements->id));
    $subnav_url = $bp->loggedin_user->domain . DPA_SLUG . '/';
    bp_core_new_subnav_item(array('name' => sprintf(__('My Achievements <span>%s</span>', 'dpa'), dpa_get_total_achievement_count_for_user()), 'slug' => DPA_SLUG_MY_ACHIEVEMENTS, 'parent_url' => $subnav_url, 'parent_slug' => $bp->achievements->slug, 'screen_function' => 'dpa_screen_my_achievements', 'position' => 10, 'item_css_id' => 'achievements_my'));
    if (bp_is_current_component($bp->achievements->slug)) {
        if (bp_is_my_profile() && !$bp->is_single_item) {
            $bp->bp_options_title = __('My Achievements', 'dpa');
        } elseif (!bp_is_my_profile() && !$bp->is_single_item) {
            $bp->bp_options_title = $bp->displayed_user->fullname;
        } elseif ($bp->is_single_item) {
            // When in a single listing, the first action is bumped down one because of the listing ID, so we need to adjust this and set the listing name to current_item.
            $bp->current_item = $bp->current_action;
            if (isset($bp->action_variables[0])) {
                $bp->current_action = $bp->action_variables[0];
            } else {
                $bp->current_action = '';
            }
            array_shift($bp->action_variables);
            $bp->bp_options_title = apply_filters('dpa_get_achievement_name', $bp->achievements->current_achievement->name);
            $achievement_link = $url . $bp->achievements->current_achievement->slug . '/';
            $parent_slug = $bp->achievements->current_achievement->slug;
            // Add to the main navigation
            $main_nav = array('name' => __('Home', 'dpa'), 'slug' => $bp->achievements->current_achievement->slug, 'position' => -1, 'screen_function' => 'dpa_screen_achievement_activity', 'default_subnav_slug' => DPA_SLUG_ACHIEVEMENT_ACTIVITY, 'item_css_id' => $bp->achievements->id);
            bp_core_new_nav_item($main_nav);
            /**
             * Setup the subnav items
             */
            // Add the "Home" subnav item, as this will always be present
            $sub_nav[] = array('name' => __('Home', 'dpa'), 'slug' => DPA_SLUG_ACHIEVEMENT_ACTIVITY, 'parent_url' => $achievement_link, 'parent_slug' => $parent_slug, 'screen_function' => 'dpa_screen_achievement_activity', 'position' => 20, 'item_css_id' => 'achievements_activity');
            $sub_nav[] = array('name' => sprintf(__('Unlocked By <span>%s</span>', 'dpa'), dpa_get_achievement_unlocked_count($bp->achievements->current_achievement->id)), 'slug' => DPA_SLUG_ACHIEVEMENT_UNLOCKED_BY, 'parent_url' => $achievement_link, 'parent_slug' => $parent_slug, 'screen_function' => 'dpa_screen_achievement_unlocked_by', 'position' => 40, 'item_css_id' => 'achievements_unlockedby');
            if (dpa_permission_can_user_change_picture()) {
                $sub_nav[] = array('name' => __('Change Picture', 'dpa'), 'slug' => DPA_SLUG_ACHIEVEMENT_CHANGE_PICTURE, 'parent_url' => $achievement_link, 'parent_slug' => $parent_slug, 'screen_function' => 'dpa_screen_achievement_change_picture', 'position' => 50, 'item_css_id' => 'achievements_changepicture');
            }
            if (dpa_permission_can_user_delete()) {
                $sub_nav[] = array('name' => __('Delete', 'dpa'), 'slug' => DPA_SLUG_ACHIEVEMENT_DELETE, 'parent_url' => $achievement_link, 'parent_slug' => $parent_slug, 'screen_function' => 'dpa_screen_achievement_delete', 'position' => 50, 'user_has_access' => dpa_permission_can_user_delete(), 'item_css_id' => 'achievements_delete');
            }
            if (dpa_permission_can_user_delete()) {
                $sub_nav[] = array('name' => __('Edit', 'dpa'), 'slug' => DPA_SLUG_ACHIEVEMENT_EDIT, 'parent_url' => $achievement_link, 'parent_slug' => $parent_slug, 'screen_function' => 'dpa_screen_achievement_edit', 'position' => 60, 'user_has_access' => dpa_permission_can_user_edit(), 'item_css_id' => 'achievements_edit');
            }
            if (dpa_permission_can_user_grant()) {
                $sub_nav[] = array('name' => __('Grant', 'dpa'), 'slug' => DPA_SLUG_ACHIEVEMENT_GRANT, 'parent_url' => $achievement_link, 'parent_slug' => $parent_slug, 'screen_function' => 'dpa_screen_achievement_grant', 'position' => 70, 'user_has_access' => dpa_permission_can_user_grant(), 'item_css_id' => 'achievements_grant');
            }
            // initialize the subnav items
            foreach ($sub_nav as $nav) {
                bp_core_new_subnav_item($nav);
            }
        }
    }
}