wp/wp-admin/includes/media.php
author ymh <ymh.work@gmail.com>
Mon, 14 Oct 2019 17:39:30 +0200
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
permissions -rw-r--r--
resynchronize code repo with production
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * WordPress Administration Media API.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Administration
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 * Defines the default media upload tabs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * @return array default tabs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
function media_upload_tabs() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
	$_default_tabs = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
		'type' => __('From Computer'), // handler action suffix => tab text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
		'type_url' => __('From URL'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
		'gallery' => __('Gallery'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
		'library' => __('Media Library')
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    25
	 * Filters the available tabs in the legacy (pre-3.5.0) media popup.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    26
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    27
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    29
	 * @param array $_default_tabs An array of media tabs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    31
	return apply_filters( 'media_upload_tabs', $_default_tabs );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
 * Adds the gallery tab back to the tabs array if post has image attachments
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    39
 * @global wpdb $wpdb WordPress database abstraction object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    40
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
 * @param array $tabs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
 * @return array $tabs with gallery if post has image attachment
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
function update_gallery_tab($tabs) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
	if ( !isset($_REQUEST['post_id']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
		unset($tabs['gallery']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
		return $tabs;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
	$post_id = intval($_REQUEST['post_id']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
	if ( $post_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
		$attachments = intval( $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
	if ( empty($attachments) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
		unset($tabs['gallery']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
		return $tabs;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	$tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
	return $tabs;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    68
 * Outputs the legacy media upload tabs UI.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
 * @since 2.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    71
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    72
 * @global string $redir_tab
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
function the_media_upload_tabs() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
	global $redir_tab;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
	$tabs = media_upload_tabs();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
	$default = 'type';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
	if ( !empty($tabs) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
		echo "<ul id='sidemenu'>\n";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
		if ( isset($redir_tab) && array_key_exists($redir_tab, $tabs) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
			$current = $redir_tab;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    83
		} elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
			$current = $_GET['tab'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    85
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    86
			/** This filter is documented in wp-admin/media-upload.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    87
			$current = apply_filters( 'media_upload_default_tab', $default );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
		foreach ( $tabs as $callback => $text ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
			$class = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
			if ( $current == $callback )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
				$class = " class='current'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
			$href = add_query_arg(array('tab' => $callback, 's' => false, 'paged' => false, 'post_mime_type' => false, 'm' => false));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
			$link = "<a href='" . esc_url($href) . "'$class>$text</a>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
			echo "\t<li id='" . esc_attr("tab-$callback") . "'>$link</li>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
		echo "</ul>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   105
 * Retrieves the image HTML to send to the editor.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   109
 * @param int          $id      Image attachment id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   110
 * @param string       $caption Image caption.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   111
 * @param string       $title   Image title attribute.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   112
 * @param string       $align   Image CSS alignment property.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   113
 * @param string       $url     Optional. Image src URL. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   114
 * @param bool|string  $rel     Optional. Value for rel attribute or whether to add a default value. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   115
 * @param string|array $size    Optional. Image size. Accepts any valid image size, or an array of width
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   116
 *                              and height values in pixels (in that order). Default 'medium'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   117
 * @param string       $alt     Optional. Image alt attribute. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   118
 * @return string The HTML output to insert into the editor.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   120
function get_image_send_to_editor( $id, $caption, $title, $align, $url = '', $rel = false, $size = 'medium', $alt = '' ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   121
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   122
	$html = get_image_tag( $id, $alt, '', $align, $size );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   123
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   124
	if ( $rel ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   125
		if ( is_string( $rel ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   126
			$rel = ' rel="' . esc_attr( $rel ) . '"';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   127
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   128
			$rel = ' rel="attachment wp-att-' . intval( $id ) . '"';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   129
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   130
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   131
		$rel = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   132
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
	if ( $url )
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   135
		$html = '<a href="' . esc_attr( $url ) . '"' . $rel . '>' . $html . '</a>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   137
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   138
	 * Filters the image HTML markup to send to the editor when inserting an image.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   139
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   140
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   142
	 * @param string       $html    The image HTML markup to send.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   143
	 * @param int          $id      The attachment id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   144
	 * @param string       $caption The image caption.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   145
	 * @param string       $title   The image title.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   146
	 * @param string       $align   The image alignment.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   147
	 * @param string       $url     The image source URL.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   148
	 * @param string|array $size    Size of image. Image size or array of width and height values
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   149
	 *                              (in that order). Default 'medium'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   150
	 * @param string       $alt     The image alternative, or alt, text.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   151
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
	$html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
	return $html;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
 * Adds image shortcode with caption to editor
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
 * @param string $html
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
 * @param integer $id
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
 * @param string $caption image caption
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
 * @param string $title image title attribute
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
 * @param string $align image css alignment property
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
 * @param string $url image src url
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
 * @param string $size image size (thumbnail, medium, large, full or added with add_image_size() )
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   169
 * @param string $alt image alt attribute
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   175
	 * Filters the caption text.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   176
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   177
	 * Note: If the caption text is empty, the caption shortcode will not be appended
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   178
	 * to the image HTML when inserted into the editor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   180
	 * Passing an empty value also prevents the {@see 'image_add_caption_shortcode'}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   181
	 * Filters from being evaluated at the end of image_add_caption().
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   182
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   183
	 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   184
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   185
	 * @param string $caption The original caption text.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   186
	 * @param int    $id      The attachment ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   188
	$caption = apply_filters( 'image_add_caption_text', $caption, $id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   189
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   190
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   191
	 * Filters whether to disable captions.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   192
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   193
	 * Prevents image captions from being appended to image HTML when inserted into the editor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   194
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   195
	 * @since 2.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   196
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   197
	 * @param bool $bool Whether to disable appending captions. Returning true to the filter
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   198
	 *                   will disable captions. Default empty string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
	if ( empty($caption) || apply_filters( 'disable_captions', '' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
		return $html;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
	$id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
	if ( ! preg_match( '/width=["\']([0-9]+)/', $html, $matches ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
		return $html;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
	$width = $matches[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
	$caption = str_replace( array("\r\n", "\r"), "\n", $caption);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
	$caption = preg_replace_callback( '/<[a-zA-Z0-9]+(?: [^<>]+>)*/', '_cleanup_image_add_caption', $caption );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   212
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   213
	// Convert any remaining line breaks to <br>.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
	$caption = preg_replace( '/[ \n\t]*\n[ \t]*/', '<br />', $caption );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
	$html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
	if ( empty($align) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
		$align = 'none';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
	$shcode = '[caption id="' . $id . '" align="align' . $align	. '" width="' . $width . '"]' . $html . ' ' . $caption . '[/caption]';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   222
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   223
	 * Filters the image HTML markup including the caption shortcode.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   224
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   225
	 * @since 2.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   226
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
	 * @param string $shcode The image HTML markup with caption shortcode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   228
	 * @param string $html   The image HTML markup.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   229
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
	return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
 * Private preg_replace callback used in image_add_caption()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
function _cleanup_image_add_caption( $matches ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   240
	// Remove any line breaks from inside the tags.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
	return preg_replace( '/[\r\n\t]+/', ' ', $matches[0] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
 * Adds image html to editor
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
 * @param string $html
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
function media_send_to_editor($html) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
var win = window.dialogArguments || opener || parent || top;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   255
win.send_to_editor( <?php echo wp_json_encode( $html ); ?> );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
	exit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   262
 * Save a file submitted from a POST request and create an attachment post for it.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   266
 * @param string $file_id   Index of the `$_FILES` array that the file was sent. Required.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   267
 * @param int    $post_id   The post ID of a post to attach the media item to. Required, but can
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   268
 *                          be set to 0, creating a media item that has no relationship to a post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   269
 * @param array  $post_data Overwrite some of the attachment. Optional.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   270
 * @param array  $overrides Override the wp_handle_upload() behavior. Optional.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   271
 * @return int|WP_Error ID of the attachment or a WP_Error object on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
	$time = current_time('mysql');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
	if ( $post = get_post($post_id) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   277
		// The post date doesn't usually matter for pages, so don't backdate this upload.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   278
		if ( 'page' !== $post->post_type && substr( $post->post_date, 0, 4 ) > 0 )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
			$time = $post->post_date;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
	$file = wp_handle_upload($_FILES[$file_id], $overrides, $time);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
	if ( isset($file['error']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
		return new WP_Error( 'upload_error', $file['error'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   287
	$name = $_FILES[$file_id]['name'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   288
	$ext  = pathinfo( $name, PATHINFO_EXTENSION );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   289
	$name = wp_basename( $name, ".$ext" );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
	$url = $file['url'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
	$type = $file['type'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
	$file = $file['file'];
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   294
	$title = sanitize_text_field( $name );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
	$content = '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
	$excerpt = '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
	if ( preg_match( '#^audio#', $type ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
		$meta = wp_read_audio_metadata( $file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   301
		if ( ! empty( $meta['title'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
			$title = $meta['title'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   303
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
		if ( ! empty( $title ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
			if ( ! empty( $meta['album'] ) && ! empty( $meta['artist'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
				/* translators: 1: audio track title, 2: album title, 3: artist name */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
				$content .= sprintf( __( '"%1$s" from %2$s by %3$s.' ), $title, $meta['album'], $meta['artist'] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   310
			} elseif ( ! empty( $meta['album'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
				/* translators: 1: audio track title, 2: album title */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
				$content .= sprintf( __( '"%1$s" from %2$s.' ), $title, $meta['album'] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   313
			} elseif ( ! empty( $meta['artist'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
				/* translators: 1: audio track title, 2: artist name */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
				$content .= sprintf( __( '"%1$s" by %2$s.' ), $title, $meta['artist'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
			} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   317
				/* translators: 1: audio track title */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
				$content .= sprintf( __( '"%s".' ), $title );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   321
		} elseif ( ! empty( $meta['album'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
			if ( ! empty( $meta['artist'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
				/* translators: 1: audio album title, 2: artist name */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
				$content .= sprintf( __( '%1$s by %2$s.' ), $meta['album'], $meta['artist'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
				$content .= $meta['album'] . '.';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
		} elseif ( ! empty( $meta['artist'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
			$content .= $meta['artist'] . '.';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   336
		if ( ! empty( $meta['year'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   337
			/* translators: Audio file track information. 1: Year of audio track release */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
			$content .= ' ' . sprintf( __( 'Released: %d.' ), $meta['year'] );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   339
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
		if ( ! empty( $meta['track_number'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
			$track_number = explode( '/', $meta['track_number'] );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   343
			if ( isset( $track_number[1] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   344
				/* translators: Audio file track information. 1: Audio track number, 2: Total audio tracks */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
				$content .= ' ' . sprintf( __( 'Track %1$s of %2$s.' ), number_format_i18n( $track_number[0] ), number_format_i18n( $track_number[1] ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   346
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   347
				/* translators: Audio file track information. 1: Audio track number */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
				$content .= ' ' . sprintf( __( 'Track %1$s.' ), number_format_i18n( $track_number[0] ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   349
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   352
		if ( ! empty( $meta['genre'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   353
			/* translators: Audio file genre information. 1: Audio genre name */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
			$content .= ' ' . sprintf( __( 'Genre: %s.' ), $meta['genre'] );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   355
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   357
	// Use image exif/iptc data for title and caption defaults if possible.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   358
	} elseif ( 0 === strpos( $type, 'image/' ) && $image_meta = wp_read_image_metadata( $file ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   359
		if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
			$title = $image_meta['title'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   361
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   362
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   363
		if ( trim( $image_meta['caption'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   364
			$excerpt = $image_meta['caption'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   365
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
	// Construct the attachment array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
	$attachment = array_merge( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
		'post_mime_type' => $type,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
		'guid' => $url,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
		'post_parent' => $post_id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
		'post_title' => $title,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
		'post_content' => $content,
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   375
		'post_excerpt' => $excerpt,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
	), $post_data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
	// This should never be set as it would then overwrite an existing attachment.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   379
	unset( $attachment['ID'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
	// Save the data
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   382
	$id = wp_insert_attachment( $attachment, $file, $post_id, true );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
	if ( !is_wp_error($id) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
		wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
	return $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   392
 * Handles a side-loaded file in the same way as an uploaded file is handled by media_handle_upload().
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   396
 * @param array  $file_array Array similar to a `$_FILES` upload array.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   397
 * @param int    $post_id    The post ID the media is associated with.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   398
 * @param string $desc       Optional. Description of the side-loaded file. Default null.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   399
 * @param array  $post_data  Optional. Post data to override. Default empty array.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   400
 * @return int|object The ID of the attachment or a WP_Error on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   402
function media_handle_sideload( $file_array, $post_id, $desc = null, $post_data = array() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
	$overrides = array('test_form'=>false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
	$time = current_time( 'mysql' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
	if ( $post = get_post( $post_id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
		if ( substr( $post->post_date, 0, 4 ) > 0 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
			$time = $post->post_date;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
	$file = wp_handle_sideload( $file_array, $overrides, $time );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
	if ( isset($file['error']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
		return new WP_Error( 'upload_error', $file['error'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
	$url = $file['url'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
	$type = $file['type'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
	$file = $file['file'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
	$title = preg_replace('/\.[^.]+$/', '', basename($file));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
	$content = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   421
	// Use image exif/iptc data for title and caption defaults if possible.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   422
	if ( $image_meta = wp_read_image_metadata( $file ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
		if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
			$title = $image_meta['title'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
		if ( trim( $image_meta['caption'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
			$content = $image_meta['caption'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
	if ( isset( $desc ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
		$title = $desc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   432
	// Construct the attachment array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
	$attachment = array_merge( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
		'post_mime_type' => $type,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
		'guid' => $url,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
		'post_parent' => $post_id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
		'post_title' => $title,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
		'post_content' => $content,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
	), $post_data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
	// This should never be set as it would then overwrite an existing attachment.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   442
	unset( $attachment['ID'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
	// Save the attachment metadata
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
	$id = wp_insert_attachment($attachment, $file, $post_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
	if ( !is_wp_error($id) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
		wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
	return $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
 * Adds the iframe to display content for the media upload page
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   457
 * @global int $body_id
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   458
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   459
 * @param string|callable $content_func
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
function wp_iframe($content_func /* ... */) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
	_wp_admin_html_begin();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
<title><?php bloginfo('name') ?> &rsaquo; <?php _e('Uploads'); ?> &#8212; <?php _e('WordPress'); ?></title>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
wp_enqueue_style( 'colors' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
// Check callback name for 'media'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
if ( ( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
	|| ( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) ) )
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   471
	wp_enqueue_style( 'deprecated-media' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
wp_enqueue_style( 'ie' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
isRtl = <?php echo (int) is_rtl(); ?>;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
<?php
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   480
	/** This action is documented in wp-admin/admin-header.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   481
	do_action( 'admin_enqueue_scripts', 'media-upload-popup' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   482
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   483
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   484
	 * Fires when admin styles enqueued for the legacy (pre-3.5.0) media upload popup are printed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   485
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   486
	 * @since 2.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   487
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   488
	do_action( 'admin_print_styles-media-upload-popup' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   489
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   490
	/** This action is documented in wp-admin/admin-header.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   491
	do_action( 'admin_print_styles' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   492
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   493
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   494
	 * Fires when admin scripts enqueued for the legacy (pre-3.5.0) media upload popup are printed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   495
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   496
	 * @since 2.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   497
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   498
	do_action( 'admin_print_scripts-media-upload-popup' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   499
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   500
	/** This action is documented in wp-admin/admin-header.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   501
	do_action( 'admin_print_scripts' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   502
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   503
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   504
	 * Fires when scripts enqueued for the admin header for the legacy (pre-3.5.0)
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   505
	 * media upload popup are printed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   506
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   507
	 * @since 2.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   508
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   509
	do_action( 'admin_head-media-upload-popup' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   510
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   511
	/** This action is documented in wp-admin/admin-header.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   512
	do_action( 'admin_head' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   513
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   514
if ( is_string( $content_func ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   515
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   516
	 * Fires in the admin header for each specific form tab in the legacy
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   517
	 * (pre-3.5.0) media upload popup.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   518
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   519
	 * The dynamic portion of the hook, `$content_func`, refers to the form
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   520
	 * callback for the media upload type. Possible values include
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   521
	 * 'media_upload_type_form', 'media_upload_type_url_form', and
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   522
	 * 'media_upload_library_form'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   523
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   524
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   525
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
	do_action( "admin_head_{$content_func}" );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   527
}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
</head>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
<body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="wp-core-ui no-js">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
document.body.className = document.body.className.replace('no-js', 'js');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
	$args = func_get_args();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
	$args = array_slice($args, 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
	call_user_func_array($content_func, $args);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   539
	/** This action is documented in wp-admin/admin-footer.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   540
	do_action( 'admin_print_footer_scripts' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
<script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
</body>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
</html>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
 * Adds the media button to the editor
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   553
 * @global int $post_ID
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   554
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   555
 * @staticvar int $instance
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   556
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
 * @param string $editor_id
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
function media_buttons($editor_id = 'content') {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   560
	static $instance = 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   561
	$instance++;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   562
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
	$post = get_post();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
	if ( ! $post && ! empty( $GLOBALS['post_ID'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
		$post = $GLOBALS['post_ID'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
	wp_enqueue_media( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
		'post' => $post
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
	) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
	$img = '<span class="wp-media-buttons-icon"></span> ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   573
	$id_attribute = $instance === 1 ? ' id="insert-media-button"' : '';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   574
	printf( '<button type="button"%s class="button insert-media add_media" data-editor="%s">%s</button>',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   575
		$id_attribute,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   576
		esc_attr( $editor_id ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   577
		$img . __( 'Add Media' )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   578
	);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   579
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   580
	 * Filters the legacy (pre-3.5.0) media buttons.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   581
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   582
	 * Use {@see 'media_buttons'} action instead.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   583
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   584
	 * @since 2.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   585
	 * @deprecated 3.5.0 Use {@see 'media_buttons'} action instead.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   586
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   587
	 * @param string $string Media buttons context. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   588
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   589
	$legacy_filter = apply_filters( 'media_buttons_context', '' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
	if ( $legacy_filter ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
		// #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
		if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
			$legacy_filter .= '</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
		echo $legacy_filter;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   599
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   600
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   601
 * @global int $post_ID
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   602
 * @param string $type
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   603
 * @param int $post_id
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   604
 * @param string $tab
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   605
 * @return string
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   606
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
	global $post_ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
	if ( empty( $post_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
		$post_id = $post_ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
	$upload_iframe_src = add_query_arg( 'post_id', (int) $post_id, admin_url('media-upload.php') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
	if ( $type && 'media' != $type )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
		$upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
	if ( ! empty( $tab ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
		$upload_iframe_src = add_query_arg('tab', $tab, $upload_iframe_src);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   621
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   622
	 * Filters the upload iframe source URL for a specific media type.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   623
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   624
	 * The dynamic portion of the hook name, `$type`, refers to the type
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   625
	 * of media uploaded.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   626
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   627
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   628
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   629
	 * @param string $upload_iframe_src The upload iframe source URL by type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   630
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   631
	$upload_iframe_src = apply_filters( "{$type}_upload_iframe_src", $upload_iframe_src );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
	return add_query_arg('TB_iframe', true, $upload_iframe_src);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   637
 * Handles form submissions for the legacy media uploader.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
 * @return mixed void|object WP_Error on failure
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
function media_upload_form_handler() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
	check_admin_referer('media-form');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
	$errors = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
	if ( isset($_POST['send']) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   649
		$keys = array_keys( $_POST['send'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   650
		$send_id = (int) reset( $keys );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
	if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
		$post = $_post = get_post($attachment_id, ARRAY_A);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
		if ( !current_user_can( 'edit_post', $attachment_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
		if ( isset($attachment['post_content']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
			$post['post_content'] = $attachment['post_content'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
		if ( isset($attachment['post_title']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
			$post['post_title'] = $attachment['post_title'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
		if ( isset($attachment['post_excerpt']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
			$post['post_excerpt'] = $attachment['post_excerpt'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
		if ( isset($attachment['menu_order']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
			$post['menu_order'] = $attachment['menu_order'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
		if ( isset($send_id) && $attachment_id == $send_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
			if ( isset($attachment['post_parent']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
				$post['post_parent'] = $attachment['post_parent'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   673
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   674
		 * Filters the attachment fields to be saved.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   675
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   676
		 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   677
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   678
		 * @see wp_get_attachment_metadata()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   679
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   680
		 * @param array $post       An array of post data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   681
		 * @param array $attachment An array of attachment metadata.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   682
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   683
		$post = apply_filters( 'attachment_fields_to_save', $post, $attachment );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
		if ( isset($attachment['image_alt']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
			$image_alt = wp_unslash( $attachment['image_alt'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
			if ( $image_alt != get_post_meta($attachment_id, '_wp_attachment_image_alt', true) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
				$image_alt = wp_strip_all_tags( $image_alt, true );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   689
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   690
				// Update_meta expects slashed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
				update_post_meta( $attachment_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
		if ( isset($post['errors']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
			$errors[$attachment_id] = $post['errors'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
			unset($post['errors']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
		if ( $post != $_post )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
			wp_update_post($post);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
		foreach ( get_attachment_taxonomies($post) as $t ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
			if ( isset($attachment[$t]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
				wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
	if ( isset($_POST['insert-gallery']) || isset($_POST['update-gallery']) ) { ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
		<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
		var win = window.dialogArguments || opener || parent || top;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
		win.tb_remove();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
		</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
		<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
		exit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
	if ( isset($send_id) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
		$attachment = wp_unslash( $_POST['attachments'][$send_id] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
		$html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
		if ( !empty($attachment['url']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
			$rel = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
			if ( strpos($attachment['url'], 'attachment_id') || get_attachment_link($send_id) == $attachment['url'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
				$rel = " rel='attachment wp-att-" . esc_attr($send_id) . "'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
			$html = "<a href='{$attachment['url']}'$rel>$html</a>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   729
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   730
		 * Filters the HTML markup for a media item sent to the editor.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   731
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   732
		 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   733
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   734
		 * @see wp_get_attachment_metadata()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   735
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   736
		 * @param string $html       HTML markup for a media item sent to the editor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   737
		 * @param int    $send_id    The first key from the $_POST['send'] data.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   738
		 * @param array  $attachment Array of attachment metadata.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   739
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   740
		$html = apply_filters( 'media_send_to_editor', $html, $send_id, $attachment );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
		return media_send_to_editor($html);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
	return $errors;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   748
 * Handles the process of uploading media.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   752
 * @return null|string
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
function wp_media_upload_handler() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
	$errors = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
	$id = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
	if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
		check_admin_referer('media-form');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
		// Upload File button was clicked
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
		$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
		unset($_FILES);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
		if ( is_wp_error($id) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
			$errors['upload_error'] = $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
			$id = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
	if ( !empty($_POST['insertonlybutton']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
		$src = $_POST['src'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
		if ( !empty($src) && !strpos($src, '://') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
			$src = "http://$src";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
		if ( isset( $_POST['media_type'] ) && 'image' != $_POST['media_type'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
			$title = esc_html( wp_unslash( $_POST['title'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
			if ( empty( $title ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
				$title = esc_html( basename( $src ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
			if ( $title && $src )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
				$html = "<a href='" . esc_url($src) . "'>$title</a>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
			$type = 'file';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
			if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
				&& ( 'audio' == $ext_type || 'video' == $ext_type ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
					$type = $ext_type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   787
			/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   788
			 * Filters the URL sent to the editor for a specific media type.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   789
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   790
			 * The dynamic portion of the hook name, `$type`, refers to the type
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   791
			 * of media being sent.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   792
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   793
			 * @since 3.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   794
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   795
			 * @param string $html  HTML markup sent to the editor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   796
			 * @param string $src   Media source URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   797
			 * @param string $title Media title.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   798
			 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   799
			$html = apply_filters( "{$type}_send_to_editor_url", $html, esc_url_raw( $src ), $title );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
			$align = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
			$alt = esc_attr( wp_unslash( $_POST['alt'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
			if ( isset($_POST['align']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
				$align = esc_attr( wp_unslash( $_POST['align'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
				$class = " class='align$align'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
			if ( !empty($src) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
				$html = "<img src='" . esc_url($src) . "' alt='$alt'$class />";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   810
			/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   811
			 * Filters the image URL sent to the editor.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   812
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   813
			 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   814
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   815
			 * @param string $html  HTML markup sent to the editor for an image.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   816
			 * @param string $src   Image source URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   817
			 * @param string $alt   Image alternate, or alt, text.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   818
			 * @param string $align The image alignment. Default 'alignnone'. Possible values include
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   819
			 *                      'alignleft', 'aligncenter', 'alignright', 'alignnone'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   820
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
			$html = apply_filters( 'image_send_to_editor_url', $html, esc_url_raw( $src ), $alt, $align );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   822
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
		return media_send_to_editor($html);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   827
	if ( isset( $_POST['save'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   828
		$errors['upload_notice'] = __('Saved.');
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   829
		wp_enqueue_script( 'admin-gallery' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   830
 		return wp_iframe( 'media_upload_gallery_form', $errors );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   831
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   832
	} elseif ( ! empty( $_POST ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
		$return = media_upload_form_handler();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
		if ( is_string($return) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   836
			return $return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
		if ( is_array($return) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
			$errors = $return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
	if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
		$type = 'image';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
		if ( isset( $_GET['type'] ) && in_array( $_GET['type'], array( 'video', 'audio', 'file' ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
			$type = $_GET['type'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
		return wp_iframe( 'media_upload_type_url_form', $type, $errors, $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
	return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   852
 * Downloads an image from the specified URL and attaches it to a post.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
 * @since 2.6.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   855
 * @since 4.2.0 Introduced the `$return` parameter.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   856
 * @since 4.8.0 Introduced the 'id' option within the `$return` parameter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   858
 * @param string $file    The URL of the image to download.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   859
 * @param int    $post_id The post ID the media is to be associated with.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   860
 * @param string $desc    Optional. Description of the image.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   861
 * @param string $return  Optional. Accepts 'html' (image tag html) or 'src' (URL), or 'id' (attachment ID). Default 'html'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   862
 * @return string|WP_Error Populated HTML img tag on success, WP_Error object otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   864
function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   865
	if ( ! empty( $file ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   866
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   867
		// Set variables for storage, fix file filename for query strings.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
		preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   869
		if ( ! $matches ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   870
			return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL' ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   871
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   872
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   873
		$file_array = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   874
		$file_array['name'] = basename( $matches[0] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   875
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   876
		// Download file to temp location.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   877
		$file_array['tmp_name'] = download_url( $file );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   878
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   879
		// If error storing temporarily, return the error.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   880
		if ( is_wp_error( $file_array['tmp_name'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   881
			return $file_array['tmp_name'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   884
		// Do the validation and storage stuff.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
		$id = media_handle_sideload( $file_array, $post_id, $desc );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   886
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   887
		// If error storing permanently, unlink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   888
		if ( is_wp_error( $id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   889
			@unlink( $file_array['tmp_name'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
			return $id;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   891
		// If attachment id was requested, return it early.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   892
		} elseif ( $return === 'id' ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   893
			return $id;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
		$src = wp_get_attachment_url( $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   899
	// Finally, check to make sure the file has been saved, then return the HTML.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   900
	if ( ! empty( $src ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   901
		if ( $return === 'src' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   902
			return $src;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   903
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   904
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   905
		$alt = isset( $desc ) ? esc_attr( $desc ) : '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
		$html = "<img src='$src' alt='$alt' />";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
		return $html;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   908
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   909
		return new WP_Error( 'image_sideload_failed' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   914
 * Retrieves the legacy media uploader form in an iframe.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   918
 * @return string|null
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
function media_upload_gallery() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
	$errors = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
	if ( !empty($_POST) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
		$return = media_upload_form_handler();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
		if ( is_string($return) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
			return $return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
		if ( is_array($return) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
			$errors = $return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
	wp_enqueue_script('admin-gallery');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
	return wp_iframe( 'media_upload_gallery_form', $errors );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   937
 * Retrieves the legacy media library form in an iframe.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   941
 * @return string|null
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
function media_upload_library() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
	$errors = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
	if ( !empty($_POST) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
		$return = media_upload_form_handler();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
		if ( is_string($return) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
			return $return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
		if ( is_array($return) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
			$errors = $return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
	return wp_iframe( 'media_upload_library_form', $errors );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
 * Retrieve HTML for the image alignment radio buttons with the specified one checked.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   962
 * @param WP_Post $post
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
 * @param string $checked
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
function image_align_input_fields( $post, $checked = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
	if ( empty($checked) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
		$checked = get_user_setting('align', 'none');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
	$alignments = array('none' => __('None'), 'left' => __('Left'), 'center' => __('Center'), 'right' => __('Right'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
	if ( !array_key_exists( (string) $checked, $alignments ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
		$checked = 'none';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
	$out = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
	foreach ( $alignments as $name => $label ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
		$name = esc_attr($name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   978
		$out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'".
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   979
			( $checked == $name ? " checked='checked'" : "" ) .
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   980
			" /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
	return join("\n", $out);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   986
 * Retrieve HTML for the size radio buttons with the specified one checked.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   987
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   988
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   990
 * @param WP_Post $post
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
 * @param bool|string $check
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
 * @return array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
function image_size_input_fields( $post, $check = '' ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   995
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   996
	 * Filters the names and labels of the default image sizes.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   997
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   998
	 * @since 3.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   999
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1000
	 * @param array $size_names Array of image sizes and their names. Default values
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1001
	 *                          include 'Thumbnail', 'Medium', 'Large', 'Full Size'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1002
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1003
	$size_names = apply_filters( 'image_size_names_choose', array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1004
		'thumbnail' => __( 'Thumbnail' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1005
		'medium'    => __( 'Medium' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1006
		'large'     => __( 'Large' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1007
		'full'      => __( 'Full Size' )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1008
	) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1009
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1010
	if ( empty( $check ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1011
		$check = get_user_setting('imgsize', 'medium');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1012
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1013
	$out = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1014
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1015
	foreach ( $size_names as $size => $label ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1016
		$downsize = image_downsize( $post->ID, $size );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1017
		$checked = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1018
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1019
		// Is this size selectable?
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1020
		$enabled = ( $downsize[3] || 'full' == $size );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1021
		$css_id = "image-size-{$size}-{$post->ID}";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1022
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1023
		// If this size is the default but that's not available, don't select it.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1024
		if ( $size == $check ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1025
			if ( $enabled ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
				$checked = " checked='checked'";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1027
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1028
				$check = '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1029
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1030
		} elseif ( ! $check && $enabled && 'thumbnail' != $size ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1031
			/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1032
			 * If $check is not enabled, default to the first available size
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1033
			 * that's bigger than a thumbnail.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1034
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1035
			$check = $size;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1036
			$checked = " checked='checked'";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1037
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1038
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1039
		$html = "<div class='image-size-item'><input type='radio' " . disabled( $enabled, false, false ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1040
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1041
		$html .= "<label for='{$css_id}'>$label</label>";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1042
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1043
		// Only show the dimensions if that choice is available.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1044
		if ( $enabled ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1045
			$html .= " <label for='{$css_id}' class='help'>" . sprintf( "(%d&nbsp;&times;&nbsp;%d)", $downsize[1], $downsize[2] ). "</label>";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1046
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1047
		$html .= '</div>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1048
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1049
		$out[] = $html;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1050
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1051
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1052
	return array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1053
		'label' => __( 'Size' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1054
		'input' => 'html',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1055
		'html'  => join( "\n", $out ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1056
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1057
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1058
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1060
 * Retrieve HTML for the Link URL buttons with the default link type as specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1061
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1062
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1063
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1064
 * @param WP_Post $post
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1065
 * @param string $url_type
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1066
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1067
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1068
function image_link_input_fields($post, $url_type = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1069
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1070
	$file = wp_get_attachment_url($post->ID);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1071
	$link = get_attachment_link($post->ID);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1072
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1073
	if ( empty($url_type) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1074
		$url_type = get_user_setting('urlbutton', 'post');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1075
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1076
	$url = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1077
	if ( $url_type == 'file' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1078
		$url = $file;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1079
	elseif ( $url_type == 'post' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1080
		$url = $link;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1081
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1082
	return "
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
	<input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1084
	<button type='button' class='button urlnone' data-link-url=''>" . __('None') . "</button>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1085
	<button type='button' class='button urlfile' data-link-url='" . esc_attr($file) . "'>" . __('File URL') . "</button>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1086
	<button type='button' class='button urlpost' data-link-url='" . esc_attr($link) . "'>" . __('Attachment Post URL') . "</button>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1087
";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1088
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1089
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1090
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1091
 * Output a textarea element for inputting an attachment caption.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1092
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1093
 * @since 3.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1094
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1095
 * @param WP_Post $edit_post Attachment WP_Post object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1096
 * @return string HTML markup for the textarea element.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1097
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1098
function wp_caption_input_textarea($edit_post) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1099
	// Post data is already escaped.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1100
	$name = "attachments[{$edit_post->ID}][post_excerpt]";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1101
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1102
	return '<textarea name="' . $name . '" id="' . $name . '">' . $edit_post->post_excerpt . '</textarea>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1104
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1105
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1106
 * Retrieves the image attachment fields to edit form fields.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1107
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1108
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1109
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1110
 * @param array $form_fields
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1111
 * @param object $post
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1112
 * @return array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1113
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1114
function image_attachment_fields_to_edit($form_fields, $post) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1115
	return $form_fields;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1116
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1117
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1118
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1119
 * Retrieves the single non-image attachment fields to edit form fields.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1120
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1122
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1123
 * @param array   $form_fields An array of attachment form fields.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1124
 * @param WP_Post $post        The WP_Post attachment object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1125
 * @return array Filtered attachment form fields.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1126
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1127
function media_single_attachment_fields_to_edit( $form_fields, $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1128
	unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1129
	return $form_fields;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1130
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1131
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1132
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1133
 * Retrieves the post non-image attachment fields to edito form fields.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1134
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1135
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1137
 * @param array   $form_fields An array of attachment form fields.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1138
 * @param WP_Post $post        The WP_Post attachment object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1139
 * @return array Filtered attachment form fields.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1140
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1141
function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1142
	unset($form_fields['image_url']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1143
	return $form_fields;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1144
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1145
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1146
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1147
 * Filters input from media_upload_form_handler() and assigns a default
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1148
 * post_title from the file name if none supplied.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1149
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1150
 * Illustrates the use of the {@see 'attachment_fields_to_save'} filter
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1151
 * which can be used to add default values to any field before saving to DB.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1152
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1153
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1154
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1155
 * @param array $post       The WP_Post attachment object converted to an array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1156
 * @param array $attachment An array of attachment metadata.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1157
 * @return array Filtered attachment post object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
function image_attachment_fields_to_save( $post, $attachment ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
	if ( substr( $post['post_mime_type'], 0, 5 ) == 'image' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
		if ( strlen( trim( $post['post_title'] ) ) == 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1162
			$attachment_url = ( isset( $post['attachment_url'] ) ) ? $post['attachment_url'] : $post['guid'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
			$post['post_title'] = preg_replace( '/\.\w+$/', '', wp_basename( $attachment_url ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1164
			$post['errors']['post_title']['errors'][] = __( 'Empty Title filled from filename.' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1165
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1167
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1168
	return $post;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1169
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1171
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1172
 * Retrieves the media element HTML to send to the editor.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1173
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1174
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1175
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1176
 * @param string $html
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1177
 * @param integer $attachment_id
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
 * @param array $attachment
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1179
 * @return string
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1181
function image_media_send_to_editor($html, $attachment_id, $attachment) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1182
	$post = get_post($attachment_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1183
	if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1184
		$url = $attachment['url'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
		$align = !empty($attachment['align']) ? $attachment['align'] : 'none';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1186
		$size = !empty($attachment['image-size']) ? $attachment['image-size'] : 'medium';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1187
		$alt = !empty($attachment['image_alt']) ? $attachment['image_alt'] : '';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1188
		$rel = ( strpos( $url, 'attachment_id') || $url === get_attachment_link( $attachment_id ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1189
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1190
		return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1192
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
	return $html;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1194
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1197
 * Retrieves the attachment fields to edit form fields.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1199
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1201
 * @param WP_Post $post
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1202
 * @param array $errors
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1203
 * @return array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1204
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1205
function get_attachment_fields_to_edit($post, $errors = null) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1206
	if ( is_int($post) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1207
		$post = get_post($post);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
	if ( is_array($post) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1209
		$post = new WP_Post( (object) $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1210
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1211
	$image_url = wp_get_attachment_url($post->ID);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1212
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1213
	$edit_post = sanitize_post($post, 'edit');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1214
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1215
	$form_fields = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1216
		'post_title'   => array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1217
			'label'      => __('Title'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1218
			'value'      => $edit_post->post_title
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1219
		),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1220
		'image_alt'   => array(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1221
		'post_excerpt' => array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1222
			'label'      => __('Caption'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1223
			'input'      => 'html',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1224
			'html'       => wp_caption_input_textarea($edit_post)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1225
		),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1226
		'post_content' => array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1227
			'label'      => __('Description'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1228
			'value'      => $edit_post->post_content,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1229
			'input'      => 'textarea'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1230
		),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1231
		'url'          => array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1232
			'label'      => __('Link URL'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1233
			'input'      => 'html',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1234
			'html'       => image_link_input_fields($post, get_option('image_default_link_type')),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1235
			'helps'      => __('Enter a link URL or click above for presets.')
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1236
		),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1237
		'menu_order'   => array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1238
			'label'      => __('Order'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1239
			'value'      => $edit_post->menu_order
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1240
		),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1241
		'image_url'	=> array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1242
			'label'      => __('File URL'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1243
			'input'      => 'html',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1244
			'html'       => "<input type='text' class='text urlfield' readonly='readonly' name='attachments[$post->ID][url]' value='" . esc_attr($image_url) . "' /><br />",
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1245
			'value'      => wp_get_attachment_url($post->ID),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1246
			'helps'      => __('Location of the uploaded file.')
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1247
		)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1248
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1249
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1250
	foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
		$t = (array) get_taxonomy($taxonomy);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1252
		if ( ! $t['public'] || ! $t['show_ui'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1253
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1254
		if ( empty($t['label']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1255
			$t['label'] = $taxonomy;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1256
		if ( empty($t['args']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1257
			$t['args'] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1258
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
		$terms = get_object_term_cache($post->ID, $taxonomy);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1260
		if ( false === $terms )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1261
			$terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1262
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1263
		$values = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1264
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1265
		foreach ( $terms as $term )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1266
			$values[] = $term->slug;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1267
		$t['value'] = join(', ', $values);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1268
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1269
		$form_fields[$taxonomy] = $t;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1270
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1271
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1272
	// Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1273
	// The recursive merge is easily traversed with array casting: foreach ( (array) $things as $thing )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1274
	$form_fields = array_merge_recursive($form_fields, (array) $errors);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1275
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1276
	// This was formerly in image_attachment_fields_to_edit().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1277
	if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1278
		$alt = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1279
		if ( empty($alt) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1280
			$alt = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1281
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1282
		$form_fields['post_title']['required'] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1283
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1284
		$form_fields['image_alt'] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1285
			'value' => $alt,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1286
			'label' => __('Alternative Text'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1287
			'helps' => __('Alt text for the image, e.g. &#8220;The Mona Lisa&#8221;')
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1288
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1289
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1290
		$form_fields['align'] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1291
			'label' => __('Alignment'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1292
			'input' => 'html',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1293
			'html'  => image_align_input_fields($post, get_option('image_default_align')),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1294
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1295
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1296
		$form_fields['image-size'] = image_size_input_fields( $post, get_option('image_default_size', 'medium') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1297
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1298
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1299
		unset( $form_fields['image_alt'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1300
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1301
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1302
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1303
	 * Filters the attachment fields to edit.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1304
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1305
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1306
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1307
	 * @param array   $form_fields An array of attachment form fields.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1308
	 * @param WP_Post $post        The WP_Post attachment object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1309
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1310
	$form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1311
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
	return $form_fields;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1313
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1314
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1316
 * Retrieve HTML for media items of post gallery.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1317
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
 * The HTML markup retrieved will be created for the progress of SWF Upload
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
 * component. Will also create link for showing and hiding the form to modify
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1320
 * the image attachment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1321
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1322
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1323
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1324
 * @global WP_Query $wp_the_query
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1325
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1326
 * @param int $post_id Optional. Post ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1327
 * @param array $errors Errors for attachment, if any.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1328
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1329
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1330
function get_media_items( $post_id, $errors ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1331
	$attachments = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1332
	if ( $post_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1333
		$post = get_post($post_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1334
		if ( $post && $post->post_type == 'attachment' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1335
			$attachments = array($post->ID => $post);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1336
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1337
			$attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1338
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1339
		if ( is_array($GLOBALS['wp_the_query']->posts) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1340
			foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1341
				$attachments[$attachment->ID] = $attachment;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1342
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1343
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1344
	$output = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1345
	foreach ( (array) $attachments as $id => $attachment ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1346
		if ( $attachment->post_status == 'trash' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1347
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1348
		if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1349
			$output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div class='progress hidden'><div class='bar'></div></div><div id='media-upload-error-$id' class='hidden'></div><div class='filename hidden'></div>$item\n</div>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1350
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1351
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1352
	return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1353
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1354
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1355
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1356
 * Retrieve HTML form for modifying the image attachment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1357
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1359
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1360
 * @global string $redir_tab
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1361
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1362
 * @param int $attachment_id Attachment ID for modification.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1363
 * @param string|array $args Optional. Override defaults.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1364
 * @return string HTML form for attachment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1365
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1366
function get_media_item( $attachment_id, $args = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1367
	global $redir_tab;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1368
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1369
	if ( ( $attachment_id = intval( $attachment_id ) ) && $thumb_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail', true ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1370
		$thumb_url = $thumb_url[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1372
		$thumb_url = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1373
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1374
	$post = get_post( $attachment_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1375
	$current_post_id = !empty( $_GET['post_id'] ) ? (int) $_GET['post_id'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1376
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1377
	$default_args = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1378
		'errors' => null,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1379
		'send' => $current_post_id ? post_type_supports( get_post_type( $current_post_id ), 'editor' ) : true,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1380
		'delete' => true,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1381
		'toggle' => true,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1382
		'show_title' => true
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1383
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1384
	$args = wp_parse_args( $args, $default_args );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1385
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1386
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1387
	 * Filters the arguments used to retrieve an image for the edit image form.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1388
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1389
	 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1390
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1391
	 * @see get_media_item
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1392
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1393
	 * @param array $args An array of arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1394
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1395
	$r = apply_filters( 'get_media_item_args', $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1396
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1397
	$toggle_on  = __( 'Show' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1398
	$toggle_off = __( 'Hide' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1399
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1400
	$file = get_attached_file( $post->ID );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1401
	$filename = esc_html( wp_basename( $file ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1402
	$title = esc_attr( $post->post_title );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1403
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1404
	$post_mime_types = get_post_mime_types();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1405
	$keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1406
	$type = reset( $keys );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1407
	$type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1408
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1409
	$form_fields = get_attachment_fields_to_edit( $post, $r['errors'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1410
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1411
	if ( $r['toggle'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1412
		$class = empty( $r['errors'] ) ? 'startclosed' : 'startopen';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1413
		$toggle_links = "
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1414
	<a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1415
	<a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1416
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1417
		$class = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1418
		$toggle_links = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1419
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1420
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1421
	$display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1422
	$display_title = $r['show_title'] ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60, '&hellip;' ) . "</span></div>" : '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1423
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1424
	$gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1425
	$order = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1426
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1427
	foreach ( $form_fields as $key => $val ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1428
		if ( 'menu_order' == $key ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1429
			if ( $gallery )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1430
				$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>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1431
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1432
				$order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1433
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1434
			unset( $form_fields['menu_order'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1435
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1436
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1437
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1438
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1439
	$media_dims = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1440
	$meta = wp_get_attachment_metadata( $post->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1441
	if ( isset( $meta['width'], $meta['height'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1442
		$media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1443
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1444
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1445
	 * Filters the media metadata.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1446
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1447
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1448
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1449
	 * @param string  $media_dims The HTML markup containing the media dimensions.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1450
	 * @param WP_Post $post       The WP_Post attachment object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1451
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1452
	$media_dims = apply_filters( 'media_meta', $media_dims, $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1453
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1454
	$image_edit_button = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1455
	if ( wp_attachment_is_image( $post->ID ) && wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1456
		$nonce = wp_create_nonce( "image_editor-$post->ID" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1457
		$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>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1458
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1459
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1460
	$attachment_url = get_permalink( $attachment_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1461
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1462
	$item = "
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1463
	$type_html
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1464
	$toggle_links
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1465
	$order
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1466
	$display_title
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1467
	<table class='slidetoggle describe $class'>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1468
		<thead class='media-item-info' id='media-head-$post->ID'>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1469
		<tr>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1470
			<td class='A1B1' id='thumbnail-head-$post->ID'>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1471
			<p><a href='$attachment_url' target='_blank'><img class='thumbnail' src='$thumb_url' alt='' /></a></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1472
			<p>$image_edit_button</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1473
			</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1474
			<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1475
			<p><strong>" . __('File name:') . "</strong> $filename</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1476
			<p><strong>" . __('File type:') . "</strong> $post->post_mime_type</p>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1477
			<p><strong>" . __('Upload date:') . "</strong> " . mysql2date( __( 'F j, Y' ), $post->post_date ). '</p>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1478
			if ( !empty( $media_dims ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1479
				$item .= "<p><strong>" . __('Dimensions:') . "</strong> $media_dims</p>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1480
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1481
			$item .= "</td></tr>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1482
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1483
	$item .= "
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1484
		</thead>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1485
		<tbody>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1486
		<tr><td colspan='2' class='imgedit-response' id='imgedit-response-$post->ID'></td></tr>\n
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1487
		<tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1488
		<tr><td colspan='2'><p class='media-types media-types-required-info'>" . sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) . "</p></td></tr>\n";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1489
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1490
	$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1491
		'input'      => 'text',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1492
		'required'   => false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1493
		'value'      => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1494
		'extra_rows' => array(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1495
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1496
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1497
	if ( $r['send'] ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1498
		$r['send'] = get_submit_button( __( 'Insert into Post' ), '', "send[$attachment_id]", false );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1499
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1500
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1501
	$delete = empty( $r['delete'] ) ? '' : $r['delete'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1502
	if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1503
		if ( !EMPTY_TRASH_DAYS ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1504
			$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>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1505
		} elseif ( !MEDIA_TRASH ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1506
			$delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1507
			 <div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'>" .
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1508
			 /* translators: %s: file name */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1509
			'<p>' . sprintf( __( 'You are about to delete %s.' ), '<strong>' . $filename . '</strong>' ) . "</p>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1510
			 <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>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1511
			 <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . "</a>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1512
			 </div>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1513
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1514
			$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>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1515
			<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>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1516
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1517
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1518
		$delete = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1519
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1520
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1521
	$thumbnail = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1522
	$calling_post_id = 0;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1523
	if ( isset( $_GET['post_id'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1524
		$calling_post_id = absint( $_GET['post_id'] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1525
	} elseif ( isset( $_POST ) && count( $_POST ) ) {// Like for async-upload where $_GET['post_id'] isn't set
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1526
		$calling_post_id = $post->post_parent;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1527
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1528
	if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1529
		&& post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1530
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1531
		$calling_post = get_post( $calling_post_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1532
		$calling_post_type_object = get_post_type_object( $calling_post->post_type );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1533
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1534
		$ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1535
		$thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html( $calling_post_type_object->labels->use_featured_image ) . "</a>";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1536
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1537
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1538
	if ( ( $r['send'] || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1539
		$form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>" . $r['send'] . " $thumbnail $delete</td></tr>\n" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1540
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1541
	$hidden_fields = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1542
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1543
	foreach ( $form_fields as $id => $field ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1544
		if ( $id[0] == '_' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1545
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1546
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1547
		if ( !empty( $field['tr'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1548
			$item .= $field['tr'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1549
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1550
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1551
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1552
		$field = array_merge( $defaults, $field );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1553
		$name = "attachments[$attachment_id][$id]";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1554
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1555
		if ( $field['input'] == 'hidden' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1556
			$hidden_fields[$name] = $field['value'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1557
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1558
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1559
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1560
		$required      = $field['required'] ? '<span class="required">*</span>' : '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1561
		$required_attr = $field['required'] ? ' required' : '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1562
		$aria_required = $field['required'] ? " aria-required='true'" : '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1563
		$class  = $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1564
		$class .= $field['required'] ? ' form-required' : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1565
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1566
		$item .= "\t\t<tr class='$class'>\n\t\t\t<th scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}{$required}</span><br class='clear' /></label></th>\n\t\t\t<td class='field'>";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1567
		if ( !empty( $field[ $field['input'] ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1568
			$item .= $field[ $field['input'] ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1569
		elseif ( $field['input'] == 'textarea' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1570
			if ( 'post_content' == $id && user_can_richedit() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1571
				// Sanitize_post() skips the post_content when user_can_richedit.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1572
				$field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1573
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1574
			// Post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit().
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1575
			$item .= "<textarea id='$name' name='$name'{$required_attr}{$aria_required}>" . $field['value'] . '</textarea>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1576
		} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1577
			$item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "'{$required_attr}{$aria_required} />";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1578
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1579
		if ( !empty( $field['helps'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1580
			$item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1581
		$item .= "</td>\n\t\t</tr>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1582
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1583
		$extra_rows = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1584
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1585
		if ( !empty( $field['errors'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1586
			foreach ( array_unique( (array) $field['errors'] ) as $error )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1587
				$extra_rows['error'][] = $error;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1588
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1589
		if ( !empty( $field['extra_rows'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1590
			foreach ( $field['extra_rows'] as $class => $rows )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1591
				foreach ( (array) $rows as $html )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1592
					$extra_rows[$class][] = $html;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1593
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1594
		foreach ( $extra_rows as $class => $rows )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1595
			foreach ( $rows as $html )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1596
				$item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1597
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1598
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1599
	if ( !empty( $form_fields['_final'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1600
		$item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1601
	$item .= "\t</tbody>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1602
	$item .= "\t</table>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1603
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1604
	foreach ( $hidden_fields as $name => $value )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1605
		$item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1606
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1607
	if ( $post->post_parent < 1 && isset( $_REQUEST['post_id'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1608
		$parent = (int) $_REQUEST['post_id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1609
		$parent_name = "attachments[$attachment_id][post_parent]";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1610
		$item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='$parent' />\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1611
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1612
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1613
	return $item;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1614
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1615
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1616
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1617
 * @since 3.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1618
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1619
 * @param int   $attachment_id
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1620
 * @param array $args
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1621
 * @return array
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1622
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1623
function get_compat_media_markup( $attachment_id, $args = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1624
	$post = get_post( $attachment_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1625
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1626
	$default_args = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1627
		'errors' => null,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1628
		'in_modal' => false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1629
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1630
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1631
	$user_can_edit = current_user_can( 'edit_post', $attachment_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1632
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1633
	$args = wp_parse_args( $args, $default_args );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1634
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1635
	/** This filter is documented in wp-admin/includes/media.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1636
	$args = apply_filters( 'get_media_item_args', $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1637
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1638
	$form_fields = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1639
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1640
	if ( $args['in_modal'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1641
		foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1642
			$t = (array) get_taxonomy($taxonomy);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1643
			if ( ! $t['public'] || ! $t['show_ui'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1644
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1645
			if ( empty($t['label']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1646
				$t['label'] = $taxonomy;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1647
			if ( empty($t['args']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1648
				$t['args'] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1649
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1650
			$terms = get_object_term_cache($post->ID, $taxonomy);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1651
			if ( false === $terms )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1652
				$terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1653
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1654
			$values = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1655
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1656
			foreach ( $terms as $term )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1657
				$values[] = $term->slug;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1658
			$t['value'] = join(', ', $values);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1659
			$t['taxonomy'] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1660
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1661
			$form_fields[$taxonomy] = $t;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1662
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1663
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1664
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1665
	// Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1666
	// The recursive merge is easily traversed with array casting: foreach ( (array) $things as $thing )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1667
	$form_fields = array_merge_recursive($form_fields, (array) $args['errors'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1668
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1669
	/** This filter is documented in wp-admin/includes/media.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1670
	$form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1671
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1672
	unset( $form_fields['image-size'], $form_fields['align'], $form_fields['image_alt'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1673
		$form_fields['post_title'], $form_fields['post_excerpt'], $form_fields['post_content'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1674
		$form_fields['url'], $form_fields['menu_order'], $form_fields['image_url'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1675
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1676
	/** This filter is documented in wp-admin/includes/media.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1677
	$media_meta = apply_filters( 'media_meta', '', $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1678
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1679
	$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1680
		'input'         => 'text',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1681
		'required'      => false,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1682
		'value'         => '',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1683
		'extra_rows'    => array(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1684
		'show_in_edit'  => true,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1685
		'show_in_modal' => true,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1686
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1687
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1688
	$hidden_fields = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1689
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1690
	$item = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1691
	foreach ( $form_fields as $id => $field ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1692
		if ( $id[0] == '_' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1693
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1694
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1695
		$name = "attachments[$attachment_id][$id]";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1696
		$id_attr = "attachments-$attachment_id-$id";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1697
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1698
		if ( !empty( $field['tr'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1699
			$item .= $field['tr'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1700
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1701
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1702
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1703
		$field = array_merge( $defaults, $field );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1704
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1705
		if ( ( ! $field['show_in_edit'] && ! $args['in_modal'] ) || ( ! $field['show_in_modal'] && $args['in_modal'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1706
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1707
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1708
		if ( $field['input'] == 'hidden' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1709
			$hidden_fields[$name] = $field['value'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1710
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1711
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1712
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1713
		$readonly      = ! $user_can_edit && ! empty( $field['taxonomy'] ) ? " readonly='readonly' " : '';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1714
		$required      = $field['required'] ? '<span class="required">*</span>' : '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1715
		$required_attr = $field['required'] ? ' required' : '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1716
		$aria_required = $field['required'] ? " aria-required='true'" : '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1717
		$class  = 'compat-field-' . $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1718
		$class .= $field['required'] ? ' form-required' : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1719
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1720
		$item .= "\t\t<tr class='$class'>";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1721
		$item .= "\t\t\t<th scope='row' class='label'><label for='$id_attr'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label>";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1722
		$item .= "</th>\n\t\t\t<td class='field'>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1723
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1724
		if ( !empty( $field[ $field['input'] ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1725
			$item .= $field[ $field['input'] ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1726
		elseif ( $field['input'] == 'textarea' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1727
			if ( 'post_content' == $id && user_can_richedit() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1728
				// sanitize_post() skips the post_content when user_can_richedit.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1729
				$field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1730
			}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1731
			$item .= "<textarea id='$id_attr' name='$name'{$required_attr}{$aria_required}>" . $field['value'] . '</textarea>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1732
		} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1733
			$item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $readonly{$required_attr}{$aria_required} />";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1734
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1735
		if ( !empty( $field['helps'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1736
			$item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1737
		$item .= "</td>\n\t\t</tr>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1738
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1739
		$extra_rows = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1740
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1741
		if ( !empty( $field['errors'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1742
			foreach ( array_unique( (array) $field['errors'] ) as $error )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1743
				$extra_rows['error'][] = $error;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1744
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1745
		if ( !empty( $field['extra_rows'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1746
			foreach ( $field['extra_rows'] as $class => $rows )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1747
				foreach ( (array) $rows as $html )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1748
					$extra_rows[$class][] = $html;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1749
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1750
		foreach ( $extra_rows as $class => $rows )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1751
			foreach ( $rows as $html )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1752
				$item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1753
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1754
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1755
	if ( !empty( $form_fields['_final'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1756
		$item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1757
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1758
	if ( $item ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1759
		$item = '<p class="media-types media-types-required-info">' .
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1760
			sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) . '</p>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1761
			<table class="compat-attachment-fields">' . $item . '</table>';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1762
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1763
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1764
	foreach ( $hidden_fields as $hidden_field => $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1765
		$item .= '<input type="hidden" name="' . esc_attr( $hidden_field ) . '" value="' . esc_attr( $value ) . '" />' . "\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1766
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1767
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1768
	if ( $item )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1769
		$item = '<input type="hidden" name="attachments[' . $attachment_id . '][menu_order]" value="' . esc_attr( $post->menu_order ) . '" />' . $item;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1770
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1771
	return array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1772
		'item'   => $item,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1773
		'meta'   => $media_meta,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1774
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1775
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1776
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1777
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1778
 * Outputs the legacy media upload header.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1779
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1780
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1781
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1782
function media_upload_header() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1783
	$post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1784
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1785
	echo '<script type="text/javascript">post_id = ' . $post_id . ';</script>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1786
	if ( empty( $_GET['chromeless'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1787
		echo '<div id="media-upload-header">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1788
		the_media_upload_tabs();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1789
		echo '</div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1790
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1791
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1792
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1793
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1794
 * Outputs the legacy media upload form.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1795
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1796
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1797
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1798
 * @global string $type
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1799
 * @global string $tab
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1800
 * @global bool   $is_IE
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1801
 * @global bool   $is_opera
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1802
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1803
 * @param array $errors
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1804
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1805
function media_upload_form( $errors = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1806
	global $type, $tab, $is_IE, $is_opera;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1807
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1808
	if ( ! _device_can_upload() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1809
		echo '<p>' . sprintf( __('The web browser on your device cannot be used to upload files. You may be able to use the <a href="%s">native app for your device</a> instead.'), 'https://apps.wordpress.org/' ) . '</p>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1810
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1811
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1812
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1813
	$upload_action_url = admin_url('async-upload.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1814
	$post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1815
	$_type = isset($type) ? $type : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1816
	$_tab = isset($tab) ? $tab : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1817
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1818
	$max_upload_size = wp_max_upload_size();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1819
	if ( ! $max_upload_size ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1820
		$max_upload_size = 0;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1821
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1822
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1823
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1824
<div id="media-upload-notice"><?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1825
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1826
	if (isset($errors['upload_notice']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1827
		echo $errors['upload_notice'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1828
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1829
?></div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1830
<div id="media-upload-error"><?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1831
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1832
	if (isset($errors['upload_error']) && is_wp_error($errors['upload_error']))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1833
		echo $errors['upload_error']->get_error_message();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1834
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1835
?></div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1836
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1837
if ( is_multisite() && !is_upload_space_available() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1838
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1839
	 * Fires when an upload will exceed the defined upload space quota for a network site.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1840
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1841
	 * @since 3.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1842
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1843
	do_action( 'upload_ui_over_quota' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1844
	return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1845
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1846
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1847
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1848
 * Fires just before the legacy (pre-3.5.0) upload interface is loaded.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1849
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1850
 * @since 2.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1851
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1852
do_action( 'pre-upload-ui' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1853
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1854
$post_params = array(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1855
	"post_id" => $post_id,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1856
	"_wpnonce" => wp_create_nonce('media-form'),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1857
	"type" => $_type,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1858
	"tab" => $_tab,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1859
	"short" => "1",
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1860
);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1861
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1862
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1863
 * Filters the media upload post parameters.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1864
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1865
 * @since 3.1.0 As 'swfupload_post_params'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1866
 * @since 3.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1867
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1868
 * @param array $post_params An array of media upload parameters used by Plupload.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1869
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1870
$post_params = apply_filters( 'upload_post_params', $post_params );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1871
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1872
/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1873
 * Since 4.9 the `runtimes` setting is hardcoded in our version of Plupload to `html5,html4`,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1874
 * and the `flash_swf_url` and `silverlight_xap_url` are not used.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1875
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1876
$plupload_init = array(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1877
	'browse_button'       => 'plupload-browse-button',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1878
	'container'           => 'plupload-upload-ui',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1879
	'drop_element'        => 'drag-drop-area',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1880
	'file_data_name'      => 'async-upload',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1881
	'url'                 => $upload_action_url,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1882
	'filters' => array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1883
		'max_file_size'   => $max_upload_size . 'b',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1884
	),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1885
	'multipart_params'    => $post_params,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1886
);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1887
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1888
// Currently only iOS Safari supports multiple files uploading but iOS 7.x has a bug that prevents uploading of videos
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1889
// when enabled. See #29602.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1890
if ( wp_is_mobile() && strpos( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) !== false &&
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1891
	strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1892
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1893
	$plupload_init['multi_selection'] = false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1894
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1895
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1896
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1897
 * Filters the default Plupload settings.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1898
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1899
 * @since 3.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1900
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1901
 * @param array $plupload_init An array of default settings used by Plupload.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1902
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1903
$plupload_init = apply_filters( 'plupload_init', $plupload_init );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1904
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1905
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1906
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1907
<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1908
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1909
// Verify size is an int. If not return default value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1910
$large_size_h = absint( get_option('large_size_h') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1911
if( !$large_size_h )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1912
	$large_size_h = 1024;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1913
$large_size_w = absint( get_option('large_size_w') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1914
if( !$large_size_w )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1915
	$large_size_w = 1024;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1916
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1917
var resize_height = <?php echo $large_size_h; ?>, resize_width = <?php echo $large_size_w; ?>,
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1918
wpUploaderInit = <?php echo wp_json_encode( $plupload_init ); ?>;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1919
</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1920
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1921
<div id="plupload-upload-ui" class="hide-if-no-js">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1922
<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1923
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1924
 * Fires before the upload interface loads.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1925
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1926
 * @since 2.6.0 As 'pre-flash-upload-ui'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1927
 * @since 3.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1928
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1929
do_action( 'pre-plupload-upload-ui' ); ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1930
<div id="drag-drop-area">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1931
	<div class="drag-drop-inside">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1932
	<p class="drag-drop-info"><?php _e('Drop files here'); ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1933
	<p><?php _ex('or', 'Uploader: Drop files here - or - Select Files'); ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1934
	<p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e('Select Files'); ?>" class="button" /></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1935
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1936
</div>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1937
<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1938
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1939
 * Fires after the upload interface loads.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1940
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1941
 * @since 2.6.0 As 'post-flash-upload-ui'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1942
 * @since 3.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1943
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1944
do_action( 'post-plupload-upload-ui' ); ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1945
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1946
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1947
<div id="html-upload-ui" class="hide-if-js">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1948
	<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1949
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1950
	 * Fires before the upload button in the media upload interface.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1951
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1952
	 * @since 2.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1953
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1954
	do_action( 'pre-html-upload-ui' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1955
	?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1956
	<p id="async-upload-wrap">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1957
		<label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1958
		<input type="file" name="async-upload" id="async-upload" />
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1959
		<?php submit_button( __( 'Upload' ), 'primary', 'html-upload', false ); ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1960
		<a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1961
	</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1962
	<div class="clear"></div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1963
<?php
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1964
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1965
 * Fires after the upload button in the media upload interface.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1966
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1967
 * @since 2.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1968
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1969
do_action( 'post-html-upload-ui' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1970
?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1971
</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1972
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1973
<p class="max-upload-size"><?php printf( __( 'Maximum upload file size: %s.' ), esc_html( size_format( $max_upload_size ) ) ); ?></p>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1974
<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1975
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1976
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1977
	 * Fires on the post upload UI screen.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1978
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1979
	 * Legacy (pre-3.5.0) media workflow hook.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1980
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1981
	 * @since 2.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1982
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1983
	do_action( 'post-upload-ui' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1984
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1985
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1986
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1987
 * Outputs the legacy media upload form for a given media type.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1988
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1989
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1990
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1991
 * @param string $type
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1992
 * @param object $errors
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1993
 * @param integer $id
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1994
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1995
function media_upload_type_form($type = 'file', $errors = null, $id = null) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1996
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1997
	media_upload_header();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1998
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1999
	$post_id = isset( $_REQUEST['post_id'] )? intval( $_REQUEST['post_id'] ) : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2000
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2001
	$form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2002
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2003
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2004
	 * Filters the media upload form action URL.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2005
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2006
	 * @since 2.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2007
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2008
	 * @param string $form_action_url The media upload form action URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2009
	 * @param string $type            The type of media. Default 'file'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2010
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2011
	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2012
	$form_class = 'media-upload-form type-form validate';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2013
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2014
	if ( get_user_setting('uploader') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2015
		$form_class .= ' html-uploader';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2016
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2017
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2018
<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2019
<?php submit_button( '', 'hidden', 'save', false ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2020
<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2021
<?php wp_nonce_field('media-form'); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2022
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2023
<h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2024
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2025
<?php media_upload_form( $errors ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2026
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2027
<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2028
jQuery(function($){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2029
	var preloaded = $(".media-item.preloaded");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2030
	if ( preloaded.length > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2031
		preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2032
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2033
	updateMediaForm();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2034
});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2035
</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2036
<div id="media-items"><?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2037
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2038
if ( $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2039
	if ( !is_wp_error($id) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2040
		add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2041
		echo get_media_items( $id, $errors );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2042
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2043
		echo '<div id="media-upload-error">'.esc_html($id->get_error_message()).'</div></div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2044
		exit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2045
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2046
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2047
?></div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2048
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2049
<p class="savebutton ml-submit">
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2050
<?php submit_button( __( 'Save all changes' ), '', 'save', false ); ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2051
</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2052
</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2053
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2054
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2055
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2056
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2057
 * Outputs the legacy media upload form for external media.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2058
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2059
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2060
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2061
 * @param string $type
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2062
 * @param object $errors
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2063
 * @param integer $id
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2064
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2065
function media_upload_type_url_form($type = null, $errors = null, $id = null) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2066
	if ( null === $type )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2067
		$type = 'image';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2068
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2069
	media_upload_header();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2070
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2071
	$post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2072
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2073
	$form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2074
	/** This filter is documented in wp-admin/includes/media.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2075
	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2076
	$form_class = 'media-upload-form type-form validate';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2077
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2078
	if ( get_user_setting('uploader') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2079
		$form_class .= ' html-uploader';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2080
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2081
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2082
<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2083
<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2084
<?php wp_nonce_field('media-form'); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2085
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2086
<h3 class="media-title"><?php _e('Insert media from another website'); ?></h3>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2087
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2088
<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2089
var addExtImage = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2090
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2091
	width : '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2092
	height : '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2093
	align : 'alignnone',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2094
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2095
	insert : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2096
		var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2097
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2098
		if ( '' == f.src.value || '' == t.width )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2099
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2100
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2101
		if ( f.alt.value )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2102
			alt = f.alt.value.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2103
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2104
<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2105
	/** This filter is documented in wp-admin/includes/media.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2106
	if ( ! apply_filters( 'disable_captions', '' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2107
		?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2108
		if ( f.caption.value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2109
			caption = f.caption.value.replace(/\r\n|\r/g, '\n');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2110
			caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2111
				return a.replace(/[\r\n\t]+/, ' ');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2112
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2113
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2114
			caption = caption.replace(/\s*\n\s*/g, '<br />');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2115
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2116
<?php } ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2117
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2118
		cls = caption ? '' : ' class="'+t.align+'"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2119
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2120
		html = '<img alt="'+alt+'" src="'+f.src.value+'"'+cls+' width="'+t.width+'" height="'+t.height+'" />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2121
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2122
		if ( f.url.value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2123
			url = f.url.value.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2124
			html = '<a href="'+url+'">'+html+'</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2125
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2126
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2127
		if ( caption )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2128
			html = '[caption id="" align="'+t.align+'" width="'+t.width+'"]'+html+caption+'[/caption]';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2129
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2130
		var win = window.dialogArguments || opener || parent || top;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2131
		win.send_to_editor(html);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2132
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2133
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2134
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2135
	resetImageData : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2136
		var t = addExtImage;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2137
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2138
		t.width = t.height = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2139
		document.getElementById('go_button').style.color = '#bbb';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2140
		if ( ! document.forms[0].src.value )
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2141
			document.getElementById('status_img').innerHTML = '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2142
		else document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/no.png' ) ); ?>" alt="" />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2143
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2144
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2145
	updateImageData : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2146
		var t = addExtImage;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2147
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2148
		t.width = t.preloadImg.width;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2149
		t.height = t.preloadImg.height;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2150
		document.getElementById('go_button').style.color = '#333';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2151
		document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/yes.png' ) ); ?>" alt="" />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2152
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2153
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2154
	getImageData : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2155
		if ( jQuery('table.describe').hasClass('not-image') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2156
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2157
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2158
		var t = addExtImage, src = document.forms[0].src.value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2159
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2160
		if ( ! src ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2161
			t.resetImageData();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2162
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2163
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2164
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2165
		document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/spinner-2x.gif' ) ); ?>" alt="" width="16" height="16" />';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2166
		t.preloadImg = new Image();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2167
		t.preloadImg.onload = t.updateImageData;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2168
		t.preloadImg.onerror = t.resetImageData;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2169
		t.preloadImg.src = src;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2170
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2171
};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2172
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2173
jQuery(document).ready( function($) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2174
	$('.media-types input').click( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2175
		$('table.describe').toggleClass('not-image', $('#not-image').prop('checked') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2176
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2177
});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2178
</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2179
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2180
<div id="media-items">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2181
<div class="media-item media-blank">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2182
<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2183
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2184
 * Filters the insert media from URL form HTML.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2185
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2186
 * @since 3.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2187
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2188
 * @param string $form_html The insert from URL form HTML.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2189
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2190
echo apply_filters( 'type_url_form_media', wp_media_insert_url_form( $type ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2191
?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2192
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2193
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2194
</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2195
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2196
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2197
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2198
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2199
 * Adds gallery form to upload iframe
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2200
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2201
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2202
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2203
 * @global string $redir_tab
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2204
 * @global string $type
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2205
 * @global string $tab
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2206
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2207
 * @param array $errors
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2208
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2209
function media_upload_gallery_form($errors) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2210
	global $redir_tab, $type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2211
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2212
	$redir_tab = 'gallery';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2213
	media_upload_header();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2214
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2215
	$post_id = intval($_REQUEST['post_id']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2216
	$form_action_url = admin_url("media-upload.php?type=$type&tab=gallery&post_id=$post_id");
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2217
	/** This filter is documented in wp-admin/includes/media.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2218
	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2219
	$form_class = 'media-upload-form validate';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2220
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2221
	if ( get_user_setting('uploader') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2222
		$form_class .= ' html-uploader';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2223
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2224
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2225
<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2226
jQuery(function($){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2227
	var preloaded = $(".media-item.preloaded");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2228
	if ( preloaded.length > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2229
		preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2230
		updateMediaForm();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2231
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2232
});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2233
</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2234
<div id="sort-buttons" class="hide-if-no-js">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2235
<span>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2236
<?php _e('All Tabs:'); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2237
<a href="#" id="showall"><?php _e('Show'); ?></a>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2238
<a href="#" id="hideall" style="display:none;"><?php _e('Hide'); ?></a>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2239
</span>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2240
<?php _e('Sort Order:'); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2241
<a href="#" id="asc"><?php _e('Ascending'); ?></a> |
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2242
<a href="#" id="desc"><?php _e('Descending'); ?></a> |
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2243
<a href="#" id="clear"><?php _ex('Clear', 'verb'); ?></a>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2244
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2245
<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="gallery-form">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2246
<?php wp_nonce_field('media-form'); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2247
<?php //media_upload_form( $errors ); ?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2248
<table class="widefat">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2249
<thead><tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2250
<th><?php _e('Media'); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2251
<th class="order-head"><?php _e('Order'); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2252
<th class="actions-head"><?php _e('Actions'); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2253
</tr></thead>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2254
</table>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2255
<div id="media-items">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2256
<?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2257
<?php echo get_media_items($post_id, $errors); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2258
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2259
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2260
<p class="ml-submit">
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2261
<?php submit_button( __( 'Save all changes' ), 'savebutton', 'save', false, array( 'id' => 'save-all', 'style' => 'display: none;' ) ); ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2262
<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2263
<input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2264
<input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2265
</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2266
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2267
<div id="gallery-settings" style="display:none;">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2268
<div class="title"><?php _e('Gallery Settings'); ?></div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2269
<table id="basic" class="describe"><tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2270
	<tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2271
	<th scope="row" class="label">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2272
		<label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2273
		<span class="alignleft"><?php _e('Link thumbnails to:'); ?></span>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2274
		</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2275
	</th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2276
	<td class="field">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2277
		<input type="radio" name="linkto" id="linkto-file" value="file" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2278
		<label for="linkto-file" class="radio"><?php _e('Image File'); ?></label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2279
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2280
		<input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2281
		<label for="linkto-post" class="radio"><?php _e('Attachment Page'); ?></label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2282
	</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2283
	</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2284
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2285
	<tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2286
	<th scope="row" class="label">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2287
		<label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2288
		<span class="alignleft"><?php _e('Order images by:'); ?></span>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2289
		</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2290
	</th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2291
	<td class="field">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2292
		<select id="orderby" name="orderby">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2293
			<option value="menu_order" selected="selected"><?php _e('Menu order'); ?></option>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2294
			<option value="title"><?php _e('Title'); ?></option>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2295
			<option value="post_date"><?php _e('Date/Time'); ?></option>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2296
			<option value="rand"><?php _e('Random'); ?></option>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2297
		</select>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2298
	</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2299
	</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2300
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2301
	<tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2302
	<th scope="row" class="label">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2303
		<label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2304
		<span class="alignleft"><?php _e('Order:'); ?></span>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2305
		</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2306
	</th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2307
	<td class="field">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2308
		<input type="radio" checked="checked" name="order" id="order-asc" value="asc" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2309
		<label for="order-asc" class="radio"><?php _e('Ascending'); ?></label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2310
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2311
		<input type="radio" name="order" id="order-desc" value="desc" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2312
		<label for="order-desc" class="radio"><?php _e('Descending'); ?></label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2313
	</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2314
	</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2315
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2316
	<tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2317
	<th scope="row" class="label">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2318
		<label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2319
		<span class="alignleft"><?php _e('Gallery columns:'); ?></span>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2320
		</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2321
	</th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2322
	<td class="field">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2323
		<select id="columns" name="columns">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2324
			<option value="1">1</option>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2325
			<option value="2">2</option>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2326
			<option value="3" selected="selected">3</option>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2327
			<option value="4">4</option>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2328
			<option value="5">5</option>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2329
			<option value="6">6</option>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2330
			<option value="7">7</option>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2331
			<option value="8">8</option>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2332
			<option value="9">9</option>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2333
		</select>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2334
	</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2335
	</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2336
</tbody></table>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2337
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2338
<p class="ml-submit">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2339
<input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php esc_attr_e( 'Insert gallery' ); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2340
<input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="update-gallery" id="update-gallery" value="<?php esc_attr_e( 'Update gallery settings' ); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2341
</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2342
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2343
</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2344
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2345
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2346
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2347
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2348
 * Outputs the legacy media upload form for the media library.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2349
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2350
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2351
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2352
 * @global wpdb      $wpdb
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2353
 * @global WP_Query  $wp_query
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2354
 * @global WP_Locale $wp_locale
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2355
 * @global string    $type
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2356
 * @global string    $tab
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2357
 * @global array     $post_mime_types
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2358
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2359
 * @param array $errors
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2360
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2361
function media_upload_library_form($errors) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2362
	global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2363
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2364
	media_upload_header();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2365
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2366
	$post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2367
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2368
	$form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id");
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2369
	/** This filter is documented in wp-admin/includes/media.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2370
	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2371
	$form_class = 'media-upload-form validate';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2372
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2373
	if ( get_user_setting('uploader') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2374
		$form_class .= ' html-uploader';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2375
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2376
	$q = $_GET;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2377
	$q['posts_per_page'] = 10;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2378
	$q['paged'] = isset( $q['paged'] ) ? intval( $q['paged'] ) : 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2379
	if ( $q['paged'] < 1 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2380
		$q['paged'] = 1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2381
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2382
	$q['offset'] = ( $q['paged'] - 1 ) * 10;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2383
	if ( $q['offset'] < 1 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2384
		$q['offset'] = 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2385
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2386
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2387
	list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query( $q );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2388
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2389
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2390
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2391
<form id="filter" method="get">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2392
<input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2393
<input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2394
<input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2395
<input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2396
<input type="hidden" name="context" value="<?php echo isset( $_GET['context'] ) ? esc_attr( $_GET['context'] ) : ''; ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2397
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2398
<p id="media-search" class="search-box">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2399
	<label class="screen-reader-text" for="media-search-input"><?php _e('Search Media');?>:</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2400
	<input type="search" id="media-search-input" name="s" value="<?php the_search_query(); ?>" />
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2401
	<?php submit_button( __( 'Search Media' ), '', '', false ); ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2402
</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2403
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2404
<ul class="subsubsub">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2405
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2406
$type_links = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2407
$_num_posts = (array) wp_count_attachments();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2408
$matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2409
foreach ( $matches as $_type => $reals )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2410
	foreach ( $reals as $real )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2411
		if ( isset($num_posts[$_type]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2412
			$num_posts[$_type] += $_num_posts[$real];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2413
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2414
			$num_posts[$_type] = $_num_posts[$real];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2415
// If available type specified by media button clicked, filter by that type
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2416
if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2417
	$_GET['post_mime_type'] = $type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2418
	list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2419
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2420
if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2421
	$class = ' class="current"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2422
else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2423
	$class = '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2424
$type_links[] = '<li><a href="' . esc_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . '"' . $class . '>' . __('All Types') . '</a>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2425
foreach ( $post_mime_types as $mime_type => $label ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2426
	$class = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2427
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2428
	if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2429
		continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2430
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2431
	if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2432
		$class = ' class="current"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2433
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2434
	$type_links[] = '<li><a href="' . esc_url(add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false))) . '"' . $class . '>' . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), '<span id="' . $mime_type . '-counter">' . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2435
}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2436
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2437
 * Filters the media upload mime type list items.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2438
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2439
 * Returned values should begin with an `<li>` tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2440
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2441
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2442
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2443
 * @param array $type_links An array of list items containing mime type link HTML.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2444
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2445
echo implode(' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2446
unset($type_links);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2447
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2448
</ul>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2449
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2450
<div class="tablenav">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2451
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2452
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2453
$page_links = paginate_links( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2454
	'base' => add_query_arg( 'paged', '%#%' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2455
	'format' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2456
	'prev_text' => __('&laquo;'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2457
	'next_text' => __('&raquo;'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2458
	'total' => ceil($wp_query->found_posts / 10),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2459
	'current' => $q['paged'],
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2460
));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2461
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2462
if ( $page_links )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2463
	echo "<div class='tablenav-pages'>$page_links</div>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2464
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2465
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2466
<div class="alignleft actions">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2467
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2468
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2469
$arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2470
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2471
$arc_result = $wpdb->get_results( $arc_query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2472
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2473
$month_count = count($arc_result);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2474
$selected_month = isset( $_GET['m'] ) ? $_GET['m'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2475
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2476
if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2477
<select name='m'>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2478
<option<?php selected( $selected_month, 0 ); ?> value='0'><?php _e( 'All dates' ); ?></option>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2479
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2480
foreach ($arc_result as $arc_row) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2481
	if ( $arc_row->yyear == 0 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2482
		continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2483
	$arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2484
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2485
	if ( $arc_row->yyear . $arc_row->mmonth == $selected_month )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2486
		$default = ' selected="selected"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2487
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2488
		$default = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2489
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2490
	echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2491
	echo esc_html( $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2492
	echo "</option>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2493
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2494
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2495
</select>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2496
<?php } ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2497
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2498
<?php submit_button( __( 'Filter &#187;' ), '', 'post-query-submit', false ); ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2499
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2500
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2501
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2502
<br class="clear" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2503
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2504
</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2505
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2506
<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="library-form">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2507
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2508
<?php wp_nonce_field('media-form'); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2509
<?php //media_upload_form( $errors ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2510
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2511
<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2512
<!--
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2513
jQuery(function($){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2514
	var preloaded = $(".media-item.preloaded");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2515
	if ( preloaded.length > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2516
		preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2517
		updateMediaForm();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2518
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2519
});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2520
-->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2521
</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2522
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2523
<div id="media-items">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2524
<?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2525
<?php echo get_media_items(null, $errors); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2526
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2527
<p class="ml-submit">
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2528
<?php submit_button( __( 'Save all changes' ), 'savebutton', 'save', false ); ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2529
<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2530
</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2531
</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2532
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2533
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2534
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2535
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2536
 * Creates the form for external url
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2537
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2538
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2539
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2540
 * @param string $default_view
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2541
 * @return string the form html
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2542
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2543
function wp_media_insert_url_form( $default_view = 'image' ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2544
	/** This filter is documented in wp-admin/includes/media.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2545
	if ( ! apply_filters( 'disable_captions', '' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2546
		$caption = '
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2547
		<tr class="image-only">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2548
			<th scope="row" class="label">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2549
				<label for="caption"><span class="alignleft">' . __('Image Caption') . '</span></label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2550
			</th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2551
			<td class="field"><textarea id="caption" name="caption"></textarea></td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2552
		</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2553
';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2554
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2555
		$caption = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2556
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2557
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2558
	$default_align = get_option('image_default_align');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2559
	if ( empty($default_align) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2560
		$default_align = 'none';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2561
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2562
	if ( 'image' == $default_view ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2563
		$view = 'image-only';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2564
		$table_class = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2565
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2566
		$view = $table_class = 'not-image';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2567
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2568
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2569
	return '
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2570
	<p class="media-types"><label><input type="radio" name="media_type" value="image" id="image-only"' . checked( 'image-only', $view, false ) . ' /> ' . __( 'Image' ) . '</label> &nbsp; &nbsp; <label><input type="radio" name="media_type" value="generic" id="not-image"' . checked( 'not-image', $view, false ) . ' /> ' . __( 'Audio, Video, or Other File' ) . '</label></p>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2571
	<p class="media-types media-types-required-info">' . sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) . '</p>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2572
	<table class="describe ' . $table_class . '"><tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2573
		<tr>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2574
			<th scope="row" class="label" style="width:130px;">
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2575
				<label for="src"><span class="alignleft">' . __( 'URL' ) . '</span> <span class="required">*</span></label>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2576
				<span class="alignright" id="status_img"></span>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2577
			</th>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2578
			<td class="field"><input id="src" name="src" value="" type="text" required aria-required="true" onblur="addExtImage.getImageData()" /></td>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2579
		</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2580
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2581
		<tr>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2582
			<th scope="row" class="label">
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2583
				<label for="title"><span class="alignleft">' . __( 'Title' ) . '</span> <span class="required">*</span></label>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2584
			</th>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2585
			<td class="field"><input id="title" name="title" value="" type="text" required aria-required="true" /></td>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2586
		</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2587
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2588
		<tr class="not-image"><td></td><td><p class="help">' . __('Link text, e.g. &#8220;Ransom Demands (PDF)&#8221;') . '</p></td></tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2589
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2590
		<tr class="image-only">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2591
			<th scope="row" class="label">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2592
				<label for="alt"><span class="alignleft">' . __('Alternative Text') . '</span></label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2593
			</th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2594
			<td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2595
			<p class="help">' . __('Alt text for the image, e.g. &#8220;The Mona Lisa&#8221;') . '</p></td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2596
		</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2597
		' . $caption . '
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2598
		<tr class="align image-only">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2599
			<th scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2600
			<td class="field">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2601
				<input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2602
				<label for="align-none" class="align image-align-none-label">' . __('None') . '</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2603
				<input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2604
				<label for="align-left" class="align image-align-left-label">' . __('Left') . '</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2605
				<input name="align" id="align-center" value="center" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'center' ? ' checked="checked"' : '').' />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2606
				<label for="align-center" class="align image-align-center-label">' . __('Center') . '</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2607
				<input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'right' ? ' checked="checked"' : '').' />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2608
				<label for="align-right" class="align image-align-right-label">' . __('Right') . '</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2609
			</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2610
		</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2611
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2612
		<tr class="image-only">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2613
			<th scope="row" class="label">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2614
				<label for="url"><span class="alignleft">' . __('Link Image To:') . '</span></label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2615
			</th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2616
			<td class="field"><input id="url" name="url" value="" type="text" /><br />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2617
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2618
			<button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2619
			<button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2620
			<p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2621
		</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2622
		<tr class="image-only">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2623
			<td></td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2624
			<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2625
				<input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__('Insert into Post') . '" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2626
			</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2627
		</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2628
		<tr class="not-image">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2629
			<td></td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2630
			<td>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2631
				' . get_submit_button( __( 'Insert into Post' ), '', 'insertonlybutton', false ) . '
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2632
			</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2633
		</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2634
	</tbody></table>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2635
';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2636
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2637
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2638
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2639
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2640
 * Displays the multi-file uploader message.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2641
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2642
 * @since 2.6.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2643
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2644
 * @global int $post_ID
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2645
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2646
function media_upload_flash_bypass() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2647
	$browser_uploader = admin_url( 'media-new.php?browser-uploader' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2648
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2649
	if ( $post = get_post() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2650
		$browser_uploader .= '&amp;post_id=' . intval( $post->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2651
	elseif ( ! empty( $GLOBALS['post_ID'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2652
		$browser_uploader .= '&amp;post_id=' . intval( $GLOBALS['post_ID'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2653
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2654
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2655
	<p class="upload-flash-bypass">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2656
	<?php printf( __( 'You are using the multi-file uploader. Problems? Try the <a href="%1$s" target="%2$s">browser uploader</a> instead.' ), $browser_uploader, '_blank' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2657
	</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2658
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2659
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2660
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2661
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2662
 * Displays the browser's built-in uploader message.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2663
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2664
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2665
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2666
function media_upload_html_bypass() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2667
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2668
	<p class="upload-html-bypass hide-if-no-js">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2669
	   <?php _e('You are using the browser&#8217;s built-in file uploader. The WordPress uploader includes multiple file selection and drag and drop capability. <a href="#">Switch to the multi-file uploader</a>.'); ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2670
	</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2671
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2672
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2673
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2674
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2675
 * Used to display a "After a file has been uploaded..." help message.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2676
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2677
 * @since 3.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2678
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2679
function media_upload_text_after() {}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2680
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2681
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2682
 * Displays the checkbox to scale images.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2683
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2684
 * @since 3.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2685
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2686
function media_upload_max_image_resize() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2687
	$checked = get_user_setting('upload_resize') ? ' checked="true"' : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2688
	$a = $end = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2689
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2690
	if ( current_user_can( 'manage_options' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2691
		$a = '<a href="' . esc_url( admin_url( 'options-media.php' ) ) . '" target="_blank">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2692
		$end = '</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2693
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2694
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2695
<p class="hide-if-no-js"><label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2696
<input name="image_resize" type="checkbox" id="image_resize" value="true"<?php echo $checked; ?> />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2697
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2698
	/* translators: %1$s is link start tag, %2$s is link end tag, %3$d is width, %4$d is height*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2699
	printf( __( 'Scale images to match the large size selected in %1$simage options%2$s (%3$d &times; %4$d).' ), $a, $end, (int) get_option( 'large_size_w', '1024' ), (int) get_option( 'large_size_h', '1024' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2700
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2701
</label></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2702
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2703
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2704
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2705
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2706
 * Displays the out of storage quota message in Multisite.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2707
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2708
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2709
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2710
function multisite_over_quota_message() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2711
	echo '<p>' . sprintf( __( 'Sorry, you have used all of your storage quota of %s MB.' ), get_space_allowed() ) . '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2712
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2713
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2714
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2715
 * Displays the image and editor in the post editor
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2716
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2717
 * @since 3.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2718
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2719
 * @param WP_Post $post A post object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2720
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2721
function edit_form_image_editor( $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2722
	$open = isset( $_GET['image-editor'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2723
	if ( $open )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2724
		require_once ABSPATH . 'wp-admin/includes/image-edit.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2725
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2726
	$thumb_url = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2727
	if ( $attachment_id = intval( $post->ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2728
		$thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2729
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2730
	$alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2731
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2732
	$att_url = wp_get_attachment_url( $post->ID ); ?>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2733
	<div class="wp_attachment_holder wp-clearfix">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2734
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2735
	if ( wp_attachment_is_image( $post->ID ) ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2736
		$image_edit_button = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2737
		if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2738
			$nonce = wp_create_nonce( "image_editor-$post->ID" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2739
			$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>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2740
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2741
	?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2742
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2743
		<div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2744
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2745
		<div<?php if ( $open ) echo ' style="display:none"'; ?> class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2746
			<p id="thumbnail-head-<?php echo $attachment_id; ?>"><img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2747
			<p><?php echo $image_edit_button; ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2748
		</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2749
		<div<?php if ( ! $open ) echo ' style="display:none"'; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2750
			<?php if ( $open ) wp_image_editor( $attachment_id ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2751
		</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2752
	<?php
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2753
	elseif ( $attachment_id && wp_attachment_is( 'audio', $post ) ):
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2754
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2755
		wp_maybe_generate_attachment_metadata( $post );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2756
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2757
		echo wp_audio_shortcode( array( 'src' => $att_url ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2758
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2759
	elseif ( $attachment_id && wp_attachment_is( 'video', $post ) ):
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2760
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2761
		wp_maybe_generate_attachment_metadata( $post );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2762
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2763
		$meta = wp_get_attachment_metadata( $attachment_id );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2764
		$w = ! empty( $meta['width'] ) ? min( $meta['width'], 640 ) : 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2765
		$h = ! empty( $meta['height'] ) ? $meta['height'] : 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2766
		if ( $h && $w < $meta['width'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2767
			$h = round( ( $meta['height'] * $w ) / $meta['width'] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2768
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2769
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2770
		$attr = array( 'src' => $att_url );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2771
		if ( ! empty( $w ) && ! empty( $h ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2772
			$attr['width'] = $w;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2773
			$attr['height'] = $h;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2774
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2775
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2776
		$thumb_id = get_post_thumbnail_id( $attachment_id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2777
		if ( ! empty( $thumb_id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2778
			$attr['poster'] = wp_get_attachment_url( $thumb_id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2779
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2780
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2781
		echo wp_video_shortcode( $attr );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2782
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2783
	elseif ( isset( $thumb_url[0] ) ):
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2784
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2785
		?>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2786
		<div class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2787
			<p id="thumbnail-head-<?php echo $attachment_id; ?>">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2788
				<img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" />
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2789
			</p>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2790
		</div>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2791
		<?php
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2792
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2793
	else:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2794
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2795
		/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2796
		 * Fires when an attachment type can't be rendered in the edit form.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2797
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2798
		 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2799
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2800
		 * @param WP_Post $post A post object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2801
		 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2802
		do_action( 'wp_edit_form_attachment_display', $post );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2803
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2804
	endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2805
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2806
	<div class="wp_attachment_details edit-form-section">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2807
		<p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2808
			<label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2809
			<textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2810
		</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2811
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2812
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2813
	<?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2814
		<p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2815
			<label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2816
			<input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" value="<?php echo esc_attr( $alt_text ); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2817
		</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2818
	<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2819
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2820
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2821
		$quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2822
		$editor_args = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2823
			'textarea_name' => 'content',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2824
			'textarea_rows' => 5,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2825
			'media_buttons' => false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2826
			'tinymce' => false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2827
			'quicktags' => $quicktags_settings,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2828
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2829
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2830
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2831
	<label for="attachment_content"><strong><?php _e( 'Description' ); ?></strong><?php
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2832
	if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2833
		echo ': ' . __( 'Displayed on attachment pages.' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2834
	} ?></label>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2835
	<?php wp_editor( $post->post_content, 'attachment_content', $editor_args ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2836
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2837
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2838
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2839
	$extras = get_compat_media_markup( $post->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2840
	echo $extras['item'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2841
	echo '<input type="hidden" id="image-edit-context" value="edit-attachment" />' . "\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2842
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2843
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2844
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2845
 * Displays non-editable attachment metadata in the publish meta box.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2846
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2847
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2848
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2849
function attachment_submitbox_metadata() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2850
	$post = get_post();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2851
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2852
	$file = get_attached_file( $post->ID );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2853
	$filename = esc_html( wp_basename( $file ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2854
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2855
	$media_dims = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2856
	$meta = wp_get_attachment_metadata( $post->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2857
	if ( isset( $meta['width'], $meta['height'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2858
		$media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2859
	/** This filter is documented in wp-admin/includes/media.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2860
	$media_dims = apply_filters( 'media_meta', $media_dims, $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2861
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2862
	$att_url = wp_get_attachment_url( $post->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2863
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2864
	<div class="misc-pub-section misc-pub-attachment">
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2865
		<label for="attachment_url"><?php _e( 'File URL:' ); ?></label>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2866
		<input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" id="attachment_url" value="<?php echo esc_attr( $att_url ); ?>" />
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2867
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2868
	<div class="misc-pub-section misc-pub-filename">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2869
		<?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2870
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2871
	<div class="misc-pub-section misc-pub-filetype">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2872
		<?php _e( 'File type:' ); ?> <strong><?php
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2873
			if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2874
				echo esc_html( strtoupper( $matches[1] ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2875
				list( $mime_type ) = explode( '/', $post->post_mime_type );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2876
				if ( $mime_type !== 'image' && ! empty( $meta['mime_type'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2877
					if ( $meta['mime_type'] !== "$mime_type/" . strtolower( $matches[1] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2878
						echo ' (' . $meta['mime_type'] . ')';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2879
					}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2880
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2881
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2882
				echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2883
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2884
		?></strong>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2885
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2886
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2887
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2888
		$file_size = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2889
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2890
		if ( isset( $meta['filesize'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2891
			$file_size = $meta['filesize'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2892
		elseif ( file_exists( $file ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2893
			$file_size = filesize( $file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2894
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2895
		if ( ! empty( $file_size ) ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2896
			<div class="misc-pub-section misc-pub-filesize">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2897
				<?php _e( 'File size:' ); ?> <strong><?php echo size_format( $file_size ); ?></strong>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2898
			</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2899
			<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2900
		endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2901
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2902
	if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2903
		$fields = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2904
			'length_formatted' => __( 'Length:' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2905
			'bitrate'          => __( 'Bitrate:' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2906
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2907
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2908
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2909
		 * Filters the audio and video metadata fields to be shown in the publish meta box.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2910
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2911
		 * The key for each item in the array should correspond to an attachment
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2912
		 * metadata key, and the value should be the desired label.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2913
		 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2914
		 * @since 3.7.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2915
		 * @since 4.9.0 Added the `$post` parameter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2916
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2917
		 * @param array   $fields An array of the attachment metadata keys and labels.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2918
		 * @param WP_Post $post   WP_Post object for the current attachment.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2919
		 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2920
		$fields = apply_filters( 'media_submitbox_misc_sections', $fields, $post );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2921
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2922
		foreach ( $fields as $key => $label ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2923
			if ( empty( $meta[ $key ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2924
				continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2925
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2926
	?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2927
		<div class="misc-pub-section misc-pub-mime-meta misc-pub-<?php echo sanitize_html_class( $key ); ?>">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2928
			<?php echo $label ?> <strong><?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2929
				switch ( $key ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2930
					case 'bitrate' :
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2931
						echo round( $meta['bitrate'] / 1000 ) . 'kb/s';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2932
						if ( ! empty( $meta['bitrate_mode'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2933
							echo ' ' . strtoupper( esc_html( $meta['bitrate_mode'] ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2934
						}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2935
						break;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2936
					default:
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2937
						echo esc_html( $meta[ $key ] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2938
						break;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2939
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2940
			?></strong>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2941
		</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2942
	<?php
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2943
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2944
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2945
		$fields = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2946
			'dataformat' => __( 'Audio Format:' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2947
			'codec'      => __( 'Audio Codec:' )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2948
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2949
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2950
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2951
		 * Filters the audio attachment metadata fields to be shown in the publish meta box.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2952
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2953
		 * The key for each item in the array should correspond to an attachment
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2954
		 * metadata key, and the value should be the desired label.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2955
		 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2956
		 * @since 3.7.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2957
		 * @since 4.9.0 Added the `$post` parameter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2958
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2959
		 * @param array   $fields An array of the attachment metadata keys and labels.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2960
		 * @param WP_Post $post   WP_Post object for the current attachment.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2961
		 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2962
		$audio_fields = apply_filters( 'audio_submitbox_misc_sections', $fields, $post );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2963
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2964
		foreach ( $audio_fields as $key => $label ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2965
			if ( empty( $meta['audio'][ $key ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2966
				continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2967
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2968
	?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2969
		<div class="misc-pub-section misc-pub-audio misc-pub-<?php echo sanitize_html_class( $key ); ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2970
			<?php echo $label; ?> <strong><?php echo esc_html( $meta['audio'][$key] ); ?></strong>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2971
		</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2972
	<?php
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2973
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2974
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2975
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2976
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2977
	if ( $media_dims ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2978
	<div class="misc-pub-section misc-pub-dimensions">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2979
		<?php _e( 'Dimensions:' ); ?> <strong><?php echo $media_dims; ?></strong>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2980
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2981
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2982
	endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2983
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2984
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2985
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2986
 * Parse ID3v2, ID3v1, and getID3 comments to extract usable data
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2987
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2988
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2989
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2990
 * @param array $metadata An existing array with data
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2991
 * @param array $data Data supplied by ID3 tags
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2992
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2993
function wp_add_id3_tag_data( &$metadata, $data ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2994
	foreach ( array( 'id3v2', 'id3v1' ) as $version ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2995
		if ( ! empty( $data[$version]['comments'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2996
			foreach ( $data[$version]['comments'] as $key => $list ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2997
				if ( 'length' !== $key && ! empty( $list ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2998
					$metadata[$key] = wp_kses_post( reset( $list ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2999
					// Fix bug in byte stream analysis.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3000
					if ( 'terms_of_use' === $key && 0 === strpos( $metadata[$key], 'yright notice.' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3001
						$metadata[$key] = 'Cop' . $metadata[$key];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3002
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3003
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3004
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3005
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3006
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3007
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3008
	if ( ! empty( $data['id3v2']['APIC'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3009
		$image = reset( $data['id3v2']['APIC']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3010
		if ( ! empty( $image['data'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3011
			$metadata['image'] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3012
				'data' => $image['data'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3013
				'mime' => $image['image_mime'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3014
				'width' => $image['image_width'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3015
				'height' => $image['image_height']
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3016
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3017
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3018
	} elseif ( ! empty( $data['comments']['picture'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3019
		$image = reset( $data['comments']['picture'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3020
		if ( ! empty( $image['data'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3021
			$metadata['image'] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3022
				'data' => $image['data'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3023
				'mime' => $image['image_mime']
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3024
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3025
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3026
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3027
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3028
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3029
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3030
 * Retrieve metadata from a video file's ID3 tags
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3031
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3032
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3033
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3034
 * @param string $file Path to file.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3035
 * @return array|bool Returns array of metadata, if found.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3036
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3037
function wp_read_video_metadata( $file ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3038
	if ( ! file_exists( $file ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3039
		return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3040
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3041
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3042
	$metadata = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3043
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3044
	if ( ! defined( 'GETID3_TEMP_DIR' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3045
		define( 'GETID3_TEMP_DIR', get_temp_dir() );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3046
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3047
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3048
	if ( ! class_exists( 'getID3', false ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3049
		require( ABSPATH . WPINC . '/ID3/getid3.php' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3050
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3051
	$id3 = new getID3();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3052
	$data = $id3->analyze( $file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3053
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3054
	if ( isset( $data['video']['lossless'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3055
		$metadata['lossless'] = $data['video']['lossless'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3056
	if ( ! empty( $data['video']['bitrate'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3057
		$metadata['bitrate'] = (int) $data['video']['bitrate'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3058
	if ( ! empty( $data['video']['bitrate_mode'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3059
		$metadata['bitrate_mode'] = $data['video']['bitrate_mode'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3060
	if ( ! empty( $data['filesize'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3061
		$metadata['filesize'] = (int) $data['filesize'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3062
	if ( ! empty( $data['mime_type'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3063
		$metadata['mime_type'] = $data['mime_type'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3064
	if ( ! empty( $data['playtime_seconds'] ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3065
		$metadata['length'] = (int) round( $data['playtime_seconds'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3066
	if ( ! empty( $data['playtime_string'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3067
		$metadata['length_formatted'] = $data['playtime_string'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3068
	if ( ! empty( $data['video']['resolution_x'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3069
		$metadata['width'] = (int) $data['video']['resolution_x'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3070
	if ( ! empty( $data['video']['resolution_y'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3071
		$metadata['height'] = (int) $data['video']['resolution_y'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3072
	if ( ! empty( $data['fileformat'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3073
		$metadata['fileformat'] = $data['fileformat'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3074
	if ( ! empty( $data['video']['dataformat'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3075
		$metadata['dataformat'] = $data['video']['dataformat'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3076
	if ( ! empty( $data['video']['encoder'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3077
		$metadata['encoder'] = $data['video']['encoder'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3078
	if ( ! empty( $data['video']['codec'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3079
		$metadata['codec'] = $data['video']['codec'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3080
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3081
	if ( ! empty( $data['audio'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3082
		unset( $data['audio']['streams'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3083
		$metadata['audio'] = $data['audio'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3084
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3085
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3086
	if ( empty( $metadata['created_timestamp'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3087
		$created_timestamp = wp_get_media_creation_timestamp( $data );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3088
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3089
		if ( $created_timestamp !== false ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3090
			$metadata['created_timestamp'] = $created_timestamp;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3091
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3092
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3093
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3094
	wp_add_id3_tag_data( $metadata, $data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3095
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3096
	$file_format = isset( $metadata['fileformat'] ) ? $metadata['fileformat'] : null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3097
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3098
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3099
	 * Filters the array of metadata retrieved from a video.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3100
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3101
	 * In core, usually this selection is what is stored.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3102
	 * More complete data can be parsed from the `$data` parameter.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3103
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3104
	 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3105
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3106
	 * @param array  $metadata       Filtered Video metadata.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3107
	 * @param string $file           Path to video file.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3108
	 * @param string $file_format    File format of video, as analyzed by getID3.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3109
	 * @param string $data           Raw metadata from getID3.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3110
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3111
	return apply_filters( 'wp_read_video_metadata', $metadata, $file, $file_format, $data );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3112
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3113
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3114
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3115
 * Retrieve metadata from a audio file's ID3 tags
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3116
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3117
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3118
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3119
 * @param string $file Path to file.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3120
 * @return array|bool Returns array of metadata, if found.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3121
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3122
function wp_read_audio_metadata( $file ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3123
	if ( ! file_exists( $file ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3124
		return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3125
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3126
	$metadata = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3127
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3128
	if ( ! defined( 'GETID3_TEMP_DIR' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3129
		define( 'GETID3_TEMP_DIR', get_temp_dir() );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3130
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3131
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3132
	if ( ! class_exists( 'getID3', false ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3133
		require( ABSPATH . WPINC . '/ID3/getid3.php' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3134
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3135
	$id3 = new getID3();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3136
	$data = $id3->analyze( $file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3137
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3138
	if ( ! empty( $data['audio'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3139
		unset( $data['audio']['streams'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3140
		$metadata = $data['audio'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3141
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3142
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3143
	if ( ! empty( $data['fileformat'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3144
		$metadata['fileformat'] = $data['fileformat'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3145
	if ( ! empty( $data['filesize'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3146
		$metadata['filesize'] = (int) $data['filesize'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3147
	if ( ! empty( $data['mime_type'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3148
		$metadata['mime_type'] = $data['mime_type'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3149
	if ( ! empty( $data['playtime_seconds'] ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3150
		$metadata['length'] = (int) round( $data['playtime_seconds'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3151
	if ( ! empty( $data['playtime_string'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3152
		$metadata['length_formatted'] = $data['playtime_string'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3153
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3154
	wp_add_id3_tag_data( $metadata, $data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3155
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3156
	return $metadata;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3157
}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3158
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3159
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3160
 * Parse creation date from media metadata.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3161
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3162
 * The getID3 library doesn't have a standard method for getting creation dates,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3163
 * so the location of this data can vary based on the MIME type.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3164
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3165
 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3166
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3167
 * @link https://github.com/JamesHeinrich/getID3/blob/master/structure.txt
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3168
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3169
 * @param array $metadata The metadata returned by getID3::analyze().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3170
 * @return int|bool A UNIX timestamp for the media's creation date if available
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3171
 *                  or a boolean FALSE if a timestamp could not be determined.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3172
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3173
function wp_get_media_creation_timestamp( $metadata ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3174
	$creation_date = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3175
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3176
	if ( empty( $metadata['fileformat'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3177
		return $creation_date;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3178
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3179
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3180
	switch ( $metadata['fileformat'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3181
		case 'asf':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3182
			if ( isset( $metadata['asf']['file_properties_object']['creation_date_unix'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3183
				$creation_date = (int) $metadata['asf']['file_properties_object']['creation_date_unix'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3184
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3185
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3186
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3187
		case 'matroska':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3188
		case 'webm':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3189
			if ( isset( $metadata['matroska']['comments']['creation_time']['0'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3190
				$creation_date = strtotime( $metadata['matroska']['comments']['creation_time']['0'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3191
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3192
			elseif ( isset( $metadata['matroska']['info']['0']['DateUTC_unix'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3193
				$creation_date = (int) $metadata['matroska']['info']['0']['DateUTC_unix'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3194
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3195
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3196
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3197
		case 'quicktime':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3198
		case 'mp4':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3199
			if ( isset( $metadata['quicktime']['moov']['subatoms']['0']['creation_time_unix'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3200
				$creation_date = (int) $metadata['quicktime']['moov']['subatoms']['0']['creation_time_unix'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3201
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3202
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3203
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3204
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3205
	return $creation_date;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3206
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3207
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3208
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3209
 * Encapsulate logic for Attach/Detach actions
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3210
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3211
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3212
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3213
 * @global wpdb $wpdb WordPress database abstraction object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3214
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3215
 * @param int    $parent_id Attachment parent ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3216
 * @param string $action    Optional. Attach/detach action. Accepts 'attach' or 'detach'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3217
 *                          Default 'attach'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3218
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3219
function wp_media_attach_action( $parent_id, $action = 'attach' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3220
	global $wpdb;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3221
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3222
	if ( ! $parent_id ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3223
		return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3224
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3225
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3226
	if ( ! current_user_can( 'edit_post', $parent_id ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3227
		wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3228
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3229
	$ids = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3230
	foreach ( (array) $_REQUEST['media'] as $att_id ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3231
		$att_id = (int) $att_id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3232
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3233
		if ( ! current_user_can( 'edit_post', $att_id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3234
			continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3235
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3236
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3237
		$ids[] = $att_id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3238
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3239
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3240
	if ( ! empty( $ids ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3241
		$ids_string = implode( ',', $ids );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3242
		if ( 'attach' === $action ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3243
			$result = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $ids_string )", $parent_id ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3244
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3245
			$result = $wpdb->query( "UPDATE $wpdb->posts SET post_parent = 0 WHERE post_type = 'attachment' AND ID IN ( $ids_string )" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3246
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3247
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3248
		foreach ( $ids as $att_id ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3249
			clean_attachment_cache( $att_id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3250
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3251
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3252
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3253
	if ( isset( $result ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3254
		$location = 'upload.php';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3255
		if ( $referer = wp_get_referer() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3256
			if ( false !== strpos( $referer, 'upload.php' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3257
				$location = remove_query_arg( array( 'attached', 'detach' ), $referer );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3258
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3259
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3260
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3261
		$key = 'attach' === $action ? 'attached' : 'detach';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3262
		$location = add_query_arg( array( $key => $result ), $location );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3263
		wp_redirect( $location );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3264
		exit;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3265
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3266
}