/**
  * 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;
 }
/**
 * Handles Media Cover deletion
 * 
 * 
 */
function mpp_action_delete_media_cover()
{
    if (!mpp_is_media_management()) {
        return;
    }
    if (!isset($_REQUEST['mpp-action']) || $_REQUEST['mpp-action'] != 'cover-delete' || empty($_REQUEST['media_id'])) {
        return;
    }
    $media = mpp_get_media(absint($_REQUEST['media_id']));
    if (empty($media)) {
        return;
    }
    $referer = $redirect_url = mpp_get_media_edit_url($media);
    if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'cover-delete')) {
        //add error message and return back to the old page
        mpp_add_feedback(__('Action not authorized!', 'mediapress'), 'error');
        if ($referer) {
            mpp_redirect($referer);
        }
        return;
    }
    //we may want to allow passing of component from the form in future!
    if (!mpp_user_can_delete_media($media)) {
        mpp_add_feedback(__("You don't have permission to delete this cover!", 'mediapress'), 'error');
        if ($referer) {
            mpp_redirect($referer);
        }
        return;
    }
    //we always need to delete this
    $cover_id = mpp_get_media_cover_id($media->id);
    mpp_delete_media_cover_id($media->id);
    mpp_delete_media($cover_id);
    mpp_add_feedback(__('Cover deleted successfully!', 'mediapress'));
    //if we are here, delete gallery and redirect to the component base url
    mpp_redirect($redirect_url);
}
Ejemplo n.º 3
0
/**
 * Remove a Media entry from gallery
 * 
 * @param type $media_id
 */
function mpp_delete_media($media_id)
{
    global $wpdb;
    if (!($media = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE ID = %d", $media_id)))) {
        return $post;
    }
    if (mpp_get_media_post_type() != $media->post_type) {
        return false;
    }
    //firs of all delete all media associated with this post
    $storage_manager = mpp_get_storage_manager($media_id);
    $storage_manager->delete($media_id);
    //now proceed to delete the post
    mpp_delete_media_meta($media_id, '_wp_trash_meta_status');
    mpp_delete_media_meta($media_id, '_wp_trash_meta_time');
    do_action('mpp_delete_media', $media_id);
    wp_delete_object_term_relationships($media_id, array('category', 'post_tag'));
    wp_delete_object_term_relationships($media_id, get_object_taxonomies(mpp_get_media_post_type()));
    delete_metadata('post', null, '_thumbnail_id', $media_id, true);
    // delete all for any posts.
    //dele if it is set as cover
    delete_metadata('post', null, '_mpp_cover_id', $media_id, true);
    // delete all for any posts.
    $comment_ids = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_post_ID = %d", $media_id));
    foreach ($comment_ids as $comment_id) {
        wp_delete_comment($comment_id, true);
    }
    //if media has cover, delete the cover
    if (mpp_media_has_cover_image($media_id)) {
        mpp_delete_media(mpp_get_media_cover_id($media_id));
    }
    //delete met
    $post_meta_ids = $wpdb->get_col($wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = %d ", $media_id));
    foreach ($post_meta_ids as $mid) {
        delete_metadata_by_mid('post', $mid);
    }
    $result = $wpdb->delete($wpdb->posts, array('ID' => $media_id));
    if (!$result) {
        return false;
    }
    //decrease the media_count in gallery by 1
    mpp_gallery_decrement_media_count($media->post_parent);
    //delete all activities related to this media
    mpp_media_delete_activities($media_id);
    //delete all activity meta key where this media is associated
    mpp_media_delete_activity_meta($media_id);
    clean_post_cache($media);
    do_action('mpp_media_deleted', $media_id);
    return $media;
}
Ejemplo n.º 4
0
/**
 * Handles Gallery Cover deletion
 * 
 * @return type
 */
function mpp_action_delete_gallery_cover()
{
    if (!mpp_is_gallery_cover_delete()) {
        return;
    }
    if (!$_REQUEST['gallery_id']) {
        return;
    }
    $gallery = mpp_get_gallery(absint($_REQUEST['gallery_id']));
    $referer = $redirect_url = mpp_get_gallery_settings_url($gallery);
    if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'delete-cover')) {
        //add error message and return back to the old page
        mpp_add_feedback(__('Action not authorized!', 'mediapress'), 'error');
        if ($referer) {
            mpp_redirect($referer);
        }
        return;
    }
    //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 cover!", 'mediapress'), 'error');
        if ($referer) {
            mpp_redirect($referer);
        }
        return;
    }
    //we always need to delete this
    $cover_id = mpp_get_gallery_cover_id($gallery->id);
    mpp_delete_gallery_cover_id($gallery->id);
    //if( $gallery->type != 'photo' ) {
    //delete the uploaded cover too
    mpp_delete_media($cover_id);
    //}
    mpp_add_feedback(__('Cover deleted successfully!', 'mediapress'));
    //if we are here, delete gallery and redirect to the component base url
    mpp_redirect($redirect_url);
}
Ejemplo n.º 5
0
 public function delete_gallery_cover()
 {
     //verify nonce
     if (!wp_verify_nonce($_POST['_wpnonce'], 'mpp-manage-gallery')) {
         wp_send_json(array('message' => __('Invalid action.', 'mediapress'), 'error' => 1));
         exit(0);
     }
     $gallery = mpp_get_gallery(absint($_REQUEST['gallery_id']));
     if (!$gallery) {
         wp_send_json(array('message' => __('Invalid action.', 'mediapress'), 'error' => 1));
         exit(0);
     }
     //we may want to allow passing of component from the form in future!
     if (!mpp_user_can_delete_gallery($gallery)) {
         wp_send_json(array('message' => __("You don't have permission to delete this cover!", 'mediapress'), 'error' => 1));
         exit(0);
     }
     //we always need to delete this
     $cover_id = mpp_get_gallery_cover_id($gallery->id);
     mpp_delete_gallery_cover_id($gallery->id);
     mpp_delete_media($cover_id);
     wp_send_json(array('message' => __("Cover deleted", 'mediapress'), 'success' => 1, 'cover' => mpp_get_gallery_cover_src('thumbnail', $gallery->id)));
     exit(0);
 }
Ejemplo n.º 6
0
/**
 *  Delete a Gallery
 * @global type $bp
 * @param type $gallery_id
 * @return boolean 
 */
function mpp_delete_gallery($gallery_id, $delete_posts = true)
{
    global $bp, $wpdb;
    if (!$gallery_id) {
        return false;
    }
    $gallery = mpp_get_gallery($gallery_id);
    //1// delete all media
    $media_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d", $gallery_id));
    foreach ($media_ids as $media_id) {
        mpp_delete_media($media_id);
        //delete all media
    }
    //delete all gallery activity
    mpp_gallery_delete_activity($gallery_id);
    //delete all associated activity meta
    mpp_gallery_delete_activity_meta($gallery_id);
    //Delete wall gallery meta
    mpp_delete_wall_gallery_id(array('component' => $gallery->component, 'component_id' => $gallery->component_id, 'gallery_id' => $gallery->id, 'media_type' => $gallery->type));
    wp_delete_post($gallery_id, true);
    //completely delete post
    do_action('mpp_gallery_deleted', $gallery_id);
    return true;
}
Ejemplo n.º 7
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']);
     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);
         $id = mpp_add_media($media_data);
         $old_cover = mpp_get_gallery_cover_id($gallery_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);
     }
 }
Ejemplo n.º 8
0
/**
 * Handles Media deletion
 * 
 * @return type
 */
function mpp_action_delete_media()
{
    if (empty($_REQUEST['mpp-action']) || $_REQUEST['mpp-action'] != 'delete-media') {
        return;
    }
    if (!$_REQUEST['mpp-media-id']) {
        return;
    }
    $referer = wp_get_referer();
    if (!wp_verify_nonce($_REQUEST['mpp-nonce'], 'mpp-delete-media')) {
        //add error message and return back to the old page
        mpp_add_feedback(__('Action not authorized!', 'mediapress'), 'error');
        if ($referer) {
            mpp_redirect($referer);
        }
        return;
    }
    $media = '';
    if (!empty($_REQUEST['mpp-media-id'])) {
        $media = mpp_get_media((int) $_REQUEST['mpp-media-id']);
    }
    //check for permission
    //we may want to allow passing of component from the form in future!
    if (!mpp_user_can_delete_media($media->id)) {
        mpp_add_feedback(__("You don't have permission to delete this!", 'mediapress'), 'error');
        if ($referer) {
            mpp_redirect($referer);
        }
        return;
    }
    //if we are here, delete media and redirect to the component base url
    mpp_delete_media($media->id);
    $redirect_url = mpp_get_gallery_permalink($media->gallery_id);
    mpp_add_feedback(__("Successfully deleted!", 'mediapress'), 'error');
    mpp_redirect($redirect_url);
}