Index: extensions/Synchronize_local_directory/README
===================================================================
--- extensions/Synchronize_local_directory/README	(revision 12844)
+++ extensions/Synchronize_local_directory/README	(revision 12844)
@@ -0,0 +1,8 @@
+This is a beta version!!!
+
+- When the plugin needs to create severall 1000 new thumbnails, it can happen, that it time outs.
+Just execute it again. It won't recreate thumbnails which already exist.
+
+- It doesn't create thumbnails of movies yet. Actually that's a bit complicated to to, since piwigo (for what ever reason) expects movies not to be in the pwg_high dir, but in the websized dir.
+
+- adjust in synchronlizeLocaldirectory.php the variables "sync_source_dir" and "piwigo_gallery_dir"
Index: extensions/Synchronize_local_directory/SynchronizeLocalDirectory.php
===================================================================
--- extensions/Synchronize_local_directory/SynchronizeLocalDirectory.php	(revision 12844)
+++ extensions/Synchronize_local_directory/SynchronizeLocalDirectory.php	(revision 12844)
@@ -0,0 +1,168 @@
+<?php
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+#include_once(PHPWG_ROOT_PATH.'include/common.inc.php' );
+include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php');
+include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
+
+class SynchronizeLocalDirectory
+{
+    public $cnt_new_dir = 0;
+    public $cnt_new_images = 0;
+    public $cnt_new_thumbnails = 0;
+    public $debug = '';
+    
+    private $high_res_dir = 'pwg_high';
+
+    
+    function rglob($pattern='*', $flags = 0, $path='')
+    {
+         $paths=glob($path.'*', GLOB_MARK|GLOB_ONLYDIR|GLOB_NOSORT);
+         $files=glob($path.$pattern, $flags);
+         foreach ($paths as $path) { $files=array_merge($files,$this->rglob($pattern, $flags, $path)); }
+         sort($files);
+         return $files;
+    }
+
+    function directory_contains_files($path)
+    {
+        $files = glob($path.'*');
+        $found_files = false;
+        foreach($files as $file)
+        {
+            if (!is_dir($file))
+            {
+                $found_files = true;
+                break;
+            }
+        }
+        return $found_files;
+    }
+    
+    function create_thumbnail($high_res_file, $dest_file)
+    {
+	global $conf;
+	#copied this code from piwigo core. why is there no function to do that???
+	#TODO: overwrite the thumbnail, if the high_res_file is newer than the thumbnail.
+	if (! file_exists($dest_file))
+	{
+	    $img = new pwg_image($high_res_file);
+	    $img->pwg_resize(
+		$dest_file,
+		$conf['upload_form_thumb_maxwidth'],
+		$conf['upload_form_thumb_maxheight'],
+		$conf['upload_form_thumb_quality'],
+		false,
+		true,
+		$conf['upload_form_thumb_crop'],
+		$conf['upload_form_thumb_follow_orientation']
+	    );
+	    $this->cnt_new_thumbnails++;
+            $img->destroy();
+	}
+    }
+
+    function create_websize_image($high_res_file, $dest_file)
+    {
+	global $conf;
+	#TODO: overwrite the websizedimage, if the high_res_file is newer than the websized image.
+	if (! file_exists($dest_file))
+	{
+	    $img = new pwg_image($high_res_file);
+	    $img->pwg_resize(
+		$dest_file,
+    		$conf['upload_form_websize_maxwidth'],
+    		$conf['upload_form_websize_maxheight'],
+    		$conf['upload_form_websize_quality'],
+    		$conf['upload_form_automatic_rotation'],
+	        false
+    	    );
+            $img->destroy();
+    	}
+    }
+    
+    function create_resized_images($base_path)
+    {
+	global $conf;
+	$high_res_path = $base_path.'/'.$this->high_res_dir;
+        $files = glob($high_res_path.'/*');
+        foreach($files as $file)
+        {
+            if (!is_dir($file))
+            {
+        	if (in_array(pathinfo($file, PATHINFO_EXTENSION), $conf['picture_ext']))
+        	{
+        	    $web_size_file = $base_path.'/'.basename($file);
+		    $thumb_file = file_path_for_type($web_size_file, 'thumb');
+        	
+        	    #TODO: integreate the two functions below in one, or directly add a pwg_image object as parameter 
+        	    #(dont know how much time it needs to instanziate this object two times, like its done now)
+		    $this->create_thumbnail($file, $thumb_file);
+		    $this->create_websize_image($file, $web_size_file);
+		} #TODO: also create thumbnails for videos
+            }
+        }
+    }
+    
+    function synchronize()
+    {
+	global $conf;
+        $sync_source_dir = '/home/gallery2/albums/Reise08';
+        $piwigo_gallery_dir = '/var/lib/piwigo/galleries/Reise08';
+        #$piwigo_gallery_dir = '/tmp/test';
+
+	#counters:
+
+        $sync_source_dirs = $this->rglob('*',GLOB_MARK|GLOB_ONLYDIR,$sync_source_dir);
+        $piwigo_dirs = $this->rglob('*',GLOB_MARK|GLOB_ONLYDIR,$piwigo_gallery_dir);
+
+        #remove dir prefixes
+        # TODO: if you have dirs with a "%" in your filename this will fail
+        $sync_source_dirs = preg_replace("%$sync_source_dir%", '', $sync_source_dirs);
+        $piwigo_dirs = preg_replace("%$piwigo_gallery_dir%", '', $piwigo_dirs);
+
+        reset($piwigo_dirs);
+        foreach ($sync_source_dirs as $source_dir)
+        {
+            $piwigo_dir = current($piwigo_dirs);
+            # dont use the thumbnail or highres dirs for comparison
+            while (basename($piwigo_dir) == $conf['dir_thumbnail'] || basename($piwigo_dir) == $this->high_res_dir)
+            {
+                next($piwigo_dirs);
+                $piwigo_dir = current($piwigo_dirs);
+            }
+
+            while (strcmp($source_dir, $piwigo_dir) > 0)
+            {
+                #TODO: there is a dir in piwigo, which doesnt exist in the source. Delete it in piwigo.
+                next($piwigo_dirs);
+                $piwigo_dir = current($piwigo_dirs);
+            }
+
+            if (strcmp($source_dir, $piwigo_dir) == 0) #equal
+            {
+                #TODO: do a comparison if there are deleted files in the source directory
+                #check if there are new files in the source directory
+                $this->create_resized_images($piwigo_gallery_dir.'/'.$source_dir);
+
+                next($piwigo_dirs);
+            } else
+            {
+                #There is a dir in the source which doesnt exist in piwigo yet. create it!
+                mkdir($piwigo_gallery_dir.'/'.$source_dir, 0775);
+                # create the thumbnail dir and a symlink to the high resolution dir, if there are files
+                # in this dir.
+                if ($this->directory_contains_files($sync_source_dir.'/'.$source_dir))
+                {
+                    mkdir($piwigo_gallery_dir.'/'.$source_dir.'/'.$conf['dir_thumbnail'], 0775);
+                    symlink($sync_source_dir.'/'.$source_dir, $piwigo_gallery_dir.'/'.$source_dir.'/'.$this->high_res_dir);
+                    $this->cnt_new_dir++;
+                    $this->create_resized_images($piwigo_gallery_dir.'/'.$source_dir);
+                }
+            }
+        }
+    }
+}
+?>
+
Index: extensions/Synchronize_local_directory/admin.php
===================================================================
--- extensions/Synchronize_local_directory/admin.php	(revision 12844)
+++ extensions/Synchronize_local_directory/admin.php	(revision 12844)
@@ -0,0 +1,25 @@
+<?php
+// Chech whether we are indeed included by Piwigo.
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+// Fetch the template.
+global $template;
+
+// Add our template to the global template
+$template->set_filenames(
+  array(
+    'plugin_admin_content' => dirname(__FILE__).'/admin.tpl'
+  )
+);
+
+
+include_once dirname(__FILE__).'/SynchronizeLocalDirectory.php';
+$sync = new SynchronizeLocalDirectory();
+$sync->synchronize();
+
+// Assign the template contents to ADMIN_CONTENT
+
+$template->assign('synchronizeLocalDirectory_output', $sync->debug);
+
+$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
+?>
Index: extensions/Synchronize_local_directory/admin.tpl
===================================================================
--- extensions/Synchronize_local_directory/admin.tpl	(revision 12844)
+++ extensions/Synchronize_local_directory/admin.tpl	(revision 12844)
@@ -0,0 +1,12 @@
+<!-- Show the title of the plugin -->
+<div class="titlePage">
+  <h2>{'Synchronize Local Directory plugin'|@translate}</h2>
+</div>
+
+<!-- Show content in a nice box -->
+<fieldset>
+  <legend>{'A minimal plugin'|@translate}</legend>
+
+  {'Hello world!'|@translate}
+  {$synchronizeLocalDirectory_output}
+</fieldset>
Index: extensions/Synchronize_local_directory/include/index.php
===================================================================
--- extensions/Synchronize_local_directory/include/index.php	(revision 12844)
+++ extensions/Synchronize_local_directory/include/index.php	(revision 12844)
@@ -0,0 +1,7 @@
+<?php
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: extensions/Synchronize_local_directory/index.php
===================================================================
--- extensions/Synchronize_local_directory/index.php	(revision 12844)
+++ extensions/Synchronize_local_directory/index.php	(revision 12844)
@@ -0,0 +1,7 @@
+<?php
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: extensions/Synchronize_local_directory/language/index.php
===================================================================
--- extensions/Synchronize_local_directory/language/index.php	(revision 12844)
+++ extensions/Synchronize_local_directory/language/index.php	(revision 12844)
@@ -0,0 +1,7 @@
+<?php
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: extensions/Synchronize_local_directory/main.inc.php
===================================================================
--- extensions/Synchronize_local_directory/main.inc.php	(revision 12844)
+++ extensions/Synchronize_local_directory/main.inc.php	(revision 12844)
@@ -0,0 +1,31 @@
+<?php
+/*
+Version: 1.0
+Plugin Name: Synchronize local directory
+Plugin URI: 
+Author: RMM
+Description: Synchronizes the piwigo gallery structure with a directory structure outside from piwigo and creates the necessay thumbnails and websized pictures. No Pictures are copied, the directories are only symlinked.
+*/
+
+// Chech whether we are indeed included by Piwigo.
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+// Define the path to our plugin.
+define('SKELETON_PATH', PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
+
+// Hook on to an event to show the administration page.
+add_event_handler('get_admin_plugin_menu_links', 'synchronize_local_directory_admin_menu');
+
+// Add an entry to the 'Plugins' menu.
+function synchronize_local_directory_admin_menu($menu) {
+  array_push(
+    $menu,
+    array(
+      'NAME'  => 'Synchronize local directory',
+      'URL'   => get_admin_plugin_menu_link(dirname(__FILE__)).'/admin.php'
+    )
+  );
+  return $menu;
+}
+
+?>
Index: extensions/Synchronize_local_directory/maintain.inc.php
===================================================================
--- extensions/Synchronize_local_directory/maintain.inc.php	(revision 12844)
+++ extensions/Synchronize_local_directory/maintain.inc.php	(revision 12844)
@@ -0,0 +1,11 @@
+function plugin_install() {
+// Put anything here that should be executed during installation.
+}
+
+function plugin_activate() {
+// Put anything here that should be executed during activation.
+}
+
+function plugin_uninstall() {
+// Put anything here that should be executed during uninstallation.
+}
