[ PHPXref.com ] [ Generated: Sun Jul 20 20:24:47 2008 ] [ Snipe Gallery 3.1.4 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/admin/import/ -> local.php (source)

   1  <?php 
   2  /**
   3  * Import Local File
   4  *
   5  * Allows importing from specific upload directory
   6  *     
   7  * @package      admin
   8  * @author       A Gianotto <snipe@snipe.net>
   9  * @version 3.1.1
  10  * @since 3.1.1
  11  */
  12  
  13  
  14  
  15  $GALLERY_SECTION = "import";
  16  $PAGE_TITLE = "Import Local Files";
  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 $PAGE_TITLE ; ?></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  } elseif (($cfg_use_cache==1) && (file_exists($cfg_cache_path)) && (!is_writable($cfg_cache_path))){
  47              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>';
  48  } elseif (!file_exists($cfg_local_import_dir)){
  49              echo '<p class="errortxt">ERROR: The cache is enabled in your config.php file, and the directory ('.$cfg_local_import_dir.') exists, but it does not appear to be writable. Please check the permissions on this directory before proceeding.</p>';
  50  
  51  
  52  } else {
  53      if (file_exists($cfg_local_import_dir)){
  54          $dir = opendir($cfg_local_import_dir);
  55          $filecount = 0;
  56          while ($file = readdir($dir)) {
  57           if ($file == '.' || $file == '..') continue;
  58           $filedata = explode(".", $file);
  59           $filpartcount = count($filedata);
  60           $ext_key = ($filpartcount - 1);
  61           if (($filedata[$ext_key]=="gif") || ($filedata[$ext_key]=="jpg") || ($filedata[$ext_key]=="jpeg") || ($filedata[$ext_key]=="png") || ($filedata[$ext_key]=="GIF")  || ($filedata[$ext_key]=="JPG")  || ($filedata[$ext_key]=="JPEG")  || ($filedata[$ext_key]=="PNG") ){
  62               $filecount++;
  63          }
  64          }
  65  
  66      }
  67  
  68      if ($filecount < 1) {
  69          echo '<p class="errortxt">ERROR: The local import directory ('.$cfg_local_import_dir.') does not contain any valid image files.</p>';
  70  
  71      } else {
  72  
  73  ?>
  74  
  75  <p>The local import tool allows you to import images that have been FTPed to the webserver.  (This can be helpful in cases where there are large numbers of images to be imported.  The information in the additional fields will be applied to all images.  All additional fields are optional.</p>
  76  <form method="post" action="local.php">
  77  <center>
  78  <table border="0" cellspacing="1" cellpadding="3" bgcolor="#999999">
  79  <tr>
  80      <td colspan="2" class="resultline"><b>Local File Import Settings</b></td>
  81  </tr>
  82  
  83  <tr>
  84      <td class="resultline-alt" valign="top"><b><?php echo $LANG_ADMIN_IMPORT_2; ?>:</b> </td>
  85      <td class="resultline-alt">
  86      
  87      <?php
  88      
  89          $sql ="select id, name from snipe_gallery_cat where cat_parent='0' order by name asc";
  90          $get_options = mysql_query($sql);    
  91          $num_options = mysql_num_rows($get_options);   
  92          echo '<select name="gallery_id">';
  93  
  94          // our category is apparently valid, so go ahead...           
  95          if ($num_options > 0) {              
  96              while (list($cat_id, $cat_name) = mysql_fetch_row($get_options)) { 
  97  
  98                  $sql ="select id, name from snipe_gallery_cat where cat_parent='".$cat_id."' order by name asc";
  99                  $get_suboptions = mysql_query($sql);    
 100                  $num_suboptions = mysql_num_rows($get_suboptions);
 101                  if ($num_suboptions > 0) {
 102                      while (list($subcat_id, $subcat_name) = mysql_fetch_row($get_suboptions)) { 
 103                  
 104                      echo "<option value=\"".$subcat_id."\">".stripslashes($cat_name).":: ".stripslashes($subcat_name)."</option>\n";
 105                      }
 106                  }
 107  
 108              }
 109              echo ' </select>';
 110                             
 111                                             
 112          }
 113      ?>    
 114      </td>
 115  </tr>
 116  <tr>
 117      <td class="resultline-alt" valign="top">Import Directory: </td>
 118      <td class="resultline-alt"><?php echo $cfg_local_import_dir; ?> (<?php echo $filecount; ?> files)</td>
 119  </tr>
 120  <tr>
 121      <td class="resultline-alt" valign="top"><?php echo $LANG_IMG_FIELD[1]; ?>: </td>
 122      <td class="resultline-alt"><input type="text" name="form_author" maxlength="100" size="30"></td>
 123  </tr>
 124  <tr>
 125      <td class="resultline-alt" valign="top"><?php echo $LANG_IMG_FIELD[2]; ?>: </td>
 126      <td class="resultline-alt"><input type="text" name="form_location" maxlength="255" size="30"></td>
 127  </tr>
 128  <tr>
 129      <td class="resultline-alt" valign="top"><?php echo $LANG_IMG_FIELD[3]; ?>: </td>
 130      <td class="resultline-alt"><textarea name="form_details" rows="4" cols="50"></textarea></td>
 131  </tr>
 132  <tr>
 133      <td class="resultline-alt" valign="top"><?php echo $LANG_IMG_FIELD[4]; ?>: </td>
 134      <td class="resultline-alt"><input type="text" name="form_keywords" maxlength="255" size="30"></td>
 135  </tr>
 136  <tr>
 137      <td class="resultline-alt" valign="top" colspan="2">
 138      <input type="checkbox" name="make_thumbs" value="1" checked="checked"><?php echo $LANG_IMG_FIELD[10]; ?>?
 139      </td>
 140  </tr>
 141  
 142  <tr>
 143      <td class="resultline-alt" valign="top" colspan="2">
 144      <input type="checkbox" name="keep_filedate" value="1"><?php echo $LANG_IMG_FIELD[11]; ?>
 145      </td>
 146  </tr>
 147  
 148  <?php 
 149  if ($cfg_use_iptc_meta==1) {
 150  ?>
 151  
 152  <tr>
 153      <td class="resultline-alt" valign="top">IPTC Meta Data: </td>
 154      <td class="resultline-alt">
 155      <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>
 156      <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>
 157      <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> 
 158      <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>
 159      <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>
 160      <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>
 161      <span class="smadmin">(NOTE: IPTC values will override user-entered fields if selected)</span>
 162  </td>
 163  </tr>
 164  <?php } ?>
 165  
 166  <tr>
 167      <td class="resultline-alt" valign="top" colspan="2">
 168      <input type="checkbox" name="form_publish" value="1" value="1" checked="checked">Publish?
 169      </td>
 170  </tr>
 171  
 172  <tr>
 173      <td colspan="2" class="resultline" align="right"><div align="right">
 174      <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();">    
 175      <input type="hidden" name="action" value="upload">
 176      
 177      </div></td>
 178  </tr>
 179  </table>
 180  </center>
 181  </form>
 182  
 183  <?php
 184  }
 185  }
 186  } elseif ($_POST['action']=="upload") {
 187  
 188          $dir = opendir($cfg_local_import_dir);
 189              while ($file = readdir($dir)) {
 190                  if ($file == '.' || $file == '..') continue;
 191                  $time = filemtime($cfg_local_import_dir."/".$file);        
 192                  $total_files++;
 193                  if ($uploaded_img_size = getimagesize($cfg_local_import_dir."/".$file, $info)) {
 194                      $img_width = $uploaded_img_size[0];
 195                      $img_height= $uploaded_img_size[1];
 196                      
 197  
 198                      /**
 199                      * Find out the file type
 200                      */                
 201                      if ($uploaded_img_size[2]==1) {
 202                          $img_ext = ".gif";
 203                          $img_filetype_err = 0;                        
 204                          
 205                      } elseif ($uploaded_img_size[2]==2) {
 206                            $img_ext = ".jpg";
 207                            $img_filetype_err = 0;
 208  
 209                      } elseif ($uploaded_img_size[2]==3) {
 210                            $img_ext = ".png";
 211                            $img_filetype_err = 0;
 212  
 213                      } elseif ($uploaded_img_size[2]==4) {
 214                            $img_ext = ".swf";
 215                            $img_filetype_err = 0;
 216  
 217                      } else {
 218                          $img_filetype_err = 1;        
 219                          
 220                      }                            
 221  
 222                      
 223                      
 224  
 225                      /**
 226                      * Make sure IPTC is enabled - and if it is, get the data from the uploaded file
 227                      */
 228  
 229                      if ($cfg_use_iptc_meta==1) {
 230                      $iptc = iptcparse($info["APP13"]);
 231                          if (is_array($iptc)) { 
 232                              $form_location='';
 233  
 234                              if ($_POST['iptc_title_override']==1) {
 235                                  $form_image_title = $iptc["2#105"][0];
 236                              } else {
 237                                  $form_image_title = $_POST['form_image_title'];
 238                              }
 239  
 240                              if ($_POST['iptc_caption_override']==1) {
 241                                  $form_details = $iptc["2#120"][0];
 242                              } else {
 243                                  $form_details = $_POST['form_details'];
 244                              }
 245  
 246                              if ($_POST['iptc_author_override']==1) {
 247                                  $form_author = $iptc["2#080"][0];
 248                              } else {
 249                                  $form_author = $_POST['form_author'];
 250                              }
 251  
 252                              if ($_POST['iptc_loc_override']==1) {
 253                                  if (!empty($iptc["2#090"][0])) {
 254                                      $form_location .=  $iptc["2#090"][0];
 255                                      if (!empty($iptc["2#095"][0])) {
 256                                          $form_location .=", ";
 257                                      }
 258                                  }
 259                                  if (!empty($iptc["2#095"][0])) {
 260                                      $form_location .= $iptc["2#095"][0]." ";
 261                                  }
 262                                  if (!empty($iptc_country)) {
 263                                      $form_location .= $iptc["2#101"][0];
 264                                  }
 265                              
 266                              } else {
 267                                  $form_location = $_POST['form_location'];
 268                              }
 269  
 270  
 271                              if ($_POST['iptc_keywords_override']==1) {
 272                                  $iptc_keywords = $iptc["2#025"][0];
 273  
 274                                  $c = count ($iptc["2#025"]);
 275                                  if ($c > 0) {
 276                                      $form_keywords = "";
 277                                          for ($i=0; $i <$c; $i++)  {
 278                                              $form_keywords .= $iptc["2#025"][$i].' ';
 279                                          }
 280                                  } else {
 281                                      $form_keywords = $_POST['form_keywords'];
 282                                  }
 283                              }
 284  
 285                              if ($_POST['iptc_date_override']==1) {
 286                                  $iptc_showdate = strtotime($iptc["2#055"][0]);
 287                                  $img_time = date("Y-m-d", $iptc_showdate);
 288                              }
 289                          } else {
 290                              $form_image_title = $_POST['form_image_title'];
 291                              $form_author = $_POST['form_author'];
 292                              $form_location = $_POST['form_location'];
 293                              $form_keywords = $_POST['form_keywords'];
 294                              $form_details = $_POST['form_details'];
 295                          }
 296  
 297  
 298                      /**
 299                      * If IPTC isn't enabled, assign the form fields to the variable names
 300                      */
 301                      } else {
 302                          $form_image_title = $_POST['form_image_title'];
 303                          $form_author = $_POST['form_author'];
 304                          $form_location = $_POST['form_location'];
 305                          $form_keywords = $_POST['form_keywords'];
 306                          $form_details = $_POST['form_details'];
 307                          
 308                          if ($_POST['keep_filedate']==1) {
 309                              $img_time = date("Y-m-d",$time);
 310                          } else {
 311                              $img_time = "";
 312                          }
 313                      }
 314  
 315                          $sql = "insert into snipe_gallery_data (img_date, title, details, author, location, cat_id, keywords, publish, added) values (";
 316                          $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())";
 317                          
 318                          
 319                          if ($add_image = mysql_query($sql)) {
 320                              $image_count++;
 321                              $this_image_id = mysql_insert_id();
 322                              $image_id = $this_image_id;
 323                              /*
 324                              * check to see if we should keep the original filename
 325                              */
 326                              if ($cfg_orig_filenames==1) {
 327                                  $image_filename = $file;
 328                              } else {
 329                                  $image_filename = $this_image_id."_".date("U").$img_ext;
 330                              }
 331                              
 332                              $sql = "update snipe_gallery_data set filename='".$image_filename."' where id='".$this_image_id."'";
 333                              $update_img = mysql_query($sql);        
 334                              copy($cfg_local_import_dir."/".$file, $cfg_pics_path."/".$image_filename);
 335  
 336                              /*
 337                              *    If caching is enabled, copy the new file into the cache
 338                              */
 339                              if (($cfg_use_cache==1) && (is_writable($cfg_cache_path))) {
 340                                  copy($cfg_local_import_dir."/".$file, $cfg_cache_path."/".$image_filename);
 341                              }
 342  
 343                                  /*
 344                                  * if this image can be resized, figure out what we need to do
 345                                  */
 346                                  if (($uploaded_img_size[2]==2) || ($uploaded_img_size[2]==3)) {
 347  
 348                                      /* 
 349                                      * if this is a landscape style image
 350                                      */
 351                                      if ($img_width > $img_height) {
 352  
 353                                          /*
 354                                          * if there is a ceiling on the max upload width, resize the image down
 355                                          * to the specified size
 356                                          */
 357                                          if (($cfg_use_fullsize_ceil==1) && ($img_width > $cfg_max_fullsize_width)) {
 358                                              $new_fw = $cfg_max_fullsize_width;
 359                                              $fratio = ($img_width / $new_fw); 
 360                                              $new_fh = round($img_height / $fratio);    
 361                                              $continue_resize = 1;
 362                                          }
 363  
 364                                      } else {
 365                                          if (($cfg_use_fullsize_hceil==1) && ($img_height > $cfg_max_fullsize_height)) {
 366  
 367                                              /*
 368                                              * if there is a ceiling on the max upload height, resize the image down
 369                                              * to the specified size
 370                                              */
 371                                              if (($cfg_use_fullsize_hceil==1) && ($img_height > $cfg_max_fullsize_height)) {
 372                                                  $new_fh = $cfg_max_fullsize_height;                                        
 373                                                  $fratio = ($img_height / $new_fh); 
 374                                                  $new_fw = round($img_width / $fratio);    
 375                                                  $continue_resize = 1;
 376                                              }
 377  
 378                                          }
 379  
 380                                      }                                
 381                                          
 382  
 383                                          if ($continue_resize == 1) {
 384                                              $fsrc_img = imagecreatefromjpeg($cfg_pics_path."/".$image_filename); 
 385                                              if (gd_version() >= 2) {
 386                                                  $fdst_img = imagecreatetruecolor($new_fw,$new_fh);                            imagecopyresampled($fdst_img,$fsrc_img,0,0,0,0,$new_fw,$new_fh,$img_width,$img_height);
 387                                              } else {
 388                                                  $fdst_img = imagecreate($new_fw,$new_fh);                                imagecopyresized($fdst_img,$fsrc_img,0,0,0,0,$new_fw,$new_fh,$img_width,$img_height);
 389                                              }
 390                                              
 391                                              
 392                                              if ($uploaded_img_size[2]==2) {
 393                                                  imagejpeg($fdst_img, $cfg_pics_path."/".$image_filename);
 394                                              } elseif ($uploaded_img_size[2]==3) {
 395                                                  imagepng($fdst_img, $cfg_pics_path."/".$image_filename);
 396                                              }
 397                                              imagedestroy($fdst_img);
 398                                          }
 399           
 400                                  }
 401  
 402                              if ((($uploaded_img_size[2]==2) || ($uploaded_img_size[2]==3)) && ($image_count <= $cfg_max_import_munge) && ($_POST['make_thumbs']==1))  {
 403                                      $uploaded_img_size = getimagesize($cfg_pics_path."/".$image_filename);
 404                                      $img_width = $uploaded_img_size[0];
 405                                      $img_height= $uploaded_img_size[1];
 406  
 407                                      
 408                      
 409                                      $new_w = $cfg_thumb_width;
 410                                      $ratio = ($img_width / $new_w); 
 411                                      $new_h = round($img_height / $ratio);
 412                                      /*
 413                                      * if dynamic thumbnailing
 414                                      */
 415                                      $src_img = imagecreatefromjpeg($cfg_pics_path."/".$image_filename); 
 416                                      $dst_img = imagecreatetruecolor($new_w,$new_h);                                    
 417                                      imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,$img_width, $img_height);
 418  
 419                                      $sql = "update snipe_gallery_data set thumbname='".$image_filename."' where id='".$this_image_id."'";
 420                                      $update_img = mysql_query($sql);    
 421  
 422                                      if ($uploaded_img_size[2]==2) {
 423                                          imagejpeg($dst_img, $cfg_thumb_path."/".$image_filename);
 424                                      } elseif ($uploaded_img_size[2]==3) {
 425                                          imagepng($dst_img, $cfg_thumb_path."/".$image_filename);
 426                                      }
 427                              }
 428  
 429                              /* 
 430                              * if we have to cache the image, make a copy of it in the cache
 431                              * directory specified in the config file
 432                              */
 433                              if (($cfg_use_cache==1) && (!empty($this_watermark_txt)) && (file_exists($cfg_cache_path)) && (is_writable($cfg_cache_path))) {
 434                                  copy($cfg_pics_path."/".$image_filename, $cfg_cache_path."/".$image_filename);
 435                                  
 436                              }         
 437                              unlink($cfg_local_import_dir."/".$file);
 438  
 439                          }
 440                          
 441                          $filelist .= "<li>".$file;
 442                          $numfiles++;
 443                      }    
 444                  }
 445  
 446                  if ($numfiles < 1) {                                                     
 447                                  
 448                      echo "<h3>No valid images found</h3>";
 449                      echo '<p>ERROR - no valid gif, jpg or png images detected.</p>';
 450                  } else {
 451                      echo "<h3>Files Imported</h3>";
 452                      echo "<p>Success - ".$numfiles." images were imported.</p>";
 453                      echo $filelist;
 454                      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>";
 455                  
 456                  
 457                  }
 458                  
 459  
 460              
 461          }
 462  
 463  
 464  
 465  include  ("../layout/admin.footer.php");   ?>    


[ Powered by PHPXref - Served by Debian GNU/Linux ]