From dd282efc6925de41389f6eb7b33cb2f6eb4e4b03 Mon Sep 17 00:00:00 2001 From: e107steved Date: Sun, 7 Dec 2008 21:41:04 +0000 Subject: [PATCH] Finalise locations of language files, option to disable auto-load of English files on non-English sites if required files not found --- class2.php | 79 ++++++++++++++++++- e107_admin/admin.php | 6 +- e107_admin/language.php | 31 ++++++-- e107_files/def_e107_prefs.php | 5 +- e107_files/shortcode/admin_alt_nav.sc | 3 +- e107_files/shortcode/admin_nav.sc | 4 +- e107_handlers/plugin_class.php | 6 +- e107_handlers/theme_handler.php | 8 +- e107_languages/English/admin/lan_language.php | 8 +- e107_plugins/calendar_menu/admin_config.php | 6 +- ...sh.php => English_admin_calendar_menu.php} | 6 +- e107_plugins/log/admin_config.php | 11 ++- e107_plugins/log/e_help.php | 6 +- .../English.php => English_admin_log.php} | 6 +- .../{admin => }/English_log_help.php | 6 +- 15 files changed, 141 insertions(+), 50 deletions(-) rename e107_plugins/calendar_menu/languages/{admin/English.php => English_admin_calendar_menu.php} (99%) rename e107_plugins/log/languages/{admin/English.php => English_admin_log.php} (97%) rename e107_plugins/log/languages/{admin => }/English_log_help.php (93%) diff --git a/class2.php b/class2.php index bb128724c..c467e5686 100644 --- a/class2.php +++ b/class2.php @@ -11,9 +11,9 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/class2.php,v $ -| $Revision: 1.84 $ -| $Date: 2008-12-04 21:05:05 $ -| $Author: mcfly_e107 $ +| $Revision: 1.85 $ +| $Date: 2008-12-07 21:41:03 $ +| $Author: e107steved $ +----------------------------------------------------------------------------+ */ // @@ -1708,20 +1708,93 @@ function e107_require($fname) function include_lan($path, $force = false) { + global $pref; if (!is_readable($path)) { + if (varsettrue($pref['noLanguageSubs']) || (e_LANGUAGE == 'English')) + { + return FALSE; + } $path = str_replace(e_LANGUAGE, 'English', $path); } $ret = ($force) ? include($path) : include_once($path); return (isset($ret)) ? $ret : ""; } +/* +withdrawn - use loadLanFiles($path, 'admin') instead // Searches a defined set of paths and file names to load language files used for admin (including install etc) function include_lan_admin($path) { include_lan($path.'languages/'.e_LANGUAGE.'/lan_config.php'); include_lan($path.'languages/admin/'.e_LANGUAGE.'.php'); } +*/ + + +// Routine looks in standard paths for language files associated with a plugin or theme - primarily for core routines, which won't know +// for sure where the author has put them. +// $unitName is the name (directory path) of the plugin or theme +// $type determines what is to be loaded: +// 'runtime' - the standard runtime language file for a plugin +// 'admin' - the standard admin language file for a plugin +// 'theme' - the standard language file for a plugin (these are usually pretty small, so one is enough) +// Otherwise, $type is treated as part of a filename within the plugin's language directory, prefixed with the current language +// Returns FALSE on failure (not found). +// Returns the include_once error return if there is one +// Otherwise returns an empty string. + +// Note - if the code knows precisely where the language file is located, use include_lan() + +// $pref['noLanguageSubs'] can be set TRUE to prevent searching for the English files if the files for the current site language don't exist. + +function loadLanFiles($unitName, $type='runtime') +{ + global $pref; + switch ($type) + { + case 'runtime' : + $searchPath[1] = e_PLUGIN.$unitName.'/languages/'.e_LANGUAGE.'_'.$unitName.'.php'; + $searchPath[2] = e_PLUGIN.$unitName.'/languages/'.e_LANGUAGE.'/'.$unitName.'.php'; + break; + case 'admin' : + $searchPath[1] = e_PLUGIN.$unitName.'/languages/'.e_LANGUAGE.'_admin_'.$unitName.'.php'; + $searchPath[2] = e_PLUGIN.$unitName.'/languages/'.e_LANGUAGE.'/'.'admin_'.$unitName.'.php'; + break; + case 'theme' : + $searchPath[1] = e_THEME.$unitName.'/languages/'.e_LANGUAGE.'_'.$unitName.'.php'; + $searchPath[2] = e_THEME.$unitName.'/languages/'.e_LANGUAGE.'/'.$unitName.'.php'; + break; + default : + $searchPath[1] = e_PLUGIN.$unitName.'/languages/'.e_LANGUAGE.'_'.$type.'.php'; + $searchPath[2] = e_PLUGIN.$unitName.'/languages/'.e_LANGUAGE.'/'.$type.'.php'; + } + foreach ($searchPath as $s) // Look for files in current language first - should usually be found + { + if (is_readable($s)) + { + $ret = include_once($s); + return (isset($ret)) ? $ret : ""; + } + } + if (varsettrue($pref['noLanguageSubs']) || (e_LANGUAGE == 'English')) + { + return FALSE; // No point looking for the English files twice + } + + foreach ($searchPath as $s) // Now look for the English files + { + $s = str_replace(e_LANGUAGE, 'English', $s); + if (is_readable($s)) + { + $ret = include_once($s); + return (isset($ret)) ? $ret : ""; + } + } + return FALSE; // Nothing found +} + + if(!function_exists('print_a')) { diff --git a/e107_admin/admin.php b/e107_admin/admin.php index d3115f181..3d911efe3 100644 --- a/e107_admin/admin.php +++ b/e107_admin/admin.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_admin/admin.php,v $ -| $Revision: 1.5 $ -| $Date: 2008-12-04 20:17:49 $ +| $Revision: 1.6 $ +| $Date: 2008-12-07 21:41:04 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */ @@ -302,7 +302,7 @@ function getPluginLinks($iconSize = E_16_PLUGMANAGER, $linkStyle = 'adminb') } else { - include_lan_admin($plugin_path); + loadLanFiles($plugin_path, 'admin'); $eplug_name = $tp->toHTML($readFile['@attributes']['name'],FALSE,"defs, emotes_off"); $eplug_conffile = $readFile['administration']['configFile']; $eplug_icon_small = $plugin_path.'/'.$readFile['administration']['iconSmall']; diff --git a/e107_admin/language.php b/e107_admin/language.php index 593b538d6..f0bcad06a 100644 --- a/e107_admin/language.php +++ b/e107_admin/language.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_admin/language.php,v $ -| $Revision: 1.10 $ -| $Date: 2008-12-06 15:48:16 $ +| $Revision: 1.11 $ +| $Date: 2008-12-07 21:41:04 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */ @@ -54,7 +54,8 @@ if (isset($_POST['submit_prefs']) && isset($_POST['mainsitelanguage'])) $temp['multilanguage'] = $_POST['multilanguage']; $temp['multilanguage_subdomain'] = $_POST['multilanguage_subdomain']; $temp['sitelanguage'] = $_POST['mainsitelanguage']; - + $temp['noLanguageSubs'] = $_POST['noLanguageSubs']; + if ($admin_log->logArrayDiffs($temp, $pref, 'LANG_01')) { save_prefs(); // Only save if changes @@ -179,9 +180,11 @@ if ($_POST['edit_existing'])
\n"; - foreach ($tabs as $table_name) { + foreach ($tabs as $table_name) + { $installed = strtolower($_POST['lang_choices'])."_".$table_name; - if (stristr($_POST['lang_choices'], $installed) === FALSE) { + if (stristr($_POST['lang_choices'], $installed) === FALSE) + { $text .= "\n + + "; + + $text .= " + + + "; diff --git a/e107_files/def_e107_prefs.php b/e107_files/def_e107_prefs.php index c54052017..ac25dfad9 100644 --- a/e107_files/def_e107_prefs.php +++ b/e107_files/def_e107_prefs.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_files/def_e107_prefs.php,v $ -| $Revision: 1.18 $ -| $Date: 2008-12-07 13:08:41 $ +| $Revision: 1.19 $ +| $Date: 2008-12-07 21:41:04 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */ @@ -164,6 +164,7 @@ City, State, Country 'ban_retrigger' => '0', 'multilanguage' => '0', + 'noLanguageSubs' => '0', 'user_tracking' => 'cookie', 'cookie_name' => 'e107cookie', diff --git a/e107_files/shortcode/admin_alt_nav.sc b/e107_files/shortcode/admin_alt_nav.sc index a5028494f..15fdb4591 100644 --- a/e107_files/shortcode/admin_alt_nav.sc +++ b/e107_files/shortcode/admin_alt_nav.sc @@ -1,6 +1,6 @@ /* * e107 website system (c) 2001-2008 Steve Dunstan (e107.org) -* $Id: admin_alt_nav.sc,v 1.5 2008-12-05 19:56:45 e107steved Exp $ +* $Id: admin_alt_nav.sc,v 1.6 2008-12-07 21:41:04 e107steved Exp $ */ if (ADMIN) @@ -81,6 +81,7 @@ if (ADMIN) if($plug->parse_plugin($_path)) { $plug_vars = $plug->plug_vars; + loadLanFiles($row['plugin_path'], 'admin'); if($plug_vars['administration']['configFile']) { $plug_vars['@attributes']['name'] = $tp->toHTML($plug_vars['@attributes']['name'], FALSE, "defs"); diff --git a/e107_files/shortcode/admin_nav.sc b/e107_files/shortcode/admin_nav.sc index 38d0b5abe..5cfb3ed2b 100644 --- a/e107_files/shortcode/admin_nav.sc +++ b/e107_files/shortcode/admin_nav.sc @@ -1,6 +1,6 @@ /* * e107 website system (c) 2001-2008 Steve Dunstan (e107.org) -* $Id: admin_nav.sc,v 1.4 2008-12-04 20:17:54 e107steved Exp $ +* $Id: admin_nav.sc,v 1.5 2008-12-07 21:41:04 e107steved Exp $ */ if (ADMIN) { @@ -49,7 +49,7 @@ if (ADMIN) if (is_readable(e_PLUGIN.$plugin_path."/plugin.xml")) { $readFile = $xml->loadXMLfile(e_PLUGIN.$plugin_path.'/plugin.xml', true, true); - include_lan_admin(e_PLUGIN.$plugin_path.'/'); + loadLanFiles($plugin_path, 'admin'); $eplug_caption = $tp->toHTML($readFile['@attributes']['name'],FALSE,"defs, emotes_off"); $eplug_conffile = $readFile['administration']['configFile']; } diff --git a/e107_handlers/plugin_class.php b/e107_handlers/plugin_class.php index 43dd4c98f..aef1cf9f0 100644 --- a/e107_handlers/plugin_class.php +++ b/e107_handlers/plugin_class.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_handlers/plugin_class.php,v $ -| $Revision: 1.54 $ -| $Date: 2008-12-05 19:56:51 $ +| $Revision: 1.55 $ +| $Date: 2008-12-07 21:41:04 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */ @@ -1542,7 +1542,7 @@ class e107plugin function parse_plugin_xml($path) { global $tp; - include_lan_admin($path); // Look for LAN files on default paths + loadLanFiles($path, 'admin'); // Look for LAN files on default paths require_once(e_HANDLER.'xml_class.php'); $xml = new xmlClass; $this->plug_vars = $xml->loadXMLfile($path.'plugin.xml', true, true); diff --git a/e107_handlers/theme_handler.php b/e107_handlers/theme_handler.php index 8d3fc387c..110aeb83d 100644 --- a/e107_handlers/theme_handler.php +++ b/e107_handlers/theme_handler.php @@ -11,9 +11,9 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_handlers/theme_handler.php,v $ -| $Revision: 1.13 $ -| $Date: 2008-12-03 18:09:00 $ -| $Author: mcfly_e107 $ +| $Revision: 1.14 $ +| $Date: 2008-12-07 21:41:04 $ +| $Author: e107steved $ +----------------------------------------------------------------------------+ */ @@ -572,7 +572,7 @@ class themeHandler{ function parse_theme_xml($path) { global $tp; - // include_lan_admin($path); // Look for LAN files on default paths + // loadLanFiles($path, 'admin'); // Look for LAN files on default paths require_once(e_HANDLER.'xml_class.php'); $xml = new xmlClass; $vars = $xml->loadXMLfile(e_THEME.$path.'/theme.xml', true, true); diff --git a/e107_languages/English/admin/lan_language.php b/e107_languages/English/admin/lan_language.php index a0de47624..93588a0f7 100644 --- a/e107_languages/English/admin/lan_language.php +++ b/e107_languages/English/admin/lan_language.php @@ -4,9 +4,9 @@ | e107 website system - Language File. | | $Source: /cvs_backup/e107_0.8/e107_languages/English/admin/lan_language.php,v $ -| $Revision: 1.4 $ -| $Date: 2007-09-20 21:45:33 $ -| $Author: e107coders $ +| $Revision: 1.5 $ +| $Date: 2008-12-07 21:41:04 $ +| $Author: e107steved $ +----------------------------------------------------------------------------+ */ @@ -36,6 +36,8 @@ define("LANG_LAN_22", "Language Pack created successfully."); define("LANG_LAN_23", "Create Language-Pack (zip)"); define("LANG_LAN_24", "Generate"); define("LANG_LAN_25", "Language-Pack Creation Status"); +define('LANG_LAN_26', 'Load language files only for current language'); +define('LANG_LAN_27', 'If checked, and a required language can\'t be found, there will be an error'); diff --git a/e107_plugins/calendar_menu/admin_config.php b/e107_plugins/calendar_menu/admin_config.php index e2f664d66..4890e47f8 100644 --- a/e107_plugins/calendar_menu/admin_config.php +++ b/e107_plugins/calendar_menu/admin_config.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/calendar_menu/admin_config.php,v $ -| $Revision: 1.10 $ -| $Date: 2008-11-20 21:43:57 $ +| $Revision: 1.11 $ +| $Date: 2008-12-07 21:41:04 $ | $Author: e107steved $ | +----------------------------------------------------------------------------+ @@ -28,7 +28,7 @@ if (!getperms("P")) } -include_lan_admin(e_PLUGIN.'calendar_menu/'); +include_lan(e_PLUGIN.'calendar_menu/languages/'.e_LANGUAGE.'_admin_calendar_menu.php'); $message = ""; diff --git a/e107_plugins/calendar_menu/languages/admin/English.php b/e107_plugins/calendar_menu/languages/English_admin_calendar_menu.php similarity index 99% rename from e107_plugins/calendar_menu/languages/admin/English.php rename to e107_plugins/calendar_menu/languages/English_admin_calendar_menu.php index b9c2ce206..bb0e978fa 100644 --- a/e107_plugins/calendar_menu/languages/admin/English.php +++ b/e107_plugins/calendar_menu/languages/English_admin_calendar_menu.php @@ -10,9 +10,9 @@ | Released under the terms and conditions of the | GNU General Public License (http://gnu.org). | -| $Source: /cvs_backup/e107_0.8/e107_plugins/calendar_menu/languages/admin/English.php,v $ -| $Revision: 1.2 $ -| $Date: 2008-08-12 19:59:59 $ +| $Source: /cvs_backup/e107_0.8/e107_plugins/calendar_menu/languages/English_admin_calendar_menu.php,v $ +| $Revision: 1.1 $ +| $Date: 2008-12-07 21:41:04 $ | $Author: e107steved $ | +----------------------------------------------------------------------------+ diff --git a/e107_plugins/log/admin_config.php b/e107_plugins/log/admin_config.php index 2e2053bff..911f021ad 100644 --- a/e107_plugins/log/admin_config.php +++ b/e107_plugins/log/admin_config.php @@ -11,17 +11,16 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/log/admin_config.php,v $ -| $Revision: 1.5 $ -| $Date: 2008-08-13 20:47:09 $ +| $Revision: 1.6 $ +| $Date: 2008-12-07 21:41:04 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ -To do: -1. Admin log for changes */ require_once("../../class2.php"); +if (!plugInstalled('log')) header("Location: ".e_BASE."index.php"); if (!getperms("P")) { header("location:../../index.php"); @@ -31,9 +30,9 @@ if (!getperms("P")) require_once(e_ADMIN."auth.php"); require_once(e_HANDLER."userclass_class.php"); -define("LOGPATH", e_PLUGIN."log/"); +define('LOGPATH', e_PLUGIN.'log/'); -include_lan(LOGPATH."languages/admin/".e_LANGUAGE.".php"); +include_lan(LOGPATH.'languages/'.e_LANGUAGE.'_admin_log.php'); if (e_QUERY) { diff --git a/e107_plugins/log/e_help.php b/e107_plugins/log/e_help.php index 765bf87e4..f376953b7 100644 --- a/e107_plugins/log/e_help.php +++ b/e107_plugins/log/e_help.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/log/e_help.php,v $ -| $Revision: 1.1 $ -| $Date: 2008-01-06 10:18:34 $ +| $Revision: 1.2 $ +| $Date: 2008-12-07 21:41:04 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */ @@ -20,7 +20,7 @@ if (!defined('e107_INIT')) { exit; } define("LOGPATH", e_PLUGIN."log/"); -include_lan(LOGPATH."languages/admin/".e_LANGUAGE."_log_help.php"); +include_lan(LOGPATH."languages/".e_LANGUAGE."_log_help.php"); if (e_QUERY) list($action,$junk) = explode('.',e_QUERY); else $action = 'list'; diff --git a/e107_plugins/log/languages/admin/English.php b/e107_plugins/log/languages/English_admin_log.php similarity index 97% rename from e107_plugins/log/languages/admin/English.php rename to e107_plugins/log/languages/English_admin_log.php index 4ccf8a514..12a1fbe22 100644 --- a/e107_plugins/log/languages/admin/English.php +++ b/e107_plugins/log/languages/English_admin_log.php @@ -10,9 +10,9 @@ | Released under the terms and conditions of the | GNU General Public License (http://gnu.org). | -| $Source: /cvs_backup/e107_0.8/e107_plugins/log/languages/admin/English.php,v $ -| $Revision: 1.6 $ -| $Date: 2008-08-13 20:47:10 $ +| $Source: /cvs_backup/e107_0.8/e107_plugins/log/languages/English_admin_log.php,v $ +| $Revision: 1.1 $ +| $Date: 2008-12-07 21:41:04 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */ diff --git a/e107_plugins/log/languages/admin/English_log_help.php b/e107_plugins/log/languages/English_log_help.php similarity index 93% rename from e107_plugins/log/languages/admin/English_log_help.php rename to e107_plugins/log/languages/English_log_help.php index 58fe30895..d572a0717 100644 --- a/e107_plugins/log/languages/admin/English_log_help.php +++ b/e107_plugins/log/languages/English_log_help.php @@ -10,9 +10,9 @@ | Released under the terms and conditions of the | GNU General Public License (http://gnu.org). | -| $Source: /cvs_backup/e107_0.8/e107_plugins/log/languages/admin/English_log_help.php,v $ -| $Revision: 1.2 $ -| $Date: 2008-02-16 14:57:37 $ +| $Source: /cvs_backup/e107_0.8/e107_plugins/log/languages/English_log_help.php,v $ +| $Revision: 1.1 $ +| $Date: 2008-12-07 21:41:04 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */
".ucfirst(str_replace("_", " ", $table_name))."\n"; @@ -228,7 +231,8 @@ if ($_POST['edit_existing']) require_once(e_ADMIN."footer.php"); // --------------------------------------------------------------------------- -function multilang_prefs() { +function multilang_prefs() +{ global $ns, $pref,$lanlist; $text = "
@@ -245,7 +249,8 @@ function multilang_prefs() { $text .= "
".LANG_LAN_12.": "; $checked = ($pref['multilanguage'] == 1) ? "checked='checked'" : ""; - $text .= " + $text .= " +
".LANG_LAN_26.":
".LANG_LAN_27."
"; + $checked = ($pref['noLanguageSubs'] == 1) ? "checked='checked'" : ""; + $text .= "