root/tags/1_0-rc2/wp-admin/inline-uploading.php

Revision 599, 22.0 kB (checked in by donncha, 3 years ago)

WP Merge

<
Line 
1 <?php
2
3 require_once('admin.php');
4
5 header('Content-Type: text/html; charset=' . get_option('blog_charset'));
6
7 if (!current_user_can('upload_files'))
8     die(__('You do not have permission to upload files.'));
9
10 $wpvarstoreset = array('action', 'post', 'all', 'last', 'link', 'sort', 'start', 'imgtitle', 'descr', 'attachment');
11
12 for ($i=0; $i<count($wpvarstoreset); $i += 1) {
13     $wpvar = $wpvarstoreset[$i];
14     if (!isset($$wpvar)) {
15         if (empty($_POST["$wpvar"])) {
16             if (empty($_GET["$wpvar"])) {
17                 $$wpvar = '';
18             } else {
19             $$wpvar = $_GET["$wpvar"];
20             }
21         } else {
22             $$wpvar = $_POST["$wpvar"];
23         }
24     }
25 }
26
27 $post = (int) $post;
28 $images_width = 1;
29
30 switch($action) {
31 case 'links':
32 // Do not pass GO.
33 break;
34
35 case 'delete':
36
37 check_admin_referer('inlineuploading');
38
39 if ( !current_user_can('edit_post', (int) $attachment) )
40     die(__('You are not allowed to delete this attachment.').' <a href="'.basename(__FILE__)."?post=$post&amp;all=$all&amp;action=upload\">".__('Go back').'</a>');
41
42 wp_delete_attachment($attachment);
43
44 wp_redirect(basename(__FILE__) ."?post=$post&all=$all&action=view&start=$start");
45 die;
46
47 case 'save':
48
49 check_admin_referer('inlineuploading');
50
51 $overrides = array('action'=>'save');
52
53 $file = wp_handle_upload($_FILES['image'], $overrides);
54
55 if( isset( $file[ 'error' ] ) == false )
56     $file[ 'error' ] = apply_filters( "check_uploaded_file", $file[ 'error' ] );
57
58 if ( isset($file['error']) )
59     die($file['error'] . '<br /><a href="' . basename(__FILE__) . '?action=upload&post=' . $post . '">'.__('Back to Image Uploading').'</a>');
60
61 $url = $file['url'];
62 $type = $file['type'];
63 $file = $file['file'];
64 $filename = basename($file);
65
66 // Construct the attachment array
67 $attachment = array(
68     'post_title' => $imgtitle ? $imgtitle : $filename,
69     'post_content' => $descr,
70     'post_type' => 'attachment',
71     'post_parent' => $post,
72     'post_mime_type' => $type,
73     'guid' => $url
74     );
75
76 // Save the data
77 $id = wp_insert_attachment($attachment, $file, $post);
78
79 if ( preg_match('!^image/!', $attachment['post_mime_type']) ) {
80     // Generate the attachment's postmeta.
81     $imagesize = getimagesize($file);
82     $imagedata['width'] = $imagesize['0'];
83     $imagedata['height'] = $imagesize['1'];
84     list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']);
85     $imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'";
86     $imagedata['file'] = $file;
87
88     add_post_meta($id, '_wp_attachment_metadata', $imagedata);
89
90     if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) {
91         if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 )
92             $thumb = wp_create_thumbnail($file, 128);
93         elseif ( $imagedata['height'] > 96 )
94             $thumb = wp_create_thumbnail($file, 96);
95
96         if ( @file_exists($thumb) ) {
97             $newdata = $imagedata;
98             $newdata['thumb'] = basename($thumb);
99             update_post_meta($id, '_wp_attachment_metadata', $newdata, $imagedata);
100         } else {
101             $error = $thumb;
102         }
103     }
104 } else {
105     add_post_meta($id, '_wp_attachment_metadata', array());
106 }
107
108 wp_redirect(basename(__FILE__) . "?post=$post&all=$all&action=view&start=0");
109 die();
110
111 case 'upload':
112
113 $current_1 = ' class="current"';
114 $back = $next = false;
115 break;
116
117 case 'view':
118
119 // How many images do we show? How many do we query?
120 $num = 5;
121 $double = $num * 2;
122
123 if ( $post && (empty($all) || $all == 'false') ) {
124     $and_post = "AND post_parent = '$post'";
125     $current_2 = ' class="current"';
126 } else {
127     $current_3 = ' class="current"';
128 }
129
130 if (! current_user_can('edit_others_posts') )
131     $and_user = "AND post_author = " . $user_ID;
132
133 if ( $last )
134     $start = $wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_type = 'attachment' $and_user $and_post") - $num;
135 else
136     $start = (int) $start;
137
138 if ( $start < 0 )
139     $start = 0;
140
141 if ( '' == $sort )
142     $sort = "post_date_gmt DESC";
143
144 $attachments = $wpdb->get_results("SELECT ID, post_date, post_title, post_mime_type, guid FROM $wpdb->posts WHERE post_type = 'attachment' $and_type $and_post $and_user ORDER BY $sort LIMIT $start, $double", ARRAY_A);
145
146 if ( count($attachments) == 0 ) {
147     wp_redirect( basename(__FILE__) ."?post=$post&action=upload" );
148     die;
149 } elseif ( count($attachments) > $num ) {
150     $next = $start + count($attachments) - $num;
151 } else {
152     $next = false;
153 }
154
155 if ( $start > 0 ) {
156     $back = $start - $num;
157     if ( $back < 1 )
158         $back = '0';
159 } else {
160     $back = false;
161 }
162
163 $uwidth_sum = 0;
164 $html = '';
165 $popups = '';
166 $style = '';
167 $script = '';
168 if ( count($attachments) > 0 ) {
169     $attachments = array_slice( $attachments, 0, $num );
170     $__delete = __('Delete');
171     $__not_linked = __('Not Linked');
172     $__linked_to_page = __('Linked to Page');
173     $__linked_to_image = __('Linked to Image');
174     $__linked_to_file = __('Linked to File');
175     $__using_thumbnail = __('Using Thumbnail');
176     $__using_original = __('Using Original');
177     $__using_title = __('Using Title');
178     $__using_filename = __('Using Filename');
179     $__using_icon = __('Using Icon');
180     $__no_thumbnail = '<del>'.__('No Thumbnail').'</del>';
181     $__send_to_editor = __('Send to editor');
182     $__close = __('Close Options');
183     $__confirmdelete = __('Delete this file from the server?');
184     $__nothumb = __('There is no thumbnail associated with this photo.');
185     $script .= "notlinked = '$__not_linked';
186 linkedtoimage = '$__linked_to_image';
187 linkedtopage = '$__linked_to_page';
188 linkedtofile = '$__linked_to_file';
189 usingthumbnail = '$__using_thumbnail';
190 usingoriginal = '$__using_original';
191 usingtitle = '$__using_title';
192 usingfilename = '$__using_filename';
193 usingicon = '$__using_icon';
194 var aa = new Array();
195 var ab = new Array();
196 var imga = new Array();
197 var imgb = new Array();
198 var srca = new Array();
199 var srcb = new Array();
200 var title = new Array();
201 var filename = new Array();
202 var icon = new Array();
203 ";
204     foreach ( $attachments as $key => $attachment ) {
205         $ID = $attachment['ID'];
206         $href = get_attachment_link($ID);
207         $meta = get_post_meta($ID, '_wp_attachment_metadata', true);
208         if (!is_array($meta)) {
209             $meta = get_post_meta($ID, 'imagedata', true); // Try 1.6 Alpha meta key
210             if (!is_array($meta)) {
211                 $meta = array();
212             }
213             add_post_meta($ID, '_wp_attachment_metadata', $meta);
214         }
215         $attachment = array_merge($attachment, $meta);
216         $noscript = "<noscript>
217         <div class='caption'><a href=\"".basename(__FILE__)."?action=links&amp;attachment={$ID}&amp;post={$post}&amp;all={$all}&amp;start={$start}\">Choose Links</a></div>
218         </noscript>
219 ";
220         $send_delete_cancel = "<a onclick=\"sendToEditor({$ID});return false;\" href=\"javascript:void()\">$__send_to_editor</a>
221 <a onclick=\"return confirm('$__confirmdelete')\" href=\"" . wp_nonce_url( basename(__FILE__) . "?action=delete&amp;attachment={$ID}&amp;all=$all&amp;start=$start&amp;post=$post", inlineuploading) . "\">$__delete</a>
222         <a onclick=\"popup.style.display='none';return false;\" href=\"javascript:void()\">$__close</a>
223 ";
224         $uwidth_sum += 128;
225         if ( preg_match('!^image/!', $attachment['post_mime_type'] ) ) {
226             $image = & $attachment;
227             if ( ($image['width'] > 128 || $image['height'] > 96) && !empty($image['thumb']) && file_exists(dirname($image['file']).'/'.$image['thumb']) ) {
228                 $src = str_replace(basename($image['guid']), $image['thumb'], $image['guid']);
229                 $script .= "srca[{$ID}] = '$src';
230 srcb[{$ID}] = '{$image['guid']}';
231 ";
232                 $thumb = 'true';
233                 $thumbtext = $__using_thumbnail;
234             } else {
235                 $src = $image['guid'];
236                 $thumb = 'false';
237                 $thumbtext = $__no_thumbnail;
238             }
239             list($image['uwidth'], $image['uheight']) = get_udims($image['width'], $image['height']);
240             $height_width = 'height="'.$image['uheight'].'" width="'.$image['uwidth'].'"';
241             $xpadding = (128 - $image['uwidth']) / 2;
242             $ypadding = (96 - $image['uheight']) / 2;
243             $style .= "#target{$ID} img { padding: {$ypadding}px {$xpadding}px; }\n";
244             $title = wp_specialchars($image['post_title'], ENT_QUOTES);
245             $script .= "aa[{$ID}] = '<a id=\"p{$ID}\" rel=\"attachment\" class=\"imagelink\" href=\"$href\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">';
246 ab[{$ID}] = '<a class=\"imagelink\" href=\"{$image['guid']}\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">';
247 imga[{$ID}] = '<img id=\"image{$ID}\" src=\"$src\" alt=\"{$title}\" $height_width />';
248 imgb[{$ID}] = '<img id=\"image{$ID}\" src=\"{$image['guid']}\" alt=\"{$title}\" $height_width />';
249 ";
250             $html .= "<div id='target{$ID}' class='attwrap left'>
251     <div id='div{$ID}' class='imagewrap' onclick=\"doPopup({$ID});\">
252         <img id=\"image{$ID}\" src=\"$src\" alt=\"{$title}\" $height_width />
253     </div>
254     {$noscript}
255 </div>
256 ";
257             $popups .= "<div id='popup{$ID}' class='popup'>
258     <a id=\"I{$ID}\" onclick=\"if($thumb)toggleImage({$ID});else alert('$__nothumb');return false;\" href=\"javascript:void()\">$thumbtext</a>
259     <a id=\"L{$ID}\" onclick=\"toggleLink({$ID});return false;\" href=\"javascript:void()\">$__not_linked</a>
260     {$send_delete_cancel}
261 </div>
262 ";
263         } else {
264             $title = wp_specialchars($attachment['post_title'], ENT_QUOTES);
265             $filename = basename($attachment['guid']);
266             $icon = get_attachment_icon($ID);
267             $toggle_icon = "<a id=\"I{$ID}\" onclick=\"toggleOtherIcon({$ID});return false;\" href=\"javascript:void()\">$__using_title</a>";
268             $script .= "aa[{$ID}] = '<a id=\"p{$ID}\" rel=\"attachment\" href=\"$href\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">';
269 ab[{$ID}] = '<a id=\"p{$ID}\" href=\"{$filename}\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">';
270 title[{$ID}] = '{$title}';
271 filename[{$ID}] = '{$filename}';
272 icon[{$ID}] = '{$icon}';
273 ";
274             $html .= "<div id='target{$ID}' class='attwrap left'>
275     <div id='div{$ID}' class='otherwrap usingtext' onmousedown=\"selectLink({$ID})\" onclick=\"doPopup({$ID});return false;\">
276         <a id=\"p{$ID}\" href=\"{$attachment['guid']}\" onmousedown=\"selectLink({$ID});\" onclick=\"return false;\">{$title}</a>
277     </div>
278     {$noscript}
279 </div>
280 ";
281             $popups .= "<div id='popup{$ID}' class='popup'>
282     <div class='filetype'>".__('File Type:').' '.str_replace('/',"/\n",$attachment['post_mime_type'])."</div>
283     <a id=\"L{$ID}\" onclick=\"toggleOtherLink({$ID});return false;\" href=\"javascript:void()\">$__linked_to_file</a>
284     {$toggle_icon}
285     {$send_delete_cancel}
286 </div>
287 ";
288         }
289     }
290 }
291
292 $images_width = $uwidth_sum + ( count($images) * 6 ) + 35;
293
294 break;
295
296 default:
297 die(__('This script was not meant to be called directly.'));
298 }
299
300 ?>
301 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
302 <html xmlns="http://www.w3.org/1999/xhtml">
303 <head>
304 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_settings('blog_charset'); ?>" />
305 <meta http-equiv="imagetoolbar" content="no" />
306 <script type="text/javascript">
307 /* Define any variables we'll need, such as alternate URLs. */
308 <?php echo $script; ?>
309 function htmldecode(st) {
310     o = document.getElementById('htmldecode');
311     if (! o) {
312         o = document.createElement("A");
313         o.id = "htmldecode"
314     }
315     o.innerHTML = st;
316     r = o.innerHTML;
317     return r;
318 }
319 function cancelUpload() {
320     o = document.getElementById('uploadForm');
321     o.method = 'GET';
322     o.action.value = 'view';
323     o.submit();
324 }
325 function doPopup(i) {
326     if ( popup )
327     popup.style.display = 'none';
328     target = document.getElementById('target'+i);
329     popup = document.getElementById('popup'+i);
330     popup.style.left = (target.offsetLeft) + 'px';
331     popup.style.top = (target.offsetTop) + 'px';
332     popup.style.display = 'block';
333 }
334 popup = false;
335 function selectLink(n) {
336     o=document.getElementById('div'+n);
337     if ( typeof document.body.createTextRange == 'undefined' || typeof win.tinyMCE == 'undefined' || win.tinyMCE.configs.length < 1 )
338         return;
339     r = document.body.createTextRange();
340     if ( typeof r != 'undefined' ) {
341         r.moveToElementText(o);
342         r.select();
343     }
344 }
345 function toggleLink(n) {
346     ol=document.getElementById('L'+n);
347     if ( ol.innerHTML == htmldecode(notlinked) ) {
348         ol.innerHTML = linkedtoimage;
349     } else if ( ol.innerHTML == htmldecode(linkedtoimage) ) {
350         ol.innerHTML = linkedtopage;
351     } else {
352         ol.innerHTML = notlinked;
353     }
354     updateImage(n);
355 }
356 function toggleOtherLink(n) {
357     ol=document.getElementById('L'+n);
358     if ( ol.innerHTML == htmldecode(linkedtofile) ) {
359         ol.innerHTML = linkedtopage;
360     } else {
361         ol.innerHTML = linkedtofile;
362     }
363     updateOtherIcon(n);
364 }
365 function toggleImage(n) {
366     oi = document.getElementById('I'+n);
367     if ( oi.innerHTML == htmldecode(usingthumbnail) ) {
368         oi.innerHTML = usingoriginal;
369     } else {
370         oi.innerHTML = usingthumbnail;
371     }
372     updateImage(n);
373 }
374 function toggleOtherIcon(n) {
375     od = document.getElementById('div'+n);
376     oi = document.getElementById('I'+n);
377     if ( oi.innerHTML == htmldecode(usingtitle) ) {
378         oi.innerHTML = usingfilename;
379         od.className = 'otherwrap usingtext';
380     } else if ( oi.innerHTML == htmldecode(usingfilename) && icon[n] != '' ) {
381         oi.innerHTML = usingicon;
382         od.className = 'otherwrap usingicon';
383     } else {
384         oi.innerHTML = usingtitle;
385         od.className = 'otherwrap usingtext';
386     }
387     updateOtherIcon(n);
388 }
389 function updateImage(n) {
390     od=document.getElementById('div'+n);
391     ol=document.getElementById('L'+n);
392     oi=document.getElementById('I'+n);
393     if ( oi.innerHTML == htmldecode(usingthumbnail) ) {
394         img = imga[n];
395     } else {
396         img = imgb[n];
397     }
398     if ( ol.innerHTML == htmldecode(linkedtoimage) ) {
399         od.innerHTML = ab[n]+img+'</a>';
400     } else if ( ol.innerHTML == htmldecode(linkedtopage) ) {
401         od.innerHTML = aa[n]+img+'</a>';
402     } else {
403         od.innerHTML = img;
404     }
405 }
406 function updateOtherIcon(n) {
407     od=document.getElementById('div'+n);
408     ol=document.getElementById('L'+n);
409     oi=document.getElementById('I'+n);
410     if ( oi.innerHTML == htmldecode(usingfilename) ) {
411         txt = filename[n];
412     } else if ( oi.innerHTML == htmldecode(usingicon) ) {
413         txt = icon[n];
414     } else {
415         txt = title[n];
416     }
417     if ( ol.innerHTML == htmldecode(linkedtofile) ) {
418         od.innerHTML = ab[n]+txt+'</a>';
419     } else if ( ol.innerHTML == htmldecode(linkedtopage) ) {
420         od.innerHTML = aa[n]+txt+'</a>';
421     } else {
422         od.innerHTML = txt;
423     }
424 }
425
426 var win = window.opener ? window.opener : window.dialogArguments;
427 if (!win) win = top;
428 tinyMCE = win.tinyMCE;
429 richedit = ( typeof tinyMCE == 'object' && tinyMCE.configs.length > 0 );
430 function sendToEditor(n) {
431     o = document.getElementById('div'+n);
432     h = o.innerHTML.replace(new RegExp('^\\s*(.*?)\\s*$', ''), '$1'); // Trim
433     h = h.replace(new RegExp(' (class|title|width|height|id|onclick|onmousedown)=([^\'"][^ ]*)( |/|>)', 'g'), ' $1="$2"$3'); // Enclose attribs in quotes
434     h = h.replace(new RegExp(' (width|height)=".*?"', 'g'), ''); // Drop size constraints
435     h = h.replace(new RegExp(' on(click|mousedown)="[^"]*"', 'g'), ''); // Drop menu events
436     h = h.replace(new RegExp('<(/?)A', 'g'), '<$1a'); // Lowercase tagnames
437     h = h.replace(new RegExp('<IMG', 'g'), '<img'); // Lowercase again
438     h = h.replace(new RegExp('(<img .+?")>', 'g'), '$1 />'); // XHTML
439     if ( richedit )
440         win.tinyMCE.execCommand('mceInsertContent', false, h);
441     else
442         win.edInsertContent(win.edCanvas, h);
443 }
444 </script>
445 <style type="text/css">
446 <?php if ( $action == 'links' ) : ?>
447 * html { overflow-x: hidden; }
448 <?php else : ?>
449 * html { overflow-y: hidden; }
450 <?php endif; ?>
451 body {
452     font: 13px "Lucida Grande", "Lucida Sans Unicode", Tahoma, Verdana;
453     border: none;
454     margin: 0px;
455     height: 150px;
456     background: #dfe8f1;
457 }
458 form {
459     margin: 3px 2px 0px 6px;
460 }
461 #wrap {
462     clear: both;
463     padding: 0px;
464     width: 100%;
465 }
466 #images {
467     position: absolute;
468     clear: both;
469     margin: 0px;
470     padding: 15px 15px;
471     width: <?php echo $images_width; ?>px;
472 }
473 #images img {
474     background-color: rgb(209, 226, 239);
475 }
476 <?php echo $style; ?>
477 .attwrap, .attwrap * {
478     margin: 0px;
479     padding: 0px;
480     border: 0px;
481 }
482 .imagewrap {
483     margin-right: 5px;
484     overflow: hidden;
485     width: 128px;
486 }
487 .otherwrap {
488     margin-right: 5px;
489     overflow: hidden;
490     background-color: #f9fcfe;
491 }
492 .otherwrap a {
493     display: block;
494 }
495 .otherwrap a, .otherwrap a:hover, .otherwrap a:active, .otherwrap a:visited {
496     color: blue;
497 }
498 .usingicon {
499     padding: 0px;
500     height: 96px;
501     text-align: center;
502     width: 128px;
503 }
504 .usingtext {
505     padding: 3px;
506     height: 90px;
507     text-align: left;
508     width: 122px;
509 }
510 .filetype {
511     font-size: 80%;
512     border-bottom: 3px double #89a
513 }
514 .imagewrap, .imagewrap img, .imagewrap a, .imagewrap a img, .imagewrap a:hover img, .imagewrap a:visited img, .imagewrap a:active img {
515     text-decoration: none;
516 }
517 #upload-menu {
518     background: #fff;
519     margin: 0px;
520     padding: 0;
521     list-style: none;
522     height: 2em;
523     border-bottom: 1px solid #448abd;
524     width: 100%;
525 }
526 #upload-menu li {
527     float: left;
528     margin: 0 0 0 .75em;
529 }
530 #upload-menu a {
531     display: block;
532     padding: 5px;
533     text-decoration: none;
534     color: #000;
535     border-top: 3px solid #fff;
536 }
537 #upload-menu .current a {
538     background: #dfe8f1;
539     border-right: 2px solid #448abd;
540 }
541 #upload-menu a:hover {
542     background: #dfe8f1;
543     color: #000;
544 }
545 .tip {
546     color: rgb(68, 138, 189);
547     padding: 2px 1em;
548 }
549 .inactive {
550     color: #fff;
551     padding: 1px 3px;
552 }
553 .left {
554     float: left;
555 }
556 .right {
557     float: right;
558 }
559 .center {
560     text-align: center;
561 }
562 #upload-menu li.spacer {
563     margin-left: 40px;
564 }
565 #title, #descr {
566     width: 99%;
567     margin-top: 1px;
568 }
569 th {
570     width: 4.5em;
571 }
572 #descr {
573     height: 36px;
574 }
575 #buttons {
576     margin-top: 2px;
577     text-align: right;
578 }
579 .popup {
580     margin: 4px 4px;
581     padding: 1px;
582     position: absolute;
583     width: 114px;
584     display: none;
585     background-color: rgb(240, 240, 238);
586     border-top: 2px solid #fff;
587     border-right: 2px solid #ddd;
588     border-bottom: 2px solid #ddd;
589     border-left: 2px solid #fff;
590     text-align: center;
591 }
592 .imagewrap .popup {
593     opacity: .90;
594     filter:alpha(opacity=90);
595 }
596 .otherwrap .popup {
597     padding-top: 20px;
598 }
599 .popup a, .popup a:visited, .popup a:active {
600     background-color: transparent;
601     display: block;
602     width: 100%;
603     text-decoration: none;
604     color: #246;
605 }
606 .popup a:hover {
607     background-color: #fff;
608     color: #000;
609 }
610 .caption {
611     text-align: center;
612 }
613 #submit {
614     margin: 1px;
615     width: 99%;
616 }
617 #submit input, #submit input:focus {
618     background: url( images/fade-butt.png );
619     border: 3px double #999;
620     border-left-color: #ccc;
621     border-top-color: #ccc;
622     color: #333;
623     padding: 0.25em;
624 }
625 #submit input:active {
626     background: #f4f4f4;
627     border: 3px double #ccc;
628     border-left-color: #999;
629     border-top-color: #999;
630 }
631 .zerosize {
632     width: 0px;
633     height: 0px;
634     overflow: hidden;
635     position: absolute;
636 }
637 #links {
638     margin: 3px 8px;
639     line-height: 2em;
640 }
641 #links textarea {
642     width: 95%;
643     height: 4.5em;
644 }
645 </style>
646 </head>
647 <body>
648 <ul id="upload-menu">
649 <li<?php echo $current_1; ?>><a href="<?php echo basename(__FILE__) . "?action=upload&amp;post=$post&amp;all=$all&amp;start=$start"; ?>"><?php _e('Upload'); ?></a></li>
650 <?php if ( $attachments = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post'") ) { ?>
651 <li<?php echo $current_2; ?>><a href="<?php echo basename(__FILE__) . "?action=view&amp;post=$post&amp;all=false"; ?>"><?php _e('Browse'); ?></a></li>
652 <?php } ?>
653 <?php if ($wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_type = 'attachment'")) { ?>
654 <li<?php echo $current_3; ?>><a href="<?php echo basename(__FILE__) . "?action=view&amp;post=$post&amp;all=true"; ?>"><?php _e('Browse All'); ?></a></li>
655 <?php } ?>
656 <li> </li>
657 <?php if ( $action == 'view' ) { ?>
658 <?php if ( false !== $back ) : ?>
659 <li class="spacer"><a href="<?php echo basename(__FILE__) . "?action=$action&amp;post=$post&amp;all=$all&amp;start=0"; ?>" title="<?php _e('First'); ?>">|&laquo;</a></li>
660 <li><a href="<?php echo basename(__FILE__) . "?action=$action&amp;post=$post&amp;all=$all&amp;start=$back"; ?>">&laquo; <?php _e('Back'); ?></a></li>
661 <?php else : ?>
662 <li class="inactive spacer">|&laquo;</li>
663 <li class="inactive">&laquo; <?php _e('Back'); ?></li>
664 <?php endif; ?>
665 <?php if ( false !== $next ) : ?>
666 <li><a href="<?php echo basename(__FILE__) . "?action=$action&amp;post=$post&amp;all=$all&amp;start=$next"; ?>"><?php _e('Next &raquo;'); ?></a></li>
667 <li><a href="<?php echo basename(__FILE__) . "?action=$action&amp;post=$post&amp;all=$all&amp;last=true"; ?>" title="<?php _e('Last'); ?>">&raquo;|</a></li>
668 <?php else : ?>
669 <li class="inactive"><?php _e('Next &raquo;'); ?></li>
670 <li class="inactive">&raquo;|</li>
671 <?php endif; ?>
672 <?php } // endif not upload?>
673 </ul>
674 <?php if ( $action == 'view' ) : ?>
675 <div id="wrap">
676 <!--<div class="tip"><?php _e('You can drag and drop these items into your post. Click on one for more options.'); ?></div>-->
677 <div id="images">
678 <?php echo $html; ?>
679 <?php echo $popups; ?>
680 </div>
681 </div>
682 <?php elseif ( $action == 'upload' ) : ?>
683     <?php $upload_err = apply_filters( "pre_upload_error", false );
684     if( $upload_err != false ) {
685         ?><div class="center tip"><?php echo $upload_err ?></div><?php
686     } else { ?>
687 <div class="tip"></div>
688 <form enctype="multipart/form-data" id="uploadForm" method="POST" action="<?php echo basename(__FILE__); ?>">
689 <table style="width:99%;">
690 <tr>
691 <th scope="row" align="right"><label for="upload"><?php _e('File:'); ?></label></th>
692 <td><input type="file" id="upload" name="image" /></td>
693 </tr>
694 <tr>
695 <th scope="row" align="right"><label for="title"><?php _e('Title:'); ?></label></th>
696 <td><input type="text" id="title" name="imgtitle" /></td>
697 </tr>
698 <tr>
699 <th scope="row" align="right"><label for="descr"><?php _e('Description:'); ?></label></th>
700 <td><input type="textarea" name="descr" id="descr" value="" /></td>
701 </tr>
702 <tr id="buttons">
703 <th></th>
704 <td>
705 <input type="hidden" name="action" value="save" />
706 <input type="hidden" name="post" value="<?php echo $post; ?>" />
707 <input type="hidden" name="all" value="<?php echo $all; ?>" />
708 <input type="hidden" name="start" value="<?php echo $start; ?>" />
709 <?php wp_nonce_field( 'inlineuploading' ); ?>
710 <div id="submit">
711 <input type="submit" value="<?php _e('Upload'); ?>" />
712 <?php if ( !empty($all) ) : ?>