Index: /trunk/admin/include/updates.class.php
===================================================================
--- /trunk/admin/include/updates.class.php	(revision 12801)
+++ /trunk/admin/include/updates.class.php	(revision 12802)
@@ -317,5 +317,5 @@
     include(PHPWG_ROOT_PATH.'admin/include/mysqldump.php');
 
-    $path = $conf['local_data_dir'].'/update';
+    $path = PHPWG_ROOT_PATH.$conf['data_location'].'update';
 
     if (@mkgetdir($path)
@@ -351,5 +351,5 @@
 
       @readfile($backupFile);
-      self::deltree($conf['local_data_dir'].'/update');
+      self::deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
       exit();
     }
@@ -387,5 +387,5 @@
     if (empty($page['errors']))
     {
-      $path = $conf['local_data_dir'].'/update';
+      $path = PHPWG_ROOT_PATH.$conf['data_location'].'update';
       $filename = $path.'/'.$code.'.zip';
       @mkgetdir($path);
@@ -450,5 +450,5 @@
           {
             self::process_obsolete_list($obsolete_list);
-            self::deltree($conf['local_data_dir'].'/update');
+            self::deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
             invalidate_user_cache(true);
             $template->delete_compiled_templates();
@@ -466,11 +466,10 @@
           else
           {
-            file_put_contents($conf['local_data_dir'].'/update/log_error.txt', $error);
-            $relative_path = trim(str_replace(dirname(dirname(dirname(dirname(__FILE__)))), '', $conf['local_data_dir']), '/\\');
+            file_put_contents(PHPWG_ROOT_PATH.$conf['data_location'].'update/log_error.txt', $error);
             array_push(
               $page['errors'],
               sprintf(
                 l10n('An error has occured during extract. Please check files permissions of your piwigo installation.<br><a href="%s">Click here to show log error</a>.'),
-                PHPWG_ROOT_PATH.$relative_path.'/update/log_error.txt'
+                get_root_url().$conf['data_location'].'update/log_error.txt'
               )
             );
@@ -479,5 +478,5 @@
         else
         {
-          self::deltree($conf['local_data_dir'].'/update');
+          self::deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
           array_push($page['errors'], l10n('An error has occured during upgrade.'));
         }
Index: /trunk/feed.php
===================================================================
--- /trunk/feed.php	(revision 12801)
+++ /trunk/feed.php	(revision 12802)
@@ -194,5 +194,5 @@
 }
 
-$fileName= $conf['local_data_dir'].'/tmp';
+$fileName= PHPWG_ROOT_PATH.$conf['data_location'].'tmp';
 mkgetdir($fileName); // just in case
 $fileName.='/feed.xml';
Index: /trunk/i.php
===================================================================
--- /trunk/i.php	(revision 12801)
+++ /trunk/i.php	(revision 12802)
@@ -27,5 +27,5 @@
 
 defined('PWG_LOCAL_DIR') or define('PWG_LOCAL_DIR', 'local/');
-defined('PWG_DERIVATIVE_DIR') or define('PWG_DERIVATIVE_DIR', PWG_LOCAL_DIR.'i/');
+defined('PWG_DERIVATIVE_DIR') or define('PWG_DERIVATIVE_DIR', $conf['data_location'].'i/');
 
 function trigger_action() {}
Index: /trunk/include/common.inc.php
===================================================================
--- /trunk/include/common.inc.php	(revision 12801)
+++ /trunk/include/common.inc.php	(revision 12802)
@@ -89,4 +89,6 @@
 include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
 @include(PHPWG_ROOT_PATH. 'local/config/config.inc.php');
+if (!isset($conf['local_data_dir'])) $conf['local_data_dir'] = realpath(PHPWG_ROOT_PATH.$conf['data_location']); // temp 2.4 for backward compatibility
+
 defined('PWG_LOCAL_DIR') or define('PWG_LOCAL_DIR', 'local/');
 
Index: /trunk/include/config_default.inc.php
===================================================================
--- /trunk/include/config_default.inc.php	(revision 12801)
+++ /trunk/include/config_default.inc.php	(revision 12802)
@@ -720,7 +720,8 @@
 $conf['light_slideshow'] = true;
 
-// the local data directory is used to store data such as compiled templates
-// or other plugin variables etc
-$conf['local_data_dir'] = dirname(dirname(__FILE__)).'/_data';
+// the local data directory is used to store data such as compiled templates,
+// plugin variables, combined css/javascript or resized images. Beware of
+// mandatory trailing slash.
+$conf['data_location'] = '_data/';
 
 // where should the API/UploadForm add photos? This path must be relative to
@@ -757,5 +758,4 @@
 $conf['derivative_url_style']=0;
 
-$conf['chmod_value']=0777;
-
+$conf['chmod_value']= substr_compare(PHP_SAPI, 'apa', 0, 3)==0 ? 0777 : 0755;
 ?>
Index: /trunk/include/constants.php
===================================================================
--- /trunk/include/constants.php	(revision 12801)
+++ /trunk/include/constants.php	(revision 12802)
@@ -28,6 +28,6 @@
 
 define('PHPWG_THEMES_PATH', $conf['themes_dir'].'/');
-defined('PWG_COMBINED_DIR') or define('PWG_COMBINED_DIR', PWG_LOCAL_DIR.'combined/');
-defined('PWG_DERIVATIVE_DIR') or define('PWG_DERIVATIVE_DIR', PWG_LOCAL_DIR.'i/');
+defined('PWG_COMBINED_DIR') or define('PWG_COMBINED_DIR', $conf['data_location'].'combined/');
+defined('PWG_DERIVATIVE_DIR') or define('PWG_DERIVATIVE_DIR', $conf['data_location'].'i/');
 
 // Required versions
Index: /trunk/include/dblayer/functions_pdo-sqlite.inc.php
===================================================================
--- /trunk/include/dblayer/functions_pdo-sqlite.inc.php	(revision 12801)
+++ /trunk/include/dblayer/functions_pdo-sqlite.inc.php	(revision 12802)
@@ -38,5 +38,5 @@
   global $conf;
 
-  $db_file = sprintf('sqlite:%s/%s.db', $conf['local_data_dir'], $database);
+  $db_file = sprintf('sqlite:%s/%s.db', PHPWG_ROOT_PATH.$conf['data_location'], $database);
 
   $link = new PDO($db_file);
Index: /trunk/include/dblayer/functions_sqlite.inc.php
===================================================================
--- /trunk/include/dblayer/functions_sqlite.inc.php	(revision 12801)
+++ /trunk/include/dblayer/functions_sqlite.inc.php	(revision 12802)
@@ -38,5 +38,5 @@
   global $conf;
 
-  $db_file = sprintf('%s/%s.db', $conf['local_data_dir'], $database);
+  $db_file = sprintf('%s/%s.db', PHPWG_ROOT_PATH.$conf['data_location'], $database);
 
   if (script_basename()=='install') 
Index: /trunk/include/functions_mail.inc.php
===================================================================
--- /trunk/include/functions_mail.inc.php	(revision 12801)
+++ /trunk/include/functions_mail.inc.php	(revision 12802)
@@ -792,5 +792,5 @@
 {
     global $conf, $user, $lang_info;
-    $dir = $conf['local_data_dir'].'/tmp';
+    $dir = PHPWG_ROOT_PATH.$conf['data_location'].'tmp';
     if ( mkgetdir( $dir,  MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR) )
     {
Index: /trunk/include/template.class.php
===================================================================
--- /trunk/include/template.class.php	(revision 12801)
+++ /trunk/include/template.class.php	(revision 12802)
@@ -60,8 +60,9 @@
     $this->smarty->force_compile = $conf['template_force_compile'];
 
-    if (!isset($conf['local_data_dir_checked']))
-    {
-      mkgetdir($conf['local_data_dir'], MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR);
-      if (!is_writable($conf['local_data_dir']))
+    if (!isset($conf['data_dir_checked']))
+    {
+      $dir = PHPWG_ROOT_PATH.$conf['data_location'];
+      mkgetdir($dir, MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR);
+      if (!is_writable($dir))
       {
         load_language('admin.lang');
@@ -69,5 +70,5 @@
           sprintf(
             l10n('Give write access (chmod 777) to "%s" directory at the root of your Piwigo installation'),
-            basename($conf['local_data_dir'])
+            $conf['data_location']
             ),
           l10n('an error happened'),
@@ -76,5 +77,5 @@
       }
       if (function_exists('pwg_query')) {
-        conf_update_param('local_data_dir_checked', 'true');
+        conf_update_param('data_dir_checked', 1);
       }
     }
@@ -82,6 +83,7 @@
     if (!isset($conf['combined_dir_checked']))
     {
-      mkgetdir(PWG_COMBINED_DIR, MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR);
-      if (!is_writable(PWG_COMBINED_DIR))
+      $dir = PHPWG_ROOT_PATH.PWG_COMBINED_DIR;
+      mkgetdir($dir, MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR);
+      if (!is_writable($dir))
       {
         load_language('admin.lang');
@@ -96,10 +98,10 @@
       }
       if (function_exists('pwg_query')) {
-        conf_update_param('combined_dir_checked', 'true');
-      }
-    }
-
-
-    $compile_dir = $conf['local_data_dir'].'/templates_c';
+        conf_update_param('combined_dir_checked', 1);
+      }
+    }
+
+
+    $compile_dir = PHPWG_ROOT_PATH.$conf['data_location'].'templates_c';
     mkgetdir( $compile_dir );
 
@@ -1182,5 +1184,4 @@
 final class FileCombiner
 {
-  const OUT_SUB_DIR = PWG_COMBINED_DIR;
   private $type; // js or css
   private $files = array();
@@ -1194,9 +1195,9 @@
   static function clear_combined_files()
   {
-    $dir = opendir(PHPWG_ROOT_PATH.self::OUT_SUB_DIR);
+    $dir = opendir(PHPWG_ROOT_PATH.PWG_COMBINED_DIR);
     while ($file = readdir($dir))
     {
       if ( get_extension($file)=='js' || get_extension($file)=='css')
-        unlink(PHPWG_ROOT_PATH.self::OUT_SUB_DIR.$file);
+        unlink(PHPWG_ROOT_PATH.PWG_COMBINED_DIR.$file);
     }
     closedir($dir);
@@ -1243,5 +1244,5 @@
 
     $file = base_convert(crc32($key),10,36);
-    $file = self::OUT_SUB_DIR . $file . '.' . $this->type;
+    $file = PWG_COMBINED_DIR . $file . '.' . $this->type;
 
     $exists = file_exists( PHPWG_ROOT_PATH . $file );
Index: /trunk/install.php
===================================================================
--- /trunk/install.php	(revision 12801)
+++ /trunk/install.php	(revision 12802)
@@ -111,7 +111,7 @@
 
 // download database config file if exists
-if (!empty($_GET['dl']) && file_exists($conf['local_data_dir'].'/pwg_'.$_GET['dl']))
-{
-  $filename = $conf['local_data_dir'].'/pwg_'.$_GET['dl'];
+if (!empty($_GET['dl']) && file_exists(PHPWG_ROOT_PATH.$conf['data_location'].'pwg_'.$_GET['dl']))
+{
+  $filename = PHPWG_ROOT_PATH.$conf['data_location'].'pwg_'.$_GET['dl'];
   header('Cache-Control: no-cache, must-revalidate');
   header('Pragma: no-cache');
@@ -282,5 +282,5 @@
     {
       $tmp_filename = md5(uniqid(time()));
-      $fh = @fopen( $conf['local_data_dir'] . '/pwg_' . $tmp_filename, 'w' );
+      $fh = @fopen( PHPWG_ROOT_PATH.$conf['data_location'] . 'pwg_' . $tmp_filename, 'w' );
       @fputs($fh, $file_content, strlen($file_content));
       @fclose($fh);
Index: /trunk/install/db/112-database.php
===================================================================
--- /trunk/install/db/112-database.php	(revision 12802)
+++ /trunk/install/db/112-database.php	(revision 12802)
@@ -0,0 +1,54 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based photo gallery                                    |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | 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!');
+}
+
+$upgrade_description = 'Change combined dir';
+
+// Add column
+$query = 'DELETE FROM '.CONFIG_TABLE.'
+  WHERE param IN (\'local_data_dir_checked\', \'combined_dir_checked\') ';
+
+pwg_query($query);
+
+$dir=PHPWG_ROOT_PATH.'local/combined/';
+if (is_dir($dir))
+{
+  foreach (glob($dir.'*.css') as $file)
+  {
+    @unlink($file);
+  }
+  foreach (glob($dir.'*.js') as $file)
+    @unlink($file);
+  @unlink($dir.'index.htm');
+  @rmdir($dir);
+}
+echo
+"\n"
+. $upgrade_description
+."\n"
+;
+?>
Index: /trunk/install/db/94-database.php
===================================================================
--- /trunk/install/db/94-database.php	(revision 12801)
+++ /trunk/install/db/94-database.php	(revision 12802)
@@ -61,5 +61,5 @@
 
 // save configuration for a future use by the Community plugin
-$backup_filepath = $conf['local_data_dir'].'/plugins/core_user_upload_to_community.php';
+$backup_filepath = PHPWG_ROOT_PATH.$conf['data_location'].'plugins/core_user_upload_to_community.php';
 $save_conf = true;
 if (is_dir(dirname($backup_filepath)))
@@ -70,5 +70,5 @@
   }
 }
-elseif (!is_writable($conf['local_data_dir']))
+elseif (!is_writable( PHPWG_ROOT_PATH.$conf['data_location'] ))
 {
   $save_conf = false;
