예제 #1
0
/**
 * Filter get_permalink for mediapress gallery post type( mpp-gallery)
 * aand make it like site.com/members/username/mediapressslug/gallery-name or site.com/{component-page}/{single-component}/mediapress-slug/gallery-name
 * It allows us to get the permalink to gallery by using the_permalink/get_permalink functions
 */
function mpp_filter_gallery_permalink($permalink, $post, $leavename, $sample)
{
    if (mpp_get_gallery_post_type() != $post->post_type) {
        return $permalink;
    }
    $gallery = mpp_get_gallery($post);
    $slug = $gallery->slug;
    $base_url = mpp_get_gallery_base_url($gallery->component, $gallery->component_id);
    return apply_filters('mpp_get_gallery_permalink', $base_url . '/' . $slug, $gallery);
}
예제 #2
0
function mp_group_nav()
{
    if (!bp_is_group()) {
        return;
    }
    $component = 'groups';
    $component_id = groups_get_current_group()->id;
    if (mpp_user_can_create_gallery($component, $component_id)) {
        echo sprintf("<li><a href='%s'>%s</a></li>", mpp_get_gallery_base_url($component, $component_id), __('All Galleries', 'mediapress'));
        echo sprintf("<li><a href='%s'>%s</a></li>", mpp_get_gallery_create_url($component, $component_id), __('Create Gallery', 'mediapress'));
    }
}
예제 #3
0
/**
 * Filter get_permalink for mediapress gallery post type( mpp-gallery)
 * aand make it like site.com/members/username/mediapressslug/gallery-name or site.com/{component-page}/{single-component}/mediapress-slug/gallery-name
 * It allows us to get the permalink to gallery by using the_permalink/get_permalink functions
 */
function mpp_filter_gallery_permalink($permalink, $post, $leavename, $sample)
{
    //check if BuddyPress is active, if not, we don't filter it yet
    //lightweight check
    if (!mediapress()->is_bp_active()) {
        return $permalink;
    }
    //a little more expensive
    if (mpp_get_gallery_post_type() != $post->post_type) {
        return $permalink;
    }
    //this is expensive if the post is not cached
    //If you see too many queries, just make sure to call _prime_post_caches($ids, true, true ); where $ids is collection of post ids
    //that will save a lot of query
    $gallery = mpp_get_gallery($post);
    // do not modify permalinks for Sitewide gallery
    if ($gallery->component == 'sitewide') {
        return $permalink;
    }
    $slug = $gallery->slug;
    $base_url = mpp_get_gallery_base_url($gallery->component, $gallery->component_id);
    return apply_filters('mpp_get_gallery_permalink', $base_url . '/' . $slug, $gallery);
}
 /**
  * Set up the Toolbar.
  *
  * @param array $wp_admin_nav See {BP_Component::setup_admin_bar()}
  *        for details.
  */
 public function setup_admin_bar($wp_admin_nav = array())
 {
     $bp = buddypress();
     // Menus for logged in user if the members gallery is enabled
     if (is_user_logged_in() && mpp_is_enabled('members', bp_loggedin_user_id())) {
         $component = 'members';
         $component_id = get_current_user_id();
         $gallery_link = trailingslashit(mpp_get_gallery_base_url($component, $component_id));
         $title = __('Gallery', 'mediapress');
         $my_galleries = __('My Gallery', 'mediapress');
         $create = __('Create', 'mediapress');
         // Add main mediapress menu
         $wp_admin_nav[] = array('parent' => $bp->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => $title, 'href' => trailingslashit($gallery_link));
         // Add main mediapress menu
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-my-galleries', 'title' => $my_galleries, 'href' => trailingslashit($gallery_link));
         if (mpp_user_can_create_gallery($component, $component_id)) {
             $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-create', 'title' => $create, 'href' => mpp_get_gallery_create_url($component, $component_id));
         }
     }
     parent::setup_admin_bar($wp_admin_nav);
 }
/**
 * Generate/Display breadcrumb 
 * @param array $args
 * @return string|null
 */
function mpp_gallery_breadcrumb($args = null)
{
    $default = array('separator' => '/', 'before' => '', 'after' => '', 'show_home' => false);
    $args = wp_parse_args($args, $default);
    extract($args);
    $crumbs = array();
    $component = mpp_get_current_component();
    $component_id = mpp_get_current_component_id();
    if (mediapress()->is_bp_active() && bp_is_active('groups') && bp_is_group()) {
        $name = bp_get_group_name(groups_get_current_group());
    } elseif (mediapress()->is_bp_active() && bp_is_user()) {
        $name = bp_get_displayed_user_fullname();
    } elseif ($component == 'sitewide') {
        $name = '';
    }
    $my_or_his_gallery = '';
    if ($name) {
        $my_or_his_gallery = sprintf(__("%s's gallery", 'mediapress'), $name);
    }
    if (function_exists('bp_is_my_profile') && bp_is_my_profile()) {
        $my_or_his_gallery = __('Your Galleries', 'mediapress');
    }
    if (mpp_is_media_management()) {
        $crumbs[] = ucwords(mediapress()->get_edit_action());
    }
    if (mpp_is_single_media()) {
        $media = mpp_get_current_media();
        if (mpp_is_media_management()) {
            $crumbs[] = sprintf('<a href="%s">%s</a>', mpp_get_media_permalink($media), mpp_get_media_title($media));
        } else {
            $crumbs[] = sprintf('<span>%s</span>', mpp_get_media_title($media));
        }
    }
    if (mpp_is_gallery_management()) {
        $crumbs[] = ucwords(mediapress()->get_edit_action());
    }
    if (mpp_is_single_gallery()) {
        $gallery = mpp_get_current_gallery();
        if (mpp_is_gallery_management() || mpp_is_single_media()) {
            $crumbs[] = sprintf('<a href="%s">%s</a>', mpp_get_gallery_permalink($gallery), mpp_get_gallery_title($gallery));
        } else {
            $crumbs[] = sprintf('<span>%s</span>', mpp_get_gallery_title($gallery));
        }
    }
    if ($my_or_his_gallery) {
        $crumbs[] = sprintf('<a href="%s">%s</a>', mpp_get_gallery_base_url($component, $component_id), $my_or_his_gallery);
    }
    if (count($crumbs) <= 1 && !$show_home) {
        return;
    }
    $crumbs = array_reverse($crumbs);
    echo join($separator, $crumbs);
}
예제 #6
0
/**
 * Handles Gallery deletion
 * 
 * @return type
 */
function mpp_action_delete_gallery()
{
    if (empty($_POST['mpp-action']) || $_POST['mpp-action'] != 'delete-gallery') {
        return;
    }
    if (empty($_POST['gallery_id'])) {
        return;
    }
    $referer = wp_get_referer();
    if (!wp_verify_nonce($_POST['mpp-nonce'], 'mpp-delete-gallery')) {
        //add error message and return back to the old page
        mpp_add_feedback(__('Action not authorized!', 'mediapress'), 'error');
        if ($referer) {
            mpp_redirect($referer);
        }
        return;
    }
    if (empty($_POST['mpp-delete-agree'])) {
        return;
        //@todo add feedback that you must agree
    }
    $gallery = '';
    if (!empty($_POST['gallery_id'])) {
        $gallery = mpp_get_gallery(absint($_POST['gallery_id']));
    }
    //check for permission
    //we may want to allow passing of component from the form in future!
    if (!mpp_user_can_delete_gallery($gallery)) {
        mpp_add_feedback(__("You don't have permission to delete this gallery!", 'mediapress'), 'error');
        if ($referer) {
            mpp_redirect($referer);
        }
        return;
    }
    //if we are here, delete gallery and redirect to the component base url
    $redirect_url = mpp_get_gallery_base_url($gallery->component, $gallery->component_id);
    mpp_delete_gallery($gallery->id);
    mpp_redirect($redirect_url);
}
예제 #7
0
function mpp_gallery_create_form_action()
{
    echo mpp_get_gallery_base_url(mpp_get_current_component(), mpp_get_current_component_id()) . '/create';
}
function mpp_group_get_user_galleries_url()
{
    $component = 'groups';
    $component_id = groups_get_current_group()->id;
    return user_trailingslashit(trailingslashit(mpp_get_gallery_base_url($component, $component_id)) . 'my-gallery');
}