/**
 * Use it only for non photo media
 * 
 * @param type $type
 * @param type $media
 * @return type
 */
function mpp_get_media_cover_src($type = 'thumbnail', $media = null)
{
    $media = mpp_get_media($media);
    $thumbnail_id = mpp_get_media_cover_id($media->id);
    if (!$thumbnail_id) {
        //if it is a photo, let us say that the photo is itself the cover
        if ($media->type == 'photo') {
            //&& mpp_gallery_has_media( $gallery->id )
            $thumbnail_id = $media->id;
        }
        if (!$thumbnail_id) {
            $default_image = mpp_get_default_media_cover_image_src($media, $type);
            return apply_filters('mpp_get_media_default_cover_image_src', $default_image, $type, $media);
        }
    }
    $storage = mpp_get_storage_manager($media->id);
    //get the image src
    $thumb_image_url = $storage->get_src($type, $thumbnail_id);
    return apply_filters('mpp_get_media_cover_src', $thumb_image_url, $type, $media);
}
 /**
  * Maps 'delete_attachment' to mpp_before_media_delete action
  * Also, cleans up cover, decrements media count and deletes activities associated
  * 
  * @param type $media_id
  * @return type
  */
 public function map_before_delete_attachment_action($media_id)
 {
     if (!mpp_is_valid_media($media_id)) {
         //the attachment is not media
         return;
     }
     //this is just a precaution in case some faulty plugin calls it again
     //if everything is normal, we don't need to check for this
     if ($this->is_queued($media_id)) {
         return;
         //
     }
     //push this media to teh queue
     $this->add_item($media_id, 'media');
     /**
      * mpp_before_media_delete action fires before WordPress starts deleting an attachment which is a valid media( in MediaPress). 
      * Any plugin utilizing this action can access the fully functional media object by using mpp_get_media() on the passed media id
      *  
      */
     do_action('mpp_before_media_delete', $media_id);
     $storage_manager = mpp_get_storage_manager($media_id);
     $storage_manager->delete_media($media_id);
     //delete if it is set as cover
     delete_metadata('post', null, '_mpp_cover_id', $media_id, true);
     // delete all for any posts.
     delete_metadata('post', null, '_mpp_unpublished_media_id', $media_id, true);
     // delete all for any posts.
     //
     //if media has cover, delete the cover
     $media = mpp_get_media($media_id);
     $gallery_id = $media->gallery_id;
     if (mpp_media_has_cover_image($media_id)) {
         mpp_delete_media(mpp_get_media_cover_id($media_id));
     }
     if (apply_filters('mpp_cleanup_single_media_on_delete', true, $media_id, $gallery_id)) {
         mpp_gallery_decrement_media_count($gallery_id);
         if (mediapress()->is_bp_active()) {
             //delete all activities related to this media
             //mpp_media_delete_activities( $media_id );
             mpp_delete_activity_for_single_published_media($media_id);
             //delete all activity meta key where this media is associated
             mpp_media_delete_activity_meta($media_id);
         }
     }
     return;
 }
function mpp_get_media_path($type = '', $media = null)
{
    $media = mpp_get_media($media);
    $storage_manager = mpp_get_storage_manager($media->id);
    return $storage_manager->get_path($type, $media->id);
}
Beispiel #4
0
/**
 * Get wp compatible meta data for the media
 * @param type $media_id
 * @param type $src
 * @return type
 */
function mpp_generate_media_metadata($media_id, $src)
{
    $storage = mpp_get_storage_manager($media_id);
    return $storage->generate_metadata($media_id, $src);
}
Beispiel #5
0
/**
 * Get the Used space by a component
 * 
 * @param type $component
 * @param type $component_id
 * @return int
 */
function mpp_get_used_space($component, $component_id)
{
    $storage_manager = mpp_get_storage_manager();
    //get default
    return $storage_manager->get_used_space($component, $component_id);
}
function _mpp_get_cover_photo_src($type = '', $media = null)
{
    if (is_object($media)) {
        $media = $media->id;
    }
    $storage_manager = mpp_get_storage_manager($media);
    return $storage_manager->get_src($type, $media);
}
Beispiel #7
0
/**
 * Generate attachment meta data.
 *
 * @param int $attachment_id Attachment Id to process.
 * @param string $file Filepath of the Attached image.
 * @return mixed Metadata for attachment.
 */
function mpp_generate_attachment_metadata($attachment_id, $file)
{
    $storage_manager = mpp_get_storage_manager($attachment_id);
    return $storage_manager->generate_metadata($attachment_id, $file);
}
Beispiel #8
0
 public function cover_upload()
 {
     check_ajax_referer('mpp_add_media');
     //check for the referrer
     $response = array();
     $file = $_FILES;
     $file_id = '_mpp_file';
     //key name in the files array
     //find the components we are trying to add for
     $component = $component_id = 0;
     $context = 'cover';
     $gallery_id = absint($_POST['mpp-gallery-id']);
     $parent_id = absint($_POST['mpp-parent-id']);
     $parent_type = isset($_POST['mpp-parent-type']) ? trim($_POST['mpp-parent-type']) : 'gallery';
     //default upload to gallery cover
     if (!$gallery_id || !$parent_id) {
         return;
     }
     $gallery = mpp_get_gallery($gallery_id);
     $component = $gallery->component;
     $component_id = $gallery->component_id;
     //get the uploader
     $uploader = mpp_get_storage_manager();
     //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')));
     }
     $media_type = mpp_get_media_type_from_extension(mpp_get_file_extension($file[$file_id]['name']));
     //cover is always a photo,
     if ($media_type != 'photo') {
         wp_send_json(array('message' => sprintf(__('Please upload a photo. Only <strong>%s</strong> files are allowed!', 'mediapress'), mpp_get_allowed_file_extensions_as_string($media_type))));
     }
     $error = false;
     //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, 'is_cover' => 1));
     //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;
         $media_data = array('title' => $title, 'description' => $content, 'gallery_id' => $parent_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, 'is_cover' => true);
         //cover shuld never be recorded as activity
         add_filter('mpp_do_not_record_add_media_activity', '__return_true');
         $id = mpp_add_media($media_data);
         if ($parent_type == 'gallery') {
             $old_cover = mpp_get_gallery_cover_id($parent_id);
         } else {
             $old_cover = mpp_get_media_cover_id($parent_id);
         }
         if ($gallery->type == 'photo') {
             mpp_gallery_increment_media_count($gallery_id);
         } else {
             //mark it as non gallery media
             mpp_delete_media_meta($id, '_mpp_is_mpp_media');
             if ($old_cover) {
                 mpp_delete_media($old_cover);
             }
         }
         mpp_update_media_cover_id($parent_id, $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 {
         echo json_encode(array('error' => 1, 'message' => $uploaded['error']));
         exit(0);
     }
 }
Beispiel #9
0
function mpp_get_media_content($media = null)
{
    $media = mpp_get_media($media);
    $view = mpp_get_media_view($media->type, mpp_get_storage_manager($media->id));
    if (!empty($view)) {
        return $view->get_html($media);
    }
    return sprintf(__('There are no view object registered to handle the display of the content of <strong> %s </strong> type', 'mediapress'), $media->type);
}