RTMediaNav::sub_nav PHP Method

sub_nav() public method

public sub_nav ( )
    public function sub_nav()
    {
        global $rtmedia, $rtmedia_query;
        if (function_exists('bp_is_group') && bp_is_group()) {
            if (isset($rtmedia->options['buddypress_enableOnGroup']) && 0 === intval($rtmedia->options['buddypress_enableOnGroup'])) {
                return;
            }
            global $bp;
            $counts = $this->actual_counts($bp->groups->current_group->id, 'group');
        } else {
            if (class_exists('BuddyPress') && isset($rtmedia->options['buddypress_enableOnProfile']) && 0 === intval($rtmedia->options['buddypress_enableOnProfile'])) {
                return;
            }
            $counts = $this->actual_counts();
        }
        $default = false;
        if (function_exists('bp_is_group') && bp_is_group()) {
            $link = get_rtmedia_group_link(bp_get_group_id());
            $model = new RTMediaModel();
            $other_count = $model->get_other_album_count(bp_get_group_id(), 'group');
        } else {
            if (function_exists('bp_displayed_user_id') && bp_displayed_user_id()) {
                $link = get_rtmedia_user_link(bp_displayed_user_id());
            } elseif (get_query_var('author')) {
                $link = get_rtmedia_user_link(get_query_var('author'));
            }
            $model = new RTMediaModel();
            $other_count = $model->get_other_album_count(bp_displayed_user_id(), 'profile');
        }
        $all = '';
        if (!isset($rtmedia_query->action_query->media_type) && !isset($rtmedia_query->query['media_type'])) {
            $all = 'current selected';
        }
        echo apply_filters('rtmedia_sub_nav_all', '<li id="rtmedia-nav-item-all-li" class="' . esc_attr($all) . '"><a id="rtmedia-nav-item-all" href="' . esc_url(trailingslashit($link)) . RTMEDIA_MEDIA_SLUG . '/">' . esc_html__('All', 'buddypress-media') . '<span>' . esc_html(isset($counts['total']['all']) ? $counts['total']['all'] : 0) . '</span>' . '</a></li>');
        // @codingStandardsIgnoreLine
        if (!isset($rtmedia_query->action_query->action) || empty($rtmedia_query->action_query->action)) {
            $default = true;
        }
        $albums = '';
        //condition to keep "Album" tab active
        if (array_key_exists('media_type', $rtmedia_query->query) && isset($rtmedia_query->query['media_type']) && 'album' === $rtmedia_query->query['media_type']) {
            $albums = 'current selected';
        } elseif (array_key_exists('media_type', $rtmedia_query->action_query) && isset($rtmedia_query->action_query->media_type) && 'album' === $rtmedia_query->action_query->media_type) {
            $albums = 'current selected';
        }
        if (is_rtmedia_album_enable()) {
            if (!isset($counts['total']['album'])) {
                $counts['total']['album'] = 0;
            }
            $counts['total']['album'] = $counts['total']['album'] + $other_count;
            $album_label = esc_html__(defined('RTMEDIA_ALBUM_PLURAL_LABEL') ? constant('RTMEDIA_ALBUM_PLURAL_LABEL') : 'Albums', 'buddypress-media');
            echo apply_filters('rtmedia_sub_nav_albums', '<li id="rtmedia-nav-item-albums-li" class="' . esc_attr($albums) . '"><a id="rtmedia-nav-item-albums" href="' . esc_url(trailingslashit($link)) . RTMEDIA_MEDIA_SLUG . '/album/">' . esc_html($album_label) . '<span>' . esc_html(isset($counts['total']['album']) ? $counts['total']['album'] : 0) . '</span>' . '</a></li>');
            // @codingStandardsIgnoreLine
        }
        foreach ($rtmedia->allowed_types as $type) {
            if (!isset($rtmedia->options['allowedTypes_' . $type['name'] . '_enabled'])) {
                continue;
            }
            if (!$rtmedia->options['allowedTypes_' . $type['name'] . '_enabled']) {
                continue;
            }
            $selected = '';
            if (isset($rtmedia_query->action_query->media_type) && $type['name'] === $rtmedia_query->action_query->media_type) {
                $selected = ' class="current selected"';
            } else {
                $selected = '';
            }
            $context = isset($rtmedia_query->query['context']) ? $rtmedia_query->query['context'] : 'default';
            $context_id = isset($rtmedia_query->query['context_id']) ? $rtmedia_query->query['context_id'] : 0;
            $name = strtoupper($type['name']);
            $is_group = false;
            $profile = self::profile_id();
            if (!$profile) {
                $profile = self::group_id();
                $is_group = true;
            }
            if (!$is_group) {
                $profile_link = trailingslashit(get_rtmedia_user_link($profile));
            } else {
                $profile_link = trailingslashit(get_rtmedia_group_link($profile));
            }
            $type_label = esc_html__(defined('RTMEDIA_' . $name . '_PLURAL_LABEL') ? constant('RTMEDIA_' . $name . '_PLURAL_LABEL') : $type['plural_label'], 'buddypress-media');
            echo apply_filters('rtmedia_sub_nav_' . $type['name'], '<li id="rtmedia-nav-item-' . esc_attr($type['name']) . '-' . esc_attr($context) . '-' . esc_attr($context_id) . '-li" ' . $selected . '><a id="rtmedia-nav-item-' . esc_attr($type['name']) . '" href="' . esc_url($profile_link . RTMEDIA_MEDIA_SLUG . '/' . constant('RTMEDIA_' . $name . '_SLUG') . '/') . '">' . $type_label . '<span>' . esc_html(isset($counts['total'][$type['name']]) ? $counts['total'][$type['name']] : 0) . '</span>' . '</a></li>', $type['name']);
        }
        do_action('add_extra_sub_nav');
    }

Usage Example

function rtmedia_sub_nav()
{
    global $rtMediaNav;
    $rtMediaNav = new RTMediaNav();
    $rtMediaNav->sub_nav();
}