Skip to content

Commit 1e1b71c

Browse files
author
rvelices
committed
fetaure 2542 replace $conf['local_data_dir'] with $conf['data_location'] and move combined files and image derivatives from local to _data
git-svn-id: http://piwigo.org/svn/trunk@12802 68402e56-0260-453c-a942-63ccdbb3a9ee
1 parent 5331c7f commit 1e1b71c

14 files changed

+94
-39
lines changed

Diff for: admin/include/updates.class.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ function dump_database($include_history=false)
316316

317317
include(PHPWG_ROOT_PATH.'admin/include/mysqldump.php');
318318

319-
$path = $conf['local_data_dir'].'/update';
319+
$path = PHPWG_ROOT_PATH.$conf['data_location'].'update';
320320

321321
if (@mkgetdir($path)
322322
and ($backupFile = tempnam($path, 'sql'))
@@ -350,7 +350,7 @@ function dump_database($include_history=false)
350350
}
351351

352352
@readfile($backupFile);
353-
self::deltree($conf['local_data_dir'].'/update');
353+
self::deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
354354
exit();
355355
}
356356
else
@@ -386,7 +386,7 @@ function upgrade_to($upgrade_to, &$step)
386386

387387
if (empty($page['errors']))
388388
{
389-
$path = $conf['local_data_dir'].'/update';
389+
$path = PHPWG_ROOT_PATH.$conf['data_location'].'update';
390390
$filename = $path.'/'.$code.'.zip';
391391
@mkgetdir($path);
392392

@@ -449,7 +449,7 @@ function upgrade_to($upgrade_to, &$step)
449449
if (empty($error))
450450
{
451451
self::process_obsolete_list($obsolete_list);
452-
self::deltree($conf['local_data_dir'].'/update');
452+
self::deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
453453
invalidate_user_cache(true);
454454
$template->delete_compiled_templates();
455455
unset($_SESSION['need_update']);
@@ -465,20 +465,19 @@ function upgrade_to($upgrade_to, &$step)
465465
}
466466
else
467467
{
468-
file_put_contents($conf['local_data_dir'].'/update/log_error.txt', $error);
469-
$relative_path = trim(str_replace(dirname(dirname(dirname(dirname(__FILE__)))), '', $conf['local_data_dir']), '/\\');
468+
file_put_contents(PHPWG_ROOT_PATH.$conf['data_location'].'update/log_error.txt', $error);
470469
array_push(
471470
$page['errors'],
472471
sprintf(
473472
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>.'),
474-
PHPWG_ROOT_PATH.$relative_path.'/update/log_error.txt'
473+
get_root_url().$conf['data_location'].'update/log_error.txt'
475474
)
476475
);
477476
}
478477
}
479478
else
480479
{
481-
self::deltree($conf['local_data_dir'].'/update');
480+
self::deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
482481
array_push($page['errors'], l10n('An error has occured during upgrade.'));
483482
}
484483
}

Diff for: feed.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function ts_to_iso8601($ts)
193193
$rss->addItem($item);
194194
}
195195

196-
$fileName= $conf['local_data_dir'].'/tmp';
196+
$fileName= PHPWG_ROOT_PATH.$conf['data_location'].'tmp';
197197
mkgetdir($fileName); // just in case
198198
$fileName.='/feed.xml';
199199
// send XML feed

Diff for: i.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
@include(PHPWG_ROOT_PATH. 'local/config/config.inc.php');
2727

2828
defined('PWG_LOCAL_DIR') or define('PWG_LOCAL_DIR', 'local/');
29-
defined('PWG_DERIVATIVE_DIR') or define('PWG_DERIVATIVE_DIR', PWG_LOCAL_DIR.'i/');
29+
defined('PWG_DERIVATIVE_DIR') or define('PWG_DERIVATIVE_DIR', $conf['data_location'].'i/');
3030

3131
function trigger_action() {}
3232
function get_extension( $filename )

Diff for: include/common.inc.php

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ function sanitize_mysql_kv(&$v, $k)
8888

8989
include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
9090
@include(PHPWG_ROOT_PATH. 'local/config/config.inc.php');
91+
if (!isset($conf['local_data_dir'])) $conf['local_data_dir'] = realpath(PHPWG_ROOT_PATH.$conf['data_location']); // temp 2.4 for backward compatibility
92+
9193
defined('PWG_LOCAL_DIR') or define('PWG_LOCAL_DIR', 'local/');
9294

9395

Diff for: include/config_default.inc.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -719,9 +719,10 @@
719719
// Every plugin from 1.7 would be design to manage light_slideshow case.
720720
$conf['light_slideshow'] = true;
721721

722-
// the local data directory is used to store data such as compiled templates
723-
// or other plugin variables etc
724-
$conf['local_data_dir'] = dirname(dirname(__FILE__)).'/_data';
722+
// the local data directory is used to store data such as compiled templates,
723+
// plugin variables, combined css/javascript or resized images. Beware of
724+
// mandatory trailing slash.
725+
$conf['data_location'] = '_data/';
725726

726727
// where should the API/UploadForm add photos? This path must be relative to
727728
// the Piwigo installation directory (but can be outside, as long as it's
@@ -756,6 +757,5 @@
756757
// 0-'auto', 1-'derivative' 2-'script'
757758
$conf['derivative_url_style']=0;
758759

759-
$conf['chmod_value']=0777;
760-
760+
$conf['chmod_value']= substr_compare(PHP_SAPI, 'apa', 0, 3)==0 ? 0777 : 0755;
761761
?>

Diff for: include/constants.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
define('PHPWG_DEFAULT_TEMPLATE', 'Sylvia');
2828

2929
define('PHPWG_THEMES_PATH', $conf['themes_dir'].'/');
30-
defined('PWG_COMBINED_DIR') or define('PWG_COMBINED_DIR', PWG_LOCAL_DIR.'combined/');
31-
defined('PWG_DERIVATIVE_DIR') or define('PWG_DERIVATIVE_DIR', PWG_LOCAL_DIR.'i/');
30+
defined('PWG_COMBINED_DIR') or define('PWG_COMBINED_DIR', $conf['data_location'].'combined/');
31+
defined('PWG_DERIVATIVE_DIR') or define('PWG_DERIVATIVE_DIR', $conf['data_location'].'i/');
3232

3333
// Required versions
3434
define('REQUIRED_PHP_VERSION', '5.0.0');

Diff for: include/dblayer/functions_pdo-sqlite.inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function pwg_db_connect($host, $user, $password, $database)
3737
{
3838
global $conf;
3939

40-
$db_file = sprintf('sqlite:%s/%s.db', $conf['local_data_dir'], $database);
40+
$db_file = sprintf('sqlite:%s/%s.db', PHPWG_ROOT_PATH.$conf['data_location'], $database);
4141

4242
$link = new PDO($db_file);
4343
if (!$link)

Diff for: include/dblayer/functions_sqlite.inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function pwg_db_connect($host, $user, $password, $database)
3737
{
3838
global $conf;
3939

40-
$db_file = sprintf('%s/%s.db', $conf['local_data_dir'], $database);
40+
$db_file = sprintf('%s/%s.db', PHPWG_ROOT_PATH.$conf['data_location'], $database);
4141

4242
if (script_basename()=='install')
4343
{

Diff for: include/functions_mail.inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ function move_ccs_rules_to_body($content)
791791
function pwg_send_mail_test($result, $to, $subject, $content, $headers, $args)
792792
{
793793
global $conf, $user, $lang_info;
794-
$dir = $conf['local_data_dir'].'/tmp';
794+
$dir = PHPWG_ROOT_PATH.$conf['data_location'].'tmp';
795795
if ( mkgetdir( $dir, MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR) )
796796
{
797797
$filename = $dir.'/mail.'.stripslashes($user['username']).'.'.$lang_info['code'].'.'.$args['theme'].'-'.date('YmdHis');

Diff for: include/template.class.php

+14-13
Original file line numberDiff line numberDiff line change
@@ -59,30 +59,32 @@ function Template($root = ".", $theme= "", $path = "template")
5959
$this->smarty->compile_check = $conf['template_compile_check'];
6060
$this->smarty->force_compile = $conf['template_force_compile'];
6161

62-
if (!isset($conf['local_data_dir_checked']))
62+
if (!isset($conf['data_dir_checked']))
6363
{
64-
mkgetdir($conf['local_data_dir'], MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR);
65-
if (!is_writable($conf['local_data_dir']))
64+
$dir = PHPWG_ROOT_PATH.$conf['data_location'];
65+
mkgetdir($dir, MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR);
66+
if (!is_writable($dir))
6667
{
6768
load_language('admin.lang');
6869
fatal_error(
6970
sprintf(
7071
l10n('Give write access (chmod 777) to "%s" directory at the root of your Piwigo installation'),
71-
basename($conf['local_data_dir'])
72+
$conf['data_location']
7273
),
7374
l10n('an error happened'),
7475
false // show trace
7576
);
7677
}
7778
if (function_exists('pwg_query')) {
78-
conf_update_param('local_data_dir_checked', 'true');
79+
conf_update_param('data_dir_checked', 1);
7980
}
8081
}
8182

8283
if (!isset($conf['combined_dir_checked']))
8384
{
84-
mkgetdir(PWG_COMBINED_DIR, MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR);
85-
if (!is_writable(PWG_COMBINED_DIR))
85+
$dir = PHPWG_ROOT_PATH.PWG_COMBINED_DIR;
86+
mkgetdir($dir, MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR);
87+
if (!is_writable($dir))
8688
{
8789
load_language('admin.lang');
8890
fatal_error(
@@ -95,12 +97,12 @@ function Template($root = ".", $theme= "", $path = "template")
9597
);
9698
}
9799
if (function_exists('pwg_query')) {
98-
conf_update_param('combined_dir_checked', 'true');
100+
conf_update_param('combined_dir_checked', 1);
99101
}
100102
}
101103

102104

103-
$compile_dir = $conf['local_data_dir'].'/templates_c';
105+
$compile_dir = PHPWG_ROOT_PATH.$conf['data_location'].'templates_c';
104106
mkgetdir( $compile_dir );
105107

106108
$this->smarty->compile_dir = $compile_dir;
@@ -1181,7 +1183,6 @@ private static function cmp_by_mode_and_order($s1, $s2)
11811183
/*Allows merging of javascript and css files into a single one.*/
11821184
final class FileCombiner
11831185
{
1184-
const OUT_SUB_DIR = PWG_COMBINED_DIR;
11851186
private $type; // js or css
11861187
private $files = array();
11871188
private $versions = array();
@@ -1193,11 +1194,11 @@ function FileCombiner($type)
11931194

11941195
static function clear_combined_files()
11951196
{
1196-
$dir = opendir(PHPWG_ROOT_PATH.self::OUT_SUB_DIR);
1197+
$dir = opendir(PHPWG_ROOT_PATH.PWG_COMBINED_DIR);
11971198
while ($file = readdir($dir))
11981199
{
11991200
if ( get_extension($file)=='js' || get_extension($file)=='css')
1200-
unlink(PHPWG_ROOT_PATH.self::OUT_SUB_DIR.$file);
1201+
unlink(PHPWG_ROOT_PATH.PWG_COMBINED_DIR.$file);
12011202
}
12021203
closedir($dir);
12031204
}
@@ -1242,7 +1243,7 @@ function combine(&$out_file, &$out_version)
12421243
$key = join('>', $key);
12431244

12441245
$file = base_convert(crc32($key),10,36);
1245-
$file = self::OUT_SUB_DIR . $file . '.' . $this->type;
1246+
$file = PWG_COMBINED_DIR . $file . '.' . $this->type;
12461247

12471248
$exists = file_exists( PHPWG_ROOT_PATH . $file );
12481249
if ($exists)

Diff for: install.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@
110110
defined('PWG_LOCAL_DIR') or define('PWG_LOCAL_DIR', 'local/');
111111

112112
// download database config file if exists
113-
if (!empty($_GET['dl']) && file_exists($conf['local_data_dir'].'/pwg_'.$_GET['dl']))
113+
if (!empty($_GET['dl']) && file_exists(PHPWG_ROOT_PATH.$conf['data_location'].'pwg_'.$_GET['dl']))
114114
{
115-
$filename = $conf['local_data_dir'].'/pwg_'.$_GET['dl'];
115+
$filename = PHPWG_ROOT_PATH.$conf['data_location'].'pwg_'.$_GET['dl'];
116116
header('Cache-Control: no-cache, must-revalidate');
117117
header('Pragma: no-cache');
118118
header('Content-Disposition: attachment; filename="database.inc.php"');
@@ -281,7 +281,7 @@
281281
if ( !($fp = @fopen( $config_file, 'w' )))
282282
{
283283
$tmp_filename = md5(uniqid(time()));
284-
$fh = @fopen( $conf['local_data_dir'] . '/pwg_' . $tmp_filename, 'w' );
284+
$fh = @fopen( PHPWG_ROOT_PATH.$conf['data_location'] . 'pwg_' . $tmp_filename, 'w' );
285285
@fputs($fh, $file_content, strlen($file_content));
286286
@fclose($fh);
287287

Diff for: install/db/112-database.php

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
// +-----------------------------------------------------------------------+
3+
// | Piwigo - a PHP based photo gallery |
4+
// +-----------------------------------------------------------------------+
5+
// | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org |
6+
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
7+
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
8+
// +-----------------------------------------------------------------------+
9+
// | This program is free software; you can redistribute it and/or modify |
10+
// | it under the terms of the GNU General Public License as published by |
11+
// | the Free Software Foundation |
12+
// | |
13+
// | This program is distributed in the hope that it will be useful, but |
14+
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
15+
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16+
// | General Public License for more details. |
17+
// | |
18+
// | You should have received a copy of the GNU General Public License |
19+
// | along with this program; if not, write to the Free Software |
20+
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21+
// | USA. |
22+
// +-----------------------------------------------------------------------+
23+
24+
if (!defined('PHPWG_ROOT_PATH'))
25+
{
26+
die('Hacking attempt!');
27+
}
28+
29+
$upgrade_description = 'Change combined dir';
30+
31+
// Add column
32+
$query = 'DELETE FROM '.CONFIG_TABLE.'
33+
WHERE param IN (\'local_data_dir_checked\', \'combined_dir_checked\') ';
34+
35+
pwg_query($query);
36+
37+
$dir=PHPWG_ROOT_PATH.'local/combined/';
38+
if (is_dir($dir))
39+
{
40+
foreach (glob($dir.'*.css') as $file)
41+
{
42+
@unlink($file);
43+
}
44+
foreach (glob($dir.'*.js') as $file)
45+
@unlink($file);
46+
@unlink($dir.'index.htm');
47+
@rmdir($dir);
48+
}
49+
echo
50+
"\n"
51+
. $upgrade_description
52+
."\n"
53+
;
54+
?>

Diff for: install/db/94-database.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
}
6161

6262
// save configuration for a future use by the Community plugin
63-
$backup_filepath = $conf['local_data_dir'].'/plugins/core_user_upload_to_community.php';
63+
$backup_filepath = PHPWG_ROOT_PATH.$conf['data_location'].'plugins/core_user_upload_to_community.php';
6464
$save_conf = true;
6565
if (is_dir(dirname($backup_filepath)))
6666
{
@@ -69,7 +69,7 @@
6969
$save_conf = false;
7070
}
7171
}
72-
elseif (!is_writable($conf['local_data_dir']))
72+
elseif (!is_writable( PHPWG_ROOT_PATH.$conf['data_location'] ))
7373
{
7474
$save_conf = false;
7575
}

Diff for: local/combined/index.htm

-1
This file was deleted.

0 commit comments

Comments
 (0)