Esempio n. 1
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 
}
Esempio n. 2
0
 /**
  * Not used, Oembed support is not yet available in 1.0 branch
  */
 public function add_oembed_media()
 {
     check_ajax_referer('mpp_add_media');
     //check for the referrer
     $media_type = '';
     $gallery_id = '';
     $component = $_POST['component'];
     $component_id = $_POST['component_id'];
     $context = mpp_get_upload_context(false, $_POST['context']);
     if (!$component) {
         $component = mpp_get_current_component();
     }
     if (!$component_id) {
         $component_id = mpp_get_current_component_id();
     }
     //get the uploader
     $uploader = mpp_get_storage_manager('oembed');
     //should we pass the component?
     //setup for component
     //$uploader->setup_for( $component, $component_id );
     //check if the server can handle the upload?
     if (!$uploader->can_handle()) {
         wp_send_json_error(array('message' => __('Server can not handle this much amount of data. Please upload a smaller file or ask your server administrator to change the settings.', 'mediapress')));
     }
     if (!mpp_has_available_space($component, $component_id)) {
         wp_send_json_error(array('message' => __('Unable to upload. You have used the allowed storage quota!', 'mediapress')));
     }
     //if we are here, the server can handle upload
     //check should be here
     $gallery_id = 0;
     if (isset($_POST['gallery_id'])) {
         $gallery_id = absint($_POST['gallery_id']);
     }
     if ($gallery_id) {
         $gallery = mpp_get_gallery($gallery_id);
     } else {
         $gallery = false;
     }
     //not set
     //if there is no gallery id given and the context is activity, we may want to auto create the gallery
     $media_type = mpp_get_media_type_from_extension(mpp_get_file_extension($file[$file_id]['name']));
     if (!$media_type) {
         wp_send_json_error(array('message' => __("This file type is not supported.", 'mediapress')));
     }
     //if there is no gallery type defined( It wil happen in case of new gallery creation from admin page
     //we will set the gallery type as the type of the first media
     if ($gallery && empty($gallery->type)) {
         //update gallery type
         //set it to media type
         mpp_update_gallery_type($gallery, $media_type);
     }
     //If the gallery is not given and It is members component, check if the upload context is activity?
     //Check if we have a profile gallery set for the current user for this type of media
     //if yes, then use that gallery to upload the media
     //otherwise we create a gallery of the current media type and set it as the profile gallery for that type
     if (!$gallery && $context == 'activity') {
         //if gallery is not given and the component supports wall gallery
         //then create
         if (!mpp_is_activity_upload_enabled($component)) {
             wp_send_json_error(array('message' => __("The gallery is not selected.", 'mediapress')));
         }
         $gallery_id = mpp_get_wall_gallery_id(array('component' => $component, 'component_id' => $component_id, 'media_type' => $media_type));
         if (!$gallery_id) {
             //if gallery does not exist, create 1
             $gallery_id = mpp_create_gallery(array('creator_id' => get_current_user_id(), 'title' => sprintf(_x('Wall %s Gallery', 'wall gallery name', 'mediapress'), $media_type), 'description' => '', 'status' => 'public', 'component' => $component, 'component_id' => $component_id, 'type' => $media_type));
             if ($gallery_id) {
                 //save the profile gallery id
                 mpp_update_wall_gallery_id(array('component' => $component, 'component_id' => $component_id, 'media_type' => $media_type, 'gallery_id' => $gallery_id));
             }
         }
         //setup gallery object from the profile gallery id
         if ($gallery_id) {
             $gallery = mpp_get_gallery($gallery_id);
         }
     }
     //we may want to check the upload type and set the gallery to activity gallery etc if it is not set already
     $error = false;
     //detect media type of uploaded file here and then upload it accordingly also check if the media type uploaded and the gallery type matches or not
     //let us build our response for javascript
     //if we are uploading to a gallery, check for type
     //since we will be allowin g upload without gallery too, It is required to make sure $gallery is present or not
     if ($gallery && !mpp_is_mixed_gallery($gallery) && $media_type !== $gallery->type) {
         //if we are uploading to a gallery and It is not a mixed gallery, the media type must match the gallery type
         wp_send_json_error(array('message' => sprintf(__('This file type is not allowed in current gallery. Only <strong>%s</strong> files are allowed!', 'mediapress'), mpp_get_allowed_file_extensions_as_string($gallery->type))));
     }
     //if we are here, all is well :)
     if (!mpp_user_can_upload($component, $component_id, $gallery)) {
         wp_send_json_error(array('message' => __("You don't have sufficient permissions to upload.", 'mediapress')));
     }
     //if we are here, we have checked for all the basic errors, so let us just upload now
     $uploaded = $uploader->upload($file, array('file_id' => $file_id, 'gallery_id' => $gallery_id, 'component' => $component, 'component_id' => $component_id));
     //upload was succesfull?
     if (!isset($uploaded['error'])) {
         //file was uploaded successfully
         $title = $_FILES[$file_id]['name'];
         $title_parts = pathinfo($title);
         $title = trim(substr($title, 0, -(1 + strlen($title_parts['extension']))));
         $url = $uploaded['url'];
         $type = $uploaded['type'];
         $file = $uploaded['file'];
         //$title = isset( $_POST['media_title'] ) ? $_POST['media_title'] : '';
         $content = isset($_POST['media_description']) ? $_POST['media_description'] : '';
         $meta = $uploader->get_meta($uploaded);
         $title_desc = $this->get_title_desc_from_meta($type, $meta);
         if (!empty($title_desc)) {
             if (empty($title) && !empty($title_desc['title'])) {
                 $title = $title_desc['title'];
             }
             if (empty($content) && !empty($title_desc['content'])) {
                 $content = $title_desc['content'];
             }
         }
         $status = isset($_POST['media_status']) ? $_POST['media_status'] : '';
         if (empty($status) && $gallery) {
             $status = $gallery->status;
         }
         //inherit from parent,gallery must have an status
         //we may need some more enhancements here
         if (!$status) {
             $status = mpp_get_default_status();
         }
         //   print_r($upload_info);
         $is_orphan = 0;
         //Any media uploaded via activity is marked as orphan( Not associated with the mediapress unless the activity to which it was attached is actually created, check core/activity/actions.php to see how the orphaned media is adopted by the activity :) )
         if ($context == 'activity') {
             $is_orphan = 1;
         }
         //by default mark all uploaded media via activity as orphan
         $media_data = array('title' => $title, 'description' => $content, 'gallery_id' => $gallery_id, 'user_id' => get_current_user_id(), 'is_remote' => false, 'type' => $media_type, 'mime_type' => $type, 'src' => $file, 'url' => $url, 'status' => $status, 'comment_status' => 'open', 'storage_method' => mpp_get_storage_method(), 'component_id' => $component_id, 'component' => $component, 'context' => $context, 'is_orphan' => $is_orphan);
         $id = mpp_add_media($media_data);
         //should we update and resize images here?
         //
         mpp_gallery_increment_media_count($gallery_id);
         $attachment = mpp_media_to_json($id);
         //$attachment['data']['type_id'] = mpp_get_type_term_id( $gallery->type );
         echo json_encode(array('success' => true, 'data' => $attachment));
         //wp_send_json_success( array('name'=>'what') );
         exit(0);
     } else {
         wp_send_json_error(array('message' => $uploaded['error']));
     }
 }