Ejemplo n.º 1
0
/**
 * Action links like view/edit/dele/upload to show on indiavidula media
 * 
 * @param type $media
 * @return type
 */
function mpp_get_media_action_links($media = null)
{
    $links = array();
    $media = mpp_get_media($media);
    //$links ['view'] = sprintf( '<a href="%1$s" title="view %2$s" class="mpp-view-media">%3$s</a>', mpp_get_media_permalink( $media ), esc_attr( $media->title ), __( 'view', 'mediapress' ) );
    //upload?
    if (mpp_user_can_edit_media($media->id)) {
        $links['edit'] = sprintf('<a href="%s" alt="' . __('Edit %s', 'mediapress') . '">%s</a>', mpp_get_media_edit_url($media), mpp_get_media_title($media), __('edit', 'mediapress'));
    }
    //delete
    if (mpp_user_can_delete_media($media)) {
        $links['delete'] = sprintf('<a href="%s" alt="' . __('delete %s', 'mediapress') . '" class="confirm mpp-confirm mpp-delete mpp-delete-media">%s</a>', mpp_get_media_delete_url($media), mpp_get_media_title($media), __('delete', 'mediapress'));
    }
    return apply_filters('mpp_media_actions_links', join(' ', $links), $links, $media);
}
/**
 * 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
 public function bulk_update_media()
 {
     //verify nonce
     if (!wp_verify_nonce($_POST['_wpnonce'], 'mpp-manage-gallery')) {
         wp_send_json(array('message' => __('Invalid action.', 'mediapress'), 'error' => 1));
         exit(0);
     }
     if (!$_POST['mpp-editing-media-ids']) {
         return;
     }
     $gallery_id = absint($_POST['gallery_id']);
     $gallery = mpp_get_gallery($gallery_id);
     if (!$gallery_id || !$gallery) {
         wp_send_json(array('message' => __('Invalid action.', 'mediapress'), 'error' => 1));
         exit(0);
     }
     $message = '';
     $media_ids = $_POST['mpp-editing-media-ids'];
     $media_ids = wp_parse_id_list($media_ids);
     $media_ids = array_filter($media_ids);
     $bulk_action = false;
     if (!empty($_POST['mpp-edit-media-bulk-action'])) {
         $bulk_action = $_POST['mpp-edit-media-bulk-action'];
         //we are leaving this to allow future enhancements with other bulk action and not restricting to delete only
     }
     foreach ($media_ids as $media_id) {
         //check what action should we take?
         //1. check if $bulk_action is set? then we may ned to check for deletion
         //otherwise, just update the details :)
         if ($bulk_action == 'delete' && !empty($_POST['mpp-delete-media-check'][$media_id])) {
             //delete and continue
             //check if current user can delete?
             if (!mpp_user_can_delete_media($media_id)) {
                 //if the user is unable to delete media, should we just continue the loop or breakout and redirect back with error?
                 //I am in favour of showing error
                 $success = 0;
                 wp_send_json(array('message' => __('Not allowed to delete!', 'mediapress'), 'error' => 1));
                 exit(0);
             }
             //if we are here, let us delete the media
             mpp_delete_media($media_id);
             $message = __('Deleted successfully!', 'mediapress');
             //it will do for each media, that is not  good thing btw
             $success = 1;
             continue;
         }
         //since we already handled delete for the media checked above,
         //we don't want to do it for the other media hoping that the user was performing bulk delete and not updating the media info
         if ($bulk_action == 'delete') {
             continue;
         }
         //is it media update
         $media_title = $_POST['mpp-media-title'][$media_id];
         $media_description = $_POST['mpp-media-description'][$media_id];
         $status = $_POST['mpp-media-status'][$media_id];
         //if we are here, It must not be a bulk action
         $media_info = array('id' => $media_id, 'title' => $media_title, 'description' => $media_description, 'status' => $status);
         mpp_update_media($media_info);
     }
     if (!$bulk_action) {
         $message = __('Updated!', 'mediapress');
     } elseif (!$message) {
         $message = __('Please select media to apply bulk actions.', 'mediapress');
     }
     mediapress()->current_gallery = $gallery;
     mediapress()->the_media_query = new MPP_Media_Query(array('gallery_id' => $gallery_id, 'per_page' => -1, 'nopaging' => true));
     global $post;
     $bkp_post = $post;
     ob_start();
     require_once $this->template_dir . 'gallery/edit-media.php';
     $contents = ob_get_clean();
     $post = $bkp_post;
     //remember to add content too
     wp_send_json(array('message' => $message, 'success' => 1, 'contents' => $contents));
     exit(0);
 }
Ejemplo n.º 4
0
/**
 * Hndles bulk edit action
 * 
 */
function mpp_action_gallery_media_bulkedit()
{
    if (empty($_POST['mpp-action']) || $_POST['mpp-action'] != 'edit-gallery-media') {
        return;
    }
    if (!$_POST['mpp-editing-media-ids']) {
        return;
    }
    $referer = wp_get_referer();
    if (!wp_verify_nonce($_POST['mpp-nonce'], 'mpp-edit-gallery-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_ids = $_POST['mpp-editing-media-ids'];
    $media_ids = wp_parse_id_list($media_ids);
    $bulk_action = false;
    if (!empty($_POST['mpp-edit-media-bulk-action'])) {
        $bulk_action = $_POST['mpp-edit-media-bulk-action'];
        //we are leaving this to allow future enhancements with other bulk action and not restricting to delete only
    }
    foreach ($media_ids as $media_id) {
        //check what action should we take?
        //1. check if $bulk_action is set? then we may ned to check for deletion
        //otherwise, just update the details :)
        if ($bulk_action == 'delete' && !empty($_POST['mpp-delete-media-check'][$media_id])) {
            //delete and continue
            //check if current user can delete?
            if (!mpp_user_can_delete_media($media_id)) {
                //if the user is unable to delete media, should we just continue the loop or breakout and redirect back with error?
                //I am in favour of showing error
                mpp_add_feedback(__('Not allowed to delete!', 'mediapress'));
                if ($referer) {
                    mpp_redirect($referer);
                }
                return;
            }
            //if we are here, let us delete the media
            mpp_delete_media($media_id);
            mpp_add_feedback(__('Deleted successfully!', 'mediapress'), 'error');
            //it will do for each media, that is not  good thing btw
            continue;
        }
        //since we already handled delete for the media checked above,
        //we don't want to do it for the other media hoping that the user was performing bulk delete and not updating the media info
        if ($bulk_action == 'delete') {
            continue;
        }
        $media_title = $_POST['mpp-media-title'][$media_id];
        $media_description = $_POST['mpp-media-description'][$media_id];
        $status = $_POST['mpp-media-status'][$media_id];
        //type is not editable
        //$type = $_POST['mpp-media-type'][$media_id];
        //if we are here, It must not be a bulk action
        $media_info = array('id' => $media_id, 'title' => $media_title, 'description' => $media_description, 'status' => $status);
        mpp_update_media($media_info);
    }
    if (!$bulk_action) {
        mpp_add_feedback(__('Updated!', 'mediapress'));
    }
    if ($referer) {
        mpp_redirect($referer);
    }
}
Ejemplo n.º 5
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);
}