Completed
Push — work-fleets ( fff2b6...e0e753 )
by SuperNova.WS
06:54
created

template.php ➔ sn_display()   F

Complexity

Conditions 48
Paths > 20000

Size

Total Lines 162
Code Lines 100

Duplication

Lines 30
Ratio 18.52 %

Importance

Changes 8
Bugs 0 Features 0
Metric Value
cc 48
eloc 100
nc 115015680
nop 6
dl 30
loc 162
rs 2
c 8
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
// Wrappers for functions
4
5
/**
6
 * @param $u_dpath
7
 *
8
 * @return mixed
9
 */
10
function gettemplatename($u_dpath) {
11
  static $template_names = array();
12
13
  if(!isset($template_names[$u_dpath])) {
14
    $template_names[$u_dpath] = file_exists(SN_ROOT_PHYSICAL . $u_dpath . 'tmpl.ini') ? sys_file_read(SN_ROOT_PHYSICAL . $u_dpath . 'tmpl.ini') : TEMPLATE_NAME;
15
  }
16
17
  return $template_names[$u_dpath];
18
}
19
20
/**
21
 * @param        $mes
22
 * @param string $title
23
 * @param string $dest
24
 * @param int    $time
25
 */
26
function AdminMessage($mes, $title = 'Error', $dest = '', $time = 3) {
27
  $page = parsetemplate(gettemplate('admin/message_body'), array('title' => $title, 'mes' => $mes,));
28
29
  display($page, $title, false, ($dest ? "<meta http-equiv=\"refresh\" content=\"{$time};URL=javascript:self.location='{$dest}';\">" : ''), true);
30
}
31
32
/**
33
 * @param           $mes
34
 * @param string    $title
35
 * @param string    $dest
36
 * @param int       $time
37
 * @param bool|true $show_header
38
 */
39
function message($mes, $title = 'Error', $dest = '', $time = 5, $show_header = true) {
40
  $template = gettemplate('message_body', true);
41
  $template->assign_vars(array(
42
    'title' => $title,
43
    'mes'   => $mes,
44
    'DEST'  => $dest,
45
  ));
46
47
  display($template, $title, $show_header, (($dest != '') ? "<meta http-equiv=\"refresh\" content=\"{$time};url={$dest}\">" : ""), false);
48
}
49
50
/**
51
 * @param $sn_menu
52
 * @param $sn_menu_extra
53
 */
54
function tpl_menu_merge_extra(&$sn_menu, &$sn_menu_extra) {
55
  if(empty($sn_menu) || empty($sn_menu_extra)) {
56
    return;
57
  }
58
59
  foreach($sn_menu_extra as $menu_item_id => $menu_item) {
60
    if(empty($menu_item['LOCATION'])) {
61
      $sn_menu[$menu_item_id] = $menu_item;
62
      continue;
63
    }
64
65
    $item_location = $menu_item['LOCATION'];
66
    unset($menu_item['LOCATION']);
67
68
    $is_positioned = $item_location[0];
69
    if($is_positioned == '+' || $is_positioned == '-') {
70
      $item_location = substr($item_location, 1);
71
    } else {
72
      $is_positioned = '';
73
    }
74
75
    if($item_location) {
76
      $menu_keys = array_keys($sn_menu);
77
      $insert_position = array_search($item_location, $menu_keys);
78
      if($insert_position === false) {
79
        $insert_position = count($sn_menu) - 1;
80
        $is_positioned = '+';
81
        $item_location = '';
82
      }
83
    } else {
84
      $insert_position = $is_positioned == '-' ? 0 : count($sn_menu);
85
    }
86
87
    $insert_position += $is_positioned == '+' ? 1 : 0;
88
    $spliced = array_splice($sn_menu, $insert_position, count($sn_menu) - $insert_position);
89
    $sn_menu[$menu_item_id] = $menu_item;
90
91
    if(!$is_positioned && $item_location) {
92
      unset($spliced[$item_location]);
93
    }
94
    $sn_menu = array_merge($sn_menu, $spliced);
95
  }
96
97
  $sn_menu_extra = array();
98
}
99
100
/**
101
 * @param array    $sn_menu
102
 * @param template $template
103
 */
104
function tpl_menu_assign_to_template(&$sn_menu, &$template) {
105
  if(empty($sn_menu) || !is_array($sn_menu)) {
106
    return;
107
  }
108
109
  foreach($sn_menu as $menu_item_id => $menu_item) {
110
    if(!$menu_item) {
111
      continue;
112
    }
113
114
    if(is_string($menu_item_id)) {
115
      $menu_item['ID'] = $menu_item_id;
116
    }
117
118
    if($menu_item['TYPE'] == 'lang') {
119
      $lang_string = &classLocale::$lang;
120
      if(preg_match('#(\w+)(?:\[(\w+)\])?(?:\[(\w+)\])?(?:\[(\w+)\])?(?:\[(\w+)\])?#', $menu_item['ITEM'], $matches) && count($matches) > 1) {
121
        for($i = 1; $i < count($matches); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
122
          if(defined($matches[$i])) {
123
            $matches[$i] = constant($matches[$i]);
124
          }
125
          $lang_string = &$lang_string[$matches[$i]];
126
        }
127
      }
128
      $menu_item['ITEM'] = $lang_string && is_string($lang_string) ? $lang_string : "{L_{$menu_item['ITEM']}}";
129
    }
130
131
    $menu_item['ALT'] = htmlentities($menu_item['ALT']);
132
    $menu_item['TITLE'] = htmlentities($menu_item['TITLE']);
133
134
    if(!empty($menu_item['ICON'])) {
135
      if(is_string($menu_item['ICON'])) {
136
        $menu_item['ICON_PATH'] = $menu_item['ICON'];
137
      } else {
138
        $menu_item['ICON'] = $menu_item_id;
139
      }
140
    }
141
142
    $template->assign_block_vars('menu', $menu_item);
143
  }
144
}
145
146
/**
147
 * @return template
148
 */
149
function tpl_render_menu() {
150
  global $user, $template_result, $sn_menu_admin_extra, $sn_menu_admin, $sn_menu, $sn_menu_extra;
151
152
  lng_include('admin');
153
154
  $template = gettemplate('menu', true);
155
  $template->assign_recursive($template_result);
156
157
  $template->assign_vars(array(
158
    'USER_AUTHLEVEL'      => $user['authlevel'],
159
    'USER_AUTHLEVEL_NAME' => classLocale::$lang['user_level'][$user['authlevel']],
160
//    'USER_IMPERSONATOR'   => $template_result[F_IMPERSONATE_STATUS] != LOGIN_UNDEFINED,
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
161
    'PAYMENT'             => sn_module_get_active_count('payment'),
162
    'MENU_START_HIDE'     => !empty($_COOKIE[SN_COOKIE . '_menu_hidden']) || defined('SN_GOOGLE'),
163
  ));
164
165
  if(isset($template_result['MENU_CUSTOMIZE'])) {
166
    $template->assign_vars(array(
167
      'PLAYER_OPTION_MENU_SHOW_ON_BUTTON'   => classSupernova::$user_options[PLAYER_OPTION_MENU_SHOW_ON_BUTTON],
168
      'PLAYER_OPTION_MENU_HIDE_ON_BUTTON'   => classSupernova::$user_options[PLAYER_OPTION_MENU_HIDE_ON_BUTTON],
169
      'PLAYER_OPTION_MENU_HIDE_ON_LEAVE'    => classSupernova::$user_options[PLAYER_OPTION_MENU_HIDE_ON_LEAVE],
170
      'PLAYER_OPTION_MENU_UNPIN_ABSOLUTE'   => classSupernova::$user_options[PLAYER_OPTION_MENU_UNPIN_ABSOLUTE],
171
      'PLAYER_OPTION_MENU_ITEMS_AS_BUTTONS' => classSupernova::$user_options[PLAYER_OPTION_MENU_ITEMS_AS_BUTTONS],
172
      'PLAYER_OPTION_MENU_WHITE_TEXT'       => classSupernova::$user_options[PLAYER_OPTION_MENU_WHITE_TEXT],
173
      'PLAYER_OPTION_MENU_OLD'              => classSupernova::$user_options[PLAYER_OPTION_MENU_OLD],
174
      'PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON' => empty($_COOKIE[SN_COOKIE . '_menu_hidden']) && !defined('SN_GOOGLE')
175
        ? classSupernova::$user_options[PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON] : 1,
176
    ));
177
  }
178
179
  if(defined('IN_ADMIN') && IN_ADMIN === true && !empty($user['authlevel']) && $user['authlevel'] > 0) {
180
    tpl_menu_merge_extra($sn_menu_admin, $sn_menu_admin_extra);
181
    tpl_menu_assign_to_template($sn_menu_admin, $template);
182
  } else {
183
    tpl_menu_merge_extra($sn_menu, $sn_menu_extra);
184
    tpl_menu_assign_to_template($sn_menu, $template);
185
  }
186
187
  return $template;
188
}
189
190
/**
191
 * @param template|string $page
192
 * @param string          $title
193
 * @param bool|true       $isDisplayTopNav
194
 * @param string          $metatags
195
 * @param bool|false      $AdminPage
196
 * @param bool|true       $isDisplayMenu
197
 *
198
 * @return mixed
199
 */
200
function display($page, $title = '', $isDisplayTopNav = true, $metatags = '', $AdminPage = false, $isDisplayMenu = true, $exitStatus = true) {
0 ignored issues
show
Unused Code introduced by
The parameter $AdminPage is not used and could be removed.

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

Loading history...
201
  return sn_function_call(__FUNCTION__, array($page, $title, $isDisplayTopNav, $metatags, $isDisplayMenu, $exitStatus));
202
}
203
204
/**
205
 * @param template|string $page
206
 * @param string          $title
207
 * @param bool|true       $isDisplayTopNav
208
 * @param string          $metatags
209
 * @param bool|false      $AdminPage
0 ignored issues
show
Bug introduced by
There is no parameter named $AdminPage. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
210
 * @param bool|true       $isDisplayMenu
211
 * @param bool|int|string $exitStatus - Код или сообщение выхода
212
 */
213
function sn_display($page, $title = '', $isDisplayTopNav = true, $metatags = '', $isDisplayMenu = true, $exitStatus = true) {
214
  global $user, $planetrow, $template_result, $sn_page_name;
215
216
  $in_admin = defined('IN_ADMIN') && IN_ADMIN === true;
217
  $is_login = defined('LOGIN_LOGOUT') && LOGIN_LOGOUT === true;
218
219
  if(is_object($page)) {
220
    isset($page->_rootref['MENU']) ? $isDisplayMenu = $page->_rootref['MENU'] : false;
221
    isset($page->_rootref['NAVBAR']) ? $isDisplayTopNav = $page->_rootref['NAVBAR'] : false;
222
223
    !$title && !empty($page->_rootref['PAGE_HEADER']) ? $title = $page->_rootref['PAGE_HEADER'] : false;
224
    !isset($page->_rootref['PAGE_HEADER']) && $title ? $page->assign_var('PAGE_HEADER', $title) : false;
225
  }
226
227
  if(empty($user['id']) || !is_numeric($user['id'])) {
228
    $isDisplayMenu = false;
229
    $isDisplayTopNav = false;
230
  }
231
232
  !empty(classSupernova::$sn_mvc['view']['']) ? execute_hooks(classSupernova::$sn_mvc['view'][''], $page, 'view', '') : false;
233
234
  // Global header
235
  $user_time_diff = playerTimeDiff::user_time_diff_get();
236
  $user_time_measured_unix = intval(isset($user_time_diff[PLAYER_OPTION_TIME_DIFF_MEASURE_TIME]) ? strtotime($user_time_diff[PLAYER_OPTION_TIME_DIFF_MEASURE_TIME]) : 0);
237
238
  $font_size = !empty($_COOKIE[SN_COOKIE_F]) ? $_COOKIE[SN_COOKIE_F] : classSupernova::$user_options[PLAYER_OPTION_BASE_FONT_SIZE];
239 View Code Duplication
  if(strpos($font_size, '%') !== false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
240
    // Размер шрифта в процентах
241
    $font_size = min(max(floatval($font_size), FONT_SIZE_PERCENT_MIN), FONT_SIZE_PERCENT_MAX) . '%';
242
  } elseif(strpos($font_size, 'px') !== false) {
243
    // Размер шрифта в пикселях
244
    $font_size = min(max(floatval($font_size), FONT_SIZE_PIXELS_MIN), FONT_SIZE_PIXELS_MAX) . 'px';
245
  } else {
246
    // Не мышонка, не лягушка...
247
    $font_size = FONT_SIZE_PERCENT_DEFAULT_STRING;
248
  }
249
250
  $template_result['LOGIN_LOGOUT'] = $is_login;
251
252
  $template = gettemplate('_global_header', true);
253
254
  if(!empty(classSupernova::$sn_mvc['javascript'])) {
255 View Code Duplication
    foreach(classSupernova::$sn_mvc['javascript'] as $page_name => $script_list) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
256
      if(empty($page_name) || $page_name == $sn_page_name) {
257
        foreach($script_list as $filename => $content) {
258
          $template_result['.']['javascript'][] = array(
259
            'FILE'    => $filename,
260
            'CONTENT' => $content,
261
          );
262
        }
263
      }
264
    }
265
  }
266
267
  empty(classSupernova::$sn_mvc['css']) ? classSupernova::$sn_mvc['css'] = array('' => array()) : false;
268
  $standard_css = array(
269
    'design/css/jquery-ui.css'  => '',
270
    'design/css/global.min.css' => '',
271
  );
272
  $is_login ? $standard_css['design/css/login.min.css'] = '' : false;
273
  $standard_css += array(
274
//    'design/css/design/css/global-ie.min.css' => '', // TODO
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
275
    TEMPLATE_PATH . '/_template.min.css'                                  => '',
276
    ($user['dpath'] ? $user['dpath'] : DEFAULT_SKINPATH) . 'skin.min.css' => '',
277
  );
278
279
  // Prepending standard CSS files
280
  classSupernova::$sn_mvc['css'][''] = array_merge($standard_css, classSupernova::$sn_mvc['css']['']);
281
282
283 View Code Duplication
  foreach(classSupernova::$sn_mvc['css'] as $page_name => $script_list) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
284
    if(empty($page_name) || $page_name == $sn_page_name) {
285
      foreach($script_list as $filename => $content) {
286
        $template_result['.']['css'][] = array(
287
          'FILE'    => $filename,
288
          'CONTENT' => $content,
289
        );
290
      }
291
    }
292
  }
293
294
  $classConfig = classSupernova::$config;
295
  $template->assign_vars(array(
296
    'USER_AUTHLEVEL' => intval($user['authlevel']),
297
298
    'FONT_SIZE'                        => $font_size,
299
    'FONT_SIZE_PERCENT_DEFAULT_STRING' => FONT_SIZE_PERCENT_DEFAULT_STRING,
300
301
    'SN_TIME_NOW'          => SN_TIME_NOW,
302
    'LOGIN_LOGOUT'         => $is_login,
303
    'GAME_MODE_CSS_PREFIX' => classSupernova::$config->game_mode == GAME_BLITZ ? 'blitz_' : '',
304
    //'TIME_DIFF'                => SN_CLIENT_TIME_DIFF,
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
305
    'TIME_DIFF_MEASURE'    => intval(
306
      empty($user_time_diff[PLAYER_OPTION_TIME_DIFF_FORCED])
307
      &&
308
      (SN_TIME_NOW - $user_time_measured_unix > PERIOD_HOUR || $user_time_diff[PLAYER_OPTION_TIME_DIFF] == '')
309
    ), // Проводить замер только если не выставлен флаг форсированного замера И (иссяк интервал замера ИЛИ замера еще не было)
310
    //'TIME_UTC_OFFSET'          => defined('SN_CLIENT_TIME_UTC_OFFSET') ? SN_CLIENT_TIME_UTC_OFFSET : '',
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
311
312
    'title'                    => ($title ? "{$title} - " : '') . classLocale::$lang['sys_server'] . " {$classConfig->game_name} - " . classLocale::$lang['sys_supernova'],
313
    '-meta-'                   => $metatags,
314
    'ADV_SEO_META_DESCRIPTION' => classSupernova::$config->adv_seo_meta_description,
315
    'ADV_SEO_META_KEYWORDS'    => classSupernova::$config->adv_seo_meta_keywords,
316
    'ADV_SEO_JAVASCRIPT'       => classSupernova::$config->adv_seo_javascript,
317
318
    'LANG_LANGUAGE'  => classLocale::$lang['LANG_INFO']['LANG_NAME_ISO2'],
319
    'LANG_ENCODING'  => 'utf-8',
320
    'LANG_DIRECTION' => classLocale::$lang['LANG_INFO']['LANG_DIRECTION'],
321
322
    'SOUND_ENABLED'                        => classSupernova::$user_options[PLAYER_OPTION_SOUND_ENABLED],
323
    'PLAYER_OPTION_ANIMATION_DISABLED'     => classSupernova::$user_options[PLAYER_OPTION_ANIMATION_DISABLED],
324
    'PLAYER_OPTION_PROGRESS_BARS_DISABLED' => classSupernova::$user_options[PLAYER_OPTION_PROGRESS_BARS_DISABLED],
325
326
    'IMPERSONATING'                        => !empty($template_result[F_IMPERSONATE_STATUS]) ? sprintf(classLocale::$lang['sys_impersonated_as'], $user['username'], $template_result[F_IMPERSONATE_OPERATOR]) : '',
327
    'PLAYER_OPTION_DESIGN_DISABLE_BORDERS' => classSupernova::$user_options[PLAYER_OPTION_DESIGN_DISABLE_BORDERS],
328
  ));
329
  $template->assign_recursive($template_result);
330
  displayP(parsetemplate($template));
331
332
  if(($isDisplayMenu || $in_admin) && !isset($_COOKIE['menu_disable'])) {
333
    // $AdminPage = $AdminPage ? $user['authlevel'] : 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
334
    displayP(parsetemplate(tpl_render_menu()));
335
  }
336
337
  if($isDisplayTopNav && !$in_admin) {
338
    displayP(parsetemplate(tpl_render_topnav($user, $planetrow)));
339
  }
340
341
  displayP(parsetemplate(gettemplate('_content_header', true)));
342
343
  !is_array($page) ? $page = array($page) : false;
344
  $result_added = false;
345
  foreach($page as $page_item) {
346
    if(!$result_added && is_object($page_item) && isset($page_item->_tpldata['result'])) {
347
      $page_item = gettemplate('_result_message', $page_item);
348
      $temp = $page_item->files['_result_message'];
349
      unset($page_item->files['_result_message']);
350
      $page_item->files = array_reverse($page_item->files);
351
      $page_item->files['_result_message'] = $temp;
352
      $page_item->files = array_reverse($page_item->files);
353
      $result_added = true;
354
    }
355
    displayP($page_item);
356
  }
357
358
  displayP(parsetemplate(gettemplate('_content_footer', true)));
359
360
  // Global footer
361
  $template = gettemplate('_global_footer', true);
362
  $template->assign_vars(array(
363
    'ADMIN_EMAIL' => classSupernova::$config->game_adminEmail,
364
    'SN_TIME_NOW' => SN_TIME_NOW,
365
    'SN_VERSION'  => SN_VERSION,
366
  ));
367
  displayP(parsetemplate($template));
368
369
  $user['authlevel'] >= 3 && classSupernova::$config->debug ? classSupernova::$debug->echo_log() : false;;
370
371
  classSupernova::$db->db_disconnect();
372
373
  $exitStatus and die($exitStatus === true ? 0 : $exitStatus);
374
}
375
376
/**
377
 * @param       $time
378
 * @param       $event
379
 * @param       $msg
380
 * @param       $coordinates
381
 * @param       $is_decrease
382
 * @param Fleet $objFleet
383
 * @param       $fleet_flying_sorter
384
 * @param       $fleet_flying_events
385
 * @param       $fleet_event_count
386
 */
387
function tpl_topnav_event_build_helper($time, $event, $msg, $coordinates, $is_decrease, Fleet $objFleet, &$fleet_flying_sorter, &$fleet_flying_events, &$fleet_event_count) {
388
  $fleet_flying_sorter[$fleet_event_count] = $time;
389
  $fleet_flying_events[$fleet_event_count] = array(
390
    'OBJECT'           => $objFleet,
391
    'FLEET_ID'         => $objFleet->dbId,
392
    'EVENT'            => $event,
393
    'COORDINATES'      => uni_render_coordinates($coordinates, ''),
394
    'COORDINATES_TYPE' => $coordinates['type'],
395
    'TEXT'             => $msg,
396
    'DECREASE'         => $is_decrease,
397
  );
398
  $fleet_event_count++;
399
}
400
401
/**
402
 * @param template       $template
403
 * @param FleetList|null $FleetList
404
 * @param string         $type
405
 */
406
function tpl_topnav_event_build(&$template, $FleetList, $type = 'fleet') {
407
  if(empty($FleetList)) {
408
    return;
409
  }
410
411
  $classLocale = classLocale::$lang;
412
413
  $fleet_event_count = 0;
414
  $fleet_flying_sorter = array();
415
  $fleet_flying_events = array();
416
  foreach($FleetList->_container as $objFleet) {
417
    $will_return = true;
418
    if(!$objFleet->isReturning()) {
419
      // cut fleets on Hold and Expedition
420
      if($objFleet->time_arrive_to_target >= SN_TIME_NOW) {
421
        $objFleet->mission_type == MT_RELOCATE ? $will_return = false : false;
422
        tpl_topnav_event_build_helper($objFleet->time_arrive_to_target, EVENT_FLEET_ARRIVE, classLocale::$lang['sys_event_arrive'], $objFleet->target_coordinates_typed(), !$will_return, $objFleet, $fleet_flying_sorter, $fleet_flying_events, $fleet_event_count);
423
      }
424
      if($objFleet->time_mission_job_complete) {
425
        tpl_topnav_event_build_helper($objFleet->time_mission_job_complete, EVENT_FLEET_STAY, classLocale::$lang['sys_event_stay'], $objFleet->target_coordinates_typed(), false, $objFleet, $fleet_flying_sorter, $fleet_flying_events, $fleet_event_count);
426
      }
427
    }
428
    if($will_return) {
429
      tpl_topnav_event_build_helper($objFleet->time_return_to_source, EVENT_FLEET_RETURN, classLocale::$lang['sys_event_return'], $objFleet->launch_coordinates_typed(), true, $objFleet, $fleet_flying_sorter, $fleet_flying_events, $fleet_event_count);
430
    }
431
  }
432
433
  asort($fleet_flying_sorter);
434
435
  $fleet_flying_count = $FleetList->count();
436
  foreach($fleet_flying_sorter as $fleet_event_id => $fleet_time) {
437
    $fleet_event = &$fleet_flying_events[$fleet_event_id];
438
    $template->assign_block_vars("flying_{$type}s", array(
439
      'TIME' => max(0, $fleet_time - SN_TIME_NOW),
440
      'TEXT' => $fleet_flying_count,
441
      'HINT' => date(FMT_DATE_TIME, $fleet_time + SN_CLIENT_TIME_DIFF) . " - {$classLocale['sys_fleet']} {$fleet_event['TEXT']} {$fleet_event['COORDINATES']} {$classLocale['sys_planet_type_sh'][$fleet_event['COORDINATES_TYPE']]} {$classLocale['type_mission'][$fleet_event['OBJECT']->mission_type]}",
442
    ));
443
    $fleet_event['DECREASE'] ? $fleet_flying_count-- : false;
444
  }
445
}
446
447
/**
448
 * @param array $user
449
 * @param array $planetrow
450
 *
451
 * @return string|template
452
 */
453
function tpl_render_topnav(&$user, $planetrow) { return sn_function_call(__FUNCTION__, array(&$user, $planetrow)); }
454
455
/**
456
 * @param array $user
457
 * @param array $planetrow
458
 *
459
 * @return string|template
460
 */
461
function sn_tpl_render_topnav(&$user, $planetrow) {
462
  global $template_result;
463
  $classLocale = classLocale::$lang;
464
465
  if(!is_array($user)) {
466
    return '';
467
  }
468
469
  $GET_mode = sys_get_param_str('mode');
470
471
  $template = gettemplate('navbar', true);
472
473
  $template->assign_recursive($template_result);
474
475
  /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
476
  $planetrow = $planetrow ? $planetrow : $user['current_planet'];
477
478
  sn_db_transaction_start();
479
  $planetrow = sys_o_get_updated($user, $planetrow, SN_TIME_NOW);
480
  sn_db_transaction_commit();
481
  $planetrow = $planetrow['planet'];
482
  */
483
484
  $ThisUsersPlanets = db_planet_list_sorted($user);
485
  // while ($CurPlanet = db_fetch($ThisUsersPlanets))
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
486
  foreach($ThisUsersPlanets as $CurPlanet) {
487
    if($CurPlanet['destruyed']) {
488
      continue;
489
    }
490
491
//    $fleet_listx = flt_get_fleets_to_planet($CurPlanet);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
492
    $fleet_listx = FleetList::EMULATE_flt_get_fleets_to_planet($CurPlanet);
493
494
    $template->assign_block_vars('topnav_planets', array(
495
      'ID'          => $CurPlanet['id'],
496
      'NAME'        => $CurPlanet['name'],
497
      'TYPE'        => $CurPlanet['planet_type'],
498
      'TYPE_TEXT'   => classLocale::$lang['sys_planet_type_sh'][$CurPlanet['planet_type']],
499
      'PLIMAGE'     => $CurPlanet['image'],
500
      'FLEET_ENEMY' => $fleet_listx['enemy']['count'],
501
      'COORDS'      => uni_render_coordinates($CurPlanet),
502
      'SELECTED'    => $CurPlanet['id'] == $user['current_planet'] ? ' selected' : '',
503
    ));
504
  }
505
506
  /**
507
   * @var FleetList[] $fleet_flying_list
508
   */
509
  $fleet_flying_list = array();
510
  $fleet_flying_list[0] = FleetList::dbGetFleetListByOwnerId($user['id']);
511
  foreach($fleet_flying_list[0]->_container as $fleet_id => $objFleet) {
512
    if(empty($fleet_flying_list[$objFleet->mission_type])) {
513
      $fleet_flying_list[$objFleet->mission_type] = new FleetList();
514
    }
515
    $fleet_flying_list[$objFleet->mission_type][$fleet_id] = $objFleet;
516
  }
517
  tpl_topnav_event_build($template, $fleet_flying_list[0]);
518
  tpl_topnav_event_build($template, $fleet_flying_list[MT_EXPLORE], 'expedition');
519
520
  que_tpl_parse($template, QUE_STRUCTURES, $user, $planetrow, null, true);
521
  que_tpl_parse($template, QUE_RESEARCH, $user, array(), null, !classSupernova::$user_options[PLAYER_OPTION_NAVBAR_RESEARCH_WIDE]);
522
  que_tpl_parse($template, SUBQUE_FLEET, $user, $planetrow, null, true);
523
524
  if(!empty(classSupernova::$sn_mvc['navbar_prefix_button']) && is_array(classSupernova::$sn_mvc['navbar_prefix_button'])) {
525
    foreach(classSupernova::$sn_mvc['navbar_prefix_button'] as $navbar_button_image => $navbar_button_url) {
526
      $template->assign_block_vars('navbar_prefix_button', array(
527
        'IMAGE'        => $navbar_button_image,
528
        'URL_RELATIVE' => $navbar_button_url,
529
      ));
530
    }
531
  }
532
533
  $template->assign_var('NAVBAR_PREFIX_BUTTONS', is_array(classSupernova::$sn_mvc['navbar_prefix_button']) ? count(classSupernova::$sn_mvc['navbar_prefix_button']) : 0);
534
535
  $str_date_format = "%3$02d %2$0s %1$04d {$classLocale['top_of_year']} %4$02d:%5$02d:%6$02d";
536
  $time_now_parsed = getdate(SN_TIME_NOW);
537
  $time_local_parsed = getdate(defined('SN_CLIENT_TIME_LOCAL') ? SN_CLIENT_TIME_LOCAL : SN_TIME_NOW);
538
539
  if(classSupernova::$config->game_news_overview) {
540
    $user_last_read_safe = intval($user['news_lastread']);
541
    nws_render($template, "WHERE UNIX_TIMESTAMP(`tsTimeStamp`) >= {$user_last_read_safe}", classSupernova::$config->game_news_overview);
542
  }
543
544
  $notes_query = db_note_list_by_owner($user['id'], true);
545
  while($note_row = db_fetch($notes_query)) {
546
    note_assign($template, $note_row);
547
  }
548
549
  $premium_lvl = mrc_get_level($user, null, UNIT_PREMIUM, true, true);
550
  $darkMatter = mrc_get_level($user, null, RES_DARK_MATTER);
551
  $darkMatterPlain = mrc_get_level($user, null, RES_DARK_MATTER, false, true);
552
  $metaMatter = mrc_get_level($user, null, RES_METAMATTER);
553
  $template->assign_vars(array(
554
    'HALLOWEEN' => !empty(sn_module::$sn_module_list['event']['event_halloween_2015']) && sn_module::$sn_module_list['event']['event_halloween_2015']->manifest['active'],
555
556
    'QUE_ID'   => QUE_RESEARCH,
557
    'QUE_HTML' => 'topnav',
558
559
    'RESEARCH_ONGOING' => (boolean)$user['que'],
560
561
    'TIME_TEXT'       => sprintf($str_date_format, $time_now_parsed['year'], classLocale::$lang['months'][$time_now_parsed['mon']], $time_now_parsed['mday'],
562
      $time_now_parsed['hours'], $time_now_parsed['minutes'], $time_now_parsed['seconds']
563
    ),
564
    'TIME_TEXT_LOCAL' => sprintf($str_date_format, $time_local_parsed['year'], classLocale::$lang['months'][$time_local_parsed['mon']], $time_local_parsed['mday'],
565
      $time_local_parsed['hours'], $time_local_parsed['minutes'], $time_local_parsed['seconds']
566
    ),
567
568
    'GAME_BLITZ_REGISTER'             => classSupernova::$config->game_blitz_register,
569
    'GAME_BLITZ_REGISTER_TEXT'        => classLocale::$lang['sys_blitz_registration_mode_list'][classSupernova::$config->game_blitz_register],
570
    'BLITZ_REGISTER_OPEN'             => classSupernova::$config->game_blitz_register == BLITZ_REGISTER_OPEN,
571
    'BLITZ_REGISTER_CLOSED'           => classSupernova::$config->game_blitz_register == BLITZ_REGISTER_CLOSED,
572
    'BLITZ_REGISTER_SHOW_LOGIN'       => classSupernova::$config->game_blitz_register == BLITZ_REGISTER_SHOW_LOGIN,
573
    'BLITZ_REGISTER_DISCLOSURE_NAMES' => classSupernova::$config->game_blitz_register == BLITZ_REGISTER_DISCLOSURE_NAMES,
574
    'GAME_BLITZ'                      => classSupernova::$config->game_mode == GAME_BLITZ,
575
576
    'USERS_ONLINE'  => classSupernova::$config->var_online_user_count,
0 ignored issues
show
Documentation introduced by
The property var_online_user_count does not exist on object<classConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
577
    'USERS_TOTAL'   => classSupernova::$config->users_amount,
578
    'USER_RANK'     => $user['total_rank'],
579
    'USER_NICK'     => $user['username'],
580
    'USER_AVATAR'   => $user['avatar'],
581
    'USER_AVATARID' => $user['id'],
582
    'USER_PREMIUM'  => $premium_lvl,
583
    'USER_RACE'     => $user['player_race'],
584
585
    'TOPNAV_CURRENT_PLANET'       => $user['current_planet'],
586
    'TOPNAV_CURRENT_PLANET_NAME'  => uni_render_planet_full($planetrow), // htmlspecialchars($planetrow['name']),
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
587
    'TOPNAV_CURRENT_PLANET_IMAGE' => $planetrow['image'],
588
    'TOPNAV_COLONIES_CURRENT'     => get_player_current_colonies($user),
589
    'TOPNAV_COLONIES_MAX'         => get_player_max_colonies($user),
590
    'TOPNAV_MODE'                 => $GET_mode,
591
592
    'TOPNAV_DARK_MATTER'            => $darkMatter,
593
    'TOPNAV_DARK_MATTER_TEXT'       => pretty_number($darkMatter),
594
    'TOPNAV_DARK_MATTER_PLAIN'      => $darkMatterPlain,
595
    'TOPNAV_DARK_MATTER_PLAIN_TEXT' => pretty_number($darkMatterPlain),
596
    'TOPNAV_METAMATTER'             => $metaMatter,
597
    'TOPNAV_METAMATTER_TEXT'        => pretty_number($metaMatter),
598
599
    // TODO ГРЯЗНЫЙ ХАК!!!
600
    'TOPNAV_PAYMENT'                => sn_module_get_active_count('payment') && !defined('SN_GOOGLE'),
601
602
    'TOPNAV_MESSAGES_ADMIN'    => $user['msg_admin'],
603
    'TOPNAV_MESSAGES_PLAYER'   => $user['mnl_joueur'],
604
    'TOPNAV_MESSAGES_ALLIANCE' => $user['mnl_alliance'],
605
    'TOPNAV_MESSAGES_ATTACK'   => $user['mnl_attaque'],
606
    'TOPNAV_MESSAGES_ALL'      => $user['new_message'],
607
608
    'TOPNAV_FLEETS_FLYING'      => is_object($fleet_flying_list[0]) ? $fleet_flying_list[0]->count() : 0,
609
    'TOPNAV_FLEETS_TOTAL'       => GetMaxFleets($user),
610
    'TOPNAV_EXPEDITIONS_FLYING' => is_object($fleet_flying_list[MT_EXPLORE]) ? $fleet_flying_list[MT_EXPLORE]->count() : 0,
611
    'TOPNAV_EXPEDITIONS_TOTAL'  => get_player_max_expeditons($user),
612
613
    'TOPNAV_QUEST_COMPLETE' => get_quest_amount_complete($user['id']),
614
615
    'GAME_NEWS_OVERVIEW'       => classSupernova::$config->game_news_overview,
616
    'GAME_RESEARCH_DISABLED'   => defined('GAME_RESEARCH_DISABLED') && GAME_RESEARCH_DISABLED,
617
    'GAME_DEFENSE_DISABLED'    => defined('GAME_DEFENSE_DISABLED') && GAME_DEFENSE_DISABLED,
618
    'GAME_STRUCTURES_DISABLED' => defined('GAME_STRUCTURES_DISABLED') && GAME_STRUCTURES_DISABLED,
619
    'GAME_HANGAR_DISABLED'     => defined('GAME_HANGAR_DISABLED') && GAME_HANGAR_DISABLED,
620
621
    'PLAYER_OPTION_NAVBAR_PLANET_VERTICAL'       => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_PLANET_VERTICAL],
622
    'PLAYER_OPTION_NAVBAR_DISABLE_RESEARCH'      => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_RESEARCH],
623
    'PLAYER_OPTION_NAVBAR_DISABLE_PLANET'        => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_PLANET],
624
    'PLAYER_OPTION_NAVBAR_DISABLE_HANGAR'        => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_HANGAR],
625
    'PLAYER_OPTION_NAVBAR_DISABLE_FLYING_FLEETS' => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_FLYING_FLEETS],
626
    'PLAYER_OPTION_NAVBAR_DISABLE_EXPEDITIONS'   => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_EXPEDITIONS],
627
    'PLAYER_OPTION_NAVBAR_DISABLE_QUESTS'        => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_QUESTS],
628
    'PLAYER_OPTION_NAVBAR_DISABLE_META_MATTER'   => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_META_MATTER],
629
    'PLAYER_OPTION_NAVBAR_RESEARCH_WIDE'         => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_RESEARCH_WIDE],
630
631
    'SUBQUE_FLEET'   => SUBQUE_FLEET,
632
    'QUE_RESEARCH'   => QUE_RESEARCH,
633
    'QUE_STRUCTURES' => QUE_STRUCTURES,
634
  ));
635
636
  if((defined('SN_RENDER_NAVBAR_PLANET') && SN_RENDER_NAVBAR_PLANET === true) || ($user['option_list'][OPT_INTERFACE]['opt_int_navbar_resource_force'] && SN_RENDER_NAVBAR_PLANET !== false)) {
637
    tpl_set_resource_info($template, $planetrow);
638
    $template->assign_vars(array(
639
      'SN_RENDER_NAVBAR_PLANET' => true,
640
      'SN_NAVBAR_HIDE_FLEETS'   => true,
641
    ));
642
  }
643
644
  return $template;
645
}
646
647
/**
648
 * @param template|string $template
649
 */
650
function displayP($template) {
651
  if(is_object($template)) {
652
    if(empty($template->parsed)) {
653
      parsetemplate($template);
654
    }
655
656
    foreach($template->files as $section => $filename) {
657
      $template->display($section);
658
    }
659
  } else {
660
    print($template);
661
  }
662
}
663
664
/**
665
 * @param template|string $template
666
 * @param array|bool      $array
667
 *
668
 * @return mixed
669
 */
670
function parsetemplate($template, $array = false) {
671
  if(is_object($template)) {
672
    global $user;
673
674
    if(!empty($array) && is_array($array)) {
675
      foreach($array as $key => $data) {
676
        $template->assign_var($key, $data);
677
      }
678
    }
679
680
    $template->assign_vars(array(
681
      'dpath'          => $user['dpath'] ? $user['dpath'] : DEFAULT_SKINPATH,
682
      'SN_TIME_NOW'    => SN_TIME_NOW,
683
      'USER_AUTHLEVEL' => isset($user['authlevel']) ? $user['authlevel'] : -1,
684
      'SN_GOOGLE'      => defined('SN_GOOGLE'),
685
    ));
686
687
    $template->parsed = true;
688
689
    return $template;
690
  } else {
691
    $search[] = '#\{L_([a-z0-9\-_]*?)\[([a-z0-9\-_]*?)\]\}#Ssie';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$search was never initialized. Although not strictly required by PHP, it is generally a good practice to add $search = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
692
    $replace[] = '((isset(classLocale::$lang[\'\1\'][\'\2\'])) ? classLocale::$lang[\'\1\'][\'\2\'] : \'{L_\1[\2]}\');';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$replace was never initialized. Although not strictly required by PHP, it is generally a good practice to add $replace = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
693
694
    $search[] = '#\{L_([a-z0-9\-_]*?)\}#Ssie';
695
    $replace[] = '((isset(classLocale::$lang[\'\1\'])) ? classLocale::$lang[\'\1\'] : \'{L_\1}\');';
696
697
    $search[] = '#\{([a-z0-9\-_]*?)\}#Ssie';
698
    $replace[] = '((isset($array[\'\1\'])) ? $array[\'\1\'] : \'{\1}\');';
699
700
    return preg_replace($search, $replace, $template);
701
  }
702
}
703
704
/**
705
 * @param array|string  $files
706
 * @param template|bool $template
707
 * @param string|bool   $template_path
708
 *
709
 * @return template
710
 */
711
function gettemplate($files, $template = false, $template_path = false) {
712
  global $sn_page_name, $user;
713
714
  $template_ex = '.tpl.html';
715
716
  if($template === false) {
717
    return sys_file_read(TEMPLATE_DIR . '/' . $files . $template_ex);
718
  }
719
720
  is_string($files) ? $files = array(basename($files) => $files) : false;
721
722
  !is_object($template) ? $template = new template() : false;
723
  //$template->set_custom_template($template_path ? $template_path : TEMPLATE_DIR, TEMPLATE_NAME, TEMPLATE_DIR);
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
724
725
  $tmpl_name = gettemplatename($user['dpath']);
726
  $template->set_custom_template(($template_path ? $template_path : SN_ROOT_PHYSICAL . 'design/templates/') . $tmpl_name . '/', $tmpl_name, TEMPLATE_DIR);
0 ignored issues
show
Documentation introduced by
TEMPLATE_DIR is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
727
728
  // TODO ГРЯЗНЫЙ ХАК! Это нужно, что бы по возможности перезаписать инфу из языковых пакетов модулей там, где она была перезаписана раньше инфой из основного пакета. Почему?
729
  //  - сначала грузятся модули и их языковые пакеты
730
  //  - затем по ходу дела ОСНОВНОЙ языковой пакет может перезаписать данные из МОДУЛЬНОГО языкового пакета
731
  // Поэтому и нужен этот грязный хак
732
  // В норме же - страницы заявляют сами, какие им пакеты нужны. Так что сначала всегда должны грузится основные языковые пакеты, а уже ПОВЕРХ них - пакеты модулей
733
  !empty(classSupernova::$sn_mvc['i18n']['']) ? lng_load_i18n(classSupernova::$sn_mvc['i18n']['']) : false;
734
  $sn_page_name ? lng_load_i18n(classSupernova::$sn_mvc['i18n'][$sn_page_name]) : false;
735
736
  foreach($files as &$filename) {
737
    $filename = $filename . $template_ex;
738
  }
739
740
  $template->set_filenames($files);
741
742
  return $template;
743
}
744
745
/**
746
 * @param template $template
747
 */
748
function tpl_login_lang(&$template) {
749
  global $language;
750
751
  $url_params = array();
752
753
  $language ? $url_params[] = "lang={$language}" : false;
754
755
  ($id_ref = sys_get_param_id('id_ref')) ? $url_params[] = "id_ref={$id_ref}" : false;
756
757
  $template->assign_vars($q = array(
758
    'LANG'     => $language ? $language : '',
759
    'referral' => $id_ref ? '&id_ref=' . $id_ref : '',
760
761
    'REQUEST_PARAMS' => !empty($url_params) ? '?' . implode('&', $url_params) : '',// "?lang={$language}" . ($id_ref ? "&id_ref={$id_ref}" : ''),
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
762
    'FILENAME'       => basename($_SERVER['PHP_SELF']),
763
  ));
764
765
  foreach(lng_get_list() as $lng_id => $lng_data) {
766
    if(isset($lng_data['LANG_VARIANTS']) && is_array($lng_data['LANG_VARIANTS'])) {
767
      foreach($lng_data['LANG_VARIANTS'] as $lang_variant) {
768
        $lng_data1 = $lng_data;
769
        $lng_data1 = array_merge($lng_data1, $lang_variant);
770
        $template->assign_block_vars('language', $lng_data1);
771
      }
772
    } else {
773
      $template->assign_block_vars('language', $lng_data);
774
    }
775
  }
776
}
777
778
/**
779
 * @param template $template
780
 * @param array    $planet
781
 * @param int      $que_type
782
 *
783
 * @return int
784
 */
785
function tpl_assign_hangar(&$template, $planet, $que_type) {
786
  $que = que_get($planet['id_owner'], $planet['id'], $que_type);
0 ignored issues
show
Documentation introduced by
$que_type is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
787
  $que = $que['ques'][$que_type][$planet['id_owner']][$planet['id']];
788
789
  $que_length = 0;
790
  if(!empty($que)) {
791
    foreach($que as $que_item) {
792
      $template->assign_block_vars('que', que_tpl_parse_element($que_item));
793
    }
794
    $que_length = count($que);
795
  }
796
797
  return $que_length;
798
}
799
800
/**
801
 * @param template $template
802
 * @param array    $density_price_chart
803
 * @param int      $user_dark_matter
804
 */
805
function tpl_planet_density_info(&$template, &$density_price_chart, $user_dark_matter) {
806
  foreach($density_price_chart as $density_price_index => &$density_price_data) {
807
    $density_cost = $density_price_data;
808
    $density_number_style = pretty_number($density_cost, true, $user_dark_matter, false, false);
809
810
    $density_price_data = array(
811
      'COST'            => $density_cost,
812
      'COST_TEXT'       => $density_number_style['text'],
813
      'COST_TEXT_CLASS' => $density_number_style['class'],
814
      'REST'            => $user_dark_matter - $density_cost,
815
      'ID'              => $density_price_index,
816
      'TEXT'            => classLocale::$lang['uni_planet_density_types'][$density_price_index],
817
    );
818
    $template->assign_block_vars('densities', $density_price_data);
819
  }
820
}
821
822
/**
823
 * @param template $template
824
 * @param string   $name
825
 * @param mixed    $values
826
 */
827
function tpl_assign_select(&$template, $name, $values) {
828
  !is_array($values) ? $values = array($values => $values) : false;
829
830
  foreach($values as $key => $value) {
831
    $template->assign_block_vars($name, array(
832
      'KEY'   => htmlentities($key, ENT_COMPAT, 'UTF-8'),
833
      'VALUE' => htmlentities($value, ENT_COMPAT, 'UTF-8'),
834
    ));
835
  }
836
}
837