• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wp_get_attachment_id3_keys函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中wp_get_attachment_id3_keys函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_get_attachment_id3_keys函数的具体用法?PHP wp_get_attachment_id3_keys怎么用?PHP wp_get_attachment_id3_keys使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了wp_get_attachment_id3_keys函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: cherry_video_meta

/**
 * Retrieve formatted video metadata.
 *
 * @author Justin Tadlock <[email protected]>
 * @author Cherry Team <[email protected]>
 * @since  4.0.0
 * @param  int   $post_id  Attachment ID.
 * @param  array $metadata The attachment metadata.
 * @return array           Video metadata.
 */
function cherry_video_meta($post_id, $metadata)
{
    // Get ID3 keys (labels for metadata).
    $id3_keys = wp_get_attachment_id3_keys($post_id);
    $items = array();
    // File size.
    if (!empty($metadata['filesize'])) {
        $items['filesize'] = array(size_format(strip_tags($metadata['filesize']), 2), $id3_keys['filesize']);
    }
    // Mime type.
    if (!empty($metadata['mime_type'])) {
        $items['mime_type'] = array(esc_html($metadata['mime_type']), $id3_keys['mime_type']);
    }
    // Formated length of time the video file runs.
    if (!empty($metadata['length_formatted'])) {
        $items['length_formatted'] = array(esc_html($metadata['length_formatted']), $id3_keys['length_formatted']);
    }
    // Dimensions (width x height in pixels).
    if (!empty($metadata['width']) && !empty($metadata['height'])) {
        // Translators: Media dimensions - 1 is width and 2 is height.
        $items['dimensions'] = array(sprintf(__('%1$s &#215; %2$s', 'cherry'), number_format_i18n(absint($metadata['width'])), number_format_i18n(absint($metadata['height']))), __('Dimensions', 'cherry'));
    }
    /**
     * Filter video metadata.
     *
     * @since 4.0.0
     * @param array $items Metadata.
     */
    return apply_filters('cherry_video_meta', $items);
}
开发者ID:xav335,项目名称:sfnettoyage,代码行数:40,代码来源:template-media.php


示例2: wp_ajax_save_attachment

/**
 * Ajax handler for updating attachment attributes.
 *
 * @since 3.5.0
 */
function wp_ajax_save_attachment()
{
    if (!isset($_REQUEST['id']) || !isset($_REQUEST['changes'])) {
        wp_send_json_error();
    }
    if (!($id = absint($_REQUEST['id']))) {
        wp_send_json_error();
    }
    check_ajax_referer('update-post_' . $id, 'nonce');
    if (!current_user_can('edit_post', $id)) {
        wp_send_json_error();
    }
    $changes = $_REQUEST['changes'];
    $post = get_post($id, ARRAY_A);
    if ('attachment' != $post['post_type']) {
        wp_send_json_error();
    }
    if (isset($changes['parent'])) {
        $post['post_parent'] = $changes['parent'];
    }
    if (isset($changes['title'])) {
        $post['post_title'] = $changes['title'];
    }
    if (isset($changes['caption'])) {
        $post['post_excerpt'] = $changes['caption'];
    }
    if (isset($changes['description'])) {
        $post['post_content'] = $changes['description'];
    }
    if (MEDIA_TRASH && isset($changes['status'])) {
        $post['post_status'] = $changes['status'];
    }
    if (isset($changes['alt'])) {
        $alt = wp_unslash($changes['alt']);
        if ($alt != get_post_meta($id, '_wp_attachment_image_alt', true)) {
            $alt = wp_strip_all_tags($alt, true);
            update_post_meta($id, '_wp_attachment_image_alt', wp_slash($alt));
        }
    }
    if (wp_attachment_is('audio', $post['ID'])) {
        $changed = false;
        $id3data = wp_get_attachment_metadata($post['ID']);
        if (!is_array($id3data)) {
            $changed = true;
            $id3data = array();
        }
        foreach (wp_get_attachment_id3_keys((object) $post, 'edit') as $key => $label) {
            if (isset($changes[$key])) {
                $changed = true;
                $id3data[$key] = sanitize_text_field(wp_unslash($changes[$key]));
            }
        }
        if ($changed) {
            wp_update_attachment_metadata($id, $id3data);
        }
    }
    if (MEDIA_TRASH && isset($changes['status']) && 'trash' === $changes['status']) {
        wp_delete_post($id);
    } else {
        wp_update_post($post);
    }
    wp_send_json_success();
}
开发者ID:hughnet,项目名称:WordPress,代码行数:68,代码来源:ajax-actions.php


示例3: edit_post

/**
 * Update an existing post with values provided in $_POST.
 *
 * @since 1.5.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $post_data Optional.
 * @return int Post ID.
 */
function edit_post($post_data = null)
{
    global $wpdb;
    if (empty($post_data)) {
        $post_data =& $_POST;
    }
    // Clear out any data in internal vars.
    unset($post_data['filter']);
    $post_ID = (int) $post_data['post_ID'];
    $post = get_post($post_ID);
    $post_data['post_type'] = $post->post_type;
    $post_data['post_mime_type'] = $post->post_mime_type;
    if (!empty($post_data['post_status'])) {
        $post_data['post_status'] = sanitize_key($post_data['post_status']);
        if ('inherit' == $post_data['post_status']) {
            unset($post_data['post_status']);
        }
    }
    $ptype = get_post_type_object($post_data['post_type']);
    if (!current_user_can('edit_post', $post_ID)) {
        if ('page' == $post_data['post_type']) {
            wp_die(__('Sorry, you are not allowed to edit this page.'));
        } else {
            wp_die(__('Sorry, you are not allowed to edit this post.'));
        }
    }
    if (post_type_supports($ptype->name, 'revisions')) {
        $revisions = wp_get_post_revisions($post_ID, array('order' => 'ASC', 'posts_per_page' => 1));
        $revision = current($revisions);
        // Check if the revisions have been upgraded
        if ($revisions && _wp_get_post_revision_version($revision) < 1) {
            _wp_upgrade_revisions_of_post($post, wp_get_post_revisions($post_ID));
        }
    }
    if (isset($post_data['visibility'])) {
        switch ($post_data['visibility']) {
            case 'public':
                $post_data['post_password'] = '';
                break;
            case 'password':
                unset($post_data['sticky']);
                break;
            case 'private':
                $post_data['post_status'] = 'private';
                $post_data['post_password'] = '';
                unset($post_data['sticky']);
                break;
        }
    }
    $post_data = _wp_translate_postdata(true, $post_data);
    if (is_wp_error($post_data)) {
        wp_die($post_data->get_error_message());
    }
    // Post Formats
    if (isset($post_data['post_format'])) {
        set_post_format($post_ID, $post_data['post_format']);
    }
    $format_meta_urls = array('url', 'link_url', 'quote_source_url');
    foreach ($format_meta_urls as $format_meta_url) {
        $keyed = '_format_' . $format_meta_url;
        if (isset($post_data[$keyed])) {
            update_post_meta($post_ID, $keyed, wp_slash(esc_url_raw(wp_unslash($post_data[$keyed]))));
        }
    }
    $format_keys = array('quote', 'quote_source_name', 'image', 'gallery', 'audio_embed', 'video_embed');
    foreach ($format_keys as $key) {
        $keyed = '_format_' . $key;
        if (isset($post_data[$keyed])) {
            if (current_user_can('unfiltered_html')) {
                update_post_meta($post_ID, $keyed, $post_data[$keyed]);
            } else {
                update_post_meta($post_ID, $keyed, wp_filter_post_kses($post_data[$keyed]));
            }
        }
    }
    if ('attachment' === $post_data['post_type'] && preg_match('#^(audio|video)/#', $post_data['post_mime_type'])) {
        $id3data = wp_get_attachment_metadata($post_ID);
        if (!is_array($id3data)) {
            $id3data = array();
        }
        foreach (wp_get_attachment_id3_keys($post, 'edit') as $key => $label) {
            if (isset($post_data['id3_' . $key])) {
                $id3data[$key] = sanitize_text_field(wp_unslash($post_data['id3_' . $key]));
            }
        }
        wp_update_attachment_metadata($post_ID, $id3data);
    }
    // Meta Stuff
    if (isset($post_data['meta']) && $post_data['meta']) {
        foreach ($post_data['meta'] as $key => $value) {
//.........这里部分代码省略.........
开发者ID:nicholasgriffintn,项目名称:WordPress,代码行数:101,代码来源:post.php


示例4: attachment_id3_data_meta_box

/**
 * Display fields for ID3 data
 *
 * @since 3.9.0
 *
 * @param WP_Post $post
 */
function attachment_id3_data_meta_box($post)
{
    $meta = array();
    if (!empty($post->ID)) {
        $meta = wp_get_attachment_metadata($post->ID);
    }
    foreach (wp_get_attachment_id3_keys($post, 'edit') as $key => $label) {
        ?>
	<p>
		<label for="title"><?php 
        echo $label;
        ?>
</label><br />
		<input type="text" name="id3_<?php 
        echo esc_attr($key);
        ?>
" id="id3_<?php 
        echo esc_attr($key);
        ?>
" class="large-text" value="<?php 
        if (!empty($meta[$key])) {
            echo esc_attr($meta[$key]);
        }
        ?>
" />
	</p>
	<?php 
    }
}
开发者ID:SayenkoDesign,项目名称:ividf,代码行数:36,代码来源:meta-boxes.php


示例5: wp_prepare_attachment_for_js


//.........这里部分代码省略.........
        $bytes = $meta['filesize'];
    } elseif (file_exists($attached_file)) {
        $bytes = filesize($attached_file);
    } else {
        $bytes = '';
    }
    if ($bytes) {
        $response['filesizeInBytes'] = $bytes;
        $response['filesizeHumanReadable'] = size_format($bytes);
    }
    if (current_user_can('edit_post', $attachment->ID)) {
        $response['nonces']['update'] = wp_create_nonce('update-post_' . $attachment->ID);
        $response['nonces']['edit'] = wp_create_nonce('image_editor-' . $attachment->ID);
        $response['editLink'] = get_edit_post_link($attachment->ID, 'raw');
    }
    if (current_user_can('delete_post', $attachment->ID)) {
        $response['nonces']['delete'] = wp_create_nonce('delete-post_' . $attachment->ID);
    }
    if ($meta && 'image' === $type) {
        $sizes = array();
        /** This filter is documented in wp-admin/includes/media.php */
        $possible_sizes = apply_filters('image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')));
        unset($possible_sizes['full']);
        // Loop through all potential sizes that may be chosen. Try to do this with some efficiency.
        // First: run the image_downsize filter. If it returns something, we can use its data.
        // If the filter does not return something, then image_downsize() is just an expensive
        // way to check the image metadata, which we do second.
        foreach ($possible_sizes as $size => $label) {
            /** This filter is documented in wp-includes/media.php */
            if ($downsize = apply_filters('image_downsize', false, $attachment->ID, $size)) {
                if (!$downsize[3]) {
                    continue;
                }
                $sizes[$size] = array('height' => $downsize[2], 'width' => $downsize[1], 'url' => $downsize[0], 'orientation' => $downsize[2] > $downsize[1] ? 'portrait' : 'landscape');
            } elseif (isset($meta['sizes'][$size])) {
                if (!isset($base_url)) {
                    $base_url = str_replace(wp_basename($attachment_url), '', $attachment_url);
                }
                // Nothing from the filter, so consult image metadata if we have it.
                $size_meta = $meta['sizes'][$size];
                // We have the actual image size, but might need to further constrain it if content_width is narrower.
                // Thumbnail, medium, and full sizes are also checked against the site's height/width options.
                list($width, $height) = image_constrain_size_for_editor($size_meta['width'], $size_meta['height'], $size, 'edit');
                $sizes[$size] = array('height' => $height, 'width' => $width, 'url' => $base_url . $size_meta['file'], 'orientation' => $height > $width ? 'portrait' : 'landscape');
            }
        }
        $sizes['full'] = array('url' => $attachment_url);
        if (isset($meta['height'], $meta['width'])) {
            $sizes['full']['height'] = $meta['height'];
            $sizes['full']['width'] = $meta['width'];
            $sizes['full']['orientation'] = $meta['height'] > $meta['width'] ? 'portrait' : 'landscape';
        }
        $response = array_merge($response, array('sizes' => $sizes), $sizes['full']);
    } elseif ($meta && 'video' === $type) {
        if (isset($meta['width'])) {
            $response['width'] = (int) $meta['width'];
        }
        if (isset($meta['height'])) {
            $response['height'] = (int) $meta['height'];
        }
    }
    if ($meta && ('audio' === $type || 'video' === $type)) {
        if (isset($meta['length_formatted'])) {
            $response['fileLength'] = $meta['length_formatted'];
        }
        $response['meta'] = array();
        foreach (wp_get_attachment_id3_keys($attachment, 'js') as $key => $label) {
            $response['meta'][$key] = false;
            if (!empty($meta[$key])) {
                $response['meta'][$key] = $meta[$key];
            }
        }
        $id = get_post_thumbnail_id($attachment->ID);
        if (!empty($id)) {
            list($src, $width, $height) = wp_get_attachment_image_src($id, 'full');
            $response['image'] = compact('src', 'width', 'height');
            list($src, $width, $height) = wp_get_attachment_image_src($id, 'thumbnail');
            $response['thumb'] = compact('src', 'width', 'height');
        } else {
            $src = wp_mime_type_icon($attachment->ID);
            $width = 48;
            $height = 64;
            $response['image'] = compact('src', 'width', 'height');
            $response['thumb'] = compact('src', 'width', 'height');
        }
    }
    if (function_exists('get_compat_media_markup')) {
        $response['compat'] = get_compat_media_markup($attachment->ID, array('in_modal' => true));
    }
    /**
     * Filter the attachment data prepared for JavaScript.
     *
     * @since 3.5.0
     *
     * @param array      $response   Array of prepared attachment data.
     * @param int|object $attachment Attachment ID or object.
     * @param array      $meta       Array of attachment meta data.
     */
    return apply_filters('wp_prepare_attachment_for_js', $response, $attachment, $meta);
}
开发者ID:nakamuraagatha,项目名称:reseptest,代码行数:101,代码来源:media.php


示例6: edit_post

/**
 * Update an existing post with values provided in $_POST.
 *
 * @since 1.5.0
 *
 * @param array $post_data Optional.
 * @return int Post ID.
 */
function edit_post($post_data = null)
{
    global $wpdb;
    if (empty($post_data)) {
        $post_data =& $_POST;
    }
    // Clear out any data in internal vars.
    unset($post_data['filter']);
    $post_ID = (int) $post_data['post_ID'];
    $post = get_post($post_ID);
    $post_data['post_type'] = $post->post_type;
    $post_data['post_mime_type'] = $post->post_mime_type;
    if (!empty($post_data['post_status'])) {
        $post_data['post_status'] = sanitize_key($post_data['post_status']);
        if ('inherit' == $post_data['post_status']) {
            unset($post_data['post_status']);
        }
    }
    $ptype = get_post_type_object($post_data['post_type']);
    if (!current_user_can('edit_post', $post_ID)) {
        if ('page' == $post_data['post_type']) {
            wp_die(__('You are not allowed to edit this page.'));
        } else {
            wp_die(__('You are not allowed to edit this post.'));
        }
    }
    if (post_type_supports($ptype->name, 'revisions')) {
        $revisions = wp_get_post_revisions($post_ID, array('order' => 'ASC', 'posts_per_page' => 1));
        $revision = current($revisions);
        // Check if the revisions have been upgraded
        if ($revisions && _wp_get_post_revision_version($revision) < 1) {
            _wp_upgrade_revisions_of_post($post, wp_get_post_revisions($post_ID));
        }
    }
    if (isset($post_data['visibility'])) {
        switch ($post_data['visibility']) {
            case 'public':
                $post_data['post_password'] = '';
                break;
            case 'password':
                unset($post_data['sticky']);
                break;
            case 'private':
                $post_data['post_status'] = 'private';
                $post_data['post_password'] = '';
                unset($post_data['sticky']);
                break;
        }
    }
    $post_data = _wp_translate_postdata(true, $post_data);
    if (is_wp_error($post_data)) {
        wp_die($post_data->get_error_message());
    }
    // Post Formats
    if (isset($post_data['post_format'])) {
        set_post_format($post_ID, $post_data['post_format']);
    }
    $format_meta_urls = array('url', 'link_url', 'quote_source_url');
    foreach ($format_meta_urls as $format_meta_url) {
        $keyed = '_format_' . $format_meta_url;
        if (isset($post_data[$keyed])) {
            update_post_meta($post_ID, $keyed, wp_slash(esc_url_raw(wp_unslash($post_data[$keyed]))));
        }
    }
    $format_keys = array('quote', 'quote_source_name', 'image', 'gallery', 'audio_embed', 'video_embed');
    foreach ($format_keys as $key) {
        $keyed = '_format_' . $key;
        if (isset($post_data[$keyed])) {
            if (current_user_can('unfiltered_html')) {
                update_post_meta($post_ID, $keyed, $post_data[$keyed]);
            } else {
                update_post_meta($post_ID, $keyed, wp_filter_post_kses($post_data[$keyed]));
            }
        }
    }
    if ('attachment' === $post_data['post_type'] && preg_match('#^(audio|video)/#', $post_data['post_mime_type'])) {
        $id3data = wp_get_attachment_metadata($post_ID);
        if (!is_array($id3data)) {
            $id3data = array();
        }
        foreach (wp_get_attachment_id3_keys($post, 'edit') as $key => $label) {
            if (isset($post_data['id3_' . $key])) {
                $id3data[$key] = sanitize_text_field(wp_unslash($post_data['id3_' . $key]));
            }
        }
        wp_update_attachment_metadata($post_ID, $id3data);
    }
    // Meta Stuff
    if (isset($post_data['meta']) && $post_data['meta']) {
        foreach ($post_data['meta'] as $key => $value) {
            if (!($meta = get_post_meta_by_id($key))) {
                continue;
//.........这里部分代码省略.........
开发者ID:GaryJones,项目名称:dockerfiles,代码行数:101,代码来源:post.php


示例7: wp_playlist_shortcode

    function wp_playlist_shortcode($output, $attr)
    {
        global $content_width;
        $post = get_post();
        static $instance = 0;
        $instance++;
        if (isset($attr['orderby'])) {
            $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
            if (!$attr['orderby']) {
                unset($attr['orderby']);
            }
        }
        extract(shortcode_atts(array('type' => 'audio', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post ? $post->ID : 0, 'include' => '', 'exclude' => '', 'style' => 'light', 'tracklist' => true, 'tracknumbers' => true, 'images' => true, 'artists' => true), $attr, 'playlist'));
        $id = intval($id);
        if ('RAND' == $order) {
            $orderby = 'none';
        }
        $args = array('post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => $type, 'order' => $order, 'orderby' => $orderby);
        if (!empty($include)) {
            $args['include'] = $include;
            $_attachments = get_posts($args);
            $attachments = array();
            foreach ($_attachments as $key => $val) {
                $attachments[$val->ID] = $_attachments[$key];
            }
        } elseif (!empty($exclude)) {
            $args['post_parent'] = $id;
            $args['exclude'] = $exclude;
            $attachments = get_children($args);
        } else {
            $args['post_parent'] = $id;
            $attachments = get_children($args);
        }
        if (empty($attachments)) {
            return '';
        }
        if (is_feed()) {
            $output = "\n";
            foreach ($attachments as $att_id => $attachment) {
                $output .= wp_get_attachment_link($att_id) . "\n";
            }
            return $output;
        }
        $outer = 22;
        $default_width = 640;
        $default_height = 360;
        $theme_width = empty($content_width) ? $default_width : $content_width - $outer;
        $theme_height = empty($content_width) ? $default_height : round($default_height * $theme_width / $default_width);
        $data = compact('type');
        foreach (array('tracklist', 'tracknumbers', 'images', 'artists') as $key) {
            $data[$key] = filter_var(${$key}, FILTER_VALIDATE_BOOLEAN);
        }
        $tracks = array();
        foreach ($attachments as $attachment) {
            $url = wp_get_attachment_url($attachment->ID);
            $ftype = wp_check_filetype($url, wp_get_mime_types());
            $track = array('src' => $url, 'type' => $ftype['type'], 'title' => $attachment->post_title, 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content);
            $track['meta'] = array();
            $meta = wp_get_attachment_metadata($attachment->ID);
            if (!empty($meta)) {
                foreach (wp_get_attachment_id3_keys($attachment) as $key => $label) {
                    if (!empty($meta[$key])) {
                        $track['meta'][$key] = $meta[$key];
                    }
                }
                if ('video' === $type) {
                    if (!empty($meta['width']) && !empty($meta['height'])) {
                        $width = $meta['width'];
                        $height = $meta['height'];
                        $theme_height = round($height * $theme_width / $width);
                    } else {
                        $width = $default_width;
                        $height = $default_height;
                    }
                    $track['dimensions'] = array('original' => compact('width', 'height'), 'resized' => array('width' => $theme_width, 'height' => $theme_height));
                }
            }
            if ($images) {
                $id = get_post_thumbnail_id($attachment->ID);
                if (!empty($id)) {
                    list($src, $width, $height) = wp_get_attachment_image_src($id, 'full');
                    $track['image'] = compact('src', 'width', 'height');
                    list($src, $width, $height) = wp_get_attachment_image_src($id, 'thumbnail');
                    $track['thumb'] = compact('src', 'width', 'height');
                } else {
                    $src = wp_mime_type_icon($attachment->ID);
                    $width = 48;
                    $height = 64;
                    $track['image'] = compact('src', 'width', 'height');
                    $track['thumb'] = compact('src', 'width', 'height');
                }
            }
            $tracks[] = $track;
        }
        $data['tracks'] = $tracks;
        $safe_type = esc_attr($type);
        $safe_style = esc_attr($style);
        $playlist_meta = 'true' == $this->options('playlist_meta') ? "" : " hide-playlist-meta-pro ";
        ob_start();
        if (1 === $instance) {
//.........这里部分代码省略.........
开发者ID:katstar01,项目名称:fivebeers,代码行数:101,代码来源:video-player.php


示例8: video_meta

 /**
  * Adds and formats video meta data for the items array.
  *
  * @since  2.0.0
  * @access public
  * @return void
  */
 public function video_meta()
 {
     /* Get ID3 keys (labels for metadata). */
     $id3_keys = wp_get_attachment_id3_keys(get_post($this->args['post_id']));
     /* Formated length of time the video file runs. */
     if (!empty($this->meta['length_formatted'])) {
         $this->items['length_formatted'] = array($this->meta['length_formatted'], $id3_keys['length_formatted']);
     }
     /* Dimensions (width x height in pixels). */
     if (!empty($this->meta['width']) && !empty($this->meta['height'])) {
         /* Translators: Media dimensions - 1 is width and 2 is height. */
         $this->items['dimensions'] = array(sprintf(__('%1$s &#215; %2$s', 'hybrid-core'), number_format_i18n(absint($this->meta['width'])), number_format_i18n(absint($this->meta['height']))), __('Dimensions', 'hybrid-core'));
     }
     /* File name.  We're linking this to the actual file URL. */
     $this->items['file_name'] = array('<a href="' . esc_url(wp_get_attachment_url($this->args['post_id'])) . '">' . basename(get_attached_file($this->args['post_id'])) . '</a>', __('File Name', 'hybrid-core'));
     /* File size. */
     if (!empty($this->meta['filesize'])) {
         $this->items['filesize'] = array(size_format($this->meta['filesize'], 2), $id3_keys['filesize']);
     }
     /* File type (the metadata for this can be incorrect, so we're just looking at the actual file). */
     if (preg_match('/^.*?\\.(\\w+)$/', get_attached_file($this->args['post_id']), $matches)) {
         $this->items['file_type'] = array(esc_html(strtoupper($matches[1])), __('File Type', 'hybrid-core'));
     }
     /* Mime type. */
     if (!empty($this->meta['mime_type'])) {
         $this->items['mime_type'] = array($this->meta['mime_type'], $id3_keys['mime_type']);
     }
 }
开发者ID:LSYanJun,项目名称:wordpress,代码行数:35,代码来源:hybrid-media-meta.php


示例9: mpp_media_to_json

/**
 * Prepare Media for JSON
 *  this is a copy from send json for attachment, we will improve it in our 1.1 release
 * @todo refactor
 * @param type $attachment
 * @return type
 */
function mpp_media_to_json($attachment)
{
    if (!($attachment = get_post($attachment))) {
        return;
    }
    if ('attachment' != $attachment->post_type) {
        return;
    }
    //the attachment can be either a media or a cover
    //in case of media, if it is non photo, we need the thumb.url to point to the cover(or generated cover)
    //in case of cover, we don't care
    $media = mpp_get_media($attachment->ID);
    $meta = wp_get_attachment_metadata($attachment->ID);
    if (false !== strpos($attachment->post_mime_type, '/')) {
        list($type, $subtype) = explode('/', $attachment->post_mime_type);
    } else {
        list($type, $subtype) = array($attachment->post_mime_type, '');
    }
    $attachment_url = wp_get_attachment_url($attachment->ID);
    $response = array('id' => $media->id, 'title' => $media->title, 'filename' => wp_basename($attachment->guid), 'url' => $attachment_url, 'link' => mpp_get_media_permalink($media), 'alt' => $media->title, 'author' => $media->user_id, 'description' => $media->description, 'caption' => $media->excerpt, 'name' => $media->slug, 'status' => $media->status, 'parent_id' => $media->gallery_id, 'date' => strtotime($attachment->post_date_gmt) * 1000, 'modified' => strtotime($attachment->post_modified_gmt) * 1000, 'menuOrder' => $attachment->menu_order, 'mime' => $attachment->post_mime_type, 'type' => $media->type, 'subtype' => $subtype, 'dateFormatted' => mysql2date(get_option('date_format'), $attachment->post_date), 'meta' => false);
    if ($attachment->post_parent) {
        $post_parent = get_post($attachment->post_parent);
        $parent_type = get_post_type_object($post_parent->post_type);
        if ($parent_type && $parent_type->show_ui && current_user_can('edit_post', $attachment->post_parent)) {
            $response['uploadedToLink'] = get_edit_post_link($attachment->post_parent, 'raw');
        }
        $response['uploadedToTitle'] = $post_parent->post_title ? $post_parent->post_title : __('(no title)');
    }
    $attached_file = get_attached_file($attachment->ID);
    if (file_exists($attached_file)) {
        $bytes = filesize($attached_file);
        $response['filesizeInBytes'] = $bytes;
        $response['filesizeHumanReadable'] = size_format($bytes);
    }
    if ($meta && 'image' === $type) {
        $sizes = array();
        /** This filter is documented in wp-admin/includes/media.php */
        $possible_sizes = apply_filters('image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')));
        unset($possible_sizes['full']);
        // Loop through all potential sizes that may be chosen. Try to do this with some efficiency.
        // First: run the image_downsize filter. If it returns something, we can use its data.
        // If the filter does not return something, then image_downsize() is just an expensive
        // way to check the image metadata, which we do second.
        foreach ($possible_sizes as $size => $label) {
            /** This filter is documented in wp-includes/media.php */
            if ($downsize = apply_filters('image_downsize', false, $attachment->ID, $size)) {
                if (!$downsize[3]) {
                    continue;
                }
                $sizes[$size] = array('height' => $downsize[2], 'width' => $downsize[1], 'url' => $downsize[0], 'orientation' => $downsize[2] > $downsize[1] ? 'portrait' : 'landscape');
            } elseif (isset($meta['sizes'][$size])) {
                if (!isset($base_url)) {
                    $base_url = str_replace(wp_basename($attachment_url), '', $attachment_url);
                }
                // Nothing from the filter, so consult image metadata if we have it.
                $size_meta = $meta['sizes'][$size];
                // We have the actual image size, but might need to further constrain it if content_width is narrower.
                // Thumbnail, medium, and full sizes are also checked against the site's height/width options.
                list($width, $height) = image_constrain_size_for_editor($size_meta['width'], $size_meta['height'], $size, 'edit');
                $sizes[$size] = array('height' => $height, 'width' => $width, 'url' => $base_url . $size_meta['file'], 'orientation' => $height > $width ? 'portrait' : 'landscape');
            }
        }
        $sizes['full'] = array('url' => $attachment_url);
        if (isset($meta['height'], $meta['width'])) {
            $sizes['full']['height'] = $meta['height'];
            $sizes['full']['width'] = $meta['width'];
            $sizes['full']['orientation'] = $meta['height'] > $meta['width'] ? 'portrait' : 'landscape';
        }
        $response = array_merge($response, array('sizes' => $sizes), $sizes['full']);
    } elseif ($meta && 'video' === $type) {
        if (isset($meta['width'])) {
            $response['width'] = (int) $meta['width'];
        }
        if (isset($meta['height'])) {
            $response['height'] = (int) $meta['height'];
        }
    }
    if ($meta && ('audio' === $type || 'video' === $type)) {
        if (isset($meta['length_formatted'])) {
            $response['fileLength'] = $meta['length_formatted'];
        }
        $response['meta'] = array();
        foreach (wp_get_attachment_id3_keys($attachment, 'js') as $key => $label) {
            $response['meta'][$key] = false;
            if (!empty($meta[$key])) {
                $response['meta'][$key] = $meta[$key];
            }
        }
        $id = mpp_get_media_cover_id($attachment->ID);
        if (!empty($id)) {
            list($url, $width, $height) = wp_get_attachment_image_src($id, 'full');
            $response['image'] = compact('url', 'width', 'height');
            list($url, $width, $height) = wp_get_attachment_image_src($id, 'thumbnail');
//.........这里部分代码省略.........
开发者ID:baden03,项目名称:mediapress,代码行数:101,代码来源:functions.php


示例10: wp_playlist_shortcode


//.........这里部分代码省略.........
     static $instance = 0;
     $instance++;
     if (!empty($attr['ids'])) {
         $attr['include'] = $attr['ids'];
         // 'ids' is explicitly ordered, unless you specify otherwise.
         if (empty($attr['orderby'])) {
             $attr['orderby'] = 'post__in';
         }
     }
     $output = apply_filters('post_playlist', '', $attr, $instance);
     if ('' !== $output) {
         return $output;
     }
     unset($output);
     $atts = shortcode_atts(array('type' => 'audio', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => get_the_ID() ?: 0, 'include' => '', 'exclude' => '', 'style' => 'light', 'tracklist' => true, 'tracknumbers' => true, 'images' => true, 'artists' => true), $attr, 'playlist');
     if ('audio' !== $atts['type']) {
         $atts['type'] = 'video';
     }
     $args = array('post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => $atts['type'], 'order' => $atts['order'], 'orderby' => $atts['orderby']);
     if ('' !== $atts['include']) {
         $args['include'] = $atts['include'];
     } else {
         $args['post_parent'] = intval($atts['id']);
         if ('' !== $atts['exclude']) {
             $args['exclude'] = $atts['exclude'];
         }
     }
     if (!($attachments = get_posts($args))) {
         return '';
     }
     if (is_feed()) {
         ob_start();
         echo "\n";
         foreach ($attachments as $a) {
             echo wp_get_attachment_link($a->ID), "\n";
         }
         return ob_get_clean();
     }
     $outer = 22;
     // default padding and border of wrapper
     global $content_width;
     $default_width = 640;
     $default_height = 360;
     $theme_width = empty($content_width) ? $default_width : $content_width - $outer;
     $theme_height = empty($content_width) ? $default_height : round($default_height * $theme_width / $default_width);
     ob_start();
     if (1 === $instance) {
         do_action('wp_playlist_scripts', $atts['type'], $atts['style']);
     }
     echo '<div class="wp-playlist wp-', $atts['type'], '-playlist wp-playlist-', esc_attr($atts['style']), '">';
     if ('audio' === $atts['type']) {
         echo '<div class="wp-playlist-current-item"></div><audio';
     } else {
         echo '<video height="', $theme_height, '"';
     }
     echo ' controls="controls" preload="none" width="', $theme_width, '">', '</', $atts['type'], '>';
     echo '<div class="wp-playlist-next"></div>', '<div class="wp-playlist-prev"></div>', '<noscript>', '<ol>';
     $atts['images'] = wp_validate_boolean($atts['images']);
     $tracks = array();
     foreach ($attachments as $a) {
         // For <noscript>.
         echo '<li>', wp_get_attachment_link($a->ID), '</li>';
         // Remaining is for JSON data.
         $track = array('src' => wp_get_attachment_url($a->ID), 'title' => $a->post_title);
         if ($a->post_excerpt) {
             $track['caption'] = $a->post_excerpt;
         }
         if ($a->post_content) {
             $track['description'] = $a->post_content;
         }
         if ($meta = $this->get_tracks_json_data($track['src'])) {
             $track['webvtt'] = $meta;
         }
         if ($meta = wp_get_attachment_metadata($a->ID)) {
             foreach (wp_get_attachment_id3_keys($a) as $key => $label) {
                 if (!empty($meta[$key])) {
                     $track['meta'][$key] = $meta[$key];
                 }
             }
             if ('video' === $atts['type']) {
                 if (!empty($meta['width']) && !empty($meta['height'])) {
                     $width = $meta['width'];
                     $height = $meta['height'];
                     $theme_height = round($height * $theme_width / $width);
                 } else {
                     $width = $default_width;
                     $height = $default_height;
                 }
                 $track['dimensions'] = array('original' => compact('width', 'height'), 'resized' => array('width' => $theme_width, 'height' => $theme_height));
             }
         }
         if (true === $atts['images'] && ($thumb_id = get_post_thumbnail_id($a->ID))) {
             $track['image'] = wp_get_attachment_image_src($thumb_id, 'full');
             $track['thumb'] = wp_get_attachment_image_src($thumb_id);
         }
         $tracks[] = $track;
     }
     echo '</ol>', '</noscript>', '<script type="application/json" class="wp-playlist-script">', wp_json_encode(array('type' => $atts['type'], 'tracklist' => wp_validate_boolean($atts['tracklist']), 'tracknumbers' => wp_validate_boolean($atts['tracknumbers']), 'images' => $atts['images'], 'artists' => wp_validate_boolean($atts['artists']), 'tracks' => $tracks)), '</script>', '</div>';
     return ob_get_clean();
 }
开发者ID:bobbywalters,项目名称:webvtt,代码行数:101,代码来源:class-webvtt.php



注:本文中的wp_get_attachment_id3_keys函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wp_get_attachment_image函数代码示例发布时间:2022-05-23
下一篇:
PHP wp_get_associated_nav_menu_items函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap