mirror of
https://github.com/e107inc/e107.git
synced 2025-07-31 03:40:37 +02:00
Simplify import language definitions syntax for both core and 3rd party language files - introducing e107::coreLan() and e107::plugLan() (see new methods documentation)
This commit is contained in:
15
class2.php
15
class2.php
@@ -522,14 +522,21 @@ if(varset($pref['multilanguage']) && (e_LANGUAGE != $pref['sitelanguage']))
|
||||
$sql2->mySQLlanguage = e_LANGUAGE;
|
||||
}
|
||||
|
||||
//TODO do it only once and with the proper function
|
||||
e107_include_once(e_LANGUAGEDIR.e_LANGUAGE.'/'.e_LANGUAGE.'.php');
|
||||
e107_include_once(e_LANGUAGEDIR.e_LANGUAGE."/".e_LANGUAGE.'_custom.php');
|
||||
//do it only once and with the proper function
|
||||
// e107_include_once(e_LANGUAGEDIR.e_LANGUAGE.'/'.e_LANGUAGE.'.php');
|
||||
// e107_include_once(e_LANGUAGEDIR.e_LANGUAGE.'/'.e_LANGUAGE.'_custom.php');
|
||||
include(e_LANGUAGEDIR.e_LANGUAGE.'/'.e_LANGUAGE.'.php'); // FASTEST - ALWAYS load
|
||||
$customLan = e_LANGUAGEDIR.e_LANGUAGE.'/'.e_LANGUAGE.'_custom.php';
|
||||
if(is_readable($customLan)) // FASTER - if exist, should be done 'once' by the core
|
||||
{
|
||||
include($customLan);
|
||||
}
|
||||
unset($customLan);
|
||||
|
||||
e107::getSession()
|
||||
->challenge() // Create a unique challenge string for CHAP login
|
||||
->check(); // Token protection
|
||||
// echo e_print($_SESSION, e107::getSession()->getSessionId(), e107::getSession()->getSessionName());
|
||||
|
||||
//
|
||||
// N: misc setups: online user tracking, cache
|
||||
//
|
||||
|
@@ -1704,6 +1704,68 @@ class e107
|
||||
$ret = ($force) ? include($path) : include_once($path);
|
||||
return (isset($ret)) ? $ret : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Simplify importing of core Language files.
|
||||
* All inputs are sanitized.
|
||||
* Core Exceptions as e_LANGUAGE.'.php' and e_LANGUAGE.'_custom.php' are manually loaded. (see class2.php)
|
||||
*
|
||||
* Examples:
|
||||
* <code><?php
|
||||
* // import defeinitions from /e107_languages/[CurrentLanguage]/lan_comment.php</code>
|
||||
* e107::coreLan('comment');
|
||||
*
|
||||
* // import defeinitions from /e107_languages/[CurrentLanguage]/admin/lan_banlist.php
|
||||
* e107::coreLan('banlist', true);
|
||||
* </code>
|
||||
*
|
||||
* @param string $fname filename without the extension part (e.g. 'comment')
|
||||
* @param boolean $admin true if it's an administration language file
|
||||
* @return void
|
||||
*/
|
||||
public static function coreLan($fname, $admin = false)
|
||||
{
|
||||
$fname = ($admin ? 'admin/' : '').'lan_'.preg_replace('/[^\w]/', '', $fname).'.php';
|
||||
$path = e_LANGUAGEDIR.e_LANGUAGE.'/'.$fname;
|
||||
|
||||
self::includeLan($path, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simplify importing of plugin Language files (following e107 plugin structure standards).
|
||||
* All inputs are sanitized.
|
||||
*
|
||||
* Examples:
|
||||
* <code><?php
|
||||
* // import defeinitions from /e107_plugins/forum/languages/[CurrentLanguage]/lan_forum.php</code>
|
||||
* e107::plugLan('forum', 'lan_forum');
|
||||
*
|
||||
* // import defeinitions from /e107_plugins/featurebox/languages/[CurrentLanguage]_admin_featurebox.php</code>
|
||||
* e107::plugLan('featurebox', 'admin_featurebox', true);
|
||||
*
|
||||
* // import defeinitions from /e107_plugins/myplug/languages/[CurrentLanguage].php
|
||||
* e107::plugLan('myplug');
|
||||
*
|
||||
* // import defeinitions from /e107_plugins/myplug/languages/[CurrentLanguage].php
|
||||
* e107::plugLan('myplug', 'admin/common');
|
||||
* </code>
|
||||
*
|
||||
* @param string $plugin plugin name
|
||||
* @param string $fname filename without the extension part (e.g. 'common')
|
||||
* @param boolean $flat false (default, preferred) Language folder structure; true - prepend Language to file name
|
||||
* @return void
|
||||
*/
|
||||
public static function plugLan($plugin, $fname = '', $flat = false)
|
||||
{
|
||||
$plugin = preg_replace('/[^\w]/', '', $plugin);
|
||||
|
||||
if($fname) $fname = e_LANGUAGE.($flat ? '_' : '/').preg_replace('#[^\w/]#', '', $fname);
|
||||
else $fname = e_LANGUAGE;
|
||||
|
||||
$path = e_PLUGIN.$plugin.'/languages/'.$fname.'.php';
|
||||
|
||||
self::includeLan($path, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Routine looks in standard paths for language files associated with a plugin or
|
||||
|
Reference in New Issue
Block a user