コード例 #1
0
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
0
ファイル: post.php プロジェクト: uwitec/findgreatmaster
/**
 * 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
0
ファイル: media.php プロジェクト: dev-lav/htdocs
/**
 * 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' => __('&#8592; 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' => __('&#8592; 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
0
 /**
  * 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
0
ファイル: form.php プロジェクト: Omuze/barakat
/**
 * 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
0
    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];
        ?>
';
            var wpmf_curent_userid = '<?php 
        echo get_current_user_id();
        ?>
';
            var wpmf_active_media = '<?php 
        echo $wpmf_active_media;
        ?>
';
            var term_root_username = '******';
            var term_root_id = '<?php 
        echo @$term_rootId;
        ?>
';
            var wpmf_post_mime_type = <?php 
        echo json_encode($post_mime_types);
        ?>
;
            var wpmflang = {
                'create_folder': "<?php 
        _e('Create Folder', 'wpmf');
        ?>
",
                'media_folder': "<?php 
        _e('Media Library', 'wpmf');
        ?>
",
                'promt': "<?php 
        _e('Please give a name to this new folder', 'wpmf');
        ?>
",
                'new_folder': "<?php 
        _e('New folder', 'wpmf');
        ?>
",
                'alert_add': "<?php 
        _e('A term with the name and slug already exists with this parent.', 'wpmf');
        ?>
",
                'alert_delete': "<?php 
        _e('Are you sure to want to delete this folder', 'wpmf');
        ?>
",
                'alert_delete1': "<?php 
        _e('this folder contains sub-folder, delete sub-folders before', 'wpmf');
        ?>
",
                'display_media': "<?php 
        _e('Display only my own media', 'wpmf');
        ?>
",
                'create_gallery_folder': "<?php 
        _e('Create a gallery from folder', 'wpmf');
        ?>
",
                'home' : "<?php 
        _e('Home', 'wpmf');
        ?>
",
                'youarehere' : "<?php 
        _e('You are here', 'wpmf');
        ?>
",
                'back' : "<?php 
        _e('Back', 'wpmf');
        ?>
",
                'dragdrop' : "<?php 
        _e('Drag and Drop me hover a folder', 'wpmf');
        ?>
",
                'ascending': "<?php 
        _e('(Ascending)', 'wpmf');
        ?>
",
                'descending': "<?php 
        _e('(Descending)', 'wpmf');
        ?>
",
                'sortattach': "<?php 
        _e('Sort attachment', 'wpmf');
        ?>
",
                'smallview': "<?php 
        _e('Small View', 'wpmf');
        ?>
",
                'mimetype': "<?php 
        _e('All media items', 'wpmf');
        ?>
",
                'all_size_label': "<?php 
        _e('Minimal size', 'wpmf');
        ?>
",
                'all_weight_label': "<?php 
        _e('All weight', 'wpmf');
        ?>
",
                'order_folder_label': "<?php 
        _e('Sort folder', 'wpmf');
        ?>
",
                'order_img_label': "<?php 
        _e('Sort attachment', 'wpmf');
        ?>
",
                'pdf': "<?php 
        _e('PDF', 'wpmf');
        ?>
",
                'zip': "<?php 
        _e('Zip & archives', 'wpmf');
        ?>
",
                'other': "<?php 
        _e('Other', 'wpmf');
        ?>
",
                'undimension': "<?php 
        _e('Remove dimension', 'wpmf');
        ?>
",
                'editdimension': "<?php 
        _e('Edit dimension', 'wpmf');
        ?>
",
                'unweight': "<?php 
        _e('Remove weight', 'wpmf');
        ?>
",
                'editweight': "<?php 
        _e('Edit weight', 'wpmf');
        ?>
",
                'error': "<?php 
        _e('This value is already existing', 'wpmf');
        ?>
",
            };
            var view = '<?php 
        echo @$_SESSION['wpmfview'];
        ?>
';
            var site_url = '<?php 
        echo get_site_url() . '/wp-admin/upload.php?mode=grid';
        ?>
';
            var useorder = '<?php 
        echo $useorder;
        ?>
';
	</script>
	<?php 
        //include jquery ui
        wp_enqueue_script(array('jquery-ui-draggable', 'jquery-ui-droppable'));
    }
コード例 #7
0
ファイル: media.php プロジェクト: realfluid/umbaugh
/**
 * 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']}&nbsp;&times;&nbsp;{$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>';
			if ( !empty( $media_dims ) )
				$item .= "<p><strong>" . __('Dimensions:') . "</strong> $media_dims</p>\n";

			$item .= "</td></tr>\n";



	$item .= "
		</thead>
		<tbody>
		<tr><td colspan='2' class='imgedit-response' id='imgedit-response-$post->ID'></td></tr>
		<tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n";

	$defaults = array(
		'input'      => 'text',
		'required'   => false,
		'value'      => '',
		'extra_rows' => array(),
	);

	if ( $send )
		$send = "<input type='submit' class='button' name='send[$attachment_id]' value='" . esc_attr__( 'Insert into Post' ) . "' />";
	if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) {
		if ( !EMPTY_TRASH_DAYS ) {
			$delete = "<a href='" . wp_nonce_url( "post.php?action=delete&amp;post=$attachment_id", 'delete-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Delete Permanently' ) . '</a>';
		} elseif ( !MEDIA_TRASH ) {
			$delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a>
			 <div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'>" . sprintf( __( 'You are about to delete <strong>%s</strong>.' ), $filename ) . "
			 <a href='" . wp_nonce_url( "post.php?action=delete&amp;post=$attachment_id", 'delete-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='button'>" . __( 'Continue' ) . "</a>
			 <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . "</a>
			 </div>";
		} else {
			$delete = "<a href='" . wp_nonce_url( "post.php?action=trash&amp;post=$attachment_id", 'trash-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Move to Trash' ) . "</a>
			<a href='" . wp_nonce_url( "post.php?action=untrash&amp;post=$attachment_id", 'untrash-attachment_' . $attachment_id ) . "' id='undo[$attachment_id]' class='undo hidden'>" . __( 'Undo' ) . "</a>";
		}
	} else {
		$delete = '';
	}

	$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 ) ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) {
		$ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" );
		$thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html__( "Use as featured image" ) . "</a>";
	}

	if ( ( $send || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) )
		$form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $thumbnail $delete</td></tr>\n" );

	$hidden_fields = array();

	foreach ( $form_fields as $id => $field ) {
		if ( $id{0} == '_' )
			continue;

		if ( !empty( $field['tr'] ) ) {
			$item .= $field['tr'];
			continue;
		}

		$field = array_merge( $defaults, $field );
		$name = "attachments[$attachment_id][$id]";

		if ( $field['input'] == 'hidden' ) {
			$hidden_fields[$name] = $field['value'];
			continue;
		}

		$required      = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : '';
		$aria_required = $field['required'] ? " aria-required='true' " : '';
		$class  = $id;
		$class .= $field['required'] ? ' form-required' : '';

		$item .= "\t\t<tr class='$class'>\n\t\t\t<th valign='top' scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label></th>\n\t\t\t<td class='field'>";
		if ( !empty( $field[ $field['input'] ] ) )
			$item .= $field[ $field['input'] ];
		elseif ( $field['input'] == 'textarea' ) {
			$item .= "<textarea type='text' id='$name' name='$name' $aria_required>" . esc_html( $field['value'] ) . '</textarea>';
		} else {
			$item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />";
		}
		if ( !empty( $field['helps'] ) )
			$item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
		$item .= "</td>\n\t\t</tr>\n";

		$extra_rows = array();

		if ( !empty( $field['errors'] ) )
			foreach ( array_unique( (array) $field['errors'] ) as $error )
				$extra_rows['error'][] = $error;

		if ( !empty( $field['extra_rows'] ) )
			foreach ( $field['extra_rows'] as $class => $rows )
				foreach ( (array) $rows as $html )
					$extra_rows[$class][] = $html;

		foreach ( $extra_rows as $class => $rows )
			foreach ( $rows as $html )
				$item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
	}

	if ( !empty( $form_fields['_final'] ) )
		$item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
	$item .= "\t</tbody>\n";
	$item .= "\t</table>\n";

	foreach ( $hidden_fields as $name => $value )
		$item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\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;
}
コード例 #8
0
ファイル: post.php プロジェクト: openify/wordpress-composer
/**
 * 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
0
 /**
  * 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
0
 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
0
ファイル: media.php プロジェクト: rkglug/WordPress
/**
 * 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']}&nbsp;&times;&nbsp;{$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
0
ファイル: media.php プロジェクト: neopunisher/WordPress
/**
 * 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' => __('&#8592; 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' => __('&#8592; 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
0
/**
 * 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' => __('&#8592; 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' => __('&#8592; 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&hellip;'), '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' => __('&#8592; 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' => __('&#8592; 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
     */
    do_action('wp_enqueue_media');
}
コード例 #14
0
 /**
  * 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
0
/**
 * {@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);
}
コード例 #16
0
ファイル: media.php プロジェクト: nakamuraagatha/reseptest
/**
 * Enqueues all scripts, styles, settings, and templates necessary to use
 * all media JS APIs.
 *
 * @since 3.5.0
 *
 * @global int       $content_width
 * @global wpdb      $wpdb
 * @global WP_Locale $wp_locale
 *
 * @param array $args {
 *     Arguments for enqueuing media scripts.
 *
 *     @type int|WP_Post A post object or ID.
 * }
 */
function wp_enqueue_media($args = array())
{
    // Enqueue me just once per page, please.
    if (did_action('wp_enqueue_media')) {
        return;
    }
    global $content_width, $wpdb, $wp_locale;
    $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;
            }
        }
    }
    $has_audio = $wpdb->get_var("\n\t\tSELECT ID\n\t\tFROM {$wpdb->posts}\n\t\tWHERE post_type = 'attachment'\n\t\tAND post_mime_type LIKE 'audio%'\n\t\tLIMIT 1\n\t");
    $has_video = $wpdb->get_var("\n\t\tSELECT ID\n\t\tFROM {$wpdb->posts}\n\t\tWHERE post_type = 'attachment'\n\t\tAND post_mime_type LIKE 'video%'\n\t\tLIMIT 1\n\t");
    $months = $wpdb->get_results($wpdb->prepare("\n\t\tSELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month\n\t\tFROM {$wpdb->posts}\n\t\tWHERE post_type = %s\n\t\tORDER BY post_date DESC\n\t", 'attachment'));
    foreach ($months as $month_year) {
        $month_year->text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($month_year->month), $month_year->year);
    }
    $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' => $has_audio ? 1 : 0, 'video' => $has_video ? 1 : 0), 'embedExts' => $exts, 'embedMimes' => $ext_mimes, 'contentWidth' => $content_width, 'months' => $months, 'mediaTrash' => MEDIA_TRASH ? 1 : 0);
    $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 (wp_attachment_is('audio', $post)) {
                $thumbnail_support = post_type_supports('attachment:audio', 'thumbnail') || current_theme_supports('post-thumbnails', 'attachment:audio');
            } elseif (wp_attachment_is('video', $post)) {
                $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;
        }
    }
    if ($post) {
        $post_type_object = get_post_type_object($post->post_type);
    } else {
        $post_type_object = get_post_type_object('post');
    }
    $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 media files.'), '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' => __('&#8592; Return to library'), 'allMediaItems' => __('All media items'), 'allDates' => __('All dates'), 'noItemsFound' => __('No items found.'), 'insertIntoPost' => $post_type_object->labels->insert_into_item, 'unattached' => __('Unattached'), 'trash' => _x('Trash', 'noun'), 'uploadedToThisPost' => $post_type_object->labels->uploaded_to_this_item, 'warnDelete' => __("You are about to permanently delete this item.\n  'Cancel' to stop, 'OK' to delete."), 'warnBulkDelete' => __("You are about to permanently delete these items.\n  'Cancel' to stop, 'OK' to delete."), 'warnBulkTrash' => __("You are about to trash these items.\n  'Cancel' to stop, 'OK' to delete."), 'bulkSelect' => __('Bulk Select'), 'cancelSelection' => __('Cancel Selection'), 'trashSelected' => __('Trash Selected'), 'untrashSelected' => __('Untrash Selected'), 'deleteSelected' => __('Delete Selected'), 'deletePermanently' => __('Delete Permanently'), 'apply' => __('Apply'), 'filterByDate' => __('Filter by date'), 'filterByType' => __('Filter by type'), 'searchMediaLabel' => __('Search Media'), 'noMedia' => __('No media attachments found.'), 'attachmentDetails' => __('Attachment Details'), 'insertFromUrlTitle' => __('Insert from URL'), 'setFeaturedImageTitle' => $post_type_object->labels->featured_image, 'setFeaturedImage' => $post_type_object->labels->set_featured_image, 'createGalleryTitle' => __('Create Gallery'), 'editGalleryTitle' => __('Edit Gallery'), 'cancelGalleryTitle' => __('&#8592; 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&hellip;'), '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' => __('&#8592; 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' => __('&#8592; 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;
    // Ensure we enqueue media-editor first, that way media-views is
    // registered internally before we try to localize it. see #24724.
    wp_enqueue_script('media-editor');
    wp_localize_script('media-views', '_wpMediaViewsL10n', $strings);
    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
     */
    do_action('wp_enqueue_media');
}
コード例 #17
0
/**
 * Retrieves a sepecific playlist item.  In this case it is a media attachment.
 * @global string $redir_tab The tab to redirect to.
 * @param int $attachment_id The id of the attachment we are retrieving.
 * @param array $args Any additional arguments for query the database.
 * @param int $current_playlist The currently selected playlist.
 * @return string The HTML representing the playlist item.
 */
function get_jw_playlist_item($attachment_id, $args, $current_playlist, $prefix = "")
{
    global $redir_tab, $p_items;
    if (($attachment_id = intval($attachment_id)) && ($thumb_url = get_attachment_icon_src($attachment_id))) {
        $thumb_url = $thumb_url[0];
    } else {
        return false;
    }
    $default_args = array('errors' => null, 'send' => true, 'delete' => true, 'toggle' => true, 'show_title' => true);
    $args = wp_parse_args($args, $default_args);
    extract($args, EXTR_SKIP);
    $post = get_post($attachment_id);
    $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);
    $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 ? true : false;
    $order = '';
    $checked = "";
    foreach ($p_items as $playlist_item) {
        if ($playlist_item == $attachment_id) {
            $checked = "checked='true'";
            break;
        }
    }
    foreach ($form_fields as $key => $val) {
        if ('menu_order' == $key) {
            if (true) {
                $order = '<div class="menu_order">';
                $order .= '<input class="menu_order_input" type="checkbox" id="' . $prefix . 'attachments[' . $attachment_id . '][enabled]" name="' . $prefix . 'attachments[' . $attachment_id . '][enabled]" value="' . $val['value'] . '"' . $checked . ' onclick="updatePlaylist(this);" /></div>';
            } else {
                $order = '<input type="hidden" name="' . $prefix . 'attachments[' . $attachment_id . '][menu_order]" value="' . $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='playlist-dims-{$post->ID}'>{$meta['width']}&nbsp;&times;&nbsp;{$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='images/wpspin_light.gif' class='imgedit-wait-spin' alt='' />";
    }
    $item = "\n\t{$type_html}\n\t{$toggle_links}\n\t{$order}\n\t{$display_title}\n  <table class='slidetoggle describe startclosed'>\n\t\t<thead class='media-item-info' id='media-head-{$post->ID}'>\n\t\t<tr>\n\t\t\t<td class='A1B1' id='thumbnail-head-{$post->ID}' rowspan='5'><img class='thumbnail' src='{$thumb_url}' alt='' /></td>\n\t\t\t<td><strong>" . __('File name:') . "</strong> {$filename}</td>\n\t\t</tr>\n\t\t<tr><td><strong>" . __('File type:') . "</strong> {$post->post_mime_type}</td></tr>\n\t\t<tr><td><strong>" . __('Upload date:') . "</strong> " . mysql2date(get_option('date_format'), $post->post_date) . "</td></tr>\n";
    if (!empty($media_dims)) {
        $item .= "<tr><td><strong>" . __('Dimensions:') . "</strong> {$media_dims}</td></tr>\n";
    }
    $item .= "\n\t\t<tr><td class='A1B1'>{$image_edit_button}</td></tr>\n\t\t</thead>\n\t\t<tbody>\n\t\t<tr><td colspan='2' class='imgedit-response' id='imgedit-response-{$post->ID}'></td></tr>\n\t\t<tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-{$post->ID}'></td></tr>\n";
    $defaults = array('input' => 'text', 'required' => false, 'value' => '', 'extra_rows' => array());
    $thumbnail = '';
    $calling_post_id = 0;
    if (isset($_GET['post_id'])) {
        $calling_post_id = $_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)) && get_post_thumbnail_id($calling_post_id) != $attachment_id) {
        $thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"{$attachment_id}\");return false;'>" . esc_html__("Use as thumbnail") . "</a>";
    }
    if (($send || $thumbnail || $delete) && !isset($form_fields['buttons'])) {
        $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>{$send} {$thumbnail} {$delete}</td></tr>\n");
    }
    $hidden_fields = array();
    foreach ($form_fields as $id => $field) {
        if ($id[0] == '_') {
            continue;
        }
        if (!empty($field['tr'])) {
            $item .= $field['tr'];
            continue;
        }
        $field = array_merge($defaults, $field);
        $name = "attachments[{$attachment_id}][{$id}]";
        if ($field['input'] == 'hidden') {
            $hidden_fields[$name] = $field['value'];
            continue;
        }
        $required = $field['required'] ? '<abbr title="required" class="required">*</abbr>' : '';
        $aria_required = $field['required'] ? " aria-required='true' " : '';
        $class = $id;
        $class .= $field['required'] ? ' form-required' : '';
        $item .= "\t\t<tr class='{$class}'>\n\t\t\t<th valign='top' scope='row' class='label'><label for='{$name}'><span class='alignleft'>{$field['label']}</span><span class='alignright'>{$required}</span><br class='clear' /></label></th>\n\t\t\t<td class='field'>";
        if (!empty($field[$field['input']])) {
            $item .= $field[$field['input']];
        } elseif ($field['input'] == 'textarea') {
            $item .= "<textarea type='text' id='{$name}' name='{$name}'" . $aria_required . ">" . esc_html($field['value']) . "</textarea>";
        } else {
            $item .= "<input type='text' class='text' id='{$name}' name='{$name}' value='" . esc_attr($field['value']) . "'" . $aria_required . "/>";
        }
        if (!empty($field['helps'])) {
            $item .= "<p class='help'>" . join("</p>\n<p class='help'>", array_unique((array) $field['helps'])) . '</p>';
        }
        $item .= "</td>\n\t\t</tr>\n";
        $extra_rows = array();
        if (!empty($field['errors'])) {
            foreach (array_unique((array) $field['errors']) as $error) {
                $extra_rows['error'][] = $error;
            }
        }
        if (!empty($field['extra_rows'])) {
            foreach ($field['extra_rows'] as $class => $rows) {
                foreach ((array) $rows as $html) {
                    $extra_rows[$class][] = $html;
                }
            }
        }
        foreach ($extra_rows as $class => $rows) {
            foreach ($rows as $html) {
                $item .= "\t\t<tr><td></td><td class='{$class}'>{$html}</td></tr>\n";
            }
        }
    }
    if (!empty($form_fields['_final'])) {
        $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
    }
    $item .= "\t</tbody>\n";
    $item .= "\t</table>\n";
    //  $item .= "<img class='thumbnail hidden' src='$thumb_url' alt='' />";
    foreach ($hidden_fields as $name => $value) {
        $item .= "\t<input type='hidden' name='{$name}' id='{$name}' value='" . esc_attr($value) . "' />\n";
    }
    if ($post->post_parent < 1 && isset($_REQUEST['post_id'])) {
        $parent = (int) $_REQUEST['post_id'];
        $parent_name = $prefix . "attachments[{$attachment_id}][post_parent]";
        $item .= "\t<input type='hidden' name='{$parent_name}' id='{$parent_name}' value='" . $parent . "' />\n";
    }
    return $item;
}
コード例 #18
0
ファイル: post.php プロジェクト: nicholasgriffintn/WordPress
/**
 * 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|false $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)
{
    wp(wp_edit_attachments_query_vars($q));
    $post_mime_types = get_post_mime_types();
    $avail_post_mime_types = get_available_post_mime_types('attachment');
    return array($post_mime_types, $avail_post_mime_types);
}
コード例 #19
0
ファイル: upload.php プロジェクト: BackupTheBerlios/oos-svn
		$media_per_page = 20;
	$media_per_page = apply_filters( 'upload_per_page', $media_per_page );

	if ( !empty($lost) ) {
		$start = ( (int) $_GET['paged'] - 1 ) * $media_per_page;
		$page_links_total = ceil(count($lost) / $media_per_page);
		$lost = implode(',', $lost);

		$orphans = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_type = 'attachment' AND ID IN (%s) LIMIT %d, %d", $lost, $start, $media_per_page ) );
	} else {
		$start = ( (int) $_GET['paged'] - 1 ) * $media_per_page;
		$orphans = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1 LIMIT %d, %d", $start, $media_per_page ) );
		$page_links_total = ceil($wpdb->get_var( "SELECT FOUND_ROWS()" ) / $media_per_page);
	}

	$post_mime_types = get_post_mime_types();
	$avail_post_mime_types = get_available_post_mime_types('attachment');

	if ( isset($_GET['post_mime_type']) && !array_intersect( (array) $_GET['post_mime_type'], array_keys($post_mime_types) ) )
		unset($_GET['post_mime_type']);

} else {
	list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
}

$is_trash = ( isset($_GET['status']) && $_GET['status'] == 'trash' );

wp_enqueue_script('media');
require_once('admin-header.php');

do_action('restrict_manage_posts');
コード例 #20
0
ファイル: media.php プロジェクト: HaraShun/WordPress
/**
 * 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 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);
    $current_post_id = !empty($_GET['post_id']) ? (int) $_GET['post_id'] : 0;
    $default_args = array('errors' => null, 'send' => $current_post_id ? post_type_supports(get_post_type($current_post_id), 'editor') : true, 'delete' => true, 'toggle' => true, 'show_title' => true);
    $args = wp_parse_args($args, $default_args);
    /**
     * Filter the arguments used to retrieve an image for the edit image form.
     *
     * @since 3.1.0
     *
     * @see get_media_item
     *
     * @param array $args An array of arguments.
     */
    $r = apply_filters('get_media_item_args', $args);
    $toggle_on = __('Show');
    $toggle_off = __('Hide');
    $filename = esc_html(wp_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) . "' />";
    $form_fields = get_attachment_fields_to_edit($post, $r['errors']);
    if ($r['toggle']) {
        $class = empty($r['errors']) ? 'startclosed' : 'startopen';
        $toggle_links = "\n\t<a class='toggle describe-toggle-on' href='#'>{$toggle_on}</a>\n\t<a class='toggle describe-toggle-off' href='#'>{$toggle_off}</a>";
    } else {
        $class = '';
        $toggle_links = '';
    }
    $display_title = !empty($title) ? $title : $filename;
    // $title shouldn't ever be empty, but just in case
    $display_title = $r['show_title'] ? "<div class='filename new'><span class='title'>" . wp_html_excerpt($display_title, 60, '&hellip;') . "</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 (isset($meta['width'], $meta['height'])) {
        $media_dims .= "<span id='media-dims-{$post->ID}'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
    }
    /**
     * Filter the media metadata.
     *
     * @since 2.5.0
     *
     * @param string  $media_dims The HTML markup containing the media dimensions.
     * @param WP_Post $post       The WP_Post attachment object.
     */
    $media_dims = apply_filters('media_meta', $media_dims, $post);
    $image_edit_button = '';
    if (wp_attachment_is_image($post->ID) && wp_image_editor_supports(array('mime_type' => $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>";
    }
    $attachment_url = get_permalink($attachment_id);
    $item = "\n\t{$type_html}\n\t{$toggle_links}\n\t{$order}\n\t{$display_title}\n\t<table class='slidetoggle describe {$class}'>\n\t\t<thead class='media-item-info' id='media-head-{$post->ID}'>\n\t\t<tr>\n\t\t\t<td class='A1B1' id='thumbnail-head-{$post->ID}'>\n\t\t\t<p><a href='{$attachment_url}' target='_blank'><img class='thumbnail' src='{$thumb_url}' alt='' /></a></p>\n\t\t\t<p>{$image_edit_button}</p>\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t<p><strong>" . __('File name:') . "</strong> {$filename}</p>\n\t\t\t<p><strong>" . __('File type:') . "</strong> {$post->post_mime_type}</p>\n\t\t\t<p><strong>" . __('Upload date:') . "</strong> " . mysql2date(get_option('date_format'), $post->post_date) . '</p>';
    if (!empty($media_dims)) {
        $item .= "<p><strong>" . __('Dimensions:') . "</strong> {$media_dims}</p>\n";
    }
    $item .= "</td></tr>\n";
    $item .= "\n\t\t</thead>\n\t\t<tbody>\n\t\t<tr><td colspan='2' class='imgedit-response' id='imgedit-response-{$post->ID}'></td></tr>\n\t\t<tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-{$post->ID}'></td></tr>\n";
    $defaults = array('input' => 'text', 'required' => false, 'value' => '', 'extra_rows' => array());
    if ($r['send']) {
        $r['send'] = get_submit_button(__('Insert into Post'), 'button', "send[{$attachment_id}]", false);
    }
    $delete = empty($r['delete']) ? '' : $r['delete'];
    if ($delete && current_user_can('delete_post', $attachment_id)) {
        if (!EMPTY_TRASH_DAYS) {
            $delete = "<a href='" . wp_nonce_url("post.php?action=delete&amp;post={$attachment_id}", 'delete-post_' . $attachment_id) . "' id='del[{$attachment_id}]' class='delete-permanently'>" . __('Delete Permanently') . '</a>';
        } elseif (!MEDIA_TRASH) {
            $delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_{$attachment_id}').style.display='block';return false;\">" . __('Delete') . "</a>\n\t\t\t <div id='del_attachment_{$attachment_id}' class='del-attachment' style='display:none;'><p>" . sprintf(__('You are about to delete <strong>%s</strong>.'), $filename) . "</p>\n\t\t\t <a href='" . wp_nonce_url("post.php?action=delete&amp;post={$attachment_id}", 'delete-post_' . $attachment_id) . "' id='del[{$attachment_id}]' class='button'>" . __('Continue') . "</a>\n\t\t\t <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __('Cancel') . "</a>\n\t\t\t </div>";
        } else {
            $delete = "<a href='" . wp_nonce_url("post.php?action=trash&amp;post={$attachment_id}", 'trash-post_' . $attachment_id) . "' id='del[{$attachment_id}]' class='delete'>" . __('Move to Trash') . "</a>\n\t\t\t<a href='" . wp_nonce_url("post.php?action=untrash&amp;post={$attachment_id}", 'untrash-post_' . $attachment_id) . "' id='undo[{$attachment_id}]' class='undo hidden'>" . __('Undo') . "</a>";
        }
    } else {
        $delete = '';
    }
    $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-{$calling_post_id}");
        $thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"{$attachment_id}\", \"{$ajax_nonce}\");return false;'>" . esc_html__("Use as featured image") . "</a>";
    }
    if (($r['send'] || $thumbnail || $delete) && !isset($form_fields['buttons'])) {
        $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>" . $r['send'] . " {$thumbnail} {$delete}</td></tr>\n");
    }
    $hidden_fields = array();
    foreach ($form_fields as $id => $field) {
        if ($id[0] == '_') {
            continue;
        }
        if (!empty($field['tr'])) {
            $item .= $field['tr'];
            continue;
        }
        $field = array_merge($defaults, $field);
        $name = "attachments[{$attachment_id}][{$id}]";
        if ($field['input'] == 'hidden') {
            $hidden_fields[$name] = $field['value'];
            continue;
        }
        $required = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : '';
        $aria_required = $field['required'] ? " aria-required='true' " : '';
        $class = $id;
        $class .= $field['required'] ? ' form-required' : '';
        $item .= "\t\t<tr class='{$class}'>\n\t\t\t<th scope='row' class='label'><label for='{$name}'><span class='alignleft'>{$field['label']}</span>{$required}<br class='clear' /></label></th>\n\t\t\t<td class='field'>";
        if (!empty($field[$field['input']])) {
            $item .= $field[$field['input']];
        } elseif ($field['input'] == 'textarea') {
            if ('post_content' == $id && user_can_richedit()) {
                // Sanitize_post() skips the post_content when user_can_richedit.
                $field['value'] = htmlspecialchars($field['value'], ENT_QUOTES);
            }
            // Post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit().
            $item .= "<textarea id='{$name}' name='{$name}' {$aria_required}>" . $field['value'] . '</textarea>';
        } else {
            $item .= "<input type='text' class='text' id='{$name}' name='{$name}' value='" . esc_attr($field['value']) . "' {$aria_required} />";
        }
        if (!empty($field['helps'])) {
            $item .= "<p class='help'>" . join("</p>\n<p class='help'>", array_unique((array) $field['helps'])) . '</p>';
        }
        $item .= "</td>\n\t\t</tr>\n";
        $extra_rows = array();
        if (!empty($field['errors'])) {
            foreach (array_unique((array) $field['errors']) as $error) {
                $extra_rows['error'][] = $error;
            }
        }
        if (!empty($field['extra_rows'])) {
            foreach ($field['extra_rows'] as $class => $rows) {
                foreach ((array) $rows as $html) {
                    $extra_rows[$class][] = $html;
                }
            }
        }
        foreach ($extra_rows as $class => $rows) {
            foreach ($rows as $html) {
                $item .= "\t\t<tr><td></td><td class='{$class}'>{$html}</td></tr>\n";
            }
        }
    }
    if (!empty($form_fields['_final'])) {
        $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
    }
    $item .= "\t</tbody>\n";
    $item .= "\t</table>\n";
    foreach ($hidden_fields as $name => $value) {
        $item .= "\t<input type='hidden' name='{$name}' id='{$name}' value='" . esc_attr($value) . "' />\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;
}
コード例 #21
0
ファイル: media.php プロジェクト: nathanalexander/wordpress
/**
 * 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(
		// handler action suffix => tab label
		'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' ),
		),
		'post'    => array(
			'id' => 0,
		),
	);

	$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(
		// Generic
		'url'         => __( 'URL' ),
		'addMedia'    => __( 'Add Media' ),
		'search'      => __( 'Search' ),
		'select'      => __( 'Select' ),
		'cancel'      => __( 'Cancel' ),
		/* translators: This is a would-be plural string used in the media manager.
		   If there is not a word you can use in your language to avoid issues with the
		   lack of plural support here, turn it into "selected: %d" then translate it.
		 */
		'selected'    => __( '%d selected' ),
		'dragInfo'    => __( 'Drag and drop to reorder images.' ),

		// Upload
		'uploadFilesTitle'  => __( 'Upload Files' ),
		'uploadImagesTitle' => __( 'Upload Images' ),

		// Library
		'mediaLibraryTitle'  => __( 'Media Library' ),
		'insertMediaTitle'   => __( 'Insert Media' ),
		'createNewGallery'   => __( 'Create a new gallery' ),
		'returnToLibrary'    => __( '&#8592; 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." ),

		// From URL
		'insertFromUrlTitle' => __( 'Insert from URL' ),

		// Featured Images
		'setFeaturedImageTitle' => __( 'Set Featured Image' ),
		'setFeaturedImage'    => __( 'Set featured image' ),

		// Gallery
		'createGalleryTitle' => __( 'Create Gallery' ),
		'editGalleryTitle'   => __( 'Edit Gallery' ),
		'cancelGalleryTitle' => __( '&#8592; 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' );

	do_action( 'wp_enqueue_media' );
}