Skip to content

Commit

Permalink
Add lang var check function update version
Browse files Browse the repository at this point in the history
  • Loading branch information
rmcgirr83 committed Sep 21, 2020
1 parent 4b08287 commit d10fe2a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions controller/main_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]),
Expand Down
25 changes: 20 additions & 5 deletions core/nationalflags.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<img class="flag_image" src="' . $this->ext_path_web . 'flags/' . $flags[$flag_id]['flag_image'] . '" ' . $size . ' alt="' . $flag_name . '" title="' . $flag_name . '" />';

Expand Down Expand Up @@ -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 .= '<option value="' . $row['flag_id'] . '" ' . $selected . '>' . $flag_name . '</option>';
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'];
}

Expand Down Expand Up @@ -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;
}
}

0 comments on commit d10fe2a

Please sign in to comment.