/**
 * 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);
}
        /**
         * Displays the Welcome screen
         *
         * @uses buddydrive_get_version() to get the current version of the plugin
         * @uses bp_get_admin_url() to build the url to settings page
         * @uses add_query_arg() to add args to the url
         */
        public function about_screen()
        {
            global $wp_version;
            $display_version = buddydrive_get_version();
            $settings_url = add_query_arg(array('page' => 'buddydrive'), bp_get_admin_url($this->settings_page));
            ?>
		<div class="wrap about-wrap">
			<h1><?php 
            printf(__('BuddyDrive %s', 'buddydrive'), $display_version);
            ?>
</h1>
			<div class="about-text"><?php 
            printf(__('Thank you for upgrading to the latest version of BuddyDrive! BuddyDrive %s is ready to manage the files and folders of your buddies!', 'buddydrive'), $display_version);
            ?>
</div>
			<div class="buddydrive-badge"></div>

			<h2 class="nav-tab-wrapper">
				<a class="nav-tab nav-tab-active" href="<?php 
            echo esc_url(bp_get_admin_url(add_query_arg(array('page' => 'buddydrive-about'), 'index.php')));
            ?>
">
					<?php 
            _e('About', 'buddydrive');
            ?>
				</a>
			</h2>

			<div class="headline-feature">
				<h3><?php 
            esc_html_e('Meet the BuddyDrive Editor', 'buddydrive');
            ?>
</h3>

				<div class="featured-image">
					<img src="<?php 
            echo esc_url(buddydrive_get_images_url() . '/buddydrive-editor.png');
            ?>
" alt="<?php 
            esc_attr_e('The BuddyDrive Editor', 'buddydrive');
            ?>
">
				</div>

				<div class="feature-section">
					<h3><?php 
            esc_html_e('BuddyDrive is now using the BuddyPress Attachments API!', 'buddydrive');
            ?>
</h3>
					<p><?php 
            esc_html_e('Introduced in BuddyPress 2.3, BuddyDrive uses this API to manage user uploads the BuddyPress way. It gave birth to a new BuddyDrive Editor. Now, you and plugins can use it to easily share public files with your community members.', 'buddydrive');
            ?>
 <a href="https://github.com/imath/buddydrive/wiki/The-BuddyDrive-Editor"><?php 
            esc_html_e('Learn more &rarr;', 'buddydrive');
            ?>
</a></p>
				</div>

				<div class="clear"></div>
			</div>

			<div class="feature-list">
				<h2><?php 
            printf(__('The other improvements in %s', 'buddydrive'), $display_version);
            ?>
</h2>

				<div class="feature-section col two-col">
					<div>
						<h4><?php 
            esc_html_e('Bulk-deleting files in the Administration screen', 'buddydrive');
            ?>
</h4>
						<p><?php 
            _e('When the community administrator bulk-deletes files having different owners, each owner&#39;s quota will now be updated.', 'buddydrive');
            ?>
</p>

						<h4><?php 
            esc_html_e('Representation of embed public image files.', 'buddydrive');
            ?>
</h4>
						<p><?php 
            esc_html_e('When you share a link to a file into the activity stream, a private message, a post, a page, ..., BuddyDrive is catching this link to build some specific output.', 'buddydrive');
            ?>
</p>
						<p><?php 
            esc_html_e('Now, if this link is about a public image, a thumbnail will be displayed next to the file title (and description if provided).', 'buddydrive');
            ?>
</p>
					</div>
					<div class="last-feature">
						<h4><?php 
            esc_html_e('BuddyPress single group&#39;s latest activity', 'buddydrive');
            ?>
</h4>
						<p><?php 
            esc_html_e('When a file is shared with the members of a group, the latest activity of the group will be updated.', 'buddydrive');
            ?>
</p>
						
						<h4><?php 
            esc_html_e('Reassign deleted files', 'buddydrive');
            ?>
</h4>
						<p><?php 
            esc_html_e('If you need to keep files when a user leaves your community (sad), you can use the following filter making sure to return the ID of a user having the bp_moderate capability.', 'buddydrive');
            ?>
</p>
						<p><code>buddydrive_set_owner_on_user_deleted</code></p>
					</div>
				</div>
			</div>

			<?php 
            if (!empty($_REQUEST['is_new_install'])) {
                ?>

			<div class="changelog">
				<h2 class="about-headline-callout"><?php 
                esc_html_e('and always..', 'buddydrive');
                ?>
</h2>
				<div class="feature-section col two-col">
					<div>
						<h4><?php 
                _e('User&#39;s BuddyDrive', 'buddydrive');
                ?>
</h4>
						<p>
							<?php 
                _e('It lives in the member&#39;s page just under the BuddyDrive tab.', 'buddydrive');
                ?>
							<?php 
                _e('The BuddyDrive edit bar allows the user to manage from one unique place his content.', 'buddydrive');
                ?>
							<?php 
                _e('He can add new files, new folders, set their privacy settings, edit them and of course delete them at any time.', 'buddydrive');
                ?>
						</p>
						<img src="<?php 
                echo buddydrive_get_plugin_url();
                ?>
/screenshot-1.png" style="width:90%">
					</div>

					<div class="last-feature">
						<h4><?php 
                _e('BuddyDrive Uploader', 'buddydrive');
                ?>
</h4>
						<p>
							<?php 
                _e('BuddyDrive uses WordPress HTML5 uploader and do not add any third party script to handle uploads.', 'buddydrive');
                ?>
							<?php 
                _e('WordPress is a fabulous tool and already knows how to deal with attachments for its content.', 'buddydrive');
                ?>
							<?php 
                _e('So BuddyDrive is managing uploads, the WordPress way!', 'buddydrive');
                ?>
						</p>
						<img src="<?php 
                echo buddydrive_get_plugin_url();
                ?>
/screenshot-2.png" style="width:90%">
					</div>
				</div>
			</div>

			<div class="changelog">
				<div class="feature-section col two-col">
					<div>
						<h4><?php 
                _e('BuddyDrive Folders', 'buddydrive');
                ?>
</h4>
						<p>
							<?php 
                _e('Using folders is a convenient way to share a list of files at once.', 'buddydrive');
                ?>
							<?php 
                _e('Users just need to create a folder, open it an add the files of their choice to it.', 'buddydrive');
                ?>
							<?php 
                _e('When sharing a folder, a member actually shares the list of files that is attached to it.', 'buddydrive');
                ?>
						</p>
						<img src="<?php 
                echo buddydrive_get_images_url();
                ?>
/folder-demo.png" style="width:90%">
					</div>

					<div class="last-feature">
						<h4><?php 
                _e('BuddyDrive privacy options', 'buddydrive');
                ?>
</h4>
						<p>
							<?php 
                _e('There are five levels of privacy for the files or folders.', 'buddydrive');
                ?>
&nbsp;
							<?php 
                _e('Depending on your BuddyPress settings, a user can set the privacy of a BuddyDrive item to:', 'buddydrive');
                ?>
						</p>
						<ul>
							<li><?php 
                _e('Private: the owner of the item will be the only one to be able to download the file.', 'buddydrive');
                ?>
</li>
							<li><?php 
                _e('Password protected: a password will be required before being able to download the file.', 'buddydrive');
                ?>
</li>
							<li><?php 
                _e('Public: everyone can download the file.', 'buddydrive');
                ?>
</li>
							<li><?php 
                _e('Friends only: if the BuddyPress friendship component is active, a user can restrict a download to his friends only.', 'buddydrive');
                ?>
</li>
							<li><?php 
                _e('One of the user&#39;s group: if the BuddyPress user groups component is active, and if the administrator of the group enabled BuddyDrive, a user can restrict the download to members of the group only.', 'buddydrive');
                ?>
</li>
						</ul>
					</div>
				</div>
			</div>

			<div class="changelog">
				<div class="feature-section col two-col">
					<div>
						<h4><?php 
                _e('Sharing BuddyDrive items', 'buddydrive');
                ?>
</h4>
						<p>
							<?php 
                _e('Depending on the privacy option of an item and the activated BuddyPress components, a user can :', 'buddydrive');
                ?>
						</p>
						<ul>
							<li><?php 
                _e('Share a public BuddyDrive item in his personal activity.', 'buddydrive');
                ?>
</li>
							<li><?php 
                _e('Share a password protected item using the private messaging BuddyPress component.', 'buddydrive');
                ?>
</li>
							<li><?php 
                _e('Alert his friends he shared a new item using the private messaging BuddyPress component.', 'buddydrive');
                ?>
</li>
							<li><?php 
                _e('Share his file in a group activity to inform the other members of the group.', 'buddydrive');
                ?>
</li>
							<li><?php 
                _e('Copy the link to his item and paste it anywhere in the blog or in a child blog (in case of a multisite configuration). This link will automatically be converted into a nice piece of html.', 'buddydrive');
                ?>
</li>
						</ul>
					</div>

					<div class="last-feature">
						<h4><?php 
                _e('Supervising BuddyDrive', 'buddydrive');
                ?>
</h4>
						<p>
							<?php 
                _e('The administrator of the community can manage all BuddyDrive items from the backend of WordPress.', 'buddydrive');
                ?>
						</p>
						<img src="<?php 
                echo buddydrive_get_plugin_url();
                ?>
/screenshot-4.png" style="width:90%">
					</div>
				</div>
			</div>

			<?php 
            }
            ?>

			<div class="changelog">
				<div class="return-to-dashboard">
					<a href="<?php 
            echo esc_url($settings_url);
            ?>
" title="<?php 
            esc_attr_e('Configure BuddyDrive', 'buddydrive');
            ?>
"><?php 
            esc_html_e('Go to the BuddyDrive Settings page', 'buddydrive');
            ?>
</a>
				</div>
			</div>

		</div>
	<?php 
        }