コード例 #1
0
 public function setup_nav($main = array(), $sub = array())
 {
     $bp = buddypress();
     $component = 'members';
     $component_id = mpp_get_current_component_id();
     if (!mpp_is_enabled($component, $component_id)) {
         //allow to disable user galleries in case they don't want it
         return false;
     }
     $view_helper = MPP_Gallery_Screens::get_instance();
     // Add 'Gallery' to the user's main navigation
     $main_nav = array('name' => sprintf(__('Gallery <span>%d</span>', 'mediapress'), mpp_get_total_gallery_for_user()), 'slug' => $this->slug, 'position' => 86, 'screen_function' => array($view_helper, 'user_galleries'), 'default_subnav_slug' => 'my-galleries', 'item_css_id' => $this->id);
     if (bp_is_user()) {
         $user_domain = bp_displayed_user_domain();
     } else {
         $user_domain = bp_loggedin_user_domain();
     }
     $gallery_link = trailingslashit($user_domain . $this->slug);
     //with a trailing slash
     // Add the My Gallery nav item
     $sub_nav[] = array('name' => __('My Gallery', 'mediapress'), 'slug' => 'my-galleries', 'parent_url' => $gallery_link, 'parent_slug' => $this->slug, 'screen_function' => array($view_helper, 'my_galleries'), 'position' => 10, 'item_css_id' => 'gallery-my-gallery');
     if (mpp_user_can_create_gallery($component, get_current_user_id())) {
         // Add the Create gallery link to gallery nav
         $sub_nav[] = array('name' => __('Create a Gallery', 'mediapress'), 'slug' => 'create', 'parent_url' => $gallery_link, 'parent_slug' => $this->slug, 'screen_function' => array($view_helper, 'my_galleries'), 'user_has_access' => bp_is_my_profile(), 'position' => 20);
     }
     if (mpp_component_has_type_filters_enabled($component, $component_id)) {
         $i = 10;
         $supported_types = mpp_component_get_supported_types($component);
         foreach ($supported_types as $type) {
             if (!mpp_is_active_type($type)) {
                 continue;
             }
             $type_object = mpp_get_type_object($type);
             $sub_nav[] = array('name' => $type_object->label, 'slug' => 'type/' . $type, 'parent_url' => $gallery_link, 'parent_slug' => $this->slug, 'screen_function' => array($view_helper, 'my_galleries'), 'position' => 20 + $i);
             $i = $i + 10;
             //increment the position
         }
     }
     // Add the Upload link to gallery nav
     /*$sub_nav[] = array(
           'name'				=> __( 'Upload', 'mediapress'),
           'slug'				=> 'upload',
           'parent_url'		=> $gallery_link,
           'parent_slug'		=> $this->slug,
           'screen_function'	=> array( $view_helper, 'upload_media' ),
           'user_has_access'	=> bp_is_my_profile(),
           'position'			=> 30
       );*/
     parent::setup_nav($main_nav, $sub_nav);
     //disallow these names in various lists
     //we have yet to implement it
     $this->forbidden_names = apply_filters('mpp_forbidden_names', array('gallery', 'galleries', 'my-gallery', 'create', 'delete', 'upload', 'add', 'edit', 'admin', 'request', 'upload', 'tags', 'audio', 'video', 'photo'));
     //use this to extend the valid status
     $this->valid_status = apply_filters('mpp_valid_gallery_status', array_keys(mpp_get_active_statuses()));
     do_action('mpp_setup_nav');
     // $bp->gallery->current_gallery->user_has_access
 }
コード例 #2
0
ファイル: widget-gallery.php プロジェクト: baden03/mediapress
 public function update($new_instance, $old_instance)
 {
     $instance = $old_instance;
     $instance['title'] = strip_tags($new_instance['title']);
     if (mpp_is_active_component($new_instance['component'])) {
         $instance['component'] = $new_instance['component'];
     }
     if (mpp_is_active_type($new_instance['type'])) {
         $instance['type'] = $new_instance['type'];
     }
     if (mpp_is_active_status($new_instance['status'])) {
         $instance['status'] = $new_instance['status'];
     }
     $instance['per_page'] = absint($new_instance['per_page']);
     $instance['orderby'] = $new_instance['orderby'];
     $instance['order'] = $new_instance['order'];
     return $instance;
 }
コード例 #3
0
 /**
  * Initilize settings based on the current stack of action variables and component etc
  */
 public function init()
 {
     $current_action = $this->get_variable(0);
     //on create or upload we don't need to setup Media or Gallery Query
     if ($current_action == 'create' || $current_action == 'upload') {
         mediapress()->set_action($current_action);
         mediapress()->set_edit_action($current_action);
         return;
     }
     //check for type/status
     $type_or_status = $this->get_variable(1);
     if ($current_action === 'type' && $type_or_status && mpp_is_active_type($type_or_status)) {
         $this->type = $type_or_status;
         mediapress()->is_gallery_home = true;
     } elseif ($current_action == 'status' && $type_or_status && mpp_is_active_status($type_or_status)) {
         $this->status = $type_or_status;
         mediapress()->is_gallery_home = true;
     } elseif ($gallery = mpp_gallery_exists($current_action, $this->component, $this->component_id)) {
         //Are we looking at single gallery? or Media?
         //current action in this case is checked for being  a gallery slug
         //setup current gallery & gallery query
         mediapress()->current_gallery = mpp_get_gallery($gallery);
         $this->gallery_id = $gallery->ID;
         $this->current_action = $this->get_variable(1);
         $this->current_manage_action = $this->get_variable(2);
         //setup pagination for single gallery media
         if ($this->get_variable(1) == 'page' && $this->get_variable(2) > 0) {
             $this->mpage = (int) $this->get_variable(2);
         }
     } else {
         if ($this->get_variable(0) == 'page' && $this->get_variable(1) > 0) {
             $this->gpage = (int) $this->get_variable(1);
         }
         //set it is the user galleries list view
         mediapress()->is_gallery_home = true;
     }
     //check and setup pagination args for status/type archives
     if ($this->get_variable(2) == 'page' && $this->get_variable(3) > 0) {
         $this->gpage = (int) $this->get_variable(3);
     }
 }
コード例 #4
0
function mpp_update_gallery($args)
{
    if (!isset($args['id'])) {
        return new WP_Error(0, __('Must provide ID to update a gallery.', 'mediapress'));
    }
    $gallery = get_post($args['id']);
    //we need meaning full error handling in future
    if (!$gallery) {
        return new WP_Error(0, __('Gallery Does not exist!', 'mediapress'));
    }
    // $gdata =  get_object_vars( $gallery );
    $gallery_data = array('id' => $gallery->ID, 'title' => $gallery->post_title, 'description' => $gallery->post_content, 'slug' => $gallery->post_name, 'creator_id' => $gallery->post_author, 'order' => $gallery->menu_order, 'component_id' => mpp_get_gallery_meta($gallery->ID, '_mpp_component_id'), 'component' => '', 'status' => '', 'type' => '', 'date_created' => '', 'date_modified' => '');
    $args = wp_parse_args($args, $gallery_data);
    extract($args);
    if (empty($id) || empty($title)) {
        return false;
    }
    //now let us check which fields need to be updated
    if ($creator_id) {
        $gallery->post_author = $creator_id;
    }
    if ($title) {
        $gallery->post_title = $title;
    }
    if ($description) {
        $gallery->post_content = $description;
    }
    if ($slug) {
        $gallery->post_name = $slug;
    }
    if ($order) {
        $gallery->menu_order = $order;
    }
    $post = get_object_vars($gallery);
    $tax = array();
    if ($component && mpp_is_active_component($component)) {
        $tax[mpp_get_component_taxname()] = mpp_underscore_it($component);
    }
    if ($type && mpp_is_active_type($type)) {
        $tax[mpp_get_type_taxname()] = mpp_underscore_it($type);
    }
    if ($status && mpp_is_active_status($status)) {
        $tax[mpp_get_status_taxname()] = mpp_underscore_it($status);
    }
    if (!empty($tax)) {
        $post['tax_input'] = $tax;
    }
    //$post['ID'] = $gallery->id;
    if (!empty($date_created)) {
        $post_data['post_date'] = $date_created;
    }
    if (!empty($date_updated)) {
        $post_data['post_modified'] = $date_updated;
    }
    $gallery_id = wp_update_post($post);
    if (is_wp_error($gallery_id)) {
        return $gallery_id;
        //error
    }
    do_action('mpp_gallery_updated', $gallery_id);
    return $gallery_id;
}
コード例 #5
0
/**
 * Add various upload icons to activity post form
 * @return type
 */
function mpp_activity_upload_buttons()
{
    if (!mpp_is_activity_upload_enabled(mpp_get_current_component())) {
        return;
    }
    //if we are here, the gallery activity stream upload is enabled,
    //let us see if we are on user profile and gallery is enabled
    if (bp_is_user() && !mpp_is_active_component('members')) {
        return;
    }
    //if we are on group page and either the group component is not enabled or gallery is not enabled for current group, do not show the icons
    if (function_exists('bp_is_group') && bp_is_group() && (!mpp_is_active_component('groups') || !(function_exists('mpp_group_is_gallery_enabled') && mpp_group_is_gallery_enabled()))) {
        return;
    }
    //for now, avoid showing it on single gallery/media activity stream
    if (mpp_is_single_gallery() || mpp_is_single_media()) {
        return;
    }
    $component = mpp_get_current_component();
    ?>
    <div id="mpp-activity-upload-buttons" class="mpp-upload-buttons">
        <?php 
    do_action("mpp_before_activity_upload_buttons");
    //allow to add more type
    ?>
        
    <?php 
    if (mpp_is_active_type('photo') && mpp_component_supports_type($component, 'photo')) {
        ?>
        <a href="#" id="mpp-photo-upload" data-media-type="photo"><img src="<?php 
        echo mediapress()->get_url() . 'assets/images/media-button-image.gif';
        ?>
"/></a>
     <?php 
    }
    ?>
        
    <?php 
    if (mpp_is_active_type('audio') && mpp_component_supports_type($component, 'audio')) {
        ?>
        <a href="#" id="mpp-audio-upload" data-media-type="audio"><img src="<?php 
        echo mediapress()->get_url() . 'assets/images/media-button-music.gif';
        ?>
"/></a>
     <?php 
    }
    ?>

     <?php 
    if (mpp_is_active_type('video') && mpp_component_supports_type($component, 'video')) {
        ?>
        <a href="#" id="mpp-video-upload"  data-media-type="video"><img src="<?php 
        echo mediapress()->get_url() . 'assets/images/media-button-video.gif';
        ?>
"/></a>
    <?php 
    }
    ?>
		
     <?php 
    if (mpp_is_active_type('doc') && mpp_component_supports_type($component, 'doc')) {
        ?>
        <a href="#" id="mpp-doc-upload"  data-media-type="doc"><img src="<?php 
        echo mediapress()->get_url() . 'assets/images/media-button-doc.png';
        ?>
" /></a>
    <?php 
    }
    ?>
		
    <?php 
    //someone please provide me doc icon and some better icons
    ?>
 
    
	<?php 
    do_action('mpp_after_activity_upload_buttons');
    //allow to add more type
    ?>

    </div>
  <?php 
}
コード例 #6
0
ファイル: actions.php プロジェクト: baden03/mediapress
/**
 * Handles Gallery creation on the front end in non ajax case
 * 
 * @return type
 */
function mpp_action_create_gallery()
{
    //allow gallery to be created from anywhere
    //the form must have mpp-action set and It should be set to 'create-gallery'
    if (empty($_POST['mpp-action']) || $_POST['mpp-action'] != 'create-gallery') {
        return;
    }
    $referer = wp_get_referer();
    //if we are here, It is gallery create action
    if (!wp_verify_nonce($_POST['mpp-nonce'], 'mpp-create-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;
    }
    //update it to allow passing component/id from the form
    $component = mpp_get_current_component();
    $component_id = mpp_get_current_component_id();
    //check for permission
    //we may want to allow passing of component from the form in future!
    if (!mpp_user_can_create_gallery($component, $component_id)) {
        mpp_add_feedback(__("You don't have permission to create gallery!", 'mediapress'), 'error');
        if ($referer) {
            mpp_redirect($referer);
        }
        return;
    }
    //if we are here, validate the data and let us see if we can create
    $title = $_POST['mpp-gallery-title'];
    $description = $_POST['mpp-gallery-description'];
    $type = $_POST['mpp-gallery-type'];
    $status = $_POST['mpp-gallery-status'];
    $errors = array();
    if (!mpp_is_active_status($status)) {
        $errors['status'] = __('Invalid Gallery status!', 'mediapress');
    }
    if (!mpp_is_active_type($type)) {
        $errors['type'] = __('Invalid gallery type!', 'mediapress');
    }
    //check for current component
    if (!mpp_is_active_component($component)) {
        $errors['component'] = __('Invalid gallery component!', 'mediapress');
    }
    if (empty($title)) {
        $errors['title'] = __('Title can not be empty', 'mediapress');
    }
    //give opportunity to other plugins to add their own validation errors
    $validation_errors = apply_filters('mpp-create-gallery-field-validation', $errors, $_POST);
    if (!empty($validation_errors)) {
        //let us add the validation error and return back to the earlier page
        $message = join('\\r\\n', $validation_errors);
        mpp_add_feedback($message, 'error');
        if ($referer) {
            mpp_redirect($referer);
        }
        return;
    }
    //let us create gallery
    $gallery_id = mpp_create_gallery(array('title' => $title, 'description' => $description, 'type' => $type, 'status' => $status, 'creator_id' => get_current_user_id(), 'component' => $component, 'component_id' => $component_id));
    if (!$gallery_id) {
        mpp_add_feedback(__('Unable to create gallery!', 'mediapress'), 'error');
        if ($referer) {
            mpp_redirect($referer);
        }
        return;
    }
    //if we are here, the gallery was created successfully,
    //let us redirect to the gallery_slug/manage/upload page
    $redirect_url = mpp_get_gallery_add_media_url($gallery_id);
    mpp_add_feedback(__('Gallery created successfully!', 'mediapress'));
    mpp_redirect($redirect_url);
}