Issues (1369)

admin/tools.php (7 issues)

1
<?php
2
/**
3
 * erreurs.php
4
 *
5
 * @version 1.0
6
 * @copyright 2009 by Gorlum for http://oGame.Triolan.COM.UA
7
 */
8
9
define('INSIDE', true);
10
define('INSTALL', false);
11
define('IN_ADMIN', true);
12
require('../common.' . substr(strrchr(__FILE__, '.'), 1));
13
14
global $lang, $user, $template_result;
15
16
SnTemplate::messageBoxAdminAccessDenied(AUTH_LEVEL_ADMINISTRATOR);
17
18
$mode = sys_get_param_int('mode');
19
20
switch ($mode) {
21
  case ADM_COUNTER_RECALC:
22
    $template_result['.']['result'][] = [
23
      'STATUS'  => ERR_NONE,
24
      'MESSAGE' => number_format(memory_get_usage()) . ' - memory Before',
25
    ];
26
    $t = new \General\LogCounterShrinker(SN::$gc);
27
    $template_result['.']['result'][] = $t->process();
28
    unset($t);
29
    $template_result['.']['result'][] = [
30
      'STATUS'  => ERR_NONE,
31
      'MESSAGE' => number_format(memory_get_usage()) . ' - memory After',
32
    ];
33
  break;
34
35
  case ADM_TOOL_CONFIG_RELOAD:
36
    SN::$config->db_loadAll();
37
    SN::$db->schema()->clear();
38
39
    SN::$config->pass()->game_watchlist;
40
    if (SN::$config->game_watchlist) {
41
      SN::$config->game_watchlist_array = explode(';', SN::$config->game_watchlist);
0 ignored issues
show
Bug Best Practice introduced by
The property game_watchlist_array does not exist on classConfig. Since you implemented __set, consider adding a @property annotation.
Loading history...
42
    } else {
43
      unset(SN::$config->game_watchlist_array);
0 ignored issues
show
Bug Best Practice introduced by
The property game_watchlist_array does not exist on classConfig. Since you implemented __get, consider adding a @property annotation.
Loading history...
44
    }
45
  break;
46
47
  case ADM_TOOL_MD5:
48
    $template = SnTemplate::gettemplate("admin/md5enc", true);
0 ignored issues
show
true of type true is incompatible with the type null|template expected by parameter $template of SnTemplate::gettemplate(). ( Ignorable by Annotation )

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

48
    $template = SnTemplate::gettemplate("admin/md5enc", /** @scrutinizer ignore-type */ true);
Loading history...
49
    $password_seed = sys_get_param_str_unsafe('seed', SN_SYS_SEC_CHARS_ALLOWED);
50
    $password_length = sys_get_param_int('length', 16);
51
    $string = ($string = sys_get_param_str_unsafe('string')) ? $string : sys_random_string($password_length, $password_seed);
52
53
    $template->assign_vars(array(
54
      'SEED'   => $password_seed,
55
      'LENGTH' => $password_length,
56
      'STRING' => htmlentities($string),
57
      'MD5'    => md5($string),
58
    ));
59
    SnTemplate::display($template, $lang['adm_tools_md5_header']);
60
  break;
61
62
  case ADM_TOOL_FORCE_ALL:
63
    SN::$config->db_saveItem('db_version', 40);
64
    require_once('../includes/update.php');
65
  break;
66
67
  case ADM_TOOL_FORCE_LAST:
68
    SN::$config->db_saveItem('db_version', floor(SN::$config->db_version - 1));
69
    require_once('../includes/update.php');
70
  break;
71
72
  case ADM_TOOL_INFO_PHP:
73
    phpinfo();
74
  break;
75
76
  case ADM_TOOL_INFO_SQL:
77
    $template = SnTemplate::gettemplate("simple_table", true);
78
79
    $template->assign_block_vars('table', $lang['adm_tool_sql_table']['server']);
80
    $status = array(
81
      $lang['adm_tool_sql_server_version'] => SN::$db->getServerInfo(),
82
      $lang['adm_tool_sql_client_version'] => SN::$db->getClientInfo(),
83
      $lang['adm_tool_sql_host_info']      => SN::$db->getHostInfo(),
84
    );
85
    foreach ($status as $key => $value) {
86
      $template->assign_block_vars('table.row', array(
87
        'VALUE_1' => $key,
88
        'VALUE_2' => $value,
89
      ));
90
    }
91
92
    $template->assign_block_vars('table', $lang['adm_tool_sql_table']['status']);
93
    $status = explode('  ', SN::$db->getServerStat());
94
    foreach ($status as $value) {
95
      $row = explode(': ', $value);
96
      $template->assign_block_vars('table.row', array(
97
        'VALUE_1' => $row[0],
98
        'VALUE_2' => $row[1],
99
      ));
100
    }
101
102
103
    $template->assign_block_vars('table', $lang['adm_tool_sql_table']['params']);
104
    $result = doquery('SHOW STATUS;');
0 ignored issues
show
Deprecated Code introduced by
The function doquery() has been deprecated. ( Ignorable by Annotation )

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

104
    $result = /** @scrutinizer ignore-deprecated */ doquery('SHOW STATUS;');
Loading history...
105
    while ($row = db_fetch($result)) {
0 ignored issues
show
Deprecated Code introduced by
The function db_fetch() has been deprecated. ( Ignorable by Annotation )

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

105
    while ($row = /** @scrutinizer ignore-deprecated */ db_fetch($result)) {
Loading history...
106
      $template->assign_block_vars('table.row', array(
107
        'VALUE_1' => $row['Variable_name'],
108
        'VALUE_2' => $row['Value'],
109
      ));
110
    }
111
112
    $template->assign_vars(array(
113
      'PAGE_HEADER'   => $lang['adm_tool_sql_page_header'],
114
      'COLUMN_NAME_1' => $lang['adm_tool_sql_param_name'],
115
      'COLUMN_NAME_2' => $lang['adm_tool_sql_param_value'],
116
      'TABLE_FOOTER'  => 'test',
117
    ));
118
119
    SnTemplate::display($template);
120
  break;
121
122
  case ADM_PTL_TEST:
123
    $template = SnTemplate::gettemplate("admin/admin_ptl_test", true);
124
125
    $template->assign_vars(array(
126
      'PAGE_TITLE' => $lang['adm_ptl_test'],
127
128
      'VAR'                => 'VALUE',
129
      'RENDER_VAR'         => '{VAR}',
130
      'RENDER_DEFINED_VAR' => '{$VAR}',
131
132
133
      'VAR_VALUE' => 'VAR_VALUE',
134
135
      'RENDER_VAR_VALUE'       => '{VAR_VALUE}',
136
      'RENDER_NAVBAR_RESEARCH' => '{I_navbar_research|html}',
137
    ));
138
139
    $template->assign_block_vars('render_test_block', array(
140
      'BLOCK_VAR' => '{VAR}',
141
    ));
142
143
144
    $tests = array(
145
      array('HEADER' => '{VAR} and {$VAR} Variables'),
146
      array(
147
        'SAMPLE'      => '{VAR}',
148
        'EXPECTED'    => 'VALUE',
149
        'DESCRIPTION' => 'Root variable - existing',
150
      ),
151
      array(
152
        'SAMPLE'      => '{VAR_NOT_EXISTS}',
153
        'EXPECTED'    => '',
154
        'DESCRIPTION' => 'Root variable - non-existing',
155
      ),
156
      array(
157
        'SAMPLE'      => '{АБВГД}',
158
        'EXPECTED'    => '{АБВГД}',
159
        'DESCRIPTION' => 'Root variable - wrong name',
160
      ),
161
      array(
162
        'SAMPLE'      => '{$VAR}',
163
        'EXPECTED'    => '$VALUE',
164
        'DESCRIPTION' => 'DEFINE-d variable - existing',
165
      ),
166
      array(
167
        'SAMPLE'      => '{$VAR_NOT_EXISTS}',
168
        'EXPECTED'    => '',
169
        'DESCRIPTION' => 'DEFINE-d variable - non-existing',
170
      ),
171
      array(
172
        'SAMPLE'      => '{$АБВГД}',
173
        'EXPECTED'    => '{$АБВГД}',
174
        'DESCRIPTION' => 'DEFINE-d variable - wrong name',
175
      ),
176
177
      array('HEADER' => '{C_xxx} - Config'),
178
      array(
179
        'SAMPLE'      => '{C___ptl_test}',
180
        'EXPECTED'    => 'config_ptl_test',
181
        'DESCRIPTION' => 'Config variable',
182
      ),
183
      array(
184
        'SAMPLE'      => '{C___ptl_test_array[value]}',
185
        'EXPECTED'    => 'config_ptl_test_array',
186
        'DESCRIPTION' => 'Config array variable',
187
      ),
188
189
      array('HEADER' => '{L_xxx} and {LA_xxx} - Language'),
190
      array(
191
        'SAMPLE'      => '{L_admin_ptl_test_la_}',
192
        'EXPECTED'    => 'Single\'Double"ZeroEnd',
193
        'DESCRIPTION' => 'Language string',
194
      ),
195
      array(
196
        'SAMPLE'      => '{LA_admin_ptl_test_la_}',
197
        'EXPECTED'    => 'Single\\\'Double\"Zero\0End',
198
        'DESCRIPTION' => 'JavaScript-safe language string',
199
      ),
200
      array(
201
        'SAMPLE'      => '{L_surely_not_exists_string_test}',
202
        'EXPECTED'    => '{ L_surely_not_exists_string_test }',
203
        'DESCRIPTION' => 'Language string - non-existing',
204
      ),
205
      array(
206
        'SAMPLE'      => '{LA_surely_not_exists_string_test}',
207
        'EXPECTED'    => '{ LA_surely_not_exists_string_test }',
208
        'DESCRIPTION' => 'JS-safe language string - non-existing',
209
      ),
210
211
      array('HEADER' => '{I_xxx} - Image rendering'),
212
      array(
213
        'SAMPLE'      => "{" . ($tag = "I_NO_IMAGE|height=\"20%\"|width=\"20%\"") . "}<br />{{$tag}|html}",
214
        'EXPECTED'    => ($imgPath = SN_ROOT_VIRTUAL . 'design/images/_no_image.png') . "<br /><img src=\"{$imgPath}\" height=\"20%\" width=\"20%\" />",
215
        'DESCRIPTION' => 'Image - not existing',
216
      ),
217
218
      array(
219
        'SAMPLE'      => "{" . ($tag = "I_/design/images/icon_note_pinned_64x64.png") . "}<br />{{$tag}|html}",
220
        'EXPECTED'    => ($imgPath = SN_ROOT_VIRTUAL . 'design/images/icon_note_pinned_64x64.png') . "<br /><img src=\"{$imgPath}\" />",
221
        'DESCRIPTION' => 'Direct image access by absolute path',
222
      ),
223
      array(
224
        'SAMPLE'      => "{" . ($tag = "I_images/border_small.png") . "}<br />{{$tag}|html}",
225
        'EXPECTED'    => ($imgPath = SN_ROOT_VIRTUAL . 'skins/EpicBlue/images/border_small.png') . "<br /><img src=\"{$imgPath}\" />",
226
        'DESCRIPTION' => 'Access image in skin by relative path',
227
      ),
228
      array(
229
        'SAMPLE'      => "{" . ($tag = "I_navbar_research") . "}<br />{{$tag}|html}",
230
        'EXPECTED'    => ($imgPath = SN_ROOT_VIRTUAL . 'design/images/navbar_research_64x64.png') . "<br /><img src=\"{$imgPath}\" />",
231
        'DESCRIPTION' => 'Image direct access by ID in skin.ini',
232
      ),
233
      array(
234
        'SAMPLE'      => "{" . ($tag = "I_navbar_research|skin=supernova-ivash") . "}<br />{{$tag}|html}",
235
        'EXPECTED'    => ($imgPath = SN_ROOT_VIRTUAL . 'skins/supernova-ivash/navbar/navbar_research_64x64.png') . "<br /><img src=\"{$imgPath}\" />",
236
        'DESCRIPTION' => 'Param \'skin\' - get image by Image ID from other skin',
237
      ),
238
      array(
239
        'SAMPLE'      => "{" . ($tag = "I_navbar_research|height=\"20%\"|width=\"20%\"") . "}<br />{{$tag}|html}",
240
        'EXPECTED'    => ($imgPath = SN_ROOT_VIRTUAL . 'design/images/navbar_research_64x64.png') . "<br /><img src=\"{$imgPath}\" height=\"20%\" width=\"20%\" />",
241
        'DESCRIPTION' => 'Image attributes - height 20%, width 20%',
242
      ),
243
      array(
244
        'SAMPLE'      => "{" . ($tag = "I_navbar_research|skin=supernova-ivash|height=\"40px\"") . "}<br />{{$tag}|html}",
245
        'EXPECTED'    => ($imgPath = SN_ROOT_VIRTUAL . 'skins/supernova-ivash/navbar/navbar_research_64x64.png') . "<br /><img src=\"{$imgPath}\" height=\"40px\" />",
246
        'DESCRIPTION' => 'Param \'skin\' with other params',
247
      ),
248
249
      array(
250
        'SAMPLE'      => "{" . ($tag = "I_[\$BLACK]") . "}<br />{{$tag}|html}",
251
        'EXPECTED'    => ($imgPath = SN_ROOT_VIRTUAL . 'skins/EpicBlue/planeten/black_moon.jpg') . "<br /><img src=\"{$imgPath}\" />",
252
        'DESCRIPTION' => 'DEFINE-d test',
253
      ),
254
255
      array(
256
        'SAMPLE'      => "{" . ($tag = "I_s_[\$BLACK]") . "}<br />{{$tag}|html}",
257
        'EXPECTED'    => ($imgPath = SN_ROOT_VIRTUAL . 'skins/EpicBlue/planeten/small/s_black_moon.jpg') . "<br /><img src=\"{$imgPath}\" />",
258
        'DESCRIPTION' => 'DEFINE-d and prefix test',
259
      ),
260
261
      array(
262
        'SAMPLE'      => '{R_[RENDER_NAVBAR_RESEARCH]}',
263
        'EXPECTED'    => '<img src="' . SN_ROOT_VIRTUAL . 'design/images/navbar_research_64x64.png"/>',
264
        'DESCRIPTION' => 'Re-rendering image',
265
      ),
266
267
      array('HEADER' => 'Blocks'),
268
    );
269
270
//    $tests = array(
271
//      array('HEADER' => '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'),
272
//      array(
273
//        'SAMPLE'      => '{L_admin_ptl_test_la_}',
274
//        'EXPECTED'    => 'Single\'Double"ZeroEnd',
275
//        'DESCRIPTION' => 'Language string',
276
//      ),
277
//    );
278
279
    SN::$config->__ptl_test = 'config_ptl_test';
0 ignored issues
show
Bug Best Practice introduced by
The property __ptl_test does not exist on classConfig. Since you implemented __set, consider adding a @property annotation.
Loading history...
280
    SN::$config->__ptl_test_array = array('value' => 'config_ptl_test_array');
0 ignored issues
show
Bug Best Practice introduced by
The property __ptl_test_array does not exist on classConfig. Since you implemented __set, consider adding a @property annotation.
Loading history...
281
282
    foreach ($tests as $test) {
283
      $test['CONSTRUCTION'] = str_replace(array('{', '}'), array('&#123;', '&#125;'), $test['SAMPLE']);
284
      $template->assign_block_vars('test', $test);
285
    }
286
287
    SnTemplate::display($template);
288
  break;
289
}
290
291
$template = SnTemplate::gettemplate("admin/admin_tools", true);
292
$template->assign_vars(array(
293
  'PAGE_HEADER' => $lang['adm_tools'],
294
));
295
296
$template->assign_recursive($template_result);
297
298
SnTemplate::display($template);
299