Changeset 8335 for branches/crazyhorse/wp-admin/includes/media.php
- Timestamp:
- 07/15/2008 02:01:08 AM (18 years ago)
- File:
-
- 1 edited
-
branches/crazyhorse/wp-admin/includes/media.php (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/crazyhorse/wp-admin/includes/media.php
r8329 r8335 27 27 28 28 function the_media_upload_tabs() { 29 global $redir_tab; 29 30 $tabs = media_upload_tabs(); 30 31 31 32 if ( !empty($tabs) ) { 32 33 echo "<ul id='sidemenu'>\n"; 33 if ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) ) 34 if ( isset($redir_tab) && array_key_exists($redir_tab, $tabs) ) 35 $current = $redir_tab; 36 elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) ) 34 37 $current = $_GET['tab']; 35 38 else { … … 65 68 function image_add_caption( $html, $id, $alt, $title, $align, $url, $size ) { 66 69 67 if ( empty($alt) ) return $html; 70 // CAPTIONS_OFF is temporary. Do not use it. 71 if ( empty($alt) || ( defined('CAPTIONS_OFF') && true == CAPTIONS_OFF ) ) return $html; 68 72 $id = ( 0 < (int) $id ) ? 'attachment_' . $id : ''; 69 73 … … 75 79 if ( empty($align) ) $align = 'none'; 76 80 77 $shcode = '[ wp_caption id="' . $id . '" align="align' . $align78 . '" width="' . $width . '" caption="' . $alt . '"]' . $html . '[/ wp_caption]';81 $shcode = '[caption id="' . $id . '" align="align' . $align 82 . '" width="' . $width . '" caption="' . $alt . '"]' . $html . '[/caption]'; 79 83 80 84 return apply_filters( 'image_add_caption_shortcode', $shcode, $html ); … … 155 159 $content = $image_meta['caption']; 156 160 } 157 161 158 162 $title = @$desc; 159 163 … … 232 236 $out = <<<EOF 233 237 234 <a href="{$image_upload_iframe_src}&TB_iframe=true" class="thickbox" title='$image_title'><img src='images/media-button-image.gif' alt='$image_title' /></a>235 <a href="{$video_upload_iframe_src}&TB_iframe=true" class="thickbox" title='$video_title'><img src='images/media-button-video.gif' alt='$video_title' /></a>236 <a href="{$audio_upload_iframe_src}&TB_iframe=true" class="thickbox" title='$audio_title'><img src='images/media-button-music.gif' alt='$audio_title' /></a>237 <a href="{$media_upload_iframe_src}&TB_iframe=true" class="thickbox" title='$media_title'><img src='images/media-button-other.gif' alt='$media_title' /></a>238 <a href="{$image_upload_iframe_src}&TB_iframe=true" id="add_image" class="thickbox" title='$image_title'><img src='images/media-button-image.gif' alt='$image_title' /></a> 239 <a href="{$video_upload_iframe_src}&TB_iframe=true" id="add_video" class="thickbox" title='$video_title'><img src='images/media-button-video.gif' alt='$video_title' /></a> 240 <a href="{$audio_upload_iframe_src}&TB_iframe=true" id="add_audio" class="thickbox" title='$audio_title'><img src='images/media-button-music.gif' alt='$audio_title' /></a> 241 <a href="{$media_upload_iframe_src}&TB_iframe=true" id="add_media" class="thickbox" title='$media_title'><img src='images/media-button-other.gif' alt='$media_title' /></a> 238 242 239 243 EOF; … … 326 330 } 327 331 328 if ( isset($_POST['save']) ) 332 if ( isset($_POST['save']) ) { 329 333 $errors['upload_notice'] = __('Saved.'); 334 return media_upload_gallery(); 335 } 330 336 331 337 return wp_iframe( 'media_upload_type_form', 'image', $errors, $id ); … … 337 343 $file_array['tmp_name'] = download_url($file); 338 344 $desc = @$desc; 339 345 340 346 $id = media_handle_sideload($file_array, $post_id, $desc); 341 347 $src = $id; 342 348 343 unset($file_array);344 345 349 if ( is_wp_error($id) ) { 346 $errors['upload_error'] = $id;350 @unlink($file_array['tmp_name']); 347 351 return $id; 348 352 } … … 388 392 } 389 393 390 if ( isset($_POST['save']) ) 394 if ( isset($_POST['save']) ) { 391 395 $errors['upload_notice'] = __('Saved.'); 396 return media_upload_gallery(); 397 } 392 398 393 399 return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id ); … … 426 432 } 427 433 428 if ( isset($_POST['save']) ) 434 if ( isset($_POST['save']) ) { 429 435 $errors['upload_notice'] = __('Saved.'); 436 return media_upload_gallery(); 437 } 430 438 431 439 return wp_iframe( 'media_upload_type_form', 'video', $errors, $id ); … … 464 472 } 465 473 466 if ( isset($_POST['save']) ) 474 if ( isset($_POST['save']) ) { 467 475 $errors['upload_notice'] = __('Saved.'); 476 return media_upload_gallery(); 477 } 468 478 469 479 return wp_iframe( 'media_upload_type_form', 'file', $errors, $id ); … … 500 510 if ( substr($post->post_mime_type, 0, 5) == 'image' ) { 501 511 $form_fields['post_title']['required'] = true; 502 $form_fields['post_excerpt']['label'] = __('Caption'); 503 $form_fields['post_excerpt']['helps'][] = __('Alternate text, e.g. "The Mona Lisa"'); 512 513 // CAPTIONS_OFF is temporary. Do not use it. 514 if ( defined('CAPTIONS_OFF') && true == CAPTIONS_OFF ) { 515 $form_fields['post_excerpt']['label'] = __('Alternate Text'); 516 $form_fields['post_excerpt']['helps'][] = __('Alt text for the image, e.g. "The Mona Lisa"'); 517 } else { 518 $form_fields['post_excerpt']['label'] = __('Caption'); 519 $form_fields['post_excerpt']['helps'][] = __('Also used as alternate text for the image'); 520 } 504 521 505 522 $form_fields['post_content']['label'] = __('Description'); … … 590 607 $link = get_attachment_link($post->ID); 591 608 609 // CAPTIONS_OFF is temporary. Do not use it. 610 if ( defined('CAPTIONS_OFF') && true == CAPTIONS_OFF ) 611 $alt = __('Alternate Text'); 612 else 613 $alt = __('Caption'); 614 592 615 $form_fields = array( 593 616 'post_title' => array( … … 596 619 ), 597 620 'post_excerpt' => array( 598 'label' => __('Caption'),621 'label' => $alt, 599 622 'value' => $edit_post->post_excerpt, 600 623 ), … … 676 699 677 700 function get_media_item( $attachment_id, $args = null ) { 701 global $redir_tab; 702 678 703 $default_args = array( 'errors' => null, 'send' => true, 'delete' => true, 'toggle' => true ); 679 704 $args = wp_parse_args( $args, $default_args ); … … 723 748 724 749 $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case 750 $display_title = wp_html_excerpt($display_title, 60); 751 752 $gallery = ( (isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab']) || (isset($redir_tab) && 'gallery' == $redir_tab) ) ? true : false; 753 $order = ''; 754 755 foreach ( $form_fields as $key => $val ) { 756 if ( 'menu_order' == $key ) { 757 if ( $gallery ) 758 $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="'.$val['value'].'" /></div>'; 759 else 760 $order = '<input type="hidden" name="attachments['.$attachment_id.'][menu_order]" value="'.$val['value'].'" />'; 761 762 unset($form_fields['menu_order']); 763 break; 764 } 765 } 725 766 726 767 $item = " 727 768 $type 728 769 $toggle_links 770 $order 729 771 <div class='filename new'>$display_title</div> 730 772 <table class='slidetoggle describe $class'> … … 960 1002 </div> 961 1003 1004 <script type="text/javascript"> 1005 //<![CDATA[ 1006 var addExtImage = { 1007 1008 width : '', 1009 height : '', 1010 align : 'alignnone', 1011 1012 insert : function() { 1013 var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = null; 1014 1015 if ( '' == f.src.value || '' == t.width ) return false; 1016 1017 if ( f.title.value ) { 1018 title = f.title.value.replace(/['"<>]+/g, ''); 1019 title = ' title="'+title+'"'; 1020 } 1021 1022 if ( f.alt.value ) { 1023 alt = f.alt.value.replace(/['"<>]+/g, ''); 1024 <?php if ( ! defined('CAPTIONS_OFF') || true != CAPTIONS_OFF ) { // CAPTIONS_OFF is temporary. Do not use it. ?> 1025 caption = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); 1026 <?php } ?> 1027 } 1028 1029 cls = caption ? '' : ' class="'+t.align+'"'; 1030 1031 html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />'; 1032 1033 if ( f.url.value ) 1034 html = '<a href="'+f.url.value+'">'+html+'</a>'; 1035 1036 if ( caption ) 1037 html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]'; 1038 1039 var win = window.dialogArguments || opener || parent || top; 1040 win.send_to_editor(html); 1041 }, 1042 1043 resetImageData : function() { 1044 var t = addExtImage; 1045 1046 t.width = t.height = ''; 1047 document.getElementById('go_button').style.color = '#bbb'; 1048 if ( ! document.forms[0].src.value ) 1049 document.getElementById('status_img').src = 'images/required.gif'; 1050 else document.getElementById('status_img').src = 'images/no.png'; 1051 }, 1052 1053 updateImageData : function() { 1054 var t = addExtImage; 1055 1056 t.width = t.preloadImg.width; 1057 t.height = t.preloadImg.height; 1058 document.getElementById('go_button').style.color = '#333'; 1059 document.getElementById('status_img').src = 'images/yes.png'; 1060 }, 1061 1062 getImageData : function() { 1063 var t = addExtImage, src = document.forms[0].src.value; 1064 1065 if ( ! src ) { 1066 t.resetImageData(); 1067 return false; 1068 } 1069 document.getElementById('status_img').src = 'images/loading.gif'; 1070 t.preloadImg = new Image(); 1071 t.preloadImg.onload = t.updateImageData; 1072 t.preloadImg.onerror = t.resetImageData; 1073 t.preloadImg.src = src; 1074 } 1075 } 1076 //]]> 1077 </script> 1078 962 1079 <div id="media-items"> 963 1080 <div class="media-item media-blank"> … … 971 1088 972 1089 function media_upload_gallery_form($errors) { 1090 global $redir_tab; 1091 1092 $redir_tab = 'gallery'; 973 1093 media_upload_header(); 974 1094 975 1095 $post_id = intval($_REQUEST['post_id']); 976 977 1096 $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=gallery&post_id=$post_id"); 978 979 1097 ?> 980 1098 … … 994 1112 <?php wp_nonce_field('media-form'); ?> 995 1113 <?php //media_upload_form( $errors ); ?> 996 1114 <table class="widefat"> 1115 <thead><tr> 1116 <th><?php _e('Media'); ?></th> 1117 <th class="order-head"><?php _e('Order'); ?></th> 1118 </tr></thead> 1119 </table> 997 1120 <div id="media-items"> 998 1121 <?php echo get_media_items($post_id, $errors); ?> 999 1122 </div> 1123 <p class="ml-submit"> 1000 1124 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" /> 1001 1125 <input type="submit" class="button insert-gallery" name="insert-gallery" value="<?php echo attribute_escape( __( 'Insert gallery into post' ) ); ?>" /> … … 1003 1127 <input type="hidden" name="type" value="<?php echo attribute_escape( $GLOBALS['type'] ); ?>" /> 1004 1128 <input type="hidden" name="tab" value="<?php echo attribute_escape( $GLOBALS['tab'] ); ?>" /> 1129 </p> 1005 1130 </form> 1006 1131 <?php … … 1154 1279 1155 1280 function type_form_image() { 1156 return'1281 $form = ' 1157 1282 <table class="describe"><tbody> 1158 1283 <tr> 1284 <th valign="top" scope="row" class="label" style="width:120px;"> 1285 <span class="alignleft"><label for="src">' . __('Source') . '</label></span> 1286 <span class="alignright"><img id="status_img" src="images/required.gif" title="required" alt="required" /></span> 1287 </th> 1288 <td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()"></td> 1289 </tr> 1290 1291 <tr> 1159 1292 <th valign="top" scope="row" class="label"> 1160 <span class="alignleft"><label for=" insertonly[src]">' . __('Image URL') . '</label></span>1293 <span class="alignleft"><label for="title">' . __('Image Title') . '</label></span> 1161 1294 <span class="alignright"><abbr title="required" class="required">*</abbr></span> 1162 1295 </th> 1163 <td class="field"><input id="insertonly[src]" name="insertonly[src]" value="" type="text" aria-required="true"></td> 1164 </tr> 1296 <td class="field"><p><input id="title" name="title" value="" type="text" aria-required="true" /></p></td> 1297 </tr> 1298 '; 1299 // CAPTIONS_OFF is temporary. Do not use it. 1300 if ( defined('CAPTIONS_OFF') && true == CAPTIONS_OFF ) { 1301 $form .= ' 1165 1302 <tr> 1166 1303 <th valign="top" scope="row" class="label"> 1167 <span class="alignleft"><label for="insertonly[alt]">' . __('Description') . '</label></span> 1168 <span class="alignright"><abbr title="required" class="required">*</abbr></span> 1304 <span class="alignleft"><label for="alt">' . __('Alternate Text') . '</label></span> 1169 1305 </th> 1170 <td class="field"><input id="insertonly[alt]" name="insertonly[alt]" value="" type="text" aria-required="true"></td> 1171 </tr> 1172 <tr><td></td><td class="help">' . __('Alternate text, e.g. "The Mona Lisa"') . '</td></tr> 1306 <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" /> 1307 <p class="help">' . __('Alt text for the image, e.g. "The Mona Lisa"') . '</p></td> 1308 </tr> 1309 '; 1310 1311 } else { 1312 $form .= ' 1313 <tr> 1314 <th valign="top" scope="row" class="label"> 1315 <span class="alignleft"><label for="alt">' . __('Image Caption') . '</label></span> 1316 </th> 1317 <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" /> 1318 <p class="help">' . __('Also used as alternate text for the image') . '</p></td> 1319 </tr> 1320 '; 1321 } 1322 $form .= ' 1173 1323 <tr class="align"> 1174 <th valign="top" scope="row" class="label">< label for="insertonly[align]">' . __('Alignment') . '</label></th>1324 <th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th> 1175 1325 <td class="field"> 1176 <input name=" insertonly[align]" id="image-align-none-0" value="none" type="radio" checked="checked" />1177 <label for=" image-align-none-0" class="align image-align-none-label">' . __('None') . '</label>1178 <input name=" insertonly[align]" id="image-align-left-0" value="left" type="radio" />1179 <label for=" image-align-left-0" class="align image-align-left-label">' . __('Left') . '</label>1180 <input name=" insertonly[align]" id="image-align-center-0" value="center" type="radio" />1181 <label for=" image-align-center-0" class="align image-align-center-label">' . __('Center') . '</label>1182 <input name=" insertonly[align]" id="image-align-right-0" value="right" type="radio" />1183 <label for=" image-align-right-0" class="align image-align-right-label">' . __('Right') . '</label>1326 <input name="align" id="align-none" value="alignnone" onclick="addExtImage.align=this.value" type="radio" checked="checked" /> 1327 <label for="align-none" class="align image-align-none-label">' . __('None') . '</label> 1328 <input name="align" id="align-left" value="alignleft" onclick="addExtImage.align=this.value" type="radio" /> 1329 <label for="align-left" class="align image-align-left-label">' . __('Left') . '</label> 1330 <input name="align" id="align-center" value="aligncenter" onclick="addExtImage.align=this.value" type="radio" /> 1331 <label for="align-center" class="align image-align-center-label">' . __('Center') . '</label> 1332 <input name="align" id="align-right" value="alignright" onclick="addExtImage.align=this.value" type="radio" /> 1333 <label for="align-right" class="align image-align-right-label">' . __('Right') . '</label> 1184 1334 </td> 1185 1335 </tr> 1336 1337 <tr> 1338 <th valign="top" scope="row" class="label"> 1339 <span class="alignleft"><label for="url">' . __('Link URL') . '</label></span> 1340 </th> 1341 <td class="field"><input id="url" name="url" value="" type="text" /><br /> 1342 1343 <button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button> 1344 <button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button> 1345 <p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td> 1346 </tr> 1347 1186 1348 <tr> 1187 1349 <td></td> 1188 1350 <td> 1189 <input type=" submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />1351 <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . attribute_escape(__('Insert into Post')) . '" /> 1190 1352 </td> 1191 1353 </tr> 1192 1354 </tbody></table> 1193 1355 '; 1356 1357 return $form; 1194 1358 } 1195 1359 … … 1278 1442 } 1279 1443 1444 // support a GET parameter for disabling the flash uploader 1445 function media_upload_use_flash($flash) { 1446 if ( array_key_exists('flash', $_REQUEST) ) 1447 $flash = !empty($_REQUEST['flash']); 1448 return $flash; 1449 } 1450 1451 add_filter('flash_uploader', 'media_upload_use_flash'); 1452 1453 function media_upload_flash_bypass() { 1454 echo '<p class="upload-flash-bypass">'; 1455 printf( __('You are using the Flash uploader. Problems? Try the <a href="%s">Browser uploader</a> instead.'), clean_url(add_query_arg('flash', 0)) ); 1456 echo '</p>'; 1457 } 1458 1459 add_action('post-flash-upload-ui', 'media_upload_flash_bypass'); 1460 1461 function media_upload_html_bypass() { 1462 echo '<p class="upload-html-bypass">'; 1463 if ( array_key_exists('flash', $_REQUEST) ) 1464 // the user manually selected the browser uploader, so let them switch back to Flash 1465 printf( __('You are using the Browser uploader. Try the <a href="%s">Flash uploader</a> instead.'), clean_url(add_query_arg('flash', 1)) ); 1466 else 1467 // the user probably doesn't have Flash 1468 printf( __('You are using the Browser uploader.') ); 1469 1470 echo '</p>'; 1471 } 1472 1473 add_action('post-flash-upload-ui', 'media_upload_flash_bypass'); 1474 add_action('post-html-upload-ui', 'media_upload_html_bypass'); 1475 1476 // make sure the GET parameter sticks when we submit a form 1477 function media_upload_bypass_url($url) { 1478 if ( array_key_exists('flash', $_REQUEST) ) 1479 $url = add_query_arg('flash', intval($_REQUEST['flash'])); 1480 return $url; 1481 } 1482 1483 add_filter('media_upload_form_url', 'media_upload_bypass_url'); 1484 1485 1486 1280 1487 add_filter('async_upload_image', 'get_media_item', 10, 2); 1281 1488 add_filter('async_upload_audio', 'get_media_item', 10, 2);
Note: See TracChangeset
for help on using the changeset viewer.