Esempio n. 1
0
 /**
  * @group bulk_delete
  */
 public function test_buddydrive_bulk_delete_items()
 {
     // create the upload dir
     $upload_dir = buddydrive_get_upload_data();
     $expected_ids = array();
     $quota_left = 0;
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     $items_users = array('screenshot-1.png' => $u1, 'screenshot-2.png' => $u1, 'screenshot-3.png' => $u2);
     $args = array('type' => buddydrive_get_file_post_type(), 'mime_type' => 'image/png');
     foreach ($items_users as $item => $user) {
         $f = trailingslashit(buddydrive()->plugin_dir) . $item;
         copy($f, trailingslashit($upload_dir['dir']) . $item);
         $fs = filesize($item);
         buddydrive_update_user_space($user, filesize($item));
         if ('screenshot-1.png' === $item) {
             $quota_left = $fs;
         }
         $args = array_merge($args, array('user_id' => $user, 'title' => $item, 'guid' => trailingslashit($upload_dir['url']) . $item));
         $expected_ids[$item] = buddydrive_save_item($args);
     }
     unset($expected_ids['screenshot-1.png']);
     $count = buddydrive_delete_item(array('ids' => $expected_ids));
     $this->assertTrue($count === count($expected_ids));
     $not_deleted = buddydrive_get_buddyfiles_by_ids($expected_ids);
     $this->assertTrue(empty($not_deleted));
     $this->assertEquals($quota_left, (int) get_user_meta($u1, '_buddydrive_total_space', true), 'u1 quota should be set');
     $this->assertEmpty((int) get_user_meta($u2, '_buddydrive_total_space', true), 'u2 quota should be 0');
 }
Esempio n. 2
0
 /**
  * @group delete
  */
 public function test_buddydrive_delete_item_zero()
 {
     // create the upload dir
     $upload_dir = buddydrive_get_upload_data();
     $expected_id = buddydrive_save_item(array('type' => buddydrive_get_file_post_type(), 'user_id' => $this->user_id, 'title' => 'screenshot-1.png', 'content' => 'foo file', 'mime_type' => 'image/png', 'guid' => trailingslashit($upload_dir['url']) . 'screenshot-1.png'));
     $count = buddydrive_delete_item(array('ids' => 0, 'user_id' => false));
     $this->assertEmpty($count);
     $not_deleted = buddydrive_get_buddyfiles_by_ids($expected_id);
     $this->assertTrue(!empty($not_deleted));
 }
Esempio n. 3
0
/**
 * Ask for a confirmation before deleting BuddyDrive items
 *
 * @uses is_super_admin() too check current user is admin
 * @uses wp_parse_id_list() to parse the comma separated list of BuddyDrive item ids
 * @uses buddydrive_get_buddyfiles_by_ids() to get some data about each BuddyDrive items of this list
 * @uses remove_query_arg() remove some arguments to the url
 * @uses screen_icon() displays the BuddyDrive icon
 * @uses esc_html() to sanitize title
 * @uses buddydrive_get_folder_post_type() get the BuddyFolder post type
 * @uses wp_nonce_url() for security reasons
 * @uses esc_attr to sanitize url
 */
function buddydrive_files_admin_delete()
{
    if (!is_super_admin()) {
        die('-1');
    }
    $item_ids = isset($_REQUEST['bid']) ? $_REQUEST['bid'] : 0;
    if (!is_array($item_ids)) {
        $item_ids = explode(',', $item_ids);
    }
    $item_ids = wp_parse_id_list($item_ids);
    $items = buddydrive_get_buddyfiles_by_ids($item_ids);
    // Create a new list of item ids, based on those that actually exist
    $bids = array();
    foreach ($items as $item) {
        $bids[] = $item->ID;
    }
    $base_url = remove_query_arg(array('action', 'action2', 'paged', 's', '_wpnonce', '_wp_http_referer', 'bid'), $_SERVER['REQUEST_URI']);
    ?>

	<div class="wrap">
		<?php 
    screen_icon('buddydrive');
    ?>
		<h2><?php 
    _e('Delete Items', 'buddydrive');
    ?>
</h2>
		<p><?php 
    _e('You are about to delete the following items:', 'buddydrive');
    ?>
</p>

		<ul class="buddydrive-items-delete-list">
		<?php 
    foreach ($items as $item) {
        ?>
			<li>
				<?php 
        echo esc_html($item->post_title);
        ?>
				<?php 
        if ($item->post_type == buddydrive_get_folder_post_type()) {
            ?>
					<?php 
            _e('(and all the files of this folder)', 'buddydrive');
            ?>
				<?php 
        }
        ?>
			</li>
		<?php 
    }
    ?>
		</ul>

		<p><strong><?php 
    _e('This action cannot be undone.', 'buddydrive');
    ?>
</strong></p>

		<a class="button-primary" href="<?php 
    echo esc_url(wp_nonce_url(add_query_arg(array('action' => 'do_delete', 'bid' => implode(',', $bids)), $base_url), 'buddydrive-delete'));
    ?>
"><?php 
    esc_html_e('Delete Permanently', 'buddydrive');
    ?>
</a>
		<a class="button" href="<?php 
    echo esc_url($base_url);
    ?>
"><?php 
    esc_html_e('Cancel', 'buddydrive');
    ?>
</a>
	</div>

	<?php 
}