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