- AA48E94B3B4B8EFC548628161409C2BB1ABDE5025797AD4645F5B43CBFE9F979BE3879427302F2F2593B050264413363AF383826B5D1CFE40D287205766FCE57+ 424AA85CB23D44ECE062ADD5C6F19AEB86FB59AA27B042DB49FDBBDEDDC366673B57EB3CF22800873B587D719BCADECA19634ED65BFF1D58B2809CF6F0F10FAEmp-wp/wp-admin/includes/media.php(9 . 169)(9 . 6)
22044 /**
22045 * {@internal Missing Short Description}}
22046 *
22047 * @since unknown
22048 *
22049 * @return unknown
22050 */
22051 function media_upload_tabs() {
22052 $_default_tabs = array(
22053 'type' => __('From Computer'), // handler action suffix => tab text
22054 'type_url' => __('From URL'),
22055 'gallery' => __('Gallery'),
22056 'library' => __('Media Library')
22057 );
22058
22059 return apply_filters('media_upload_tabs', $_default_tabs);
22060 }
22061
22062 /**
22063 * {@internal Missing Short Description}}
22064 *
22065 * @since unknown
22066 *
22067 * @param unknown_type $tabs
22068 * @return unknown
22069 */
22070 function update_gallery_tab($tabs) {
22071 global $wpdb;
22072
22073 if ( !isset($_REQUEST['post_id']) ) {
22074 unset($tabs['gallery']);
22075 return $tabs;
22076 }
22077
22078 if ( intval($_REQUEST['post_id']) )
22079 $attachments = intval($wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $_REQUEST['post_id'])));
22080
22081 if ( empty($attachments) ) {
22082 unset($tabs['gallery']);
22083 return $tabs;
22084 }
22085
22086 $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>");
22087
22088 return $tabs;
22089 }
22090 add_filter('media_upload_tabs', 'update_gallery_tab');
22091
22092 /**
22093 * {@internal Missing Short Description}}
22094 *
22095 * @since unknown
22096 */
22097 function the_media_upload_tabs() {
22098 global $redir_tab;
22099 $tabs = media_upload_tabs();
22100
22101 if ( !empty($tabs) ) {
22102 echo "<ul id='sidemenu'>\n";
22103 if ( isset($redir_tab) && array_key_exists($redir_tab, $tabs) )
22104 $current = $redir_tab;
22105 elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) )
22106 $current = $_GET['tab'];
22107 else {
22108 $keys = array_keys($tabs);
22109 $current = array_shift($keys);
22110 }
22111 foreach ( $tabs as $callback => $text ) {
22112 $class = '';
22113 if ( $current == $callback )
22114 $class = " class='current'";
22115 $href = add_query_arg(array('tab'=>$callback, 's'=>false, 'paged'=>false, 'post_mime_type'=>false, 'm'=>false));
22116 $link = "<a href='" . clean_url($href) . "'$class>$text</a>";
22117 echo "\t<li id='" . attribute_escape("tab-$callback") . "'>$link</li>\n";
22118 }
22119 echo "</ul>\n";
22120 }
22121 }
22122
22123 /**
22124 * {@internal Missing Short Description}}
22125 *
22126 * @since unknown
22127 *
22128 * @param unknown_type $id
22129 * @param unknown_type $alt
22130 * @param unknown_type $title
22131 * @param unknown_type $align
22132 * @param unknown_type $url
22133 * @param unknown_type $rel
22134 * @param unknown_type $size
22135 * @return unknown
22136 */
22137 function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') {
22138
22139 $htmlalt = ( empty($alt) ) ? $title : $alt;
22140
22141 $html = get_image_tag($id, $htmlalt, $title, $align, $size);
22142
22143 $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : '';
22144
22145 if ( $url )
22146 $html = '<a href="' . clean_url($url) . "\"$rel>$html</a>";
22147
22148 $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url, $size );
22149
22150 return $html;
22151 }
22152
22153 /**
22154 * {@internal Missing Short Description}}
22155 *
22156 * @since unknown
22157 *
22158 * @param unknown_type $html
22159 * @param unknown_type $id
22160 * @param unknown_type $alt
22161 * @param unknown_type $title
22162 * @param unknown_type $align
22163 * @param unknown_type $url
22164 * @param unknown_type $size
22165 * @return unknown
22166 */
22167 function image_add_caption( $html, $id, $alt, $title, $align, $url, $size ) {
22168
22169 if ( empty($alt) || apply_filters( 'disable_captions', '' ) ) return $html;
22170 $id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
22171
22172 preg_match( '/width="([0-9]+)/', $html, $matches );
22173 if ( ! isset($matches[1]) ) return $html;
22174 $width = $matches[1];
22175
22176 $html = preg_replace( '/align[^\s\'"]+\s?/', '', $html );
22177 if ( empty($align) ) $align = 'none';
22178
22179 $alt = ! empty($alt) ? addslashes($alt) : '';
22180
22181 $shcode = '[caption id="' . $id . '" align="align' . $align
22182 . '" width="' . $width . '" caption="' . $alt . '"]' . $html . '[/caption]';
22183
22184 return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
22185 }
22186 add_filter( 'image_send_to_editor', 'image_add_caption', 20, 7 );
22187
22188 /**
22189 * {@internal Missing Short Description}}
22190 *
22191 * @since unknown
22192 *
22193 * @param unknown_type $html
22194 */
22195 function media_send_to_editor($html) {
22196 ?>
22197 <script type="text/javascript">
22198 /* <![CDATA[ */
22199 var win = window.dialogArguments || opener || parent || top;
22200 win.send_to_editor('<?php echo addslashes($html); ?>');
22201 /* ]]> */
22202 </script>
22203 <?php
22204 exit;
22205 }
22206
22207 /**
22208 * {@internal Missing Short Description}}
22209 *
22210 * This handles the file upload POST itself, creating the attachment post.
22211 *
22212 * @since unknown
(233 . 137)(70 . 6)
22214 *
22215 * @since unknown
22216 *
22217 * @param unknown_type $file_array
22218 * @param unknown_type $post_id
22219 * @param unknown_type $desc
22220 * @param unknown_type $post_data
22221 * @return unknown
22222 */
22223 function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
22224 $overrides = array('test_form'=>false);
22225 $file = wp_handle_sideload($file_array, $overrides);
22226
22227 if ( isset($file['error']) )
22228 return new WP_Error( 'upload_error', $file['error'] );
22229
22230 $url = $file['url'];
22231 $type = $file['type'];
22232 $file = $file['file'];
22233 $title = preg_replace('/\.[^.]+$/', '', basename($file));
22234 $content = '';
22235
22236 // use image exif/iptc data for title and caption defaults if possible
22237 if ( $image_meta = @wp_read_image_metadata($file) ) {
22238 if ( trim($image_meta['title']) )
22239 $title = $image_meta['title'];
22240 if ( trim($image_meta['caption']) )
22241 $content = $image_meta['caption'];
22242 }
22243
22244 $title = @$desc;
22245
22246 // Construct the attachment array
22247 $attachment = array_merge( array(
22248 'post_mime_type' => $type,
22249 'guid' => $url,
22250 'post_parent' => $post_id,
22251 'post_title' => $title,
22252 'post_content' => $content,
22253 ), $post_data );
22254
22255 // Save the data
22256 $id = wp_insert_attachment($attachment, $file, $post_id);
22257 if ( !is_wp_error($id) ) {
22258 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
22259 return $url;
22260 }
22261 return $id;
22262 }
22263
22264 /**
22265 * {@internal Missing Short Description}}
22266 *
22267 * Wrap iframe content (produced by $content_func) in a doctype, html head/body
22268 * etc any additional function args will be passed to content_func.
22269 *
22270 * @since unknown
22271 *
22272 * @param unknown_type $content_func
22273 */
22274 function wp_iframe($content_func /* ... */) {
22275 ?>
22276 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
22277 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
22278 <head>
22279 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
22280 <title><?php bloginfo('name') ?> › <?php _e('Uploads'); ?> — <?php _e('WordPress'); ?></title>
22281 <?php
22282 wp_enqueue_style( 'global' );
22283 wp_enqueue_style( 'wp-admin' );
22284 wp_enqueue_style( 'colors' );
22285 if ( 0 === strpos( $content_func, 'media' ) )
22286 wp_enqueue_style( 'media' );
22287
22288 ?>
22289 <script type="text/javascript">
22290 //<![CDATA[
22291 function addLoadEvent(func) {if ( typeof wpOnload!='function'){wpOnload=func;}else{ var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}
22292 //]]>
22293 </script>
22294 <?php
22295 do_action('admin_print_styles');
22296 do_action('admin_print_scripts');
22297 do_action('admin_head');
22298 if ( is_string($content_func) )
22299 do_action( "admin_head_{$content_func}" );
22300 ?>
22301 </head>
22302 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?>>
22303 <?php
22304 $args = func_get_args();
22305 $args = array_slice($args, 1);
22306 call_user_func_array($content_func, $args);
22307 ?>
22308 </body>
22309 </html>
22310 <?php
22311 }
22312
22313 /**
22314 * {@internal Missing Short Description}}
22315 *
22316 * @since unknown
22317 */
22318 function media_buttons() {
22319 global $post_ID, $temp_ID;
22320 $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
22321 $context = apply_filters('media_buttons_context', __('Upload/Insert %s'));
22322 $media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
22323 $media_title = __('Add Media');
22324 $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&type=image");
22325 $image_title = __('Add an Image');
22326 $video_upload_iframe_src = apply_filters('video_upload_iframe_src', "$media_upload_iframe_src&type=video");
22327 $video_title = __('Add Video');
22328 $audio_upload_iframe_src = apply_filters('audio_upload_iframe_src', "$media_upload_iframe_src&type=audio");
22329 $audio_title = __('Add Audio');
22330 $out = <<<EOF
22331
22332 <a href="{$image_upload_iframe_src}&TB_iframe=true" id="add_image" class="thickbox" title='$image_title'><img src='images/media-button-image.svg' alt='$image_title' /></a>
22333 <a href="{$video_upload_iframe_src}&TB_iframe=true" id="add_video" class="thickbox" title='$video_title'><img src='images/media-button-video.svg' alt='$video_title' /></a>
22334 <a href="{$audio_upload_iframe_src}&TB_iframe=true" id="add_audio" class="thickbox" title='$audio_title'><img src='images/media-button-music.svg' alt='$audio_title' /></a>
22335 <a href="{$media_upload_iframe_src}&TB_iframe=true" id="add_media" class="thickbox" title='$media_title'><img src='images/media-button-other.svg' alt='$media_title' /></a>
22336
22337 EOF;
22338 printf($context, $out);
22339 }
22340 add_action( 'media_buttons', 'media_buttons' );
22341 add_action('media_upload_media', 'media_upload_handler');
22342
22343 /**
22344 * {@internal Missing Short Description}}
22345 *
22346 * @since unknown
22347 *
22348 * @return unknown
22349 */
22350 function media_upload_form_handler() {
(397 . 31)(103 . 6)
22352 wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false);
22353 }
22354
22355 if ( isset($_POST['insert-gallery']) || isset($_POST['update-gallery']) ) { ?>
22356 <script type="text/javascript">
22357 /* <![CDATA[ */
22358 var win = window.dialogArguments || opener || parent || top;
22359 win.tb_remove();
22360 /* ]]> */
22361 </script>
22362 <?php
22363 exit;
22364 }
22365
22366 if ( isset($_POST['send']) ) {
22367 $keys = array_keys($_POST['send']);
22368 $send_id = (int) array_shift($keys);
22369 $attachment = stripslashes_deep( $_POST['attachments'][$send_id] );
22370 $html = $attachment['post_title'];
22371 if ( !empty($attachment['url']) ) {
22372 if ( strpos($attachment['url'], 'attachment_id') || false !== strpos($attachment['url'], get_permalink($_POST['post_id'])) )
22373 $rel = " rel='attachment wp-att-".attribute_escape($send_id)."'";
22374 $html = "<a href='{$attachment['url']}'$rel>$html</a>";
22375 }
22376 $html = apply_filters('media_send_to_editor', $html, $send_id, $attachment);
22377 return media_send_to_editor($html);
22378 }
22379
22380 return $errors;
22381 }
22382
(430 . 431)(111 . 6)
22384 *
22385 * @since unknown
22386 *
22387 * @return unknown
22388 */
22389 function media_upload_image() {
22390 $errors = array();
22391 $id = 0;
22392
22393 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
22394 // Upload File button was clicked
22395 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
22396 unset($_FILES);
22397 if ( is_wp_error($id) ) {
22398 $errors['upload_error'] = $id;
22399 $id = false;
22400 }
22401 }
22402
22403 if ( !empty($_POST['insertonlybutton']) ) {
22404 $src = $_POST['insertonly']['src'];
22405 if ( !empty($src) && !strpos($src, '://') )
22406 $src = "http://$src";
22407 $alt = attribute_escape($_POST['insertonly']['alt']);
22408 if ( isset($_POST['insertonly']['align']) ) {
22409 $align = attribute_escape($_POST['insertonly']['align']);
22410 $class = " class='align$align'";
22411 }
22412 if ( !empty($src) )
22413 $html = "<img src='$src' alt='$alt'$class />";
22414 return media_send_to_editor($html);
22415 }
22416
22417 if ( !empty($_POST) ) {
22418 $return = media_upload_form_handler();
22419
22420 if ( is_string($return) )
22421 return $return;
22422 if ( is_array($return) )
22423 $errors = $return;
22424 }
22425
22426 if ( isset($_POST['save']) ) {
22427 $errors['upload_notice'] = __('Saved.');
22428 return media_upload_gallery();
22429 }
22430
22431 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
22432 return wp_iframe( 'media_upload_type_url_form', 'image', $errors, $id );
22433
22434 return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
22435 }
22436
22437 /**
22438 * {@internal Missing Short Description}}
22439 *
22440 * @since unknown
22441 *
22442 * @param unknown_type $file
22443 * @param unknown_type $post_id
22444 * @param unknown_type $desc
22445 * @return unknown
22446 */
22447 function media_sideload_image($file, $post_id, $desc = null) {
22448 if (!empty($file) ) {
22449 $file_array['name'] = basename($file);
22450 $tmp = download_url($file);
22451 $file_array['tmp_name'] = $tmp;
22452 $desc = @$desc;
22453
22454 if ( is_wp_error($tmp) ) {
22455 @unlink($file_array['tmp_name']);
22456 $file_array['tmp_name'] = '';
22457 }
22458
22459 $id = media_handle_sideload($file_array, $post_id, $desc);
22460 $src = $id;
22461
22462 if ( is_wp_error($id) ) {
22463 @unlink($file_array['tmp_name']);
22464 return $id;
22465 }
22466 }
22467
22468 if ( !empty($src) ) {
22469 $alt = @$desc;
22470 $html = "<img src='$src' alt='$alt' />";
22471 return $html;
22472 }
22473 }
22474
22475 /**
22476 * {@internal Missing Short Description}}
22477 *
22478 * @since unknown
22479 *
22480 * @return unknown
22481 */
22482 function media_upload_audio() {
22483 $errors = array();
22484 $id = 0;
22485
22486 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
22487 // Upload File button was clicked
22488 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
22489 unset($_FILES);
22490 if ( is_wp_error($id) ) {
22491 $errors['upload_error'] = $id;
22492 $id = false;
22493 }
22494 }
22495
22496 if ( !empty($_POST['insertonlybutton']) ) {
22497 $href = $_POST['insertonly']['href'];
22498 if ( !empty($href) && !strpos($href, '://') )
22499 $href = "http://$href";
22500 $title = attribute_escape($_POST['insertonly']['title']);
22501 if ( empty($title) )
22502 $title = basename($href);
22503 if ( !empty($title) && !empty($href) )
22504 $html = "<a href='$href' >$title</a>";
22505 return media_send_to_editor($html);
22506 }
22507
22508 if ( !empty($_POST) ) {
22509 $return = media_upload_form_handler();
22510
22511 if ( is_string($return) )
22512 return $return;
22513 if ( is_array($return) )
22514 $errors = $return;
22515 }
22516
22517 if ( isset($_POST['save']) ) {
22518 $errors['upload_notice'] = __('Saved.');
22519 return media_upload_gallery();
22520 }
22521
22522 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
22523 return wp_iframe( 'media_upload_type_url_form', 'audio', $errors, $id );
22524
22525 return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id );
22526 }
22527
22528 /**
22529 * {@internal Missing Short Description}}
22530 *
22531 * @since unknown
22532 *
22533 * @return unknown
22534 */
22535 function media_upload_video() {
22536 $errors = array();
22537 $id = 0;
22538
22539 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
22540 // Upload File button was clicked
22541 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
22542 unset($_FILES);
22543 if ( is_wp_error($id) ) {
22544 $errors['upload_error'] = $id;
22545 $id = false;
22546 }
22547 }
22548
22549 if ( !empty($_POST['insertonlybutton']) ) {
22550 $href = $_POST['insertonly']['href'];
22551 if ( !empty($href) && !strpos($href, '://') )
22552 $href = "http://$href";
22553 $title = attribute_escape($_POST['insertonly']['title']);
22554 if ( empty($title) )
22555 $title = basename($href);
22556 if ( !empty($title) && !empty($href) )
22557 $html = "<a href='$href' >$title</a>";
22558 return media_send_to_editor($html);
22559 }
22560
22561 if ( !empty($_POST) ) {
22562 $return = media_upload_form_handler();
22563
22564 if ( is_string($return) )
22565 return $return;
22566 if ( is_array($return) )
22567 $errors = $return;
22568 }
22569
22570 if ( isset($_POST['save']) ) {
22571 $errors['upload_notice'] = __('Saved.');
22572 return media_upload_gallery();
22573 }
22574
22575 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
22576 return wp_iframe( 'media_upload_type_url_form', 'video', $errors, $id );
22577
22578 return wp_iframe( 'media_upload_type_form', 'video', $errors, $id );
22579 }
22580
22581 /**
22582 * {@internal Missing Short Description}}
22583 *
22584 * @since unknown
22585 *
22586 * @return unknown
22587 */
22588 function media_upload_file() {
22589 $errors = array();
22590 $id = 0;
22591
22592 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
22593 // Upload File button was clicked
22594 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
22595 unset($_FILES);
22596 if ( is_wp_error($id) ) {
22597 $errors['upload_error'] = $id;
22598 $id = false;
22599 }
22600 }
22601
22602 if ( !empty($_POST['insertonlybutton']) ) {
22603 $href = $_POST['insertonly']['href'];
22604 if ( !empty($href) && !strpos($href, '://') )
22605 $href = "http://$href";
22606 $title = attribute_escape($_POST['insertonly']['title']);
22607 if ( empty($title) )
22608 $title = basename($href);
22609 if ( !empty($title) && !empty($href) )
22610 $html = "<a href='$href' >$title</a>";
22611 return media_send_to_editor($html);
22612 }
22613
22614 if ( !empty($_POST) ) {
22615 $return = media_upload_form_handler();
22616
22617 if ( is_string($return) )
22618 return $return;
22619 if ( is_array($return) )
22620 $errors = $return;
22621 }
22622
22623 if ( isset($_POST['save']) ) {
22624 $errors['upload_notice'] = __('Saved.');
22625 return media_upload_gallery();
22626 }
22627
22628 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
22629 return wp_iframe( 'media_upload_type_url_form', 'file', $errors, $id );
22630
22631 return wp_iframe( 'media_upload_type_form', 'file', $errors, $id );
22632 }
22633
22634 /**
22635 * {@internal Missing Short Description}}
22636 *
22637 * @since unknown
22638 *
22639 * @return unknown
22640 */
22641 function media_upload_gallery() {
22642 $errors = array();
22643
22644 if ( !empty($_POST) ) {
22645 $return = media_upload_form_handler();
22646
22647 if ( is_string($return) )
22648 return $return;
22649 if ( is_array($return) )
22650 $errors = $return;
22651 }
22652
22653 wp_enqueue_script('admin-gallery');
22654 return wp_iframe( 'media_upload_gallery_form', $errors );
22655 }
22656
22657 /**
22658 * {@internal Missing Short Description}}
22659 *
22660 * @since unknown
22661 *
22662 * @return unknown
22663 */
22664 function media_upload_library() {
22665 $errors = array();
22666 if ( !empty($_POST) ) {
22667 $return = media_upload_form_handler();
22668
22669 if ( is_string($return) )
22670 return $return;
22671 if ( is_array($return) )
22672 $errors = $return;
22673 }
22674
22675 return wp_iframe( 'media_upload_library_form', $errors );
22676 }
22677
22678 /**
22679 * Retrieve HTML for the image alignment radio buttons with the specified one checked.
22680 *
22681 * @since unknown
22682 *
22683 * @param unknown_type $post
22684 * @param unknown_type $checked
22685 * @return unknown
22686 */
22687 function image_align_input_fields($post, $checked='') {
22688
22689 $alignments = array('none' => 'None', 'left' => 'Left', 'center' => 'Center', 'right' => 'Right');
22690 if ( !array_key_exists($checked, $alignments) )
22691 $checked = 'none';
22692
22693 $out = array();
22694 foreach ($alignments as $name => $label) {
22695
22696 $out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'".
22697 ( $checked == $name ? " checked='checked'" : "" ) .
22698 " /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>" . __($label) . "</label>";
22699 }
22700 return join("\n", $out);
22701 }
22702
22703 /**
22704 * Retrieve HTML for the size radio buttons with the specified one checked.
22705 *
22706 * @since unknown
22707 *
22708 * @param unknown_type $post
22709 * @param unknown_type $checked
22710 * @return unknown
22711 */
22712 function image_size_input_fields($post, $checked='') {
22713
22714 // get a list of the actual pixel dimensions of each possible intermediate version of this image
22715 $size_names = array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full size'));
22716
22717 foreach ( $size_names as $size => $name) {
22718 $downsize = image_downsize($post->ID, $size);
22719
22720 // is this size selectable?
22721 $enabled = ( $downsize[3] || 'full' == $size );
22722 $css_id = "image-size-{$size}-{$post->ID}";
22723 // if this size is the default but that's not available, don't select it
22724 if ( $checked && !$enabled )
22725 $checked = '';
22726 // if $checked was not specified, default to the first available size that's bigger than a thumbnail
22727 if ( !$checked && $enabled && 'thumbnail' != $size )
22728 $checked = $size;
22729
22730 $html = "<div class='image-size-item'><input type='radio' ".( $enabled ? '' : "disabled='disabled'")."name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'".( $checked == $size ? " checked='checked'" : '') ." />";
22731
22732 $html .= "<label for='{$css_id}'>" . __($name). "</label>";
22733 // only show the dimensions if that choice is available
22734 if ( $enabled )
22735 $html .= " <label for='{$css_id}' class='help'>" . sprintf( __("(%d × %d)"), $downsize[1], $downsize[2] ). "</label>";
22736
22737 $html .= '</div>';
22738
22739 $out[] = $html;
22740 }
22741
22742 return array(
22743 'label' => __('Size'),
22744 'input' => 'html',
22745 'html' => join("\n", $out),
22746 );
22747 }
22748
22749 /**
22750 * Retrieve HTML for the Link URL buttons with the default link type as specified.
22751 *
22752 * @since unknown
22753 *
22754 * @param unknown_type $post
22755 * @param unknown_type $url_type
22756 * @return unknown
22757 */
22758 function image_link_input_fields($post, $url_type='') {
22759
22760 $file = wp_get_attachment_url($post->ID);
22761 $link = get_attachment_link($post->ID);
22762
22763 $url = '';
22764 if ( $url_type == 'file' )
22765 $url = $file;
22766 elseif ( $url_type == 'post' )
22767 $url = $link;
22768
22769 return "<input type='text' class='urlfield' name='attachments[$post->ID][url]' value='" . attribute_escape($url) . "' /><br />
22770 <button type='button' class='button urlnone' title=''>" . __('None') . "</button>
22771 <button type='button' class='button urlfile' title='" . attribute_escape($file) . "'>" . __('File URL') . "</button>
22772 <button type='button' class='button urlpost' title='" . attribute_escape($link) . "'>" . __('Post URL') . "</button>
22773 ";
22774 }
22775
22776 /**
22777 * {@internal Missing Short Description}}
22778 *
22779 * @since unknown
22780 *
22781 * @param unknown_type $form_fields
22782 * @param unknown_type $post
22783 * @return unknown
22784 */
22785 function image_attachment_fields_to_edit($form_fields, $post) {
22786 if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
22787 $form_fields['post_title']['required'] = true;
22788
22789 $form_fields['post_excerpt']['label'] = __('Caption');
22790 $form_fields['post_excerpt']['helps'][] = __('Also used as alternate text for the image');
22791
22792 $form_fields['post_content']['label'] = __('Description');
22793
22794 $form_fields['align'] = array(
22795 'label' => __('Alignment'),
22796 'input' => 'html',
22797 'html' => image_align_input_fields($post, get_option('image_default_align')),
22798 );
22799
22800 $form_fields['image-size'] = image_size_input_fields($post, get_option('image_default_size'));
22801 }
22802 return $form_fields;
22803 }
22804
22805 add_filter('attachment_fields_to_edit', 'image_attachment_fields_to_edit', 10, 2);
22806
22807 /**
22808 * {@internal Missing Short Description}}
22809 *
22810 * @since unknown
22811 *
22812 * @param unknown_type $form_fields
22813 * @param unknown_type $post
22814 * @return unknown
(891 . 41)(147 . 6)
22816 *
22817 * @since unknown
22818 *
22819 * @param unknown_type $html
22820 * @param unknown_type $attachment_id
22821 * @param unknown_type $attachment
22822 * @return unknown
22823 */
22824 function image_media_send_to_editor($html, $attachment_id, $attachment) {
22825 $post =& get_post($attachment_id);
22826 if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
22827 $url = $attachment['url'];
22828
22829 if ( isset($attachment['align']) )
22830 $align = $attachment['align'];
22831 else
22832 $align = 'none';
22833
22834 if ( !empty($attachment['image-size']) )
22835 $size = $attachment['image-size'];
22836 else
22837 $size = 'medium';
22838
22839 $rel = ( $url == get_attachment_link($attachment_id) );
22840
22841 return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size);
22842 }
22843
22844 return $html;
22845 }
22846
22847 add_filter('media_send_to_editor', 'image_media_send_to_editor', 10, 3);
22848
22849 /**
22850 * {@internal Missing Short Description}}
22851 *
22852 * @since unknown
22853 *
22854 * @param unknown_type $post
22855 * @param unknown_type $errors
22856 * @return unknown
(952 . 12)(173 . 6)
22858 'value' => $edit_post->post_content,
22859 'input' => 'textarea',
22860 ),
22861 'url' => array(
22862 'label' => __('Link URL'),
22863 'input' => 'html',
22864 'html' => image_link_input_fields($post, get_option('image_default_link_type')),
22865 'helps' => __('Enter a link URL or click above for presets.'),
22866 ),
22867 'menu_order' => array(
22868 'label' => __('Order'),
22869 'value' => $edit_post->menu_order
(993 . 39)(208 . 6)
22871 return $form_fields;
22872 }
22873
22874 /**
22875 * Retrieve HTML for media items of post gallery.
22876 *
22877 * The HTML markup retrieved will be created for the progress of SWF Upload
22878 * component. Will also create link for showing and hiding the form to modify
22879 * the image attachment.
22880 *
22881 * @since unknown
22882 *
22883 * @param int $post_id Optional. Post ID.
22884 * @param array $errors Errors for attachment, if any.
22885 * @return string
22886 */
22887 function get_media_items( $post_id, $errors ) {
22888 if ( $post_id ) {
22889 $post = get_post($post_id);
22890 if ( $post && $post->post_type == 'attachment' )
22891 $attachments = array($post->ID => $post);
22892 else
22893 $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') );
22894 } else {
22895 if ( is_array($GLOBALS['wp_the_query']->posts) )
22896 foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
22897 $attachments[$attachment->ID] = $attachment;
22898 }
22899
22900 $output = '';
22901 foreach ( (array) $attachments as $id => $attachment )
22902 if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )
22903 $output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div class='progress'><div class='bar'></div></div><div id='media-upload-error-$id'></div><div class='filename'></div>$item\n</div>";
22904
22905 return $output;
22906 }
22907
22908 /**
22909 * Retrieve HTML form for modifying the image attachment.
(1039 . 7)(221 . 7)
22911 function get_media_item( $attachment_id, $args = null ) {
22912 global $redir_tab;
22913
22914 $default_args = array( 'errors' => null, 'send' => true, 'delete' => true, 'toggle' => true, 'show_title' => true );
22915 $default_args = array( 'errors' => null, 'delete' => true, 'toggle' => true, 'show_title' => true );
22916 $args = wp_parse_args( $args, $default_args );
22917 extract( $args, EXTR_SKIP );
22918
(1124 . 16)(306 . 6)
22920 'extra_rows' => array(),
22921 );
22922
22923 $delete_href = wp_nonce_url("post.php?action=delete-post&post=$attachment_id", 'delete-post_' . $attachment_id);
22924 if ( $send )
22925 $send = "<input type='submit' class='button' name='send[$attachment_id]' value='" . attribute_escape( __( 'Insert into Post' ) ) . "' />";
22926 if ( $delete )
22927 $delete = "<a href=\"#\" class=\"del-link\" onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __('Delete') . "</a>";
22928 if ( ( $send || $delete ) && !isset($form_fields['buttons']) )
22929 $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $delete
22930 <div id=\"del_attachment_$attachment_id\" class=\"del-attachment\" style=\"display:none;\">" . sprintf(__("You are about to delete <strong>%s</strong>."), $filename) . " <a href=\"$delete_href\" id=\"del[$attachment_id]\" class=\"delete\">" . __('Continue') . "</a>
22931 <a href=\"#\" class=\"del-link\" onclick=\"this.parentNode.style.display='none';return false;\">" . __('Cancel') . "</a></div></td></tr>\n");
22932
22933 $hidden_fields = array();
22934
22935 foreach ( $form_fields as $id => $field ) {
(1211 . 7)(383 . 6)
22937 */
22938 function media_upload_header() {
22939 ?>
22940 <script type="text/javascript">post_id = <?php echo intval($_REQUEST['post_id']); ?>;</script>
22941 <div id="media-upload-header">
22942 <?php the_media_upload_tabs(); ?>
22943 </div>
(1252 . 65)(423 . 10)
22945
22946 <?php do_action('pre-upload-ui'); ?>
22947
22948 <?php if ( $flash ) : ?>
22949 <script type="text/javascript">
22950 <!--
22951 SWFUpload.onload = function() {
22952 swfu = new SWFUpload({
22953 button_text: '<span class="button"><?php _e('Select Files'); ?></span>',
22954 button_text_style: '.button { text-align: center; font-weight: bold; font-family:"Lucida Grande","Lucida Sans Unicode",Tahoma,Verdana,sans-serif; }',
22955 button_height: "24",
22956 button_width: "132",
22957 button_image_url: '<?php echo includes_url('images/upload.svg'); ?>',
22958 button_placeholder_id: "flash-browse-button",
22959 upload_url : "<?php echo attribute_escape( $flash_action_url ); ?>",
22960 flash_url : "<?php echo includes_url('js/swfupload/swfupload.swf'); ?>",
22961 file_post_name: "async-upload",
22962 file_types: "<?php echo apply_filters('upload_file_glob', '*.*'); ?>",
22963 post_params : {
22964 "post_id" : "<?php echo $post_id; ?>",
22965 "auth_cookie" : "<?php if ( is_ssl() ) echo $_COOKIE[SECURE_AUTH_COOKIE]; else echo $_COOKIE[AUTH_COOKIE]; ?>",
22966 "_wpnonce" : "<?php echo wp_create_nonce('media-form'); ?>",
22967 "type" : "<?php echo $type; ?>",
22968 "tab" : "<?php echo $tab; ?>",
22969 "short" : "1"
22970 },
22971 file_size_limit : "<?php echo wp_max_upload_size(); ?>b",
22972 file_dialog_start_handler : fileDialogStart,
22973 file_queued_handler : fileQueued,
22974 upload_start_handler : uploadStart,
22975 upload_progress_handler : uploadProgress,
22976 upload_error_handler : uploadError,
22977 upload_success_handler : uploadSuccess,
22978 upload_complete_handler : uploadComplete,
22979 file_queue_error_handler : fileQueueError,
22980 file_dialog_complete_handler : fileDialogComplete,
22981 swfupload_pre_load_handler: swfuploadPreLoad,
22982 swfupload_load_failed_handler: swfuploadLoadFailed,
22983 custom_settings : {
22984 degraded_element_id : "html-upload-ui", // id of the element displayed when swfupload is unavailable
22985 swfupload_element_id : "flash-upload-ui" // id of the element displayed when swfupload is available
22986 },
22987 debug: false
22988 });
22989 };
22990 //-->
22991 </script>
22992
22993 <div id="flash-upload-ui">
22994 <?php do_action('pre-flash-upload-ui'); ?>
22995
22996 <div><?php _e( 'Choose files to upload' ); ?> <div id="flash-browse-button"></div></div>
22997 <?php do_action('post-flash-upload-ui'); ?>
22998 <p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>
22999 </div>
23000
23001 <?php endif; // $flash ?>
23002
23003 <div id="html-upload-ui">
23004 <?php do_action('pre-html-upload-ui'); ?>
23005 <p id="async-upload-wrap">
23006 <input type="file" name="async-upload" id="async-upload" /> <input type="submit" class="button" name="html-upload" value="<?php echo attribute_escape(__('Upload')); ?>" /> <a href="#" onclick="return top.tb_remove();"><?php _e('Cancel'); ?></a>
23007 <input type="file" name="async-upload" id="async-upload" /> <input type="submit" class="button" name="html-upload" value="<?php echo attribute_escape(__('Upload')); ?>" /> <a href="upload.php"><?php _e('Cancel'); ?></a>
23008 </p>
23009
23010 <br class="clear" />
(1323 . 725)(439 . 4)
23012 <?php
23013 }
23014
23015 /**
23016 * {@internal Missing Short Description}}
23017 *
23018 * @since unknown
23019 *
23020 * @param unknown_type $type
23021 * @param unknown_type $errors
23022 * @param unknown_type $id
23023 */
23024 function media_upload_type_form($type = 'file', $errors = null, $id = null) {
23025 media_upload_header();
23026
23027 $post_id = intval($_REQUEST['post_id']);
23028
23029 $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
23030 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
23031 ?>
23032
23033 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form type-form validate" id="<?php echo $type; ?>-form">
23034 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
23035 <?php wp_nonce_field('media-form'); ?>
23036
23037 <h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3>
23038
23039 <?php media_upload_form( $errors ); ?>
23040
23041 <script type="text/javascript">
23042 <!--
23043 jQuery(function($){
23044 var preloaded = $(".media-item.preloaded");
23045 if ( preloaded.length > 0 ) {
23046 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
23047 }
23048 updateMediaForm();
23049 });
23050 -->
23051 </script>
23052 <div id="media-items">
23053 <?php
23054 if ( $id ) {
23055 if ( !is_wp_error($id) ) {
23056 echo get_media_items( $id, $errors );
23057 } else {
23058 echo '<div id="media-upload-error">'.wp_specialchars($id->get_error_message()).'</div>';
23059 exit;
23060 }
23061 }
23062 ?>
23063 </div>
23064 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
23065 <?php
23066 }
23067
23068 /**
23069 * {@internal Missing Short Description}}
23070 *
23071 * @since unknown
23072 *
23073 * @param unknown_type $type
23074 * @param unknown_type $errors
23075 * @param unknown_type $id
23076 */
23077 function media_upload_type_url_form($type = 'file', $errors = null, $id = null) {
23078 media_upload_header();
23079
23080 $post_id = intval($_REQUEST['post_id']);
23081
23082 $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
23083 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
23084
23085 $callback = "type_url_form_$type";
23086 ?>
23087
23088 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form type-form validate" id="<?php echo $type; ?>-form">
23089 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
23090 <?php wp_nonce_field('media-form'); ?>
23091
23092 <?php if ( is_callable($callback) ) { ?>
23093
23094 <h3 class="media-title"><?php _e('Add media file from URL'); ?></h3>
23095
23096 <script type="text/javascript">
23097 //<![CDATA[
23098 var addExtImage = {
23099
23100 width : '',
23101 height : '',
23102 align : 'alignnone',
23103
23104 insert : function() {
23105 var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = null;
23106
23107 if ( '' == f.src.value || '' == t.width ) return false;
23108
23109 if ( f.title.value ) {
23110 title = f.title.value.replace(/['"<>]+/g, '');
23111 title = ' title="'+title+'"';
23112 }
23113
23114 if ( f.alt.value ) {
23115 alt = f.alt.value.replace(/['"<>]+/g, '');
23116 <?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?>
23117 caption = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
23118 <?php } ?>
23119 }
23120
23121 cls = caption ? '' : ' class="'+t.align+'"';
23122
23123 html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />';
23124
23125 if ( f.url.value )
23126 html = '<a href="'+f.url.value+'">'+html+'</a>';
23127
23128 if ( caption )
23129 html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]';
23130
23131 var win = window.dialogArguments || opener || parent || top;
23132 win.send_to_editor(html);
23133 },
23134
23135 resetImageData : function() {
23136 var t = addExtImage;
23137
23138 t.width = t.height = '';
23139 document.getElementById('go_button').style.color = '#bbb';
23140 if ( ! document.forms[0].src.value )
23141 document.getElementById('status_img').src = 'images/required.svg';
23142 else document.getElementById('status_img').src = 'images/no.svg';
23143 },
23144
23145 updateImageData : function() {
23146 var t = addExtImage;
23147
23148 t.width = t.preloadImg.width;
23149 t.height = t.preloadImg.height;
23150 document.getElementById('go_button').style.color = '#333';
23151 document.getElementById('status_img').src = 'images/yes.svg';
23152 },
23153
23154 getImageData : function() {
23155 var t = addExtImage, src = document.forms[0].src.value;
23156
23157 if ( ! src ) {
23158 t.resetImageData();
23159 return false;
23160 }
23161 document.getElementById('status_img').src = 'images/loading.svg';
23162 t.preloadImg = new Image();
23163 t.preloadImg.onload = t.updateImageData;
23164 t.preloadImg.onerror = t.resetImageData;
23165 t.preloadImg.src = src;
23166 }
23167 }
23168 //]]>
23169 </script>
23170
23171 <div id="media-items">
23172 <div class="media-item media-blank">
23173 <?php echo call_user_func($callback); ?>
23174 </div>
23175 </div>
23176 </form>
23177 <?php
23178 } else {
23179 wp_die( __('Unknown action.') );
23180 }
23181 }
23182
23183 /**
23184 * {@internal Missing Short Description}}
23185 *
23186 * @since unknown
23187 *
23188 * @param unknown_type $errors
23189 */
23190 function media_upload_gallery_form($errors) {
23191 global $redir_tab;
23192
23193 $redir_tab = 'gallery';
23194 media_upload_header();
23195
23196 $post_id = intval($_REQUEST['post_id']);
23197 $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=gallery&post_id=$post_id");
23198 ?>
23199
23200 <script type="text/javascript">
23201 <!--
23202 jQuery(function($){
23203 var preloaded = $(".media-item.preloaded");
23204 if ( preloaded.length > 0 ) {
23205 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
23206 updateMediaForm();
23207 }
23208 });
23209 -->
23210 </script>
23211
23212 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form validate" id="gallery-form">
23213 <?php wp_nonce_field('media-form'); ?>
23214 <?php //media_upload_form( $errors ); ?>
23215 <table class="widefat" cellspacing="0">
23216 <thead><tr>
23217 <th><?php _e('Media'); ?></th>
23218 <th class="order-head"><?php _e('Order'); ?></th>
23219 </tr></thead>
23220 </table>
23221 <div id="media-items">
23222 <?php echo get_media_items($post_id, $errors); ?>
23223 </div>
23224
23225 <p class="ml-submit">
23226 <input type="submit" class="button savebutton" style="display:none;" name="save" id="save-all" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
23227 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
23228 <input type="hidden" name="type" value="<?php echo attribute_escape( $GLOBALS['type'] ); ?>" />
23229 <input type="hidden" name="tab" value="<?php echo attribute_escape( $GLOBALS['tab'] ); ?>" />
23230 </p>
23231
23232 <div id="gallery-settings" style="display:none;">
23233 <div class="title"><?php _e('Gallery Settings'); ?></div>
23234 <table id="basic" class="describe"><tbody>
23235 <tr>
23236 <th scope="row" class="label">
23237 <label>
23238 <span class="alignleft"><?php _e('Link thumbnails to:'); ?></span>
23239 </label>
23240 </th>
23241 <td class="field">
23242 <input type="radio" name="linkto" id="linkto-file" value="file" />
23243 <label for="linkto-file" class="radio"><?php _e('Image File'); ?></label>
23244
23245 <input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" />
23246 <label for="linkto-post" class="radio"><?php _e('Attachment Page'); ?></label>
23247 </td>
23248 </tr>
23249
23250 <tr>
23251 <th scope="row" class="label">
23252 <label>
23253 <span class="alignleft"><?php _e('Order images by:'); ?></span>
23254 </label>
23255 </th>
23256 <td class="field">
23257 <select id="orderby" name="orderby">
23258 <option value="menu_order" selected="selected"><?php _e('Menu order'); ?></option>
23259 <option value="post_name"><?php _e('Name'); ?></option>
23260 <option value="ID"><?php _e('Date/Time'); ?></option>
23261 </select>
23262 </td>
23263 </tr>
23264
23265 <tr>
23266 <th scope="row" class="label">
23267 <label>
23268 <span class="alignleft"><?php _e('Order:'); ?></span>
23269 </label>
23270 </th>
23271 <td class="field">
23272 <input type="radio" checked="checked" name="order" id="order-asc" value="asc" />
23273 <label for="order-asc" class="radio"><?php _e('Ascending'); ?></label>
23274
23275 <input type="radio" name="order" id="order-desc" value="desc" />
23276 <label for="order-desc" class="radio"><?php _e('Descending'); ?></label>
23277 </td>
23278 </tr>
23279
23280 <tr>
23281 <th scope="row" class="label">
23282 <label>
23283 <span class="alignleft"><?php _e('Gallery columns:'); ?></span>
23284 </label>
23285 </th>
23286 <td class="field">
23287 <select id="columns" name="columns">
23288 <option value="2"><?php _e('2'); ?></option>
23289 <option value="3" selected="selected"><?php _e('3'); ?></option>
23290 <option value="4"><?php _e('4'); ?></option>
23291 <option value="5"><?php _e('5'); ?></option>
23292 <option value="6"><?php _e('6'); ?></option>
23293 <option value="7"><?php _e('7'); ?></option>
23294 <option value="8"><?php _e('8'); ?></option>
23295 <option value="9"><?php _e('9'); ?></option>
23296 </select>
23297 </td>
23298 </tr>
23299 </tbody></table>
23300
23301 <p class="ml-submit">
23302 <input type="button" class="button" style="display:none;" onmousedown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php echo attribute_escape( __( 'Insert gallery' ) ); ?>" />
23303 <input type="button" class="button" style="display:none;" onmousedown="wpgallery.update();" name="update-gallery" id="update-gallery" value="<?php echo attribute_escape( __( 'Update gallery settings' ) ); ?>" />
23304 </p>
23305 </div>
23306 </form>
23307 <?php
23308 }
23309
23310 /**
23311 * {@internal Missing Short Description}}
23312 *
23313 * @since unknown
23314 *
23315 * @param unknown_type $errors
23316 */
23317 function media_upload_library_form($errors) {
23318 global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
23319
23320 media_upload_header();
23321
23322 $post_id = intval($_REQUEST['post_id']);
23323
23324 $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=library&post_id=$post_id");
23325
23326 $_GET['paged'] = isset( $_GET['paged'] ) ? intval($_GET['paged']) : 0;
23327 if ( $_GET['paged'] < 1 )
23328 $_GET['paged'] = 1;
23329 $start = ( $_GET['paged'] - 1 ) * 10;
23330 if ( $start < 1 )
23331 $start = 0;
23332 add_filter( 'post_limits', $limit_filter = create_function( '$a', "return 'LIMIT $start, 10';" ) );
23333
23334 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
23335
23336 ?>
23337
23338 <form id="filter" action="" method="get">
23339 <input type="hidden" name="type" value="<?php echo attribute_escape( $type ); ?>" />
23340 <input type="hidden" name="tab" value="<?php echo attribute_escape( $tab ); ?>" />
23341 <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" />
23342 <input type="hidden" name="post_mime_type" value="<?php echo attribute_escape( $_GET['post_mime_type'] ); ?>" />
23343
23344 <p id="media-search" class="search-box">
23345 <label class="hidden" for="media-search-input"><?php _e('Search Media');?>:</label>
23346 <input type="text" id="media-search-input" class="search-input" name="s" value="<?php the_search_query(); ?>" />
23347 <input type="submit" value="<?php echo attribute_escape( __( 'Search Media' ) ); ?>" class="button" />
23348 </p>
23349
23350 <ul class="subsubsub">
23351 <?php
23352 $type_links = array();
23353 $_num_posts = (array) wp_count_attachments();
23354 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
23355 foreach ( $matches as $_type => $reals )
23356 foreach ( $reals as $real )
23357 $num_posts[$_type] += $_num_posts[$real];
23358 // If available type specified by media button clicked, filter by that type
23359 if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) {
23360 $_GET['post_mime_type'] = $type;
23361 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
23362 }
23363 if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' )
23364 $class = ' class="current"';
23365 $type_links[] = "<li><a href='" . clean_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . "'$class>".__('All Types')."</a>";
23366 foreach ( $post_mime_types as $mime_type => $label ) {
23367 $class = '';
23368
23369 if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
23370 continue;
23371
23372 if ( wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
23373 $class = ' class="current"';
23374
23375 $type_links[] = "<li><a href='" . clean_url(add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false))) . "'$class>" . sprintf(__ngettext($label[2][0], $label[2][1], $num_posts[$mime_type]), "<span id='$mime_type-counter'>" . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>';
23376 }
23377 echo implode(' | </li>', $type_links) . '</li>';
23378 unset($type_links);
23379 ?>
23380 </ul>
23381
23382 <div class="tablenav">
23383
23384 <?php
23385 $page_links = paginate_links( array(
23386 'base' => add_query_arg( 'paged', '%#%' ),
23387 'format' => '',
23388 'prev_text' => __('«'),
23389 'next_text' => __('»'),
23390 'total' => ceil($wp_query->found_posts / 10),
23391 'current' => $_GET['paged']
23392 ));
23393
23394 if ( $page_links )
23395 echo "<div class='tablenav-pages'>$page_links</div>";
23396 ?>
23397
23398 <div class="alignleft actions">
23399 <?php
23400
23401 $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";
23402
23403 $arc_result = $wpdb->get_results( $arc_query );
23404
23405 $month_count = count($arc_result);
23406
23407 if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?>
23408 <select name='m'>
23409 <option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>
23410 <?php
23411 foreach ($arc_result as $arc_row) {
23412 if ( $arc_row->yyear == 0 )
23413 continue;
23414 $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
23415
23416 if ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] )
23417 $default = ' selected="selected"';
23418 else
23419 $default = '';
23420
23421 echo "<option$default value='" . attribute_escape( $arc_row->yyear . $arc_row->mmonth ) . "'>";
23422 echo wp_specialchars( $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear" );
23423 echo "</option>\n";
23424 }
23425 ?>
23426 </select>
23427 <?php } ?>
23428
23429 <input type="submit" id="post-query-submit" value="<?php echo attribute_escape( __( 'Filter »' ) ); ?>" class="button-secondary" />
23430
23431 </div>
23432
23433 <br class="clear" />
23434 </div>
23435 </form>
23436
23437 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form validate" id="library-form">
23438
23439 <?php wp_nonce_field('media-form'); ?>
23440 <?php //media_upload_form( $errors ); ?>
23441
23442 <script type="text/javascript">
23443 <!--
23444 jQuery(function($){
23445 var preloaded = $(".media-item.preloaded");
23446 if ( preloaded.length > 0 ) {
23447 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
23448 updateMediaForm();
23449 }
23450 });
23451 -->
23452 </script>
23453
23454 <div id="media-items">
23455 <?php echo get_media_items(null, $errors); ?>
23456 </div>
23457 <p class="ml-submit">
23458 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
23459 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
23460 </p>
23461 </form>
23462 <?php
23463 }
23464
23465 /**
23466 * {@internal Missing Short Description}}
23467 *
23468 * @since unknown
23469 *
23470 * @return unknown
23471 */
23472 function type_url_form_image() {
23473
23474 if ( apply_filters( 'disable_captions', '' ) ) {
23475 $alt = __('Alternate Text');
23476 $alt_help = __('Alt text for the image, e.g. "The Mona Lisa"');
23477 } else {
23478 $alt = __('Image Caption');
23479 $alt_help = __('Also used as alternate text for the image');
23480 }
23481
23482 $default_align = get_option('image_default_align');
23483 if ( empty($default_align) )
23484 $default_align = 'none';
23485
23486 return '
23487 <table class="describe"><tbody>
23488 <tr>
23489 <th valign="top" scope="row" class="label" style="width:120px;">
23490 <span class="alignleft"><label for="src">' . __('Image URL') . '</label></span>
23491 <span class="alignright"><img id="status_img" src="images/required.svg" title="required" alt="required" /></span>
23492 </th>
23493 <td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td>
23494 </tr>
23495
23496 <tr>
23497 <th valign="top" scope="row" class="label">
23498 <span class="alignleft"><label for="title">' . __('Image Title') . '</label></span>
23499 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
23500 </th>
23501 <td class="field"><p><input id="title" name="title" value="" type="text" aria-required="true" /></p></td>
23502 </tr>
23503
23504 <tr>
23505 <th valign="top" scope="row" class="label">
23506 <span class="alignleft"><label for="alt">' . $alt . '</label></span>
23507 </th>
23508 <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" />
23509 <p class="help">' . $alt_help . '</p></td>
23510 </tr>
23511
23512 <tr class="align">
23513 <th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
23514 <td class="field">
23515 <input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' />
23516 <label for="align-none" class="align image-align-none-label">' . __('None') . '</label>
23517 <input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' />
23518 <label for="align-left" class="align image-align-left-label">' . __('Left') . '</label>
23519 <input name="align" id="align-center" value="center" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'center' ? ' checked="checked"' : '').' />
23520 <label for="align-center" class="align image-align-center-label">' . __('Center') . '</label>
23521 <input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'right' ? ' checked="checked"' : '').' />
23522 <label for="align-right" class="align image-align-right-label">' . __('Right') . '</label>
23523 </td>
23524 </tr>
23525
23526 <tr>
23527 <th valign="top" scope="row" class="label">
23528 <span class="alignleft"><label for="url">' . __('Link Image To:') . '</label></span>
23529 </th>
23530 <td class="field"><input id="url" name="url" value="" type="text" /><br />
23531
23532 <button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button>
23533 <button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button>
23534 <p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td>
23535 </tr>
23536
23537 <tr>
23538 <td></td>
23539 <td>
23540 <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . attribute_escape(__('Insert into Post')) . '" />
23541 </td>
23542 </tr>
23543 </tbody></table>
23544 ';
23545
23546 }
23547
23548 /**
23549 * {@internal Missing Short Description}}
23550 *
23551 * @since unknown
23552 *
23553 * @return unknown
23554 */
23555 function type_url_form_audio() {
23556 return '
23557 <table class="describe"><tbody>
23558 <tr>
23559 <th valign="top" scope="row" class="label">
23560 <span class="alignleft"><label for="insertonly[href]">' . __('Audio File URL') . '</label></span>
23561 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
23562 </th>
23563 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
23564 </tr>
23565 <tr>
23566 <th valign="top" scope="row" class="label">
23567 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
23568 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
23569 </th>
23570 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
23571 </tr>
23572 <tr><td></td><td class="help">' . __('Link text, e.g. "Still Alive by Jonathan Coulton"') . '</td></tr>
23573 <tr>
23574 <td></td>
23575 <td>
23576 <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
23577 </td>
23578 </tr>
23579 </tbody></table>
23580 ';
23581 }
23582
23583 /**
23584 * {@internal Missing Short Description}}
23585 *
23586 * @since unknown
23587 *
23588 * @return unknown
23589 */
23590 function type_url_form_video() {
23591 return '
23592 <table class="describe"><tbody>
23593 <tr>
23594 <th valign="top" scope="row" class="label">
23595 <span class="alignleft"><label for="insertonly[href]">' . __('Video URL') . '</label></span>
23596 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
23597 </th>
23598 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
23599 </tr>
23600 <tr>
23601 <th valign="top" scope="row" class="label">
23602 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
23603 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
23604 </th>
23605 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
23606 </tr>
23607 <tr><td></td><td class="help">' . __('Link text, e.g. "Lucy on YouTube"') . '</td></tr>
23608 <tr>
23609 <td></td>
23610 <td>
23611 <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
23612 </td>
23613 </tr>
23614 </tbody></table>
23615 ';
23616 }
23617
23618 /**
23619 * {@internal Missing Short Description}}
23620 *
23621 * @since unknown
23622 *
23623 * @return unknown
23624 */
23625 function type_url_form_file() {
23626 return '
23627 <table class="describe"><tbody>
23628 <tr>
23629 <th valign="top" scope="row" class="label">
23630 <span class="alignleft"><label for="insertonly[href]">' . __('URL') . '</label></span>
23631 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
23632 </th>
23633 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
23634 </tr>
23635 <tr>
23636 <th valign="top" scope="row" class="label">
23637 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
23638 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
23639 </th>
23640 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
23641 </tr>
23642 <tr><td></td><td class="help">' . __('Link text, e.g. "Ransom Demands (PDF)"') . '</td></tr>
23643 <tr>
23644 <td></td>
23645 <td>
23646 <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
23647 </td>
23648 </tr>
23649 </tbody></table>
23650 ';
23651 }
23652
23653 /**
23654 * {@internal Missing Short Description}}
23655 *
23656 * Support a GET parameter for disabling the flash uploader.
23657 *
23658 * @since unknown
23659 *
23660 * @param unknown_type $flash
23661 * @return unknown
23662 */
23663 function media_upload_use_flash($flash) {
23664 if ( array_key_exists('flash', $_REQUEST) )
23665 $flash = !empty($_REQUEST['flash']);
23666 return $flash;
23667 }
23668
23669 add_filter('flash_uploader', 'media_upload_use_flash');
23670
23671 /**
23672 * {@internal Missing Short Description}}
23673 *
23674 * @since unknown
23675 */
23676 function media_upload_flash_bypass() {
23677 echo '<p class="upload-flash-bypass">';
23678 printf( __('You are using the Flash uploader. Problems? Try the <a href="%s">Browser uploader</a> instead.'), clean_url(add_query_arg('flash', 0)) );
23679 echo '</p>';
23680 }
23681
23682 /**
23683 * {@internal Missing Short Description}}
23684 *
23685 * @since unknown
23686 */
23687 function media_upload_html_bypass() {
23688 echo '<p class="upload-html-bypass">';
23689 if ( array_key_exists('flash', $_REQUEST) )
23690 // the user manually selected the browser uploader, so let them switch back to Flash
23691 printf( __('You are using the Browser uploader. Try the <a href="%s">Flash uploader</a> instead.'), clean_url(add_query_arg('flash', 1)) );
23692 else
23693 // the user probably doesn't have Flash
23694 printf( __('You are using the Browser uploader.') );
23695
23696 echo '</p>';
23697 }
23698
23699 add_action('post-flash-upload-ui', 'media_upload_flash_bypass');
23700 add_action('post-html-upload-ui', 'media_upload_html_bypass');
23701
23702 /**
23703 * {@internal Missing Short Description}}
23704 *
23705 * Make sure the GET parameter sticks when we submit a form.
23706 *
23707 * @since unknown
23708 *
23709 * @param unknown_type $url
23710 * @return unknown
23711 */
23712 function media_upload_bypass_url($url) {
23713 if ( array_key_exists('flash', $_REQUEST) )
23714 $url = add_query_arg('flash', intval($_REQUEST['flash']));
23715 return $url;
23716 }
23717
23718 add_filter('media_upload_form_url', 'media_upload_bypass_url');
23719
23720
23721
23722 add_filter('async_upload_image', 'get_media_item', 10, 2);
23723 add_filter('async_upload_audio', 'get_media_item', 10, 2);
23724 add_filter('async_upload_video', 'get_media_item', 10, 2);
23725 add_filter('async_upload_file', 'get_media_item', 10, 2);
23726
23727 add_action('media_upload_image', 'media_upload_image');
23728 add_action('media_upload_audio', 'media_upload_audio');
23729 add_action('media_upload_video', 'media_upload_video');
23730 add_action('media_upload_file', 'media_upload_file');
23731
23732 add_filter('media_upload_gallery', 'media_upload_gallery');
23733
23734 add_filter('media_upload_library', 'media_upload_library');
23735
23736 ?>