| [ 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 * Import Zip File 4 * 5 * Allows uploading .zip archives. 6 * 7 * @package admin 8 * @author A Gianotto <snipe@snipe.net> 9 * @version 3.0 10 * @since 3.0 11 */ 12 13 14 15 $GALLERY_SECTION = "import"; 16 $PAGE_TITLE = "Import Files From .zip"; 17 include ("../../inc/config.php"); 18 include ($cfg_admin_path."/lib/connect.php"); 19 include ($cfg_admin_path."/lib/admin.functions.php"); 20 21 22 include ("../layout/admin.header.php"); 23 24 // get the category details 25 if (!empty($_REQUEST['gallery_id'])) { 26 $sql = "select name, frame_style, watermark_txt, display_orderby, display_order from snipe_gallery_cat where id='".$_REQUEST['gallery_id']."'"; 27 if ($get_catname = mysql_query($sql)) { 28 $valid_cat = mysql_num_rows($get_catname); 29 if ($valid_cat > 0) { 30 list($this_catname, $this_frame_style, $this_watermark_txt, $this_display_orderby, $this_display_order) = mysql_fetch_row($get_catname); 31 } 32 } 33 34 } 35 36 if ($_POST['action']!="upload") { 37 ?> 38 <h3><?php echo $LANG_ADMIN_IMPORT_ZIP; ?></h3> 39 40 41 <?php 42 if (($cfg_use_cache==1) && (!file_exists($cfg_cache_path))){ 43 echo '<p class="errortxt">ERROR: The cache is enabled in your config.php file, but that directory ('.$cfg_cache_path.') does not appear to exist.</p>'; 44 } elseif (($cfg_use_cache==1) && (file_exists($cfg_cache_path)) && (!is_writable($cfg_cache_path))){ 45 echo '<p class="errortxt">ERROR: The cache is enabled in your config.php file, and the directory ('.$cfg_cache_path.') exists, but it does not appear to be writable. Please check the permissions on this directory before proceeding.</p>'; 46 47 } else { 48 echo $LANG_ADMIN_IMPORT_TXT; 49 50 ?> 51 <form method="post" action="zip.php" enctype="multipart/form-data"> 52 <center> 53 <table border="0" cellspacing="1" cellpadding="3" bgcolor="#999999"> 54 <tr> 55 <td colspan="2" class="resultline"><b><?php echo $LANG_ADMIN_IMPORT_1; ?></b></td> 56 </tr> 57 58 <tr> 59 <td class="resultline-alt" valign="top"><b><?php echo $LANG_ADMIN_IMPORT_2; ?>:</b> </td> 60 <td class="resultline-alt"> 61 62 <?php 63 64 $sql ="select id, name from snipe_gallery_cat where cat_parent='0' order by name asc"; 65 $get_options = mysql_query($sql); 66 $num_options = mysql_num_rows($get_options); 67 echo '<select name="gallery_id">'; 68 69 // our category is apparently valid, so go ahead... 70 if ($num_options > 0) { 71 while (list($cat_id, $cat_name) = mysql_fetch_row($get_options)) { 72 73 $sql ="select id, name from snipe_gallery_cat where cat_parent='".$cat_id."' order by name asc"; 74 $get_suboptions = mysql_query($sql); 75 $num_suboptions = mysql_num_rows($get_suboptions); 76 if ($num_suboptions > 0) { 77 while (list($subcat_id, $subcat_name) = mysql_fetch_row($get_suboptions)) { 78 79 echo "<option value=\"".$subcat_id."\">".stripslashes($cat_name).":: ".stripslashes($subcat_name)."</option>\n"; 80 } 81 } 82 83 } 84 echo ' </select>'; 85 86 87 } 88 ?> 89 </td> 90 </tr> 91 <tr> 92 <td class="resultline-alt" valign="top"><?php echo $LANG_IMG_FIELD[0]; ?>: </td> 93 <td class="resultline-alt"><input name="userfile" type="file" size="50"></td> 94 </tr> 95 <tr> 96 <td class="resultline-alt" valign="top"><?php echo $LANG_IMG_FIELD[1]; ?>: </td> 97 <td class="resultline-alt"><input type="text" name="form_author" maxlength="100" size="30"></td> 98 </tr> 99 <tr> 100 <td class="resultline-alt" valign="top"><?php echo $LANG_IMG_FIELD[2]; ?>: </td> 101 <td class="resultline-alt"><input type="text" name="form_location" maxlength="255" size="30"></td> 102 </tr> 103 <tr> 104 <td class="resultline-alt" valign="top"><?php echo $LANG_IMG_FIELD[3]; ?>: </td> 105 <td class="resultline-alt"><textarea name="form_details" rows="4" cols="50"></textarea></td> 106 </tr> 107 <tr> 108 <td class="resultline-alt" valign="top"><?php echo $LANG_IMG_FIELD[4]; ?>: </td> 109 <td class="resultline-alt"><input type="text" name="form_keywords" maxlength="255" size="30"></td> 110 </tr> 111 <tr> 112 <td class="resultline-alt" valign="top" colspan="2"> 113 <input type="checkbox" name="make_thumbs" value="1" checked="checked"><?php echo $LANG_IMG_FIELD[10]; ?>? 114 </td> 115 </tr> 116 <!-- <tr> 117 <td class="resultline-alt" valign="top" colspan="2"> 118 <input type="checkbox" name="watermark" value="1">Watermark images (when applicable) 119 </td> 120 </tr> --> 121 <tr> 122 <td class="resultline-alt" valign="top" colspan="2"> 123 <input type="checkbox" name="keep_filedate" value="1"><?php echo $LANG_IMG_FIELD[11]; ?> 124 </td> 125 </tr> 126 127 <?php 128 if ($cfg_use_iptc_meta==1) { 129 ?> 130 131 <tr> 132 <td class="resultline-alt" valign="top">IPTC Meta Data: </td> 133 <td class="resultline-alt"> 134 <input type="checkbox" name="iptc_title_override" value="1"<?php if ($cfg_iptc_meta_default==1) { echo ' checked="checked"'; } ?>>Use IPTC headline as title<br> 135 <input type="checkbox" name="iptc_caption_override" value="1"<?php if ($cfg_iptc_meta_default==1) { echo ' checked="checked"'; } ?>>Use IPTC caption as description <br> 136 <input type="checkbox" name="iptc_author_override" value="1"<?php if ($cfg_iptc_meta_default==1) { echo ' checked="checked"'; } ?>>Use IPTC author as photographer <br> 137 <input type="checkbox" name="iptc_loc_override" value="1"<?php if ($cfg_iptc_meta_default==1) { echo ' checked="checked"'; } ?>>Use IPTC location as location <br> 138 <input type="checkbox" name="iptc_keywords_override" value="1"<?php if ($cfg_iptc_meta_default==1) { echo ' checked="checked"'; } ?>>Use IPTC keywords as keywords <br> 139 <input type="checkbox" name="iptc_date_override" value="1"<?php if ($cfg_iptc_meta_default==1) { echo ' checked="checked"'; } ?>>Use IPTC creation date as date<br> 140 <span class="smadmin">(NOTE: IPTC values will override user-entered fields if selected)</span> 141 </td> 142 </tr> 143 <?php } ?> 144 145 146 <tr> 147 <td class="resultline-alt" valign="top" colspan="2"> 148 <input type="checkbox" name="form_publish" value="1" value="1" checked="checked">Publish? 149 </td> 150 </tr> 151 <tr> 152 <td colspan="2" class="resultline" align="right"><div align="right"> 153 <input type="submit" value="<?php echo $LANG_IMG_FIELD[12]; ?>" class="formbutton" onClick="this.disabled=true; this.value='<?php echo $LANG_IMG_FIELD[13]; ?>...'; this.form.submit();"> 154 <input type="hidden" name="action" value="upload"> 155 156 </div></td> 157 </tr> 158 </table> 159 </center> 160 <input type="hidden" name="MAX_FILE_SIZE" value="300000"> 161 </form> 162 163 <?php 164 } 165 } elseif ($_POST['action']=="upload") { 166 if (!empty($_FILES['userfile']['tmp_name']) && ($_FILES['userfile']['tmp_name']!= 'none')) { 167 168 $ext = substr(strrchr($_FILES['userfile']['name'], "."), 1); 169 if ($ext!="zip") { 170 echo "<h3>".$LANG_ERR_IMPORT_FORMAT_HEAD."</h3>"; 171 echo '<p class="errortxt">'.$LANG_ERR_IMPORT_FORMAT_TXT.'</p>'; 172 } else { 173 174 $temp_dir = date("U"); 175 $temp_dirname = $cfg_admin_path."/import/files/".$temp_dir; 176 $dirname = $cfg_admin_path."/import/files/"; 177 $filename = escapeshellarg($_FILES['userfile']['name']); 178 $file = $dirname.$filename; 179 180 if (move_uploaded_file($_FILES['userfile']['tmp_name'], $dirname."/".$_FILES['userfile']['name'])) { 181 if (mkdir($temp_dirname)) { 182 chmod($temp_dirname, 0755); 183 chmod($file, 0755); 184 if (exec("$cfg_unzip_path $file -d $temp_dirname 2>&1", $error) === FALSE) { 185 echo "<h3>".$LANG_ERR_IMPORT_UNZIP_HEAD."</h3>"; 186 echo '<p class="errortxt">'.$LANG_ERR_IMPORT_UNZIP_TXT.'</p><br><b>More Info:</b><br>'; 187 188 print_r ($error); 189 } else { 190 191 192 $dir = opendir($temp_dirname); 193 while ($file = readdir($dir)) { 194 if ($file == '.' || $file == '..') continue; 195 $time = filemtime($temp_dirname."/".$file); 196 $total_files++; 197 if ($uploaded_img_size = getimagesize($temp_dirname."/".$file, $info)) { 198 199 /** 200 * Make sure IPTC is enabled - and if it is, get the data from the uploaded file 201 */ 202 203 if ($cfg_use_iptc_meta==1) { 204 $iptc = iptcparse($info["APP13"]); 205 if (is_array($iptc)) { 206 207 if ($_POST['iptc_title_override']==1) { 208 $form_image_title = $iptc["2#105"][0]; 209 } 210 211 if ($_POST['iptc_caption_override']==1) { 212 $form_details = $iptc["2#120"][0]; 213 } 214 215 if ($_POST['iptc_author_override']==1) { 216 $form_author = $iptc["2#080"][0]; 217 } 218 219 if ($_POST['iptc_loc_override']==1) { 220 if (!empty($iptc["2#090"][0])) { 221 $form_location .= $iptc["2#090"][0]; 222 if (!empty($iptc["2#095"][0])) { 223 $form_location .=", "; 224 } 225 } 226 if (!empty($iptc["2#095"][0])) { 227 $form_location .= $iptc["2#095"][0]." "; 228 } 229 if (!empty($iptc_country)) { 230 $form_location .= $iptc["2#101"][0]; 231 } 232 233 } 234 235 236 if ($_POST['iptc_keywords_override']==1) { 237 $iptc_keywords = $iptc["2#025"][0]; 238 239 $c = count ($iptc["2#025"]); 240 if ($c > 0) { 241 $form_keywords = ""; 242 for ($i=0; $i <$c; $i++) { 243 $form_keywords .= $iptc["2#025"][$i].' '; 244 } 245 } 246 } 247 248 if ($_POST['iptc_date_override']==1) { 249 $iptc_showdate = strtotime($iptc["2#055"][0]); 250 $img_time = date("Y-m-d", $iptc_showdate); 251 } 252 } 253 254 255 /** 256 * If IPTC isn't enabled, assign the form fields to the variable names 257 */ 258 } else { 259 $form_image_title = $_POST['form_image_title']; 260 $form_author = $_POST['form_author']; 261 $form_location = $_POST['form_location']; 262 $form_keywords = $_POST['form_keywords']; 263 $form_details = $_POST['form_details']; 264 265 if ($_POST['keep_filedate']==1) { 266 $img_time = date("Y-m-d",$time); 267 } else { 268 $img_time = ""; 269 } 270 } 271 272 273 /** 274 * Find out the file type 275 */ 276 if ($uploaded_img_size[2]==1) { 277 $img_ext = ".gif"; 278 $img_filetype_err = 0; 279 280 } elseif ($uploaded_img_size[2]==2) { 281 $img_ext = ".jpg"; 282 $img_filetype_err = 0; 283 284 } elseif ($uploaded_img_size[2]==3) { 285 $img_ext = ".png"; 286 $img_filetype_err = 0; 287 288 } elseif ($uploaded_img_size[2]==4) { 289 $img_ext = ".swf"; 290 $img_filetype_err = 0; 291 292 } else { 293 $img_filetype_err = 1; 294 295 } 296 297 298 if ($_POST['keep_filedate']==1) { 299 $img_time = date("Y-m-d",$time); 300 } else { 301 $img_time = ""; 302 } 303 304 $sql = "insert into snipe_gallery_data (img_date, title, details, author, location, cat_id, keywords, publish, added) values ("; 305 $sql .="'".$img_time."', '".trim(addslashes($form_image_title))."', '".trim(addslashes($form_details))."', '".trim(addslashes($form_author))."', '".trim(addslashes($form_location))."', '".$_POST['gallery_id']."', '".trim(addslashes($form_keywords))."', '".$_POST['form_publish']."', NOW())"; 306 307 if ($add_image = mysql_query($sql)) { 308 309 $image_count++; 310 $this_image_id = mysql_insert_id(); 311 $image_id = $this_image_id; 312 $image_filename = $this_image_id."_".date("U").$img_ext; 313 /* 314 * If caching is enabled, copy the new file into the cache 315 */ 316 if (($cfg_use_cache==1) && (is_writable($cfg_cache_path))) { 317 copy($temp_dirname."/".$file, $cfg_cache_path."/".$image_filename); 318 } 319 $sql = "update snipe_gallery_data set filename='".$image_filename."' where id='".$this_image_id."'"; 320 $update_img = mysql_query($sql); 321 copy($temp_dirname."/".$file, $cfg_pics_path."/".$image_filename); 322 323 if ((($uploaded_img_size[2]==2) || ($uploaded_img_size[2]==3)) && ($cfg_use_fullsize_ceil==1) && ($uploaded_img_size[0] > $cfg_max_fullsize_width)) { 324 325 $fimg_width = $uploaded_img_size[0]; 326 $fimg_height= $uploaded_img_size[1]; 327 328 $new_fw = $cfg_max_fullsize_width; 329 $fratio = ($fimg_width / $new_fw); 330 $new_fh = round($fimg_height / $fratio); 331 /* 332 * if dynamic thumbnailing 333 */ 334 $fsrc_img = imagecreatefromjpeg($cfg_pics_path."/".$image_filename); 335 $fdst_img = imagecreatetruecolor($new_fw,$new_fh); 336 imagecopyresampled($fdst_img,$fsrc_img,0,0,0,0,$new_fw,$new_fh,$fimg_width,$fimg_height); 337 338 if ($uploaded_img_size[2]==2) { 339 imagejpeg($fdst_img, $cfg_pics_path."/".$image_filename); 340 } elseif ($uploaded_img_size[2]==3) { 341 imagepng($fdst_img, $cfg_pics_path."/".$image_filename); 342 } 343 imagedestroy($fdst_img); 344 345 346 347 348 } 349 350 351 if ((($uploaded_img_size[2]==2) || ($uploaded_img_size[2]==3)) && ($image_count <= $cfg_max_import_munge) && ($_POST['make_thumbs']==1)) { 352 $uploaded_img_size = getimagesize($cfg_pics_path."/".$image_filename); 353 $img_width = $uploaded_img_size[0]; 354 $img_height= $uploaded_img_size[1]; 355 356 357 358 $new_w = $cfg_thumb_width; 359 $ratio = ($img_width / $new_w); 360 $new_h = round($img_height / $ratio); 361 /* 362 * if dynamic thumbnailing 363 */ 364 $src_img = imagecreatefromjpeg($cfg_pics_path."/".$image_filename); 365 $dst_img = imagecreatetruecolor($new_w,$new_h); 366 imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,$img_width, $img_height); 367 368 $sql = "update snipe_gallery_data set thumbname='".$image_filename."' where id='".$this_image_id."'"; 369 $update_img = mysql_query($sql); 370 371 if ($uploaded_img_size[2]==2) { 372 imagejpeg($dst_img, $cfg_thumb_path."/".$image_filename); 373 } elseif ($uploaded_img_size[2]==3) { 374 imagepng($dst_img, $cfg_thumb_path."/".$image_filename); 375 } 376 } 377 378 /* 379 * if we have to cache the image, make a copy of it in the cache 380 * directory specified in the config file 381 */ 382 if (($cfg_use_cache==1) && (!empty($this_watermark_txt)) && (file_exists($cfg_cache_path)) && (is_writable($cfg_cache_path))) { 383 copy($cfg_pics_path."/".$image_filename, $cfg_cache_path."/".$image_filename); 384 385 } 386 unlink($temp_dirname."/".$file); 387 388 } 389 390 $filelist .= "<li>".$file; 391 $numfiles++; 392 } 393 } 394 395 if ($numfiles < 1) { 396 397 echo "<h3>".$LANG_ERR_IMPORT_NOIMG_HEAD."</h3>"; 398 echo '<p class="errortxt">'.$LANG_ERR_IMPORT_NOIMG_TXT.' </p><br><b>More Info:</b><br>'; 399 print_r ($error); 400 } else { 401 echo "<h3>".$LANG_ADMIN_FILE_IMPORTED."</h3>"; 402 echo "<p>".$LANG_ADMIN_FILES_IMPORTED."</p>"; 403 echo $filelist; 404 echo "<br><br><b><a href=\"../gallery/view.php?gallery_id=".$_POST['gallery_id']."\">".$LANG_SUBNAV_VIEW_IMAGES."</a></b><br><br><b>More Info:</b><br>"; 405 print_r ($error); 406 407 } 408 409 410 411 } 412 } else { 413 echo "<h3>".$LANG_ERR_ERROR."</h3>"; 414 echo "<p>".$LANG_ERR_IMPORT_TEMPDIR."</p>"; 415 } 416 417 418 } 419 @unlink($temp_dirname); 420 @unlink($dirname."/".$_FILES['userfile']['name']); 421 @unlink($_FILES['userfile']['tmp_name']); 422 } 423 424 425 } else { 426 echo "<h3>".$LANG_ERR_ERROR."</h3>"; 427 echo "<p>".$LANG_ERR_NOIMAGE_HEAD."</p>"; 428 429 430 } 431 432 433 } 434 435 include ("../layout/admin.footer.php"); ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |