Make WordPress Core

Ticket #1718: im.diff

File im.diff, 15.8 KB (added by skeltoac, 21 years ago)

svn diff

  • wp-admin.css

     
    148148        line-height: 130%;
    149149}
    150150
    151 textarea, input, select, iframe#imageup {
     151textarea, input, select {
    152152        background: #f4f4f4;
    153153        border: 1px solid #b2b2b2;
    154154        color: #000;
     
    157157        padding: 3px;
    158158}
    159159
    160 iframe#imageup {
    161         margin: 0px;
     160#imageup {
     161        border-style: none;
    162162        padding: 0px;
    163         border: 1px solid #ccc;
    164         height: 13em;
    165         width: 98%;
     163        margin-bottom: 16px;
     164        height: 180px;
     165        width: 100%;
     166        overflow-y: hidden;
    166167}
    167168
    168169.alignleft {
  • edit-form-advanced.php

     
    172172
    173173<?php do_action('edit_form_advanced'); ?>
    174174
     175<iframe border="0" src="image-uploading.php?action=view&amp;post=<?php echo 0 == $post_ID ? $temp_ID : $post_ID; ?>" id="imageup">This feature requires iframe support.</iframe>
     176
    175177<div id="advancedstuff" class="dbx-group" >
    176178
    177 <fieldset id="imageuploading" class="dbx-box">
    178 <h3 class="dbx-handle"><?php _e('Image Uploading') ?></h3>
    179 <div class="dbx-content"><iframe src="image-uploading.php?action=view&amp;post=<?php echo 0 == $post_ID ? $temp_ID : $post_ID; ?>" id="imageup"></iframe></div>
    180 </fieldset>
    181 
    182179<fieldset id="postexcerpt" class="dbx-box">
    183180<h3 class="dbx-handle"><?php _e('Optional Excerpt') ?></h3>
    184181<div class="dbx-content"><textarea rows="1" cols="40" name="excerpt" tabindex="7" id="excerpt"><?php echo $post->post_excerpt ?></textarea></div>
  • image-uploading.php

     
    11<?php
     2
    23require_once('admin.php');
    34
    45if (!current_user_can('edit_posts'))
     
    2223}
    2324
    2425$post = (int) $post;
     26$images_width = 1;
    2527
     28function get_udims($width, $height) {
     29        if ( $height < 96 && $width < 128 )
     30                return array($width, $height);
     31        elseif ( $width / $height > 4 / 3 )
     32                return array(128, (int) ($height / $width * 128));
     33        else
     34                return array((int) ($width / $height * 96), 96);
     35}
     36
    2637switch($action) {
    2738case 'save':
    2839
     
    113124$imagesize = getimagesize($file);
    114125$imagedata['width'] = $imagesize['0'];
    115126$imagedata['height'] = $imagesize['1'];
    116 if ( $imagedata['height'] < 96 && $imagedata['width'] < 128 ) {
    117         $uheight = $imagedata['height'];
    118         $uwidth = $imagedata['width'];
    119 } elseif ( $imagedata['width'] / $imagedata['height'] > 4 / 3 ) {
    120         $uwidth = 128;
    121         $uheight = $imagedata['height'] / $imagedata['width'] * $uwidth;
    122 } else {
    123         $uheight = 96;
    124         $uwidth = $imagedata['width'] / $imagedata['height'] * $uheight;
    125 }
     127list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']);
    126128$imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'";
    127129$imagedata['file'] = $file;
    128130
     
    133135die;
    134136
    135137case 'upload':
    136 ?>
    137 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    138 <html xmlns="http://www.w3.org/1999/xhtml">
    139         <head>
    140                 <script type="text/javascript">
    141                         function validateImageName() {
    142                                 /* This is more for convenience than security. Server-side validation is very thorough.*/
    143                                 obj = document.getElementById('upload');
    144                                 r = /.jpg$|.gif$|.png$/i;
    145                                 if ( obj.value.match(r) )
    146                                         return true;
    147                                 alert('Please select a JPG, PNG or GIF file.');
    148                                 obj.parentNode.reset();
    149                                 return false;
    150                         }
    151                         function cancelUpload() {
    152                                 o = document.getElementById('uploadForm');
    153                                 o.method = 'GET';
    154                                 o.action.value = 'view';
    155                                 o.submit();
    156                         }
    157                 </script>
    158                 <style type="text/css">
    159                         label {
    160                                 float: left;
    161                                 width: 18%;
    162                         }
    163                         #title, #descr {
    164                                 width: 80%;
    165                                 margin-top: 2px;
    166                         }
    167                         #descr {
    168                                 height: 3em;
    169                                 v-align: top;
    170                         }
    171                         #buttons {
    172                                 width: 98%;
    173                                 text-align: right;
    174                         }
    175                 </style>
    176         </head>
    177         <body>
    178                 <form enctype="multipart/form-data" id="uploadForm" method="POST" action="image-uploading.php" onsubmit="return validateImageName()">
    179                         <label for="upload">Image:</label><input type="file" id="upload" name="image" onchange="validateImageName()" /><br />
    180                         <label for="title">Title:</label><input type="text" id="title" name="imgtitle" /><br />
    181                         <label for="descr">Description:</label><input type="textarea" name="descr" id="descr" value="" /><br />
    182                         <input type="hidden" name="action" value="save" />
    183                         <input type="hidden" name="post" value="<?php echo $post; ?>" />
    184                         <input type="hidden" name="all" value="<?php echo $all; ?>" />
    185                         <div id="buttons">
    186                                 <input type="submit" value="Upload" />
    187                                 <input type="button" value="Cancel" onclick="cancelUpload()" />
    188                         </div>
    189                 </form>
    190         </body>
    191 </html>
    192 <?php
    193138
     139$current_1 = ' class="current"';
     140$back = $next = false;
    194141break;
    195142
    196143case 'view':
    197144
    198 if ( $post && empty($all) )
     145// How many images do we show? How many do we query?
     146$num = 5;
     147$double = $num * 2;
     148
     149if ( $post && empty($all) ) {
    199150        $and_post = "AND post_parent = '$post'";
     151        $current_2 = ' class="current"';
     152} else {
     153        $current_3 = ' class="current"';
     154}
    200155
    201156if ( $last )
    202         $start = $wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_status = 'object' AND left(post_type, 5) = 'image' $and_post") - 5;
     157        $start = $wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_status = 'object' AND left(post_type, 5) = 'image' $and_post") - $num;
    203158else
    204159        $start = (int) $start;
    205160
     
    209164if ( '' == $sort )
    210165        $sort = "ID";
    211166
    212 $images = $wpdb->get_results("SELECT ID, post_date, post_title, guid FROM $wpdb->posts WHERE post_status = 'object' AND left(post_type, 5) = 'image' $and_post ORDER BY $sort LIMIT $start, 10", ARRAY_A);
     167$images = $wpdb->get_results("SELECT ID, post_date, post_title, guid FROM $wpdb->posts WHERE post_status = 'object' AND left(post_type, 5) = 'image' $and_post ORDER BY $sort LIMIT $start, $double", ARRAY_A);
    213168
    214 //if ( count($images) == 0 )
    215 //      header("Location: ".basename(__FILE__)."?post=$post&all=$all&action=upload");
    216 
    217 if ( count($images) > 5 ) {
    218         $next = $start + count($images) - 5;
     169if ( count($images) > $num ) {
     170        $next = $start + count($images) - $num;
    219171} else {
    220172        $next = false;
    221173}
    222174
    223175if ( $start > 0 ) {
    224         $back = $start - 5;
     176        $back = $start - $num;
    225177        if ( $back < 1 )
    226178                $back = '0';
    227179} else {
    228180        $back = false;
    229181}
    230182
     183$uwidth_sum = 0;
     184$images_html = '';
     185if ( count($images) > 0 ) {
     186        $images = array_slice( $images, 0, $num );
     187        foreach ( $images as $key => $image ) {
     188                $image = array_merge($image, get_post_meta($image['ID'], 'imagedata', true) );
     189                list($image['uwidth'], $image['uheight']) = get_udims($image['width'], $image['height']);
     190                $uwidth_sum += $image['uwidth'];
     191                $images_html .= "<div class='image left'><a href='{$image['guid']}' onclick='return false;' title='{$image['post_title']}'><img src='{$image['guid']}' alt='{$image['post_title']}' {$image['hwstring_small']} /></a></div>\n";
     192        }
     193}
     194
     195$images_width = $uwidth_sum + ( count($images) * 5 ) + 15;
     196
     197break;
     198
     199default:
     200die('This script was not meant to be called directly.');
     201}
     202
    231203?>
    232204<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    233205<html xmlns="http://www.w3.org/1999/xhtml">
    234206<head>
    235         <style type="text/css">
    236                 form {
    237                         display: inline;
    238                 }
    239                 #images, #buttons {
    240                         position: absolute;
    241                         left: 0px;
    242                         width: 98%;
    243                         text-align: center;
    244                 }
    245                 #images {
    246                         top: 0px;
    247                 }
    248                 #buttons {
    249                         top: 112px;
    250                 }
    251         </style>
     207<meta http-equiv="imagetoolbar" content="no" />
     208<script type="text/javascript">
     209function validateImageName() {
     210/* This is more for convenience than security. Server-side validation is very thorough.*/
     211obj = document.getElementById('upload');
     212r = /.jpg$|.gif$|.png$/i;
     213if ( obj.value.match(r) )
     214return true;
     215alert('Please select a JPG, PNG or GIF file.');
     216return false;
     217}
     218function cancelUpload() {
     219o = document.getElementById('uploadForm');
     220o.method = 'GET';
     221o.action.value = 'view';
     222o.submit();
     223}
     224</script>
     225<style type="text/css">
     226body {
     227font: 13px "Lucida Grande", "Lucida Sans Unicode", Tahoma, Verdana;
     228border: none;
     229margin: 0px;
     230height: 150px;
     231background: rgb(223, 232, 241);
     232}
     233form {
     234margin: 6px 2px 0px 6px;
     235}
     236#wrap {
     237clear: both;
     238margin: 0px;
     239padding: 0px;
     240height: 133px;
     241width: 100%;
     242overflow: auto;
     243}
     244#images {
     245clear: both;
     246margin: 0px;
     247padding: 5px 5px;
     248height: 100px;
     249width: <?php echo $images_width; ?>px;
     250}
     251.image {
     252margin-right: 5px;
     253}
     254.image * {
     255margin: 0px;
     256padding: 0px;
     257border: 0px;
     258}
     259.image a, .image a img, .image a:hover img, .image a:visited img, .image a:active img {
     260text-decoration: none;
     261float: left;
     262display: block;
     263text-align: center;
     264}
     265#menu {
     266margin: 0px;
     267list-style: none;
     268background: rgb(109, 166, 209);
     269padding: 4px 0px 0px 8px;
     270text-align: left;
     271border-bottom: 3px solid rgb(68, 138, 189);
     272}
     273#menu li {
     274display: inline;
     275margin: 0px;
     276}
     277#menu a, #menu a:visited, #menu a:active {
     278padding: 1px 3px 3px;
     279text-decoration: none;
     280color: #345;
     281background: transparent;
     282}
     283#menu a:hover {
     284background: rgb(203, 214, 228);
     285color: #000;
     286}
     287#menu .current a, #menu .current a:hover, #menu .current a:visited, #menu .current a:active {
     288background: rgb(223, 232, 241);
     289color: #000;
     290border-right: 2px solid rgb(20, 86, 138);
     291}
     292.tip {
     293color: rgb(109, 166, 209);
     294padding: 1px 3px;
     295}
     296.inactive {
     297color: #68a;
     298padding: 1px 3px;
     299}
     300.left {
     301float: left;
     302}
     303.right {
     304float: right;
     305}
     306.center {
     307text-align: center;
     308}
     309#menu li.spacer {
     310margin-left: 40px;
     311}
     312label {
     313float: left;
     314width: 18%;
     315}
     316#title, #descr {
     317width: 80%;
     318margin-top: 2px;
     319}
     320#descr {
     321height: 35px;
     322v-align: top;
     323}
     324#buttons {
     325width: 98%;
     326margin-top: 2px;
     327text-align: right;
     328}
     329</style>
    252330</head>
    253331<body>
    254         <div id="images">
    255 <?php
    256 if ( count($images) > 0 ) {
    257         $imagerow = '';
    258         $i = 1;
    259         foreach ( $images as $image ) {
    260                 if ( $i++ > 5 ) break;
    261                 $image = array_merge($image, get_post_meta($image['ID'], 'imagedata', true) );
    262 ?>
    263         <a href="<?php echo $image['guid']; ?>" disabled="true">
    264                 <img src="<?php echo $image['guid']; ?>" alt="<?php echo $image['post_title']; ?>" <?php echo $image['hwstring_small']; ?> />
    265         </a>
    266 <?php
    267         }
    268 }
    269 ?>
    270         <div>
    271         <div id="buttons">
    272         <form action="image-uploading.php" method="GET">
    273                 <input type="hidden" name="action" value="view" />
    274                 <input type="hidden" name="all" value="<?php echo $all; ?>" />
    275                 <input type="hidden" name="post" value="<?php echo $post; ?>" />
    276                 <input type="hidden" name="start" value="0" />
    277                 <input type="submit" value="| < <" <?php if ( false === $back ) echo 'disabled="true" ' ?>/>
    278         </form>
    279         <form action="image-uploading.php" method="GET">
    280                 <input type="hidden" name="action" value="view" />
    281                 <input type="hidden" name="all" value="<?php echo $all; ?>" />
    282                 <input type="hidden" name="post" value="<?php echo $post; ?>" />
    283                 <input type="hidden" name="start" value="<?php echo $back; ?>" />
    284                 <input type="submit" value="< < < < <" <?php if ( false === $back ) echo 'disabled="true" ' ?>/>
    285         </form>
    286         <form action="image-uploading.php" method="GET">
    287                 <input type="hidden" name="action" value="upload" />
    288                 <input type="hidden" name="all" value="<?php echo $all; ?>" />
    289                 <input type="hidden" name="post" value="<?php echo $post; ?>" />
    290                 <input type="submit" value="Upload New" />
    291         </form>
    292 <?php if ( $all ) : ?>
    293         <form action="image-uploading.php" method="GET">
    294                 <input type="hidden" name="action" value="view" />
    295                 <input type="hidden" name="all" value="" />
    296                 <input type="hidden" name="post" value="<?php echo $post; ?>" />
    297                 <input type="submit" value="Browse Attached" />
    298         </form>
     332<ul id="menu">
     333<li<?php echo $current_1; ?>><a href="image-uploading.php?action=upload&amp;post=<?php echo $post; ?>&amp;all=<?php echo $all; ?>">Upload Photo</a></li>
     334<li<?php echo $current_2; ?>><a href="image-uploading.php?action=view&amp;post=<?php echo $post; ?>">Browse Attached</a></li>
     335<li<?php echo $current_3; ?>><a href="image-uploading.php?action=view&amp;post=<?php echo $post; ?>&amp;all=true">Browse All</a></li>
     336<li> </li>
     337<?php if ( false !== $back ) : ?>
     338<li class="spacer"><a href="image-uploading.php?action=view&amp;post=<?php echo $post; ?>&amp;all=<?php echo $all; ?>&amp;start=0" title="First">|&lt;</a></li>
     339<li><a href="image-uploading.php?action=view&amp;post=<?php echo $post; ?>&amp;all=<?php echo $all; ?>&amp;start=<?php echo $back; ?>" title="Back">&lt;&lt;</a></li>
    299340<?php else : ?>
    300         <form action="image-uploading.php" method="GET">
    301                 <input type="hidden" name="action" value="view" />
    302                 <input type="hidden" name="all" value="true" />
    303                 <input type="hidden" name="post" value="<?php echo $post; ?>" />
    304                 <input type="submit" value="Browse All" />
    305         </form>
     341<li class="inactive spacer">|&lt;</li>
     342<li class="inactive">&lt;&lt;</li>
    306343<?php endif; ?>
    307         <form action="image-uploading.php" method="GET">
    308                 <input type="hidden" name="action" value="view" />
    309                 <input type="hidden" name="all" value="<?php echo $all; ?>" />
    310                 <input type="hidden" name="post" value="<?php echo $post; ?>" />
    311                 <input type="hidden" name="start" value="<?php echo $next; ?>" />
    312                 <input type="submit" value="> > > > >" <?php if ( false === $next ) echo 'disabled="true" ' ?>/>
    313         </form>
    314         <form action="image-uploading.php" method="GET">
    315                 <input type="hidden" name="action" value="view" />
    316                 <input type="hidden" name="all" value="<?php echo $all; ?>" />
    317                 <input type="hidden" name="post" value="<?php echo $post; ?>" />
    318                 <input type="hidden" name="last" value="true" />
    319                 <input type="submit" value="> > |" <?php if ( false === $next ) echo 'disabled="true" ' ?>/>
    320         </form>
    321         </div>
    322 <?php // echo "<pre>".print_r($images,1)."</pre>";
    323 ?>
     344<?php if ( false !== $next ) : ?>
     345<li><a href="image-uploading.php?action=view&amp;post=<?php echo $post; ?>&amp;all=<?php echo $all; ?>&amp;start=<?php echo $next; ?>" title="Next">&gt;&gt;</a></li>
     346<li><a href="image-uploading.php?action=view&amp;post=<?php echo $post; ?>&amp;all=<?php echo $all; ?>&amp;last=true" title="Last">&gt;|</a></li>
     347<?php else : ?>
     348<li class="inactive">&gt;&gt;</li>
     349<li class="inactive">&gt;|</li>
     350<?php endif; ?>
     351</ul>
     352<?php if ( $action == 'view' ) : ?>
     353<span class="left tip">Drag and drop photos to post</span>
     354<span class="right tip">Click photos for more options</span>
     355<div id="wrap">
     356<div id="images">
     357<?php echo $images_html; ?>
     358</div>
     359</div>
     360<?php elseif ( $action = 'upload' ) : ?>
     361<div class="center tip">Duplicated filenames will be numbered (photo.jpg, photo1.jpg, etc.)</div>
     362<form enctype="multipart/form-data" id="uploadForm" method="POST" action="image-uploading.php" onsubmit="return validateImageName()">
     363<label for="upload">Image:</label><input type="file" id="upload" name="image" onchange="validateImageName()" />
     364<label for="title">Title:</label><input type="text" id="title" name="imgtitle" />
     365<label for="descr">Description:</label><input type="textarea" name="descr" id="descr" value="" />
     366<input type="hidden" name="action" value="save" />
     367<input type="hidden" name="post" value="<?php echo $post; ?>" />
     368<input type="hidden" name="all" value="<?php echo $all; ?>" />
     369<div id="buttons">
     370<input type="submit" value="Upload" />
     371<input type="button" value="Cancel" onclick="cancelUpload()" />
     372</div>
     373</form>
     374<?php endif; ?>
    324375</body>
    325376</html>
    326 <?php
    327 die;
    328 
    329 default:
    330 die('This script was not meant to be called directly.');
    331 }
    332 ?>