Issues (1369)

includes/functions/int_banner_create.php (8 issues)

1
<?php
2
3
use Planet\DBStaticPlanet;
4
5
/**
6
 * int_banner_create.php
7
 * @version 2.0
8
 * @copyright 2010 Gorlum for http://supernova.ws
9
 *
10
 * heavily based on
11
 *   CreateBanner.php
12
 * @version 1.2 by Ihor
13
 * @version 1.0 copyright 2008 By e-Zobar for XNova
14
 */
15
16
function int_banner_create($id, $type = 'userbar', $format = 'png') {
0 ignored issues
show
The parameter $format is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

16
function int_banner_create($id, $type = 'userbar', /** @scrutinizer ignore-unused */ $format = 'png') {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
17
// banner.php?id=<userid>&type=<banner|userbar>&format=<png>
18
  global $config, $lang;
19
20
  $id = intval($id);
21
22
  switch ($type) {
23
    case 'banner':
24
      $img_name = $config->int_banner_background;
25
    break;
26
27
    default:
28
      $img_name = $config->int_userbar_background;
29
    break;
30
  }
31
  $size = getimagesize(SN_ROOT_PHYSICAL . $img_name);
32
  $im = imagecreatefrompng(SN_ROOT_PHYSICAL . $img_name);
33
  $image = imagecreatetruecolor($size[0], $size[1]);
34
  imagecopy($image, $im, 0, 0, 0, 0, $size[0], $size[1]);
35
  imagedestroy($im);
36
37
  // Colors
38
//  $color = "FFFFFF";
39
//  $red = hexdec(substr($color, 0, 2));
40
//  $green = hexdec(substr($color, 2, 4));
41
//  $blue = hexdec(substr($color, 4, 6));
42
//  $select = imagecolorallocate($image, $red, $green, $blue);
43
  $txt_shadow = imagecolorallocatealpha($image, 255, 255, 255, 0); // was 255
44
  $txt_color = imagecolorallocatealpha($image, 255, 255, 255, 2);
45
  $txt_shadow2 = imagecolorallocatealpha($image, 255, 255, 255, 0); // was 255
46
  $txt_color2 = imagecolorallocatealpha($image, 255, 255, 255, 40);
47
48
  $fonts = array(
49
    'userbar'  => SN_ROOT_PHYSICAL . "design/fonts/" . $config->int_userbar_font,
50
    'universe' => SN_ROOT_PHYSICAL . "design/fonts/" . $config->int_banner_fontUniverse,
51
    'raids'    => SN_ROOT_PHYSICAL . "design/fonts/" . $config->int_banner_fontRaids,
52
    'info'     => SN_ROOT_PHYSICAL . "design/fonts/" . $config->int_banner_fontInfo,
53
  );
54
55
  if ($id) {
56
    // Querys
57
    $user = db_user_by_id($id);
0 ignored issues
show
Deprecated Code introduced by
The function db_user_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

57
    $user = /** @scrutinizer ignore-deprecated */ db_user_by_id($id);
Loading history...
58
    $planet_row = DBStaticPlanet::db_planet_by_id($user['id_planet']);
59
60
    // Variables
61
    $b_user = $user['username'];
62
    $b_ally = $user['ally_name'];
63
    $b_planet = $planet_row['name'];
64
    $b_xyz = "[" . $planet_row['galaxy'] . ":" . $planet_row['system'] . ":" . $planet_row['planet'] . "]";
65
    $b_lvl = ($user['total_rank'] ? $user['total_rank'] : $config->users_amount) . "/{$config->users_amount}";
66
  } else {
67
    $b_user = $lang['ov_banner_empty_id'];
68
  }
69
70
  $b_univ = $config->game_name;
71
  switch ($type) {
72
    case 'banner':
73
      // Banner size 416 x 58
74
      $fsize = 15;
75
76
      $is = imagettfbbox($fsize, 0, $fonts['universe'], $b_univ);
77
      imagettftext($image, $fsize, 0, $size[0] - 4 - $is[2], $size[1] - 2, $txt_shadow, $fonts['universe'], $b_univ);
78
      imagettftext($image, $fsize, 0, $size[0] - 6 - $is[2], $size[1] - 4, $txt_color, $fonts['universe'], $b_univ);
79
80
      // Player name
81
      imagettftext($image, 11, 0, 8, 26, $txt_shadow, $fonts['info'], $b_user);
82
      imagettftext($image, 11, 0, 6, 23, $txt_color, $fonts['info'], $b_user);
83
84
      if ($id) {
85
        // Player level - right-alligned
86
        $is = imagettfbbox(11, 0, $fonts['info'], $b_lvl);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $b_lvl does not seem to be defined for all execution paths leading up to this point.
Loading history...
87
        imagettftext($image, 11, 0, $size[0] - 4 - $is[2], 25, $txt_shadow, $fonts['info'], $b_lvl);
88
        imagettftext($image, 11, 0, $size[0] - 6 - $is[2], 23, $txt_color, $fonts['info'], $b_lvl);
89
90
        // Ally name
91
        $is = imagettfbbox(9, 0, $fonts['info'], $b_ally);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $b_ally does not seem to be defined for all execution paths leading up to this point.
Loading history...
92
        imagettftext($image, 9, 0, 412 - $is[2], 37, $txt_shadow, $fonts['info'], $b_ally);
93
        imagettftext($image, 9, 0, 410 - $is[2], 35, $txt_color, $fonts['info'], $b_ally);
94
95
        // Player b_planet
96
        imagettftext($image, 6, 0, 8, 10, $txt_shadow2, $fonts['raids'], $b_planet . " " . $b_xyz);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $b_xyz does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $b_planet does not seem to be defined for all execution paths leading up to this point.
Loading history...
97
        imagettftext($image, 6, 0, 6, 9, $txt_color2, $fonts['raids'], $b_planet . " " . $b_xyz);
98
99
        //StatPoint
100
        $b_points = $lang['ov_points'] . ": " . HelperString::numberFloorAndFormat($user['total_points']);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $user does not seem to be defined for all execution paths leading up to this point.
Loading history...
101
        $is = imagettfbbox(8, 0, $fonts['info'], $b_points);
102
        imagettftext($image, 8, 0, 412 - $is[2], 11, $txt_shadow, $fonts['info'], $b_points);
103
        imagettftext($image, 8, 0, 410 - $is[2], 9, $txt_color, $fonts['info'], $b_points);
104
105
        //Raids Total
106
        imagettftext($image, 6, 0, 8, 37, $txt_shadow2, $fonts['raids'], $lang['NumberOfRaids']);
107
        imagettftext($image, 6, 0, 6, 35, $txt_color2, $fonts['raids'], $lang['NumberOfRaids']);
108
        $b_points = ": " . HelperString::numberFloorAndFormat($user['raids']);
109
        imagettftext($image, 6, 0, 61, 37, $txt_shadow2, $fonts['raids'], $b_points);
110
        imagettftext($image, 6, 0, 59, 35, $txt_color2, $fonts['raids'], $b_points);
111
112
        //Raids Won
113
        imagettftext($image, 6, 0, 8, 47, $txt_shadow2, $fonts['raids'], $lang['RaidsWin']);
114
        imagettftext($image, 6, 0, 6, 45, $txt_color2, $fonts['raids'], $lang['RaidsWin']);
115
        $b_points = ": " . HelperString::numberFloorAndFormat($user['raidswin']);
116
        imagettftext($image, 6, 0, 61, 47, $txt_shadow2, $fonts['raids'], $b_points);
117
        imagettftext($image, 6, 0, 59, 45, $txt_color2, $fonts['raids'], $b_points);
118
119
        //Raids Lost
120
        imagettftext($image, 6, 0, 8, 57, $txt_shadow2, $fonts['raids'], $lang['RaidsLoose']);
121
        imagettftext($image, 6, 0, 6, 55, $txt_color2, $fonts['raids'], $lang['RaidsLoose']);
122
        $b_points = ": " . HelperString::numberFloorAndFormat($user['raidsloose']);
123
        imagettftext($image, 6, 0, 61, 57, $txt_shadow2, $fonts['raids'], $b_points);
124
        imagettftext($image, 6, 0, 59, 55, $txt_color2, $fonts['raids'], $b_points);
125
      }
126
127
    break;
128
129
    default:
130
      // Userbar 350 x 19
131
      $b_univ = strtoupper($b_univ);
132
      $is = imagettfbbox(9, 0, $fonts['userbar'], $b_univ);
133
      $is = $size[0] - $is[2] - 2;
134
      imagettftext($image, 9, 0, $is, $size[1] - 3, $txt_shadow, $fonts['userbar'], $b_univ);
135
      imagettftext($image, 9, 0, $is - 1, $size[1] - 5, $txt_color, $fonts['userbar'], $b_univ);
136
      imagettftext($image, 22, 0, $is - 8, $size[1], $txt_color, $fonts['userbar'], '/');
137
138
      // Player name
139
      imagettftext($image, 9, 0, 4, $size[1] - 4, $txt_shadow, $fonts['userbar'], $b_user);
140
      imagettftext($image, 9, 0, 2, $size[1] - 6, $txt_color, $fonts['userbar'], $b_user);
141
142
      if ($id) {
143
        // Player level - right-alligned
144
        $isp = imagettfbbox(9, 0, $fonts['userbar'], $b_lvl);
145
        imagettftext($image, 9, 0, $is - $isp[2] - 10, $size[1] - 4, $txt_shadow, $fonts['userbar'], $b_lvl);
146
        imagettftext($image, 9, 0, $is - $isp[2] - 10 - 1, $size[1] - 4 - 1, $txt_color, $fonts['userbar'], $b_lvl);
147
      }
148
  }
149
150
  //And now convert it back to PNG-8
151
  $im_result = imagecreate($size[0], $size[1]);
152
  imagecopy($im_result, $image, 0, 0, 0, 0, $size[0], $size[1]);
153
  imagedestroy($image);
154
  //And save it
155
  $imagetypes = imagetypes();
0 ignored issues
show
The assignment to $imagetypes is dead and can be removed.
Loading history...
156
  // TODO: Add support to different image types
157
  header("Content-type: image/png");
158
  imagepng($im_result);
159
  imagedestroy($im_result);
160
}
161