Skip to content

Commit

Permalink
improvements on getImageMenuRandom() function.
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel committed Sep 3, 2024
1 parent 5a05116 commit 4463941
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 89 deletions.
File renamed without changes
121 changes: 32 additions & 89 deletions templates/tibiacom/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,38 @@
if (isset($config['boxes'])) {
$config['boxes'] = explode(',', $config['boxes']);
}

/**
* @param $menu
* @return string
*/
function getImageMenuRandom($menu): string
{
global $config, $template_path;
if (!$config['allow_menu_animated']) {
return $menu === 'bgs' ? "/images/header/{$config['background_image']}" : "/images/menu/icon-{$menu}.gif";
}
$images = [
'bgs' => ['last' => '13'],
'news' => ['name' => 'icon-news', 'last' => '06'],
'community' => ['name' => 'icon-community', 'last' => '08'],
'forum' => ['name' => 'icon-forum', 'last' => '10'],
'account' => ['name' => 'icon-account', 'last' => '05'],
'library' => ['name' => 'icon-library', 'last' => '05'],
'wars' => ['name' => 'icon-wars', 'last' => '14'],
'events' => ['name' => 'icon-events', 'last' => '13'],
'support' => ['name' => 'icon-support', 'last' => '11'],
'shops' => ['name' => 'icon-shops', 'last' => '04'],
'charactertrade' => ['name' => 'icon-bazaar', 'last' => '02'],
];
if (!$cfg = $images[$menu] ?? null) {
return "/images/menu/icon-{$menu}.gif";
}
$randomNum = str_pad((string)rand(1, (int)$cfg['last']), strlen($cfg['last']), '0', STR_PAD_LEFT);
$img = isset($cfg['name']) ? "{$cfg['name']}{$randomNum}.gif" : "{$randomNum}.jpg";
return $template_path . ($menu !== 'bgs' ? "/images/menu/anim/{$img}" : "/images/header/bgs/{$img}");
}

?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
Expand Down Expand Up @@ -829,92 +861,3 @@ class="carousel-control-next-icon"

</body>
</html>
/**
* @param $menu
* @return string
*/<?php function getImageMenuRandom($menu): string
{
global $config, $template_path;
if (!$config['allow_menu_animated']) {
return $menu === 'bgs' ? "/images/header/{$config['background_image']}" : "/images/menu/icon-{$menu}.gif";
}
$images = [
'bgs' => ['00.jpg', '01.jpg', '02.jpg', '03.jpg', '04.jpg', '05.jpg', '06.jpg', '07.jpg', '08.jpg', '09.jpg', '10.jpg', '11.jpg', '12.jpg'],
'news' => ['icon-news01.gif', 'icon-news02.gif', 'icon-news03.gif', 'icon-news04.gif', 'icon-news05.gif', 'icon-news06.gif'],
'community' => [
'icon-community01.gif',
'icon-community02.gif',
'icon-community03.gif',
'icon-community04.gif',
'icon-community05.gif',
'icon-community06.gif',
'icon-community07.gif',
'icon-community08.gif',
],
'forum' => [
'icon-forum01.gif',
'icon-forum02.gif',
'icon-forum03.gif',
'icon-forum04.gif',
'icon-forum05.gif',
'icon-forum06.gif',
'icon-forum07.gif',
'icon-forum08.gif',
'icon-forum09.gif',
'icon-forum10.gif',
],
'account' => ['icon-account01.gif', 'icon-account02.gif', 'icon-account03.gif', 'icon-account04.gif', 'icon-account05.gif'],
'library' => ['icon-library01.gif', 'icon-library02.gif', 'icon-library03.gif', 'icon-library04.gif', 'icon-library05.gif'],
'wars' => [
'icon-wars01.gif',
'icon-wars02.gif',
'icon-wars03.gif',
'icon-wars04.gif',
'icon-wars05.gif',
'icon-wars06.gif',
'icon-wars07.gif',
'icon-wars08.gif',
'icon-wars09.gif',
'icon-wars10.gif',
'icon-wars11.gif',
'icon-wars12.gif',
'icon-wars13.gif',
'icon-wars14.gif',
],
'events' => [
'icon-events01.gif',
'icon-events02.gif',
'icon-events03.gif',
'icon-events04.gif',
'icon-events05.gif',
'icon-events06.gif',
'icon-events07.gif',
'icon-events08.gif',
'icon-events09.gif',
'icon-events10.gif',
'icon-events11.gif',
'icon-events12.gif',
'icon-events13.gif',
],
'support' => [
'icon-support01.gif',
'icon-support02.gif',
'icon-support03.gif',
'icon-support04.gif',
'icon-support05.gif',
'icon-support06.gif',
'icon-support07.gif',
'icon-support08.gif',
'icon-support09.gif',
'icon-support10.gif',
'icon-support11.gif',
],
'shops' => ['icon-shops01.gif', 'icon-shops02.gif', 'icon-shops03.gif', 'icon-shops04.gif'],
'charactertrade' => ['icon-bazaar01.gif', 'icon-bazaar02.gif'],
];
if (!$images[$menu]) {
return "/images/menu/icon-{$menu}.gif";
} // generate random number size of the array
$img = $images[$menu][rand(0, count($images[$menu]) - 1)];
return $template_path . ($menu !== 'bgs' ? "/images/menu/anim/{$img}" : "/images/header/bgs/{$img}");
}

0 comments on commit 4463941

Please sign in to comment.