| [ PHPXref.com ] | [ Generated: Sun Jul 20 20:24:47 2008 ] | [ Snipe Gallery 3.1.4 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * image.php.php 4 * 5 * Displays the image form and performs the add or update for images 6 * 7 * @package admin 8 * @author A Gianotto <snipe@snipe.net> 9 * @version 3.0 10 * @since 3.0 11 * 12 */ 13 14 /** 15 * 16 * {@source } 17 */ 18 19 $GALLERY_SECTION = "image"; 20 $PAGE_TITLE = "Images"; 21 22 include ("../../inc/config.php"); 23 include ($cfg_admin_path."/lib/connect.php"); 24 include ($cfg_admin_path."/lib/admin.functions.php"); 25 include ($cfg_admin_path."/lib/dropdown.functions.php"); 26 27 28 /** 29 * Get the category details 30 */ 31 if ((!empty($_REQUEST['gallery_id'])) || (!empty($_REQUEST['form_gallery_id']))){ 32 if (!empty($_REQUEST['form_gallery_id'])) { 33 $get_gall_id = $_REQUEST['form_gallery_id']; 34 } else { 35 $get_gall_id = $_REQUEST['gallery_id']; 36 } 37 38 $sql = "select name, cat_parent, default_thumbtype, watermark_txt from snipe_gallery_cat "; 39 $sql .="where id='".$get_gall_id."'"; 40 if ($get_catname = mysql_query($sql)) { 41 $valid_cat = mysql_num_rows($get_catname); 42 if ($valid_cat > 0) { 43 list($this_catname, $this_cat_parent, $this_thumbtype, $this_watermark_txt) = mysql_fetch_row($get_catname); 44 } 45 } 46 } 47 48 /** 49 * If this is a new image, we need to find out what whether or not is valid, 50 * what the file type is, and whether or not the category type require watermarking 51 */ 52 53 54 /** 55 * make sure an image was actually uploaded 56 */ 57 if (!empty($_FILES['form_image']['tmp_name']) && ($_FILES['form_image']['tmp_name']!= 'none')) { 58 $uploaded_img_size = getimagesize($_FILES['form_image']['tmp_name'], $info); 59 60 /** 61 * Make sure IPTC is enabled - and if it is, get the data from the uploaded file 62 */ 63 64 if ($cfg_use_iptc_meta==1) { 65 $iptc = iptcparse($info["APP13"]); 66 if (is_array($iptc)) { 67 68 if ($_POST['iptc_title_override']==1) { 69 $form_image_title = $iptc["2#105"][0]; 70 } 71 72 if ($_POST['iptc_caption_override']==1) { 73 $form_details = $iptc["2#120"][0]; 74 } 75 76 if ($_POST['iptc_author_override']==1) { 77 $form_author = $iptc["2#080"][0]; 78 } 79 80 if ($_POST['iptc_loc_override']==1) { 81 if (!empty($iptc["2#090"][0])) { 82 $form_location .= $iptc["2#090"][0]; 83 if (!empty($iptc["2#095"][0])) { 84 $form_location .=", "; 85 } 86 } 87 if (!empty($iptc["2#095"][0])) { 88 $form_location .= $iptc["2#095"][0]." "; 89 } 90 if (!empty($iptc_country)) { 91 $form_location .= $iptc["2#101"][0]; 92 } 93 94 } 95 96 97 if ($_POST['iptc_keywords_override']==1) { 98 $iptc_keywords = $iptc["2#025"][0]; 99 100 $c = count ($iptc["2#025"]); 101 if ($c > 0) { 102 $form_keywords = ""; 103 for ($i=0; $i <$c; $i++) { 104 $form_keywords .= $iptc["2#025"][$i].' '; 105 } 106 } 107 } 108 109 if ($_POST['iptc_date_override']==1) { 110 $iptc_showdate = strtotime($iptc["2#055"][0]); 111 $date = date("Y-m-d", $iptc_showdate)."<br>"; 112 } 113 } 114 115 116 /** 117 * If IPTC isn't enabled, assign the form fields to the variable names 118 */ 119 } else { 120 $form_image_title = $_POST['form_image_title']; 121 $form_author = $_POST['form_author']; 122 $form_location = $_POST['form_location']; 123 $form_keywords = $_POST['form_keywords']; 124 $form_details = $_POST['form_details']; 125 $date = $_POST['form_year']."-".$_POST['form_month']."".$_POST['form_day']; 126 } 127 128 129 /** 130 * Find out the file type 131 */ 132 if ($uploaded_img_size[2]==1) { 133 $img_ext = ".gif"; 134 $img_filetype_err = 0; 135 136 } elseif ($uploaded_img_size[2]==2) { 137 $img_ext = ".jpg"; 138 $img_filetype_err = 0; 139 140 } elseif ($uploaded_img_size[2]==3) { 141 $img_ext = ".png"; 142 $img_filetype_err = 0; 143 144 } elseif ($uploaded_img_size[2]==4) { 145 $img_ext = ".swf"; 146 $img_filetype_err = 0; 147 148 } else { 149 $img_filetype_err = 1; 150 151 } 152 153 /* 154 * if the image isn't valid, return an error and stop the process 155 */ 156 if ($img_filetype_err ==1) { 157 $err_message = "<h3>".$LANG_ERR_INVALID_FILETYPE_HEAD."</h3>\n\n<p>".$LANG_ERR_INVALID_FILETYPE_TXT."</p>"; 158 159 /* 160 * otherwise, go ahead... 161 */ 162 } else { 163 164 if (!empty($_REQUEST['image_id'])) { 165 $sql = "select filename, thumbname from snipe_gallery_data "; 166 $sql .="where id='".$_REQUEST['image_id']."' "; 167 168 } else { 169 170 $sql = "insert into snipe_gallery_data (img_date, title, details, author, location, cat_id, keywords, publish, added) values ("; 171 $sql .="'".$date."', '".trim(addslashes($form_image_title))."', '".trim(addslashes($form_details))."', '".trim(addslashes($form_author))."', '".trim(addslashes($form_location))."', '".$_POST['form_gallery_id']."', '".trim(addslashes($form_keywords))."', '".$_POST['form_publish']."', NOW())"; 172 } 173 174 175 176 if ($add_image = mysql_query($sql)) { 177 if (empty($_REQUEST['image_id'])) { 178 $this_image_id = mysql_insert_id(); 179 $image_id = $this_image_id; 180 181 /* 182 * check to see if we should keep the original filename 183 */ 184 if ($cfg_orig_filenames==1) { 185 $image_filename = $_FILES['form_image']['name']; 186 } else { 187 $image_filename = $this_image_id."_".date("U").$img_ext; 188 } 189 } else { 190 list($edit_image_filename, $edit_image_thumbname) = mysql_fetch_row($add_image); 191 $image_filename = $edit_image_filename; 192 $this_image_id = $_REQUEST['image_id']; 193 } 194 195 /* 196 * move the uploaded file to where it belongs 197 */ 198 if (move_uploaded_file($_FILES['form_image']['tmp_name'], $cfg_pics_path."/".$image_filename)) { 199 200 $img_width = $uploaded_img_size[0]; 201 $img_height= $uploaded_img_size[1]; 202 203 /* 204 * if this image can be resized, figure out what we need to do 205 */ 206 if (($uploaded_img_size[2]==2) || ($uploaded_img_size[2]==3)) { 207 208 /* 209 * if this is a landscape style image 210 */ 211 if ($img_width > $img_height) { 212 213 /* 214 * if there is a ceiling on the max upload width, resize the image down 215 * to the specified size 216 */ 217 if (($cfg_use_fullsize_ceil==1) && ($img_width > $cfg_max_fullsize_width)) { 218 $new_fw = $cfg_max_fullsize_width; 219 $fratio = ($img_width / $new_fw); 220 $new_fh = round($img_height / $fratio); 221 $continue_resize = 1; 222 } 223 224 } else { 225 if (($cfg_use_fullsize_hceil==1) && ($img_height > $cfg_max_fullsize_height)) { 226 227 /* 228 * if there is a ceiling on the max upload height, resize the image down 229 * to the specified size 230 */ 231 if (($cfg_use_fullsize_hceil==1) && ($img_height > $cfg_max_fullsize_height)) { 232 $new_fh = $cfg_max_fullsize_height; 233 $fratio = ($img_height / $new_fh); 234 $new_fw = round($img_width / $fratio); 235 $continue_resize = 1; 236 } 237 238 } 239 240 } 241 242 243 if ($continue_resize == 1) { 244 $fsrc_img = imagecreatefromjpeg($cfg_pics_path."/".$image_filename); 245 if (gd_version() >= 2) { 246 $fdst_img = imagecreatetruecolor($new_fw,$new_fh); imagecopyresampled($fdst_img,$fsrc_img,0,0,0,0,$new_fw,$new_fh,$img_width,$img_height); 247 } else { 248 $fdst_img = imagecreate($new_fw,$new_fh); imagecopyresized($fdst_img,$fsrc_img,0,0,0,0,$new_fw,$new_fh,$img_width,$img_height); 249 } 250 251 252 if ($uploaded_img_size[2]==2) { 253 imagejpeg($fdst_img, $cfg_pics_path."/".$image_filename); 254 } elseif ($uploaded_img_size[2]==3) { 255 imagepng($fdst_img, $cfg_pics_path."/".$image_filename); 256 } 257 imagedestroy($fdst_img); 258 } 259 260 } 261 262 /* 263 * if we have to cache the image, make a copy of it in the cache 264 * directory specified in the config file 265 */ 266 if (($cfg_use_cache==1) && (file_exists($cfg_cache_path)) && (is_writable($cfg_cache_path))) { 267 copy($cfg_pics_path."/".$image_filename, $cfg_cache_path."/".$image_filename); 268 269 } 270 271 $sql = "update snipe_gallery_data set filename='".$image_filename."' where id='".$this_image_id."'"; 272 $update_img = mysql_query($sql); 273 274 if ((isset($this_thumbtype)) && (!empty($this_thumbtype)) && ($this_thumbtype==2) && (($uploaded_img_size[2]==2) || ($uploaded_img_size[2]==3))) { 275 $print_message = "<h3>".$LANG_ADMIN_ADD_IMAGE.": ".$LANG_SEL_THUMB."</h3>"; 276 $show_crop_js = 1; 277 if (!empty($this_watermark_txt)) { 278 /** 279 * position of watermark text on image 280 * 0 = top 281 * 1 = bottom 282 * 2 = middle left 283 */ 284 285 if ($cfg_font_pos == 0) { 286 $h_pos = $cfg_font_h_padding; 287 $v_pos = $cfg_font_v_padding; 288 } elseif ($cfg_font_pos == 1) { 289 $h_pos = $cfg_font_h_padding; 290 $v_pos = round($uploaded_img_size[1] - $cfg_font_v_padding); 291 } elseif ($cfg_font_pos == 2) { 292 $h_pos = $cfg_font_h_padding; 293 $v_pos = round($uploaded_img_size[1]/2); 294 } else { 295 $h_pos = $cfg_font_h_padding; 296 $v_pos = $cfg_font_v_padding; 297 } 298 299 /* 300 * If the cache option is turned on, create a copy of the 301 */ 302 303 if ($cfg_use_cache==1) { 304 $use_filename = $cfg_cache_path."/".$image_filename; 305 } else { 306 $use_filename = $cfg_pics_path."/".$image_filename; 307 } 308 309 if (!$image = imagecreatetruecolor($uploaded_img_size[0], $uploaded_img_size[1])) { 310 $image = imagecreate($uploaded_img_size[0], $uploaded_img_size[1]); 311 } 312 313 if ($uploaded_img_size[2]==2) { 314 $image = imagecreatefromjpeg($use_filename); 315 } elseif ($uploaded_img_size[2]==3) { 316 $image = imagecreatefrompng($use_filename); 317 } 318 319 $color = imagecolorallocate($image, 255,255,255); 320 $black = imagecolorallocate($image, 0,0,0); 321 322 ImageTTFText ($image, $cfg_font_size, 0, ($h_pos+2), ($v_pos+2), $black, $cfg_font_path."/".$cfg_font_name,stripslashes($this_watermark_txt)); 323 324 /* 325 * Now add the colored text "on top" 326 */ 327 ImageTTFText ($image, $cfg_font_size, 0, $h_pos, $v_pos, $color, $cfg_font_path."/".$cfg_font_name,stripslashes($this_watermark_txt)); 328 329 if ($uploaded_img_size[2]==2) { 330 imagejpeg($image,$use_filename); 331 } elseif ($uploaded_img_size[2]==3) { 332 imagepng($image,$use_filename); 333 334 } 335 336 imagedestroy($image); 337 338 } 339 header("Location: ".$cfg_admin_url."/gallery/crop.php?gallery_id=".$_REQUEST['form_gallery_id']."&image_id=".$this_image_id."&page=".$_REQUEST['page']); 340 341 /* 342 * if the gallery type specifies automatic thumbnailing 343 */ 344 } elseif ((isset($this_thumbtype)) && (!empty($this_thumbtype)) && ($this_thumbtype!=2) && (($uploaded_img_size[2]==2) || ($uploaded_img_size[2]==3))) { 345 346 347 $uploaded_img_size = getimagesize($cfg_pics_path."/".$image_filename); 348 $img_width = $uploaded_img_size[0]; 349 $img_height= $uploaded_img_size[1]; 350 $new_w = $cfg_thumb_width; 351 $ratio = ($img_width / $new_w); 352 $new_h = round($img_height / $ratio); 353 /* 354 * if dynamic thumbnailing 355 */ 356 357 if ($uploaded_img_size[2]==2) { 358 $src_img = imagecreatefromjpeg($cfg_pics_path."/".$image_filename); 359 } elseif ($uploaded_img_size[2]==3) { 360 $src_img = imagecreatefrompng($cfg_pics_path."/".$image_filename); 361 } 362 if (gd_version() >= 2) { 363 $dst_img = imagecreatetruecolor($new_w,$new_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,$img_width,$img_height); 364 } else { 365 $dst_img = imagecreate($new_w,$new_h); imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,$img_width,$img_height); 366 } 367 368 369 $sql = "update snipe_gallery_data set thumbname='".$image_filename."' where id='".$this_image_id."'"; 370 if ($update_img = mysql_query($sql)) { 371 372 if ($uploaded_img_size[2]==2) { 373 imagejpeg($dst_img, $cfg_thumb_path."/".$image_filename); 374 } elseif ($uploaded_img_size[2]==3) { 375 imagepng($dst_img, $cfg_thumb_path."/".$image_filename); 376 } 377 imagedestroy($dst_img); 378 379 header("Location: ".$cfg_admin_url."/gallery/view.php?gallery_id=".$_REQUEST['form_gallery_id']."&image_id=".$this_image_id."&page=".$_REQUEST['page']); 380 } else { 381 $thumb_db_error= "SQL: $sql <br>Mysql Said: ".mysql_error(); 382 } 383 } else { 384 header("Location: ".$cfg_admin_url."/gallery/view.php?gallery_id=".$_REQUEST['form_gallery_id']."&image_id=".$this_image_id."&page=".$_REQUEST['page']."&bar"); 385 } 386 387 } else{ 388 $err_message = '<h3>'.$LANG_ERR_IMAGE_HEAD.'</h3><span class="errortxt">'.$LANG_ERR_IMAGE_TXT.'</span>'; 389 } 390 391 392 393 394 } else { 395 $err_message = "<h3>".$LANG_ERR_IMAGE_HEAD."</h3><span class=\"errortxt\">".$LANG_ERR_DB_ERROR."</span>"; 396 if ($cfg_debug_on==1) { 397 $err_message .= "<p><b>mySQL said: </b>"; 398 $err_message .= mysql_error(); 399 $err_message .= "</p>\n\n<p><b>SQL query:</b> $sql </p>"; 400 401 } 402 } 403 } 404 405 406 } else { 407 $err_message = "<h3>".$LANG_ERR_NOIMAGE_HEAD."</h3>"; 408 $err_message .="<p>".$LANG_ERR_NOIMAGE_TXT."</p>"; 409 410 } 411 412 413 414 415 include ("../layout/admin.header.php"); 416 417 if (!empty($thumb_db_error)) { 418 echo "<p>ERROR: ".$thumb_db_error."</p>"; 419 } 420 421 if (!empty($_REQUEST['image_id'])) { 422 423 if ($_GET['rethumb']==1) { 424 $sql = "select filename, thumbname from snipe_gallery_data "; 425 $sql .="where id='".$_REQUEST['image_id']."' "; 426 $getthumbinfo = mysql_query($sql); 427 428 list($image_filename, $image_thumbname) = mysql_fetch_row($getthumbinfo); 429 430 $temp_size = getimagesize($cfg_pics_path."/".$image_filename); 431 432 if (($cfg_use_cache==1) && (file_exists($cfg_cache_path."/".$image_filename))) { 433 if ($temp_size[2]==2) { 434 $src_img = imagecreatefromjpeg($cfg_cache_path."/".$image_filename); 435 } else { 436 $src_img = imagecreatefrompng($cfg_cache_path."/".$image_filename); 437 } 438 } else { 439 if ($temp_size[2]==2) { 440 $src_img = imagecreatefromjpeg($cfg_pics_path."/".$image_filename); 441 } else { 442 $src_img = imagecreatefrompng($cfg_pics_path."/".$image_filename); 443 } 444 445 } 446 447 if (file_exists($cfg_pics_path."/".$image_filename)) { 448 449 450 $img_width = $temp_size[0]; 451 $img_height = $temp_size[1]; 452 $new_w = $cfg_thumb_width; 453 $ratio = ($img_width / $new_w); 454 $new_h = round($img_height / $ratio); 455 456 $dst_img = imagecreatetruecolor($new_w,$new_h); 457 imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,$img_width,$img_height); 458 459 if ($temp_size[2]==2) { 460 imagejpeg($dst_img, $cfg_thumb_path."/".$image_filename); 461 } elseif ($temp_size[2]==3) { 462 imagepng($dst_img, $cfg_thumb_path."/".$image_filename); 463 } 464 $sql = "update snipe_gallery_data set thumbname='".$image_filename."' where id='".$_REQUEST['image_id']."'"; 465 $update_img = mysql_query($sql); 466 467 } 468 469 } 470 471 472 if ($_POST['action']!="save") { 473 $sql = "select filename, thumbname, img_date, title, "; 474 $sql .="details, author, location, cat_id, keywords, "; 475 $sql .="publish, added from snipe_gallery_data "; 476 $sql .="where id='".$_REQUEST['image_id']."' "; 477 478 if ($show_image=mysql_query($sql)) { 479 $valid_image = mysql_num_rows($show_image); 480 if ($valid_image > 0) { 481 482 echo "<h3>".stripslashes($this_catname)." - View Image Details</h3>"; 483 list($image_filename, $image_thumbname, $image_date, $image_title, $image_details, $image_author, $image_location, $image_cat_id, $image_keywords, $image_publish, $image_added) = mysql_fetch_row($show_image); 484 $temp_size = @getimagesize($cfg_pics_path."/".$image_filename); 485 486 list($image_year, $image_month, $image_day) = split("-",$image_date); 487 $monthlist= MakeMonthDropMenu("form_month",$image_month); 488 489 /* 490 * rotate the image if requested 491 */ 492 493 if (function_exists('imagerotate')) { 494 if (($_REQUEST['rotate']=="left") || ($_REQUEST['rotate']=="right")) { 495 496 $rotate_img = turn_img($image_filename, "right", 0); 497 if ($cfg_use_cache==1) { 498 $rotate_img_cache = turn_img($image_filename, "right", 1); 499 } 500 } 501 } 502 503 504 $daylist= MakeDayDropMenu("form_day",$image_day); 505 if ($image_year=="0000") { 506 $image_year=""; 507 } 508 include ($cfg_admin_path."/lib/forms/image_form.php"); 509 510 } else { 511 echo "<h3>".stripslashes($this_catname)." - ".$LANG_ERR_INVALID_IMAGEID_HEAD."</h3><p class=\"errortxt\">".$LANG_ERR_INVALID_IMAGEID_TXT."</p>"; 512 } 513 514 515 516 } else { 517 echo "<h3>".stripslashes($this_catname)." - ".$LANG_ERR_ERROR."</h3><span class=\"errortxt\">".$LANG_ERR_DB_ERROR."</span>"; 518 if ($cfg_debug_on==1) { 519 echo "<p><b>mySQL said: </b>"; 520 echo mysql_error(); 521 echo "</p>\n\n<p><b>SQL query:</b> $sql </p>"; 522 523 } 524 } 525 526 } else { 527 $date = $_POST['form_year']."-".$_POST['form_month']."".$_POST['form_day']; 528 $sql = "update snipe_gallery_data set img_date='".$date."', "; 529 $sql .="title='".addslashes($_POST['form_image_title'])."', "; 530 $sql .="details='".addslashes($_POST['form_details'])."', "; 531 $sql .="author='".addslashes($_POST['form_author'])."', "; 532 $sql .="location='".addslashes($_POST['form_location'])."', "; 533 $sql .="cat_id='".$_POST['form_gallery_id']."', "; 534 $sql .=" keywords='".addslashes($_POST['form_keywords'])."', "; 535 $sql .="publish='".$_POST['form_publish']."' "; 536 $sql .="where id='".$_REQUEST['image_id']."' "; 537 538 if ($show_image=mysql_query($sql)) { 539 540 echo "<h3>".stripslashes($this_catname)." - ".$LANG_ADMIN_IMAGEEDIT_SAVED_HEAD."</h3>\n\n"; 541 echo '<p>'.$LANG_ADMIN_IMAGEEDIT_SAVED_TXT.'</p>'; 542 } else { 543 echo "<h3>".stripslashes($this_catname)." - ".$LANG_ERR_IMAGEEDIT_HEAD."</h3><span class=\"errortxt\">".$LANG_ERR_DB_ERROR."</span>"; 544 if ($cfg_debug_on==1) { 545 echo "<p><b>mySQL said: </b>"; 546 echo mysql_error(); 547 echo "</p>\n\n<p><b>SQL query:</b> $sql </p>"; 548 549 } 550 } 551 552 } 553 554 555 556 557 } else { 558 559 if (($this_cat_parent==0) && ($valid_cat > 0)) { 560 echo "<h3>".$LANG_ADMIN_ADD_IMAGE."</h3>\n "; 561 echo '<p>'.$LANG_ERR_IMG_TOPLVL.'</p>'; 562 563 564 } else { 565 if ($valid_cat > 0) { 566 567 if ($_POST['action']=="new") { 568 if (!empty($err_message)) { 569 echo $err_message; 570 } 571 } else { 572 573 echo "<h3>Add New Image in "".stripslashes($this_catname).""</h3>"; 574 echo "<p>Use the form below to add a new image to this gallery. "; 575 if (($cfg_use_cache==1) && (!empty($this_watermark_txt))) { 576 if (($cfg_use_cache==1) && (!empty($this_watermark_txt)) && (file_exists($cfg_cache_path)) && (is_writable($cfg_cache_path))) { 577 echo " This gallery has watermarking enabled, so a copy of the original image will also be stored in the directory you have specified in the config.php file."; 578 } else { 579 echo " This gallery has watermarking enabled, however a problem has been detected in the cache directory, so an additional copy will not be stored. Please check the settings for your cache directory specified in the config.php file."; 580 } 581 } 582 583 echo "</p>"; 584 $monthlist= MakeMonthDropMenu("form_month",""); 585 $daylist= MakeDayDropMenu("form_day",""); 586 include ($cfg_admin_path."/lib/forms/image_form.php"); 587 588 589 } 590 } else { 591 echo "<h3>Invalid Gallery</h3>"; 592 echo "<p>This category is not valid. Perhaps it has been deleted? Please select a valid gallery from the <b><a href=\"index.php\">gallery listings page</a></b>.</p>"; 593 } 594 } 595 } 596 597 598 include ("../layout/admin.footer.php"); ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |