コード例 #1
0
/**
 * Displays the title of the BuddyDrive item
 *
 * @uses buddydrive_get_item_title() to get the title of the item
 */
function buddydrive_item_title()
{
    echo buddydrive_get_item_title();
}
コード例 #2
0
/**
 * 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);
}