mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-01 03:54:56 +02:00
[ticket/17191] Use di and avoid circular ref
PHPBB3-17191
This commit is contained in:
parent
14b7caecd1
commit
8abf9b66e1
@ -3,12 +3,14 @@ services:
|
||||
class: phpbb\language\language_file_helper
|
||||
arguments:
|
||||
- '%core.root_path%'
|
||||
- '@user'
|
||||
- '@config'
|
||||
|
||||
language:
|
||||
class: phpbb\language\language
|
||||
arguments:
|
||||
- '@language.loader'
|
||||
- '@language.helper.language_file'
|
||||
- '@config'
|
||||
|
||||
language.loader_abstract:
|
||||
abstract: true
|
||||
|
@ -3829,10 +3829,10 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
|
||||
$language_file_helper = $phpbb_container->get('language.helper.language_file');
|
||||
|
||||
// Grab the users lang direction and store it for later use
|
||||
$direction = $language_file_helper->get_lang_key_value('direction');
|
||||
$direction = $language_file_helper->get_lang_key_value('direction', $user->data['user_lang']);
|
||||
|
||||
// Get the user_lang string
|
||||
$user_lang = $language_file_helper->get_lang_key_value('user_lang');
|
||||
$user_lang = $language_file_helper->get_lang_key_value('user_lang', $user->data['user_lang']);
|
||||
if (strpos($user_lang, '-x-') !== false)
|
||||
{
|
||||
$user_lang = substr($user_lang, 0, strpos($user_lang, '-x-'));
|
||||
@ -3938,7 +3938,7 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
|
||||
'L_INDEX' => ($config['board_index_text'] !== '') ? $config['board_index_text'] : $user->lang['FORUM_INDEX'],
|
||||
'L_SITE_HOME' => ($config['site_home_text'] !== '') ? $config['site_home_text'] : $user->lang['HOME'],
|
||||
'L_ONLINE_EXPLAIN' => $l_online_time,
|
||||
'L_RECAPTCHA_LANG' => $language_file_helper->get_lang_key_value('recaptcha_lang'),
|
||||
'L_RECAPTCHA_LANG' => $language_file_helper->get_lang_key_value('recaptcha_lang', $user->data['user_lang']),
|
||||
|
||||
'U_PRIVATEMSGS' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=inbox'),
|
||||
'U_RETURN_INBOX' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=inbox'),
|
||||
|
@ -74,10 +74,10 @@ function adm_page_header($page_title)
|
||||
$language_file_helper = $phpbb_container->get('language.helper.language_file');
|
||||
|
||||
// Grab the users lang direction and store it for later use
|
||||
$direction = $language_file_helper->get_lang_key_value('direction');
|
||||
$direction = $language_file_helper->get_lang_key_value('direction', $user->data['user_lang']);
|
||||
|
||||
// Get the user_lang string
|
||||
$user_lang = $language_file_helper->get_lang_key_value('user_lang');
|
||||
$user_lang = $language_file_helper->get_lang_key_value('user_lang', $user->data['user_lang']);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'PAGE_TITLE' => $page_title,
|
||||
|
@ -395,7 +395,7 @@ class feed
|
||||
'FEED_TITLE' => $this->config['sitename'],
|
||||
'FEED_SUBTITLE' => $this->config['site_desc'],
|
||||
'FEED_UPDATED' => $this->feed_helper->format_date($feed_updated_time),
|
||||
'FEED_LANG' => $this->lang_helper->get_lang_key_value('user_lang'),
|
||||
'FEED_LANG' => $this->lang_helper->get_lang_key_value('user_lang', $user->data['user_lang']),
|
||||
'FEED_AUTHOR' => $this->config['sitename'],
|
||||
|
||||
// Feed entries
|
||||
|
@ -253,19 +253,16 @@ class helper
|
||||
*/
|
||||
protected function page_header($page_title, $selected_language = false)
|
||||
{
|
||||
global $phpbb_container;
|
||||
global $user;
|
||||
|
||||
// Path to templates
|
||||
$paths = array($this->phpbb_root_path . 'install/update/new/adm/', $this->phpbb_admin_path);
|
||||
$paths = array_filter($paths, 'is_dir');
|
||||
$path = array_shift($paths);
|
||||
$path = substr($path, strlen($this->phpbb_root_path));
|
||||
// Get the language helper
|
||||
/* @var $language_helper \phpbb\language\language_file_helper */
|
||||
$language_file_helper = $phpbb_container->get('language.helper.language_file');
|
||||
|
||||
// Grab the users lang direction and store it for later use
|
||||
$direction = $language_file_helper->get_lang_key_value('direction');
|
||||
$direction = $this->lang_helper->get_lang_key_value('direction', $user->data['user_lang']);
|
||||
|
||||
$this->template->assign_vars(array(
|
||||
'L_CHANGE' => $this->language->lang('CHANGE'),
|
||||
@ -285,7 +282,7 @@ class helper
|
||||
'S_CONTENT_ENCODING' => 'UTF-8',
|
||||
'S_LANG_SELECT' => $selected_language,
|
||||
|
||||
'S_USER_LANG' => $language_file_helper->get_lang_key_value('user_lang'),
|
||||
'S_USER_LANG' => $this->lang_helper->get_lang_key_value('user_lang', $user->data['user_lang']),
|
||||
));
|
||||
|
||||
$this->render_navigation();
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
namespace phpbb\language;
|
||||
|
||||
use phpbb\config\config;
|
||||
use phpbb\language\exception\invalid_plural_rule_exception;
|
||||
|
||||
/**
|
||||
@ -70,15 +71,29 @@ class language
|
||||
*/
|
||||
protected $loader;
|
||||
|
||||
/**
|
||||
* @var language_file_helper
|
||||
*/
|
||||
protected $lang_helper;
|
||||
|
||||
/**
|
||||
* @var \phpbb\config\config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\language\language_file_loader $loader Language file loader
|
||||
* @param language_file_helper $lang_helper
|
||||
* @param array|null $common_modules Array of common language modules to load (optional)
|
||||
* @param config $config The config
|
||||
*/
|
||||
public function __construct(language_file_loader $loader, $common_modules = null)
|
||||
public function __construct(language_file_loader $loader, language_file_helper $lang_helper, config $config, $common_modules = null)
|
||||
{
|
||||
$this->loader = $loader;
|
||||
$this->lang_helper = $lang_helper;
|
||||
$this->config = $config;
|
||||
|
||||
// Set up default information
|
||||
$this->user_language = null;
|
||||
@ -403,13 +418,10 @@ class language
|
||||
*/
|
||||
public function get_plural_form($number, $force_rule = false)
|
||||
{
|
||||
global $phpbb_container;
|
||||
// Get the language helper
|
||||
/* @var $language_helper \phpbb\language\language_file_helper */
|
||||
$language_file_helper = $phpbb_container->get('language.helper.language_file');
|
||||
global $user;
|
||||
|
||||
// Grab the users lang plural rule
|
||||
$plural_rule_content = $language_file_helper->get_lang_key_value('plural_rule');
|
||||
$plural_rule_content = $this->lang_helper->get_lang_key_value('plural_rule', $user->data['user_lang']);
|
||||
|
||||
$number = (int) $number;
|
||||
$plural_rule = ($force_rule !== false) ? $force_rule : ((isset($plural_rule_content)) ? $plural_rule_content : 1);
|
||||
|
@ -15,8 +15,8 @@ namespace phpbb\language;
|
||||
|
||||
use DomainException;
|
||||
use phpbb\json\sanitizer as json_sanitizer;
|
||||
use phpbb\user;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use phpbb\config\config;
|
||||
|
||||
/**
|
||||
* Helper class for language file related functions
|
||||
@ -28,19 +28,22 @@ class language_file_helper
|
||||
*/
|
||||
protected $phpbb_root_path;
|
||||
|
||||
/** @var user */
|
||||
protected $user;
|
||||
/**
|
||||
* @var \phpbb\config\config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $phpbb_root_path Path to phpBB's root
|
||||
* @param user $user User Object
|
||||
* @param string $phpbb_root_path Path to phpBB's root
|
||||
* @param config $config The config
|
||||
*
|
||||
*/
|
||||
public function __construct(string $phpbb_root_path, \phpbb\user $user)
|
||||
public function __construct(string $phpbb_root_path, config $config)
|
||||
{
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->user = $user;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,16 +82,18 @@ class language_file_helper
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
public function get_lang_key_value($lang_key) : string
|
||||
public function get_lang_key_value($lang_key, $user_lang_db) : string
|
||||
{
|
||||
$available_languages = $this->get_available_languages();
|
||||
|
||||
foreach ($available_languages as $key => $value)
|
||||
{
|
||||
$available_languages[$value['iso']] = $value;
|
||||
unset($available_languages[$key]);
|
||||
}
|
||||
$user_lang = $this->user->data['user_lang'] ?? 'en';
|
||||
return $available_languages[$user_lang][$lang_key];
|
||||
$board_default_lang = $this->config['default_lang'];
|
||||
$user_lang_db = $user_lang_db ?? $board_default_lang;
|
||||
return $available_languages[$user_lang_db][$lang_key];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user