Index: /extensions/upload_form/include/functions_upload.inc.php
===================================================================
--- /extensions/upload_form/include/functions_upload.inc.php	(revision 4739)
+++ /extensions/upload_form/include/functions_upload.inc.php	(revision 4739)
@@ -0,0 +1,250 @@
+<?php
+// TODO
+// * check md5sum (already exists?)
+
+include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
+include_once(PHPWG_ROOT_PATH.'include/ws_functions.inc.php');
+include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+
+// Here is the plan
+//
+// 1) move uploaded file to upload/2010/01/22/20100122003814-449ada00.jpg
+//
+// 2) if taller than max_height or wider than max_width, move to pwg_high
+//    + web sized creation
+//
+// 3) thumbnail creation from web sized
+//
+// 4) register in database
+
+$page['max_width'] = 800;
+$page['max_height'] = 800;
+
+$page['thumb_width'] = 128;
+$page['thumb_height'] = 96;
+
+$page['source_file'] = '/home/pierrick/public_html/test/resize/phpthumb/examples/statue_small.jpg';
+
+function add_uploaded_file($source_filepath, $name=null, $categories=null)
+{
+  global $page;
+
+  // current date
+  list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
+  list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4);
+  
+  // upload directory hierarchy
+  $upload_dir = sprintf(
+    PHPWG_ROOT_PATH.'upload/%s/%s/%s',
+    $year,
+    $month,
+    $day
+    );
+
+  // compute file path
+  $md5sum = md5_file($source_filepath);
+  $date_string = preg_replace('/[^\d]/', '', $dbnow);
+  $random_string = substr($md5sum, 0, 8);
+  $filename_wo_ext = $date_string.'-'.$random_string;
+  $file_path = $upload_dir.'/'.$filename_wo_ext.'.jpg';
+
+  prepare_directory($upload_dir);
+  if (is_uploaded_file($source_filepath))
+  {
+    move_uploaded_file($source_filepath, $file_path);
+  }
+  else
+  {
+    copy($source_filepath, $file_path);
+  }
+
+  if (need_resize($file_path, $page['max_width'], $page['max_height']))
+  {
+    $high_path = file_path_for_type($file_path, 'high');
+    $high_dir = dirname($high_path);
+    prepare_directory($high_dir);
+    
+    rename($file_path, $high_path);
+    $high_infos = pwg_image_infos($high_path);
+    
+    pwg_image_resize($high_path, $file_path, $page['max_width'], $page['max_height']);
+  }
+
+  $file_infos = pwg_image_infos($file_path);
+  
+  $thumb_path = file_path_for_type($file_path, 'thumb');
+  $thumb_dir = dirname($thumb_path);
+  prepare_directory($thumb_dir);
+  pwg_image_resize($file_path, $thumb_path, $page['thumb_width'], $page['thumb_height']);
+  $thumb_infos = pwg_image_infos($thumb_path);
+
+  // database registration
+  $insert = array(
+    'file' => basename($file_path),
+    'date_available' => $dbnow,
+    'tn_ext' => 'jpg',
+    'path' => $file_path,
+    'filesize' => $file_infos['filesize'],
+    'width' => $file_infos['width'],
+    'height' => $file_infos['height'],
+    'md5sum' => $md5sum,
+    );
+
+  if (isset($name))
+  {
+    $insert['name'] = $name;
+  }
+
+  if (isset($high_infos))
+  {
+    $insert['has_high'] = 'true';
+    $insert['high_filesize'] = $high_infos['filesize'];
+  }
+  
+  mass_inserts(
+    IMAGES_TABLE,
+    array_keys($insert),
+    array($insert)
+    );
+  
+  $image_id = mysql_insert_id();
+
+  if (isset($categories) and count($categories) > 0)
+  {
+    associate_images_to_categories(
+      array($image_id),
+      $categories
+      );
+  }
+  
+  // update metadata from the uploaded file (exif/iptc)
+  update_metadata(array($image_id=>$file_path));
+  
+  invalidate_user_cache();
+}
+
+function prepare_directory($directory)
+{
+  if (!is_dir($directory)) {
+    umask(0000);
+    $recursive = true;
+    if (!@mkdir($directory, 0777, $recursive))
+    {
+      die('[prepare_directory] cannot create directory "'.$directory.'"');
+    }
+  }
+
+  if (!is_writable($directory))
+  {
+    // last chance to make the directory writable
+    @chmod($directory, 0777);
+
+    if (!is_writable($directory))
+    {
+      die('[prepare_directory] directory "'.$directory.'" has no write access');
+    }
+  }
+
+  secure_directory($directory);
+}
+
+function need_resize($image_filepath, $max_width, $max_height)
+{
+  list($width, $height) = getimagesize($image_filepath);
+  
+  if ($width > $max_width or $height > $max_height)
+  {
+    return true;
+  }
+
+  return false;
+}
+
+function pwg_image_resize($source_filepath, $destination_filepath, $max_width, $max_height)
+{
+  if (!function_exists('gd_info'))
+  {
+    return false;
+  }
+
+  // extension of the picture filename
+  $extension = strtolower(get_extension($source_filepath));
+
+  $source_image = null;
+  if (in_array($extension, array('jpg', 'jpeg')))
+  {
+    $source_image = @imagecreatefromjpeg($source_filepath);
+  }
+  else if ($extension == 'png')
+  {
+    $source_image = @imagecreatefrompng($source_filepath);
+  }
+  else
+  {
+    die('unsupported file extension');
+  }
+  
+  // width/height
+  $source_width  = imagesx($source_image); 
+  $source_height = imagesy($source_image);
+  
+  $ratio_width  = $source_width / $max_width;
+  $ratio_height = $source_height / $max_height;
+  
+  // maximal size exceeded ?
+  if ($ratio_width > 1 or $ratio_height > 1)
+  {
+    if ($ratio_width < $ratio_height)
+    { 
+      $destination_width = ceil($source_width / $ratio_height);
+      $destination_height = $max_height; 
+    }
+    else
+    { 
+      $destination_width = $max_width; 
+      $destination_height = ceil($source_height / $ratio_width);
+    }
+  }
+  else
+  {
+    // the image doesn't need any resize! We just copy it to the destination
+    copy($source_filepath, $destination_filepath);
+    return true;
+  }
+  
+  $destination_image = imagecreatetruecolor($destination_width, $destination_height);
+  
+  imagecopyresampled(
+    $destination_image,
+    $source_image,
+    0,
+    0,
+    0,
+    0,
+    $destination_width,
+    $destination_height,
+    $source_width,
+    $source_height
+    );
+  
+  imagejpeg($destination_image, $destination_filepath, 95);
+  // freeing memory ressources
+  imagedestroy($source_image);
+  imagedestroy($destination_image);
+
+  // everything should be OK if we are here!
+  return true;
+}
+
+function pwg_image_infos($path)
+{
+  list($width, $height) = getimagesize($path);
+  $filesize = floor(filesize($path)/1024);
+  
+  return array(
+    'width'  => $width,
+    'height' => $height,
+    'filesize' => $filesize,
+    );
+}
+?>
Index: /extensions/upload_form/include/upload.js
===================================================================
--- /extensions/upload_form/include/upload.js	(revision 4739)
+++ /extensions/upload_form/include/upload.js	(revision 4739)
@@ -0,0 +1,18 @@
+var upload_limit = 10;
+var upload_slots = 1;
+
+function UpdateUploadSlots()
+{
+  upload_slots++;
+
+  //  if (upload_slots <= upload_limit) {
+  if (upload_slots <= upload_limit) {
+    new_slot = document.createElement("p");
+    new_slot.innerHTML = "<input  class='file' type='file' name='image_upload[]' size='70' />";
+    document.getElementById("uploadBoxes").appendChild(new_slot);
+  }
+
+  if (upload_slots >= upload_limit) {
+    document.getElementById("addUploadBox").innerHTML = '';
+  }
+}
Index: /extensions/upload_form/index.php
===================================================================
--- /extensions/upload_form/index.php	(revision 4739)
+++ /extensions/upload_form/index.php	(revision 4739)
@@ -0,0 +1,33 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery                           |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | file          : $Id: index.php 1912 2007-03-16 06:30:07Z rub $
+// | last update   : $Date: 2007-03-16 07:30:07 +0100 (ven, 16 mar 2007) $
+// | last modifier : $Author: rub $
+// | revision      : $Revision: 1912 $
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/upload_form/main.inc.php
===================================================================
--- /extensions/upload_form/main.inc.php	(revision 4739)
+++ /extensions/upload_form/main.inc.php	(revision 4739)
@@ -0,0 +1,33 @@
+<?php
+/*
+Plugin Name: Upload Form
+Version: 2.0.a
+Description: A web uploader with "web sized" + thumbnail generation, multiple files, progress bar...
+Plugin URI: http://piwigo.org/ext/extension_view.php?eid=350
+Author: plg
+Author URI: http://piwigo.wordpress.com
+*/
+
+if (!defined('PHPWG_ROOT_PATH'))
+{
+  die('Hacking attempt!');
+}
+
+define('UPLOAD_FORM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
+
+/* Plugin admin */
+add_event_handler('get_admin_plugin_menu_links', 'upload_form_admin_menu');
+
+function upload_form_admin_menu($menu)
+{
+  array_push(
+    $menu,
+    array(
+      'NAME' => 'Upload Form',
+      'URL'  => get_admin_plugin_menu_link(dirname(__FILE__).'/upload.php')
+      )
+    );
+
+  return $menu;
+}
+?>
Index: /extensions/upload_form/upload.php
===================================================================
--- /extensions/upload_form/upload.php	(revision 4739)
+++ /extensions/upload_form/upload.php	(revision 4739)
@@ -0,0 +1,96 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2009      Pierrick LE GALL             http://piwigo.org |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+if( !defined("PHPWG_ROOT_PATH") )
+{
+  die ("Hacking attempt!");
+}
+
+include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+include_once(UPLOAD_FORM_PATH.'include/functions_upload.inc.php');
+// load_language('plugin.lang', COMMUNITY_PATH);
+
+$admin_base_url = get_root_url().'admin.php?page=plugin&section=upload_form%2Fupload.php';
+
+// +-----------------------------------------------------------------------+
+// | Check Access and exit when user status is not ok                      |
+// +-----------------------------------------------------------------------+
+check_status(ACCESS_ADMINISTRATOR);
+
+// +-----------------------------------------------------------------------+
+// |                               functions                               |
+// +-----------------------------------------------------------------------+
+
+if (isset($_POST['submit_upload']))
+{
+  // echo '<pre>'; print_r($_FILES); echo '</pre>'; exit();
+  
+  $starttime = get_moment();
+  
+  foreach ($_FILES['image_upload']['error'] as $idx => $error)
+  {
+    if (UPLOAD_ERR_OK == $error)
+    {
+      $source_filepath = $_FILES['image_upload']['tmp_name'][$idx];
+      $name = $_FILES['image_upload']['name'][$idx];
+      add_uploaded_file($source_filepath, $name, array($_POST['category']));
+    }
+  }
+  
+  $endtime = get_moment();
+  $elapsed = ($endtime - $starttime) * 1000;
+  // printf('%.2f ms', $elapsed);
+}
+
+// +-----------------------------------------------------------------------+
+// |                             template init                             |
+// +-----------------------------------------------------------------------+
+
+$template->set_filenames(
+  array(
+    'plugin_admin_content' => dirname(__FILE__).'/upload.tpl'
+    )
+  );
+
+$template->assign(
+    array(
+      'F_ADD_ACTION'=> $admin_base_url,
+      'plugin_path' => UPLOAD_FORM_PATH,
+    )
+  );
+
+$query = '
+SELECT id,name,uppercats,global_rank
+  FROM '.CATEGORIES_TABLE.'
+;';
+
+display_select_cat_wrapper(
+  $query,
+  array(),
+  'category_options'
+  );
+
+// +-----------------------------------------------------------------------+
+// |                           sending html code                           |
+// +-----------------------------------------------------------------------+
+
+$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
+?>
Index: /extensions/upload_form/upload.tpl
===================================================================
--- /extensions/upload_form/upload.tpl	(revision 4739)
+++ /extensions/upload_form/upload.tpl	(revision 4739)
@@ -0,0 +1,49 @@
+<script type="text/javascript" src="{$plugin_path}/include/upload.js"></script>
+
+{literal}
+<style>
+#uploadBoxes P {
+  margin:0;
+  margin-bottom:2px;
+  padding:0;
+}
+</style>
+{/literal}
+
+<div class="titrePage">
+  <h2>{'Upload Form'|@translate}</h2>
+</div>
+
+<form enctype="multipart/form-data" method="post" action="{$F_ACTION}" class="properties">
+  <fieldset>
+    <legend>{'Upload Photos'|@translate}</legend>
+
+    <table>
+      <tr>
+        <td>{'Drop into category'|@translate}</td>
+        <td>
+          <select class="categoryDropDown" name="category">
+            <option value="0">------------</option>
+            {html_options options=$category_options}
+          </select>
+        </td>
+      </tr>
+
+      <tr>
+        <td colspan="2">
+          <div id="uploadBoxes">
+            <p><input class="file" type="file" size="70" name="image_upload[]" /></p>
+          </div>
+          <div id="addUploadBox">
+            <a href="javascript: UpdateUploadSlots()">+ Add an upload box</a>
+          </div>
+        </td>
+      </tr>
+      
+    </table>
+    
+    <p>
+      <input class="submit" type="submit" name="submit_upload" value="{'Upload'|@translate}" {$TAG_INPUT_ENABLED}/>
+    </p>
+  </fieldset>
+</form>
