本文整理汇总了PHP中wp_match_mime_types函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_match_mime_types函数的具体用法?PHP wp_match_mime_types怎么用?PHP wp_match_mime_types使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_match_mime_types函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: get_views
function get_views()
{
global $wpdb, $post_mime_types, $avail_post_mime_types;
$type_links = array();
$_num_posts = (array) wp_count_attachments();
$_total_posts = array_sum($_num_posts) - $_num_posts['trash'];
if (!isset($total_orphans)) {
$total_orphans = $wpdb->get_var("SELECT COUNT( * ) FROM {$wpdb->posts} WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1");
}
$matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
foreach ($matches as $type => $reals) {
foreach ($reals as $real) {
$num_posts[$type] = isset($num_posts[$type]) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real];
}
}
$class = empty($_GET['post_mime_type']) && !isset($_GET['status']) ? ' class="current"' : '';
$type_links['all'] = "<a href='upload.php'{$class}>" . sprintf(_nx('All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $_total_posts, 'uploaded files'), number_format_i18n($_total_posts)) . '</a>';
foreach ($post_mime_types as $mime_type => $label) {
$class = '';
if (!wp_match_mime_types($mime_type, $avail_post_mime_types)) {
continue;
}
if (!empty($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type'])) {
$class = ' class="current"';
}
if (!empty($num_posts[$mime_type])) {
$type_links[$mime_type] = "<a href='upload.php?post_mime_type={$mime_type}'{$class}>" . sprintf(translate_nooped_plural($label[2], $num_posts[$mime_type]), number_format_i18n($num_posts[$mime_type])) . '</a>';
}
}
if (!empty($_num_posts['trash'])) {
$type_links['trash'] = '<a href="upload.php?status=trash"' . (isset($_GET['status']) && $_GET['status'] == 'trash' ? ' class="current"' : '') . '>' . sprintf(_nx('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', $_num_posts['trash'], 'uploaded files'), number_format_i18n($_num_posts['trash'])) . '</a>';
}
return array();
}
开发者ID:sangikumar,项目名称:IP,代码行数:34,代码来源:class-frontend-uploader-wp-posts-list-table.php
示例2: get_views
protected function get_views()
{
global $wpdb, $post_mime_types, $avail_post_mime_types;
$type_links = array();
$_num_posts = (array) wp_count_attachments();
$_total_posts = array_sum($_num_posts) - $_num_posts['trash'];
$total_orphans = $wpdb->get_var("SELECT COUNT( * ) FROM {$wpdb->posts} WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1");
$matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
foreach ($matches as $type => $reals) {
foreach ($reals as $real) {
$num_posts[$type] = isset($num_posts[$type]) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real];
}
}
$selected = empty($_GET['attachment-filter']) ? ' selected="selected"' : '';
$type_links['all'] = "<option value=''{$selected}>" . sprintf(_nx('All (%s)', 'All (%s)', $_total_posts, 'uploaded files'), number_format_i18n($_total_posts)) . '</option>';
foreach ($post_mime_types as $mime_type => $label) {
if (!wp_match_mime_types($mime_type, $avail_post_mime_types)) {
continue;
}
$selected = '';
if (!empty($_GET['attachment-filter']) && strpos($_GET['attachment-filter'], 'post_mime_type:') === 0 && wp_match_mime_types($mime_type, str_replace('post_mime_type:', '', $_GET['attachment-filter']))) {
$selected = ' selected="selected"';
}
if (!empty($num_posts[$mime_type])) {
$type_links[$mime_type] = '<option value="post_mime_type:' . esc_attr($mime_type) . '"' . $selected . '>' . sprintf(translate_nooped_plural($label[2], $num_posts[$mime_type]), number_format_i18n($num_posts[$mime_type])) . '</option>';
}
}
$type_links['detached'] = '<option value="detached"' . ($this->detached ? ' selected="selected"' : '') . '>' . sprintf(_nx('Unattached (%s)', 'Unattached (%s)', $total_orphans, 'detached files'), number_format_i18n($total_orphans)) . '</option>';
$type_links['uncategorized'] = '<option value="uncategorized"' . ($this->uncategorized ? ' selected="selected"' : '') . '>' . __('All Uncategorized', 'eml') . '</option>';
if (!empty($_num_posts['trash'])) {
$type_links['trash'] = '<option value="trash"' . (isset($_GET['attachment-filter']) && $_GET['attachment-filter'] == 'trash' ? ' selected="selected"' : '') . '>' . sprintf(_nx('Trash (%s)', 'Trash (%s)', $_num_posts['trash'], 'uploaded files'), number_format_i18n($_num_posts['trash'])) . '</option>';
}
return $type_links;
}
开发者ID:vanlong200880,项目名称:uni,代码行数:34,代码来源:class-eml-media-list-table.php
示例3: get_custom_uploader_allowed_types
/**
* Lista os formatos permitidos dentro do custom uploader
*
* @return array $allowed_mime_types Os tipos permitidos
*/
function get_custom_uploader_allowed_types($mime_types = array())
{
if (empty($mime_types)) {
$mime_types = get_allowed_mime_types();
}
$allowed_mime_types = $mime_types;
foreach ($mime_types as $key => $value) {
if (wp_match_mime_types('image, audio, video', $value)) {
unset($allowed_mime_types[$key]);
}
}
return $allowed_mime_types;
}
开发者ID:aspto,项目名称:wordpress-themes,代码行数:18,代码来源:custom-uploader.php
示例4: 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);
}
}
}
}
}
}
}
开发者ID:joffcrabtree,项目名称:wp-pronamic-framework,代码行数:49,代码来源:shortcode-edit-post-form.php
示例5: get_views
/**
* @global array $post_mime_types
* @global array $avail_post_mime_types
* @return array
*/
protected function get_views()
{
global $post_mime_types, $avail_post_mime_types;
$type_links = array();
$filter = empty($_GET['attachment-filter']) ? '' : $_GET['attachment-filter'];
$type_links['all'] = sprintf('<option value=""%s>%s</option>', selected($filter, true, false), __('All media items'));
foreach ($post_mime_types as $mime_type => $label) {
if (!wp_match_mime_types($mime_type, $avail_post_mime_types)) {
continue;
}
$selected = selected($filter && 0 === strpos($filter, 'post_mime_type:') && wp_match_mime_types($mime_type, str_replace('post_mime_type:', '', $filter)), true, false);
$type_links[$mime_type] = sprintf('<option value="post_mime_type:%s"%s>%s</option>', esc_attr($mime_type), $selected, $label[0]);
}
$type_links['detached'] = '<option value="detached"' . ($this->detached ? ' selected="selected"' : '') . '>' . __('Unattached') . '</option>';
if ($this->is_trash || defined('MEDIA_TRASH') && MEDIA_TRASH) {
$type_links['trash'] = sprintf('<option value="trash"%s>%s</option>', selected('trash' === $filter, true, false), __('Trash'));
}
return $type_links;
}
开发者ID:leonardopires,项目名称:projectnami,代码行数:24,代码来源:class-wp-media-list-table.php
示例6: wp_custom_recount_attachments
public static function wp_custom_recount_attachments($views)
{
$_total_posts = array();
$_num_posts = array();
global $wpdb, $current_user, $post_mime_types, $avail_post_mime_types;
$views = array();
$count = $wpdb->get_results("\r\n\t\t\t\t\tSELECT post_mime_type, COUNT( * ) AS num_posts \r\n\t\t\t\t\tFROM {$wpdb->posts} \r\n\t\t\t\t\tWHERE post_type = 'attachment' \r\n\t\t\t\t\tAND post_author = {$current_user->ID} \r\n\t\t\t\t\tAND post_status != 'trash' \r\n\t\t\t\t\tGROUP BY post_mime_type\r\n\t\t\t\t", ARRAY_A);
foreach ($count as $row) {
$_num_posts[$row['post_mime_type']] = $row['num_posts'];
}
$_total_posts = array_sum($_num_posts);
$detached = isset($_REQUEST['detached']) || isset($_REQUEST['find_detached']);
if (!isset($total_orphans)) {
$total_orphans = $wpdb->get_var("\r\n\t\t\t\t\t\tSELECT COUNT( * ) \r\n\t\t\t\t\t\tFROM {$wpdb->posts} \r\n\t\t\t\t\t\tWHERE post_type = 'attachment' \r\n\t\t\t\t\t\tAND post_author = {$current_user->ID} \r\n\t\t\t\t\t\tAND post_status != 'trash' \r\n\t\t\t\t\t\tAND post_parent < 1\r\n\t\t\t\t\t");
}
$matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
foreach ($matches as $type => $reals) {
foreach ($reals as $real) {
$num_posts[$type] = isset($num_posts[$type]) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real];
}
}
$class = empty($_GET['post_mime_type']) && !$detached && !isset($_GET['status']) ? ' class="current"' : '';
$views['all'] = "<a href='upload.php'{$class}>" . sprintf(__('All <span class="count">(%s)</span>', 'uploaded files'), number_format_i18n($_total_posts)) . '</a>';
foreach ($post_mime_types as $mime_type => $label) {
$class = '';
if (!wp_match_mime_types($mime_type, $avail_post_mime_types)) {
continue;
}
if (!empty($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type'])) {
$class = ' class="current"';
}
if (!empty($num_posts[$mime_type])) {
$views[$mime_type] = "<a href='upload.php?post_mime_type={$mime_type}'{$class}>" . sprintf(translate_nooped_plural($label[2], $num_posts[$mime_type]), $num_posts[$mime_type]) . '</a>';
}
}
$views['detached'] = '<a href="upload.php?detached=1"' . ($detached ? ' class="current"' : '') . '>' . sprintf(__('Unattached <span class="count">(%s)</span>', 'detached files'), $total_orphans) . '</a>';
return $views;
}
开发者ID:zruiz,项目名称:NG,代码行数:38,代码来源:wp_media_custom.php
示例7: wie_upload_import_file
/**
* Upload import file
*
* @since 0.3
*/
function wie_upload_import_file()
{
// Check nonce for security since form was posted
if (!empty($_POST) && !empty($_FILES['wie_import_file']) && check_admin_referer('wie_import', 'wie_import_nonce')) {
// check_admin_referer prints fail page and dies
// Uploaded file
$uploaded_file = $_FILES['wie_import_file'];
// Check file type
// This will also fire if no file uploaded
$wp_filetype = wp_check_filetype_and_ext($uploaded_file['tmp_name'], $uploaded_file['name'], false);
if ('wie' != $wp_filetype['ext'] && !wp_match_mime_types('wie', $wp_filetype['type'])) {
wp_die(__('You must upload a <b>.wie</b> file generated by this plugin.', 'widget-importer-exporter'), '', array('back_link' => true));
}
// Check and move file to uploads dir, get file data
// Will show die with WP errors if necessary (file too large, quota exceeded, etc.)
$overrides = array('test_form' => false);
$file_data = wp_handle_upload($uploaded_file, $overrides);
if (isset($file_data['error'])) {
wp_die($file_data['error'], '', array('back_link' => true));
}
// Process import file
wie_process_import_file($file_data['file']);
}
}
开发者ID:dot2006,项目名称:jobify,代码行数:29,代码来源:import.php
示例8: handle_upload
/**
* Upload the file to be cropped in the second step.
*
* @since 4.3.0
*/
public function handle_upload()
{
$uploaded_file = $_FILES['site-icon'];
$file_type = wp_check_filetype_and_ext($uploaded_file['tmp_name'], $uploaded_file['name']);
if (!wp_match_mime_types('image', $file_type['type'])) {
wp_die(__('The uploaded file is not a valid image. Please try again.'));
}
$file = wp_handle_upload($uploaded_file, array('test_form' => false));
if (isset($file['error'])) {
wp_die($file['error'], __('Image Upload Error'));
}
$url = $file['url'];
$type = $file['type'];
$file = $file['file'];
$filename = basename($file);
// Construct the object array
$object = array('post_title' => $filename, 'post_content' => $url, 'post_mime_type' => $type, 'guid' => $url, 'context' => 'site-icon');
// Save the data
$attachment_id = wp_insert_attachment($object, $file);
return compact('attachment_id', 'file', 'filename', 'url', 'type');
}
开发者ID:naturalogy,项目名称:WordPress,代码行数:26,代码来源:class-wp-site-icon.php
示例9: bp_attachments_get_allowed_mimes
/**
* Get allowed attachment mime types.
*
* @since 2.4.0
*
* @param string $type The extension types to get (Optional).
* @param array $allowed_types List of allowed extensions
* @return array List of allowed mime types
*/
function bp_attachments_get_allowed_mimes($type = '', $allowed_types = array())
{
if (empty($allowed_types)) {
$allowed_types = bp_attachments_get_allowed_types($type);
}
$validate_mimes = wp_match_mime_types(join(',', $allowed_types), wp_get_mime_types());
$allowed_mimes = array_map('implode', $validate_mimes);
/**
* Include jpg type if jpeg is set
*/
if (isset($allowed_mimes['jpeg']) && !isset($allowed_mimes['jpg'])) {
$allowed_mimes['jpg'] = $allowed_mimes['jpeg'];
}
return $allowed_mimes;
}
开发者ID:mawilliamson,项目名称:wordpress,代码行数:24,代码来源:bp-core-attachments.php
示例10: wp_count_attachments
$_num_posts = (array) wp_count_attachments();
$_total_posts = array_sum($_num_posts);
$matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
foreach ($matches as $type => $reals) {
foreach ($reals as $real) {
$num_posts[$type] = isset($num_posts[$type]) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real];
}
}
$class = empty($_GET['post_mime_type']) && !isset($_GET['detached']) ? ' class="current"' : '';
$type_links[] = "<li><a href='upload.php'{$class}>" . sprintf(_nx('All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $_total_posts, 'uploaded files'), number_format_i18n($_total_posts)) . '</a>';
foreach ($post_mime_types as $mime_type => $label) {
$class = '';
if (!wp_match_mime_types($mime_type, $avail_post_mime_types)) {
continue;
}
if (!empty($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type'])) {
$class = ' class="current"';
}
$type_links[] = "<li><a href='upload.php?post_mime_type={$mime_type}'{$class}>" . sprintf(_n($label[2][0], $label[2][1], $num_posts[$mime_type]), number_format_i18n($num_posts[$mime_type])) . '</a>';
}
$class = isset($_GET['detached']) ? ' class="current"' : '';
$type_links[] = '<li><a href="upload.php?detached=1"' . $class . '>' . __('Unattached') . '</a>';
echo implode(" |</li>\n", $type_links) . '</li>';
unset($type_links);
?>
</ul>
<form class="search-form" action="" method="get">
<p class="search-box">
<label class="screen-reader-text" for="media-search-input"><?php
_e('Search Media');
开发者ID:papayalabs,项目名称:htdocs,代码行数:31,代码来源:upload.php
示例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
}
开发者ID:rkglug,项目名称:WordPress,代码行数:92,代码来源:media.php
示例12: yoimg_search_upload_images
function yoimg_search_upload_images()
{
$post_id = esc_html(isset($_POST['postId']) ? $_POST['postId'] : '');
if (current_user_can('upload_files') && current_user_can('edit_post', $post_id)) {
header('Content-type: application/json; charset=UTF-8');
$images_urls = isset($_POST['imagesUrls']) ? $_POST['imagesUrls'] : array();
if (count($images_urls) > 0) {
status_header(200);
$results = array();
foreach ($images_urls as $image_url) {
$result = array('origUrl' => $image_url);
$downloaded_image = download_url($image_url);
if (is_wp_error($downloaded_image)) {
$result['errorMessage'] = $downloaded_image->get_error_message();
status_header(503);
} else {
$result['imageFilename'] = $downloaded_image;
$downloaded_image_info = pathinfo($downloaded_image);
$downloaded_image_basename = $downloaded_image_info['basename'];
$downloaded_image_basename .= '.gif';
$downloaded_image_filetype = wp_check_filetype_and_ext($downloaded_image, $downloaded_image_basename, false);
if (!wp_match_mime_types('image', $downloaded_image_filetype['type'])) {
$result['errorMessage'] = __('The uploaded file is not a valid image. Please try again.');
status_header(503);
} else {
$time = current_time('mysql');
if ($post = get_post($post_id)) {
if (substr($post->post_date, 0, 4) > 0) {
$time = $post->post_date;
}
}
$uploads = wp_upload_dir($time);
if (isset($uploads['error']) && $uploads['error'] === false) {
$filename = isset($downloaded_image_filetype['proper_filename']) ? $downloaded_image_filetype['proper_filename'] : $downloaded_image_basename;
$filename = wp_unique_filename($uploads['path'], $filename);
$new_file = $uploads['path'] . '/' . $filename;
$move_new_file = @rename($downloaded_image, $new_file);
if (false === $move_new_file) {
$result['errorMessage'] = sprintf(__('The uploaded file could not be moved to %s.'), $new_file);
status_header(503);
} else {
$stat = stat(dirname($new_file));
$perms = $stat['mode'] & 0666;
@chmod($new_file, $perms);
$url = $uploads['url'] . '/' . $filename;
$result['imageFilename'] = $new_file;
$result['imageUrl'] = $url;
$attachment = array('post_mime_type' => $downloaded_image_filetype['type'], 'guid' => $url, 'post_parent' => $post_id, 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($filename)), 'post_content' => '', 'post_status' => 'inherit');
$image_id = wp_insert_attachment($attachment, $new_file, $post_id);
if (!is_wp_error($image_id)) {
require_once ABSPATH . 'wp-admin/includes/image.php';
wp_update_attachment_metadata($image_id, wp_generate_attachment_metadata($image_id, $new_file));
$result['imageId'] = $image_id;
} else {
$result['errorMessage'] = 'cannot insert attachment';
status_header(503);
}
}
} else {
$result['errorMessage'] = __($uploads['error']);
status_header(503);
}
}
}
array_push($results, $result);
}
echo json_encode($results);
} else {
status_header(204);
}
} else {
status_header(401);
}
die;
}
开发者ID:odie2,项目名称:yoimages-search,代码行数:75,代码来源:image-uploader.php
示例13: _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;
}
开发者ID:rongandat,项目名称:best-picture,代码行数:100,代码来源:class-mla-list-table.php
示例14: media_upload_library_form
/**
* {@internal Missing Short Description}}
*
* @since 2.5.0
*
* @param array $errors
*/
function media_upload_library_form($errors)
{
global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
media_upload_header();
$post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
$form_action_url = admin_url("media-upload.php?type={$type}&tab=library&post_id={$post_id}");
/** This filter is documented in wp-admin/includes/media.php */
$form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
$form_class = 'media-upload-form validate';
if (get_user_setting('uploader')) {
$form_class .= ' html-uploader';
}
$q = $_GET;
$q['posts_per_page'] = 10;
$q['paged'] = isset($q['paged']) ? intval($q['paged']) : 0;
if ($q['paged'] < 1) {
$q['paged'] = 1;
}
$q['offset'] = ($q['paged'] - 1) * 10;
if ($q['offset'] < 1) {
$q['offset'] = 0;
}
list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query($q);
?>
<form id="filter" action="" method="get">
<input type="hidden" name="type" value="<?php
echo esc_attr($type);
?>
" />
<input type="hidden" name="tab" value="<?php
echo esc_attr($tab);
?>
" />
<input type="hidden" name="post_id" value="<?php
echo (int) $post_id;
?>
" />
<input type="hidden" name="post_mime_type" value="<?php
echo isset($_GET['post_mime_type']) ? esc_attr($_GET['post_mime_type']) : '';
?>
" />
<input type="hidden" name="context" value="<?php
echo isset($_GET['context']) ? esc_attr($_GET['context']) : '';
?>
" />
<p id="media-search" class="search-box">
<label class="screen-reader-text" for="media-search-input"><?php
_e('Search Media');
?>
:</label>
<input type="search" id="media-search-input" name="s" value="<?php
the_search_query();
?>
" />
<?php
submit_button(__('Search Media'), 'button', '', false);
?>
</p>
<ul class="subsubsub">
<?php
$type_links = array();
$_num_posts = (array) wp_count_attachments();
$matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
foreach ($matches as $_type => $reals) {
foreach ($reals as $real) {
if (isset($num_posts[$_type])) {
$num_posts[$_type] += $_num_posts[$real];
} else {
$num_posts[$_type] = $_num_posts[$real];
}
}
}
// If available type specified by media button clicked, filter by that type
if (empty($_GET['post_mime_type']) && !empty($num_posts[$type])) {
$_GET['post_mime_type'] = $type;
list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
}
if (empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all') {
$class = ' class="current"';
} else {
$class = '';
}
$type_links[] = '<li><a href="' . esc_url(add_query_arg(array('post_mime_type' => 'all', 'paged' => false, 'm' => false))) . '"' . $class . '>' . __('All Types') . '</a>';
foreach ($post_mime_types as $mime_type => $label) {
$class = '';
if (!wp_match_mime_types($mime_type, $avail_post_mime_types)) {
continue;
}
if (isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type'])) {
$class = ' class="current"';
//.........这里部分代码省略.........
开发者ID:HaraShun,项目名称:WordPress,代码行数:101,代码来源:media.php
示例15: update
/**
* Update user meta.
*
* @param int $user_id
*/
public function update($user_id)
{
if (!empty($_FILES) && isset($_FILES[$this->name]) && !empty($_FILES[$this->name]['tmp_name'])) {
$current_attachment_id = get_user_meta($user_id, $this->name, true);
if ($current_attachment_id) {
wp_delete_attachment($current_attachment_id);
}
$filetype = wp_check_filetype_and_ext($_FILES[$this->name]['tmp_name'], $_FILES[$this->name]['name']);
if (!wp_match_mime_types('image', $filetype['type'])) {
die;
}
$attachment_id = media_handle_upload($this->name, 0);
if (!is_wp_error($attachment_id)) {
update_user_meta($user_id, $this->name, $attachment_id);
}
}
}
开发者ID:Bonus3,项目名称:ib-educator-theme,代码行数:22,代码来源:user-meta.php
示例16: _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;
}
开发者ID:Omuze,项目名称:barakat,代码行数:52,代码来源:form.php
示例17: _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;
}
开发者ID:unity3software,项目名称:clearbase,代码行数:18,代码来源:class-view-folder.php
示例18: array
<?php
$type_links = array();
$_num_posts = (array) wp_count_attachments();
$matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
foreach ( $matches as $type => $reals )
f
|
请发表评论