/**
 * Updates an item
 *
 * @uses check_admin_referer() for security reasons
 * @uses buddydrive_get_buddyfile() to get the item
 * @uses buddydrive_get_folder_post_type() to get the BuddyFolder post type
 * @uses buddydrive_get_file_post_type() to get the BuddyFile post type
 * @uses wp_kses() to sannitize data
 * @uses buddydrive_update_item() to update the item (folder or file)
 * @uses the BuddyDrive Loop to get the item updated
 * @uses buddydrive_get_template() to get the template for bp-default or any theme
 * @return array containing the updated item
 */
function buddydrive_ajax_update_item()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Check the nonce
    check_admin_referer('buddydrive_actions', '_wpnonce_buddydrive_actions');
    $item_id = intval($_POST['id']);
    $item = buddydrive_get_buddyfile($item_id, array(buddydrive_get_folder_post_type(), buddydrive_get_file_post_type()));
    if (empty($item->title)) {
        echo json_encode(array(0));
        die;
    }
    $args = array();
    if (!empty($_POST['title'])) {
        $args['title'] = wp_kses($_POST['title'], array());
    }
    if (!empty($_POST['content'])) {
        $args['content'] = wp_kses($_POST['content'], array());
    }
    if (!empty($_POST['sharing'])) {
        $args['privacy'] = $_POST['sharing'];
    }
    if (!empty($_POST['password'])) {
        $args['password'] = wp_kses($_POST['password'], array());
    }
    if (!empty($_POST['group'])) {
        $args['group'] = $_POST['group'];
    }
    $args['parent_folder_id'] = !empty($_POST['folder']) ? intval($_POST['folder']) : 0;
    // We need to check if the parent folder is attached to a group.
    if (!empty($args['parent_folder_id'])) {
        $maybe_in_group = get_post_meta($args['parent_folder_id'], '_buddydrive_sharing_groups', true);
        if (!empty($maybe_in_group)) {
            $args['group'] = intval($maybe_in_group);
        }
    }
    if (!empty($_POST['customs'])) {
        $args['buddydrive_meta'] = json_decode(wp_unslash($_POST['customs']));
    }
    $updated = buddydrive_update_item($args, $item);
    $result = array();
    if (!empty($updated)) {
        if (buddydrive_has_items('id=' . $updated)) {
            ob_start();
            while (buddydrive_has_items()) {
                buddydrive_the_item();
                bp_get_template_part('buddydrive-entry', false);
            }
            $result[] = ob_get_contents();
            ob_end_clean();
        }
        $result[] = $args['parent_folder_id'];
        echo json_encode($result);
    } else {
        echo json_encode(array(0));
    }
    die;
}
/**
 * Builds the folder select box to attach the BuddyFile to
 * @param  int $user_id the user id
 * @param  int $selected the id of the folder in case of edit form
 * @param  string $name  the name of the select box
 * @uses bp_loggedin_user_id() to get current user id
 * @uses buddydrive_get_folder_post_type() to get BuddyFolder post type
 * @uses The BuddyDrive loop and some template tags
 * @uses selected() to activate a folder if $selected is defined
 * @return string  the select box
 */
function buddydrive_get_select_folder_options($user_id = false, $selected = false, $name = false)
{
    if (empty($user_id)) {
        $user_id = bp_loggedin_user_id();
    }
    if (!empty($name)) {
        $name = 'name="' . $name . '"';
    }
    $output = __('No folder available', 'buddydrive');
    $buddydrive_args = array('user_id' => $user_id, 'per_page' => false, 'paged' => false, 'type' => buddydrive_get_folder_post_type());
    if (buddydrive_has_items($buddydrive_args)) {
        $output = '<select id="folders" ' . $name . '>';
        $output .= '<option value="0" ' . selected($selected, 0, false) . '>' . __('Root folder', 'buddydrive') . '</option>';
        while (buddydrive_has_items()) {
            buddydrive_the_item();
            $output .= '<option value="' . buddydrive_get_item_id() . '" ' . selected($selected, buddydrive_get_item_id(), false) . '>' . buddydrive_get_item_title() . '</option>';
        }
        $output .= '</select>';
    }
    return apply_filters('buddydrive_get_select_folder_options', $output, $buddydrive_args);
}
Beispiel #3
0
    function course_drive()
    {
        ?>
		<form action="" method="get" id="buddydrive-form-filter">
			<div class="item-list-tabs no-ajax" id="subnav" role="navigation">
				<ul>

					<?php 
        do_action('buddydrive_member_before_toolbar');
        ?>
						<li class="current">
							<a href="<?php 
        esc_url(buddydrive_component_home_url());
        ?>
" name="home" id="buddydrive-home" data-project="<?php 
        echo esc_attr($post->id);
        ?>
"><?php 
        _e('All Files', 'buddydrive');
        ?>
</a>
						</li>
						<li id="buddydrive-action-new-file">
							<a href="#" id="buddy-new-file" title="<?php 
        _e('New File', 'buddydrive');
        ?>
"><?php 
        _e('New File', 'buddydrive');
        ?>
</a>
						</li>
						<!--li id="buddydrive-action-new-folder">
							<a href="#" id="buddy-new-folder" title="<?php 
        _e('New Folder', 'buddydrive');
        ?>
"><?php 
        _e('New Folder', 'buddydrive');
        ?>
</a>
						</li-->

					<li class="last"><?php 
        esc_html_e('Order by:', 'buddydrive');
        ?>
						<select name="buddydrive_filter" id="buddydrive-filter">
							<option value="title"><?php 
        esc_html_e('Name', 'buddydrive');
        ?>
</option>
							<option value="modified"><?php 
        esc_html_e('Last edit', 'buddydrive');
        ?>
</option>
						</select>
					</li>

				</ul>
			</div>	
		</form>

		<div id="buddydrive-forms">

			<div id="buddydrive-file-uploader" class="hide">
				<?php 
        buddydrive_upload_form();
        ?>
			</div>
			<div id="buddydrive-folder-editor" class="hide">
				<?php 
        buddydrive_folder_form();
        ?>
			</div>
			<div id="buddydrive-edit-item" class="hide"></div>

		</div>

		<?php 
        do_action('buddydrive_after_member_upload_form');
        ?>
		<?php 
        do_action('buddydrive_before_member_body');
        ?>


				<div class="buddydrive single-project" role="main"> 
								
				<?php 
        do_action('buddydrive_before_loop');
        ?>

				<?php 
        if (buddydrive_has_items(buddydrive_querystring())) {
            ?>

					<?php 
            if (empty($_POST['page']) && empty($_POST['folder'])) {
                ?>

						<table id="buddydrive-dir" class="user-dir">
							<thead>
								<tr><th><?php 
                buddydrive_th_owner_or_cb();
                ?>
</th><th class="buddydrive-item-name"><?php 
                _e('Name', 'buddydrive');
                ?>
</th><th class="buddydrive-privacy"><?php 
                _e('Privacy', 'buddydrive');
                ?>
</th><th class="buddydrive-mime-type"><?php 
                _e('Type', 'buddydrive');
                ?>
</th><th class="buddydrive-last-edit"><?php 
                _e('Last edit', 'buddydrive');
                ?>
</th></tr>
							</thead>
							<tbody>
					<?php 
            }
            ?>

					<?php 
            while (buddydrive_has_items()) {
                buddydrive_the_item();
                ?>

						<?php 
                if (empty($_POST['createdid'])) {
                    ?>

						<tr id="item-<?php 
                    buddydrive_item_id();
                    ?>
">

						<?php 
                }
                ?>

								<td>
									<?php 
                buddydrive_owner_or_cb();
                ?>
								</td>
								<td>
									<div class="buddydrive-file-content"><?php 
                buddydrive_item_icon();
                ?>
&nbsp;<a href="<?php 
                buddydrive_action_link();
                ?>
" class="<?php 
                buddydrive_action_link_class();
                ?>
" title="<?php 
                esc_attr(buddydrive_item_title());
                ?>
"<?php 
                buddydrive_item_attribute();
                ?>
><?php 
                buddydrive_item_title();
                ?>
</a></div>
									<?php 
                buddydrive_row_actions();
                ?>
								</td>
								<td>
									<?php 
                buddydrive_item_privacy();
                ?>
								</td>
								<td>
									<?php 
                buddydrive_item_mime_type();
                ?>
								</td>
								<td>
									<?php 
                buddydrive_item_date();
                ?>
								</td>

						<?php 
                if (empty($_POST['createdid'])) {
                    ?>

							</tr>

						<?php 
                }
                ?>


					<?php 
            }
            ?>

					<?php 
            if (buddydrive_has_more_items()) {
                ?>

						<tr>
							<td class="buddydrive-load-more" colspan="5">
								<a href="#more-buddydrive"><?php 
                _e('Load More', 'buddydrive');
                ?>
</a>
							</td>
						</tr>

					<?php 
            }
            ?>

					<?php 
            if (empty($_POST['page']) && empty($_POST['folder'])) {
                ?>
							</tbody>
						</table>

					<?php 
            }
            ?>

				<?php 
        } else {
            ?>

					<?php 
            if (empty($_POST['page']) && empty($_POST['folder'])) {
                ?>
						<table id="buddydrive-dir" class="user-dir">
							<thead>
								<tr><th><?php 
                buddydrive_th_owner_or_cb();
                ?>
</th><th class="buddydrive-item-name"><?php 
                _e('Name', 'buddydrive');
                ?>
</th><th class="buddydrive-privacy"><?php 
                _e('Privacy', 'buddydrive');
                ?>
</th><th class="buddydrive-mime-type"><?php 
                _e('Type', 'buddydrive');
                ?>
</th><th class="buddydrive-last-edit"><?php 
                _e('Last edit', 'buddydrive');
                ?>
</th></tr>
							</thead>
							<tbody>
					<?php 
            }
            ?>
							<tr id="no-buddyitems">
								<td colspan="5">
									<div id="message" class="info">
										<p><?php 
            printf(__('Sorry, there was no %s items found.', 'buddydrive'), buddydrive_get_name());
            ?>
</p>
									</div>
								</td>
							</tr>
					<?php 
            if (empty($_POST['page']) && empty($_POST['folder'])) {
                ?>
							</tbody>
						</table>
					<?php 
            }
            ?>
					

				<?php 
        }
        ?>

				<?php 
        do_action('buddydrive_after_loop');
        ?>

				<?php 
        if (empty($_POST['page']) && empty($_POST['folder'])) {
            ?>

					<form action="" name="buddydrive-loop-form" id="buddydrive-loop-form" method="post">

						<?php 
            wp_nonce_field('buddydrive_actions', '_wpnonce_buddydrive_actions');
            ?>

					</form>
				<?php 
        }
        ?>
			</div>
		<?php 
    }
Beispiel #4
0
 /**
  * Handle filtering of data, sorting, pagination, and any other data-manipulation required prior to rendering.
  *
  * @since BuddyDrive (1.0)
  * @uses get_current_screen() to get current admin screen
  * @uses WP_List_Table::get_pagenum to set the current page
  * @uses buddydrive_get_folder_post_type() to get BuddyFolder post type
  * @uses buddydrive_get_file_post_type() to get BuddyFile post type
  * @uses The BuddyDrive loop to list items
  * @uses WP_List_Table::set_pagination_args() to build the pagination
  */
 function prepare_items()
 {
     global $buddydrive_template;
     $screen = get_current_screen();
     // Option defaults
     $include_id = false;
     $search_terms = false;
     // Set current page
     $page = $this->get_pagenum();
     // Set per page from the screen options
     $per_page = 20;
     // Sort order
     $order = 'ASC';
     if (!empty($_REQUEST['order'])) {
         $order = 'desc' == strtolower($_REQUEST['order']) ? 'DESC' : 'ASC';
     }
     // Order by - default to title
     $orderby = false;
     if (!empty($_REQUEST['orderby'])) {
         switch ($_REQUEST['orderby']) {
             case 'name':
                 $orderby = 'title';
                 break;
             case 'owner':
                 $orderby = 'user_id';
                 break;
             case 'last_edit':
                 $orderby = 'post_modified_gmt';
                 break;
         }
     }
     // Are we doing a search?
     if (!empty($_REQUEST['s'])) {
         $search_terms = $_REQUEST['s'];
     }
     // Check if user has clicked on a specific item (if so, fetch only that item).
     if (!empty($_REQUEST['bid'])) {
         $include_id = (int) $_REQUEST['bid'];
     }
     $type = array(buddydrive_get_folder_post_type(), buddydrive_get_file_post_type());
     /* Set the current view */
     if (isset($_GET['buddydrive_type']) && in_array($_GET['buddydrive_type'], $type)) {
         $this->view = $_GET['buddydrive_type'];
         $type = $_GET['buddydrive_type'];
     }
     $buddydrive_args = array('buddydrive_scope' => 'admin', 'per_page' => $per_page, 'paged' => $page, 'type' => $type);
     if (!empty($orderby)) {
         $buddydrive_args['orderby'] = $orderby;
         $buddydrive_args['order'] = $order;
     }
     if (!empty($search_terms)) {
         $buddydrive_args['search'] = $search_terms;
     }
     $buddydrive_items = array();
     if (buddydrive_has_items($buddydrive_args)) {
         while (buddydrive_has_items()) {
             buddydrive_the_item();
             $buddydrive_items[] = (array) $buddydrive_template->query->post;
         }
     }
     // Set raw data to display
     $this->items = $buddydrive_items;
     // Store information needed for handling table pagination
     $this->set_pagination_args(array('per_page' => $per_page, 'total_items' => $buddydrive_template->query->found_posts, 'total_pages' => ceil($buddydrive_template->query->found_posts / $per_page)));
 }
/**
 * Handles an embed BuddyDrive item
 *
 * @param array $matches the result of the preg_match
 * @param array $attr
 * @param string $url
 * @param array $rawattr
 * @uses is_multisite() to check for multisite config
 * @uses bp_get_root_blog_id() to get the root blog id
 * @uses switch_to_blog() to change for root blog id
 * @uses buddydrive_get_buddyfile() to get the BuddyDrive Item
 * @uses buddydrive_get_file_post_type() to get the BuddyFile post type
 * @uses wp_mime_type_icon() to get the WordPress crystal icon
 * @uses buddydrive_get_folder_post_type() to get the BuddyFolder post type
 * @uses buddydrive_get_group_buddydrive_url() to build the url to the BuddyDrive group
 * @uses buddydrive_get_user_buddydrive_url() to get the user's BuddyDrive url
 * @uses buddydrive_get_images_url() to get the image url of the plugin
 * @uses the BuddyDrive Loop and some tempkate tags
 * @uses wp_reset_postdata() to avoid some weird link..
 * @uses restore_current_blog() to restore the child blog.
 * @return string $embed the html output
 */
function wp_embed_handler_buddydrive($matches, $attr, $url, $rawattr)
{
    $link = $title = $icon = $content = $mime_type = $filelist = $hw_attr = false;
    $current_blog = get_current_blog_id();
    if (is_multisite() && (int) $current_blog !== (int) bp_get_root_blog_id()) {
        switch_to_blog(bp_get_root_blog_id());
    }
    if ($matches[1] == 'file') {
        $buddyfile = buddydrive_get_buddyfile($matches[2], buddydrive_get_file_post_type());
        if (empty($buddyfile)) {
            return '';
        }
        $link = $buddyfile->link;
        $title = $buddyfile->title;
        $content = $buddyfile->content;
        $mime_type = $buddyfile->mime_type;
        $icon = wp_mime_type_icon($buddyfile->ID);
        if ('public' === $buddyfile->check_for) {
            $thumbnail = buddydrive_get_thumbnail($buddyfile->ID, 'thumburl', false);
            if (!empty($thumbnail[0])) {
                $icon = $thumbnail[0];
                $hw_attr = image_hwstring($thumbnail[1], $thumbnail[2]);
            }
        }
        // It's a folfer
    } else {
        $buddyfile = buddydrive_get_buddyfile($matches[2], buddydrive_get_folder_post_type());
        if (empty($buddyfile)) {
            return '';
        }
        $buddydrive_root_link = $buddyfile->check_for == 'groups' ? buddydrive_get_group_buddydrive_url($buddyfile->group) : buddydrive_get_user_buddydrive_url($buddyfile->user_id);
        $link = $buddydrive_root_link . '?folder-' . $buddyfile->ID;
        $title = $buddyfile->title;
        $mime_type = $buddyfile->mime_type;
        $icon = buddydrive_get_images_url() . 'folder.png';
    }
    $embed = '<table style="width:auto"><tr>';
    $tdwidth = 'width:60px;';
    if (!empty($hw_attr)) {
        $tdwidth = '';
    }
    $embed .= '<td style="vertical-align:middle;' . $tdwidth . '"><a href="' . esc_url($link) . '" title="' . esc_attr($title) . '"><img src="' . esc_url($icon) . '" alt="' . esc_attr($mime_type) . '" class="buddydrive-thumb" ' . $hw_attr . '></a></td>';
    $embed .= '<td style="vertical-align:middle"><h6 style="margin:0"><a href="' . esc_url($link) . '" title="' . esc_attr($title) . '">' . esc_html($title) . '</a></h6>';
    if (!empty($content)) {
        $embed .= '<p style="margin:0">' . esc_html($content) . '</p>';
    }
    if ($matches[1] == 'folder') {
        global $buddydrive_template;
        if (buddydrive_has_items(array('buddydrive_parent' => $buddyfile->ID))) {
            $filelist = '<p style="margin-top:1em;margin-bottom:0">' . esc_html__('Files included in this folder :', 'buddydrive') . '</p><ul>';
            while (buddydrive_has_items()) {
                buddydrive_the_item();
                $filelist .= '<li><a href="' . esc_url(buddydrive_get_action_link()) . '" title="' . esc_attr(buddydrive_get_item_title()) . '">' . esc_html(buddydrive_get_item_title()) . '</a></li>';
            }
            $filelist .= '</ul>';
            $buddydrive_template = false;
        }
        wp_reset_postdata();
        $embed .= $filelist;
    }
    $embed .= '</td></tr></table>';
    if (is_multisite() && (int) $current_blog !== (int) bp_get_root_blog_id()) {
        restore_current_blog();
    }
    return apply_filters('embed_buddydrive', $embed, $matches, $attr, $url, $rawattr);
}
Beispiel #6
0
</th><th class="buddydrive-mime-type"><?php 
        _e('Type', 'buddydrive');
        ?>
</th><th class="buddydrive-last-edit"><?php 
        _e('Last edit', 'buddydrive');
        ?>
</th></tr>
			</thead>
			<tbody>
	<?php 
    }
    ?>

	<?php 
    while (buddydrive_has_items()) {
        buddydrive_the_item();
        ?>

		<?php 
        bp_get_template_part('buddydrive-entry', false);
        ?>

	<?php 
    }
    ?>

	<?php 
    if (buddydrive_has_more_items()) {
        ?>

		<tr>