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