本文整理汇总了PHP中get_post_mime_types函数的典型用法代码示例。如果您正苦于以下问题:PHP get_post_mime_types函数的具体用法?PHP get_post_mime_types怎么用?PHP get_post_mime_types使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_post_mime_types函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pronamic_framework_maybe_save_post
function pronamic_framework_maybe_save_post()
{
if (isset($_POST['pronamic_framework_edit_post_submit'])) {
$post_ID = filter_input(INPUT_POST, 'post_ID', FILTER_SANITIZE_NUMBER_INT);
// Post
$post_title = filter_input(INPUT_POST, 'post_title', FILTER_SANITIZE_STRING);
$post_content = filter_input(INPUT_POST, 'post_content', FILTER_UNSAFE_RAW);
$post_content = wp_kses_post($post_content);
$post = array('ID' => $post_ID, 'post_title' => $post_title, 'post_content' => $post_content);
$result = wp_update_post($post);
if (0 !== $result) {
} else {
}
// Meta
$meta = filter_input(INPUT_POST, 'post_meta', FILTER_SANITIZE_STRING, FILTER_REQUIRE_ARRAY);
foreach ($meta as $key => $value) {
update_post_meta($post_ID, $key, $value);
}
// Attachments
if (isset($_FILES['post_attachments'])) {
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/media.php';
require_once ABSPATH . 'wp-admin/includes/post.php';
$post_mime_types = get_post_mime_types();
foreach ($_FILES['post_attachments']['error'] as $key => $error) {
if (UPLOAD_ERR_OK == $error) {
// no error
$tmp_name = $_FILES['post_attachments']['tmp_name'][$key];
$name = $_FILES['post_attachments']['name'][$key];
$bits = file_get_contents($tmp_name);
$result = wp_upload_bits($name, null, $bits);
if (false === $result['error']) {
// no error
$file_type = wp_check_filetype($result['file']);
$keys = array_keys(wp_match_mime_types(array_keys($post_mime_types), $file_type));
$type = array_shift($keys);
$attachment = array('post_title' => $name, 'post_mime_type' => $file_type['type'], 'guid' => $result['url'], 'post_parent' => $post_ID);
$attachment_id = wp_insert_attachment($attachment, $result['file'], $post_ID);
$meta_data = wp_generate_attachment_metadata($attachment_id, $result['file']);
$updated = wp_update_attachment_metadata($attachment_id, $meta_data);
if ('image' == $type) {
update_post_meta($post_ID, '_thumbnail_id', $attachment_id);
}
}
}
}
}
}
}
示例2: wp_edit_attachments_query
/**
* Executes a query for attachments. An array of WP_Query arguments
* can be passed in, which will override the arguments set by this function.
*
* @since 2.5.0
*
* @param array|bool $q Array of query variables to use to build the query or false to use $_GET superglobal.
* @return array
*/
function wp_edit_attachments_query($q = false)
{
if (false === $q) {
$q = $_GET;
}
$q['m'] = isset($q['m']) ? (int) $q['m'] : 0;
$q['cat'] = isset($q['cat']) ? (int) $q['cat'] : 0;
$q['post_type'] = 'attachment';
$post_type = get_post_type_object('attachment');
$states = 'inherit';
if (current_user_can($post_type->cap->read_private_posts)) {
$states .= ',private';
}
$q['post_status'] = isset($q['status']) && 'trash' == $q['status'] ? 'trash' : $states;
$q['post_status'] = isset($q['attachment-filter']) && 'trash' == $q['attachment-filter'] ? 'trash' : $states;
$media_per_page = (int) get_user_option('upload_per_page');
if (empty($media_per_page) || $media_per_page < 1) {
$media_per_page = 20;
}
/**
* Filter the number of items to list per page when listing media items.
*
* @since 2.9.0
*
* @param int $media_per_page Number of media to list. Default 20.
*/
$q['posts_per_page'] = apply_filters('upload_per_page', $media_per_page);
$post_mime_types = get_post_mime_types();
$avail_post_mime_types = get_available_post_mime_types('attachment');
if (isset($q['post_mime_type']) && !array_intersect((array) $q['post_mime_type'], array_keys($post_mime_types))) {
unset($q['post_mime_type']);
}
foreach (array_keys($post_mime_types) as $type) {
if (isset($q['attachment-filter']) && "post_mime_type:{$type}" == $q['attachment-filter']) {
$q['post_mime_type'] = $type;
break;
}
}
if (isset($q['detached']) || isset($q['attachment-filter']) && 'detached' == $q['attachment-filter']) {
$q['post_parent'] = 0;
}
wp($q);
return array($post_mime_types, $avail_post_mime_types);
}
示例3: wp_enqueue_media
/**
* Enqueues all scripts, styles, settings, and templates necessary to use
* all media JS APIs.
*
* @since 3.5.0
*/
function wp_enqueue_media($args = array())
{
// Enqueue me just once per page, please.
if (did_action('wp_enqueue_media')) {
return;
}
$defaults = array('post' => null);
$args = wp_parse_args($args, $defaults);
// We're going to pass the old thickbox media tabs to `media_upload_tabs`
// to ensure plugins will work. We will then unset those tabs.
$tabs = array('type' => '', 'type_url' => '', 'gallery' => '', 'library' => '');
$tabs = apply_filters('media_upload_tabs', $tabs);
unset($tabs['type'], $tabs['type_url'], $tabs['gallery'], $tabs['library']);
$props = array('link' => get_option('image_default_link_type'), 'align' => get_option('image_default_align'), 'size' => get_option('image_default_size'));
$settings = array('tabs' => $tabs, 'tabUrl' => add_query_arg(array('chromeless' => true), admin_url('media-upload.php')), 'mimeTypes' => wp_list_pluck(get_post_mime_types(), 0), 'captions' => !apply_filters('disable_captions', ''), 'nonce' => array('sendToEditor' => wp_create_nonce('media-send-to-editor')), 'post' => array('id' => 0), 'defaultProps' => $props, 'embedExts' => array_merge(wp_get_audio_extensions(), wp_get_video_extensions()));
$post = null;
if (isset($args['post'])) {
$post = get_post($args['post']);
$settings['post'] = array('id' => $post->ID, 'nonce' => wp_create_nonce('update-post_' . $post->ID));
if (current_theme_supports('post-thumbnails', $post->post_type) && post_type_supports($post->post_type, 'thumbnail')) {
$featured_image_id = get_post_meta($post->ID, '_thumbnail_id', true);
$settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1;
}
}
$hier = $post && is_post_type_hierarchical($post->post_type);
$strings = array('url' => __('URL'), 'addMedia' => __('Add Media'), 'search' => __('Search'), 'select' => __('Select'), 'cancel' => __('Cancel'), 'selected' => __('%d selected'), 'dragInfo' => __('Drag and drop to reorder images.'), 'uploadFilesTitle' => __('Upload Files'), 'uploadImagesTitle' => __('Upload Images'), 'mediaLibraryTitle' => __('Media Library'), 'insertMediaTitle' => __('Insert Media'), 'createNewGallery' => __('Create a new gallery'), 'returnToLibrary' => __('← Return to library'), 'allMediaItems' => __('All media items'), 'noItemsFound' => __('No items found.'), 'insertIntoPost' => $hier ? __('Insert into page') : __('Insert into post'), 'uploadedToThisPost' => $hier ? __('Uploaded to this page') : __('Uploaded to this post'), 'warnDelete' => __("You are about to permanently delete this item.\n 'Cancel' to stop, 'OK' to delete."), 'insertFromUrlTitle' => __('Insert from URL'), 'setFeaturedImageTitle' => __('Set Featured Image'), 'setFeaturedImage' => __('Set featured image'), 'createGalleryTitle' => __('Create Gallery'), 'editGalleryTitle' => __('Edit Gallery'), 'cancelGalleryTitle' => __('← Cancel Gallery'), 'insertGallery' => __('Insert gallery'), 'updateGallery' => __('Update gallery'), 'addToGallery' => __('Add to gallery'), 'addToGalleryTitle' => __('Add to Gallery'), 'reverseOrder' => __('Reverse order'));
$settings = apply_filters('media_view_settings', $settings, $post);
$strings = apply_filters('media_view_strings', $strings, $post);
$strings['settings'] = $settings;
wp_localize_script('media-views', '_wpMediaViewsL10n', $strings);
wp_enqueue_script('media-editor');
wp_enqueue_style('media-views');
wp_plupload_default_settings();
require_once ABSPATH . WPINC . '/media-template.php';
add_action('admin_footer', 'wp_print_media_templates');
add_action('wp_footer', 'wp_print_media_templates');
add_action('customize_controls_print_footer_scripts', 'wp_print_media_templates');
do_action('wp_enqueue_media');
}
示例4: _get_post_mime_templates
/**
* Assemble the in-memory representation of the Post MIME Types
*
* @since 1.40
*
* @param boolean Force a reload/recalculation of types
*
* @return boolean Success (true) or failure (false) of the operation
*/
private static function _get_post_mime_templates($force_refresh = false)
{
if (false == $force_refresh && NULL != self::$mla_post_mime_templates) {
return true;
}
/*
* Start with MLA standard types
*/
$mla_types = MLAOptions::mla_get_option(MLAOptions::MLA_POST_MIME_TYPES, true);
if (!is_array($mla_types)) {
$mla_types = array();
}
/*
* If this is the first time MLA Post MIME support is invoked, match to the
* filter-enhanced extensions, retain anything new as a custom type.
* Otherwise, add the current MLA custom types.
*/
$custom_types = MLAOptions::mla_get_option(MLAOptions::MLA_POST_MIME_TYPES, false, true);
if (is_array($custom_types)) {
$mla_types = array_merge($mla_types, $custom_types);
} else {
/*
* Add existing types that are not already in the MLA list
*/
self::$disable_mla_filtering = true;
$post_mime_types = get_post_mime_types();
self::$disable_mla_filtering = false;
foreach ($post_mime_types as $slug => $value) {
if (!isset($mla_types[$slug])) {
$mla_types[$slug] = array('singular' => substr($value[2][0], 0, strpos($value[2][0], ' <')), 'plural' => $value[0], 'specification' => '', 'post_mime_type' => true, 'table_view' => true, 'menu_order' => 0, 'description' => _x('Copied from previous filter/plugin', 'post_mime_types_description', 'media-library-assistant'));
}
}
// new type
}
// First time called
self::$mla_post_mime_templates = array();
self::$mla_post_mime_highest_ID = 0;
/*
* Load and number the entries
*/
foreach ($mla_types as $slug => $value) {
self::$mla_post_mime_templates[$slug] = $value;
self::$mla_post_mime_templates[$slug]['post_ID'] = ++self::$mla_post_mime_highest_ID;
}
self::_put_post_mime_templates();
return true;
}
示例5: _kc_field_file_single
/**
* Field: single file
*/
function _kc_field_file_single($args)
{
extract($args, EXTR_OVERWRITE);
$size = isset($field['size']) ? $field['size'] : 'thumbnail';
# Handle migration from multiple mode
if (is_array($db_value)) {
if (!empty($db_value['selected'])) {
$db_value = $db_value['selected'][0];
} elseif (!empty($db_value['files'])) {
$db_value = $db_value['files'][0];
} else {
$db_value = '';
}
}
if (get_post_type(absint($db_value)) === 'attachment' && ($attachment = get_post(absint($db_value)))) {
$post_mime_types = get_post_mime_types();
$keys = array_keys(wp_match_mime_types(array_keys($post_mime_types), $attachment->post_mime_type));
$type = esc_attr(array_shift($keys));
$valid = true;
$title = $attachment->post_title;
} else {
$type = 'default';
$valid = false;
$title = '';
$db_value = '';
}
$out = "<div id='{$id}' class='kcs-file-single' data-type='{$type}' data-size='{$size}' data-mime-type='{$field['mime_type']}'>\n";
$out .= "\t<p class='current";
if (!$valid) {
$out .= ' hidden';
}
$out .= "'>\n";
$out .= "<a href='" . esc_url($up_url) . "' title='" . __('Change file', 'kc-settings') . "' class='up'><img src='" . kc_get_attachment_icon_src($db_value, $size) . "' alt=''";
if (!empty($field['size']) && is_numeric($field['size'])) {
$out .= " style='width:{$field['size']}px'";
}
$out .= ' /></a>';
$out .= "<span>{$title}</span>";
$out .= '<br /><a href="#" class="rm">' . __('Remove', 'kc-settings') . '</a>';
$out .= "\t</p>\n";
$out .= "\t<a href='" . esc_url($up_url) . "' class='up";
if ($valid) {
$out .= ' hidden';
}
$out .= "'>" . __('Select file', 'kc-settings') . '</a>';
$out .= "\t<input type='hidden' name='{$name}' value='{$db_value}' />\n";
$out .= "</div>\n";
return $out;
}
示例6: wpmf_admin_head
function wpmf_admin_head()
{
$post_mime_types = get_post_mime_types();
$allowed_mimes = get_allowed_mime_types();
foreach (wp_get_mime_types() as $type => $mime) {
$wpuxss_eml_mimes[$type] = array('mime' => $mime, 'singular' => $mime, 'plural' => $mime, 'filter' => 0, 'upload' => isset($allowed_mimes[$type]) ? 1 : 0);
}
$useorder = get_option('wpmf_useorder');
if (!$useorder || $useorder == 0 || $useorder == '') {
unset($_SESSION['wpmfview']);
}
global $pagenow, $current_user;
$taxo = $this->get_taxonomy();
$attachment_terms = array();
$terms = get_categories(array('hide_empty' => false, 'taxonomy' => $taxo));
$terms = $this->generatePageTree($terms);
$terms = $this->parent_sort($terms);
$attachment_terms_order = array();
$wpmf_active_media = get_option('wpmf_active_media');
$user_roles = $current_user->roles;
if ($user_roles[0] == 'administrator' || $wpmf_active_media == 0) {
$attachment_terms[] = array('id' => 0, 'label' => __('No') . ' Categories', 'slug' => '', 'parent_id' => 0);
$attachment_terms_order[] = '0';
} else {
$wpmfterm = $this->wpmf_term_root();
$term_rootId = $wpmfterm['term_rootId'];
if (!$term_rootId) {
$attachment_terms[] = array('id' => 0, 'label' => __('No') . ' Categories', 'slug' => '', 'parent_id' => 0);
$attachment_terms_order[] = '0';
}
}
foreach ($terms as $term) {
if (isset($wpmf_active_media) && $wpmf_active_media == 1 && $user_roles[0] != 'administrator') {
if ($term->term_group == get_current_user_id()) {
$wpmfterm = $this->wpmf_term_root();
$term_rootId = $wpmfterm['term_rootId'];
if ($term_rootId) {
if ($term->name == $current_user->user_login || $term->category_parent != 0) {
$attachment_terms[$term->term_id] = array('id' => $term->term_id, 'label' => $term->name, 'slug' => $term->slug, 'parent_id' => $term->category_parent, 'depth' => $term->depth, 'term_group' => $term->term_group);
$attachment_terms_order[] = $term->term_id;
}
} else {
$attachment_terms[$term->term_id] = array('id' => $term->term_id, 'label' => $term->name, 'slug' => $term->slug, 'parent_id' => $term->category_parent, 'depth' => $term->depth, 'term_group' => $term->term_group);
$attachment_terms_order[] = $term->term_id;
}
}
} else {
$attachment_terms[$term->term_id] = array('id' => $term->term_id, 'label' => $term->name, 'slug' => $term->slug, 'parent_id' => $term->category_parent, 'depth' => $term->depth, 'term_group' => $term->term_group);
$attachment_terms_order[] = $term->term_id;
}
}
$wcat = isset($_GET['wcat']) ? $_GET['wcat'] : '0';
$parents = array();
$pCat = (int) $wcat;
while ($pCat != 0) {
$parents[] = $pCat;
$pCat = (int) $attachment_terms[$pCat]['parent_id'];
}
$parents_array = json_encode(array_reverse($parents));
$usegellery = get_option('wpmf_usegellery');
$get_plugin_enhanced_media = strpos(json_encode(get_option('active_plugins')), 'enhanced-media-library.php');
$usegellery = get_option('wpmf_usegellery');
?>
<script type="text/javascript">
wpmf_categories = <?php
echo json_encode($attachment_terms);
?>
;
wpmf_categories_order = <?php
echo json_encode($attachment_terms_order);
?>
;
wpmf_images_path = '<?php
echo plugins_url('assets/images', dirname(__FILE__));
?>
';
taxo = '<?php
echo $taxo;
?>
';
var parents_array = <?php
echo $parents_array;
?>
;
var wpmf_pagenow = '<?php
echo $pagenow;
?>
';
var usegellery = '<?php
echo $usegellery;
?>
';
var enhanced_media_plugin = '<?php
echo $get_plugin_enhanced_media;
?>
';
var wpmf_role = '<?php
echo $user_roles[0];
?>
';
//.........这里部分代码省略.........
示例7: get_media_item
/**
* Retrieve HTML form for modifying the image attachment.
*
* @since unknown
*
* @param int $attachment_id Attachment ID for modification.
* @param string|array $args Optional. Override defaults.
* @return string HTML form for attachment.
*/
function get_media_item( $attachment_id, $args = null ) {
global $redir_tab;
if ( ( $attachment_id = intval( $attachment_id ) ) && $thumb_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail', true ) )
$thumb_url = $thumb_url[0];
else
$thumb_url = false;
$post = get_post( $attachment_id );
$default_args = array( 'errors' => null, 'send' => post_type_supports(get_post_type($post->post_parent), 'editor'), 'delete' => true, 'toggle' => true, 'show_title' => true );
$args = wp_parse_args( $args, $default_args );
extract( $args, EXTR_SKIP );
$toggle_on = __( 'Show' );
$toggle_off = __( 'Hide' );
$filename = basename( $post->guid );
$title = esc_attr( $post->post_title );
if ( $_tags = get_the_tags( $attachment_id ) ) {
foreach ( $_tags as $tag )
$tags[] = $tag->name;
$tags = esc_attr( join( ', ', $tags ) );
}
$post_mime_types = get_post_mime_types();
$keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) );
$type = array_shift( $keys );
$type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />";
$form_fields = get_attachment_fields_to_edit( $post, $errors );
if ( $toggle ) {
$class = empty( $errors ) ? 'startclosed' : 'startopen';
$toggle_links = "
<a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
<a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
} else {
$class = 'form-table';
$toggle_links = '';
}
$display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
$display_title = $show_title ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60 ) . "</span></div>" : '';
$gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) );
$order = '';
foreach ( $form_fields as $key => $val ) {
if ( 'menu_order' == $key ) {
if ( $gallery )
$order = "<div class='menu_order'> <input class='menu_order_input' type='text' id='attachments[$attachment_id][menu_order]' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ). "' /></div>";
else
$order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />";
unset( $form_fields['menu_order'] );
break;
}
}
$media_dims = '';
$meta = wp_get_attachment_metadata( $post->ID );
if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
$media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> ";
$media_dims = apply_filters( 'media_meta', $media_dims, $post );
$image_edit_button = '';
if ( gd_edit_image_support( $post->post_mime_type ) ) {
$nonce = wp_create_nonce( "image_editor-$post->ID" );
$image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <img src='" . esc_url( admin_url( 'images/wpspin_light.gif' ) ) . "' class='imgedit-wait-spin' alt='' />";
}
$attachment_url = get_permalink( $attachment_id );
$item = "
$type_html
$toggle_links
$order
$display_title
<table class='slidetoggle describe $class'>
<thead class='media-item-info' id='media-head-$post->ID'>
<tr valign='top'>
<td class='A1B1' id='thumbnail-head-$post->ID'>
<p><a href='$attachment_url' target='_blank'><img class='thumbnail' src='$thumb_url' alt='' style='margin-top: 3px' /></a></p>
<p>$image_edit_button</p>
</td>
<td>
<p><strong>" . __('File name:') . "</strong> $filename</p>
<p><strong>" . __('File type:') . "</strong> $post->post_mime_type</p>
<p><strong>" . __('Upload date:') . "</strong> " . mysql2date( get_option('date_format'), $post->post_date ). '</p>';
//.........这里部分代码省略.........
示例8: wp_edit_attachments_query
/**
* Executes a query for attachments. An array of WP_Query arguments
* can be passed in, which will override the arguments set by this function.
*
* @since 2.5.0
* @uses apply_filters() Calls 'upload_per_page' on posts_per_page argument
*
* @param array|bool $q Array of query variables to use to build the query or false to use $_GET superglobal.
* @return array
*/
function wp_edit_attachments_query($q = false)
{
if (false === $q) {
$q = $_GET;
}
$q['m'] = isset($q['m']) ? (int) $q['m'] : 0;
$q['cat'] = isset($q['cat']) ? (int) $q['cat'] : 0;
$q['post_type'] = 'attachment';
$post_type = get_post_type_object('attachment');
$states = 'inherit';
if (current_user_can($post_type->cap->read_private_posts)) {
$states .= ',private';
}
$q['post_status'] = isset($q['status']) && 'trash' == $q['status'] ? 'trash' : $states;
$media_per_page = (int) get_user_option('upload_per_page');
if (empty($media_per_page) || $media_per_page < 1) {
$media_per_page = 20;
}
$q['posts_per_page'] = apply_filters('upload_per_page', $media_per_page);
$post_mime_types = get_post_mime_types();
$avail_post_mime_types = get_available_post_mime_types('attachment');
if (isset($q['post_mime_type']) && !array_intersect((array) $q['post_mime_type'], array_keys($post_mime_types))) {
unset($q['post_mime_type']);
}
if (isset($q['detached'])) {
add_filter('posts_where', '_edit_attachments_query_helper');
}
wp($q);
if (isset($q['detached'])) {
remove_filter('posts_where', '_edit_attachments_query_helper');
}
return array($post_mime_types, $avail_post_mime_types);
}
示例9: _get_view
/**
* Returns HTML markup for one view that can be used with this table
*
* @since 1.40
*
* @param string View slug, key to MLA_POST_MIME_TYPES array
* @param string Slug for current view
*
* @return string | false HTML for link to display the view, false if count = zero
*/
function _get_view($view_slug, $current_view)
{
global $wpdb;
static $mla_types = NULL, $posts_per_type, $post_mime_types, $avail_post_mime_types, $matches, $num_posts;
/*
* Calculate the common values once per page load
*/
if (is_null($mla_types)) {
$query_types = MLAMime::mla_query_view_items(array('orderby' => 'menu_order'), 0, 0);
if (!is_array($query_types)) {
$query_types = array();
}
$mla_types = array();
foreach ($query_types as $value) {
$mla_types[$value->slug] = $value;
}
$posts_per_type = (array) wp_count_attachments();
$post_mime_types = get_post_mime_types();
$avail_post_mime_types = $this->_avail_mime_types($posts_per_type);
$matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($posts_per_type));
foreach ($matches as $type => $reals) {
foreach ($reals as $real) {
$num_posts[$type] = isset($num_posts[$type]) ? $num_posts[$type] + $posts_per_type[$real] : $posts_per_type[$real];
}
}
}
$class = $view_slug == $current_view ? ' class="current"' : '';
$base_url = 'upload.php?page=' . MLA::ADMIN_PAGE_SLUG;
/*
* Handle the special cases: all, unattached and trash
*/
switch ($view_slug) {
case 'all':
$total_items = array_sum($posts_per_type) - $posts_per_type['trash'];
return "<a href='{$base_url}'{$class}>" . sprintf(_nx('All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_items, 'uploaded files'), number_format_i18n($total_items)) . '</a>';
case 'unattached':
$total_items = $wpdb->get_var("\r\n\t\t\t\t\t\tSELECT COUNT( * ) FROM {$wpdb->posts}\r\n\t\t\t\t\t\tWHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1\r\n\t\t\t\t\t\t");
if ($total_items) {
return '<a href="' . add_query_arg(array('detached' => '1'), $base_url) . '"' . $class . '>' . sprintf(_nx('Unattached <span class="count">(%s)</span>', 'Unattached <span class="count">(%s)</span>', $total_items, 'detached files'), number_format_i18n($total_items)) . '</a>';
} else {
return false;
}
case 'trash':
if ($posts_per_type['trash']) {
return '<a href="' . add_query_arg(array('status' => 'trash'), $base_url) . '"' . $class . '>' . sprintf(_nx('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', $posts_per_type['trash'], 'uploaded files'), number_format_i18n($posts_per_type['trash'])) . '</a>';
} else {
return false;
}
}
// switch special cases
/*
* Make sure the slug is in our list
*/
if (array_key_exists($view_slug, $mla_types)) {
$mla_type = $mla_types[$view_slug];
} else {
return false;
}
/*
* Handle post_mime_types
*/
if ($mla_type->post_mime_type) {
if (!empty($num_posts[$view_slug])) {
return "<a href='" . add_query_arg(array('post_mime_type' => $view_slug), $base_url) . "'{$class}>" . sprintf(translate_nooped_plural($post_mime_types[$view_slug][2], $num_posts[$view_slug]), number_format_i18n($num_posts[$view_slug])) . '</a>';
} else {
return false;
}
}
/*
* Handle extended specification types
*/
if (empty($mla_type->specification)) {
$query = array('post_mime_type' => $view_slug);
} else {
$query = MLAMime::mla_prepare_view_query($view_slug, $mla_type->specification);
}
$total_items = MLAData::mla_count_list_table_items($query);
if ($total_items) {
$singular = sprintf('%s <span class="count">(%%s)</span>', $mla_type->singular);
$plural = sprintf('%s <span class="count">(%%s)</span>', $mla_type->plural);
$nooped_plural = _n_noop($singular, $plural);
if (isset($query['post_mime_type'])) {
$query['post_mime_type'] = urlencode($query['post_mime_type']);
} else {
$query['meta_query'] = urlencode(serialize($query['meta_query']));
}
return "<a href='" . add_query_arg($query, $base_url) . "'{$class}>" . sprintf(translate_nooped_plural($nooped_plural, $total_items), number_format_i18n($total_items)) . '</a>';
}
return false;
}
示例10: _media_view_settings
public function _media_view_settings($settings = array(), $post = null)
{
$media_filter = clearbase_get_value('media_filter', '', clearbase_get_folder_settings($cb_post_id));
if (!empty($media_filter)) {
$post_mime_types = get_post_mime_types();
$matches = wp_match_mime_types($media_filter, array_keys($post_mime_types));
$settings['mimeTypes'] = wp_list_pluck(array_intersect_key($post_mime_types, $matches), 0);
global $wpdb, $wp_locale;
$post_parent = absint($post->ID);
$and_where_mime = wp_post_mime_type_where($media_filter);
$months = $wpdb->get_results("\n SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month\n FROM {$wpdb->posts}\n WHERE post_parent = {$post_parent} AND post_type = 'attachment' {$and_where_mime}\n ORDER BY post_date DESC");
foreach ($months as $month_year) {
$month_year->text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($month_year->month), $month_year->year);
}
$settings['months'] = $months;
}
return $settings;
}
示例11: edit_form_image_editor
/**
* Displays the image and editor in the post editor
*
* @since 3.5.0
*/
function edit_form_image_editor()
{
$post = get_post();
$thumb_url = false;
if ($attachment_id = intval($post->ID)) {
$thumb_url = wp_get_attachment_image_src($attachment_id, array(900, 600), true);
}
$filename = esc_html(basename($post->guid));
$title = esc_attr($post->post_title);
$post_mime_types = get_post_mime_types();
$keys = array_keys(wp_match_mime_types(array_keys($post_mime_types), $post->post_mime_type));
$type = array_shift($keys);
$type_html = "<input type='hidden' id='type-of-{$attachment_id}' value='" . esc_attr($type) . "' />";
$media_dims = '';
$meta = wp_get_attachment_metadata($post->ID);
if (is_array($meta) && array_key_exists('width', $meta) && array_key_exists('height', $meta)) {
$media_dims .= "<span id='media-dims-{$post->ID}'>{$meta['width']} × {$meta['height']}</span> ";
}
$media_dims = apply_filters('media_meta', $media_dims, $post);
$att_url = wp_get_attachment_url($post->ID);
$image_edit_button = '';
if (gd_edit_image_support($post->post_mime_type)) {
$nonce = wp_create_nonce("image_editor-{$post->ID}");
$image_edit_button = "<input type='button' id='imgedit-open-btn-{$post->ID}' onclick='imageEdit.open( {$post->ID}, \"{$nonce}\" )' class='button' value='" . esc_attr__('Edit Image') . "' /> <span class='spinner'></span>";
}
?>
<div class="wp_attachment_holder">
<div class="imgedit-response" id="imgedit-response-<?php
echo $attachment_id;
?>
"></div>
<div class="wp_attachment_image" id="media-head-<?php
echo $attachment_id;
?>
">
<p><img class="thumbnail" src="<?php
echo set_url_scheme($thumb_url[0]);
?>
" style="max-width:100%" width="<?php
echo $thumb_url[1];
?>
" alt="" /></p>
<p><?php
echo $image_edit_button;
?>
</p>
</div>
<div style="display:none" class="image-editor" id="image-editor-<?php
echo $attachment_id;
?>
"></div>
<div class="wp_attachment_details">
<p>
<label for="attachment_url"><strong><?php
_e('File URL');
?>
</strong></label><br />
<input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" value="<?php
echo esc_attr($att_url);
?>
" /><br />
</p>
<p><strong><?php
_e('File name:');
?>
</strong> <?php
echo $filename;
?>
<br />
<strong><?php
_e('File type:');
?>
</strong> <?php
echo $post->post_mime_type;
?>
<?php
if ($media_dims) {
echo '<br /><strong>' . __('Dimensions:') . '</strong> ' . $media_dims;
}
?>
</p>
</div>
</div>
<?php
}
示例12: wp_enqueue_media
/**
* Enqueues all scripts, styles, settings, and templates necessary to use
* all media JS APIs.
*
* @since 3.5.0
*/
function wp_enqueue_media($args = array())
{
$defaults = array('post' => null);
$args = wp_parse_args($args, $defaults);
// We're going to pass the old thickbox media tabs to `media_upload_tabs`
// to ensure plugins will work. We will then unset those tabs.
$tabs = array('type' => '', 'type_url' => '', 'gallery' => '', 'library' => '');
$tabs = apply_filters('media_upload_tabs', $tabs);
unset($tabs['type'], $tabs['type_url'], $tabs['gallery'], $tabs['library']);
$settings = array('tabs' => $tabs, 'tabUrl' => add_query_arg(array('chromeless' => true), admin_url('media-upload.php')), 'mimeTypes' => wp_list_pluck(get_post_mime_types(), 0), 'captions' => !apply_filters('disable_captions', ''), 'nonce' => array('sendToEditor' => wp_create_nonce('media-send-to-editor')), 'postId' => 0);
$post = null;
if (isset($args['post'])) {
$post = get_post($args['post']);
$settings['postId'] = $post->ID;
}
$hier = $post && is_post_type_hierarchical($post->post_type);
$strings = array('url' => __('URL'), 'addMedia' => __('Add Media'), 'search' => __('Search'), 'select' => __('Select'), 'cancel' => __('Cancel'), 'addImages' => __('Add images'), 'selected' => __('selected'), 'dragInfo' => __('Drag and drop to reorder images.'), 'uploadFilesTitle' => __('Upload Files'), 'selectFiles' => __('Select files'), 'uploadImagesTitle' => __('Upload Images'), 'uploadMoreFiles' => __('Upload more files'), 'mediaLibraryTitle' => __('Media Library'), 'createNewGallery' => __('Create a new gallery'), 'returnToLibrary' => __('← Return to library'), 'allMediaItems' => __('All media items'), 'insertIntoPost' => $hier ? __('Insert into page') : __('Insert into post'), 'uploadedToThisPost' => $hier ? __('Uploaded to this page') : __('Uploaded to this post'), 'warnDelete' => __("You are about to permanently delete this item.\n 'Cancel' to stop, 'OK' to delete."), 'fromUrlTitle' => __('From URL'), 'createGalleryTitle' => __('Create Gallery'), 'editGalleryTitle' => __('Edit Gallery'), 'cancelGalleryTitle' => __('← Cancel Gallery'), 'insertGallery' => __('Insert gallery'), 'updateGallery' => __('Update gallery'), 'continueEditing' => __('Continue editing'), 'addToGallery' => __('Add to gallery'));
$settings = apply_filters('media_view_settings', $settings, $post);
$strings = apply_filters('media_view_strings', $strings, $post);
$strings['settings'] = $settings;
wp_localize_script('media-views', '_wpMediaViewsL10n', $strings);
wp_enqueue_script('media-editor');
wp_enqueue_style('media-views');
wp_plupload_default_settings();
add_action('admin_footer', 'wp_print_media_templates');
add_action('wp_footer', 'wp_print_media_templates');
}
示例13: wp_enqueue_media
/**
* Enqueues all scripts, styles, settings, and templates necessary to use
* all media JS APIs.
*
* @since 3.5.0
*/
function wp_enqueue_media($args = array())
{
// Enqueue me just once per page, please.
if (did_action('wp_enqueue_media')) {
return;
}
global $content_width;
$defaults = array('post' => null);
$args = wp_parse_args($args, $defaults);
// We're going to pass the old thickbox media tabs to `media_upload_tabs`
// to ensure plugins will work. We will then unset those tabs.
$tabs = array('type' => '', 'type_url' => '', 'gallery' => '', 'library' => '');
/** This filter is documented in wp-admin/includes/media.php */
$tabs = apply_filters('media_upload_tabs', $tabs);
unset($tabs['type'], $tabs['type_url'], $tabs['gallery'], $tabs['library']);
$props = array('link' => get_option('image_default_link_type'), 'align' => get_option('image_default_align'), 'size' => get_option('image_default_size'));
$exts = array_merge(wp_get_audio_extensions(), wp_get_video_extensions());
$mimes = get_allowed_mime_types();
$ext_mimes = array();
foreach ($exts as $ext) {
foreach ($mimes as $ext_preg => $mime_match) {
if (preg_match('#' . $ext . '#i', $ext_preg)) {
$ext_mimes[$ext] = $mime_match;
break;
}
}
}
$audio = $video = 0;
$counts = (array) wp_count_attachments();
foreach ($counts as $mime => $total) {
if (0 === strpos($mime, 'audio/')) {
$audio += (int) $total;
} elseif (0 === strpos($mime, 'video/')) {
$video += (int) $total;
}
}
$settings = array('tabs' => $tabs, 'tabUrl' => add_query_arg(array('chromeless' => true), admin_url('media-upload.php')), 'mimeTypes' => wp_list_pluck(get_post_mime_types(), 0), 'captions' => !apply_filters('disable_captions', ''), 'nonce' => array('sendToEditor' => wp_create_nonce('media-send-to-editor')), 'post' => array('id' => 0), 'defaultProps' => $props, 'attachmentCounts' => array('audio' => $audio, 'video' => $video), 'embedExts' => $exts, 'embedMimes' => $ext_mimes, 'contentWidth' => $content_width);
$post = null;
if (isset($args['post'])) {
$post = get_post($args['post']);
$settings['post'] = array('id' => $post->ID, 'nonce' => wp_create_nonce('update-post_' . $post->ID));
$thumbnail_support = current_theme_supports('post-thumbnails', $post->post_type) && post_type_supports($post->post_type, 'thumbnail');
if (!$thumbnail_support && 'attachment' === $post->post_type && $post->post_mime_type) {
if (0 === strpos($post->post_mime_type, 'audio/')) {
$thumbnail_support = post_type_supports('attachment:audio', 'thumbnail') || current_theme_supports('post-thumbnails', 'attachment:audio');
} elseif (0 === strpos($post->post_mime_type, 'video/')) {
$thumbnail_support = post_type_supports('attachment:video', 'thumbnail') || current_theme_supports('post-thumbnails', 'attachment:video');
}
}
if ($thumbnail_support) {
$featured_image_id = get_post_meta($post->ID, '_thumbnail_id', true);
$settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1;
}
}
$hier = $post && is_post_type_hierarchical($post->post_type);
$strings = array('url' => __('URL'), 'addMedia' => __('Add Media'), 'search' => __('Search'), 'select' => __('Select'), 'cancel' => __('Cancel'), 'update' => __('Update'), 'replace' => __('Replace'), 'remove' => __('Remove'), 'back' => __('Back'), 'selected' => __('%d selected'), 'dragInfo' => __('Drag and drop to reorder images.'), 'uploadFilesTitle' => __('Upload Files'), 'uploadImagesTitle' => __('Upload Images'), 'mediaLibraryTitle' => __('Media Library'), 'insertMediaTitle' => __('Insert Media'), 'createNewGallery' => __('Create a new gallery'), 'createNewPlaylist' => __('Create a new playlist'), 'createNewVideoPlaylist' => __('Create a new video playlist'), 'returnToLibrary' => __('← Return to library'), 'allMediaItems' => __('All media items'), 'noItemsFound' => __('No items found.'), 'insertIntoPost' => $hier ? __('Insert into page') : __('Insert into post'), 'uploadedToThisPost' => $hier ? __('Uploaded to this page') : __('Uploaded to this post'), 'warnDelete' => __("You are about to permanently delete this item.\n 'Cancel' to stop, 'OK' to delete."), 'insertFromUrlTitle' => __('Insert from URL'), 'setFeaturedImageTitle' => __('Set Featured Image'), 'setFeaturedImage' => __('Set featured image'), 'createGalleryTitle' => __('Create Gallery'), 'editGalleryTitle' => __('Edit Gallery'), 'cancelGalleryTitle' => __('← Cancel Gallery'), 'insertGallery' => __('Insert gallery'), 'updateGallery' => __('Update gallery'), 'addToGallery' => __('Add to gallery'), 'addToGalleryTitle' => __('Add to Gallery'), 'reverseOrder' => __('Reverse order'), 'imageDetailsTitle' => __('Image Details'), 'imageReplaceTitle' => __('Replace Image'), 'imageDetailsCancel' => __('Cancel Edit'), 'editImage' => __('Edit Image'), 'chooseImage' => __('Choose Image'), 'selectAndCrop' => __('Select and Crop'), 'skipCropping' => __('Skip Cropping'), 'cropImage' => __('Crop Image'), 'cropYourImage' => __('Crop your image'), 'cropping' => __('Cropping…'), 'suggestedDimensions' => __('Suggested image dimensions:'), 'cropError' => __('There has been an error cropping your image.'), 'audioDetailsTitle' => __('Audio Details'), 'audioReplaceTitle' => __('Replace Audio'), 'audioAddSourceTitle' => __('Add Audio Source'), 'audioDetailsCancel' => __('Cancel Edit'), 'videoDetailsTitle' => __('Video Details'), 'videoReplaceTitle' => __('Replace Video'), 'videoAddSourceTitle' => __('Add Video Source'), 'videoDetailsCancel' => __('Cancel Edit'), 'videoSelectPosterImageTitle' => _('Select Poster Image'), 'videoAddTrackTitle' => __('Add Subtitles'), 'playlistDragInfo' => __('Drag and drop to reorder tracks.'), 'createPlaylistTitle' => __('Create Audio Playlist'), 'editPlaylistTitle' => __('Edit Audio Playlist'), 'cancelPlaylistTitle' => __('← Cancel Audio Playlist'), 'insertPlaylist' => __('Insert audio playlist'), 'updatePlaylist' => __('Update audio playlist'), 'addToPlaylist' => __('Add to audio playlist'), 'addToPlaylistTitle' => __('Add to Audio Playlist'), 'videoPlaylistDragInfo' => __('Drag and drop to reorder videos.'), 'createVideoPlaylistTitle' => __('Create Video Playlist'), 'editVideoPlaylistTitle' => __('Edit Video Playlist'), 'cancelVideoPlaylistTitle' => __('← Cancel Video Playlist'), 'insertVideoPlaylist' => __('Insert video playlist'), 'updateVideoPlaylist' => __('Update video playlist'), 'addToVideoPlaylist' => __('Add to video playlist'), 'addToVideoPlaylistTitle' => __('Add to Video Playlist'));
/**
* Filter the media view settings.
*
* @since 3.5.0
*
* @param array $settings List of media view settings.
* @param WP_Post $post Post object.
*/
$settings = apply_filters('media_view_settings', $settings, $post);
/**
* Filter the media view strings.
*
* @since 3.5.0
*
* @param array $strings List of media view strings.
* @param WP_Post $post Post object.
*/
$strings = apply_filters('media_view_strings', $strings, $post);
$strings['settings'] = $settings;
wp_localize_script('media-views', '_wpMediaViewsL10n', $strings);
wp_enqueue_script('media-editor');
wp_enqueue_script('media-audiovideo');
wp_enqueue_style('media-views');
if (is_admin()) {
wp_enqueue_script('mce-view');
wp_enqueue_script('image-edit');
}
wp_enqueue_style('imgareaselect');
wp_plupload_default_settings();
require_once ABSPATH . WPINC . '/media-template.php';
add_action('admin_footer', 'wp_print_media_templates');
add_action('wp_footer', 'wp_print_media_templates');
add_action('customize_controls_print_footer_scripts', 'wp_print_media_templates');
/**
* Fires at the conclusion of wp_enqueue_media().
*
* @since 3.5.0
*/
//.........这里部分代码省略.........
示例14: recipe_get_media_item
/**
* Retrieve HTML form for modifying the image attachment.
*
* @since 2.5.0
*
* @param int $attachment_id Attachment ID for modification.
* @param string|array $args Optional. Override defaults.
* @return string HTML form for attachment.
*/
function recipe_get_media_item($attachment_id, $recipe_id)
{
global $redir_tab;
if (($attachment_id = intval($attachment_id)) && ($thumb_url = wp_get_attachment_image_src($attachment_id, 'thumbnail', true))) {
$thumb_url = $thumb_url[0];
} else {
$thumb_url = false;
}
$post = get_post($attachment_id);
$current_post_id = !empty($_GET['post_id']) ? (int) $_GET['post_id'] : 0;
$target_post_id = !empty($_GET['target_id']) ? (int) $_GET['target_id'] : 0;
$filename = esc_html(basename($post->guid));
$title = esc_attr($post->post_title);
$post_mime_types = get_post_mime_types();
$keys = array_keys(wp_match_mime_types(array_keys($post_mime_types), $post->post_mime_type));
$type = array_shift($keys);
$type_html = "<input type='hidden' id='type-of-{$attachment_id}' value='" . esc_attr($type) . "' />";
$display_title = !empty($title) ? $title : $filename;
// $title shouldn't ever be empty, but just in case
$display_title = "<div class='filename new'><span class='title'>" . wp_html_excerpt($display_title, 60) . "</span></div>";
$attachment_url = get_permalink($attachment_id);
$thumbnail = '';
$calling_post_id = 0;
if (isset($_GET['post_id'])) {
$calling_post_id = absint($_GET['post_id']);
} elseif (isset($_POST) && count($_POST)) {
// Like for async-upload where $_GET['post_id'] isn't set
$calling_post_id = $post->post_parent;
}
if ('image' == $type && $calling_post_id && current_theme_supports('post-thumbnails', get_post_type($calling_post_id)) && post_type_supports(get_post_type($calling_post_id), 'thumbnail') && get_post_thumbnail_id($calling_post_id) != $attachment_id) {
$ajax_nonce = wp_create_nonce("set_post_thumbnail-{$target_post_id}");
$thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='RecipeSetAsThumbnail(\"{$attachment_id}\", \"{$target_post_id}\", \"{$ajax_nonce}\");return false;'>" . esc_html__("Use as featured image") . "</a>";
}
$item = "\n \t\t{$type_html}\n\n\n \t\t{$display_title}\n \t\t<table class='describe'>\n \t\t\t<thead class='media-item-info' id='media-head-{$post->ID}'>\n \t\t\t<tr valign='top'>\n \t\t\t\t<td class='A1B1' id='thumbnail-head-{$post->ID}'>\n \t\t\t\t<p><a href='{$attachment_url}' target='_blank'><img class='thumbnail' src='{$thumb_url}' alt='' /></a></p>\n \t\t \t\t</td><td>{$thumbnail}</td></tr>\n";
$item .= "\n \t\t\t</thead>\n \t\t\t<tbody>\n \t\t\t<tr><td colspan='2' class='imgedit-response' id='imgedit-response-{$post->ID}'></td></tr>\n \t\t\t<tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-{$post->ID}'></td></tr>\n";
$item .= "\t</tbody>\n";
$item .= "\t</table>\n";
if ($post->post_parent < 1 && isset($_REQUEST['post_id'])) {
$parent = (int) $_REQUEST['post_id'];
$parent_name = "attachments[{$attachment_id}][post_parent]";
$item .= "\t<input type='hidden' name='{$parent_name}' id='{$parent_name}' value='{$parent}' />\n";
}
return $item;
}
示例15: wp_edit_attachments_query
/**
* {@internal Missing Short Description}}
*
* @since unknown
*
* @param unknown_type $q
* @return unknown
*/
function wp_edit_attachments_query($q = false)
{
if (false === $q) {
$q = $_GET;
}
$q['m'] = isset($q['m']) ? (int) $q['m'] : 0;
$q['cat'] = isset($q['cat']) ? (int) $q['cat'] : 0;
$q['post_type'] = 'attachment';
$q['post_status'] = isset($q['status']) && 'trash' == $q['status'] ? 'trash' : 'inherit';
$media_per_page = (int) get_user_option('upload_per_page', 0, false);
if (empty($media_per_page) || $media_per_page < 1) {
$media_per_page = 20;
}
$q['posts_per_page'] = apply_filters('upload_per_page', $media_per_page);
$post_mime_types = get_post_mime_types();
$avail_post_mime_types = get_available_post_mime_types('attachment');
if (isset($q['post_mime_type']) && !array_intersect((array) $q['post_mime_type'], array_keys($post_mime_types))) {
unset($q['post_mime_type']);
}
wp($q);
return array($post_mime_types, $avail_post_mime_types);
}