diff options
author | plegall <plg@piwigo.org> | 2005-09-27 21:57:14 +0000 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2005-09-27 21:57:14 +0000 |
commit | 0c0ab6d700167e3a8c4f9734233ff70738b12e18 (patch) | |
tree | a157b099f09a79bdce02c1ca8e3af72bfff7624b | |
parent | b7b05eafc360c258d0d711625051ad10a840613b (diff) |
- bug 168 fixed: crash when language file does not exists. Constant
PHPWG_DEFAULT_LANGUAGE added. New function get_language_filepath always
used to find language files.
git-svn-id: http://piwigo.org/svn/trunk@879 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r-- | admin/help.php | 20 | ||||
-rw-r--r-- | doc/ChangeLog | 6 | ||||
-rw-r--r-- | include/common.inc.php | 25 | ||||
-rw-r--r-- | include/constants.php | 1 | ||||
-rw-r--r-- | include/functions_user.inc.php | 34 | ||||
-rw-r--r-- | popuphelp.php | 20 |
6 files changed, 55 insertions, 51 deletions
diff --git a/admin/help.php b/admin/help.php index 7447c3fc9..32019840a 100644 --- a/admin/help.php +++ b/admin/help.php @@ -27,19 +27,11 @@ include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' ); -// language files -$user_langdir = PHPWG_ROOT_PATH.'language/'.$user['language']; -$conf_langdir = PHPWG_ROOT_PATH.'language/'.$conf['default_language']; - -if (file_exists($user_langdir.'/help.html')) -{ - $html_file = $user_langdir.'/help.html'; -} -else -{ - $html_file = $conf_langdir.'/help.html'; -} - -$template->set_filenames(array('help_content' => $html_file)); +$template->set_filenames( + array( + 'help_content' => get_language_filepath('help.html') + ) + ); + $template->assign_var_from_handle('ADMIN_CONTENT', 'help_content'); ?> diff --git a/doc/ChangeLog b/doc/ChangeLog index 94009b7a1..9f59dc243 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,9 @@ +2005-09-27 Pierrick LE GALL + + * bug 168 fixed: crash when language file does not + exists. Constant PHPWG_DEFAULT_LANGUAGE added. New function + get_language_filepath always used to find language files. + 2005-09-26 Pierrick LE GALL * bug 158 fixed: display error on "double selects" screens (with diff --git a/include/common.inc.php b/include/common.inc.php index fa0a7f3db..38b0e7de0 100644 --- a/include/common.inc.php +++ b/include/common.inc.php @@ -166,32 +166,11 @@ while ( $row =mysql_fetch_array( $result ) ) include(PHPWG_ROOT_PATH.'include/user.inc.php'); // language files -$user_langdir = PHPWG_ROOT_PATH.'language/'.$user['language']; -$conf_langdir = PHPWG_ROOT_PATH.'language/'.$conf['default_language']; +include_once(get_language_filepath('common.lang.php')); -if (file_exists($user_langdir.'/common.lang.php')) -{ - include_once($user_langdir.'/common.lang.php'); -} -else -{ - include_once($conf_langdir.'/common.lang.php'); -} - -// The administration section requires 2 more language files if (defined('IN_ADMIN') and IN_ADMIN) { - foreach (array('admin') as $section) - { - if (file_exists($user_langdir.'/'.$section.'.lang.php')) - { - include_once($user_langdir.'/'.$section.'.lang.php'); - } - else - { - include_once($conf_langdir.'/'.$section.'.lang.php'); - } - } + include_once(get_language_filepath('admin.lang.php')); } // only now we can set the localized username of the guest user (and not in diff --git a/include/constants.php b/include/constants.php index a04020d50..a7823b230 100644 --- a/include/constants.php +++ b/include/constants.php @@ -29,6 +29,7 @@ define('PHPWG_VERSION', '%PWGVERSION%'); define('PHPWG_URL', 'http://www.phpwebgallery.net'); define('PHPWG_FORUM_URL', 'http://forum.phpwebgallery.net'); +define('PHPWG_DEFAULT_LANGUAGE', 'en_UK.iso-8859-1'); // Error codes define('GENERAL_MESSAGE', 200); diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php index 41321a587..25dc3efda 100644 --- a/include/functions_user.inc.php +++ b/include/functions_user.inc.php @@ -497,4 +497,38 @@ SELECT name return $groupname; } + +/** + * return the file path of the given language filename, depending on the + * availability of the file + * + * in descending order of preference: user language, default language, + * PhpWebGallery default language. + * + * @param string filename + * @return string filepath + */ +function get_language_filepath($filename) +{ + global $user, $conf; + + $directories = + array( + PHPWG_ROOT_PATH.'language/'.$user['language'], + PHPWG_ROOT_PATH.'language/'.$conf['default_language'], + PHPWG_ROOT_PATH.'language/'.PHPWG_DEFAULT_LANGUAGE + ); + + foreach ($directories as $directory) + { + $filepath = $directory.'/'.$filename; + + if (file_exists($filepath)) + { + return $filepath; + } + } + + return false; +} ?>
\ No newline at end of file diff --git a/popuphelp.php b/popuphelp.php index 97ae7532a..0c5c205da 100644 --- a/popuphelp.php +++ b/popuphelp.php @@ -32,23 +32,15 @@ define('PHPWG_ROOT_PATH','./'); include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); -// language files -$user_langdir = PHPWG_ROOT_PATH.'language/'.$user['language']; -$conf_langdir = PHPWG_ROOT_PATH.'language/'.$conf['default_language']; - -if (file_exists($user_langdir.'/help/'.$_GET['page'].'.html')) -{ - $html_file = $user_langdir.'/help/'.$_GET['page'].'.html'; -} -else -{ - $html_file = $conf_langdir.'/help/'.$_GET['page'].'.html'; -} - $page['body_id'] = 'thePopuphelpPage'; $page['gallery_title'] = $title = l10n('PhpWebGallery Help'); include(PHPWG_ROOT_PATH.'include/page_header.php'); -$template->set_filenames(array('help_content' => $html_file)); + +$template->set_filenames( + array( + 'help_content' => get_language_filepath('help/'.$_GET['page'].'.html') + ) + ); $template->set_filenames(array('popuphelp' => 'popuphelp.tpl')); |