| 1 | | <?php |
| 2 | | |
| 3 | | require_once('admin.php'); |
| 4 | | |
| 5 | | if (!current_user_can('edit_posts')) |
| 6 | | die(__('You do not have permission to edit posts.')); |
| 7 | | |
| 8 | | $wpvarstoreset = array('action', 'post', 'all', 'last', 'link', 'sort', 'start', 'imgtitle', 'descr', 'object'); |
| 9 | | |
| 10 | | for ($i=0; $i<count($wpvarstoreset); $i += 1) { |
| 11 | | $wpvar = $wpvarstoreset[$i]; |
| 12 | | if (!isset($$wpvar)) { |
| 13 | | if (empty($_POST["$wpvar"])) { |
| 14 | | if (empty($_GET["$wpvar"])) { |
| 15 | | $$wpvar = ''; |
| 16 | | } else { |
| 17 | | $$wpvar = $_GET["$wpvar"]; |
| 18 | | } |
| 19 | | } else { |
| 20 | | $$wpvar = $_POST["$wpvar"]; |
| 21 | | } |
| 22 | | } |
| 23 | | } |
| 24 | | |
| 25 | | $post = (int) $post; |
| 26 | | $images_width = 1; |
| 27 | | |
| 28 | | function 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 | | |
| 37 | | switch($action) { |
| 38 | | case 'delete': |
| 39 | | |
| 40 | | wp_delete_object($object); |
| 41 | | |
| 42 | | header("Location: ".basename(__FILE__)."?post=$post&all=$all&action=view&start=$start"); |
| 43 | | die; |
| 44 | | |
| 45 | | case 'save': |
| 46 | | |
| 47 | | // Define acceptable image extentions/types here. Tests will apply strtolower(). |
| 48 | | $exts = array('gif' => IMAGETYPE_GIF, 'jpg' => IMAGETYPE_JPEG, 'png' => IMAGETYPE_PNG); |
| 49 | | |
| 50 | | // Define the error messages for bad uploads. |
| 51 | | $upload_err = array(false, |
| 52 | | __("The uploaded file exceeds the <code>upload_max_filesize</code> directive in <code>php.ini</code>."), |
| 53 | | __("The uploaded file exceeds the <em>MAX_FILE_SIZE</em> directive that was specified in the HTML form."), |
| 54 | | __("The uploaded file was only partially uploaded."), |
| 55 | | __("No file was uploaded."), |
| 56 | | __("Missing a temporary folder."), |
| 57 | | __("Failed to write file to disk.")); |
| 58 | | |
| 59 | | $iuerror = false; |
| 60 | | |
| 61 | | // Failing any single one of the following tests is fatal. |
| 62 | | |
| 63 | | // A correct form post will pass this test. |
| 64 | | if ( !isset($_POST['action']) || $_POST['action'] != 'save' || count($_FILES) != 1 || ! isset($_FILES['image']) || is_array($_FILES['image']['name']) ) |
| 65 | | $error = __('Invalid form submission. Only submit approved forms.'); |
| 66 | | |
| 67 | | // A successful upload will pass this test. |
| 68 | | elseif ( $_FILES['image']['error'] > 0 ) |
| 69 | | $error = $upload_err[$_FILES['image']['error']]; |
| 70 | | |
| 71 | | // A non-empty file will pass this test. |
| 72 | | elseif ( 0 == $_FILES['image']['size'] ) |
| 73 | | $error = __('File is empty. Please upload something more substantial.'); |
| 74 | | |
| 75 | | // A correct MIME category will pass this test. Full types are not consistent across browsers. |
| 76 | | elseif ( ! 'image/' == substr($_FILES['image']['type'], 0, 6) ) |
| 77 | | $error = __('Bad MIME type submitted by your browser.'); |
| 78 | | |
| 79 | | // An acceptable file extension will pass this test. |
| 80 | | elseif ( ! ( ( 0 !== preg_match('#\.?([^\.]*)$#', $_FILES['image']['name'], $matches) ) && ( $ext = strtolower($matches[1]) ) && array_key_exists($ext, $exts) ) ) |
| 81 | | $error = __('Bad file extension.'); |
| 82 | | |
| 83 | | // A valid uploaded file will pass this test. |
| 84 | | elseif ( ! is_uploaded_file($_FILES['image']['tmp_name']) ) |
| 85 | | $error = __('Bad temp file. Try renaming the file and uploading again.'); |
| 86 | | |
| 87 | | // A valid image file will pass this test. |
| 88 | | elseif ( function_exists('exif_imagetype') && $exts[$ext] != $imagetype = exif_imagetype($_FILES['image']['tmp_name']) ) |
| 89 | | $error = __('Bad image file. Try again, or try recreating it.'); |
| 90 | | |
| 91 | | // An image with at least one pixel will pass this test. |
| 92 | | elseif ( ! ( ( $imagesize = getimagesize($_FILES['image']['tmp_name']) ) && $imagesize[0] > 1 && $imagesize[1] > 1 ) ) |
| 93 | | $error = __('The image has no pixels. Isn\'t that odd?'); |
| 94 | | |
| 95 | | // A writable uploads dir will pass this test. |
| 96 | | elseif ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) |
| 97 | | $error = $uploads['error']; |
| 98 | | |
| 99 | | if ( $error ) |
| 100 | | // Something wasn't right. Abort and never touch the temp file again. |
| 101 | | die("$error <a href='".basename(__FILE__)."?action=upload&post=$post'>Back to Image Uploading</a>"); |
| 102 | | |
| 103 | | // Increment the file number until we have a unique file to save in $dir |
| 104 | | $number = ''; |
| 105 | | $filename = $_FILES['image']['name']; |
| 106 | | while ( file_exists($uploads['path'] . "/$filename") ) |
| 107 | | $filename = str_replace("$number.$ext", ++$number . ".$ext", $filename); |
| 108 | | |
| 109 | | // Move the file to the uploads dir |
| 110 | | $file = $uploads['path'] . "/$filename"; |
| 111 | | if ( false === move_uploaded_file($_FILES['image']['tmp_name'], $file) ) |
| 112 | | die('The uploaded file could not be moved to $file.'); |
| 113 | | chmod($file, 0666); // FIXME: Need to set this according to rw bits on parent dir. |
| 114 | | |
| 115 | | // Compute the URL |
| 116 | | $url = $uploads['url'] . "/$filename"; |
| 117 | | |
| 118 | | // Construct the object array |
| 119 | | $object = array( |
| 120 | | 'post_title' => $imgtitle ? $imgtitle : $filename, |
| 121 | | 'post_content' => $descr, |
| 122 | | 'post_status' => 'object', |
| 123 | | 'post_parent' => $post, |
| 124 | | 'post_type' => $_FILES['image']['type'], |
| 125 | | 'guid' => $url |
| 126 | | ); |
| 127 | | |
| 128 | | // Save the data |
| 129 | | $id = wp_attach_object($object, $post); |
| 130 | | |
| 131 | | // Generate the object's postmeta. |
| 132 | | $imagesize = getimagesize($file); |
| 133 | | $imagedata['width'] = $imagesize['0']; |
| 134 | | $imagedata['height'] = $imagesize['1']; |
| 135 | | list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']); |
| 136 | | $imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'"; |
| 137 | | $imagedata['file'] = $file; |
| 138 | | $imagedata['thumb'] = "thumb-$filename"; |
| 139 | | |
| 140 | | add_post_meta($id, 'imagedata', $imagedata); |
| 141 | | |
| 142 | | if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) { |
| 143 | | if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 ) |
| 144 | | $error = wp_create_thumbnail($file, 128); |
| 145 | | elseif ( $imagedata['height'] > 96 ) |
| 146 | | $error = wp_create_thumbnail($file, 96); |
| 147 | | } |
| 148 | | |
| 149 | | header("Location: ".basename(__FILE__)."?post=$post&all=$all&action=view&last=true"); |
| 150 | | die; |
| 151 | | |
| 152 | | case 'upload': |
| 153 | | |
| 154 | | $current_1 = ' class="current"'; |
| 155 | | $back = $next = false; |
| 156 | | break; |
| 157 | | |
| 158 | | case 'view': |
| 159 | | |
| 160 | | // How many images do we show? How many do we query? |
| 161 | | $num = 5; |
| 162 | | $double = $num * 2; |
| 163 | | |
| 164 | | if ( $post && empty($all) ) { |
| 165 | | $and_post = "AND post_parent = '$post'"; |
| 166 | | $current_2 = ' class="current"'; |
| 167 | | } else { |
| 168 | | $current_3 = ' class="current"'; |
| 169 | | } |
| 170 | | |
| 171 | | if ( $last ) |
| 172 | | $start = $wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_status = 'object' AND left(post_type, 5) = 'image' $and_post") - $num; |
| 173 | | else |
| 174 | | $start = (int) $start; |
| 175 | | |
| 176 | | if ( $start < 0 ) |
| 177 | | $start = 0; |
| 178 | | |
| 179 | | if ( '' == $sort ) |
| 180 | | $sort = "ID"; |
| 181 | | |
| 182 | | $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); |
| 183 | | |
| 184 | | if ( count($images) > $num ) { |
| 185 | | $next = $start + count($images) - $num; |
| 186 | | } else { |
| 187 | | $next = false; |
| 188 | | } |
| 189 | | |
| 190 | | if ( $start > 0 ) { |
| 191 | | $back = $start - $num; |
| 192 | | if ( $back < 1 ) |
| 193 | | $back = '0'; |
| 194 | | } else { |
| 195 | | $back = false; |
| 196 | | } |
| 197 | | |
| 198 | | $i = 0; |
| 199 | | $uwidth_sum = 0; |
| 200 | | $images_html = ''; |
| 201 | | $images_style = ''; |
| 202 | | $images_script = ''; |
| 203 | | if ( count($images) > 0 ) { |
| 204 | | $images = array_slice( $images, 0, $num ); |
| 205 | | $__delete = __('DELETE'); |
| 206 | | $__subpost_on = __('SUBPOST <strong>ON</strong>'); |
| 207 | | $__subpost_off = __('SUBPOST <strong>OFF</strong>'); |
| 208 | | $__thumbnail_on = __('THUMBNAIL <strong>ON</strong>'); |
| 209 | | $__thumbnail_off = __('THUMBNAIL <strong>OFF</strong>'); |
| 210 | | $__no_thumbnail = __('<del>THUMBNAIL</del>'); |
| 211 | | $__close = __('CLOSE'); |
| 212 | | $__confirmdelete = __('Delete this photo from the server?'); |
| 213 | | $__nothumb = __('There is no thumbnail associated with this photo.'); |
| 214 | | $images_script .= "subposton = '$__subpost_on';\nsubpostoff = '$__subpost_off';\n"; |
| 215 | | $images_script .= "thumbnailon = '$__thumbnail_on';\nthumbnailoff = '$__thumbnail_off';\n"; |
| 216 | | foreach ( $images as $key => $image ) { |
| 217 | | $meta = get_post_meta($image['ID'], 'imagedata', true); |
| 218 | | if (!is_array($meta)) { |
| 219 | | wp_delete_object($image['ID']); |
| 220 | | continue; |
| 221 | | } |
| 222 | | $image = array_merge($image, $meta); |
| 223 | | if ( ($image['width'] > 128 || $image['height'] > 96) && !empty($image['thumb']) && file_exists(dirname($image['file']).'/'.$image['thumb']) ) { |
| 224 | | $src = str_replace(basename($image['guid']), '', $image['guid']) . $image['thumb']; |
| 225 | | $images_script .= "src".$i."a = '$src';\nsrc".$i."b = '".$image['guid']."';\n"; |
| 226 | | $thumb = 'true'; |
| 227 | | $thumbtext = $__thumbnail_on; |
| 228 | | } else { |
| 229 | | $src = $image['guid']; |
| 230 | | $thumb = 'false'; |
| 231 | | $thumbtext = $__no_thumbnail; |
| 232 | | } |
| 233 | | list($image['uwidth'], $image['uheight']) = get_udims($image['width'], $image['height']); |
| 234 | | $height_width = 'height="'.$image['uheight'].'" width="'.$image['uwidth'].'"'; |
| 235 | | $uwidth_sum += 128; |
| 236 | | $xpadding = (128 - $image['uwidth']) / 2; |
| 237 | | $ypadding = (96 - $image['uheight']) / 2; |
| 238 | | $object = $image['ID']; |
| 239 | | $images_style .= "#target$i img { padding: {$ypadding}px {$xpadding}px; }\n"; |
| 240 | | $href = get_subpost_link($object); |
| 241 | | $images_script .= "href".$i."a = '$href';\nhref".$i."b = '{$image['guid']}';\n"; |
| 242 | | $images_html .= <<<HERE |
| 243 | | <div id='target$i' class='imagewrap left'> |
| 244 | | <div id='popup$i' class='popup'> |
| 245 | | <a id="L$i" onclick="toggleLink($i);return false;" href="javascript:void();">$__subpost_on</a> |
| 246 | | <a id="I$i" onclick="if($thumb)toggleImage($i);else alert('$__nothumb');return false;" href="javascript:void();">$thumbtext</a> |
| 247 | | <a onclick="return confirm('$__confirmdelete')" href="image-uploading.php?action=delete&object=$object&all=$all&start=$start&post=$post">$__delete</a> |
| 248 | | <a onclick="popup.style.display='none';return false;" href="javascript:void()">$__close</a> |
| 249 | | </div> |
| 250 | | <a id="link$i" class="imagelink" href="$href" onclick="imagePopup($i);return false;" title="{$image['post_title']}"> |
| 251 | | <img id='image$i' src='$src' alt='{$image['post_title']}' $height_width /> |
| 252 | | </a> |
| 253 | | </div> |
| 254 | | HERE; |
| 255 | | $i++; |
| 256 | | } |
| 257 | | } |
| 258 | | |
| 259 | | $images_width = $uwidth_sum + ( count($images) * 5 ) + 30; |
| 260 | | |
| 261 | | break; |
| 262 | | |
| 263 | | default: |
| 264 | | die('This script was not meant to be called directly.'); |
| 265 | | } |
| 266 | | |
| 267 | | ?> |
| 268 | | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 269 | | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 270 | | <head> |
| 271 | | <meta http-equiv="imagetoolbar" content="no" /> |
| 272 | | <script type="text/javascript"> |
| 273 | | /* Define any variables we'll need, such as alternate URLs. */ |
| 274 | | <?php echo $images_script; ?> |
| 275 | | |
| 276 | | function validateImageName() { |
| 277 | | /* This is more for convenience than security. Server-side validation is very thorough.*/ |
| 278 | | obj = document.getElementById('upload'); |
| 279 | | r = /.jpg$|.gif$|.png$/i; |
| 280 | | if ( obj.value.match(r) ) |
| 281 | | return true; |
| 282 | | alert('Please select a JPG, PNG or GIF file.'); |
| 283 | | return false; |
| 284 | | } |
| 285 | | function cancelUpload() { |
| 286 | | o = document.getElementById('uploadForm'); |
| 287 | | o.method = 'GET'; |
| 288 | | o.action.value = 'view'; |
| 289 | | o.submit(); |
| 290 | | } |
| 291 | | function imagePopup(i) { |
| 292 | | if ( popup ) |
| 293 | | popup.style.display = 'none'; |
| 294 | | target = document.getElementById('target'+i); |
| 295 | | popup = document.getElementById('popup'+i); |
| 296 | | //popup.style.top = (target.offsetTop + 3) + 'px'; |
| 297 | | popup.style.left = (target.offsetLeft) + 'px'; |
| 298 | | popup.style.display = 'block'; |
| 299 | | } |
| 300 | | function init() { |
| 301 | | popup = false; |
| 302 | | } |
| 303 | | function toggleLink(n) { |
| 304 | | o=document.getElementById('link'+n); |
| 305 | | oi=document.getElementById('L'+n); |
| 306 | | if ( oi.innerHTML == subposton ) { |
| 307 | | o.href = eval('href'+n+'b'); |
| 308 | | oi.innerHTML = subpostoff; |
| 309 | | } else { |
| 310 | | o.href = eval('href'+n+'a'); |
| 311 | | oi.innerHTML = subposton; |
| 312 | | } |
| 313 | | } |
| 314 | | function toggleImage(n) { |
| 315 | | o = document.getElementById('image'+n); |
| 316 | | oi = document.getElementById('I'+n); |
| 317 | | if ( oi.innerHTML == thumbnailon ) { |
| 318 | | o.src = eval('src'+n+'b'); |
| 319 | | oi.innerHTML = thumbnailoff; |
| 320 | | } else { |
| 321 | | o.src = eval('src'+n+'a'); |
| 322 | | oi.innerHTML = thumbnailon; |
| 323 | | } |
| 324 | | } |
| 325 | | </script> |
| 326 | | <style type="text/css"> |
| 327 | | body { |
| 328 | | font: 13px "Lucida Grande", "Lucida Sans Unicode", Tahoma, Verdana; |
| 329 | | border: none; |
| 330 | | margin: 0px; |
| 331 | | height: 150px; |
| 332 | | background: rgb(223, 232, 241); |
| 333 | | } |
| 334 | | form { |
| 335 | | margin: 6px 2px 0px 6px; |
| 336 | | } |
| 337 | | #wrap { |
| 338 | | clear: both; |
| 339 | | margin: 0px; |
| 340 | | padding: 0px; |
| 341 | | height: 133px; |
| 342 | | width: 100%; |
| 343 | | overflow: auto; |
| 344 | | } |
| 345 | | #images { |
| 346 | | clear: both; |
| 347 | | margin: 0px; |
| 348 | | padding: 5px 15px; |
| 349 | | height: 96px; |
| 350 | | width: <?php echo $images_width; ?>px; |
| 351 | | } |
| 352 | | #images img { |
| 353 | | background-color: rgb(209, 226, 239); |
| 354 | | } |
| 355 | | <?php echo $images_style; ?> |
| 356 | | .imagewrap { |
| 357 | | margin-right: 5px; |
| 358 | | } |
| 359 | | .imagewrap * { |
| 360 | | margin: 0px; |
| 361 | | padding: 0px; |
| 362 | | border: 0px; |
| 363 | | } |
| 364 | | .imagewrap a, .imagewrap a img, .imagewrap a:hover img, .imagewrap a:visited img, .imagewrap a:active img { |
| 365 | | text-decoration: none; |
| 366 | | float: left; |
| 367 | | display: block; |
| 368 | | text-align: center; |
| 369 | | } |
| 370 | | #menu { |
| 371 | | margin: 0px; |
| 372 | | list-style: none; |
| 373 | | background: rgb(109, 166, 209); |
| 374 | | padding: 4px 0px 0px 8px; |
| 375 | | text-align: left; |
| 376 | | border-bottom: 3px solid rgb(68, 138, 189); |
| 377 | | } |
| 378 | | #menu li { |
| 379 | | display: inline; |
| 380 | | margin: 0px; |
| 381 | | } |
| 382 | | #menu a, #menu a:visited, #menu a:active { |
| 383 | | padding: 1px 3px 3px; |
| 384 | | text-decoration: none; |
| 385 | | color: #234; |
| 386 | | background: transparent; |
| 387 | | } |
| 388 | | #menu a:hover { |
| 389 | | background: rgb(203, 214, 228); |
| 390 | | color: #000; |
| 391 | | } |
| 392 | | #menu .current a, #menu .current a:hover, #menu .current a:visited, #menu .current a:active { |
| 393 | | background: rgb(223, 232, 241); |
| 394 | | padding-bottom: 3px; |
| 395 | | color: #000; |
| 396 | | border-right: 2px solid rgb(20, 86, 138); |
| 397 | | } |
| 398 | | .tip { |
| 399 | | color: rgb(68, 138, 189); |
| 400 | | padding: 1px 3px; |
| 401 | | } |
| 402 | | .inactive { |
| 403 | | color: #579; |
| 404 | | padding: 1px 3px; |
| 405 | | } |
| 406 | | .left { |
| 407 | | float: left; |
| 408 | | } |
| 409 | | .right { |
| 410 | | float: right; |
| 411 | | } |
| 412 | | .center { |
| 413 | | text-align: center; |
| 414 | | } |
| 415 | | #menu li.spacer { |
| 416 | | margin-left: 40px; |
| 417 | | } |
| 418 | | label { |
| 419 | | float: left; |
| 420 | | width: 18%; |
| 421 | | } |
| 422 | | #title, #descr { |
| 423 | | width: 80%; |
| 424 | | margin-top: 2px; |
| 425 | | } |
| 426 | | #descr { |
| 427 | | height: 35px; |
| 428 | | v-align: top; |
| 429 | | } |
| 430 | | #buttons { |
| 431 | | width: 98%; |
| 432 | | margin-top: 2px; |
| 433 | | text-align: right; |
| 434 | | } |
| 435 | | .popup { |
| 436 | | margin: 4px 4px; |
| 437 | | padding: 3px; |
| 438 | | position: absolute; |
| 439 | | width: 114px; |
| 440 | | height: 82px; |
| 441 | | display: none; |
| 442 | | background-color: rgb(223, 232, 241); |
| 443 | | opacity: .90; |
| 444 | | filter:alpha(opacity=90); |
| 445 | | text-align: center; |
| 446 | | } |
| 447 | | .popup a, .popup a:visited, .popup a:active { |
| 448 | | background-color: transparent; |
| 449 | | display: block; |
| 450 | | width: 100%; |
| 451 | | text-decoration: none; |
| 452 | | color: #246; |
| 453 | | } |
| 454 | | .popup a:hover { |
| 455 | | background-color: #fff; |
| 456 | | color: #000; |
| 457 | | } |
| 458 | | </style> |
| 459 | | </head> |
| 460 | | <body onload="init()"> |
| 461 | | <ul id="menu"> |
| 462 | | <li<?php echo $current_1; ?>><a href="image-uploading.php?action=upload&post=<?php echo $post; ?>&all=<?php echo $all; ?>">Upload Photo</a></li> |
| 463 | | <li<?php echo $current_2; ?>><a href="image-uploading.php?action=view&post=<?php echo $post; ?>">Browse Attached</a></li> |
| 464 | | <li<?php echo $current_3; ?>><a href="image-uploading.php?action=view&post=<?php echo $post; ?>&all=true">Browse All</a></li> |
| 465 | | <li> </li> |
| 466 | | <?php if ( false !== $back ) : ?> |
| 467 | | <li class="spacer"><a href="image-uploading.php?action=view&post=<?php echo $post; ?>&all=<?php echo $all; ?>&start=0" title="First">|<</a></li> |
| 468 | | <li><a href="image-uploading.php?action=view&post=<?php echo $post; ?>&all=<?php echo $all; ?>&start=<?php echo $back; ?>" title="Back"><<</a></li> |
| 469 | | <?php else : ?> |
| 470 | | <li class="inactive spacer">|<</li> |
| 471 | | <li class="inactive"><<</li> |
| 472 | | <?php endif; ?> |
| 473 | | <?php if ( false !== $next ) : ?> |
| 474 | | <li><a href="image-uploading.php?action=view&post=<?php echo $post; ?>&all=<?php echo $all; ?>&start=<?php echo $next; ?>" title="Next">>></a></li> |
| 475 | | <li><a href="image-uploading.php?action=view&post=<?php echo $post; ?>&all=<?php echo $all; ?>&last=true" title="Last">>|</a></li> |
| 476 | | <?php else : ?> |
| 477 | | <li class="inactive">>></li> |
| 478 | | <li class="inactive">>|</li> |
| 479 | | <?php endif; ?> |
| 480 | | </ul> |
| 481 | | <?php if ( $action == 'view' ) : ?> |
| 482 | | <span class="left tip">Drag and drop photos to post</span> |
| 483 | | <span class="right tip">Click photos for more options</span> |
| 484 | | <div id="wrap"> |
| 485 | | <div id="images"> |
| 486 | | <?php echo $images_html; ?> |
| 487 | | </div> |
| 488 | | </div> |
| 489 | | <?php elseif ( $action = 'upload' ) : ?> |
| 490 | | <div class="center tip">Duplicated filenames will be numbered (photo.jpg, photo1.jpg, etc.)</div> |
| 491 | | <form enctype="multipart/form-data" id="uploadForm" method="POST" action="image-uploading.php" onsubmit="return validateImageName()"> |
| 492 | | <label for="upload">Image:</label><input type="file" id="upload" name="image" onchange="validateImageName()" /> |
| 493 | | <label for="title">Title:</label><input type="text" id="title" name="imgtitle" /> |
| 494 | | <label for="descr">Description:</label><input type="textarea" name="descr" id="descr" value="" /> |
| 495 | | <input type="hidden" name="action" value="save" /> |
| 496 | | <input type="hidden" name="post" value="<?php echo $post; ?>" /> |
| 497 | | <input type="hidden" name="all" value="<?php echo $all; ?>" /> |
| 498 | | <div id="buttons"> |
| 499 | | <input type="submit" value="Upload" /> |
| 500 | | <input type="button" value="Cancel" onclick="cancelUpload()" /> |
| 501 | | </div> |
| 502 | | </form> |
| 503 | | <?php endif; ?> |
| 504 | | </body> |
| 505 | | </html> |
| | 1 | <?php |
| | 2 | |
| | 3 | require_once('admin.php'); |
| | 4 | |
| | 5 | if (!current_user_can('edit_posts')) |
| | 6 | die(__('You do not have permission to edit posts.')); |
| | 7 | |
| | 8 | $wpvarstoreset = array('action', 'post', 'all', 'last', 'link', 'sort', 'start', 'imgtitle', 'descr', 'object', 'flickrtag'); |
| | 9 | |
| | 10 | for ($i=0; $i<count($wpvarstoreset); $i += 1) { |
| | 11 | $wpvar = $wpvarstoreset[$i]; |
| | 12 | if (!isset($$wpvar)) { |
| | 13 | if (empty($_POST["$wpvar"])) { |
| | 14 | if (empty($_GET["$wpvar"])) { |
| | 15 | $$wpvar = ''; |
| | 16 | } else { |
| | 17 | $$wpvar = $_GET["$wpvar"]; |
| | 18 | } |
| | 19 | } else { |
| | 20 | $$wpvar = $_POST["$wpvar"]; |
| | 21 | } |
| | 22 | } |
| | 23 | } |
| | 24 | |
| | 25 | $post = (int) $post; |
| | 26 | $images_width = 1; |
| | 27 | |
| | 28 | function 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 | |
| | 37 | switch($action) { |
| | 38 | case 'delete': |
| | 39 | |
| | 40 | wp_delete_object($object); |
| | 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'] . '<a href="' . basename(__FILE__) . '?action=upload&post="' . $post . '">Back to Image Uploading</a>'); |
| | 53 | |
| | 54 | $url = $file['url']; |
| | 55 | $file = $file['file']; |
| | 56 | $filename = basename($file); |
| | 57 | |
| | 58 | // Construct the object array |
| | 59 | $object = array( |
| | 60 | 'post_title' => $imgtitle ? $imgtitle : $filename, |
| | 61 | 'post_content' => $descr, |
| | 62 | 'post_status' => 'object', |
| | 63 | 'post_parent' => $post, |
| | 64 | 'post_type' => $_FILES['image']['type'], |
| | 65 | 'guid' => $url |
| | 66 | ); |
| | 67 | |
| | 68 | // Save the data |
| | 69 | $id = wp_attach_object($object, $post); |
| | 70 | |
| | 71 | // Generate the object's postmeta. |
| | 72 | $imagesize = getimagesize($file); |
| | 73 | $imagedata['width'] = $imagesize['0']; |
| | 74 | $imagedata['height'] = $imagesize['1']; |
| | 75 | list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']); |
| | 76 | $imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'"; |
| | 77 | $imagedata['file'] = $file; |
| | 78 | $imagedata['thumb'] = "thumb-$filename"; |
| | 79 | |
| | 80 | add_post_meta($id, 'imagedata', $imagedata); |
| | 81 | |
| | 82 | if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) { |
| | 83 | if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 ) |
| | 84 | $error = wp_create_thumbnail($file['file'], 128); |
| | 85 | elseif ( $imagedata['height'] > 96 ) |
| | 86 | $error = wp_create_thumbnail($file, 96); |
| | 87 | } |
| | 88 | |
| | 89 | header("Location: ".basename(__FILE__)."?post=$post&all=$all&action=view&last=true"); |
| | 90 | die; |
| | 91 | |
| | 92 | case 'upload': |
| | 93 | |
| | 94 | $current_1 = ' class="current"'; |
| | 95 | $back = $next = false; |
| | 96 | break; |
| | 97 | |
| | 98 | case 'view': |
| | 99 | |
| | 100 | // How many images do we show? How many do we query? |
| | 101 | $num = 5; |
| | 102 | $double = $num * 2; |
| | 103 | |
| | 104 | if ( $post && empty($all) ) { |
| | 105 | $and_post = "AND post_parent = '$post'"; |
| | 106 | $current_2 = ' class="current"'; |
| | 107 | } else { |
| | 108 | $current_3 = ' class="current"'; |
| | 109 | } |
| | 110 | |
| | 111 | if ( $last ) |
| | 112 | $start = $wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_status = 'object' AND left(post_type, 5) = 'image' $and_post") - $num; |
| | 113 | else |
| | 114 | $start = (int) $start; |
| | 115 | |
| | 116 | if ( $start < 0 ) |
| | 117 | $start = 0; |
| | 118 | |
| | 119 | if ( '' == $sort ) |
| | 120 | $sort = "ID"; |
| | 121 | |
| | 122 | $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); |
| | 123 | |
| | 124 | if ( count($images) > $num ) { |
| | 125 | $next = $start + count($images) - $num; |
| | 126 | } else { |
| | 127 | $next = false; |
| | 128 | } |
| | 129 | |
| | 130 | if ( $start > 0 ) { |
| | 131 | $back = $start - $num; |
| | 132 | if ( $back < 1 ) |
| | 133 | $back = '0'; |
| | 134 | } else { |
| | 135 | $back = false; |
| | 136 | } |
| | 137 | |
| | 138 | $i = 0; |
| | 139 | $uwidth_sum = 0; |
| | 140 | $images_html = ''; |
| | 141 | $images_style = ''; |
| | 142 | $images_script = ''; |
| | 143 | if ( count($images) > 0 ) { |
| | 144 | $images = array_slice( $images, 0, $num ); |
| | 145 | $__delete = __('DELETE'); |
| | 146 | $__subpost_on = __('SUBPOST <strong>ON</strong>'); |
| | 147 | $__subpost_off = __('SUBPOST <strong>OFF</strong>'); |
| | 148 | $__thumbnail_on = __('THUMBNAIL <strong>ON</strong>'); |
| | 149 | $__thumbnail_off = __('THUMBNAIL <strong>OFF</strong>'); |
| | 150 | $__no_thumbnail = __('<del>THUMBNAIL</del>'); |
| | 151 | $__close = __('CLOSE'); |
| | 152 | $__confirmdelete = __('Delete this photo from the server?'); |
| | 153 | $__nothumb = __('There is no thumbnail associated with this photo.'); |
| | 154 | $images_script .= "subposton = '$__subpost_on';\nsubpostoff = '$__subpost_off';\n"; |
| | 155 | $images_script .= "thumbnailon = '$__thumbnail_on';\nthumbnailoff = '$__thumbnail_off';\n"; |
| | 156 | foreach ( $images as $key => $image ) { |
| | 157 | $meta = get_post_meta($image['ID'], 'imagedata', true); |
| | 158 | if (!is_array($meta)) { |
| | 159 | wp_delete_object($image['ID']); |
| | 160 | continue; |
| | 161 | } |
| | 162 | $image = array_merge($image, $meta); |
| | 163 | if ( ($image['width'] > 128 || $image['height'] > 96) && !empty($image['thumb']) && file_exists(dirname($image['file']).'/'.$image['thumb']) ) { |
| | 164 | $src = str_replace(basename($image['guid']), '', $image['guid']) . $image['thumb']; |
| | 165 | $images_script .= "src".$i."a = '$src';\nsrc".$i."b = '".$image['guid']."';\n"; |
| | 166 | $thumb = 'true'; |
| | 167 | $thumbtext = $__thumbnail_on; |
| | 168 | } else { |
| | 169 | $src = $image['guid']; |
| | 170 | $thumb = 'false'; |
| | 171 | $thumbtext = $__no_thumbnail; |
| | 172 | } |
| | 173 | list($image['uwidth'], $image['uheight']) = get_udims($image['width'], $image['height']); |
| | 174 | $height_width = 'height="'.$image['uheight'].'" width="'.$image['uwidth'].'"'; |
| | 175 | $uwidth_sum += 128; |
| | 176 | $xpadding = (128 - $image['uwidth']) / 2; |
| | 177 | $ypadding = (96 - $image['uheight']) / 2; |
| | 178 | $object = $image['ID']; |
| | 179 | $images_style .= "#target$i img { padding: {$ypadding}px {$xpadding}px; }\n"; |
| | 180 | $href = get_subpost_link($object); |
| | 181 | $images_script .= "href".$i."a = '$href';\nhref".$i."b = '{$image['guid']}';\n"; |
| | 182 | $images_html .= <<<HERE |
| | 183 | <div id='target$i' class='imagewrap left'> |
| | 184 | <div id='popup$i' class='popup'> |
| | 185 | <a id="L$i" onclick="toggleLink($i);return false;" href="javascript:void();">$__subpost_on</a> |
| | 186 | <a id="I$i" onclick="if($thumb)toggleImage($i);else alert('$__nothumb');return false;" href="javascript:void();">$thumbtext</a> |
| | 187 | <a onclick="return confirm('$__confirmdelete')" href="image-uploading.php?action=delete&object=$object&all=$all&start=$start&post=$post">$__delete</a> |
| | 188 | <a onclick="popup.style.display='none';return false;" href="javascript:void()">$__close</a> |
| | 189 | </div> |
| | 190 | <a id="link$i" class="imagelink" href="$href" onclick="imagePopup($i);return false;" title="{$image['post_title']}"> |
| | 191 | <img id='image$i' src='$src' alt='{$image['post_title']}' $height_width /> |
| | 192 | </a> |
| | 193 | </div> |
| | 194 | HERE; |
| | 195 | $i++; |
| | 196 | } |
| | 197 | } |
| | 198 | |
| | 199 | $images_width = $uwidth_sum + ( count($images) * 5 ) + 30; |
| | 200 | |
| | 201 | break; |
| | 202 | |
| | 203 | case 'flickr': |
| | 204 | |
| | 205 | require_once ABSPATH . WPINC . '/class-snoopy.php'; |
| | 206 | |
| | 207 | function flickr_api_call($method, $params = '') { |
| | 208 | $api_key = '7cd7b7dea9c9d3069caf99d12471008e'; // An API key reserved for WordPress |
| | 209 | $searchurl = 'http://www.flickr.com/services/rest/?method=' . $method . '&api_key=' . $api_key . '&' . $params; |
| | 210 | $client = new Snoopy(); |
| | 211 | $client->agent = 'WordPress/Flickr Browser'; |
| | 212 | $client->read_timeout = 2; |
| | 213 | $client->use_gzip = true; |
| | 214 | @$client->fetch($searchurl); |
| | 215 | return $client->results; |
| | 216 | } |
| | 217 | |
| | 218 | // How many images do we show? How many do we query? |
| | 219 | $num = 5; |
| | 220 | $double = $num * 2; |
| | 221 | |
| | 222 | $flickr_user_id = get_user_option('flickr_userid'); |
| | 223 | if($flickr_user_id == '') { |
| | 224 | $flickr_username = get_user_option('flickr_username'); |
| | 225 | $user_xml = flickr_api_call('flickr.people.findByUsername', "username={$flickr_username}"); |
| | 226 | if(preg_match('/nsid="(.*?)">/', $user_xml, $matches)) { |
| | 227 | $flickr_user_id = $matches[1]; |
| | 228 | } |
| | 229 | else die("Failed to find Flickr ID for '$flickr_username'"); // Oh, dear - no Flickr user_id! |
| | 230 | |
| | 231 | // Store the found Flickr user_id in usermeta... |
| | 232 | // Don't forget on the options page to update the user_id along with the username! |
| | 233 | update_user_option($current_user->id, 'flickr_userid', $flickr_user_id, true); |
| | 234 | } |
| | 235 | |
| | 236 | // Fetch photo list from Flickr |
| | 237 | $ustart = $start + 1; |
| | 238 | //$photos_xml = flickr_api_call('flickr.photos.search', array('per_page' => $num, 'user_id' => $flickr_user_id)); |
| | 239 | if($flickrtag == '') { |
| | 240 | $all = '0'; |
| | 241 | $photos_xml = flickr_api_call('flickr.people.getPublicPhotos', "per_page={$num}&user_id={$flickr_user_id}&page={$ustart}"); |
| | 242 | } |
| | 243 | else { |
| | 244 | $photos_xml = flickr_api_call('flickr.photos.search', "per_page={$num}&user_id={$flickr_user_id}&page={$ustart}&tags={$flickrtag}"); |
| | 245 | $all = '0&flickrtag=' . $flickrtag; |
| | 246 | } |
| | 247 | //echo "<pre>" . htmlentities($photos_xml) . "</pre>"; // Displays the XML returned by Flickr for the photo list |
| | 248 | |
| | 249 | //Get Page Count |
| | 250 | preg_match('/<photos.*pages="([0-9]+)"/', $photos_xml, $page_counta); |
| | 251 | $page_count = $page_counta[1]; |
| | 252 | if($page_count == 0) { |
| | 253 | $back = false; |
| | 254 | $next = false; |
| | 255 | break; |
| | 256 | } |
| | 257 | if($start < $page_count) $next = $start + 1; else $next = false; |
| | 258 | if($start > 0) $back = $start - 1; else $back = false; |
| | 259 | if($last != '') { |
| | 260 | $photos_xml = flickr_api_call('flickr.people.getPublicPhotos', "per_page={$num}&user_id={$flickr_user_id}&page={$page_count}"); |
| | 261 | $back = $page_count -1; |
| | 262 | $next = false; |
| | 263 | } |
| | 264 | |
| | 265 | //Get Photos |
| | 266 | preg_match_all('/<photo.*?id="([0-9]+)".*?secret="([0-9a-f]+)".*?server="([0-9]+)".*?title="([^"]*)".*?\/>/', $photos_xml, $matches, PREG_SET_ORDER); |
| | 267 | foreach($matches as $match) { |
| | 268 | $img['post_title'] = $match[4]; |
| | 269 | |
| | 270 | $sizes_xml = flickr_api_call('flickr.photos.getSizes', "photo_id={$match[1]}"); |
| | 271 | preg_match_all('/<size.*?label="([^"]+)".*?width="([0-9]+)".*?height="([0-9]+)".*?source="([^"]+)".*?\/>/', $sizes_xml, $sizes, PREG_SET_ORDER); |
| | 272 | |
| | 273 | $max_size = ''; |
| | 274 | foreach($sizes as $size) { |
| | 275 | $img_size[$size[1]]['width'] = $size[2]; |
| | 276 | $img_size[$size[1]]['height'] = $size[3]; |
| | 277 | $img_size[$size[1]]['url'] = $size[4]; |
| | 278 | if($max_size == '' || $img_size[$size[1]]['width'] > $img_size[$max_size]['width']) { |
| | 279 | $max_size = $size[1]; |
| | 280 | } |
| | 281 | } |
| | 282 | |
| | 283 | $images[] = array( |
| | 284 | 'post_title' => $match[4], |
| | 285 | 'thumbnail' => $img_size['Thumbnail']['url'], |
| | 286 | 'full' => $img_size[$max_size]['url'], |
| | 287 | 'href' => "http://flickr.com/photos/{$flickr_user_id}/{$match[1]}/", |
| | 288 | 'width' => $img_size['Thumbnail']['width'], |
| | 289 | 'height' => $img_size['Thumbnail']['height'], |
| | 290 | 'size_info' => $img_size, |
| | 291 | ); |
| | 292 | } |
| | 293 | |
| | 294 | $current_flickr = ' class="current"'; |
| | 295 | |
| | 296 | $__use_size = __('Use %s'); |
| | 297 | $__close = __('CLOSE'); |
| | 298 | |
| | 299 | $images_script .= "var flickr_src = new Array();\n"; |
| | 300 | |
| | 301 | $i=0; |
| | 302 | foreach($images as $image) { |
| | 303 | list($uwidth, $uheight) = get_udims($image['width'], $image['height']); |
| | 304 | $xpadding = (128 - $uwidth) / 2; |
| | 305 | $ypadding = (96 - $uheight) / 2; |
| | 306 | $height_width = 'height="'.$uheight.'" width="'.$uwidth.'"'; |
| | 307 | $images_style .= "#target$i img { padding: {$ypadding}px {$xpadding}px; }\n"; |
| | 308 | $images_html .= " |
| | 309 | <div id='target$i' class='imagewrap left'> |
| | 310 | <div id='popup$i' class='popup'> |
| | 311 | "; |
| | 312 | |
| | 313 | $images_script .= "flickr_src[$i] = new Array();\n"; |
| | 314 | foreach($image['size_info'] as $szkey => $size) { |
| | 315 | $images_script .= "flickr_src[$i]['{$szkey}']= '{$size['url']}';\n"; |
| | 316 | $use = sprintf($__use_size, $szkey); |
| | 317 | $prefix = ($szkey == 'Thumbnail') ? '<strong>':''; |
| | 318 | $postfix = ($szkey == 'Thumbnail') ? '</strong>':''; |
| | 319 | $images_html .= "<a id=\"I{$i}_{$szkey}\" onclick=\"toggleSize($i,'$szkey');return false;\" href=\"javascript:void();\">{$prefix}{$use}{$postfix}</a>\n"; |
| | 320 | } |
| | 321 | $images_html .= " |
| | 322 | <a onclick=\"popup.style.display='none';return false;\" href=\"javascript:void()\">$__close</a> |
| | 323 | </div> |
| | 324 | <a id=\"link$i\" class=\"imagelink\" href=\"{$image['href']}\" onclick=\"imagePopup($i);return false;\" title=\"{$image['post_title']}\"> |
| | 325 | <img id=\"image$i\" src=\"{$image['thumbnail']}\" alt=\"{$image['post_title']}\" $height_width /> |
| | 326 | </a> |
| | 327 | </div> |
| | 328 | "; |
| | 329 | $i++; |
| | 330 | } |
| | 331 | |
| | 332 | $images_width = ( count($images) * 133 ) + 5; |
| | 333 | |
| | 334 | break; |
| | 335 | |
| | 336 | default: |
| | 337 | die('This script was not meant to be called directly.'); |
| | 338 | } |
| | 339 | |
| | 340 | ?> |
| | 341 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| | 342 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| | 343 | <head> |
| | 344 | <meta http-equiv="imagetoolbar" content="no" /> |
| | 345 | <script type="text/javascript"> |
| | 346 | /* Define any variables we'll need, such as alternate URLs. */ |
| | 347 | <?php echo $images_script; ?> |
| | 348 | |
| | 349 | function validateImageName() { |
| | 350 | /* This is more for convenience than security. Server-side validation is very thorough.*/ |
| | 351 | obj = document.getElementById('upload'); |
| | 352 | r = /.jpg$|.gif$|.png$/i; |
| | 353 | if ( obj.value.match(r) ) |
| | 354 | return true; |
| | 355 | alert('Please select a JPG, PNG or GIF file.'); |
| | 356 | return false; |
| | 357 | } |
| | 358 | function cancelUpload() { |
| | 359 | o = document.getElementById('uploadForm'); |
| | 360 | o.method = 'GET'; |
| | 361 | o.action.value = 'view'; |
| | 362 | o.submit(); |
| | 363 | } |
| | 364 | function imagePopup(i) { |
| | 365 | if ( popup ) |
| | 366 | popup.style.display = 'none'; |
| | 367 | target = document.getElementById('target'+i); |
| | 368 | popup = document.getElementById('popup'+i); |
| | 369 | //popup.style.top = (target.offsetTop + 3) + 'px'; |
| | 370 | popup.style.left = (target.offsetLeft) + 'px'; |
| | 371 | popup.style.display = 'block'; |
| | 372 | } |
| | 373 | function init() { |
| | 374 | popup = false; |
| | 375 | } |
| | 376 | function toggleLink(n) { |
| | 377 | o=document.getElementById('link'+n); |
| | 378 | oi=document.getElementById('L'+n); |
| | 379 | if ( oi.innerHTML == subposton ) { |
| | 380 | o.href = eval('href'+n+'b'); |
| | 381 | oi.innerHTML = subpostoff; |
| | 382 | } else { |
| | 383 | o.href = eval('href'+n+'a'); |
| | 384 | oi.innerHTML = subposton; |
| | 385 | } |
| | 386 | } |
| | 387 | function toggleImage(n) { |
| | 388 | o = document.getElementById('image'+n); |
| | 389 | oi = document.getElementById('I'+n); |
| | 390 | if ( oi.innerHTML == thumbnailon ) { |
| | 391 | o.src = eval('src'+n+'b'); |
| | 392 | oi.innerHTML = thumbnailoff; |
| | 393 | } else { |
| | 394 | o.src = eval('src'+n+'a'); |
| | 395 | oi.innerHTML = thumbnailon; |
| | 396 | } |
| | 397 | } |
| | 398 | function toggleSize(n,sz) { |
| | 399 | o = document.getElementById('image'+n); |
| | 400 | oi = document.getElementById('popup'+n); |
| | 401 | o.src = flickr_src[n][sz]; |
| | 402 | if (!document.getElementsByTagName) return; |
| | 403 | var anchors = document.getElementsByTagName("a"); |
| | 404 | var re_id = 'I'+n+'_'; // /i[0-9]+_.+/i; |
| | 405 | var re_strip = /<.*?>/i; |
| | 406 | for (var i=0; i< anchors.length; i++) { |
| | 407 | var anchor = anchors[i]; |
| | 408 | if (anchor.getAttribute("href") && anchor.id.match(re_id)) |
| | 409 | anchor.innerHTML = anchor.innerHTML.replace(re_strip, ''); |
| | 410 | } |
| | 411 | var anchor = document.getElementById('I'+n+'_'+sz); |
| | 412 | anchor.innerHTML = '<strong>' + anchor.innerHTML + '</strong>'; |
| | 413 | } |
| | 414 | </script> |
| | 415 | <style type="text/css"> |
| | 416 | body { |
| | 417 | font: 13px "Lucida Grande", "Lucida Sans Unicode", Tahoma, Verdana; |
| | 418 | border: none; |
| | 419 | margin: 0px; |
| | 420 | height: 150px; |
| | 421 | background: rgb(223, 232, 241); |
| | 422 | } |
| | 423 | form { |
| | 424 | margin: 6px 2px 0px 6px; |
| | 425 | } |
| | 426 | #wrap { |
| | 427 | clear: both; |
| | 428 | margin: 0px; |
| | 429 | padding: 0px; |
| | 430 | height: 133px; |
| | 431 | width: 100%; |
| | 432 | overflow: auto; |
| | 433 | } |
| | 434 | #images { |
| | 435 | clear: both; |
| | 436 | margin: 0px; |
| | 437 | padding: 5px 15px; |
| | 438 | height: 96px; |
| | 439 | white-space: nowrap; |
| | 440 | width: <?php echo $images_width; ?>px; |
| | 441 | } |
| | 442 | #images img { |
| | 443 | background-color: rgb(209, 226, 239); |
| | 444 | } |
| | 445 | <?php echo $images_style; ?> |
| | 446 | .imagewrap { |
| | 447 | margin-right: 5px; |
| | 448 | height: 96px; |
| | 449 | overflow: hidden; |
| | 450 | } |
| | 451 | .imagewrap * { |
| | 452 | margin: 0px; |
| | 453 | padding: 0px; |
| | 454 | border: 0px; |
| | 455 | } |
| | 456 | .imagewrap a, .imagewrap a img, .imagewrap a:hover img, .imagewrap a:visited img, .imagewrap a:active img { |
| | 457 | text-decoration: none; |
| | 458 | float: left; |
| | 459 | /*display: block;*/ |
| | 460 | text-align: center; |
| | 461 | } |
| | 462 | #menu { |
| | 463 | margin: 0px; |
| | 464 | list-style: none; |
| | 465 | background: rgb(109, 166, 209); |
| | 466 | padding: 4px 0px 0px 8px; |
| | 467 | text-align: left; |
| | 468 | border-bottom: 3px solid rgb(68, 138, 189); |
| | 469 | } |
| | 470 | #menu li { |
| | 471 | display: inline; |
| | 472 | margin: 0px; |
| | 473 | } |
| | 474 | #menu a, #menu a:visited, #menu a:active { |
| | 475 | padding: 1px 3px 3px; |
| | 476 | text-decoration: none; |
| | 477 | color: #234; |
| | 478 | background: transparent; |
| | 479 | } |
| | 480 | #menu a:hover { |
| | 481 | background: rgb(203, 214, 228); |
| | 482 | color: #000; |
| | 483 | } |
| | 484 | #menu .current a, #menu .current a:hover, #menu .current a:visited, #menu .current a:active { |
| | 485 | background: rgb(223, 232, 241); |
| | 486 | padding-bottom: 3px; |
| | 487 | color: #000; |
| | 488 | border-right: 2px solid rgb(20, 86, 138); |
| | 489 | } |
| | 490 | .tip { |
| | 491 | color: rgb(68, 138, 189); |
| | 492 | padding: 1px 3px; |
| | 493 | } |
| | 494 | .inactive { |
| | 495 | color: #579; |
| | 496 | padding: 1px 3px; |
| | 497 | } |
| | 498 | .left { |
| | 499 | float: left; |
| | 500 | } |
| | 501 | .right { |
| | 502 | float: right; |
| | 503 | } |
| | 504 | .center { |
| | 505 | text-align: center; |
| | 506 | } |
| | 507 | #menu li.spacer { |
| | 508 | margin-left: 40px; |
| | 509 | } |
| | 510 | label { |
| | 511 | float: left; |
| | 512 | width: 18%; |
| | 513 | } |
| | 514 | #title, #descr { |
| | 515 | width: 80%; |
| | 516 | margin-top: 2px; |
| | 517 | } |
| | 518 | #descr { |
| | 519 | height: 35px; |
| | 520 | v-align: top; |
| | 521 | } |
| | 522 | #buttons { |
| | 523 | width: 98%; |
| | 524 | margin-top: 2px; |
| | 525 | text-align: right; |
| | 526 | } |
| | 527 | .popup { |
| | 528 | margin: 4px 4px; |
| | 529 | padding: 3px; |
| | 530 | position: absolute; |
| | 531 | width: 114px; |
| | 532 | height: 82px; |
| | 533 | display: none; |
| | 534 | background-color: rgb(223, 232, 241); |
| | 535 | opacity: .90; |
| | 536 | filter:alpha(opacity=90); |
| | 537 | text-align: center; |
| | 538 | } |
| | 539 | .popup a, .popup a:visited, .popup a:active { |
| | 540 | background-color: transparent; |
| | 541 | display: block; |
| | 542 | width: 100%; |
| | 543 | text-decoration: none; |
| | 544 | color: #246; |
| | 545 | } |
| | 546 | .popup a:hover { |
| | 547 | background-color: #fff; |
| | 548 | color: #000; |
| | 549 | } |
| | 550 | #flickrtags { |
| | 551 | display: inline; |
| | 552 | } |
| | 553 | #flickrtags input { |
| | 554 | border:0px; |
| | 555 | } |
| | 556 | input#flickrtag { |
| | 557 | background-color: white; |
| | 558 | color: black; |
| | 559 | width:65px; |
| | 560 | } |
| | 561 | input#flickrsubmit { |
| | 562 | background-color: #dfe8f1; |
| | 563 | color: black; |
| | 564 | } |
| | 565 | </style> |
| | 566 | </head> |
| | 567 | <body onload="init()"> |
| | 568 | <ul id="menu"> |
| | 569 | <li<?php echo $current_1; ?>><a href="image-uploading.php?action=upload&post=<?php echo $post; ?>&all=<?php echo $all; ?>">Upload Photo</a></li> |
| | 570 | <li<?php echo $current_flickr; ?>><a href="image-uploading.php?action=flickr&post=<?php echo $post; ?>">Browse Flickr</a></li> |
| | 571 | <li<?php echo $current_2; ?>><a href="image-uploading.php?action=view&post=<?php echo $post; ?>">Browse Attached</a></li> |
| | 572 | <li<?php echo $current_3; ?>><a href="image-uploading.php?action=view&post=<?php echo $post; ?>&all=true">Browse All</a></li> |
| | 573 | <li> </li> |
| | 574 | <?php if ( false !== $back ) : ?> |
| | 575 | <li class="spacer"><a href="image-uploading.php?action=<?php echo $action; ?>&post=<?php echo $post; ?>&all=<?php echo $all; ?>&start=0" title="First">|<</a></li> |
| | 576 | <li><a href="image-uploading.php?action=<?php echo $action; ?>&post=<?php echo $post; ?>&all=<?php echo $all; ?>&start=<?php echo $back; ?>" title="Back"><<</a></li> |
| | 577 | <?php else : ?> |
| | 578 | <li class="inactive spacer">|<</li> |
| | 579 | <li class="inactive"><<</li> |
| | 580 | <?php endif; ?> |
| | 581 | |
| | 582 | <?php if($action == 'flickr') : ?> |
| | 583 | <form id="flickrtags" method="get"><?php echo sprintf(__('Tag: %s'), '<input type="text" id="flickrtag" name="flickrtag" value="' . $flickrtag . '" />'); ?><input id="flickrsubmit" type="submit" value="Filter" /><?php |
| | 584 | parse_str($_SERVER['QUERY_STRING'], $formquery); |
| | 585 | foreach($formquery as $k=>$v) if($k!='flickrtag') echo "<input type=\"hidden\" name=\"$k\" value=\"$v\" />"; |
| | 586 | ?></form> |
| | 587 | <?php endif; ?> |
| | 588 | |
| | 589 | <?php if ( false !== $next ) : ?> |
| | 590 | <li><a href="image-uploading.php?action=<?php echo $action; ?>&post=<?php echo $post; ?>&all=<?php echo $all; ?>&start=<?php echo $next; ?>" title="Next">>></a></li> |
| | 591 | <li><a href="image-uploading.php?action=<?php echo $action; ?>&post=<?php echo $post; ?>&all=<?php echo $all; ?>&last=true" title="Last">>|</a></li> |
| | 592 | <?php else : ?> |
| | 593 | <li class="inactive">>></li> |
| | 594 | <li class="inactive">>|</li> |
| | 595 | <?php endif; ?> |
| | 596 | </ul> |
| | 597 | <?php if ( $action == 'view' || $action == 'flickr' ) : ?> |
| | 598 | <span class="left tip"><?php _e('Drag and drop photos to post'); ?></span> |
| | 599 | <span class="right tip"><?php _e('Click photos for more options'); ?></span> |
| | 600 | <div id="wrap"> |
| | 601 | <div id="images"> |
| | 602 | <?php echo $images_html; ?> |
| | 603 | </div> |
| | 604 | </div> |
| | 605 | <?php elseif ( $action == 'upload' ) : ?> |
| | 606 | <div class="center tip">Duplicated filenames will be numbered (photo.jpg, photo1.jpg, etc.)</div> |
| | 607 | <form enctype="multipart/form-data" id="uploadForm" method="POST" action="image-uploading.php" onsubmit="return validateImageName()"> |
| | 608 | <label for="upload">Image:</label><input type="file" id="upload" name="image" onchange="validateImageName()" /> |
| | 609 | <label for="title">Title:</label><input type="text" id="title" name="imgtitle" /> |
| | 610 | <label for="descr">Description:</label><input type="textarea" name="descr" id="descr" value="" /> |
| | 611 | <input type="hidden" name="action" value="save" /> |
| | 612 | <input type="hidden" name="post" value="<?php echo $post; ?>" /> |
| | 613 | <input type="hidden" name="all" value="<?php echo $all; ?>" /> |
| | 614 | <div id="buttons"> |
| | 615 | <input type="submit" value="Upload" /> |
| | 616 | <input type="button" value="Cancel" onclick="cancelUpload()" /> |
| | 617 | </div> |
| | 618 | </form> |
| | 619 | <?php endif; ?> |
| | 620 | </body> |
| | 621 | </html> |
| | 622 | |
| | 623 | |
| | 624 | |