Completed
Push — work-fleets ( 0fb536...3e8bfe )
by SuperNova.WS
06:08
created

template.php ➔ calculateFontSize()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 14
Code Lines 9

Duplication

Lines 10
Ratio 71.43 %

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 6
nop 0
dl 10
loc 14
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
// Wrappers for functions
4
use DBStatic\DBStaticNote;
5
use DBStatic\DBStaticPlanet;
6
7
/**
8
 * @param $u_dpath
9
 *
10
 * @return mixed
11
 */
12
function gettemplatename($u_dpath) {
13
  static $template_names = array();
14
15
  if(!isset($template_names[$u_dpath])) {
16
    $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;
17
  }
18
19
  return $template_names[$u_dpath];
20
}
21
22
/**
23
 * @param        $mes
24
 * @param string $title
25
 * @param string $dest
26
 * @param int    $time
27
 */
28
function AdminMessage($mes, $title = 'Error', $dest = '', $time = 3) {
29
  $page = parsetemplate(gettemplate('admin/message_body'), array('title' => $title, 'mes' => $mes,));
30
31
  display($page, $title, false, ($dest ? "<meta http-equiv=\"refresh\" content=\"{$time};URL=javascript:self.location='{$dest}';\">" : ''), true);
32
}
33
34
/**
35
 * @param           $mes
36
 * @param string    $title
37
 * @param string    $dest
38
 * @param int       $time
39
 * @param bool|true $show_header
40
 */
41
function message($mes, $title = 'Error', $dest = '', $time = 5, $show_header = true) {
42
  $template = gettemplate('message_body', true);
43
  $template->assign_vars(array(
44
    'title' => $title,
45
    'mes'   => $mes,
46
    'DEST'  => $dest,
47
  ));
48
49
  display($template, $title, $show_header, (($dest != '') ? "<meta http-equiv=\"refresh\" content=\"{$time};url={$dest}\">" : ""), false);
50
}
51
52
/**
53
 * @param $sn_menu
54
 * @param $sn_menu_extra
55
 */
56
function tpl_menu_merge_extra(&$sn_menu, &$sn_menu_extra) {
57
  if(empty($sn_menu) || empty($sn_menu_extra)) {
58
    return;
59
  }
60
61
  foreach($sn_menu_extra as $menu_item_id => $menu_item) {
62
    if(empty($menu_item['LOCATION'])) {
63
      $sn_menu[$menu_item_id] = $menu_item;
64
      continue;
65
    }
66
67
    $item_location = $menu_item['LOCATION'];
68
    unset($menu_item['LOCATION']);
69
70
    $is_positioned = $item_location[0];
71
    if($is_positioned == '+' || $is_positioned == '-') {
72
      $item_location = substr($item_location, 1);
73
    } else {
74
      $is_positioned = '';
75
    }
76
77
    if($item_location) {
78
      $menu_keys = array_keys($sn_menu);
79
      $insert_position = array_search($item_location, $menu_keys);
80
      if($insert_position === false) {
81
        $insert_position = count($sn_menu) - 1;
82
        $is_positioned = '+';
83
        $item_location = '';
84
      }
85
    } else {
86
      $insert_position = $is_positioned == '-' ? 0 : count($sn_menu);
87
    }
88
89
    $insert_position += $is_positioned == '+' ? 1 : 0;
90
    $spliced = array_splice($sn_menu, $insert_position, count($sn_menu) - $insert_position);
91
    $sn_menu[$menu_item_id] = $menu_item;
92
93
    if(!$is_positioned && $item_location) {
94
      unset($spliced[$item_location]);
95
    }
96
    $sn_menu = array_merge($sn_menu, $spliced);
97
  }
98
99
  $sn_menu_extra = array();
100
}
101
102
/**
103
 * @param array    $sn_menu
104
 * @param template $template
105
 */
106
function tpl_menu_assign_to_template(&$sn_menu, &$template) {
107
  if(empty($sn_menu) || !is_array($sn_menu)) {
108
    return;
109
  }
110
111
  foreach($sn_menu as $menu_item_id => $menu_item) {
112
    if(!$menu_item) {
113
      continue;
114
    }
115
116
    if(is_string($menu_item_id)) {
117
      $menu_item['ID'] = $menu_item_id;
118
    }
119
120
    if($menu_item['TYPE'] == 'lang') {
121
      $lang_string = &classLocale::$lang;
122
      if(preg_match('#(\w+)(?:\[(\w+)\])?(?:\[(\w+)\])?(?:\[(\w+)\])?(?:\[(\w+)\])?#', $menu_item['ITEM'], $matches) && count($matches) > 1) {
123
        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...
124
          if(defined($matches[$i])) {
125
            $matches[$i] = constant($matches[$i]);
126
          }
127
          $lang_string = &$lang_string[$matches[$i]];
128
        }
129
      }
130
      $menu_item['ITEM'] = $lang_string && is_string($lang_string) ? $lang_string : "{L_{$menu_item['ITEM']}}";
131
    }
132
133
    $menu_item['ALT'] = htmlentities($menu_item['ALT']);
134
    $menu_item['TITLE'] = htmlentities($menu_item['TITLE']);
135
136
    if(!empty($menu_item['ICON'])) {
137
      if(is_string($menu_item['ICON'])) {
138
        $menu_item['ICON_PATH'] = $menu_item['ICON'];
139
      } else {
140
        $menu_item['ICON'] = $menu_item_id;
141
      }
142
    }
143
144
    $template->assign_block_vars('menu', $menu_item);
145
  }
146
}
147
148
/**
149
 * @return template
150
 */
151
function tpl_render_menu() {
152
  global $user, $template_result, $sn_menu_admin_extra, $sn_menu_admin, $sn_menu, $sn_menu_extra;
153
154
  lng_include('admin');
155
156
  $template = gettemplate('menu', true);
157
  $template->assign_recursive($template_result);
158
159
  $template->assign_vars(array(
160
    'USER_AUTHLEVEL'      => $user['authlevel'],
161
    'USER_AUTHLEVEL_NAME' => classLocale::$lang['user_level'][$user['authlevel']],
162
//    '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...
163
    'PAYMENT'             => sn_module_get_active_count('payment'),
164
    'MENU_START_HIDE'     => !empty($_COOKIE[SN_COOKIE . '_menu_hidden']) || defined('SN_GOOGLE'),
165
  ));
166
167
  if(isset($template_result['MENU_CUSTOMIZE'])) {
168
    $template->assign_vars(array(
169
      'PLAYER_OPTION_MENU_SHOW_ON_BUTTON'   => classSupernova::$user_options[PLAYER_OPTION_MENU_SHOW_ON_BUTTON],
170
      'PLAYER_OPTION_MENU_HIDE_ON_BUTTON'   => classSupernova::$user_options[PLAYER_OPTION_MENU_HIDE_ON_BUTTON],
171
      'PLAYER_OPTION_MENU_HIDE_ON_LEAVE'    => classSupernova::$user_options[PLAYER_OPTION_MENU_HIDE_ON_LEAVE],
172
      'PLAYER_OPTION_MENU_UNPIN_ABSOLUTE'   => classSupernova::$user_options[PLAYER_OPTION_MENU_UNPIN_ABSOLUTE],
173
      'PLAYER_OPTION_MENU_ITEMS_AS_BUTTONS' => classSupernova::$user_options[PLAYER_OPTION_MENU_ITEMS_AS_BUTTONS],
174
      'PLAYER_OPTION_MENU_WHITE_TEXT'       => classSupernova::$user_options[PLAYER_OPTION_MENU_WHITE_TEXT],
175
      'PLAYER_OPTION_MENU_OLD'              => classSupernova::$user_options[PLAYER_OPTION_MENU_OLD],
176
      'PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON' => empty($_COOKIE[SN_COOKIE . '_menu_hidden']) && !defined('SN_GOOGLE')
177
        ? classSupernova::$user_options[PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON] : 1,
178
    ));
179
  }
180
181
  if(defined('IN_ADMIN') && IN_ADMIN === true && !empty($user['authlevel']) && $user['authlevel'] > 0) {
182
    tpl_menu_merge_extra($sn_menu_admin, $sn_menu_admin_extra);
183
    tpl_menu_assign_to_template($sn_menu_admin, $template);
184
  } else {
185
    tpl_menu_merge_extra($sn_menu, $sn_menu_extra);
186
    tpl_menu_assign_to_template($sn_menu, $template);
187
  }
188
189
  return $template;
190
}
191
192
/**
193
 * @param template|string $page
194
 * @param string          $title
195
 * @param bool|true       $isDisplayTopNav
196
 * @param string          $metatags
197
 * @param bool|false      $AdminPage
198
 * @param bool|true       $isDisplayMenu
199
 *
200
 * @return mixed
201
 */
202
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...
203
  return sn_function_call(__FUNCTION__, array($page, $title, $isDisplayTopNav, $metatags, $isDisplayMenu, $exitStatus));
204
}
205
206
/**
207
 * @param template|string $page
208
 * @param string          $title
209
 * @param bool|true       $isDisplayTopNav
210
 * @param string          $metatags
211
 * @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...
212
 * @param bool|true       $isDisplayMenu
213
 * @param bool|int|string $exitStatus - Код или сообщение выхода
214
 */
215
function sn_display($page, $title = '', $isDisplayTopNav = true, $metatags = '', $isDisplayMenu = true, $exitStatus = true) {
216
  global $user, $planetrow, $template_result, $sn_page_name;
217
218
  $in_admin = defined('IN_ADMIN') && IN_ADMIN === true;
219
  $is_login = defined('LOGIN_LOGOUT') && LOGIN_LOGOUT === true;
220
221
  if(is_object($page)) {
222
    isset($page->_rootref['MENU']) ? $isDisplayMenu = $page->_rootref['MENU'] : false;
223
    isset($page->_rootref['NAVBAR']) ? $isDisplayTopNav = $page->_rootref['NAVBAR'] : false;
224
225
    !$title && !empty($page->_rootref['PAGE_HEADER']) ? $title = $page->_rootref['PAGE_HEADER'] : false;
226
    !isset($page->_rootref['PAGE_HEADER']) && $title ? $page->assign_var('PAGE_HEADER', $title) : false;
227
  }
228
229
  if(empty($user['id']) || !is_numeric($user['id'])) {
230
    $isDisplayMenu = false;
231
    $isDisplayTopNav = false;
232
  }
233
234
  !empty(classSupernova::$sn_mvc['view']['']) ? execute_hooks(classSupernova::$sn_mvc['view'][''], $page, 'view', '') : false;
235
236
  // Global header
237
  $user_time_diff = playerTimeDiff::user_time_diff_get();
238
  $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);
239
240
  $font_size = calculateFontSize();
241
242
  $template_result['LOGIN_LOGOUT'] = $is_login;
243
244
  $template = gettemplate('_global_header', true);
245
246
  $jsStandard = array(
247
    'js/lib/jquery' => '',
248
    'js/lib/jquery-ui'  => '',
249
    'js/lib/ion.sound' => '',
250
    'js/sn_global' => '',
251
    'js/sn_sound' => '',
252
    'js/sn_timer' => '',
253
  );
254
  // Prepending standard JS files
255
  classSupernova::$js[''] = array_merge($jsStandard, classSupernova::$js['']);
256
  renderFileList(classSupernova::$js, 'js', $sn_page_name, $template_result);
257
258
259
  classSupernova::$css[''] = array_merge(
260
    array(
261
      'design/css/jquery-ui' => '',
262
      'design/css/global'    => '',
263
    ),
264
    $is_login ? array('design/css/login' => '') : array(),
265
    array(
266
      TEMPLATE_PATH . '/_template'                                  => '',
267
      ($user['dpath'] ? $user['dpath'] : DEFAULT_SKINPATH) . 'skin' => '',
268
      // 'design/css/global-ie' => '', // 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...
269
    ),
270
    classSupernova::$css[''],
271
    array(
272
      'design/css/global_override' => ''
273
    )
274
  );
275
  // Prepending standard CSS files
276
  renderFileList(classSupernova::$css, 'css', $sn_page_name, $template_result);
277
278
  $classConfig = classSupernova::$config;
279
  $template->assign_vars(array(
280
    'USER_AUTHLEVEL' => intval($user['authlevel']),
281
282
    'FONT_SIZE'                        => $font_size,
283
    'FONT_SIZE_PERCENT_DEFAULT_STRING' => FONT_SIZE_PERCENT_DEFAULT_STRING,
284
285
    'SN_TIME_NOW'          => SN_TIME_NOW,
286
    'LOGIN_LOGOUT'         => $is_login,
287
    'GAME_MODE_CSS_PREFIX' => classSupernova::$config->game_mode == GAME_BLITZ ? 'blitz_' : '',
288
    //'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...
289
    'TIME_DIFF_MEASURE'    => intval(
290
      empty($user_time_diff[PLAYER_OPTION_TIME_DIFF_FORCED])
291
      &&
292
      (SN_TIME_NOW - $user_time_measured_unix > PERIOD_HOUR || $user_time_diff[PLAYER_OPTION_TIME_DIFF] == '')
293
    ), // Проводить замер только если не выставлен флаг форсированного замера И (иссяк интервал замера ИЛИ замера еще не было)
294
    //'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...
295
296
    'title'                    => ($title ? "{$title} - " : '') . classLocale::$lang['sys_server'] . " {$classConfig->game_name} - " . classLocale::$lang['sys_supernova'],
297
    '-meta-'                   => $metatags,
298
    'ADV_SEO_META_DESCRIPTION' => classSupernova::$config->adv_seo_meta_description,
299
    'ADV_SEO_META_KEYWORDS'    => classSupernova::$config->adv_seo_meta_keywords,
300
    'ADV_SEO_JAVASCRIPT'       => classSupernova::$config->adv_seo_javascript,
301
302
    'LANG_LANGUAGE'  => classLocale::$lang['LANG_INFO']['LANG_NAME_ISO2'],
303
    'LANG_ENCODING'  => 'utf-8',
304
    'LANG_DIRECTION' => classLocale::$lang['LANG_INFO']['LANG_DIRECTION'],
305
306
    'SOUND_ENABLED'                        => classSupernova::$user_options[PLAYER_OPTION_SOUND_ENABLED],
307
    'PLAYER_OPTION_ANIMATION_DISABLED'     => classSupernova::$user_options[PLAYER_OPTION_ANIMATION_DISABLED],
308
    'PLAYER_OPTION_PROGRESS_BARS_DISABLED' => classSupernova::$user_options[PLAYER_OPTION_PROGRESS_BARS_DISABLED],
309
310
    'IMPERSONATING'                        => !empty($template_result[F_IMPERSONATE_STATUS]) ? sprintf(classLocale::$lang['sys_impersonated_as'], $user['username'], $template_result[F_IMPERSONATE_OPERATOR]) : '',
311
    'PLAYER_OPTION_DESIGN_DISABLE_BORDERS' => classSupernova::$user_options[PLAYER_OPTION_DESIGN_DISABLE_BORDERS],
312
  ));
313
  $template->assign_recursive($template_result);
314
  displayP(parsetemplate($template));
315
316
  if(($isDisplayMenu || $in_admin) && !isset($_COOKIE['menu_disable'])) {
317
    // $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...
318
    displayP(parsetemplate(tpl_render_menu()));
319
  }
320
321
  if($isDisplayTopNav && !$in_admin) {
322
    displayP(parsetemplate(tpl_render_topnav($user, $planetrow)));
323
  }
324
325
  displayP(parsetemplate(gettemplate('_content_header', true)));
326
327
  !is_array($page) ? $page = array($page) : false;
328
  $result_added = false;
329
  foreach($page as $page_item) {
330
    if(!$result_added && is_object($page_item) && isset($page_item->_tpldata['result'])) {
331
      $page_item = gettemplate('_result_message', $page_item);
332
      $temp = $page_item->files['_result_message'];
333
      unset($page_item->files['_result_message']);
334
      $page_item->files = array_reverse($page_item->files);
335
      $page_item->files['_result_message'] = $temp;
336
      $page_item->files = array_reverse($page_item->files);
337
      $result_added = true;
338
    }
339
    displayP($page_item);
340
  }
341
342
  displayP(parsetemplate(gettemplate('_content_footer', true)));
343
344
  // Global footer
345
  $template = gettemplate('_global_footer', true);
346
  $template->assign_vars(array(
347
    'ADMIN_EMAIL' => classSupernova::$config->game_adminEmail,
348
    'SN_TIME_NOW' => SN_TIME_NOW,
349
    'SN_VERSION'  => SN_VERSION,
350
  ));
351
  displayP(parsetemplate($template));
352
353
  $user['authlevel'] >= 3 && classSupernova::$config->debug ? classSupernova::$debug->echo_log() : false;;
354
355
  classSupernova::$db->db_disconnect();
356
357
  $exitStatus and die($exitStatus === true ? 0 : $exitStatus);
358
}
359
360
/**
361
 * @param $fileList
362
 * @param $extension
363
 * @param $sn_page_name
364
 * @param $template_result
365
 *
366
 * @internal param $filename
367
 * @internal param $content
368
 */
369
function renderFileList(&$fileList, $extension, $sn_page_name, &$template_result) {
370
  if (empty($fileList)) {
371
    return;
372
  }
373
  foreach ($fileList as $page_name => $script_list) {
374
    if (empty($page_name) || $page_name == $sn_page_name) {
375
      foreach ($script_list as $filename => $content) {
376
        if (empty($content) && !($filename = getMinifiedName($filename, '.' . $extension))) {
377
          continue;
378
        }
379
380
        $template_result['.'][$extension][] = array(
381
          'FILE'    => $filename,
382
          'CONTENT' => $content,
383
        );
384
      }
385
    }
386
  }
387
}
388
389
/**
390
 * @return mixed|string
391
 */
392
function calculateFontSize() {
393
  $font_size = !empty($_COOKIE[SN_COOKIE_F]) ? $_COOKIE[SN_COOKIE_F] : classSupernova::$user_options[PLAYER_OPTION_BASE_FONT_SIZE];
394 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...
395
    // Размер шрифта в процентах
396
    $font_size = min(max(floatval($font_size), FONT_SIZE_PERCENT_MIN), FONT_SIZE_PERCENT_MAX) . '%';
397
  } elseif (strpos($font_size, 'px') !== false) {
398
    // Размер шрифта в пикселях
399
    $font_size = min(max(floatval($font_size), FONT_SIZE_PIXELS_MIN), FONT_SIZE_PIXELS_MAX) . 'px';
400
  } else {
401
    // Не мышонка, не лягушка...
402
    $font_size = FONT_SIZE_PERCENT_DEFAULT_STRING;
403
  }
404
  return $font_size;
405
}
406
407
/**
408
 * @param       $time
409
 * @param       $event
410
 * @param       $msg
411
 * @param       $coordinates
412
 * @param       $is_decrease
413
 * @param Fleet $objFleet
414
 * @param       $fleet_flying_sorter
415
 * @param       $fleet_flying_events
416
 * @param       $fleet_event_count
417
 */
418
function tpl_topnav_event_build_helper($time, $event, $msg, $coordinates, $is_decrease, Fleet $objFleet, &$fleet_flying_sorter, &$fleet_flying_events, &$fleet_event_count) {
419
  $fleet_flying_sorter[$fleet_event_count] = $time;
420
  $fleet_flying_events[$fleet_event_count] = array(
421
    'OBJECT'           => $objFleet,
422
    'FLEET_ID'         => $objFleet->dbId,
423
    'EVENT'            => $event,
424
    'COORDINATES'      => uni_render_coordinates($coordinates, ''),
425
    'COORDINATES_TYPE' => $coordinates['type'],
426
    'TEXT'             => $msg,
427
    'DECREASE'         => $is_decrease,
428
  );
429
  $fleet_event_count++;
430
}
431
432
/**
433
 * @param template       $template
434
 * @param FleetList|null $FleetList
435
 * @param string         $type
436
 */
437
function tpl_topnav_event_build(&$template, $FleetList, $type = 'fleet') {
438
  if(empty($FleetList)) {
439
    return;
440
  }
441
442
  $classLocale = classLocale::$lang;
443
444
  $fleet_event_count = 0;
445
  $fleet_flying_sorter = array();
446
  $fleet_flying_events = array();
447
  foreach($FleetList->_container as $objFleet) {
448
    $will_return = true;
449
    if(!$objFleet->isReturning()) {
450
      // cut fleets on Hold and Expedition
451
      if($objFleet->time_arrive_to_target >= SN_TIME_NOW) {
452
        $objFleet->mission_type == MT_RELOCATE ? $will_return = false : false;
453
        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);
454
      }
455
      if($objFleet->time_mission_job_complete) {
456
        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);
457
      }
458
    }
459
    if($will_return) {
460
      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);
461
    }
462
  }
463
464
  asort($fleet_flying_sorter);
465
466
  $fleet_flying_count = $FleetList->count();
467
  foreach($fleet_flying_sorter as $fleet_event_id => $fleet_time) {
468
    $fleet_event = &$fleet_flying_events[$fleet_event_id];
469
    $template->assign_block_vars("flying_{$type}s", array(
470
      'TIME' => max(0, $fleet_time - SN_TIME_NOW),
471
      'TEXT' => $fleet_flying_count,
472
      '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]}",
473
    ));
474
    $fleet_event['DECREASE'] ? $fleet_flying_count-- : false;
475
  }
476
}
477
478
/**
479
 * @param array $user
480
 * @param array $planetrow
481
 *
482
 * @return string|template
483
 */
484
function tpl_render_topnav(&$user, $planetrow) { return sn_function_call(__FUNCTION__, array(&$user, $planetrow)); }
485
486
/**
487
 * @param array $user
488
 * @param array $planetrow
489
 *
490
 * @return string|template
491
 */
492
function sn_tpl_render_topnav(&$user, $planetrow) {
493
  global $template_result;
494
  $classLocale = classLocale::$lang;
495
496
  if(!is_array($user)) {
497
    return '';
498
  }
499
500
  $GET_mode = sys_get_param_str('mode');
501
502
  $template = gettemplate('navbar', true);
503
504
  $template->assign_recursive($template_result);
505
506
  /*
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...
507
  $planetrow = $planetrow ? $planetrow : $user['current_planet'];
508
509
  sn_db_transaction_start();
510
  $planetrow = sys_o_get_updated($user, $planetrow, SN_TIME_NOW);
511
  sn_db_transaction_commit();
512
  $planetrow = $planetrow['planet'];
513
  */
514
515
  $ThisUsersPlanets = DBStaticPlanet::db_planet_list_sorted($user);
516
  // 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...
517
  foreach($ThisUsersPlanets as $CurPlanet) {
518
    if($CurPlanet['destruyed']) {
519
      continue;
520
    }
521
522
//    $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...
523
    $fleet_listx = FleetList::EMULATE_flt_get_fleets_to_planet($CurPlanet);
524
525
    $template->assign_block_vars('topnav_planets', array(
526
      'ID'          => $CurPlanet['id'],
527
      'NAME'        => $CurPlanet['name'],
528
      'TYPE'        => $CurPlanet['planet_type'],
529
      'TYPE_TEXT'   => classLocale::$lang['sys_planet_type_sh'][$CurPlanet['planet_type']],
530
      'PLIMAGE'     => $CurPlanet['image'],
531
      'FLEET_ENEMY' => $fleet_listx['enemy']['count'],
532
      'COORDS'      => uni_render_coordinates($CurPlanet),
533
      'SELECTED'    => $CurPlanet['id'] == $user['current_planet'] ? ' selected' : '',
534
    ));
535
  }
536
537
  /**
538
   * @var FleetList[] $fleet_flying_list
539
   */
540
  $fleet_flying_list = array();
541
  $fleet_flying_list[0] = FleetList::dbGetFleetListByOwnerId($user['id']);
542
  foreach($fleet_flying_list[0]->_container as $fleet_id => $objFleet) {
543
    if(empty($fleet_flying_list[$objFleet->mission_type])) {
544
      $fleet_flying_list[$objFleet->mission_type] = new FleetList();
545
    }
546
    $fleet_flying_list[$objFleet->mission_type][$fleet_id] = $objFleet;
547
  }
548
  tpl_topnav_event_build($template, $fleet_flying_list[0]);
549
  tpl_topnav_event_build($template, $fleet_flying_list[MT_EXPLORE], 'expedition');
550
551
  que_tpl_parse($template, QUE_STRUCTURES, $user, $planetrow, null, true);
552
  que_tpl_parse($template, QUE_RESEARCH, $user, array(), null, !classSupernova::$user_options[PLAYER_OPTION_NAVBAR_RESEARCH_WIDE]);
553
  que_tpl_parse($template, SUBQUE_FLEET, $user, $planetrow, null, true);
554
555
  if(!empty(classSupernova::$sn_mvc['navbar_prefix_button']) && is_array(classSupernova::$sn_mvc['navbar_prefix_button'])) {
556
    foreach(classSupernova::$sn_mvc['navbar_prefix_button'] as $navbar_button_image => $navbar_button_url) {
557
      $template->assign_block_vars('navbar_prefix_button', array(
558
        'IMAGE'        => $navbar_button_image,
559
        'URL_RELATIVE' => $navbar_button_url,
560
      ));
561
    }
562
  }
563
564
  $template->assign_var('NAVBAR_PREFIX_BUTTONS', is_array(classSupernova::$sn_mvc['navbar_prefix_button']) ? count(classSupernova::$sn_mvc['navbar_prefix_button']) : 0);
565
566
  $str_date_format = "%3$02d %2$0s %1$04d {$classLocale['top_of_year']} %4$02d:%5$02d:%6$02d";
567
  $time_now_parsed = getdate(SN_TIME_NOW);
568
  $time_local_parsed = getdate(defined('SN_CLIENT_TIME_LOCAL') ? SN_CLIENT_TIME_LOCAL : SN_TIME_NOW);
569
570
  if(classSupernova::$config->game_news_overview) {
571
    $user_last_read_safe = intval($user['news_lastread']);
572
    nws_render($template, "WHERE UNIX_TIMESTAMP(`tsTimeStamp`) >= {$user_last_read_safe}", classSupernova::$config->game_news_overview);
573
  }
574
575
  $notes_query = DBStaticNote::db_note_list_by_owner($user['id'], true);
576
  while($note_row = db_fetch($notes_query)) {
577
    note_assign($template, $note_row);
578
  }
579
580
  $premium_lvl = mrc_get_level($user, null, UNIT_PREMIUM, true, true);
581
  $darkMatter = mrc_get_level($user, null, RES_DARK_MATTER);
582
  $darkMatterPlain = mrc_get_level($user, null, RES_DARK_MATTER, false, true);
583
  $metaMatter = mrc_get_level($user, null, RES_METAMATTER);
584
  $template->assign_vars(array(
585
    'HALLOWEEN' => !empty(sn_module::$sn_module_list['event']['event_halloween_2015']) && sn_module::$sn_module_list['event']['event_halloween_2015']->manifest['active'],
586
587
    'QUE_ID'   => QUE_RESEARCH,
588
    'QUE_HTML' => 'topnav',
589
590
    'RESEARCH_ONGOING' => (boolean)$user['que'],
591
592
    'TIME_TEXT'       => sprintf($str_date_format, $time_now_parsed['year'], classLocale::$lang['months'][$time_now_parsed['mon']], $time_now_parsed['mday'],
593
      $time_now_parsed['hours'], $time_now_parsed['minutes'], $time_now_parsed['seconds']
594
    ),
595
    'TIME_TEXT_LOCAL' => sprintf($str_date_format, $time_local_parsed['year'], classLocale::$lang['months'][$time_local_parsed['mon']], $time_local_parsed['mday'],
596
      $time_local_parsed['hours'], $time_local_parsed['minutes'], $time_local_parsed['seconds']
597
    ),
598
599
    'GAME_BLITZ_REGISTER'             => classSupernova::$config->game_blitz_register,
600
    'GAME_BLITZ_REGISTER_TEXT'        => classLocale::$lang['sys_blitz_registration_mode_list'][classSupernova::$config->game_blitz_register],
601
    'BLITZ_REGISTER_OPEN'             => classSupernova::$config->game_blitz_register == BLITZ_REGISTER_OPEN,
602
    'BLITZ_REGISTER_CLOSED'           => classSupernova::$config->game_blitz_register == BLITZ_REGISTER_CLOSED,
603
    'BLITZ_REGISTER_SHOW_LOGIN'       => classSupernova::$config->game_blitz_register == BLITZ_REGISTER_SHOW_LOGIN,
604
    'BLITZ_REGISTER_DISCLOSURE_NAMES' => classSupernova::$config->game_blitz_register == BLITZ_REGISTER_DISCLOSURE_NAMES,
605
    'GAME_BLITZ'                      => classSupernova::$config->game_mode == GAME_BLITZ,
606
607
    '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...
608
    'USERS_TOTAL'   => classSupernova::$config->users_amount,
609
    'USER_RANK'     => $user['total_rank'],
610
    'USER_NICK'     => $user['username'],
611
    'USER_AVATAR'   => $user['avatar'],
612
    'USER_AVATARID' => $user['id'],
613
    'USER_PREMIUM'  => $premium_lvl,
614
    'USER_RACE'     => $user['player_race'],
615
616
    'TOPNAV_CURRENT_PLANET'       => $user['current_planet'],
617
    '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...
618
    'TOPNAV_CURRENT_PLANET_IMAGE' => $planetrow['image'],
619
    'TOPNAV_COLONIES_CURRENT'     => get_player_current_colonies($user),
620
    'TOPNAV_COLONIES_MAX'         => get_player_max_colonies($user),
621
    'TOPNAV_MODE'                 => $GET_mode,
622
623
    'TOPNAV_DARK_MATTER'            => $darkMatter,
624
    'TOPNAV_DARK_MATTER_TEXT'       => pretty_number($darkMatter),
625
    'TOPNAV_DARK_MATTER_PLAIN'      => $darkMatterPlain,
626
    'TOPNAV_DARK_MATTER_PLAIN_TEXT' => pretty_number($darkMatterPlain),
627
    'TOPNAV_METAMATTER'             => $metaMatter,
628
    'TOPNAV_METAMATTER_TEXT'        => pretty_number($metaMatter),
629
630
    // TODO ГРЯЗНЫЙ ХАК!!!
631
    'TOPNAV_PAYMENT'                => sn_module_get_active_count('payment') && !defined('SN_GOOGLE'),
632
633
    'TOPNAV_MESSAGES_ADMIN'    => $user['msg_admin'],
634
    'TOPNAV_MESSAGES_PLAYER'   => $user['mnl_joueur'],
635
    'TOPNAV_MESSAGES_ALLIANCE' => $user['mnl_alliance'],
636
    'TOPNAV_MESSAGES_ATTACK'   => $user['mnl_attaque'],
637
    'TOPNAV_MESSAGES_ALL'      => $user['new_message'],
638
639
    'TOPNAV_FLEETS_FLYING'      => is_object($fleet_flying_list[0]) ? $fleet_flying_list[0]->count() : 0,
640
    'TOPNAV_FLEETS_TOTAL'       => GetMaxFleets($user),
641
    'TOPNAV_EXPEDITIONS_FLYING' => is_object($fleet_flying_list[MT_EXPLORE]) ? $fleet_flying_list[MT_EXPLORE]->count() : 0,
642
    'TOPNAV_EXPEDITIONS_TOTAL'  => get_player_max_expeditons($user),
643
644
    'TOPNAV_QUEST_COMPLETE' => get_quest_amount_complete($user['id']),
645
646
    'GAME_NEWS_OVERVIEW'       => classSupernova::$config->game_news_overview,
647
    'GAME_RESEARCH_DISABLED'   => defined('GAME_RESEARCH_DISABLED') && GAME_RESEARCH_DISABLED,
648
    'GAME_DEFENSE_DISABLED'    => defined('GAME_DEFENSE_DISABLED') && GAME_DEFENSE_DISABLED,
649
    'GAME_STRUCTURES_DISABLED' => defined('GAME_STRUCTURES_DISABLED') && GAME_STRUCTURES_DISABLED,
650
    'GAME_HANGAR_DISABLED'     => defined('GAME_HANGAR_DISABLED') && GAME_HANGAR_DISABLED,
651
652
    'PLAYER_OPTION_NAVBAR_PLANET_VERTICAL'       => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_PLANET_VERTICAL],
653
    'PLAYER_OPTION_NAVBAR_DISABLE_RESEARCH'      => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_RESEARCH],
654
    'PLAYER_OPTION_NAVBAR_DISABLE_PLANET'        => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_PLANET],
655
    'PLAYER_OPTION_NAVBAR_DISABLE_HANGAR'        => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_HANGAR],
656
    'PLAYER_OPTION_NAVBAR_DISABLE_FLYING_FLEETS' => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_FLYING_FLEETS],
657
    'PLAYER_OPTION_NAVBAR_DISABLE_EXPEDITIONS'   => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_EXPEDITIONS],
658
    'PLAYER_OPTION_NAVBAR_DISABLE_QUESTS'        => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_QUESTS],
659
    'PLAYER_OPTION_NAVBAR_DISABLE_META_MATTER'   => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_META_MATTER],
660
    'PLAYER_OPTION_NAVBAR_RESEARCH_WIDE'         => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_RESEARCH_WIDE],
661
662
    'SUBQUE_FLEET'   => SUBQUE_FLEET,
663
    'QUE_RESEARCH'   => QUE_RESEARCH,
664
    'QUE_STRUCTURES' => QUE_STRUCTURES,
665
  ));
666
667
  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)) {
668
    tpl_set_resource_info($template, $planetrow);
669
    $template->assign_vars(array(
670
      'SN_RENDER_NAVBAR_PLANET' => true,
671
      'SN_NAVBAR_HIDE_FLEETS'   => true,
672
    ));
673
  }
674
675
  return $template;
676
}
677
678
/**
679
 * @param template|string $template
680
 */
681
function displayP($template) {
682
  if(is_object($template)) {
683
    if(empty($template->parsed)) {
684
      parsetemplate($template);
685
    }
686
687
    foreach($template->files as $section => $filename) {
688
      $template->display($section);
689
    }
690
  } else {
691
    print($template);
692
  }
693
}
694
695
/**
696
 * @param template|string $template
697
 * @param array|bool      $array
698
 *
699
 * @return mixed
700
 */
701
function parsetemplate($template, $array = false) {
702
  if(is_object($template)) {
703
    global $user;
704
705
    if(!empty($array) && is_array($array)) {
706
      foreach($array as $key => $data) {
707
        $template->assign_var($key, $data);
708
      }
709
    }
710
711
    $template->assign_vars(array(
712
      'dpath'          => $user['dpath'] ? $user['dpath'] : DEFAULT_SKINPATH,
713
      'SN_TIME_NOW'    => SN_TIME_NOW,
714
      'USER_AUTHLEVEL' => isset($user['authlevel']) ? $user['authlevel'] : -1,
715
      'SN_GOOGLE'      => defined('SN_GOOGLE'),
716
    ));
717
718
    $template->parsed = true;
719
720
    return $template;
721
  } else {
722
    $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...
723
    $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...
724
725
    $search[] = '#\{L_([a-z0-9\-_]*?)\}#Ssie';
726
    $replace[] = '((isset(classLocale::$lang[\'\1\'])) ? classLocale::$lang[\'\1\'] : \'{L_\1}\');';
727
728
    $search[] = '#\{([a-z0-9\-_]*?)\}#Ssie';
729
    $replace[] = '((isset($array[\'\1\'])) ? $array[\'\1\'] : \'{\1}\');';
730
731
    return preg_replace($search, $replace, $template);
732
  }
733
}
734
735
/**
736
 * @param array|string  $files
737
 * @param template|bool $template
738
 * @param string|bool   $template_path
739
 *
740
 * @return template
741
 */
742
function gettemplate($files, $template = false, $template_path = false) {
743
  global $sn_page_name, $user;
744
745
  $template_ex = '.tpl.html';
746
747
  if($template === false) {
748
    return sys_file_read(TEMPLATE_DIR . '/' . $files . $template_ex);
749
  }
750
751
  is_string($files) ? $files = array(basename($files) => $files) : false;
752
753
  !is_object($template) ? $template = new template() : false;
754
  //$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...
755
756
  $tmpl_name = gettemplatename($user['dpath']);
757
  $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...
758
759
  // TODO ГРЯЗНЫЙ ХАК! Это нужно, что бы по возможности перезаписать инфу из языковых пакетов модулей там, где она была перезаписана раньше инфой из основного пакета. Почему?
760
  //  - сначала грузятся модули и их языковые пакеты
761
  //  - затем по ходу дела ОСНОВНОЙ языковой пакет может перезаписать данные из МОДУЛЬНОГО языкового пакета
762
  // Поэтому и нужен этот грязный хак
763
  // В норме же - страницы заявляют сами, какие им пакеты нужны. Так что сначала всегда должны грузится основные языковые пакеты, а уже ПОВЕРХ них - пакеты модулей
764
  !empty(classSupernova::$sn_mvc['i18n']['']) ? lng_load_i18n(classSupernova::$sn_mvc['i18n']['']) : false;
765
  $sn_page_name ? lng_load_i18n(classSupernova::$sn_mvc['i18n'][$sn_page_name]) : false;
766
767
  foreach($files as &$filename) {
768
    $filename = $filename . $template_ex;
769
  }
770
771
  $template->set_filenames($files);
772
773
  return $template;
774
}
775
776
/**
777
 * @param template $template
778
 */
779
function tpl_login_lang(&$template) {
780
  global $language;
781
782
  $url_params = array();
783
784
  $language ? $url_params[] = "lang={$language}" : false;
785
786
  ($id_ref = sys_get_param_id('id_ref')) ? $url_params[] = "id_ref={$id_ref}" : false;
787
788
  $template->assign_vars($q = array(
789
    'LANG'     => $language ? $language : '',
790
    'referral' => $id_ref ? '&id_ref=' . $id_ref : '',
791
792
    '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...
793
    'FILENAME'       => basename($_SERVER['PHP_SELF']),
794
  ));
795
796
  foreach(lng_get_list() as $lng_id => $lng_data) {
797
    if(isset($lng_data['LANG_VARIANTS']) && is_array($lng_data['LANG_VARIANTS'])) {
798
      foreach($lng_data['LANG_VARIANTS'] as $lang_variant) {
799
        $lng_data1 = $lng_data;
800
        $lng_data1 = array_merge($lng_data1, $lang_variant);
801
        $template->assign_block_vars('language', $lng_data1);
802
      }
803
    } else {
804
      $template->assign_block_vars('language', $lng_data);
805
    }
806
  }
807
}
808
809
/**
810
 * @param template $template
811
 * @param array    $planet
812
 * @param int      $que_type
813
 *
814
 * @return int
815
 */
816
function tpl_assign_hangar(&$template, $planet, $que_type) {
817
  $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...
818
  $que = $que['ques'][$que_type][$planet['id_owner']][$planet['id']];
819
820
  $que_length = 0;
821
  if(!empty($que)) {
822
    foreach($que as $que_item) {
823
      $template->assign_block_vars('que', que_tpl_parse_element($que_item));
824
    }
825
    $que_length = count($que);
826
  }
827
828
  return $que_length;
829
}
830
831
/**
832
 * @param template $template
833
 * @param array    $density_price_chart
834
 * @param int      $user_dark_matter
835
 */
836
function tpl_planet_density_info(&$template, &$density_price_chart, $user_dark_matter) {
837
  foreach($density_price_chart as $density_price_index => &$density_price_data) {
838
    $density_cost = $density_price_data;
839
    $density_number_style = pretty_number($density_cost, true, $user_dark_matter, false, false);
840
841
    $density_price_data = array(
842
      'COST'            => $density_cost,
843
      'COST_TEXT'       => $density_number_style['text'],
844
      'COST_TEXT_CLASS' => $density_number_style['class'],
845
      'REST'            => $user_dark_matter - $density_cost,
846
      'ID'              => $density_price_index,
847
      'TEXT'            => classLocale::$lang['uni_planet_density_types'][$density_price_index],
848
    );
849
    $template->assign_block_vars('densities', $density_price_data);
850
  }
851
}
852
853
/**
854
 * @param template $template
855
 * @param string   $name
856
 * @param mixed    $values
857
 */
858
function tpl_assign_select(&$template, $name, $values) {
859
  !is_array($values) ? $values = array($values => $values) : false;
860
861
  foreach($values as $key => $value) {
862
    $template->assign_block_vars($name, array(
863
      'KEY'   => htmlentities($key, ENT_COMPAT, 'UTF-8'),
864
      'VALUE' => htmlentities($value, ENT_COMPAT, 'UTF-8'),
865
    ));
866
  }
867
}
868