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

options.php ➔ sn_options_model()   F

Complexity

Conditions 47
Paths > 20000

Size

Total Lines 242
Code Lines 153

Duplication

Lines 0
Ratio 0 %

Importance

Changes 8
Bugs 0 Features 0
Metric Value
cc 47
eloc 153
nc 2280982
nop 0
dl 0
loc 242
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
/**
4
 * options.php
5
 *
6
 * 1.1s - Security checks by Gorlum for http://supernova.ws
7
 * @version 1.0
8
 * @copyright 2008 by ??????? for XNova
9
 */
10
function sn_options_model() {
11
  global $user, $user_option_list, $template_result;
12
13
  $language_new = sys_get_param_str('langer', $user['lang']);
14
15
  if($language_new != $user['lang']) {
16
    classLocale::$lang->lng_switch($language_new);
17
  }
18
19
  lng_include('options');
20
  lng_include('messages');
21
22
  $FMT_DATE = preg_replace(array('/d/', '/m/', '/Y/'), array('DD', 'MM', 'YYYY'), FMT_DATE);
23
24
  if(sys_get_param_str('mode') == 'change') {
25
    if($user['authlevel'] > 0) {
26
      $planet_protection = sys_get_param_int('adm_pl_prot') ? $user['authlevel'] : 0;
27
      db_planet_set_by_owner($user['id'], "`id_level` = '{$planet_protection}'");
28
      db_user_set_by_id($user['id'], "`admin_protection` = '{$planet_protection}'");
29
      $user['admin_protection'] = $planet_protection;
30
    }
31
32
    if(sys_get_param_int('vacation') && !classSupernova::$config->user_vacation_disable) {
33
      sn_db_transaction_start();
34
      if($user['authlevel'] < 3) {
35
        if($user['vacation_next'] > SN_TIME_NOW) {
36
          message(classLocale::$lang['opt_vacation_err_timeout'], classLocale::$lang['Error'], 'index.php?page=options', 5);
37
          die();
38
        }
39
40
        if(FleetList::fleet_count_flying($user['id'])) {
41
          message(classLocale::$lang['opt_vacation_err_your_fleet'], classLocale::$lang['Error'], 'index.php?page=options', 5);
42
          die();
43
        }
44
45
        $que = que_get($user['id'], false);
46
        if(!empty($que)) {
47
          message(classLocale::$lang['opt_vacation_err_que'], classLocale::$lang['Error'], 'index.php?page=options', 5);
48
          die();
49
        }
50
51
        $query = classSupernova::db_get_record_list(LOC_PLANET, "`id_owner` = {$user['id']}");
52
        foreach($query as $planet) {
53
          // $planet = sys_o_get_updated($user, $planet, SN_TIME_NOW);
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...
54
          // $planet = $planet['planet'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
55
56
          $classConfig = classSupernova::$config;
57
          db_planet_set_by_id($planet['id'],
58
            "last_update = " . SN_TIME_NOW . ", energy_used = '0', energy_max = '0',
59
            metal_perhour = '{$classConfig->metal_basic_income}', crystal_perhour = '{$classConfig->crystal_basic_income}', deuterium_perhour = '{$classConfig->deuterium_basic_income}',
60
            metal_mine_porcent = '0', crystal_mine_porcent = '0', deuterium_sintetizer_porcent = '0', solar_plant_porcent = '0',
61
            fusion_plant_porcent = '0', solar_satelit_porcent = '0', ship_sattelite_sloth_porcent = 0"
62
          );
63
        }
64
        $user['vacation'] = SN_TIME_NOW + classSupernova::$config->player_vacation_time;
65
      } else {
66
        $user['vacation'] = SN_TIME_NOW;
67
      }
68
      sn_db_transaction_commit();
69
    }
70
71
    foreach($user_option_list as $option_group_id => $option_group) {
72
      foreach($option_group as $option_name => $option_value) {
73
        if($user[$option_name] !== null) {
74
          $user[$option_name] = sys_get_param_str($option_name);
75
        } else {
76
          $user[$option_name] = $option_value;
77
        }
78
      }
79
    }
80
    $options = sys_user_options_pack($user);
0 ignored issues
show
Unused Code introduced by
$options is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
81
82
83
    $player_options = sys_get_param('options');
84
    if(!empty($player_options)) {
85
      array_walk($player_options, function (&$value) {
86
        // TODO - Когда будет больше параметров - сделать больше проверок
87
        $value = intval($value);
88
      });
89
      classSupernova::$user_options->offsetSet($player_options);
90
      // pdump($player_options);die();
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% 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...
91
      //      player_save_option_array($user, $player_options);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
92
    }
93
94
    $username = substr(sys_get_param_str_unsafe('username'), 0, 32);
95
    $username_safe = db_escape($username);
96
    if($username && $user['username'] != $username && classSupernova::$config->game_user_changename != SERVER_PLAYER_NAME_CHANGE_NONE && sys_get_param_int('username_confirm') && !strpbrk($username, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) {
97
      // проверка на корректность
98
      sn_db_transaction_start();
99
      $name_check = db_player_name_history_get_name_by_name($username_safe);
100
      if(!$name_check || $name_check['player_id'] == $user['id']) {
101
        $user = db_user_by_id($user['id'], true);
102
        switch(classSupernova::$config->game_user_changename) {
103
          case SERVER_PLAYER_NAME_CHANGE_PAY:
104
            if(mrc_get_level($user, $planetrow, RES_DARK_MATTER) < classSupernova::$config->game_user_changename_cost) {
0 ignored issues
show
Bug introduced by
The variable $planetrow does not exist. Did you mean $planet?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
105
              $template_result['.']['result'][] = array(
106
                'STATUS'  => ERR_ERROR,
107
                'MESSAGE' => classLocale::$lang['opt_msg_name_change_err_no_dm'],
108
              );
109
              break;
110
            }
111
            rpg_points_change($user['id'], RPG_NAME_CHANGE, -classSupernova::$config->game_user_changename_cost, sprintf('Пользователь ID %d сменил имя с "%s" на "%s"', $user['id'], $user['username'], $username));
112
113
          case SERVER_PLAYER_NAME_CHANGE_FREE:
114
            db_user_set_by_id($user['id'], "`username` = '{$username_safe}'");
115
            db_player_name_history_replace($user, $username_safe);
116
            // TODO: Change cookie to not force user relogin
117
            // sn_setcookie(SN_COOKIE, '', time() - PERIOD_WEEK, SN_ROOT_RELATIVE);
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
118
            $template_result['.']['result'][] = array(
119
              'STATUS'  => ERR_NONE,
120
              'MESSAGE' => classLocale::$lang['opt_msg_name_changed']
121
            );
122
            $user['username'] = $username;
123
          break;
124
        }
125
      } else {
126
        $template_result['.']['result'][] = array(
127
          'STATUS'  => ERR_ERROR,
128
          'MESSAGE' => classLocale::$lang['opt_msg_name_change_err_used_name'],
129
        );
130
      }
131
      sn_db_transaction_commit();
132
    }
133
134
    if($new_password = sys_get_param('newpass1')) {
135
      try {
136
        if($new_password != sys_get_param('newpass2')) {
137
          throw new Exception(classLocale::$lang['opt_err_pass_unmatched'], ERR_WARNING);
138
        }
139
140
        if(!classSupernova::$auth->password_change(sys_get_param('db_password'), $new_password)) {
141
          throw new Exception(classLocale::$lang['opt_err_pass_wrong'], ERR_WARNING);
142
        }
143
144
        throw new Exception(classLocale::$lang['opt_msg_pass_changed'], ERR_NONE);
145
      } catch(Exception $e) {
146
        $template_result['.']['result'][] = array(
147
          'STATUS'  => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR,
148
          'MESSAGE' => $e->getMessage()
149
        );
150
      }
151
    }
152
153
    $user['email'] = sys_get_param_str('db_email');
154
    $user['dpath'] = sys_get_param_str('dpath');
155
    $user['lang'] = sys_get_param_str('langer', $user['lang']);
156
157
158
    $user['design'] = sys_get_param_int('design');
159
    $user['noipcheck'] = sys_get_param_int('noipcheck');
160
    $user['deltime'] = !sys_get_param_int('deltime') ? 0 : ($user['deltime'] ? $user['deltime'] : SN_TIME_NOW + classSupernova::$config->player_delete_time);
161
162
    $gender = sys_get_param_int('gender', $user['gender']);
163
    !isset(classLocale::$lang['sys_gender_list'][$gender]) ? $gender = $user['gender'] : false;
164
    $user['gender'] = $user['gender'] == GENDER_UNKNOWN ? $gender : $user['gender'];
165
166
    try {
167
      if($user['birthday']) {
168
        throw new exception();
169
      }
170
171
      $user_birthday = sys_get_param_str_unsafe('user_birthday');
172
      if(!$user_birthday || $user_birthday == $FMT_DATE) {
173
        throw new exception();
174
      }
175
176
      // Some black magic to parse any valid date format - those that contains all three "d", "m" and "Y" and any of the delimeters "\", "/", ".", "-"
177
      $pos['d'] = strpos(FMT_DATE, 'd');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$pos was never initialized. Although not strictly required by PHP, it is generally a good practice to add $pos = 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...
178
      $pos['m'] = strpos(FMT_DATE, 'm');
179
      $pos['Y'] = strpos(FMT_DATE, 'Y');
180
      asort($pos);
181
      $i = 0;
182
      foreach($pos as &$position) {
183
        $position = ++$i;
184
      }
185
186
      $regexp = "/" . preg_replace(array('/\\\\/', '/\//', '/\./', '/\-/', '/d/', '/m/', '/Y/'), array('\\\\\\', '\/', '\.', '\-', '(\d?\d)', '(\d?\d)', '(\d{4})'), FMT_DATE) . "/";
187
      if(!preg_match($regexp, $user_birthday, $match)) {
188
        throw new exception();
189
      }
190
191
      if(!checkdate($match[$pos['m']], $match[$pos['d']], $match[$pos['Y']])) {
192
        throw new exception();
193
      }
194
195
      $user['user_birthday'] = db_escape("{$match[$pos['Y']]}-{$match[$pos['m']]}-{$match[$pos['d']]}");
196
      // EOF black magic! Now we have valid SQL date in $user['user_birthday'] - independent of date format
197
198
      $year = date('Y', SN_TIME_NOW);
199
      if(mktime(0, 0, 0, $match[$pos['m']], $match[$pos['d']], $year) > SN_TIME_NOW) {
200
        $year--;
201
      }
202
      $user['user_birthday_celebrated'] = db_escape("{$year}-{$match[$pos['m']]}-{$match[$pos['d']]}");
203
204
      $user_birthday = ", `user_birthday` = '{$user['user_birthday']}', `user_birthday_celebrated` = '{$user['user_birthday_celebrated']}'";
205
    } catch(exception $e) {
206
      $user_birthday = '';
207
    }
208
209
    require_once('includes/includes/sys_avatar.php');
210
211
    $avatar_upload_result = sys_avatar_upload($user['id'], $user['avatar']);
212
    $template_result['.']['result'][] = $avatar_upload_result;
213
214
    $user_time_diff = playerTimeDiff::user_time_diff_get();
215
    if(sys_get_param_int('PLAYER_OPTION_TIME_DIFF_FORCED')) {
216
      playerTimeDiff::user_time_diff_set(array(
217
        PLAYER_OPTION_TIME_DIFF              => sys_get_param_int('PLAYER_OPTION_TIME_DIFF'),
218
        PLAYER_OPTION_TIME_DIFF_UTC_OFFSET   => 0,
219
        PLAYER_OPTION_TIME_DIFF_FORCED       => 1,
220
        PLAYER_OPTION_TIME_DIFF_MEASURE_TIME => SN_TIME_SQL,
221
      ));
222
    } elseif(sys_get_param_int('opt_time_diff_clear') || $user_time_diff[PLAYER_OPTION_TIME_DIFF_FORCED]) {
223
      playerTimeDiff::user_time_diff_set(array(
224
        PLAYER_OPTION_TIME_DIFF              => '',
225
        PLAYER_OPTION_TIME_DIFF_UTC_OFFSET   => 0,
226
        PLAYER_OPTION_TIME_DIFF_FORCED       => 0,
227
        PLAYER_OPTION_TIME_DIFF_MEASURE_TIME => SN_TIME_SQL,
228
      ));
229
    }
230
231
    $user_options_safe = db_escape($user['options']);
232
    db_user_set_by_id($user['id'], "`email` = '{$user['email']}', `lang` = '{$user['lang']}', `avatar` = '{$user['avatar']}',
233
      `dpath` = '{$user['dpath']}', `design` = '{$user['design']}', `noipcheck` = '{$user['noipcheck']}',
234
      `deltime` = '{$user['deltime']}', `vacation` = '{$user['vacation']}', `options` = '{$user_options_safe}', `gender` = {$user['gender']}
235
      {$user_birthday}"
236
    );
237
238
    $template_result['.']['result'][] = array(
239
      'STATUS'  => ERR_NONE,
240
      'MESSAGE' => classLocale::$lang['opt_msg_saved']
241
    );
242
  } elseif(sys_get_param_str('result') == 'ok') {
243
    $template_result['.']['result'][] = array(
244
      'STATUS'  => ERR_NONE,
245
      'MESSAGE' => classLocale::$lang['opt_msg_saved']
246
    );
247
  }
248
249
  $user = db_user_by_id($user['id']);
250
  $options = sys_user_options_unpack($user);
0 ignored issues
show
Unused Code introduced by
$options is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
251
}
252
253
//-------------------------------
254
255
function sn_options_view($template = null) {
256
  global $template_result, $user, $planetrow, $user_option_list, $user_option_types, $sn_message_class_list;
257
  $classLocale = classLocale::$lang;
258
259
  sys_user_vacation($user);
260
261
  $FMT_DATE = preg_replace(array('/d/', '/m/', '/Y/'), array('DD', 'MM', 'YYYY'), FMT_DATE);
262
263
  $template = gettemplate('options', $template);
264
265
  $dir = dir(SN_ROOT_PHYSICAL . 'skins');
266
  while(($entry = $dir->read()) !== false) {
267
    if(is_dir("skins/{$entry}") && $entry[0] != '.') {
268
      $template_result['.']['skin_list'][] = array(
269
        'VALUE'    => $entry,
270
        'NAME'     => $entry,
271
        'SELECTED' => $user['dpath'] == "skins/{$entry}/",
272
      );
273
    }
274
  }
275
  $dir->close();
276
277
  foreach(classLocale::$lang['opt_planet_sort_options'] as $key => &$value) {
278
    $template_result['.']['planet_sort_options'][] = array(
279
      'VALUE'    => $key,
280
      'NAME'     => $value,
281
      'SELECTED' => classSupernova::$user_options[PLAYER_OPTION_PLANET_SORT] == $key,
282
    );
283
  }
284
285
  foreach(classLocale::$lang['sys_gender_list'] as $key => $value) {
286
    $template_result['.']['gender_list'][] = array(
287
      'VALUE'    => $key,
288
      'NAME'     => $value,
289
      'SELECTED' => $user['gender'] == $key,
290
    );
291
  }
292
293
  $lang_list = lng_get_list();
294
  foreach($lang_list as $lang_id => $lang_data) {
295
    $template_result['.']['languages'][] = array(
296
      'VALUE'    => $lang_id,
297
      'NAME'     => $lang_data['LANG_NAME_NATIVE'],
298
      'SELECTED' => $lang_id == $user['lang'],
299
    );
300
  }
301
302
303
  if(isset(classLocale::$lang['menu_customize_show_hide_button_state'])) {
304
    foreach(classLocale::$lang['menu_customize_show_hide_button_state'] as $key => $value) {
305
      $template->assign_block_vars('menu_customize_show_hide_button_state', array(
306
        'ID'   => $key,
307
        'NAME' => $value,
308
      ));
309
    }
310
  }
311
312
  $str_date_format = "%3$02d %2$0s %1$04d {$classLocale['top_of_year']} %4$02d:%5$02d:%6$02d";
313
  $time_now_parsed = getdate($user['deltime']);
314
315
  $user_time_diff = playerTimeDiff::user_time_diff_get();
316
  // $player_options = player_load_option($user);
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...
317
  $template->assign_vars(array(
318
    'USER_ID' => $user['id'],
319
320
    'ACCOUNT_NAME' => sys_safe_output(classSupernova::$auth->account->account_name),
321
322
    'USER_AUTHLEVEL' => $user['authlevel'],
323
324
    'menu_customize_show_hide_button'           => classSupernova::$user_options[PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON],
325
    'PLAYER_OPTION_MENU_SHOW_ON_BUTTON'         => classSupernova::$user_options[PLAYER_OPTION_MENU_SHOW_ON_BUTTON],
326
    'PLAYER_OPTION_MENU_HIDE_ON_BUTTON'         => classSupernova::$user_options[PLAYER_OPTION_MENU_HIDE_ON_BUTTON],
327
    'PLAYER_OPTION_MENU_HIDE_ON_LEAVE'          => classSupernova::$user_options[PLAYER_OPTION_MENU_HIDE_ON_LEAVE],
328
    'PLAYER_OPTION_MENU_UNPIN_ABSOLUTE'         => classSupernova::$user_options[PLAYER_OPTION_MENU_UNPIN_ABSOLUTE],
329
    'PLAYER_OPTION_MENU_ITEMS_AS_BUTTONS'       => classSupernova::$user_options[PLAYER_OPTION_MENU_ITEMS_AS_BUTTONS],
330
    'PLAYER_OPTION_MENU_WHITE_TEXT'             => classSupernova::$user_options[PLAYER_OPTION_MENU_WHITE_TEXT],
331
    'PLAYER_OPTION_MENU_OLD'                    => classSupernova::$user_options[PLAYER_OPTION_MENU_OLD],
332
    'PLAYER_OPTION_UNIVERSE_OLD'                => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_OLD],
333
    'PLAYER_OPTION_UNIVERSE_DISABLE_COLONIZE'   => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_DISABLE_COLONIZE],
334
    'PLAYER_OPTION_DESIGN_DISABLE_BORDERS'      => classSupernova::$user_options[PLAYER_OPTION_DESIGN_DISABLE_BORDERS],
335
    'PLAYER_OPTION_TECH_TREE_TABLE'             => classSupernova::$user_options[PLAYER_OPTION_TECH_TREE_TABLE],
336
    'sound_enabled'                             => classSupernova::$user_options[PLAYER_OPTION_SOUND_ENABLED],
337
    'PLAYER_OPTION_ANIMATION_DISABLED'          => classSupernova::$user_options[PLAYER_OPTION_ANIMATION_DISABLED],
338
    'PLAYER_OPTION_PROGRESS_BARS_DISABLED'      => classSupernova::$user_options[PLAYER_OPTION_PROGRESS_BARS_DISABLED],
339
    'PLAYER_OPTION_FLEET_SHIP_SELECT_OLD'       => classSupernova::$user_options[PLAYER_OPTION_FLEET_SHIP_SELECT_OLD],
340
    'PLAYER_OPTION_FLEET_SHIP_HIDE_SPEED'       => classSupernova::$user_options[PLAYER_OPTION_FLEET_SHIP_HIDE_SPEED],
341
    'PLAYER_OPTION_FLEET_SHIP_HIDE_CAPACITY'    => classSupernova::$user_options[PLAYER_OPTION_FLEET_SHIP_HIDE_CAPACITY],
342
    'PLAYER_OPTION_FLEET_SHIP_HIDE_CONSUMPTION' => classSupernova::$user_options[PLAYER_OPTION_FLEET_SHIP_HIDE_CONSUMPTION],
343
344
    'ADM_PROTECT_PLANETS' => $user['authlevel'] >= 3,
345
    'opt_usern_data'      => htmlspecialchars($user['username']),
346
    'opt_mail1_data'      => $user['email'],
347
    'opt_mail2_data'      => sys_safe_output(classSupernova::$auth->account->account_email),
348
    'OPT_DPATH_DATA'      => $user['dpath'],
349
350
    'PLAYER_OPTION_PLANET_SORT_INVERSE'    => classSupernova::$user_options[PLAYER_OPTION_PLANET_SORT_INVERSE],
351
    'PLAYER_OPTION_FLEET_SPY_DEFAULT'      => classSupernova::$user_options[PLAYER_OPTION_FLEET_SPY_DEFAULT],
352
    'PLAYER_OPTION_TOOLTIP_DELAY'          => classSupernova::$user_options[PLAYER_OPTION_TOOLTIP_DELAY],
353
    'PLAYER_OPTION_BUILD_AUTOCONVERT_HIDE' => classSupernova::$user_options[PLAYER_OPTION_BUILD_AUTOCONVERT_HIDE],
354
355
    'PLAYER_OPTION_NAVBAR_PLANET_VERTICAL'       => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_PLANET_VERTICAL],
356
    'PLAYER_OPTION_NAVBAR_RESEARCH_WIDE'         => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_RESEARCH_WIDE],
357
    'PLAYER_OPTION_NAVBAR_DISABLE_EXPEDITIONS'   => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_EXPEDITIONS],
358
    'PLAYER_OPTION_NAVBAR_DISABLE_FLYING_FLEETS' => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_FLYING_FLEETS],
359
    'PLAYER_OPTION_NAVBAR_DISABLE_RESEARCH'      => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_RESEARCH],
360
    'PLAYER_OPTION_NAVBAR_DISABLE_PLANET'        => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_PLANET],
361
    'PLAYER_OPTION_NAVBAR_DISABLE_HANGAR'        => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_HANGAR],
362
    'PLAYER_OPTION_NAVBAR_DISABLE_QUESTS'        => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_QUESTS],
363
    'PLAYER_OPTION_NAVBAR_DISABLE_META_MATTER'   => classSupernova::$user_options[PLAYER_OPTION_NAVBAR_DISABLE_META_MATTER],
364
365
    'opt_sskin_data' => ($user['design'] == 1) ? " checked='checked'" : '',
366
    'opt_noipc_data' => ($user['noipcheck'] == 1) ? " checked='checked'" : '',
367
    'deltime'        => $user['deltime'],
368
    'deltime_text'   => sprintf($str_date_format, $time_now_parsed['year'], classLocale::$lang['months'][$time_now_parsed['mon']], $time_now_parsed['mday'],
369
      $time_now_parsed['hours'], $time_now_parsed['minutes'], $time_now_parsed['seconds']
370
    ),
371
372
    'opt_avatar' => $user['avatar'],
373
374
    'config_game_email_pm' => classSupernova::$config->game_email_pm,
375
376
    'user_settings_esp'        => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_SPYING],
377
    'user_settings_mis'        => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_MISSILE],
378
    'user_settings_wri'        => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_PM],
379
    'user_settings_statistics' => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_STATS],
380
    'user_settings_info'       => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_PROFILE],
381
    'user_settings_bud'        => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_BUDDY],
382
383
    'user_time_diff_forced' => $user_time_diff[PLAYER_OPTION_TIME_DIFF_FORCED],
384
    // '_user_time_diff' => SN_CLIENT_TIME_DIFF,
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
385
386
    'adm_pl_prot' => $user['admin_protection'],
387
388
    'user_birthday' => $user['user_birthday'],
389
    'GENDER'        => $user['gender'],
390
    'GENDER_TEXT'   => classLocale::$lang['sys_gender_list'][$user['gender']],
391
    'FMT_DATE'      => $FMT_DATE,
392
    'JS_FMT_DATE'   => js_safe_string($FMT_DATE),
393
394
    'USER_VACATION_DISABLE' => classSupernova::$config->user_vacation_disable,
395
    'VACATION_NEXT'         => $user['vacation_next'],
396
    'VACATION_NEXT_TEXT'    => date(FMT_DATE_TIME, $user['vacation_next']),
397
    'VACATION_TIMEOUT'      => $user['vacation_next'] - SN_TIME_NOW > 0 ? $user['vacation_next'] - SN_TIME_NOW : 0,
398
    'SN_TIME_NOW'           => SN_TIME_NOW,
399
400
    'SERVER_SEND_EMAIL' => classSupernova::$config->game_email_pm,
401
402
    'SERVER_NAME_CHANGE'         => classSupernova::$config->game_user_changename != SERVER_PLAYER_NAME_CHANGE_NONE,
403
    'SERVER_NAME_CHANGE_PAY'     => classSupernova::$config->game_user_changename == SERVER_PLAYER_NAME_CHANGE_PAY,
404
    'SERVER_NAME_CHANGE_ENABLED' => classSupernova::$config->game_user_changename == SERVER_PLAYER_NAME_CHANGE_FREE || (classSupernova::$config->game_user_changename == SERVER_PLAYER_NAME_CHANGE_PAY && mrc_get_level($user, $planetrow, RES_DARK_MATTER) >= classSupernova::$config->game_user_changename_cost),
405
406
    'DARK_MATTER' => pretty_number(classSupernova::$config->game_user_changename_cost, true, mrc_get_level($user, $planetrow, RES_DARK_MATTER)),
407
408
    'PAGE_HEADER' => classLocale::$lang['opt_header'],
409
  ));
410
411
  foreach($user_option_list as $option_group_id => $option_group) {
412
    if($option_group_id == OPT_MESSAGE) {
413
      foreach($sn_message_class_list as $message_class_id => $message_class_data) {
414
        if($message_class_data['switchable'] || ($message_class_data['email'] && classSupernova::$config->game_email_pm)) {
415
          $option_name = $message_class_data['name'];
416
417
          $template->assign_block_vars("options_{$option_group_id}", array(
418
            'NAME'  => $message_class_data['name'],
419
            'TEXT'  => classLocale::$lang['msg_class'][$message_class_id],
420
            'PM'    => $message_class_data['switchable'] ? $user["opt_{$option_name}"] : -1,
421
            'EMAIL' => $message_class_data['email'] && classSupernova::$config->game_email_pm ? $user["opt_email_{$option_name}"] : -1,
422
          ));
423
        }
424
      }
425
    } else {
426
      foreach($option_group as $option_name => $option_value) {
427
        if(array_key_exists($option_name, $user_option_types)) {
428
          $option_type = $user_option_types[$option_name];
429
        } else {
430
          $option_type = 'switch';
431
        }
432
433
        $template->assign_block_vars("options_{$option_group_id}", array(
434
          'NAME'  => $option_name,
435
          'TYPE'  => $option_type,
436
          'TEXT'  => classLocale::$lang['opt_custom'][$option_name],
437
          'HINT'  => classLocale::$lang['opt_custom']["{$option_name}_hint"],
438
          'VALUE' => $user[$option_name],
439
        ));
440
      }
441
    }
442
  }
443
444
  return parsetemplate($template);
445
}
446