Index: /extensions/virtualize/admin.php
===================================================================
--- /extensions/virtualize/admin.php	(revision 9562)
+++ /extensions/virtualize/admin.php	(revision 9562)
@@ -0,0 +1,170 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2011      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');
+
+$admin_base_url = get_root_url().'admin.php?page=plugin&section=virtualize%2Fadmin.php';
+load_language('plugin.lang', dirname(__FILE__).'/');
+
+// +-----------------------------------------------------------------------+
+// | Check Access and exit when user status is not ok                      |
+// +-----------------------------------------------------------------------+
+
+check_status(ACCESS_ADMINISTRATOR);
+
+// +-----------------------------------------------------------------------+
+// |                            add permissions                            |
+// +-----------------------------------------------------------------------+
+
+if (isset($_POST['submit']))
+{
+  $query = '
+SELECT
+    path AS oldpath,
+    date_available,
+    has_high,
+    tn_ext,
+    id
+  FROM '.IMAGES_TABLE.'
+  WHERE path NOT LIKE \'./upload/%\'
+;';
+  $result = pwg_query($query);
+  while ($row = pwg_db_fetch_assoc($result))
+  {
+    $file_for_md5sum  = $row['oldpath'];
+    if ('true' == $row['has_high'])
+    {
+      $file_for_md5sum = dirname($row['oldpath']).'/pwg_high/'.basename($row['oldpath']);
+    }
+    $md5sum = md5_file($file_for_md5sum);
+
+    list($year, $month, $day, $hour, $minute, $second) = preg_split('/[^\d]+/', $row['date_available']);
+
+    $upload_dir = './upload/'.$year.'/'.$month.'/'.$day;
+    if (!is_dir($upload_dir))
+    {
+      umask(0000);
+      $recursive = true;
+      if (!@mkdir($upload_dir, 0777, $recursive))
+      {
+        echo 'error during "'.$upload_dir.'" directory creation';
+        exit();
+      }
+    }
+    secure_directory($upload_dir);
+
+    $newfilename = $year.$month.$day.$hour.$minute.$second.'-'.substr($md5sum, 0, 8).'.jpg';
+
+    $newpath = $upload_dir.'/'.$newfilename;
+
+    $query = '
+UPDATE '.IMAGES_TABLE.'
+  SET path = \''.$newpath.'\',
+      storage_category_id = NULL
+  WHERE id = '.$row['id'].'
+;';
+    pwg_query($query);
+
+    rename($row['oldpath'], $newpath);
+
+    # high definition
+    if ('true' == $row['has_high'])
+    {
+      $high_dir = $upload_dir.'/pwg_high';
+      
+      if (!is_dir($high_dir))
+      {
+        umask(0000);
+        $recursive = true;
+        if (!@mkdir($high_dir, 0777, $recursive))
+        {
+          echo 'error during "'.$high_dir.'" directory creation';
+          exit();
+        }
+      }
+      
+      rename(
+        dirname($row['oldpath']).'/pwg_high/'.basename($row['oldpath']),
+        $high_dir.'/'.$newfilename
+        );
+    }
+
+    # thumbnail
+    $tn_dir = $upload_dir.'/thumbnail';
+
+    if (!is_dir($tn_dir))
+    {
+      umask(0000);
+      $recursive = true;
+      if (!@mkdir($tn_dir, 0777, $recursive))
+      {
+        echo 'error during "'.$tn_dir.'" directory creation';
+        exit();
+      }
+    }
+
+    $tn_oldname = $conf['prefix_thumbnail'];
+    $tn_oldname.= get_filename_wo_extension(basename($row['oldpath']));
+    $tn_oldname.= '.'.$row['tn_ext'];
+    
+    rename(
+      dirname($row['oldpath']).'/thumbnail/'.$tn_oldname,
+      $tn_dir.'/'.$conf['prefix_thumbnail'].$newfilename
+      );
+    
+    // break;
+  }
+
+  $query = '
+UPDATE '.CATEGORIES_TABLE.'
+  SET dir = NULL
+;';
+  pwg_query($query);
+}
+
+
+// +-----------------------------------------------------------------------+
+// |                             template init                             |
+// +-----------------------------------------------------------------------+
+
+$template->set_filenames(
+  array(
+    'plugin_admin_content' => dirname(__FILE__).'/admin.tpl'
+    )
+  );
+
+$template->assign(
+    array(
+      'F_ADD_ACTION'=> $admin_base_url,
+    )
+  );
+
+// +-----------------------------------------------------------------------+
+// |                           sending html code                           |
+// +-----------------------------------------------------------------------+
+
+$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
+?>
Index: /extensions/virtualize/admin.tpl
===================================================================
--- /extensions/virtualize/admin.tpl	(revision 9562)
+++ /extensions/virtualize/admin.tpl	(revision 9562)
@@ -0,0 +1,24 @@
+{literal}
+<style>
+.warnings {padding-bottom:5px; -moz-border-radius:5px;}
+.warnings li {margin-bottom:5px}
+</style>
+{/literal}
+
+<div class="titrePage">
+  <h2>Virtualize</h2>
+</div>
+
+<div class="warnings">
+  <ul>
+    <li>{'This plugin moves all your photos from <em>"galleries"</em> (added with the synchronization process) to <em>"upload"</em> and mark categories as virtual.'|@translate}</li>
+    <li>{'Make sure you have a backup of your <em>"galleries"</em> directory and a dump of your database.'|@translate}</li>
+    <li>{'Once categories are virtual, you can move them the way you want.'|@translate}</li>
+  </ul>
+</div>
+
+<form method="post" name="virtualize" action="{$F_ADD_ACTION}" class="properties">
+  <p>
+    <input class="submit" type="submit" name="submit" value="{'Start to virtualize'|@translate}"/>
+  </p>
+</form>
Index: /extensions/virtualize/language/en_UK/description.txt
===================================================================
--- /extensions/virtualize/language/en_UK/description.txt	(revision 9562)
+++ /extensions/virtualize/language/en_UK/description.txt	(revision 9562)
@@ -0,0 +1,1 @@
+Make categories virtual and move photos from "galleries" to "upload"
Index: /extensions/virtualize/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/virtualize/language/en_UK/plugin.lang.php	(revision 9562)
+++ /extensions/virtualize/language/en_UK/plugin.lang.php	(revision 9562)
@@ -0,0 +1,26 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2011      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.                                                                  |
+// +-----------------------------------------------------------------------+
+
+$lang['This plugin moves all your photos from <em>"galleries"</em> (added with the synchronization process) to <em>"upload"</em> and mark categories as virtual.'] = 'This plugin moves all your photos from <em>"galleries"</em> (added with the synchronization process) to <em>"upload"</em> and mark categories as virtual.';
+$lang['Make sure you have a backup of your <em>"galleries"</em> directory and a dump of your database.'] = 'Make sure you have a backup of your <em>"galleries"</em> directory and a dump of your database.';
+$lang['Once categories are virtual, you can move them the way you want.'] = 'Once categories are virtual, you can move them the way you want.';
+$lang['Start to virtualize'] = 'Start to virtualize';
+?>
Index: /extensions/virtualize/language/fr_FR/description.txt
===================================================================
--- /extensions/virtualize/language/fr_FR/description.txt	(revision 9562)
+++ /extensions/virtualize/language/fr_FR/description.txt	(revision 9562)
@@ -0,0 +1,1 @@
+Rend les catégories virtuelles et déplace les photos de "galleries" vers "upload"
Index: /extensions/virtualize/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/virtualize/language/fr_FR/plugin.lang.php	(revision 9562)
+++ /extensions/virtualize/language/fr_FR/plugin.lang.php	(revision 9562)
@@ -0,0 +1,26 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2011      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.                                                                  |
+// +-----------------------------------------------------------------------+
+
+$lang['This plugin moves all your photos from <em>"galleries"</em> (added with the synchronization process) to <em>"upload"</em> and mark categories as virtual.'] = 'Ce plugin déplace toutes vos photos du répertoire <em>"galleries"</em> (ajoutées par synchronisation) vers <em>"upload"</em> et déclare les catégories virtuelles.';
+$lang['Make sure you have a backup of your <em>"galleries"</em> directory and a dump of your database.'] = 'Assurez vous d\'avoir une sauvegarde de votre répertoire <em>"galleries"</em> ainsi qu\'un dump de votre base de données.';
+$lang['Once categories are virtual, you can move them the way you want.'] = 'Une fois que vos catégories sont virtuelles, vous pouvez les déplacer comme cela vous chante.';
+$lang['Start to virtualize'] = 'Démarrer la virtualisation';
+?>
Index: /extensions/virtualize/main.inc.php
===================================================================
--- /extensions/virtualize/main.inc.php	(revision 9562)
+++ /extensions/virtualize/main.inc.php	(revision 9562)
@@ -0,0 +1,32 @@
+<?php
+/*
+Plugin Name: Virtualize
+Version: 2.1.a
+Description: Make categories virtual and move photos from "galleries" to "upload"
+Plugin URI: http://piwigo.org/ext/extension_view.php?eid=
+Author: plg
+Author URI: http://piwigo.wordpress.com
+*/
+
+if (!defined('PHPWG_ROOT_PATH'))
+{
+  die('Hacking attempt!');
+}
+
+// define('COMMUNITY_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
+
+/* Plugin admin */
+add_event_handler('get_admin_plugin_menu_links', 'virtualize_admin_menu');
+function virtualize_admin_menu($menu)
+{
+  array_push(
+    $menu,
+    array(
+      'NAME' => 'Virtualize',
+      'URL'  => get_admin_plugin_menu_link(dirname(__FILE__).'/admin.php')
+      )
+    );
+
+  return $menu;
+}
+?>
