/**
 * Loads a form to edit a file or a folder
 *
 * @uses buddydrive_get_buddyfile() to get the item to edit
 * @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 sanitize data
 * @uses buddydrive_select_sharing_options() to display the privacy choices
 * @uses buddydrive_select_user_group() to display the groups available
 * @uses buddydrive_select_folder_options() to display the available folders
 * @return string the edit form
 */
function buddydrive_edit_form()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    $item_id = !empty($_POST['buddydrive_item']) ? intval($_POST['buddydrive_item']) : false;
    if (!empty($item_id)) {
        $item = buddydrive_get_buddyfile($item_id, array(buddydrive_get_folder_post_type(), buddydrive_get_file_post_type()));
        ?>
		<form class="standard-form" id="buddydrive-item-edit-form">

			<div id="buddyitem-description">
				<input type="hidden" id="buddydrive-item-id" value="<?php 
        echo $item->ID;
        ?>
">
				<label for="buddydrive-item-title"><?php 
        esc_html_e('Name', 'buddydrive');
        ?>
</label>
				<input type="text" name="buddydrive-edit[item-title]" id="buddydrive-item-title" value="<?php 
        echo esc_attr(stripslashes($item->title));
        ?>
" />

				<?php 
        if ($item->post_type == buddydrive_get_file_post_type()) {
            ?>
					<label for="buddydrive-item-content"><?php 
            esc_html_e('Description', 'buddydrive');
            ?>
</label>
					<textarea name="buddydrive-edit[item-content]" id="buddydrive-item-content" maxlength="140"><?php 
            echo wp_kses(stripslashes($item->content), array());
            ?>
</textarea>
					<?php 
            if (has_action('buddydrive_uploader_custom_fields')) {
                ?>
						<div id="buddydrive-custom-step-edit" class="buddydrive-step hide">
							<?php 
                do_action('buddydrive_uploader_custom_fields', $item->ID);
                ?>
						</div>
					<?php 
            }
            ?>
				<?php 
        }
        ?>

			</div>

			<?php 
        if (empty($item->post_parent)) {
            ?>

				<div id="buddydrive-privacy-section-options">
					<label for="buddydrive-sharing-option"><?php 
            esc_html_e('Item Sharing options', 'buddydrive');
            ?>
</label>
					<?php 
            buddydrive_select_sharing_options('buddyitem-sharing-options', $item->check_for, 'buddydrive-edit[sharing]');
            ?>

					<div id="buddydrive-admin-privacy-detail">
						<?php 
            if ($item->check_for == 'password') {
                ?>
							<label for="buddydrive-password"><?php 
                esc_html_e('Password', 'buddydrive');
                ?>
</label>
							<input type="text" value="<?php 
                echo esc_attr(stripslashes($item->password));
                ?>
" name="buddydrive-edit[password]" id="buddypass"/>
						<?php 
            } elseif ($item->check_for == 'groups') {
                ?>
							<label for="buddygroup"><?php 
                esc_html_e('Choose the group', 'buddydrive');
                ?>
</label>
							<?php 
                buddydrive_select_user_group($item->user_id, $item->group, 'buddydrive-edit[buddygroup]');
                ?>
						<?php 
            }
            ?>
					</div>
				</div>

			<?php 
        } else {
            ?>

				<div id="buddyitem-sharing-option">
					<label for="buddydrive-sharing-option"><?php 
            esc_html_e('Edit your sharing options', 'buddydrive');
            ?>
</label>
					<p><?php 
            esc_html_e('Privacy of this item rely on its parent folder', 'buddydrive');
            ?>
</p>
				</div>

			<?php 
        }
        ?>

			<?php 
        if ($item->post_type == buddydrive_get_file_post_type()) {
            ?>

				<div class="buddyitem-folder-section" id="buddyitem-folder-section-options">
					<label for="buddyitem-folder-option"><?php 
            esc_html_e('Folder', 'buddydrive');
            ?>
</label>
					<?php 
            buddydrive_select_folder_options($item->user_id, $item->post_parent, 'buddydrive-edit[folder]');
            ?>
				</div>

			<?php 
        }
        ?>

			<p class="buddydrive-action folder"><input type="submit" value="<?php 
        esc_html_e('Edit Item', 'buddydrive');
        ?>
" name="buddydrive_edit[submit]">&nbsp;<a href="#" class="cancel-item button"><?php 
        esc_html_e('Cancel', 'buddydrive');
        ?>
</a></p>

		</form>
		<?php 
    }
    die;
}
Example #2
0
/**
 * Privacy Metabox settings
 *
 * @param  object $item The BuddyDrive Item object
 * @uses get_post_meta() to get the privacy settings
 * @uses buddydrive_get_show_owner_avatar() to get owner's avatar
 * @uses buddydrive_user_used_quota() to get user's space left
 * @uses buddydrive_select_sharing_options() to display the select box of available privacy options
 * @uses buddydrive_select_user_group() to display the group select box
 * @uses buddydrive_get_file_post_type() to get the BuddyFile post type
 * @uses buddydrive_select_folder_options() to display the parent folder select box
 */
function buddydrive_admin_edit_metabox_privacy($item)
{
    $privacy_status = get_post_meta($item->ID, '_buddydrive_sharing_option', true);
    $owner = $item->user_id;
    $avatar = buddydrive_get_show_owner_avatar($owner);
    ?>
	<div class="buddydrive-owner-section" id="buddydrive-owner-section-info">
		<div>
			<label><?php 
    _e('Owner', 'buddydrive');
    ?>
</label>
			<table>
				<tr>
					<td><?php 
    echo $avatar;
    ?>
</td>
					<td><?php 
    _e('BuddyDrive Usage', 'buddydrive');
    ?>
 : <?php 
    buddydrive_user_used_quota(false, $owner);
    ?>
 %</td>
				</tr>
			</table>
		</div>
		<input type="hidden" value="<?php 
    echo $owner;
    ?>
" id="buddydrive-owner-id" disabled>
	</div>

	<?php 
    if (empty($item->post_parent)) {
        ?>

		<div class="buddydrive-privacy-section" id="buddydrive-privacy-section-options">
			<label for="buddydrive-sharing-option"><?php 
        _e('Item Sharing options', 'buddydrive');
        ?>
</label>
			<?php 
        buddydrive_select_sharing_options('buddydrive-admin-sharing-options', $privacy_status, 'buddydrive-edit[sharing]');
        ?>

			<div id="buddydrive-admin-privacy-detail">
				<?php 
        if ($privacy_status == 'password') {
            ?>
					<label for="buddydrive-password"><?php 
            _e('Password', 'buddydrive');
            ?>
</label>
					<input type="text" value="<?php 
            echo esc_attr(stripslashes($item->password));
            ?>
" name="buddydrive-edit[password]" id="buddydrive-password"/>
				<?php 
        } elseif ($privacy_status == 'groups') {
            ?>
					<label for="buddygroup"><?php 
            _e('Choose the group', 'buddydrive');
            ?>
</label>
					<?php 
            buddydrive_select_user_group($owner, $item->group, 'buddydrive-edit[buddygroup]');
            ?>
				<?php 
        }
        ?>
			</div>
		</div>

		<?php 
        if (empty($privacy_status)) {
            ?>
			<p><strong><?php 
            _e('The privacy of this item is not defined, please correct this!', 'buddydrive');
            ?>
</strong></p>
		<?php 
        }
        ?>

	<?php 
    } else {
        ?>

		<div class="buddydrive-privacy-section" id="buddydrive-privacy-section-options">
			<label for="buddydrive-sharing-option"><?php 
        _e('Item Sharing options', 'buddydrive');
        ?>
</label>
			<p><?php 
        printf(__("Privacy of this item rely on its parent <a href=\"%s\">folder</a>", "buddydrive"), esc_url(add_query_arg(array('page' => 'buddydrive-files', 'bid' => $item->post_parent, 'action' => 'edit'), bp_get_admin_url('admin.php'))));
        ?>
</p>
		</div>

	<?php 
    }
    ?>

	<?php 
    if ($item->post_type == buddydrive_get_file_post_type()) {
        ?>

		<div class="buddydrive-folder-section" id="buddydrive-folder-section-options">
			<label for="buddydrive-folder-option"><?php 
        _e('Folder', 'buddydrive');
        ?>
</label>
			<?php 
        buddydrive_select_folder_options($owner, $item->post_parent, 'buddydrive-edit[folder]');
        ?>
		</div>

	<?php 
    }
    ?>

<?php 
}