Skip to content

Commit

Permalink
fetaure 2542 replace $conf['local_data_dir'] with $conf['data_locatio…
Browse files Browse the repository at this point in the history
…n'] 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
  • Loading branch information
rvelices committed Dec 29, 2011
1 parent 5331c7f commit 1e1b71c
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 39 deletions.
15 changes: 7 additions & 8 deletions admin/include/updates.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function dump_database($include_history=false)

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)
and ($backupFile = tempnam($path, 'sql'))
Expand Down Expand Up @@ -350,7 +350,7 @@ function dump_database($include_history=false)
}

@readfile($backupFile);
self::deltree($conf['local_data_dir'].'/update');
self::deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
exit();
}
else
Expand Down Expand Up @@ -386,7 +386,7 @@ function upgrade_to($upgrade_to, &$step)

if (empty($page['errors']))
{
$path = $conf['local_data_dir'].'/update';
$path = PHPWG_ROOT_PATH.$conf['data_location'].'update';
$filename = $path.'/'.$code.'.zip';
@mkgetdir($path);

Expand Down Expand Up @@ -449,7 +449,7 @@ function upgrade_to($upgrade_to, &$step)
if (empty($error))
{
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();
unset($_SESSION['need_update']);
Expand All @@ -465,20 +465,19 @@ function upgrade_to($upgrade_to, &$step)
}
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'
)
);
}
}
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.'));
}
}
Expand Down
2 changes: 1 addition & 1 deletion feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function ts_to_iso8601($ts)
$rss->addItem($item);
}

$fileName= $conf['local_data_dir'].'/tmp';
$fileName= PHPWG_ROOT_PATH.$conf['data_location'].'tmp';
mkgetdir($fileName); // just in case
$fileName.='/feed.xml';
// send XML feed
Expand Down
2 changes: 1 addition & 1 deletion i.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@include(PHPWG_ROOT_PATH. 'local/config/config.inc.php');

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() {}
function get_extension( $filename )
Expand Down
2 changes: 2 additions & 0 deletions include/common.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ function sanitize_mysql_kv(&$v, $k)

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/');


Expand Down
10 changes: 5 additions & 5 deletions include/config_default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -719,9 +719,10 @@
// Every plugin from 1.7 would be design to manage light_slideshow case.
$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
// the Piwigo installation directory (but can be outside, as long as it's
Expand Down Expand Up @@ -756,6 +757,5 @@
// 0-'auto', 1-'derivative' 2-'script'
$conf['derivative_url_style']=0;

$conf['chmod_value']=0777;

$conf['chmod_value']= substr_compare(PHP_SAPI, 'apa', 0, 3)==0 ? 0777 : 0755;
?>
4 changes: 2 additions & 2 deletions include/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
define('PHPWG_DEFAULT_TEMPLATE', 'Sylvia');

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
define('REQUIRED_PHP_VERSION', '5.0.0');
Expand Down
2 changes: 1 addition & 1 deletion include/dblayer/functions_pdo-sqlite.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function pwg_db_connect($host, $user, $password, $database)
{
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);
if (!$link)
Expand Down
2 changes: 1 addition & 1 deletion include/dblayer/functions_sqlite.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function pwg_db_connect($host, $user, $password, $database)
{
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')
{
Expand Down
2 changes: 1 addition & 1 deletion include/functions_mail.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ function move_ccs_rules_to_body($content)
function pwg_send_mail_test($result, $to, $subject, $content, $headers, $args)
{
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) )
{
$filename = $dir.'/mail.'.stripslashes($user['username']).'.'.$lang_info['code'].'.'.$args['theme'].'-'.date('YmdHis');
Expand Down
27 changes: 14 additions & 13 deletions include/template.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,32 @@ function Template($root = ".", $theme= "", $path = "template")
$this->smarty->compile_check = $conf['template_compile_check'];
$this->smarty->force_compile = $conf['template_force_compile'];

if (!isset($conf['local_data_dir_checked']))
if (!isset($conf['data_dir_checked']))
{
mkgetdir($conf['local_data_dir'], MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR);
if (!is_writable($conf['local_data_dir']))
$dir = PHPWG_ROOT_PATH.$conf['data_location'];
mkgetdir($dir, MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR);
if (!is_writable($dir))
{
load_language('admin.lang');
fatal_error(
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'),
false // show trace
);
}
if (function_exists('pwg_query')) {
conf_update_param('local_data_dir_checked', 'true');
conf_update_param('data_dir_checked', 1);
}
}

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');
fatal_error(
Expand All @@ -95,12 +97,12 @@ function Template($root = ".", $theme= "", $path = "template")
);
}
if (function_exists('pwg_query')) {
conf_update_param('combined_dir_checked', 'true');
conf_update_param('combined_dir_checked', 1);
}
}


$compile_dir = $conf['local_data_dir'].'/templates_c';
$compile_dir = PHPWG_ROOT_PATH.$conf['data_location'].'templates_c';
mkgetdir( $compile_dir );

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

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);
}
Expand Down Expand Up @@ -1242,7 +1243,7 @@ function combine(&$out_file, &$out_version)
$key = join('>', $key);

$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 );
if ($exists)
Expand Down
6 changes: 3 additions & 3 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@
defined('PWG_LOCAL_DIR') or define('PWG_LOCAL_DIR', 'local/');

// download database config file if exists
if (!empty($_GET['dl']) && file_exists($conf['local_data_dir'].'/pwg_'.$_GET['dl']))
if (!empty($_GET['dl']) && file_exists(PHPWG_ROOT_PATH.$conf['data_location'].'pwg_'.$_GET['dl']))
{
$filename = $conf['local_data_dir'].'/pwg_'.$_GET['dl'];
$filename = PHPWG_ROOT_PATH.$conf['data_location'].'pwg_'.$_GET['dl'];
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-Disposition: attachment; filename="database.inc.php"');
Expand Down Expand Up @@ -281,7 +281,7 @@
if ( !($fp = @fopen( $config_file, 'w' )))
{
$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);

Expand Down
54 changes: 54 additions & 0 deletions install/db/112-database.php
Original file line number Diff line number Diff line change
@@ -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"
;
?>
4 changes: 2 additions & 2 deletions install/db/94-database.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
}

// 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)))
{
Expand All @@ -69,7 +69,7 @@
$save_conf = false;
}
}
elseif (!is_writable($conf['local_data_dir']))
elseif (!is_writable( PHPWG_ROOT_PATH.$conf['data_location'] ))
{
$save_conf = false;
}
Expand Down
1 change: 0 additions & 1 deletion local/combined/index.htm

This file was deleted.

0 comments on commit 1e1b71c

Please sign in to comment.