]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/inline-uploading.php
Wordpress 2.0.4
[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 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']) )
56         die($file['error'] . '<br /><a href="' . basename(__FILE__) . '?action=upload&post=' . $post . '">'.__('Back to Image Uploading').'</a>');
57
58 $url = $file['url'];
59 $type = $file['type'];
60 $file = $file['file'];
61 $filename = basename($file);
62
63 // Construct the attachment array
64 $attachment = array(
65         'post_title' => $imgtitle ? $imgtitle : $filename,
66         'post_content' => $descr,
67         'post_status' => 'attachment',
68         'post_parent' => $post,
69         'post_mime_type' => $type,
70         'guid' => $url
71         );
72
73 // Save the data
74 $id = wp_insert_attachment($attachment, $file, $post);
75
76 if ( preg_match('!^image/!', $attachment['post_mime_type']) ) {
77         // Generate the attachment's postmeta.
78         $imagesize = getimagesize($file);
79         $imagedata['width'] = $imagesize['0'];
80         $imagedata['height'] = $imagesize['1'];
81         list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']);
82         $imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'";
83         $imagedata['file'] = $file;
84
85         add_post_meta($id, '_wp_attachment_metadata', $imagedata);
86
87         if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) {
88                 if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 )
89                         $thumb = wp_create_thumbnail($file, 128);
90                 elseif ( $imagedata['height'] > 96 )
91                         $thumb = wp_create_thumbnail($file, 96);
92
93                 if ( @file_exists($thumb) ) {
94                         $newdata = $imagedata;
95                         $newdata['thumb'] = basename($thumb);
96                         update_post_meta($id, '_wp_attachment_metadata', $newdata, $imagedata);
97                 } else {
98                         $error = $thumb;
99                 }
100         }
101 } else {
102         add_post_meta($id, '_wp_attachment_metadata', array());
103 }
104
105 wp_redirect(basename(__FILE__) . "?post=$post&all=$all&action=view&start=0");
106 die();
107
108 case 'upload':
109
110 $current_1 = ' class="current"';
111 $back = $next = false;
112 break;
113
114 case 'view':
115
116 // How many images do we show? How many do we query?
117 $num = 5;
118 $double = $num * 2;
119
120 if ( $post && (empty($all) || $all == 'false') ) {
121         $and_post = "AND post_parent = '$post'";
122         $current_2 = ' class="current"';
123 } else {
124         $current_3 = ' class="current"';
125 }
126
127 if (! current_user_can('edit_others_posts') )
128         $and_user = "AND post_author = " . $user_ID;
129
130 if ( $last )
131         $start = $wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_status = 'attachment' $and_user $and_post") - $num;
132 else
133         $start = (int) $start;
134
135 if ( $start < 0 )
136         $start = 0;
137
138 if ( '' == $sort )
139         $sort = "post_date_gmt DESC";
140
141 $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);
142
143 if ( count($attachments) == 0 ) {
144         wp_redirect( basename(__FILE__) ."?post=$post&action=upload" );
145         die;
146 } elseif ( count($attachments) > $num ) {
147         $next = $start + count($attachments) - $num;
148 } else {
149         $next = false;
150 }
151
152 if ( $start > 0 ) {
153         $back = $start - $num;
154         if ( $back < 1 )
155                 $back = '0';
156 } else {
157         $back = false;
158 }
159
160 $uwidth_sum = 0;
161 $html = '';
162 $popups = '';
163 $style = '';
164 $script = '';
165 if ( count($attachments) > 0 ) {
166         $attachments = array_slice( $attachments, 0, $num );
167         $__delete = __('Delete');
168         $__not_linked = __('Not Linked');
169         $__linked_to_page = __('Linked to Page');
170         $__linked_to_image = __('Linked to Image');
171         $__linked_to_file = __('Linked to File');
172         $__using_thumbnail = __('Using Thumbnail');
173         $__using_original = __('Using Original');
174         $__using_title = __('Using Title');
175         $__using_filename = __('Using Filename');
176         $__using_icon = __('Using Icon');
177         $__no_thumbnail = '<del>'.__('No Thumbnail').'</del>';
178         $__send_to_editor = __('Send to editor');
179         $__close = __('Close Options');
180         $__confirmdelete = __('Delete this file from the server?');
181         $__nothumb = __('There is no thumbnail associated with this photo.');
182         $script .= "notlinked = '$__not_linked';
183 linkedtoimage = '$__linked_to_image';
184 linkedtopage = '$__linked_to_page';
185 linkedtofile = '$__linked_to_file';
186 usingthumbnail = '$__using_thumbnail';
187 usingoriginal = '$__using_original';
188 usingtitle = '$__using_title';
189 usingfilename = '$__using_filename';
190 usingicon = '$__using_icon';
191 var aa = new Array();
192 var ab = new Array();
193 var imga = new Array();
194 var imgb = new Array();
195 var srca = new Array();
196 var srcb = new Array();
197 var title = new Array();
198 var filename = new Array();
199 var icon = new Array();
200 ";
201         foreach ( $attachments as $key => $attachment ) {
202                 $ID = $attachment['ID'];
203                 $href = get_attachment_link($ID);
204                 $meta = get_post_meta($ID, '_wp_attachment_metadata', true);
205                 if (!is_array($meta)) {
206                         $meta = get_post_meta($ID, 'imagedata', true); // Try 1.6 Alpha meta key
207                         if (!is_array($meta)) {
208                                 $meta = array();
209                         }
210                         add_post_meta($ID, '_wp_attachment_metadata', $meta);
211                 }
212                 $attachment = array_merge($attachment, $meta);
213                 $noscript = "<noscript>
214                 <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>
215                 </noscript>
216 ";
217                 $send_delete_cancel = "<a onclick=\"sendToEditor({$ID});return false;\" href=\"javascript:void()\">$__send_to_editor</a>
218 <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>
219                 <a onclick=\"popup.style.display='none';return false;\" href=\"javascript:void()\">$__close</a>
220 ";
221                 $uwidth_sum += 128;
222                 if ( preg_match('!^image/!', $attachment['post_mime_type'] ) ) {
223                         $image = & $attachment;
224                         if ( ($image['width'] > 128 || $image['height'] > 96) && !empty($image['thumb']) && file_exists(dirname($image['file']).'/'.$image['thumb']) ) {
225                                 $src = str_replace(basename($image['guid']), $image['thumb'], $image['guid']);
226                                 $script .= "srca[{$ID}] = '$src';
227 srcb[{$ID}] = '{$image['guid']}';
228 ";
229                                 $thumb = 'true';
230                                 $thumbtext = $__using_thumbnail;
231                         } else {
232                                 $src = $image['guid'];
233                                 $thumb = 'false';
234                                 $thumbtext = $__no_thumbnail;
235                         }
236                         list($image['uwidth'], $image['uheight']) = get_udims($image['width'], $image['height']);
237                         $height_width = 'height="'.$image['uheight'].'" width="'.$image['uwidth'].'"';
238                         $xpadding = (128 - $image['uwidth']) / 2;
239                         $ypadding = (96 - $image['uheight']) / 2;
240                         $style .= "#target{$ID} img { padding: {$ypadding}px {$xpadding}px; }\n";
241                         $title = wp_specialchars($image['post_title'], ENT_QUOTES);
242                         $script .= "aa[{$ID}] = '<a id=\"p{$ID}\" rel=\"attachment\" class=\"imagelink\" href=\"$href\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">';
243 ab[{$ID}] = '<a class=\"imagelink\" href=\"{$image['guid']}\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">';
244 imga[{$ID}] = '<img id=\"image{$ID}\" src=\"$src\" alt=\"{$title}\" $height_width />';
245 imgb[{$ID}] = '<img id=\"image{$ID}\" src=\"{$image['guid']}\" alt=\"{$title}\" $height_width />';
246 ";
247                         $html .= "<div id='target{$ID}' class='attwrap left'>
248         <div id='div{$ID}' class='imagewrap' onclick=\"doPopup({$ID});\">
249                 <img id=\"image{$ID}\" src=\"$src\" alt=\"{$title}\" $height_width />
250         </div>
251         {$noscript}
252 </div>
253 ";
254                         $popups .= "<div id='popup{$ID}' class='popup'>
255         <a id=\"I{$ID}\" onclick=\"if($thumb)toggleImage({$ID});else alert('$__nothumb');return false;\" href=\"javascript:void()\">$thumbtext</a>
256         <a id=\"L{$ID}\" onclick=\"toggleLink({$ID});return false;\" href=\"javascript:void()\">$__not_linked</a>
257         {$send_delete_cancel}
258 </div>
259 ";
260                 } else {
261                         $title = wp_specialchars($attachment['post_title'], ENT_QUOTES);
262                         $filename = basename($attachment['guid']);
263                         $icon = get_attachment_icon($ID);
264                         $toggle_icon = "<a id=\"I{$ID}\" onclick=\"toggleOtherIcon({$ID});return false;\" href=\"javascript:void()\">$__using_title</a>";
265                         $script .= "aa[{$ID}] = '<a id=\"p{$ID}\" rel=\"attachment\" href=\"$href\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">';
266 ab[{$ID}] = '<a id=\"p{$ID}\" href=\"{$filename}\" onclick=\"doPopup({$ID});return false;\" title=\"{$title}\">';
267 title[{$ID}] = '{$title}';
268 filename[{$ID}] = '{$filename}';
269 icon[{$ID}] = '{$icon}';
270 ";
271                         $html .= "<div id='target{$ID}' class='attwrap left'>
272         <div id='div{$ID}' class='otherwrap usingtext' onmousedown=\"selectLink({$ID})\" onclick=\"doPopup({$ID});return false;\">
273                 <a id=\"p{$ID}\" href=\"{$attachment['guid']}\" onmousedown=\"selectLink({$ID});\" onclick=\"return false;\">{$title}</a>
274         </div>
275         {$noscript}
276 </div>
277 ";
278                         $popups .= "<div id='popup{$ID}' class='popup'>
279         <div class='filetype'>".__('File Type:').' '.str_replace('/',"/\n",$attachment['post_mime_type'])."</div>
280         <a id=\"L{$ID}\" onclick=\"toggleOtherLink({$ID});return false;\" href=\"javascript:void()\">$__linked_to_file</a>
281         {$toggle_icon}
282         {$send_delete_cancel}
283 </div>
284 ";
285                 }
286         }
287 }
288
289 $images_width = $uwidth_sum + ( count($images) * 6 ) + 35;
290
291 break;
292
293 default:
294 die(__('This script was not meant to be called directly.'));
295 }
296
297 ?>
298 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
299 <html xmlns="http://www.w3.org/1999/xhtml">
300 <head>
301 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_settings('blog_charset'); ?>" />
302 <title></title>
303 <meta http-equiv="imagetoolbar" content="no" />
304 <script type="text/javascript">
305 // <![CDATA[
306 /* Define any variables we'll need, such as alternate URLs. */
307 <?php echo $script; ?>
308 function htmldecode(st) {
309         o = document.getElementById('htmldecode');
310         if (! o) {
311                 o = document.createElement("A");
312                 o.id = "htmldecode"
313         }
314         o.innerHTML = st;
315         r = o.innerHTML;
316         return r;
317 }
318 function cancelUpload() {
319         o = document.getElementById('uploadForm');
320         o.method = 'GET';
321         o.action.value = 'view';
322         o.submit();
323 }
324 function doPopup(i) {
325         if ( popup )
326         popup.style.display = 'none';
327         target = document.getElementById('target'+i);
328         popup = document.getElementById('popup'+i);
329         popup.style.left = (target.offsetLeft) + 'px';
330         popup.style.top = (target.offsetTop) + 'px';
331         popup.style.display = 'block';
332 }
333 popup = false;
334 function selectLink(n) {
335         o=document.getElementById('div'+n);
336         if ( typeof document.body.createTextRange == 'undefined' || typeof win.tinyMCE == 'undefined' || win.tinyMCE.configs.length < 1 )
337                 return;
338         r = document.body.createTextRange();
339         if ( typeof r != 'undefined' ) {
340                 r.moveToElementText(o);
341                 r.select();
342         }
343 }
344 function toggleLink(n) {
345         ol=document.getElementById('L'+n);
346         if ( ol.innerHTML == htmldecode(notlinked) ) {
347                 ol.innerHTML = linkedtoimage;
348         } else if ( ol.innerHTML == htmldecode(linkedtoimage) ) {
349                 ol.innerHTML = linkedtopage;
350         } else {
351                 ol.innerHTML = notlinked;
352         }
353         updateImage(n);
354 }
355 function toggleOtherLink(n) {
356         ol=document.getElementById('L'+n);
357         if ( ol.innerHTML == htmldecode(linkedtofile) ) {
358                 ol.innerHTML = linkedtopage;
359         } else {
360                 ol.innerHTML = linkedtofile;
361         }
362         updateOtherIcon(n);
363 }
364 function toggleImage(n) {
365         oi = document.getElementById('I'+n);
366         if ( oi.innerHTML == htmldecode(usingthumbnail) ) {
367                 oi.innerHTML = usingoriginal;
368         } else {
369                 oi.innerHTML = usingthumbnail;
370         }
371         updateImage(n);
372 }
373 function toggleOtherIcon(n) {
374         od = document.getElementById('div'+n);
375         oi = document.getElementById('I'+n);
376         if ( oi.innerHTML == htmldecode(usingtitle) ) {
377                 oi.innerHTML = usingfilename;
378                 od.className = 'otherwrap usingtext';
379         } else if ( oi.innerHTML == htmldecode(usingfilename) && icon[n] != '' ) {
380                 oi.innerHTML = usingicon;
381                 od.className = 'otherwrap usingicon';
382         } else {
383                 oi.innerHTML = usingtitle;
384                 od.className = 'otherwrap usingtext';
385         }
386         updateOtherIcon(n);
387 }
388 function updateImage(n) {
389         od=document.getElementById('div'+n);
390         ol=document.getElementById('L'+n);
391         oi=document.getElementById('I'+n);
392         if ( oi.innerHTML == htmldecode(usingthumbnail) ) {
393                 img = imga[n];
394         } else {
395                 img = imgb[n];
396         }
397         if ( ol.innerHTML == htmldecode(linkedtoimage) ) {
398                 od.innerHTML = ab[n]+img+'</a>';
399         } else if ( ol.innerHTML == htmldecode(linkedtopage) ) {
400                 od.innerHTML = aa[n]+img+'</a>';
401         } else {
402                 od.innerHTML = img;
403         }
404 }
405 function updateOtherIcon(n) {
406         od=document.getElementById('div'+n);
407         ol=document.getElementById('L'+n);
408         oi=document.getElementById('I'+n);
409         if ( oi.innerHTML == htmldecode(usingfilename) ) {
410                 txt = filename[n];
411         } else if ( oi.innerHTML == htmldecode(usingicon) ) {
412                 txt = icon[n];
413         } else {
414                 txt = title[n];
415         }
416         if ( ol.innerHTML == htmldecode(linkedtofile) ) {
417                 od.innerHTML = ab[n]+txt+'</a>';
418         } else if ( ol.innerHTML == htmldecode(linkedtopage) ) {
419                 od.innerHTML = aa[n]+txt+'</a>';
420         } else {
421                 od.innerHTML = txt;
422         }
423 }
424
425 var win = window.opener ? window.opener : window.dialogArguments;
426 if (!win) win = top;
427 tinyMCE = win.tinyMCE;
428 richedit = ( typeof tinyMCE == 'object' && tinyMCE.configs.length > 0 );
429 function sendToEditor(n) {
430         o = document.getElementById('div'+n);
431         h = o.innerHTML.replace(new RegExp('^\\s*(.*?)\\s*$', ''), '$1'); // Trim
432         h = h.replace(new RegExp(' (class|title|width|height|id|onclick|onmousedown)=([^\'"][^ ]*)( |/|>)', 'g'), ' $1="$2"$3'); // Enclose attribs in quotes
433         h = h.replace(new RegExp(' (width|height)=".*?"', 'g'), ''); // Drop size constraints
434         h = h.replace(new RegExp(' on(click|mousedown)="[^"]*"', 'g'), ''); // Drop menu events
435         h = h.replace(new RegExp('<(/?)A', 'g'), '<$1a'); // Lowercase tagnames
436         h = h.replace(new RegExp('<IMG', 'g'), '<img'); // Lowercase again
437         h = h.replace(new RegExp('(<img .+?")>', 'g'), '$1 />'); // XHTML
438         if ( richedit )
439                 win.tinyMCE.execCommand('mceInsertContent', false, h);
440         else
441                 win.edInsertContent(win.edCanvas, h);
442 }
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_status = '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 <div class="tip"></div>
684 <form enctype="multipart/form-data" id="uploadForm" method="post" action="<?php echo basename(__FILE__); ?>">
685 <table style="width:99%;">
686 <tr>
687 <th scope="row" align="right"><label for="upload"><?php _e('File:'); ?></label></th>
688 <td><input type="file" id="upload" name="image" /></td>
689 </tr>
690 <tr>
691 <th scope="row" align="right"><label for="title"><?php _e('Title:'); ?></label></th>
692 <td><input type="text" id="title" name="imgtitle" /></td>
693 </tr>
694 <tr>
695 <th scope="row" align="right"><label for="descr"><?php _e('Description:'); ?></label></th>
696 <td><input type="textarea" name="descr" id="descr" value="" /></td>
697 </tr>
698 <tr id="buttons">
699 <th></th>
700 <td>
701 <input type="hidden" name="action" value="save" />
702 <input type="hidden" name="post" value="<?php echo $post; ?>" />
703 <input type="hidden" name="all" value="<?php echo $all; ?>" />
704 <input type="hidden" name="start" value="<?php echo $start; ?>" />
705 <?php wp_nonce_field( 'inlineuploading' ); ?>
706 <div id="submit">
707 <input type="submit" value="<?php _e('Upload'); ?>" />
708 <?php if ( !empty($all) ) : ?>
709 <input type="button" value="<?php _e('Cancel'); ?>" onclick="cancelUpload()" />
710 <?php endif; ?>
711 </div>
712 </td>
713 </tr>
714 </table>
715 </form>
716 <?php elseif ( $action == 'links' ) : ?>
717 <div id="links">
718 <?php the_attachment_links($attachment); ?>
719 </div>
720 <?php endif; ?>
721 </body>
722 </html>