PageRenderTime 63ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/includes/media.php

https://bitbucket.org/abnopanda/wordpress
PHP | 2345 lines | 2286 code | 18 blank | 41 comment | 11 complexity | e4b411a17d748fbb59a5985102763ef4 MD5 | raw file
  1. <?php
  2. /**
  3. * WordPress Administration Media API.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /**
  9. * Defines the default media upload tabs
  10. *
  11. * @since 2.5.0
  12. *
  13. * @return array default tabs
  14. */
  15. function media_upload_tabs() {
  16. $_default_tabs = array(
  17. 'type' => __('From Computer'), // handler action suffix => tab text
  18. 'type_url' => __('From URL'),
  19. 'gallery' => __('Gallery'),
  20. 'library' => __('Media Library')
  21. );
  22. return apply_filters('media_upload_tabs', $_default_tabs);
  23. }
  24. /**
  25. * Adds the gallery tab back to the tabs array if post has image attachments
  26. *
  27. * @since 2.5.0
  28. *
  29. * @param array $tabs
  30. * @return array $tabs with gallery if post has image attachment
  31. */
  32. function update_gallery_tab($tabs) {
  33. global $wpdb;
  34. if ( !isset($_REQUEST['post_id']) ) {
  35. unset($tabs['gallery']);
  36. return $tabs;
  37. }
  38. $post_id = intval($_REQUEST['post_id']);
  39. if ( $post_id )
  40. $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 ) ) );
  41. if ( empty($attachments) ) {
  42. unset($tabs['gallery']);
  43. return $tabs;
  44. }
  45. $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>");
  46. return $tabs;
  47. }
  48. add_filter('media_upload_tabs', 'update_gallery_tab');
  49. /**
  50. * {@internal Missing Short Description}}
  51. *
  52. * @since 2.5.0
  53. */
  54. function the_media_upload_tabs() {
  55. global $redir_tab;
  56. $tabs = media_upload_tabs();
  57. $default = 'type';
  58. if ( !empty($tabs) ) {
  59. echo "<ul id='sidemenu'>\n";
  60. if ( isset($redir_tab) && array_key_exists($redir_tab, $tabs) )
  61. $current = $redir_tab;
  62. elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) )
  63. $current = $_GET['tab'];
  64. else
  65. $current = apply_filters('media_upload_default_tab', $default);
  66. foreach ( $tabs as $callback => $text ) {
  67. $class = '';
  68. if ( $current == $callback )
  69. $class = " class='current'";
  70. $href = add_query_arg(array('tab' => $callback, 's' => false, 'paged' => false, 'post_mime_type' => false, 'm' => false));
  71. $link = "<a href='" . esc_url($href) . "'$class>$text</a>";
  72. echo "\t<li id='" . esc_attr("tab-$callback") . "'>$link</li>\n";
  73. }
  74. echo "</ul>\n";
  75. }
  76. }
  77. /**
  78. * {@internal Missing Short Description}}
  79. *
  80. * @since 2.5.0
  81. *
  82. * @param integer $id image attachment id
  83. * @param string $caption image caption
  84. * @param string $alt image alt attribute
  85. * @param string $title image title attribute
  86. * @param string $align image css alignment property
  87. * @param string $url image src url
  88. * @param string|bool $rel image rel attribute
  89. * @param string $size image size (thumbnail, medium, large, full or added with add_image_size() )
  90. * @return string the html to insert into editor
  91. */
  92. function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') {
  93. $html = get_image_tag($id, $alt, '', $align, $size);
  94. $rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id).'"' : '';
  95. if ( $url )
  96. $html = '<a href="' . esc_attr($url) . "\"$rel>$html</a>";
  97. $html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt );
  98. return $html;
  99. }
  100. /**
  101. * Adds image shortcode with caption to editor
  102. *
  103. * @since 2.6.0
  104. *
  105. * @param string $html
  106. * @param integer $id
  107. * @param string $caption image caption
  108. * @param string $alt image alt attribute
  109. * @param string $title image title attribute
  110. * @param string $align image css alignment property
  111. * @param string $url image src url
  112. * @param string $size image size (thumbnail, medium, large, full or added with add_image_size() )
  113. * @return string
  114. */
  115. function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
  116. if ( empty($caption) || apply_filters( 'disable_captions', '' ) )
  117. return $html;
  118. $id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
  119. if ( ! preg_match( '/width=["\']([0-9]+)/', $html, $matches ) )
  120. return $html;
  121. $width = $matches[1];
  122. $caption = str_replace( array("\r\n", "\r"), "\n", $caption);
  123. $caption = preg_replace_callback( '/<[a-zA-Z0-9]+(?: [^<>]+>)*/', '_cleanup_image_add_caption', $caption );
  124. // convert any remaining line breaks to <br>
  125. $caption = preg_replace( '/[ \n\t]*\n[ \t]*/', '<br />', $caption );
  126. $html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html );
  127. if ( empty($align) )
  128. $align = 'none';
  129. $shcode = '[caption id="' . $id . '" align="align' . $align . '" width="' . $width . '"]' . $html . ' ' . $caption . '[/caption]';
  130. return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
  131. }
  132. add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 );
  133. /**
  134. * Private preg_replace callback used in image_add_caption()
  135. *
  136. * @access private
  137. * @since 3.4.0
  138. */
  139. function _cleanup_image_add_caption( $matches ) {
  140. // remove any line breaks from inside the tags
  141. return preg_replace( '/[\r\n\t]+/', ' ', $matches[0] );
  142. }
  143. /**
  144. * Adds image html to editor
  145. *
  146. * @since 2.5.0
  147. *
  148. * @param string $html
  149. */
  150. function media_send_to_editor($html) {
  151. ?>
  152. <script type="text/javascript">
  153. /* <![CDATA[ */
  154. var win = window.dialogArguments || opener || parent || top;
  155. win.send_to_editor('<?php echo addslashes($html); ?>');
  156. /* ]]> */
  157. </script>
  158. <?php
  159. exit;
  160. }
  161. /**
  162. * This handles the file upload POST itself, creating the attachment post.
  163. *
  164. * @since 2.5.0
  165. *
  166. * @param string $file_id Index into the {@link $_FILES} array of the upload
  167. * @param int $post_id The post ID the media is associated with
  168. * @param array $post_data allows you to overwrite some of the attachment
  169. * @param array $overrides allows you to override the {@link wp_handle_upload()} behavior
  170. * @return int the ID of the attachment
  171. */
  172. function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) {
  173. $time = current_time('mysql');
  174. if ( $post = get_post($post_id) ) {
  175. if ( substr( $post->post_date, 0, 4 ) > 0 )
  176. $time = $post->post_date;
  177. }
  178. $name = $_FILES[$file_id]['name'];
  179. $file = wp_handle_upload($_FILES[$file_id], $overrides, $time);
  180. if ( isset($file['error']) )
  181. return new WP_Error( 'upload_error', $file['error'] );
  182. $name_parts = pathinfo($name);
  183. $name = trim( substr( $name, 0, -(1 + strlen($name_parts['extension'])) ) );
  184. $url = $file['url'];
  185. $type = $file['type'];
  186. $file = $file['file'];
  187. $title = $name;
  188. $content = '';
  189. // use image exif/iptc data for title and caption defaults if possible
  190. if ( $image_meta = @wp_read_image_metadata($file) ) {
  191. if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) )
  192. $title = $image_meta['title'];
  193. if ( trim( $image_meta['caption'] ) )
  194. $content = $image_meta['caption'];
  195. }
  196. // Construct the attachment array
  197. $attachment = array_merge( array(
  198. 'post_mime_type' => $type,
  199. 'guid' => $url,
  200. 'post_parent' => $post_id,
  201. 'post_title' => $title,
  202. 'post_content' => $content,
  203. ), $post_data );
  204. // This should never be set as it would then overwrite an existing attachment.
  205. if ( isset( $attachment['ID'] ) )
  206. unset( $attachment['ID'] );
  207. // Save the data
  208. $id = wp_insert_attachment($attachment, $file, $post_id);
  209. if ( !is_wp_error($id) ) {
  210. wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
  211. }
  212. return $id;
  213. }
  214. /**
  215. * This handles a sideloaded file in the same way as an uploaded file is handled by {@link media_handle_upload()}
  216. *
  217. * @since 2.6.0
  218. *
  219. * @param array $file_array Array similar to a {@link $_FILES} upload array
  220. * @param int $post_id The post ID the media is associated with
  221. * @param string $desc Description of the sideloaded file
  222. * @param array $post_data allows you to overwrite some of the attachment
  223. * @return int|object The ID of the attachment or a WP_Error on failure
  224. */
  225. function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
  226. $overrides = array('test_form'=>false);
  227. $time = current_time( 'mysql' );
  228. if ( $post = get_post( $post_id ) ) {
  229. if ( substr( $post->post_date, 0, 4 ) > 0 )
  230. $time = $post->post_date;
  231. }
  232. $file = wp_handle_sideload( $file_array, $overrides, $time );
  233. if ( isset($file['error']) )
  234. return new WP_Error( 'upload_error', $file['error'] );
  235. $url = $file['url'];
  236. $type = $file['type'];
  237. $file = $file['file'];
  238. $title = preg_replace('/\.[^.]+$/', '', basename($file));
  239. $content = '';
  240. // use image exif/iptc data for title and caption defaults if possible
  241. if ( $image_meta = @wp_read_image_metadata($file) ) {
  242. if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) )
  243. $title = $image_meta['title'];
  244. if ( trim( $image_meta['caption'] ) )
  245. $content = $image_meta['caption'];
  246. }
  247. if ( isset( $desc ) )
  248. $title = $desc;
  249. // Construct the attachment array
  250. $attachment = array_merge( array(
  251. 'post_mime_type' => $type,
  252. 'guid' => $url,
  253. 'post_parent' => $post_id,
  254. 'post_title' => $title,
  255. 'post_content' => $content,
  256. ), $post_data );
  257. // This should never be set as it would then overwrite an existing attachment.
  258. if ( isset( $attachment['ID'] ) )
  259. unset( $attachment['ID'] );
  260. // Save the attachment metadata
  261. $id = wp_insert_attachment($attachment, $file, $post_id);
  262. if ( !is_wp_error($id) )
  263. wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
  264. return $id;
  265. }
  266. /**
  267. * Adds the iframe to display content for the media upload page
  268. *
  269. * @since 2.5.0
  270. *
  271. * @param array $content_func
  272. */
  273. function wp_iframe($content_func /* ... */) {
  274. _wp_admin_html_begin();
  275. ?>
  276. <title><?php bloginfo('name') ?> &rsaquo; <?php _e('Uploads'); ?> &#8212; <?php _e('WordPress'); ?></title>
  277. <?php
  278. wp_enqueue_style( 'colors' );
  279. // Check callback name for 'media'
  280. if ( ( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) )
  281. || ( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) ) )
  282. wp_enqueue_style( 'media' );
  283. wp_enqueue_style( 'ie' );
  284. ?>
  285. <script type="text/javascript">
  286. //<![CDATA[
  287. 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();}}};
  288. var userSettings = {'url':'<?php echo SITECOOKIEPATH; ?>','uid':'<?php if ( ! isset($current_user) ) $current_user = wp_get_current_user(); echo $current_user->ID; ?>','time':'<?php echo time(); ?>'};
  289. var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup',
  290. isRtl = <?php echo (int) is_rtl(); ?>;
  291. //]]>
  292. </script>
  293. <?php
  294. do_action('admin_enqueue_scripts', 'media-upload-popup');
  295. do_action('admin_print_styles-media-upload-popup');
  296. do_action('admin_print_styles');
  297. do_action('admin_print_scripts-media-upload-popup');
  298. do_action('admin_print_scripts');
  299. do_action('admin_head-media-upload-popup');
  300. do_action('admin_head');
  301. if ( is_string($content_func) )
  302. do_action( "admin_head_{$content_func}" );
  303. ?>
  304. </head>
  305. <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="no-js">
  306. <script type="text/javascript">
  307. document.body.className = document.body.className.replace('no-js', 'js');
  308. </script>
  309. <?php
  310. $args = func_get_args();
  311. $args = array_slice($args, 1);
  312. call_user_func_array($content_func, $args);
  313. do_action('admin_print_footer_scripts');
  314. ?>
  315. <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>
  316. </body>
  317. </html>
  318. <?php
  319. }
  320. /**
  321. * Adds the media button to the editor
  322. *
  323. * @since 2.5.0
  324. *
  325. * @param string $editor_id
  326. */
  327. function media_buttons($editor_id = 'content') {
  328. wp_enqueue_media( array(
  329. 'post' => get_post()
  330. ) );
  331. // $context = apply_filters('media_buttons_context', __('Upload/Insert %s'));
  332. $img = '<span class="wp-media-buttons-icon"></span> ';
  333. echo '<a href="#" class="button insert-media add_media" data-editor="' . esc_attr( $editor_id ) . '" title="' . esc_attr__( 'Add Media' ) . '">' . $img . __( 'Add Media' ) . '</a>';
  334. // echo '<a href="' . esc_url( get_upload_iframe_src() ) . '" class="thickbox add_media" id="' . esc_attr( $editor_id ) . '-add_media" title="' . esc_attr__( 'Add Media' ) . '" onclick="return false;">' . sprintf( $context, $img ) . '</a>';
  335. }
  336. add_action( 'media_buttons', 'media_buttons' );
  337. function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) {
  338. global $post_ID;
  339. if ( empty( $post_id ) )
  340. $post_id = $post_ID;
  341. $upload_iframe_src = add_query_arg( 'post_id', (int) $post_id, admin_url('media-upload.php') );
  342. if ( $type && 'media' != $type )
  343. $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src);
  344. if ( ! empty( $tab ) )
  345. $upload_iframe_src = add_query_arg('tab', $tab, $upload_iframe_src);
  346. $upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src);
  347. return add_query_arg('TB_iframe', true, $upload_iframe_src);
  348. }
  349. /**
  350. * {@internal Missing Short Description}}
  351. *
  352. * @since 2.5.0
  353. *
  354. * @return mixed void|object WP_Error on failure
  355. */
  356. function media_upload_form_handler() {
  357. check_admin_referer('media-form');
  358. $errors = null;
  359. if ( isset($_POST['send']) ) {
  360. $keys = array_keys($_POST['send']);
  361. $send_id = (int) array_shift($keys);
  362. }
  363. if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) {
  364. $post = $_post = get_post($attachment_id, ARRAY_A);
  365. $post_type_object = get_post_type_object( $post[ 'post_type' ] );
  366. if ( !current_user_can( $post_type_object->cap->edit_post, $attachment_id ) )
  367. continue;
  368. if ( isset($attachment['post_content']) )
  369. $post['post_content'] = $attachment['post_content'];
  370. if ( isset($attachment['post_title']) )
  371. $post['post_title'] = $attachment['post_title'];
  372. if ( isset($attachment['post_excerpt']) )
  373. $post['post_excerpt'] = $attachment['post_excerpt'];
  374. if ( isset($attachment['menu_order']) )
  375. $post['menu_order'] = $attachment['menu_order'];
  376. if ( isset($send_id) && $attachment_id == $send_id ) {
  377. if ( isset($attachment['post_parent']) )
  378. $post['post_parent'] = $attachment['post_parent'];
  379. }
  380. $post = apply_filters('attachment_fields_to_save', $post, $attachment);
  381. if ( isset($attachment['image_alt']) ) {
  382. $image_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
  383. if ( $image_alt != stripslashes($attachment['image_alt']) ) {
  384. $image_alt = wp_strip_all_tags( stripslashes($attachment['image_alt']), true );
  385. // update_meta expects slashed
  386. update_post_meta( $attachment_id, '_wp_attachment_image_alt', addslashes($image_alt) );
  387. }
  388. }
  389. if ( isset($post['errors']) ) {
  390. $errors[$attachment_id] = $post['errors'];
  391. unset($post['errors']);
  392. }
  393. if ( $post != $_post )
  394. wp_update_post($post);
  395. foreach ( get_attachment_taxonomies($post) as $t ) {
  396. if ( isset($attachment[$t]) )
  397. wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false);
  398. }
  399. }
  400. if ( isset($_POST['insert-gallery']) || isset($_POST['update-gallery']) ) { ?>
  401. <script type="text/javascript">
  402. /* <![CDATA[ */
  403. var win = window.dialogArguments || opener || parent || top;
  404. win.tb_remove();
  405. /* ]]> */
  406. </script>
  407. <?php
  408. exit;
  409. }
  410. if ( isset($send_id) ) {
  411. $attachment = stripslashes_deep( $_POST['attachments'][$send_id] );
  412. $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
  413. if ( !empty($attachment['url']) ) {
  414. $rel = '';
  415. if ( strpos($attachment['url'], 'attachment_id') || get_attachment_link($send_id) == $attachment['url'] )
  416. $rel = " rel='attachment wp-att-" . esc_attr($send_id) . "'";
  417. $html = "<a href='{$attachment['url']}'$rel>$html</a>";
  418. }
  419. $html = apply_filters('media_send_to_editor', $html, $send_id, $attachment);
  420. return media_send_to_editor($html);
  421. }
  422. return $errors;
  423. }
  424. /**
  425. * {@internal Missing Short Description}}
  426. *
  427. * @since 2.5.0
  428. *
  429. * @return mixed
  430. */
  431. function wp_media_upload_handler() {
  432. $errors = array();
  433. $id = 0;
  434. if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
  435. check_admin_referer('media-form');
  436. // Upload File button was clicked
  437. $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
  438. unset($_FILES);
  439. if ( is_wp_error($id) ) {
  440. $errors['upload_error'] = $id;
  441. $id = false;
  442. }
  443. }
  444. if ( !empty($_POST['insertonlybutton']) ) {
  445. $src = $_POST['src'];
  446. if ( !empty($src) && !strpos($src, '://') )
  447. $src = "http://$src";
  448. if ( isset( $_POST['media_type'] ) && 'image' != $_POST['media_type'] ) {
  449. $title = esc_html( stripslashes( $_POST['title'] ) );
  450. if ( empty( $title ) )
  451. $title = esc_html( basename( $src ) );
  452. if ( $title && $src )
  453. $html = "<a href='" . esc_url($src) . "'>$title</a>";
  454. $type = 'file';
  455. if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) )
  456. && ( 'audio' == $ext_type || 'video' == $ext_type ) )
  457. $type = $ext_type;
  458. $html = apply_filters( $type . '_send_to_editor_url', $html, esc_url_raw( $src ), $title );
  459. } else {
  460. $align = '';
  461. $alt = esc_attr( stripslashes( $_POST['alt'] ) );
  462. if ( isset($_POST['align']) ) {
  463. $align = esc_attr( stripslashes( $_POST['align'] ) );
  464. $class = " class='align$align'";
  465. }
  466. if ( !empty($src) )
  467. $html = "<img src='" . esc_url($src) . "' alt='$alt'$class />";
  468. $html = apply_filters( 'image_send_to_editor_url', $html, esc_url_raw( $src ), $alt, $align );
  469. }
  470. return media_send_to_editor($html);
  471. }
  472. if ( !empty($_POST) ) {
  473. $return = media_upload_form_handler();
  474. if ( is_string($return) )
  475. return $return;
  476. if ( is_array($return) )
  477. $errors = $return;
  478. }
  479. if ( isset($_POST['save']) ) {
  480. $errors['upload_notice'] = __('Saved.');
  481. return media_upload_gallery();
  482. }
  483. if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) {
  484. $type = 'image';
  485. if ( isset( $_GET['type'] ) && in_array( $_GET['type'], array( 'video', 'audio', 'file' ) ) )
  486. $type = $_GET['type'];
  487. return wp_iframe( 'media_upload_type_url_form', $type, $errors, $id );
  488. }
  489. return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
  490. }
  491. /**
  492. * Download an image from the specified URL and attach it to a post.
  493. *
  494. * @since 2.6.0
  495. *
  496. * @param string $file The URL of the image to download
  497. * @param int $post_id The post ID the media is to be associated with
  498. * @param string $desc Optional. Description of the image
  499. * @return string|WP_Error Populated HTML img tag on success
  500. */
  501. function media_sideload_image($file, $post_id, $desc = null) {
  502. if ( ! empty($file) ) {
  503. // Download file to temp location
  504. $tmp = download_url( $file );
  505. // Set variables for storage
  506. // fix file filename for query strings
  507. preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
  508. $file_array['name'] = basename($matches[0]);
  509. $file_array['tmp_name'] = $tmp;
  510. // If error storing temporarily, unlink
  511. if ( is_wp_error( $tmp ) ) {
  512. @unlink($file_array['tmp_name']);
  513. $file_array['tmp_name'] = '';
  514. }
  515. // do the validation and storage stuff
  516. $id = media_handle_sideload( $file_array, $post_id, $desc );
  517. // If error storing permanently, unlink
  518. if ( is_wp_error($id) ) {
  519. @unlink($file_array['tmp_name']);
  520. return $id;
  521. }
  522. $src = wp_get_attachment_url( $id );
  523. }
  524. // Finally check to make sure the file has been saved, then return the html
  525. if ( ! empty($src) ) {
  526. $alt = isset($desc) ? esc_attr($desc) : '';
  527. $html = "<img src='$src' alt='$alt' />";
  528. return $html;
  529. }
  530. }
  531. /**
  532. * {@internal Missing Short Description}}
  533. *
  534. * @since 2.5.0
  535. *
  536. * @return unknown
  537. */
  538. function media_upload_gallery() {
  539. $errors = array();
  540. if ( !empty($_POST) ) {
  541. $return = media_upload_form_handler();
  542. if ( is_string($return) )
  543. return $return;
  544. if ( is_array($return) )
  545. $errors = $return;
  546. }
  547. wp_enqueue_script('admin-gallery');
  548. return wp_iframe( 'media_upload_gallery_form', $errors );
  549. }
  550. /**
  551. * {@internal Missing Short Description}}
  552. *
  553. * @since 2.5.0
  554. *
  555. * @return unknown
  556. */
  557. function media_upload_library() {
  558. $errors = array();
  559. if ( !empty($_POST) ) {
  560. $return = media_upload_form_handler();
  561. if ( is_string($return) )
  562. return $return;
  563. if ( is_array($return) )
  564. $errors = $return;
  565. }
  566. return wp_iframe( 'media_upload_library_form', $errors );
  567. }
  568. /**
  569. * Retrieve HTML for the image alignment radio buttons with the specified one checked.
  570. *
  571. * @since 2.7.0
  572. *
  573. * @param object $post
  574. * @param string $checked
  575. * @return string
  576. */
  577. function image_align_input_fields( $post, $checked = '' ) {
  578. if ( empty($checked) )
  579. $checked = get_user_setting('align', 'none');
  580. $alignments = array('none' => __('None'), 'left' => __('Left'), 'center' => __('Center'), 'right' => __('Right'));
  581. if ( !array_key_exists( (string) $checked, $alignments ) )
  582. $checked = 'none';
  583. $out = array();
  584. foreach ( $alignments as $name => $label ) {
  585. $name = esc_attr($name);
  586. $out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'".
  587. ( $checked == $name ? " checked='checked'" : "" ) .
  588. " /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>";
  589. }
  590. return join("\n", $out);
  591. }
  592. /**
  593. * Retrieve HTML for the size radio buttons with the specified one checked.
  594. *
  595. * @since 2.7.0
  596. *
  597. * @param object $post
  598. * @param bool|string $check
  599. * @return array
  600. */
  601. function image_size_input_fields( $post, $check = '' ) {
  602. // get a list of the actual pixel dimensions of each possible intermediate version of this image
  603. $size_names = apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) );
  604. if ( empty($check) )
  605. $check = get_user_setting('imgsize', 'medium');
  606. foreach ( $size_names as $size => $label ) {
  607. $downsize = image_downsize($post->ID, $size);
  608. $checked = '';
  609. // is this size selectable?
  610. $enabled = ( $downsize[3] || 'full' == $size );
  611. $css_id = "image-size-{$size}-{$post->ID}";
  612. // if this size is the default but that's not available, don't select it
  613. if ( $size == $check ) {
  614. if ( $enabled )
  615. $checked = " checked='checked'";
  616. else
  617. $check = '';
  618. } elseif ( !$check && $enabled && 'thumbnail' != $size ) {
  619. // if $check is not enabled, default to the first available size that's bigger than a thumbnail
  620. $check = $size;
  621. $checked = " checked='checked'";
  622. }
  623. $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 />";
  624. $html .= "<label for='{$css_id}'>$label</label>";
  625. // only show the dimensions if that choice is available
  626. if ( $enabled )
  627. $html .= " <label for='{$css_id}' class='help'>" . sprintf( "(%d&nbsp;&times;&nbsp;%d)", $downsize[1], $downsize[2] ). "</label>";
  628. $html .= '</div>';
  629. $out[] = $html;
  630. }
  631. return array(
  632. 'label' => __('Size'),
  633. 'input' => 'html',
  634. 'html' => join("\n", $out),
  635. );
  636. }
  637. /**
  638. * Retrieve HTML for the Link URL buttons with the default link type as specified.
  639. *
  640. * @since 2.7.0
  641. *
  642. * @param object $post
  643. * @param string $url_type
  644. * @return string
  645. */
  646. function image_link_input_fields($post, $url_type = '') {
  647. $file = wp_get_attachment_url($post->ID);
  648. $link = get_attachment_link($post->ID);
  649. if ( empty($url_type) )
  650. $url_type = get_user_setting('urlbutton', 'post');
  651. $url = '';
  652. if ( $url_type == 'file' )
  653. $url = $file;
  654. elseif ( $url_type == 'post' )
  655. $url = $link;
  656. return "
  657. <input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br />
  658. <button type='button' class='button urlnone' data-link-url=''>" . __('None') . "</button>
  659. <button type='button' class='button urlfile' data-link-url='" . esc_attr($file) . "'>" . __('File URL') . "</button>
  660. <button type='button' class='button urlpost' data-link-url='" . esc_attr($link) . "'>" . __('Attachment Post URL') . "</button>
  661. ";
  662. }
  663. function wp_caption_input_textarea($edit_post) {
  664. // post data is already escaped
  665. $name = "attachments[{$edit_post->ID}][post_excerpt]";
  666. return '<textarea name="' . $name . '" id="' . $name . '">' . $edit_post->post_excerpt . '</textarea>';
  667. }
  668. /**
  669. * {@internal Missing Short Description}}
  670. *
  671. * @since 2.5.0
  672. *
  673. * @param array $form_fields
  674. * @param object $post
  675. * @return array
  676. */
  677. function image_attachment_fields_to_edit($form_fields, $post) {
  678. return $form_fields;
  679. }
  680. /**
  681. * {@internal Missing Short Description}}
  682. *
  683. * @since 2.5.0
  684. *
  685. * @param array $form_fields
  686. * @param object $post {@internal $post not used}}
  687. * @return array
  688. */
  689. function media_single_attachment_fields_to_edit( $form_fields, $post ) {
  690. unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']);
  691. return $form_fields;
  692. }
  693. /**
  694. * {@internal Missing Short Description}}
  695. *
  696. * @since 2.8.0
  697. *
  698. * @param array $form_fields
  699. * @param object $post {@internal $post not used}}
  700. * @return array
  701. */
  702. function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
  703. unset($form_fields['image_url']);
  704. return $form_fields;
  705. }
  706. /**
  707. * Filters input from media_upload_form_handler() and assigns a default
  708. * post_title from the file name if none supplied.
  709. *
  710. * Illustrates the use of the attachment_fields_to_save filter
  711. * which can be used to add default values to any field before saving to DB.
  712. *
  713. * @since 2.5.0
  714. *
  715. * @param object $post
  716. * @param array $attachment {@internal $attachment not used}}
  717. * @return array
  718. */
  719. function image_attachment_fields_to_save($post, $attachment) {
  720. if ( substr($post['post_mime_type'], 0, 5) == 'image' ) {
  721. if ( strlen(trim($post['post_title'])) == 0 ) {
  722. $post['post_title'] = preg_replace('/\.\w+$/', '', basename($post['guid']));
  723. $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.');
  724. }
  725. }
  726. return $post;
  727. }
  728. add_filter('attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2);
  729. /**
  730. * {@internal Missing Short Description}}
  731. *
  732. * @since 2.5.0
  733. *
  734. * @param string $html
  735. * @param integer $attachment_id
  736. * @param array $attachment
  737. * @return array
  738. */
  739. function image_media_send_to_editor($html, $attachment_id, $attachment) {
  740. $post = get_post($attachment_id);
  741. if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
  742. $url = $attachment['url'];
  743. $align = !empty($attachment['align']) ? $attachment['align'] : 'none';
  744. $size = !empty($attachment['image-size']) ? $attachment['image-size'] : 'medium';
  745. $alt = !empty($attachment['image_alt']) ? $attachment['image_alt'] : '';
  746. $rel = ( $url == get_attachment_link($attachment_id) );
  747. return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt);
  748. }
  749. return $html;
  750. }
  751. add_filter('media_send_to_editor', 'image_media_send_to_editor', 10, 3);
  752. /**
  753. * {@internal Missing Short Description}}
  754. *
  755. * @since 2.5.0
  756. *
  757. * @param object $post
  758. * @param array $errors
  759. * @return array
  760. */
  761. function get_attachment_fields_to_edit($post, $errors = null) {
  762. if ( is_int($post) )
  763. $post = get_post($post);
  764. if ( is_array($post) )
  765. $post = new WP_Post( (object) $post );
  766. $image_url = wp_get_attachment_url($post->ID);
  767. $edit_post = sanitize_post($post, 'edit');
  768. $form_fields = array(
  769. 'post_title' => array(
  770. 'label' => __('Title'),
  771. 'value' => $edit_post->post_title
  772. ),
  773. 'image_alt' => array(),
  774. 'post_excerpt' => array(
  775. 'label' => __('Caption'),
  776. 'input' => 'html',
  777. 'html' => wp_caption_input_textarea($edit_post)
  778. ),
  779. 'post_content' => array(
  780. 'label' => __('Description'),
  781. 'value' => $edit_post->post_content,
  782. 'input' => 'textarea'
  783. ),
  784. 'url' => array(
  785. 'label' => __('Link URL'),
  786. 'input' => 'html',
  787. 'html' => image_link_input_fields($post, get_option('image_default_link_type')),
  788. 'helps' => __('Enter a link URL or click above for presets.')
  789. ),
  790. 'menu_order' => array(
  791. 'label' => __('Order'),
  792. 'value' => $edit_post->menu_order
  793. ),
  794. 'image_url' => array(
  795. 'label' => __('File URL'),
  796. 'input' => 'html',
  797. 'html' => "<input type='text' class='text urlfield' readonly='readonly' name='attachments[$post->ID][url]' value='" . esc_attr($image_url) . "' /><br />",
  798. 'value' => wp_get_attachment_url($post->ID),
  799. 'helps' => __('Location of the uploaded file.')
  800. )
  801. );
  802. foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
  803. $t = (array) get_taxonomy($taxonomy);
  804. if ( ! $t['public'] || ! $t['show_ui'] )
  805. continue;
  806. if ( empty($t['label']) )
  807. $t['label'] = $taxonomy;
  808. if ( empty($t['args']) )
  809. $t['args'] = array();
  810. $terms = get_object_term_cache($post->ID, $taxonomy);
  811. if ( false === $terms )
  812. $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
  813. $values = array();
  814. foreach ( $terms as $term )
  815. $values[] = $term->slug;
  816. $t['value'] = join(', ', $values);
  817. $form_fields[$taxonomy] = $t;
  818. }
  819. // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
  820. // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
  821. $form_fields = array_merge_recursive($form_fields, (array) $errors);
  822. // This was formerly in image_attachment_fields_to_edit().
  823. if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
  824. $alt = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
  825. if ( empty($alt) )
  826. $alt = '';
  827. $form_fields['post_title']['required'] = true;
  828. $form_fields['image_alt'] = array(
  829. 'value' => $alt,
  830. 'label' => __('Alternative Text'),
  831. 'helps' => __('Alt text for the image, e.g. &#8220;The Mona Lisa&#8221;')
  832. );
  833. $form_fields['align'] = array(
  834. 'label' => __('Alignment'),
  835. 'input' => 'html',
  836. 'html' => image_align_input_fields($post, get_option('image_default_align')),
  837. );
  838. $form_fields['image-size'] = image_size_input_fields( $post, get_option('image_default_size', 'medium') );
  839. } else {
  840. unset( $form_fields['image_alt'] );
  841. }
  842. $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post);
  843. return $form_fields;
  844. }
  845. /**
  846. * Retrieve HTML for media items of post gallery.
  847. *
  848. * The HTML markup retrieved will be created for the progress of SWF Upload
  849. * component. Will also create link for showing and hiding the form to modify
  850. * the image attachment.
  851. *
  852. * @since 2.5.0
  853. *
  854. * @param int $post_id Optional. Post ID.
  855. * @param array $errors Errors for attachment, if any.
  856. * @return string
  857. */
  858. function get_media_items( $post_id, $errors ) {
  859. $attachments = array();
  860. if ( $post_id ) {
  861. $post = get_post($post_id);
  862. if ( $post && $post->post_type == 'attachment' )
  863. $attachments = array($post->ID => $post);
  864. else
  865. $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') );
  866. } else {
  867. if ( is_array($GLOBALS['wp_the_query']->posts) )
  868. foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
  869. $attachments[$attachment->ID] = $attachment;
  870. }
  871. $output = '';
  872. foreach ( (array) $attachments as $id => $attachment ) {
  873. if ( $attachment->post_status == 'trash' )
  874. continue;
  875. if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )
  876. $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>";
  877. }
  878. return $output;
  879. }
  880. /**
  881. * Retrieve HTML form for modifying the image attachment.
  882. *
  883. * @since 2.5.0
  884. *
  885. * @param int $attachment_id Attachment ID for modification.
  886. * @param string|array $args Optional. Override defaults.
  887. * @return string HTML form for attachment.
  888. */
  889. function get_media_item( $attachment_id, $args = null ) {
  890. global $redir_tab;
  891. if ( ( $attachment_id = intval( $attachment_id ) ) && $thumb_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail', true ) )
  892. $thumb_url = $thumb_url[0];
  893. else
  894. $thumb_url = false;
  895. $post = get_post( $attachment_id );
  896. $current_post_id = !empty( $_GET['post_id'] ) ? (int) $_GET['post_id'] : 0;
  897. $default_args = array( 'errors' => null, 'send' => $current_post_id ? post_type_supports( get_post_type( $current_post_id ), 'editor' ) : true, 'delete' => true, 'toggle' => true, 'show_title' => true );
  898. $args = wp_parse_args( $args, $default_args );
  899. $args = apply_filters( 'get_media_item_args', $args );
  900. extract( $args, EXTR_SKIP );
  901. $toggle_on = __( 'Show' );
  902. $toggle_off = __( 'Hide' );
  903. $filename = esc_html( wp_basename( $post->guid ) );
  904. $title = esc_attr( $post->post_title );
  905. if ( $_tags = get_the_tags( $attachment_id ) ) {
  906. foreach ( $_tags as $tag )
  907. $tags[] = $tag->name;
  908. $tags = esc_attr( join( ', ', $tags ) );
  909. }
  910. $post_mime_types = get_post_mime_types();
  911. $keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) );
  912. $type = array_shift( $keys );
  913. $type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />";
  914. $form_fields = get_attachment_fields_to_edit( $post, $errors );
  915. if ( $toggle ) {
  916. $class = empty( $errors ) ? 'startclosed' : 'startopen';
  917. $toggle_links = "
  918. <a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
  919. <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
  920. } else {
  921. $class = '';
  922. $toggle_links = '';
  923. }
  924. $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
  925. $display_title = $show_title ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60 ) . "</span></div>" : '';
  926. $gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) );
  927. $order = '';
  928. foreach ( $form_fields as $key => $val ) {
  929. if ( 'menu_order' == $key ) {
  930. if ( $gallery )
  931. $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>";
  932. else
  933. $order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />";
  934. unset( $form_fields['menu_order'] );
  935. break;
  936. }
  937. }
  938. $media_dims = '';
  939. $meta = wp_get_attachment_metadata( $post->ID );
  940. if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
  941. $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
  942. $media_dims = apply_filters( 'media_meta', $media_dims, $post );
  943. $image_edit_button = '';
  944. if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) {
  945. $nonce = wp_create_nonce( "image_editor-$post->ID" );
  946. $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>";
  947. }
  948. $attachment_url = get_permalink( $attachment_id );
  949. $item = "
  950. $type_html
  951. $toggle_links
  952. $order
  953. $display_title
  954. <table class='slidetoggle describe $class'>
  955. <thead class='media-item-info' id='media-head-$post->ID'>
  956. <tr valign='top'>
  957. <td class='A1B1' id='thumbnail-head-$post->ID'>
  958. <p><a href='$attachment_url' target='_blank'><img class='thumbnail' src='$thumb_url' alt='' /></a></p>
  959. <p>$image_edit_button</p>
  960. </td>
  961. <td>
  962. <p><strong>" . __('File name:') . "</strong> $filename</p>
  963. <p><strong>" . __('File type:') . "</strong> $post->post_mime_type</p>
  964. <p><strong>" . __('Upload date:') . "</strong> " . mysql2date( get_option('date_format'), $post->post_date ). '</p>';
  965. if ( !empty( $media_dims ) )
  966. $item .= "<p><strong>" . __('Dimensions:') . "</strong> $media_dims</p>\n";
  967. $item .= "</td></tr>\n";
  968. $item .= "
  969. </thead>
  970. <tbody>
  971. <tr><td colspan='2' class='imgedit-response' id='imgedit-response-$post->ID'></td></tr>
  972. <tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n";
  973. $defaults = array(
  974. 'input' => 'text',
  975. 'required' => false,
  976. 'value' => '',
  977. 'extra_rows' => array(),
  978. );
  979. if ( $send )
  980. $send = get_submit_button( __( 'Insert into Post' ), 'button', "send[$attachment_id]", false );
  981. if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) {
  982. if ( !EMPTY_TRASH_DAYS ) {
  983. $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>';
  984. } elseif ( !MEDIA_TRASH ) {
  985. $delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a>
  986. <div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'><p>" . sprintf( __( 'You are about to delete <strong>%s</strong>.' ), $filename ) . "</p>
  987. <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>
  988. <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . "</a>
  989. </div>";
  990. } else {
  991. $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>
  992. <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>";
  993. }
  994. } else {
  995. $delete = '';
  996. }
  997. $thumbnail = '';
  998. $calling_post_id = 0;
  999. if ( isset( $_GET['post_id'] ) )
  1000. $calling_post_id = absint( $_GET['post_id'] );
  1001. elseif ( isset( $_POST ) && count( $_POST ) ) // Like for async-upload where $_GET['post_id'] isn't set
  1002. $calling_post_id = $post->post_parent;
  1003. if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) )
  1004. && post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) {
  1005. $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" );
  1006. $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>";
  1007. }
  1008. if ( ( $send || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) )
  1009. $form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $thumbnail $delete</td></tr>\n" );
  1010. $hidden_fields = array();
  1011. foreach ( $form_fields as $id => $field ) {
  1012. if ( $id[0] == '_' )
  1013. continue;
  1014. if ( !empty( $field['tr'] ) ) {
  1015. $item .= $field['tr'];
  1016. continue;
  1017. }
  1018. $field = array_merge( $defaults, $field );
  1019. $name = "attachments[$attachment_id][$id]";
  1020. if ( $field['input'] == 'hidden' ) {
  1021. $hidden_fields[$name] = $field['value'];
  1022. continue;
  1023. }
  1024. $required = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : '';
  1025. $aria_required = $field['required'] ? " aria-required='true' " : '';
  1026. $class = $id;
  1027. $class .= $field['required'] ? ' form-required' : '';
  1028. $item .= "\t\t<tr class='$class'>\n\t\t\t<th valign='top' scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label></th>\n\t\t\t<td class='field'>";
  1029. if ( !empty( $field[ $field['input'] ] ) )
  1030. $item .= $field[ $field['input'] ];
  1031. elseif ( $field['input'] == 'textarea' ) {
  1032. if ( 'post_content' == $id && user_can_richedit() ) {
  1033. // sanitize_post() skips the post_content when user_can_richedit
  1034. $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
  1035. }
  1036. // post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit()
  1037. $item .= "<textarea id='$name' name='$name' $aria_required>" . $field['value'] . '</textarea>';
  1038. } else {
  1039. $item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />";
  1040. }
  1041. if ( !empty( $field['helps'] ) )
  1042. $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
  1043. $item .= "</td>\n\t\t</tr>\n";
  1044. $extra_rows = array();
  1045. if ( !empty( $field['errors'] ) )
  1046. foreach ( array_unique( (array) $field['errors'] ) as $error )
  1047. $extra_rows['error'][] = $error;
  1048. if ( !empty( $field['extra_rows'] ) )
  1049. foreach ( $field['extra_rows'] as $class => $rows )
  1050. foreach ( (array) $rows as $html )
  1051. $extra_rows[$class][] = $html;
  1052. foreach ( $extra_rows as $class => $rows )
  1053. foreach ( $rows as $html )
  1054. $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
  1055. }
  1056. if ( !empty( $form_fields['_final'] ) )
  1057. $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
  1058. $item .= "\t</tbody>\n";
  1059. $item .= "\t</table>\n";
  1060. foreach ( $hidden_fields as $name => $value )
  1061. $item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\n";
  1062. if ( $post->post_parent < 1 && isset( $_REQUEST['post_id'] ) ) {
  1063. $parent = (int) $_REQUEST['post_id'];
  1064. $parent_name = "attachments[$attachment_id][post_parent]";
  1065. $item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='$parent' />\n";
  1066. }
  1067. return $item;
  1068. }
  1069. function get_compat_media_markup( $attachment_id, $args = null ) {
  1070. $post = get_post( $attachment_id );
  1071. $default_args = array(
  1072. 'errors' => null,
  1073. 'taxonomies' => false,
  1074. );
  1075. $args = wp_parse_args( $args, $default_args );
  1076. $args = apply_filters( 'get_media_item_args', $args );
  1077. $form_fields = array();
  1078. if ( $args['taxonomies'] ) {
  1079. foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
  1080. $t = (array) get_taxonomy($taxonomy);
  1081. if ( ! $t['public'] || ! $t['show_ui'] )
  1082. continue;
  1083. if ( empty($t['label']) )
  1084. $t['label'] = $taxonomy;
  1085. if ( empty($t['args']) )
  1086. $t['args'] = array();
  1087. $terms = get_object_term_cache($post->ID, $taxonomy);
  1088. if ( false === $terms )
  1089. $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
  1090. $values = array();
  1091. foreach ( $terms as $term )
  1092. $values[] = $term->slug;
  1093. $t['value'] = join(', ', $values);
  1094. $form_fields[$taxonomy] = $t;
  1095. }
  1096. }
  1097. // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
  1098. // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
  1099. $form_fields = array_merge_recursive($form_fields, (array) $args['errors'] );
  1100. $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );
  1101. unset( $form_fields['image-size'], $form_fields['align'], $form_fields['image_alt'],
  1102. $form_fields['post_title'], $form_fields['post_excerpt'], $form_fields['post_content'],
  1103. $form_fields['url'], $form_fields['menu_order'], $form_fields['image_url'] );
  1104. $media_meta = apply_filters( 'media_meta', '', $post );
  1105. $defaults = array(
  1106. 'input' => 'text',
  1107. 'required' => false,
  1108. 'value' => '',
  1109. 'extra_rows' => array(),
  1110. );
  1111. $hidden_fields = array();
  1112. $item = '';
  1113. foreach ( $form_fields as $id => $field ) {
  1114. if ( $id[0] == '_' )
  1115. continue;
  1116. $name = "attachments[$attachment_id][$id]";
  1117. $id_attr = "attachments-$attachment_id-$id";
  1118. if ( !empty( $field['tr'] ) ) {
  1119. $item .= $field['tr'];
  1120. continue;
  1121. }
  1122. $field = array_merge( $defaults, $field );
  1123. if ( $field['input'] == 'hidden' ) {
  1124. $hidden_fields[$name] = $field['value'];
  1125. continue;
  1126. }
  1127. $required = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : '';
  1128. $aria_required = $field['required'] ? " aria-required='true' " : '';
  1129. $class = 'compat-field-' . $id;
  1130. $class .= $field['required'] ? ' form-required' : '';
  1131. $item .= "\t\t<tr class='$class'>";
  1132. $item .= "\t\t\t<th valign='top' scope='row' class='label'><label for='$id_attr'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label>";
  1133. $item .= "</th>\n\t\t\t<td class='field'>";
  1134. if ( !empty( $field[ $field['input'] ] ) )
  1135. $item .= $field[ $field['input'] ];
  1136. elseif ( $field['input'] == 'textarea' ) {
  1137. if ( 'post_content' == $id && user_can_richedit() ) {
  1138. // sanitize_post() skips the post_content when user_can_richedit
  1139. $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
  1140. }
  1141. $item .= "<textarea id='$id_attr' name='$name' $aria_required>" . $field['value'] . '</textarea>';
  1142. } else {
  1143. $item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />";
  1144. }
  1145. if ( !empty( $field['helps'] ) )
  1146. $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
  1147. $item .= "</td>\n\t\t</tr>\n";
  1148. $extra_rows = array();
  1149. if ( !empty( $field['errors'] ) )
  1150. foreach ( array_unique( (array) $field['errors'] ) as $error )
  1151. $extra_rows['error'][] = $error;
  1152. if ( !empty( $field['extra_rows'] ) )
  1153. foreach ( $field['extra_rows'] as $class => $rows )
  1154. foreach ( (array) $rows as $html )
  1155. $extra_rows[$class][] = $html;
  1156. foreach ( $extra_rows as $class => $rows )
  1157. foreach ( $rows as $html )
  1158. $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
  1159. }
  1160. if ( !empty( $form_fields['_final'] ) )
  1161. $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
  1162. if ( $item )
  1163. $item = '<table class="compat-attachment-fields">' . $item . '</table>';
  1164. return array(
  1165. 'item' => $item,
  1166. 'hidden' => $hidden_fields,
  1167. 'meta' => $media_meta,
  1168. );
  1169. }
  1170. /**
  1171. * {@internal Missing Short Description}}
  1172. *
  1173. * @since 2.5.0
  1174. */
  1175. function media_upload_header() {
  1176. $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
  1177. echo '<script type="text/javascript">post_id = ' . $post_id . ";</script>\n";
  1178. if ( empty( $_GET['chromeless'] ) ) {
  1179. echo '<div id="media-upload-header">';
  1180. the_media_upload_tabs();
  1181. echo '</div>';
  1182. }
  1183. }
  1184. /**
  1185. * {@internal Missing Short Description}}
  1186. *
  1187. * @since 2.5.0
  1188. *
  1189. * @param unknown_type $errors
  1190. */
  1191. function media_upload_form( $errors = null ) {
  1192. global $type, $tab, $pagenow, $is_IE, $is_opera;
  1193. if ( ! _device_can_upload() ) {
  1194. echo '<p>' . __('The web browser on your device cannot be used to upload files. You may be able to use the <a href="http://wordpress.org/extend/mobile/">native app for your device</a> instead.') . '</p>';
  1195. return;
  1196. }
  1197. $upload_action_url = admin_url('async-upload.php');
  1198. $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
  1199. $_type = isset($type) ? $type : '';
  1200. $_tab = isset($tab) ? $tab : '';
  1201. $upload_size_unit = $max_upload_size = wp_max_upload_size();
  1202. $sizes = array( 'KB', 'MB', 'GB' );
  1203. for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) {
  1204. $upload_size_unit /= 1024;
  1205. }
  1206. if ( $u < 0 ) {
  1207. $upload_size_unit = 0;
  1208. $u = 0;
  1209. } else {
  1210. $upload_size_unit = (int) $upload_size_unit;
  1211. }
  1212. ?>
  1213. <div id="media-upload-notice"><?php
  1214. if (isset($errors['upload_notice']) )
  1215. echo $errors['upload_notice'];
  1216. ?></div>
  1217. <div id="media-upload-error"><?php
  1218. if (isset($errors['upload_error']) && is_wp_error($errors['upload_error']))
  1219. echo $errors['upload_error']->get_error_message();
  1220. ?></div>
  1221. <?php
  1222. if ( is_multisite() && !is_upload_space_available() ) {
  1223. do_action( 'upload_ui_over_quota' );
  1224. return;
  1225. }
  1226. do_action('pre-upload-ui');
  1227. $post_params = array(
  1228. "post_id" => $post_id,
  1229. "_wpnonce" => wp_create_nonce('media-form'),
  1230. "type" => $_type,
  1231. "tab" => $_tab,
  1232. "short" => "1",
  1233. );
  1234. $post_params = apply_filters( 'upload_post_params', $post_params ); // hook change! old name: 'swfupload_post_params'
  1235. $plupload_init = array(
  1236. 'runtimes' => 'html5,silverlight,flash,html4',
  1237. 'browse_button' => 'plupload-browse-button',
  1238. 'container' => 'plupload-upload-ui',
  1239. 'drop_element' => 'drag-drop-area',
  1240. 'file_data_name' => 'async-upload',
  1241. 'multiple_queues' => true,
  1242. 'max_file_size' => $max_upload_size . 'b',
  1243. 'url' => $upload_action_url,
  1244. 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'),
  1245. 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'),
  1246. 'filters' => array( array('title' => __( 'Allowed Files' ), 'extensions' => '*') ),
  1247. 'multipart' => true,
  1248. 'urlstream_upload' => true,
  1249. 'multipart_params' => $post_params
  1250. );
  1251. $plupload_init = apply_filters( 'plupload_init', $plupload_init );
  1252. ?>
  1253. <script type="text/javascript">
  1254. <?php
  1255. // Verify size is an int. If not return default value.
  1256. $large_size_h = absint( get_option('large_size_h') );
  1257. if( !$large_size_h )
  1258. $large_size_h = 1024;
  1259. $large_size_w = absint( get_option('large_size_w') );
  1260. if( !$large_size_w )
  1261. $large_size_w = 1024;
  1262. ?>
  1263. var resize_height = <?php echo $large_size_h; ?>, resize_width = <?php echo $large_size_w; ?>,
  1264. wpUploaderInit = <?php echo json_encode($plupload_init); ?>;
  1265. </script>
  1266. <div id="plupload-upload-ui" class="hide-if-no-js">
  1267. <?php do_action('pre-plupload-upload-ui'); // hook change, old name: 'pre-flash-upload-ui' ?>
  1268. <div id="drag-drop-area">
  1269. <div class="drag-drop-inside">
  1270. <p class="drag-drop-info"><?php _e('Drop files here'); ?></p>
  1271. <p><?php _ex('or', 'Uploader: Drop files here - or - Select Files'); ?></p>
  1272. <p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e('Select Files'); ?>" class="button" /></p>
  1273. </div>
  1274. </div>
  1275. <?php do_action('post-plupload-upload-ui'); // hook change, old name: 'post-flash-upload-ui' ?>
  1276. </div>
  1277. <div id="html-upload-ui" class="hide-if-js">
  1278. <?php do_action('pre-html-upload-ui'); ?>
  1279. <p id="async-upload-wrap">
  1280. <label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label>
  1281. <input type="file" name="async-upload" id="async-upload" />
  1282. <?php submit_button( __( 'Upload' ), 'button', 'html-upload', false ); ?>
  1283. <a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a>
  1284. </p>
  1285. <div class="clear"></div>
  1286. <?php do_action('post-html-upload-ui'); ?>
  1287. </div>
  1288. <span class="max-upload-size"><?php printf( __( 'Maximum upload file size: %d%s.' ), esc_html($upload_size_unit), esc_html($sizes[$u]) ); ?></span>
  1289. <?php
  1290. if ( ($is_IE || $is_opera) && $max_upload_size > 100 * 1024 * 1024 ) { ?>
  1291. <span class="big-file-warning"><?php _e('Your browser has some limitations uploading large files with the multi-file uploader. Please use the browser uploader for files over 100MB.'); ?></span>
  1292. <?php }
  1293. do_action('post-upload-ui');
  1294. }
  1295. /**
  1296. * {@internal Missing Short Description}}
  1297. *
  1298. * @since 2.5.0
  1299. *
  1300. * @param string $type
  1301. * @param object $errors
  1302. * @param integer $id
  1303. */
  1304. function media_upload_type_form($type = 'file', $errors = null, $id = null) {
  1305. media_upload_header();
  1306. $post_id = isset( $_REQUEST['post_id'] )? intval( $_REQUEST['post_id'] ) : 0;
  1307. $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
  1308. $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
  1309. $form_class = 'media-upload-form type-form validate';
  1310. if ( get_user_setting('uploader') )
  1311. $form_class .= ' html-uploader';
  1312. ?>
  1313. <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form">
  1314. <?php submit_button( '', 'hidden', 'save', false ); ?>
  1315. <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  1316. <?php wp_nonce_field('media-form'); ?>
  1317. <h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3>
  1318. <?php media_upload_form( $errors ); ?>
  1319. <script type="text/javascript">
  1320. //<![CDATA[
  1321. jQuery(function($){
  1322. var preloaded = $(".media-item.preloaded");
  1323. if ( preloaded.length > 0 ) {
  1324. preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
  1325. }
  1326. updateMediaForm();
  1327. });
  1328. //]]>
  1329. </script>
  1330. <div id="media-items"><?php
  1331. if ( $id ) {
  1332. if ( !is_wp_error($id) ) {
  1333. add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2);
  1334. echo get_media_items( $id, $errors );
  1335. } else {
  1336. echo '<div id="media-upload-error">'.esc_html($id->get_error_message()).'</div></div>';
  1337. exit;
  1338. }
  1339. }
  1340. ?></div>
  1341. <p class="savebutton ml-submit">
  1342. <?php submit_button( __( 'Save all changes' ), 'button', 'save', false ); ?>
  1343. </p>
  1344. </form>
  1345. <?php
  1346. }
  1347. /**
  1348. * {@internal Missing Short Description}}
  1349. *
  1350. * @since 2.7.0
  1351. *
  1352. * @param string $type
  1353. * @param object $errors
  1354. * @param integer $id
  1355. */
  1356. function media_upload_type_url_form($type = null, $errors = null, $id = null) {
  1357. if ( null === $type )
  1358. $type = 'image';
  1359. media_upload_header();
  1360. $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
  1361. $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
  1362. $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
  1363. $form_class = 'media-upload-form type-form validate';
  1364. if ( get_user_setting('uploader') )
  1365. $form_class .= ' html-uploader';
  1366. ?>
  1367. <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form">
  1368. <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  1369. <?php wp_nonce_field('media-form'); ?>
  1370. <h3 class="media-title"><?php _e('Insert media from another website'); ?></h3>
  1371. <script type="text/javascript">
  1372. //<![CDATA[
  1373. var addExtImage = {
  1374. width : '',
  1375. height : '',
  1376. align : 'alignnone',
  1377. insert : function() {
  1378. var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = '';
  1379. if ( '' == f.src.value || '' == t.width )
  1380. return false;
  1381. if ( f.alt.value )
  1382. alt = f.alt.value.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  1383. <?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?>
  1384. if ( f.caption.value ) {
  1385. caption = f.caption.value.replace(/\r\n|\r/g, '\n');
  1386. caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){
  1387. return a.replace(/[\r\n\t]+/, ' ');
  1388. });
  1389. caption = caption.replace(/\s*\n\s*/g, '<br />');
  1390. }
  1391. <?php } ?>
  1392. cls = caption ? '' : ' class="'+t.align+'"';
  1393. html = '<img alt="'+alt+'" src="'+f.src.value+'"'+cls+' width="'+t.width+'" height="'+t.height+'" />';
  1394. if ( f.url.value ) {
  1395. url = f.url.value.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  1396. html = '<a href="'+url+'">'+html+'</a>';
  1397. }
  1398. if ( caption )
  1399. html = '[caption id="" align="'+t.align+'" width="'+t.width+'"]'+html+caption+'[/caption]';
  1400. var win = window.dialogArguments || opener || parent || top;
  1401. win.send_to_editor(html);
  1402. return false;
  1403. },
  1404. resetImageData : function() {
  1405. var t = addExtImage;
  1406. t.width = t.height = '';
  1407. document.getElementById('go_button').style.color = '#bbb';
  1408. if ( ! document.forms[0].src.value )
  1409. document.getElementById('status_img').innerHTML = '*';
  1410. else document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/no.png' ) ); ?>" alt="" />';
  1411. },
  1412. updateImageData : function() {
  1413. var t = addExtImage;
  1414. t.width = t.preloadImg.width;
  1415. t.height = t.preloadImg.height;
  1416. document.getElementById('go_button').style.color = '#333';
  1417. document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/yes.png' ) ); ?>" alt="" />';
  1418. },
  1419. getImageData : function() {
  1420. if ( jQuery('table.describe').hasClass('not-image') )
  1421. return;
  1422. var t = addExtImage, src = document.forms[0].src.value;
  1423. if ( ! src ) {
  1424. t.resetImageData();
  1425. return false;
  1426. }
  1427. document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" width="16" />';
  1428. t.preloadImg = new Image();
  1429. t.preloadImg.onload = t.updateImageData;
  1430. t.preloadImg.onerror = t.resetImageData;
  1431. t.preloadImg.src = src;
  1432. }
  1433. }
  1434. jQuery(document).ready( function($) {
  1435. $('.media-types input').click( function() {
  1436. $('table.describe').toggleClass('not-image', $('#not-image').prop('checked') );
  1437. });
  1438. });
  1439. //]]>
  1440. </script>
  1441. <div id="media-items">
  1442. <div class="media-item media-blank">
  1443. <?php echo apply_filters( 'type_url_form_media', wp_media_insert_url_form( $type ) ); ?>
  1444. </div>
  1445. </div>
  1446. </form>
  1447. <?php
  1448. }
  1449. /**
  1450. * Adds gallery form to upload iframe
  1451. *
  1452. * @since 2.5.0
  1453. *
  1454. * @param array $errors
  1455. */
  1456. function media_upload_gallery_form($errors) {
  1457. global $redir_tab, $type;
  1458. $redir_tab = 'gallery';
  1459. media_upload_header();
  1460. $post_id = intval($_REQUEST['post_id']);
  1461. $form_action_url = admin_url("media-upload.php?type=$type&tab=gallery&post_id=$post_id");
  1462. $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
  1463. $form_class = 'media-upload-form validate';
  1464. if ( get_user_setting('uploader') )
  1465. $form_class .= ' html-uploader';
  1466. ?>
  1467. <script type="text/javascript">
  1468. <!--
  1469. jQuery(function($){
  1470. var preloaded = $(".media-item.preloaded");
  1471. if ( preloaded.length > 0 ) {
  1472. preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
  1473. updateMediaForm();
  1474. }
  1475. });
  1476. -->
  1477. </script>
  1478. <div id="sort-buttons" class="hide-if-no-js">
  1479. <span>
  1480. <?php _e('All Tabs:'); ?>
  1481. <a href="#" id="showall"><?php _e('Show'); ?></a>
  1482. <a href="#" id="hideall" style="display:none;"><?php _e('Hide'); ?></a>
  1483. </span>
  1484. <?php _e('Sort Order:'); ?>
  1485. <a href="#" id="asc"><?php _e('Ascending'); ?></a> |
  1486. <a href="#" id="desc"><?php _e('Descending'); ?></a> |
  1487. <a href="#" id="clear"><?php _ex('Clear', 'verb'); ?></a>
  1488. </div>
  1489. <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="<?php echo $form_class; ?>" id="gallery-form">
  1490. <?php wp_nonce_field('media-form'); ?>
  1491. <?php //media_upload_form( $errors ); ?>
  1492. <table class="widefat" cellspacing="0">
  1493. <thead><tr>
  1494. <th><?php _e('Media'); ?></th>
  1495. <th class="order-head"><?php _e('Order'); ?></th>
  1496. <th class="actions-head"><?php _e('Actions'); ?></th>
  1497. </tr></thead>
  1498. </table>
  1499. <div id="media-items">
  1500. <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
  1501. <?php echo get_media_items($post_id, $errors); ?>
  1502. </div>
  1503. <p class="ml-submit">
  1504. <?php submit_button( __( 'Save all changes' ), 'button savebutton', 'save', false, array( 'id' => 'save-all', 'style' => 'display: none;' ) ); ?>
  1505. <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  1506. <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" />
  1507. <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" />
  1508. </p>
  1509. <div id="gallery-settings" style="display:none;">
  1510. <div class="title"><?php _e('Gallery Settings'); ?></div>
  1511. <table id="basic" class="describe"><tbody>
  1512. <tr>
  1513. <th scope="row" class="label">
  1514. <label>
  1515. <span class="alignleft"><?php _e('Link thumbnails to:'); ?></span>
  1516. </label>
  1517. </th>
  1518. <td class="field">
  1519. <input type="radio" name="linkto" id="linkto-file" value="file" />
  1520. <label for="linkto-file" class="radio"><?php _e('Image File'); ?></label>
  1521. <input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" />
  1522. <label for="linkto-post" class="radio"><?php _e('Attachment Page'); ?></label>
  1523. </td>
  1524. </tr>
  1525. <tr>
  1526. <th scope="row" class="label">
  1527. <label>
  1528. <span class="alignleft"><?php _e('Order images by:'); ?></span>
  1529. </label>
  1530. </th>
  1531. <td class="field">
  1532. <select id="orderby" name="orderby">
  1533. <option value="menu_order" selected="selected"><?php _e('Menu order'); ?></option>
  1534. <option value="title"><?php _e('Title'); ?></option>
  1535. <option value="post_date"><?php _e('Date/Time'); ?></option>
  1536. <option value="rand"><?php _e('Random'); ?></option>
  1537. </select>
  1538. </td>
  1539. </tr>
  1540. <tr>
  1541. <th scope="row" class="label">
  1542. <label>
  1543. <span class="alignleft"><?php _e('Order:'); ?></span>
  1544. </label>
  1545. </th>
  1546. <td class="field">
  1547. <input type="radio" checked="checked" name="order" id="order-asc" value="asc" />
  1548. <label for="order-asc" class="radio"><?php _e('Ascending'); ?></label>
  1549. <input type="radio" name="order" id="order-desc" value="desc" />
  1550. <label for="order-desc" class="radio"><?php _e('Descending'); ?></label>
  1551. </td>
  1552. </tr>
  1553. <tr>
  1554. <th scope="row" class="label">
  1555. <label>
  1556. <span class="alignleft"><?php _e('Gallery columns:'); ?></span>
  1557. </label>
  1558. </th>
  1559. <td class="field">
  1560. <select id="columns" name="columns">
  1561. <option value="1">1</option>
  1562. <option value="2">2</option>
  1563. <option value="3" selected="selected">3</option>
  1564. <option value="4">4</option>
  1565. <option value="5">5</option>
  1566. <option value="6">6</option>
  1567. <option value="7">7</option>
  1568. <option value="8">8</option>
  1569. <option value="9">9</option>
  1570. </select>
  1571. </td>
  1572. </tr>
  1573. </tbody></table>
  1574. <p class="ml-submit">
  1575. <input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php esc_attr_e( 'Insert gallery' ); ?>" />
  1576. <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' ); ?>" />
  1577. </p>
  1578. </div>
  1579. </form>
  1580. <?php
  1581. }
  1582. /**
  1583. * {@internal Missing Short Description}}
  1584. *
  1585. * @since 2.5.0
  1586. *
  1587. * @param array $errors
  1588. */
  1589. function media_upload_library_form($errors) {
  1590. global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
  1591. media_upload_header();
  1592. $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
  1593. $form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id");
  1594. $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
  1595. $form_class = 'media-upload-form validate';
  1596. if ( get_user_setting('uploader') )
  1597. $form_class .= ' html-uploader';
  1598. $_GET['paged'] = isset( $_GET['paged'] ) ? intval($_GET['paged']) : 0;
  1599. if ( $_GET['paged'] < 1 )
  1600. $_GET['paged'] = 1;
  1601. $start = ( $_GET['paged'] - 1 ) * 10;
  1602. if ( $start < 1 )
  1603. $start = 0;
  1604. add_filter( 'post_limits', create_function( '$a', "return 'LIMIT $start, 10';" ) );
  1605. list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
  1606. ?>
  1607. <form id="filter" action="" method="get">
  1608. <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" />
  1609. <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" />
  1610. <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" />
  1611. <input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" />
  1612. <input type="hidden" name="context" value="<?php echo isset( $_GET['context'] ) ? esc_attr( $_GET['context'] ) : ''; ?>" />
  1613. <p id="media-search" class="search-box">
  1614. <label class="screen-reader-text" for="media-search-input"><?php _e('Search Media');?>:</label>
  1615. <input type="search" id="media-search-input" name="s" value="<?php the_search_query(); ?>" />
  1616. <?php submit_button( __( 'Search Media' ), 'button', '', false ); ?>
  1617. </p>
  1618. <ul class="subsubsub">
  1619. <?php
  1620. $type_links = array();
  1621. $_num_posts = (array) wp_count_attachments();
  1622. $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
  1623. foreach ( $matches as $_type => $reals )
  1624. foreach ( $reals as $real )
  1625. if ( isset($num_posts[$_type]) )
  1626. $num_posts[$_type] += $_num_posts[$real];
  1627. else
  1628. $num_posts[$_type] = $_num_posts[$real];
  1629. // If available type specified by media button clicked, filter by that type
  1630. if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) {
  1631. $_GET['post_mime_type'] = $type;
  1632. list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
  1633. }
  1634. if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' )
  1635. $class = ' class="current"';
  1636. else
  1637. $class = '';
  1638. $type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . "'$class>".__('All Types')."</a>";
  1639. foreach ( $post_mime_types as $mime_type => $label ) {
  1640. $class = '';
  1641. if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
  1642. continue;
  1643. if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
  1644. $class = ' class="current"';
  1645. $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>';
  1646. }
  1647. echo implode(' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>';
  1648. unset($type_links);
  1649. ?>
  1650. </ul>
  1651. <div class="tablenav">
  1652. <?php
  1653. $page_links = paginate_links( array(
  1654. 'base' => add_query_arg( 'paged', '%#%' ),
  1655. 'format' => '',
  1656. 'prev_text' => __('&laquo;'),
  1657. 'next_text' => __('&raquo;'),
  1658. 'total' => ceil($wp_query->found_posts / 10),
  1659. 'current' => $_GET['paged']
  1660. ));
  1661. if ( $page_links )
  1662. echo "<div class='tablenav-pages'>$page_links</div>";
  1663. ?>
  1664. <div class="alignleft actions">
  1665. <?php
  1666. $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";
  1667. $arc_result = $wpdb->get_results( $arc_query );
  1668. $month_count = count($arc_result);
  1669. if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?>
  1670. <select name='m'>
  1671. <option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>
  1672. <?php
  1673. foreach ($arc_result as $arc_row) {
  1674. if ( $arc_row->yyear == 0 )
  1675. continue;
  1676. $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
  1677. if ( isset($_GET['m']) && ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] ) )
  1678. $default = ' selected="selected"';
  1679. else
  1680. $default = '';
  1681. echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>";
  1682. echo esc_html( $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear" );
  1683. echo "</option>\n";
  1684. }
  1685. ?>
  1686. </select>
  1687. <?php } ?>
  1688. <?php submit_button( __( 'Filter &#187;' ), 'button', 'post-query-submit', false ); ?>
  1689. </div>
  1690. <br class="clear" />
  1691. </div>
  1692. </form>
  1693. <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="<?php echo $form_class; ?>" id="library-form">
  1694. <?php wp_nonce_field('media-form'); ?>
  1695. <?php //media_upload_form( $errors ); ?>
  1696. <script type="text/javascript">
  1697. <!--
  1698. jQuery(function($){
  1699. var preloaded = $(".media-item.preloaded");
  1700. if ( preloaded.length > 0 ) {
  1701. preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
  1702. updateMediaForm();
  1703. }
  1704. });
  1705. -->
  1706. </script>
  1707. <div id="media-items">
  1708. <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
  1709. <?php echo get_media_items(null, $errors); ?>
  1710. </div>
  1711. <p class="ml-submit">
  1712. <?php submit_button( __( 'Save all changes' ), 'button savebutton', 'save', false ); ?>
  1713. <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  1714. </p>
  1715. </form>
  1716. <?php
  1717. }
  1718. /**
  1719. * Creates the form for external url
  1720. *
  1721. * @since 2.7.0
  1722. *
  1723. * @param string $default_view
  1724. * @return string the form html
  1725. */
  1726. function wp_media_insert_url_form( $default_view = 'image' ) {
  1727. if ( !apply_filters( 'disable_captions', '' ) ) {
  1728. $caption = '
  1729. <tr class="image-only">
  1730. <th valign="top" scope="row" class="label">
  1731. <label for="caption"><span class="alignleft">' . __('Image Caption') . '</span></label>
  1732. </th>
  1733. <td class="field"><textarea id="caption" name="caption"></textarea></td>
  1734. </tr>
  1735. ';
  1736. } else {
  1737. $caption = '';
  1738. }
  1739. $default_align = get_option('image_default_align');
  1740. if ( empty($default_align) )
  1741. $default_align = 'none';
  1742. if ( 'image' == $default_view ) {
  1743. $view = 'image-only';
  1744. $table_class = '';
  1745. } else {
  1746. $view = $table_class = 'not-image';
  1747. }
  1748. return '
  1749. <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>
  1750. <table class="describe ' . $table_class . '"><tbody>
  1751. <tr>
  1752. <th valign="top" scope="row" class="label" style="width:130px;">
  1753. <label for="src"><span class="alignleft">' . __('URL') . '</span></label>
  1754. <span class="alignright"><abbr id="status_img" title="required" class="required">*</abbr></span>
  1755. </th>
  1756. <td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td>
  1757. </tr>
  1758. <tr>
  1759. <th valign="top" scope="row" class="label">
  1760. <label for="title"><span class="alignleft">' . __('Title') . '</span></label>
  1761. <span class="alignright"><abbr title="required" class="required">*</abbr></span>
  1762. </th>
  1763. <td class="field"><input id="title" name="title" value="" type="text" aria-required="true" /></td>
  1764. </tr>
  1765. <tr class="not-image"><td></td><td><p class="help">' . __('Link text, e.g. &#8220;Ransom Demands (PDF)&#8221;') . '</p></td></tr>
  1766. <tr class="image-only">
  1767. <th valign="top" scope="row" class="label">
  1768. <label for="alt"><span class="alignleft">' . __('Alternative Text') . '</span></label>
  1769. </th>
  1770. <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" />
  1771. <p class="help">' . __('Alt text for the image, e.g. &#8220;The Mona Lisa&#8221;') . '</p></td>
  1772. </tr>
  1773. ' . $caption . '
  1774. <tr class="align image-only">
  1775. <th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
  1776. <td class="field">
  1777. <input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' />
  1778. <label for="align-none" class="align image-align-none-label">' . __('None') . '</label>
  1779. <input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' />
  1780. <label for="align-left" class="align image-align-left-label">' . __('Left') . '</label>
  1781. <input name="align" id="align-center" value="center" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'center' ? ' checked="checked"' : '').' />
  1782. <label for="align-center" class="align image-align-center-label">' . __('Center') . '</label>
  1783. <input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'right' ? ' checked="checked"' : '').' />
  1784. <label for="align-right" class="align image-align-right-label">' . __('Right') . '</label>
  1785. </td>
  1786. </tr>
  1787. <tr class="image-only">
  1788. <th valign="top" scope="row" class="label">
  1789. <label for="url"><span class="alignleft">' . __('Link Image To:') . '</span></label>
  1790. </th>
  1791. <td class="field"><input id="url" name="url" value="" type="text" /><br />
  1792. <button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button>
  1793. <button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button>
  1794. <p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td>
  1795. </tr>
  1796. <tr class="image-only">
  1797. <td></td>
  1798. <td>
  1799. <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__('Insert into Post') . '" />
  1800. </td>
  1801. </tr>
  1802. <tr class="not-image">
  1803. <td></td>
  1804. <td>
  1805. ' . get_submit_button( __( 'Insert into Post' ), 'button', 'insertonlybutton', false ) . '
  1806. </td>
  1807. </tr>
  1808. </tbody></table>
  1809. ';
  1810. }
  1811. /**
  1812. * Displays the multi-file uploader message.
  1813. *
  1814. * @since 2.6.0
  1815. */
  1816. function media_upload_flash_bypass() {
  1817. ?>
  1818. <p class="upload-flash-bypass">
  1819. <?php printf( __( 'You are using the multi-file uploader. Problems? Try the <a href="%1$s" target="%2$s">browser uploader</a> instead.' ), admin_url( 'media-new.php?browser-uploader' ), '_blank' ); ?>
  1820. </p>
  1821. <?php
  1822. }
  1823. add_action('post-plupload-upload-ui', 'media_upload_flash_bypass');
  1824. /**
  1825. * Displays the browser's built-in uploader message.
  1826. *
  1827. * @since 2.6.0
  1828. */
  1829. function media_upload_html_bypass() {
  1830. ?>
  1831. <p class="upload-html-bypass hide-if-no-js">
  1832. <?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>.'); ?>
  1833. </p>
  1834. <?php
  1835. }
  1836. add_action('post-html-upload-ui', 'media_upload_html_bypass');
  1837. /**
  1838. * Used to display a "After a file has been uploaded..." help message.
  1839. *
  1840. * @since 3.3.0
  1841. */
  1842. function media_upload_text_after() {}
  1843. /**
  1844. * Displays the checkbox to scale images.
  1845. *
  1846. * @since 3.3.0
  1847. */
  1848. function media_upload_max_image_resize() {
  1849. $checked = get_user_setting('upload_resize') ? ' checked="true"' : '';
  1850. $a = $end = '';
  1851. if ( current_user_can( 'manage_options' ) ) {
  1852. $a = '<a href="' . esc_url( admin_url( 'options-media.php' ) ) . '" target="_blank">';
  1853. $end = '</a>';
  1854. }
  1855. ?>
  1856. <p class="hide-if-no-js"><label>
  1857. <input name="image_resize" type="checkbox" id="image_resize" value="true"<?php echo $checked; ?> />
  1858. <?php
  1859. /* translators: %1$s is link start tag, %2$s is link end tag, %3$d is width, %4$d is height*/
  1860. 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' ) );
  1861. ?>
  1862. </label></p>
  1863. <?php
  1864. }
  1865. /**
  1866. * Displays the out of storage quota message in Multisite.
  1867. *
  1868. * @since 3.5.0
  1869. */
  1870. function multisite_over_quota_message() {
  1871. echo '<p>' . sprintf( __( 'Sorry, you have used all of your storage quota of %s MB.' ), get_space_allowed() ) . '</p>';
  1872. }
  1873. /**
  1874. * Displays the image and editor in the post editor
  1875. *
  1876. * @since 3.5.0
  1877. */
  1878. function edit_form_image_editor() {
  1879. $post = get_post();
  1880. $thumb_url = false;
  1881. if ( $attachment_id = intval( $post->ID ) )
  1882. $thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 600 ), true );
  1883. $filename = esc_html( basename( $post->guid ) );
  1884. $title = esc_attr( $post->post_title );
  1885. $alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
  1886. $media_dims = '';
  1887. $meta = wp_get_attachment_metadata( $post->ID );
  1888. if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
  1889. $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
  1890. $media_dims = apply_filters( 'media_meta', $media_dims, $post );
  1891. $att_url = wp_get_attachment_url( $post->ID );
  1892. $image_edit_button = '';
  1893. if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) {
  1894. $nonce = wp_create_nonce( "image_editor-$post->ID" );
  1895. $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>";
  1896. }
  1897. ?>
  1898. <div class="wp_attachment_holder">
  1899. <div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div>
  1900. <div class="wp_attachment_image" id="media-head-<?php echo $attachment_id; ?>">
  1901. <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>
  1902. <p><?php echo $image_edit_button; ?></p>
  1903. </div>
  1904. <div style="display:none" class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"></div>
  1905. </div>
  1906. <div class="wp_attachment_details">
  1907. <p>
  1908. <label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br />
  1909. <textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea>
  1910. </p>
  1911. <?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?>
  1912. <p>
  1913. <label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br />
  1914. <input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" value="<?php echo esc_attr( $alt_text ); ?>" />
  1915. </p>
  1916. <?php endif; ?>
  1917. </div>
  1918. <?php
  1919. $extras = get_compat_media_markup( $post->ID );
  1920. echo $extras['item'];
  1921. foreach ( $extras['hidden'] as $hidden_field => $value ) {
  1922. echo '<input type="hidden" name="' . esc_attr( $hidden_field ) . '" value="' . esc_attr( $value ) . '" />' . "\n";
  1923. }
  1924. echo '<input type="hidden" id="image-edit-context" value="edit-attachment" />' . "\n";
  1925. }
  1926. /**
  1927. * Displays non-editable attachment metadata in the publish metabox
  1928. *
  1929. * @since 3.5.0
  1930. */
  1931. function attachment_submitbox_metadata() {
  1932. $post = get_post();
  1933. $filename = esc_html( basename( $post->guid ) );
  1934. $media_dims = '';
  1935. $meta = wp_get_attachment_metadata( $post->ID );
  1936. if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
  1937. $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
  1938. $media_dims = apply_filters( 'media_meta', $media_dims, $post );
  1939. $att_url = wp_get_attachment_url( $post->ID );
  1940. ?>
  1941. <div class="misc-pub-section">
  1942. <label for="attachment_url"><?php _e( 'File URL:' ); ?></label>
  1943. <input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" value="<?php echo esc_attr($att_url); ?>" />
  1944. </div>
  1945. <div class="misc-pub-section">
  1946. <?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong>
  1947. </div>
  1948. <div class="misc-pub-section">
  1949. <?php _e( 'File type:' ); ?> <strong><?php echo $post->post_mime_type; ?></strong>
  1950. </div>
  1951. <?php if ( $media_dims ) : ?>
  1952. <div class="misc-pub-section">
  1953. <?php _e( 'Dimensions:' ); ?> <strong><?php echo $media_dims; ?></strong>
  1954. </div>
  1955. <?php
  1956. endif;
  1957. }
  1958. add_filter( 'async_upload_image', 'get_media_item', 10, 2 );
  1959. add_filter( 'async_upload_audio', 'get_media_item', 10, 2 );
  1960. add_filter( 'async_upload_video', 'get_media_item', 10, 2 );
  1961. add_filter( 'async_upload_file', 'get_media_item', 10, 2 );
  1962. add_action( 'media_upload_image', 'wp_media_upload_handler' );
  1963. add_action( 'media_upload_audio', 'wp_media_upload_handler' );
  1964. add_action( 'media_upload_video', 'wp_media_upload_handler' );
  1965. add_action( 'media_upload_file', 'wp_media_upload_handler' );
  1966. add_filter( 'media_upload_gallery', 'media_upload_gallery' );
  1967. add_filter( 'media_upload_library', 'media_upload_library' );
  1968. add_action( 'attachment_submitbox_misc_actions', 'attachment_submitbox_metadata' );