From d10fe2ad80e910e1db4f9f43129bc88135f10740 Mon Sep 17 00:00:00 2001 From: Richard McGirr Date: Mon, 21 Sep 2020 06:57:06 -0500 Subject: [PATCH] Add lang var check function update version --- composer.json | 4 ++-- controller/main_controller.php | 5 +++-- core/nationalflags.php | 25 ++++++++++++++++++++----- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index ac6f9e3..8ed2305 100644 --- a/composer.json +++ b/composer.json @@ -3,8 +3,8 @@ "type": "phpbb-extension", "description": "Allows a user to be able to choose a national flag and have a top (those with the most users selecting the flag) number of flags display on the index page of a phpBB forum. Header is link to a listing of all users of a flag. Clicking on user count of the flag displays the users that have that flag set. This extension requires at least phpBB version 3.2.6. Must have version 2.0.0 of Collapsible Forum Categories to take advantage of that extension.", "homepage": "https://github.com/rmcgirr83/nationalflags", - "version": "2.2.3", - "time": "2020-09-12", + "version": "2.2.4", + "time": "2020-09-21", "keywords": [ "phpbb", "extension", diff --git a/controller/main_controller.php b/controller/main_controller.php index 5cb6843..f3a47fb 100644 --- a/controller/main_controller.php +++ b/controller/main_controller.php @@ -319,7 +319,7 @@ protected function display_flag($flag_id, $start, $limit) $flags_array = $this->nationalflags->get_flag_cache(); - $flag_name = ($this->language->lang(strtoupper(str_replace(" ", "_", $flags_array[$flag_id]['flag_name']))) !== null) ? html_entity_decode($this->language->lang(strtoupper(str_replace(" ", "_", $flags_array[$flag_id]['flag_name'])))) : html_entity_decode($flags_array[$flag_id]['flag_name']); + $flag_name = $this->nationalflags->flag_name_lang_var($flags_array[$flag_id]['flag_name']); $this->template->assign_vars([ 'FLAG' => $flag_name, @@ -337,7 +337,8 @@ protected function display_flag($flag_id, $start, $limit) 'FORUM_NAME' => $this->language->lang('NATIONAL_FLAGS'), ]); - $flag_name = ($this->language->lang(strtoupper(str_replace(" ", "_", $flags_array[$flag_id]['flag_name']))) !== null) ? html_entity_decode($this->language->lang(strtoupper(str_replace(" ", "_", $flags_array[$flag_id]['flag_name'])))) : html_entity_decode($flags_array[$flag_id]['flag_name']); + $flag_name = $this->nationalflags->flag_name_lang_var($flags_array[$flag_id]['flag_name']); + // Assign breadcrumb template vars for the flags page $this->template->assign_block_vars('navlinks', [ 'U_VIEW_FORUM' => $this->helper->route('rmcgirr83_nationalflags_getflags', ['flag_id' => $flag_id]), diff --git a/core/nationalflags.php b/core/nationalflags.php index 3fbe15f..6b76c41 100644 --- a/core/nationalflags.php +++ b/core/nationalflags.php @@ -118,7 +118,7 @@ public function get_user_flag($flag_id = false, $size = 0) if ($flag_id) { - $flag_name = ($this->language->lang(strtoupper(str_replace(" ", "_", $flags[$flag_id]['flag_name']))) !== null) ? html_entity_decode($this->language->lang(strtoupper(str_replace(" ", "_", $flags[$flag_id]['flag_name'])))) : html_entity_decode($flags[$flag_id]['flag_name']); + $flag_name = $this->flag_name_lang_var($flags[$flag_id]['flag_name']); $size = (!empty($size)) ? 'style="height:' . $size . 'px; width:auto;"' : ''; $flag = '' . $flag_name . ''; @@ -187,7 +187,7 @@ public function list_flags($flag_id = false) $selected = ' selected="selected"'; } - $flag_name = ($this->language->lang(strtoupper(str_replace(" ", "_", $row['flag_name']))) !== null) ? html_entity_decode($this->language->lang(strtoupper(str_replace(" ", "_", $row['flag_name'])))) : $row['flag_name']; + $flag_name = $this->flag_name_lang_var($row['flag_name']); $flag_options .= ''; } @@ -309,7 +309,7 @@ public function get_flag($flag_id) $flag_img = $this->ext_path . 'flags/' . $flags[$flag_id]['flag_image']; $flag_img = str_replace('./', generate_board_url() . '/', $flag_img); //fix paths - $flag_name = ($this->language->lang(strtoupper(str_replace(" ", "_", $flags[$flag_id]['flag_name']))) !== null) ? $this->language->lang(strtoupper(str_replace(" ", "_", $flags[$flag_id]['flag_name']))) : $flags[$flag_id]['flag_name']; + $flag_name = $this->flag_name_lang_var($flags[$flag_id]['flag_name']); $json = new JsonResponse([ 'flag_image' => $flag_img, @@ -455,9 +455,8 @@ public function display_flag_options($user_flag) if ($user_flag) { - $flag_name = ($this->language->lang(strtoupper(str_replace(" ", "_", $flags[$user_flag]['flag_name']))) !== null) ? html_entity_decode($this->language->lang(strtoupper(str_replace(" ", "_", $flags[$user_flag]['flag_name'])))) : html_entity_decode($flags[$user_flag]['flag_name']); + $flag_name = $this->flag_name_lang_var($flags[$user_flag]['flag_name']); - $flag_name = $flag_name; $flag_image = $flags[$user_flag]['flag_image']; } @@ -485,4 +484,20 @@ public function trash_the_cache() { $this->cache->destroy('_users_and_flags'); } + + /** + * Check for translated flag name for the user + * + * @return string translated flag name + * @access public + */ + public function flag_name_lang_var($flag_name = '') + { + if (array_key_exists((strtoupper(str_replace(" ", "_", $flag_name))), $this->language->get_lang_array())) + { + $flag_name = html_entity_decode($this->language->lang(strtoupper(str_replace(" ", "_", $flag_name)))); + } + + return $flag_name; + } }