Ejemplo 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');
 }
Ejemplo n.º 2
0
 public function create_files()
 {
     $args = 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(buddydrive()->upload_url) . 'screenshot-1.png');
     $this->expected_ids['foo'] = buddydrive_save_item($args);
     $args = array_merge($args, array('title' => 'readme.txt', 'content' => 'bar file', 'mime_type' => 'text/plain', 'guid' => trailingslashit(buddydrive()->upload_url) . 'readme.txt'));
     $this->expected_ids['bar'] = buddydrive_save_item($args);
 }
Ejemplo n.º 3
0
 public function tearDown()
 {
     parent::tearDown();
     $dir = buddydrive()->upload_dir;
     $d = glob($dir . '/*');
     if (!empty($d)) {
         foreach ($d as $file) {
             @unlink($file);
         }
     }
     if (file_exists($dir . '/.htaccess')) {
         @unlink($dir . '/.htaccess');
     }
     if (is_dir($dir)) {
         rmdir($dir);
     }
 }
Ejemplo n.º 4
0
 /**
  * @group upload
  * @group check_mimes
  */
 public function test_buddydrive_upload_item_mimes()
 {
     $reset_files = $_FILES;
     $reset_post = $_POST;
     $file = trailingslashit(buddydrive()->plugin_dir) . 'readme.txt';
     $tmp_name = wp_tempnam($file);
     copy($file, $tmp_name);
     $_POST['action'] = 'buddydrive_upload';
     $_FILES['buddyfile-upload'] = array('tmp_name' => $tmp_name, 'name' => 'readme.txt', 'type' => 'text/plain', 'error' => 0, 'size' => filesize($file));
     bp_update_option('_buddydrive_allowed_extensions', array('png'));
     // Upload the file
     $upload = buddydrive_upload_item($_FILES, bp_loggedin_user_id());
     $this->assertTrue(!empty($upload['error']));
     bp_update_option('_buddydrive_allowed_extensions', array('png', 'txt|asc|c|cc|h|srt'));
     $upload = buddydrive_upload_item($_FILES, bp_loggedin_user_id());
     $this->assertTrue(file_exists($upload['file']));
     bp_delete_option('_buddydrive_allowed_extensions');
     // clean up!
     $_FILES = $reset_files;
     $_POST = $reset_post;
 }
Ejemplo n.º 5
0
/**
 * An Editor other plugins can use for their need.
 *
 * @since 1.3.0
 *
 * @param string $editor_id the Editor's id to insert the BuddyDrive oembed link into.
 */
function buddydrive_editor($editor_id = '')
{
    $buddydrive = buddydrive();
    $current_user_can = (bool) apply_filters('buddydrive_editor_can', is_user_logged_in());
    // Bail if current user can't use it and if not in front end
    if (!$current_user_can || is_admin()) {
        return;
    }
    // Enqueue Thickbox
    wp_enqueue_style('thickbox');
    wp_enqueue_script('thickbox');
    if (!empty($editor_id)) {
        $buddydrive->editor_id = $editor_id;
    }
    // Temporary filters to add custom strings and settings
    add_filter('bp_attachments_get_plupload_l10n', 'buddydrive_editor_strings', 10, 1);
    add_filter('bp_attachments_get_plupload_default_settings', 'buddydrive_editor_settings', 10, 1);
    // Enqueue BuddyPress attachments scripts
    bp_attachments_enqueue_scripts('BuddyDrive_Attachment');
    // Remove the temporary filters
    remove_filter('bp_attachments_get_plupload_l10n', 'buddydrive_editor_strings', 10, 1);
    remove_filter('bp_attachments_get_plupload_default_settings', 'buddydrive_editor_settings', 10, 1);
    $url = remove_query_arg(array_keys($_REQUEST));
    ?>
	<a href="<?php 
    echo esc_url($url);
    ?>
#TB_inline?inlineId=buddydrive-public-uploader" title="<?php 
    esc_attr_e('Add file', 'buddydrive');
    ?>
" id="buddydrive-btn" class="thickbox button">
		<?php 
    echo esc_html_e('Add File', 'buddydrive');
    ?>
	</a>
	<div id="buddydrive-public-uploader" style="display:none;">
		<?php 
    /* Markup for the uploader */
    ?>
			<div class="buddydrive-uploader"></div>
			<div class="buddydrive-uploader-status"></div>

		<?php 
    bp_attachments_get_template_part('uploader');
    /* Markup for the uploader */
    ?>
	</div>
	<?php 
}
Ejemplo n.º 6
0
                    foreach ((array) $resolve as $step) {
                        $resolve_message .= '<li>' . $step . '</li>';
                    }
                    if ($config['network_status'] && $config['blog_status']) {
                        $resolve_message .= '<li>' . esc_html__('Once done try to activate BuddyDrive again.', 'buddydrive') . '</li></ol>';
                    }
                    $warnings[] = $resolve_message;
                }
                ?>
		<div id="message" class="error">
			<?php 
                foreach ($warnings as $warning) {
                    ?>
				<p><?php 
                    echo $warning;
                    ?>
</p>
			<?php 
                }
                ?>
		</div>
		<?php 
            }
        }
    }
    function buddydrive()
    {
        return buddydrive::instance();
    }
    buddydrive();
}
Ejemplo n.º 7
0
 /**
  * Filter the templates part for user's screens
  *
  * @package BuddyDrive Component
  * @subpackage Screens
  * @since 1.2.0
  */
 public static function template_part($templates, $slug, $name)
 {
     if ($slug != 'members/single/plugins') {
         return $templates;
     }
     $templates = array(buddydrive()->screens->template . '.php');
     return $templates;
 }
Ejemplo n.º 8
0
/**
 * Waits before checking if a 404 was a BuddyDrive file.
 *
 * @since  version 1.1
 *
 * @uses is_404() to check it's a 404
 * @uses bp_get_root_domain() to get the blog's url where BuddyPress is running
 * @uses esc_url() to sanitize url
 * @uses buddydrive() to get the BuddyDrive globals
 * @uses buddydrive_get_root_url() to get the plugin's root url
 * @uses bp_core_redirect() to redirect to the BuddyDrive item
 */
function buddydrive_maybe_redirect_oldlink()
{
    if (!is_404()) {
        return;
    }
    $root_domain_url = bp_get_root_domain();
    $maybe_buddydrive = trailingslashit($root_domain_url . esc_url($_SERVER['REQUEST_URI']));
    $buddydrive_slug = buddydrive()->buddydrive_slug;
    $buddydrive_old_root_url = trailingslashit($root_domain_url) . $buddydrive_slug;
    if (strpos($maybe_buddydrive, $buddydrive_old_root_url) === 0) {
        $buddydrive_new_url = str_replace($buddydrive_old_root_url, buddydrive_get_root_url(), $maybe_buddydrive);
        bp_core_redirect($buddydrive_new_url);
    }
}
/**
 * Get a file thumbnail (if public)
 *
 * @since 1.3.0
 *
 * @param int $buddyfile_id the file ID
 * @param string whether to get the url or the patch to the thumbnail
 */
function buddydrive_get_thumbnail($buddyfile_id = 0, $type = 'thumburl', $link_only = true)
{
    if (empty($buddyfile_id) || 'thumbdir' !== $type && 'thumburl' !== $type) {
        return false;
    }
    $file_metada = wp_get_attachment_metadata($buddyfile_id);
    if (empty($file_metada['sizes']['thumbnail']['file'])) {
        return false;
    }
    $link = trailingslashit(buddydrive()->{$type}) . $file_metada['sizes']['thumbnail']['file'];
    if (!empty($link_only)) {
        return $link;
    } else {
        return array($link, $file_metada['sizes']['thumbnail']['width'], $file_metada['sizes']['thumbnail']['height']);
    }
}
Ejemplo n.º 10
0
/**
 * Change the relative path to match with WordPress upload organisation
 *
 * @since 1.3.0
 *
 * @param  string $new_path the relative path to the protected file
 * @return string           the path to the public file
 */
function buddydrive_public_relative_path($new_path = '', $path = '')
{
    $bp_upload_dir = bp_upload_dir();
    $bd_relative = ltrim(str_replace($bp_upload_dir['basedir'], '', buddydrive()->upload_dir), '/');
    return ltrim(str_replace($bd_relative, '', $new_path), '/');
}
Ejemplo n.º 11
0
 /**
  * Updates the user quota on role changed
  *
  * @since version 1.1
  *
  * @param  integer $user_id the id of the user being edited
  * @param  string $role the new role of the user
  * @global $blog_id the id of the current blog
  * @uses bp_get_root_blog_id() to make sure we're on the blog BuddyPress is activated on
  * @uses buddydrive() to get the old role global
  * @uses bp_get_option() to get main blog option
  * @uses update_user_meta() to save user's preference
  */
 public static function update_user_quota_to_role($user_id, $role)
 {
     global $blog_id;
     if ($blog_id != bp_get_root_blog_id()) {
         return;
     }
     $buddydrive = buddydrive();
     $old_role = !empty($buddydrive->old_role) ? $buddydrive->old_role : false;
     if (isset($_POST['_buddydrive_user_quota']) && $old_role == $role) {
         return;
     }
     $option_user_quota = bp_get_option('_buddydrive_user_quota', 1000);
     if (is_array($option_user_quota)) {
         $user_quota = !empty($option_user_quota[$role]) ? $option_user_quota[$role] : 1000;
     } else {
         $user_quota = $option_user_quota;
     }
     update_user_meta($user_id, '_buddydrive_user_quota', $user_quota);
 }
Ejemplo n.º 12
0
 /**
  * register the BuddyDrive upload data in instance
  *
  * @uses buddydrive_get_upload_data() to get the specific BuddyDrive upload datas
  */
 public function register_upload_dir()
 {
     $upload_data = buddydrive_get_upload_data();
     if (is_array($upload_data)) {
         buddydrive()->upload_dir = $upload_data['dir'];
         buddydrive()->upload_url = $upload_data['url'];
         buddydrive()->thumbdir = $upload_data['thumbdir'];
         buddydrive()->thumburl = $upload_data['thumburl'];
     }
 }