/**
 * Post an activity in user's profile
 *
 * @uses check_admin_referer() for security reasons
 * @uses bp_loggedin_user_id() to get the current user id
 * @uses buddydrive_get_folder_post_type() to get the BuddyFolder post type
 * @uses buddydrive_get_name() so that it's possible to brand the plugin
 * @uses buddydrive_get_file_post_type() to get the BuddyFile post type
 * @uses buddydrive_get_buddyfile() to get item
 * @uses bp_core_get_userlink() to get link to user's profile
 * @uses bp_activity_add() to finaly record the activity without updating the latest meta
 * @return int 1 or string an error message
 */
function buddydrive_share_in_profile()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Check the nonce
    check_admin_referer('buddydrive_actions', '_wpnonce_buddydrive_actions');
    $buddyitem = intval($_POST['itemid']);
    if (empty($buddyitem)) {
        _e('this is embarassing, it did not work :(', 'buddydrive');
        die;
    }
    $link = $_POST['url'];
    $result = false;
    $user_id = bp_loggedin_user_id();
    $item_type = 'folder' == $_POST['itemtype'] ? buddydrive_get_folder_post_type() : buddydrive_get_file_post_type();
    if (!empty($buddyitem)) {
        $buddyfile = buddydrive_get_buddyfile($buddyitem, $item_type);
        if (empty($buddyfile->ID) || $buddyfile->check_for != 'public') {
            // no item or not a public one ??
            _e('We could not find your BuddyDrive item or its privacy is not set to public', 'buddydrive');
            die;
        }
        $action = sprintf(__('%1$s shared a %2$s Item', 'buddydrive'), bp_core_get_userlink($user_id), buddydrive_get_name());
        $content = $link;
        $args = array('user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => bp_core_get_userlink($user_id, false, true), 'component' => 'activity', 'type' => 'activity_update');
        $result = bp_activity_add($args);
    }
    if (!empty($result)) {
        echo 1;
    } else {
        echo _e('this is embarassing, it did not work :(', 'buddydrive');
    }
    die;
}
/**
 * Adds post datas to include a file / folder to a private message
 *
 * @uses buddydrive_get_buddyfile() gets the BuddyFile Object
 * @uses buddydrive_get_file_post_type() gets the BuddyFile post type
 * @uses buddydrive_get_name() so that it's possible to brand the plugin
 * @uses buddydrive_get_folder_post_type() gets the BuddyFolder post type
 * @uses bp_loggedin_user_id() to get current user id
 * @uses buddydrive_get_user_buddydrive_url() to build the folder url on user's BuddyDrive
 * @return string html output and inputs
 */
function buddydrive_attached_file_to_message()
{
    if (!empty($_REQUEST['buddyitem'])) {
        $link = $buddytype = $password = false;
        $buddyitem = buddydrive_get_buddyfile($_REQUEST['buddyitem'], array(buddydrive_get_file_post_type(), buddydrive_get_folder_post_type()));
        if (!empty($buddyitem->ID)) {
            if ($buddyitem->user_id != bp_loggedin_user_id()) {
                ?>
				<div id="message" class="error"><p><?php 
                _e('Cheating ?', 'buddydrive');
                ?>
</p></div>
				<?php 
                return;
            }
            $link = $buddyitem->link;
            if ($buddyitem->post_type == buddydrive_get_file_post_type()) {
                $displayed_link = $buddyitem->link;
                $buddytype = buddydrive_get_name() . ' File';
                if (!empty($buddyitem->post_parent)) {
                    $parent = buddydrive_get_buddyfile($buddyitem->post_parent, buddydrive_get_folder_post_type());
                    $password = !empty($parent->password) ? $parent->password : false;
                } else {
                    $password = !empty($buddyitem->password) ? $buddyitem->password : false;
                }
            } else {
                $displayed_link = buddydrive_get_user_buddydrive_url(bp_loggedin_user_id()) . '?folder-' . $buddyitem->ID;
                $buddytype = buddydrive_get_name() . ' Folder';
                $password = !empty($buddyitem->password) ? $buddyitem->password : false;
            }
            ?>
			<p>
				<label for="buddyitem-link"><?php 
            printf(__('%s attached : %s', 'buddydrive'), esc_html($buddytype), '<a href="' . esc_url($displayed_link) . '">' . esc_html($buddyitem->title) . '</a>');
            ?>
</label>
				<input type="hidden" value="<?php 
            echo esc_url($link);
            ?>
" id="buddyitem-link" name="_buddyitem_link">
				<input type="hidden" value="<?php 
            echo esc_attr($buddyitem->ID);
            ?>
" id="buddyitem-id" name="_buddyitem_id">

				<?php 
            if (!empty($password)) {
                ?>
					<input type="checkbox" name="_buddyitem_pass" value="1" checked> <?php 
                _e('Automatically add the password in the message', 'buddydrive');
                ?>
				<?php 
            }
            ?>
			</p>
			<?php 
        }
    }
}
 /**
  * Update the global $post with directory data
  *
  * @package BuddyDrive Component
  * @subpackage Screens
  * @since 1.2.0
  *
  * @uses bp_theme_compat_reset_post() to reset the post data
  */
 public function directory_dummy_post()
 {
     bp_theme_compat_reset_post(array('ID' => 0, 'post_title' => buddydrive_get_name(), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => 'page', 'post_status' => 'publish', 'is_page' => true, 'comment_status' => 'closed'));
 }
 /**
  * construct method to add some settings and hooks
  *
  * @uses buddydrive_get_name() to get the plugin name
  * @uses buddydrive_get_slug() to get the plugin slug
  */
 public function __construct()
 {
     $args = array('slug' => buddydrive_get_slug(), 'name' => buddydrive_get_name(), 'visibility' => 'private', 'nav_item_position' => 31, 'enable_nav_item' => $this->enable_nav_item(), 'screens' => array('admin' => array('metabox_context' => 'side', 'metabox_priority' => 'core'), 'create' => array('enabled' => false), 'edit' => array('enabled' => true)));
     parent::init($args);
 }
Example #5
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 
    }
/**
 * Handles Plugin activation
 *
 * @uses bp_core_get_directory_page_ids() to get the BuddyPress component page ids
 * @uses buddydrive_get_slug() to get BuddyDrive slug
 * @uses wp_insert_post() to eventually create a new page for BuddyDrive
 * @uses buddydrive_get_name() to get BuddyDrive plugin name
 * @uses bp_core_update_directory_page_ids() to update the BuddyPres component pages ids
 */
function buddydrive_activation()
{
    // For network, as plugin is not yet activated, bail method won't help..
    if (is_network_admin() && function_exists('buddypress')) {
        $check = !empty($_REQUEST) && 'activate' == $_REQUEST['action'] && $_REQUEST['plugin'] == buddydrive()->basename && bp_is_network_activated() && buddydrive::version_check();
    } else {
        $check = !buddydrive::bail();
    }
    if (empty($check)) {
        return;
    }
    // let's check for BuddyDrive page in directory pages first !
    $directory_pages = bp_core_get_directory_page_ids();
    $buddydrive_slug = buddydrive_get_slug();
    if (empty($directory_pages[$buddydrive_slug])) {
        // let's create a page and add it to BuddyPress directory pages
        $buddydrive_page_content = __('BuddyDrive uses this page to manage the downloads of your buddies files, please leave it as is. It will not show in your navigation bar.', 'buddydrive');
        $buddydrive_page_id = wp_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_title' => buddydrive_get_name(), 'post_content' => $buddydrive_page_content, 'post_name' => $buddydrive_slug, 'post_status' => 'publish', 'post_type' => 'page'));
        $directory_pages[$buddydrive_slug] = $buddydrive_page_id;
        bp_core_update_directory_page_ids($directory_pages);
    }
    do_action('buddydrive_activation');
}
Example #7
0
        _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 
    }
    ?>
	
 /**
  * Builds the user's navigation in WP Admin Bar
  *
  * @uses buddydrive_get_slug() to get BuddyDrive slug
  * @uses is_user_logged_in() to check if the user is logged in
  * @uses bp_loggedin_user_domain() to get current user's profile link
  * @uses buddydrive_get_name() to get BuddyDrive plugin name
  * @uses buddydrive_get_user_subnav_name() to get main subnav name
  * @uses buddydrive_get_friends_subnav_name() to get friends subnav name
  * @uses buddydrive_get_friends_subnav_slug() to get friends subnav slug
  * @uses bp_is_active() to check for the friends component
  */
 public function setup_admin_bar($wp_admin_nav = array())
 {
     // Prevent debug notices
     $wp_admin_nav = array();
     $buddydrive_slug = buddydrive_get_slug();
     // Menus for logged in user
     if (is_user_logged_in()) {
         // Setup the logged in user variables
         $buddydrive_link = trailingslashit(bp_loggedin_user_domain() . $buddydrive_slug);
         // Add main BuddyDrive menu
         $wp_admin_nav[] = array('parent' => 'my-account-buddypress', 'id' => 'my-account-' . $buddydrive_slug, 'title' => buddydrive_get_name(), 'href' => trailingslashit($buddydrive_link));
         // Add BuddyDrive submenu
         $wp_admin_nav[] = array('parent' => 'my-account-' . $buddydrive_slug, 'id' => 'my-account-' . $buddydrive_slug . '-files', 'title' => buddydrive_get_user_subnav_name(), 'href' => trailingslashit($buddydrive_link));
         if (bp_is_active('friends')) {
             // Add shared by friends BuddyDrive submenu
             $wp_admin_nav[] = array('parent' => 'my-account-' . $buddydrive_slug, 'id' => 'my-account-' . $buddydrive_slug . '-friends', 'title' => buddydrive_get_friends_subnav_name(), 'href' => trailingslashit($buddydrive_link . buddydrive_get_friends_subnav_slug()));
         }
     }
     parent::setup_admin_bar($wp_admin_nav);
 }