Completed
Push — master ( df8ec4...96358d )
by Nazar
04:25
created

general   B

Complexity

Total Complexity 39

Size/Duplication

Total Lines 411
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 5
Bugs 1 Features 3
Metric Value
wmc 39
lcom 1
cbo 7
dl 0
loc 411
rs 8.2857
c 5
b 1
f 3

9 Methods

Rating   Name   Duplication   Size   Complexity  
D general_about_server() 0 228 14
A state() 0 3 2
B server_api() 0 18 7
A apache_version() 0 8 1
A general_appearance() 0 7 1
A general_languages() 0 7 1
B general_optimization() 0 40 6
B general_site_info() 0 30 4
A general_system() 0 63 3
1
<?php
2
/**
3
 * @package    CleverStyle CMS
4
 * @subpackage System module
5
 * @category   modules
6
 * @author     Nazar Mokrynskyi <[email protected]>
7
 * @copyright  Copyright (c) 2015, Nazar Mokrynskyi
8
 * @license    MIT License, see license.txt
9
 */
10
namespace cs\modules\System\admin\Controller;
11
use
12
	cs\Cache,
13
	cs\Config,
14
	cs\Core,
15
	cs\DB,
16
	cs\Index,
17
	cs\Language,
18
	h;
19
20
trait general {
21
	static function general_about_server (
22
		/** @noinspection PhpUnusedParameterInspection */
23
		$route_ids,
1 ignored issue
show
Unused Code introduced by
The parameter $route_ids 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...
24
		$route_path
25
	) {
26
		$Core  = Core::instance();
27
		$Index = Index::instance();
28
		$L     = Language::instance();
29
		if (isset($route_path[2])) {
30
			interface_off();
31
			$Index->form = false;
32
			switch ($route_path[2]) {
33
				case 'phpinfo':
34
					$Index->Content = ob_wrapper(
35
						function () {
36
							phpinfo();
37
						}
38
					);
39
					break;
40
				case 'readme.html':
41
					$Index->Content = file_get_contents(DIR.'/readme.html');
42
			}
43
			return;
44
		}
45
		$hhvm_version = defined('HHVM_VERSION') ? HHVM_VERSION : false;
46
		$Index->form  = false;
47
		$Index->content(
48
			h::{'div.cs-text-right'}(
49
				h::{'a[is=cs-link-button][target=_blank]'}(
50
					'phpinfo()',
51
					[
52
						'href' => "$Index->action/phpinfo"
53
					]
54
				).
55
				h::{'a[is=cs-link-button][icon=info][target=_blank]'}(
56
					$L->information_about_system,
57
					[
58
						'href' => "$Index->action/readme.html"
59
					]
60
				).
61
				h::{'button[is=cs-button][icon=legal]'}(
62
					$L->license
63
				).
64
				h::{'section[is=cs-section-modal] pre'}(
65
					file_get_contents(DIR.'/license.txt')
66
				)
67
			).
68
			static::vertical_table(
69
				[
70
					"$L->operation_system:",
71
					php_uname('s').' '.php_uname('r').' '.php_uname('v')
72
				],
73
				[
74
					"$L->server_type:",
75
					self::server_api()
76
				],
77
				stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== false ? [
78
					$L->version_of('Apache').':',
0 ignored issues
show
Documentation Bug introduced by
The method version_of does not exist on object<cs\Language>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
79
					self::apache_version()
80
				] : false,
81
				stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false ? [
82
					$L->version_of('Nginx').':',
0 ignored issues
show
Documentation Bug introduced by
The method version_of does not exist on object<cs\Language>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
83
					explode('/', $_SERVER['SERVER_SOFTWARE'])[1]
84
				] : false,
85
				$hhvm_version ? [
86
					$L->version_of('HHVM').':',
0 ignored issues
show
Documentation Bug introduced by
The method version_of does not exist on object<cs\Language>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
87
					$hhvm_version
88
				] : false,
89
				$hhvm_version ? false : [
90
					"$L->available_ram:",
91
					str_replace(
92
						['K', 'M', 'G'],
93
						[" $L->KB", " $L->MB", " $L->GB"],
94
						ini_get('memory_limit')
95
					)
96
				],
97
				[
98
					$L->version_of('PHP').':',
0 ignored issues
show
Documentation Bug introduced by
The method version_of does not exist on object<cs\Language>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
99
					PHP_VERSION
100
				],
101
				[
102
					"$L->php_components:",
103
					h::{'table.cs-table tr| td'}(
104
						[
105
							"$L->openssl:",
106
							[
107
								extension_loaded('openssl') ? $L->on : $L->off.' '.h::icon('info-circle', ['tooltip' => $L->openssl_warning]),
108
								[
109
									'class' => self::state(extension_loaded('openssl'))
110
								]
111
							]
112
						],
113
						[
114
							"$L->curl_lib:",
115
							[
116
								$L->get(extension_loaded('curl')),
117
								[
118
									'class' => self::state(extension_loaded('curl'))
119
								]
120
							]
121
						],
122
						[
123
							"$L->apcu_module:",
124
							[
125
								$L->get(extension_loaded('apcu')),
126
								[
127
									'class' => self::state(extension_loaded('apcu'))
128
								]
129
							]
130
						],
131
						[
132
							"$L->memcached_module:",
133
							[
134
								$L->get(extension_loaded('memcached'))
135
							]
136
						]
137
					)
138
				],
139
				[
140
					"$L->main_db:",
141
					$Core->db_type
142
				],
143
				[
144
					"$L->properties $Core->db_type:",
145
					h::{'table.cs-table tr| td'}(
146
						[
147
							"$L->host:",
148
							$Core->db_host
149
						],
150
						[
151
							$L->version_of($Core->db_type).':',
0 ignored issues
show
Documentation Bug introduced by
The method version_of does not exist on object<cs\Language>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
152
							[
153
								DB::instance()->server()
0 ignored issues
show
Documentation Bug introduced by
The method server does not exist on object<cs\DB>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
154
							]
155
						],
156
						[
157
							"$L->name_of_db:",
158
							$Core->db_name
159
						],
160
						[
161
							"$L->prefix_for_db_tables:",
162
							$Core->db_prefix
163
						]
164
					)
165
				],
166
				[
167
					"$L->main_storage:",
168
					$Core->storage_type
169
				],
170
				[
171
					"$L->cache_engine:",
172
					$Core->cache_engine
173
				],
174
				[
175
					"$L->free_disk_space:",
176
					format_filesize(disk_free_space('./'), 2)
177
				],
178
				[
179
					"$L->php_ini_settings:",
180
					h::{'table.cs-table tr| td'}(
181
						[
182
							"$L->allow_file_upload:",
183
							[
184
								$L->get(ini_get('file_uploads')),
185
								[
186
									'class' => self::state(ini_get('file_uploads'))
187
								]
188
							]
189
						],
190
						$hhvm_version ? false : [
191
							"$L->max_file_uploads:",
192
							ini_get('max_file_uploads')
193
						],
194
						[
195
							"$L->upload_limit:",
196
							format_filesize(
197
								str_replace(
198
									['K', 'M', 'G'],
199
									[" $L->KB", " $L->MB", " $L->GB"],
200
									ini_get('upload_max_filesize')
201
								)
202
							)
203
						],
204
						[
205
							"$L->post_max_size:",
206
							format_filesize(
207
								str_replace(
208
									['K', 'M', 'G'],
209
									[" $L->KB", " $L->MB", " $L->GB"],
210
									ini_get('post_max_size')
211
								)
212
							)
213
						],
214
						$hhvm_version ? false : [
215
							"$L->max_execution_time:",
216
							format_time(ini_get('max_execution_time'))
217
						],
218
						$hhvm_version ? false : [
219
							"$L->max_input_time:",
220
							format_time(ini_get('max_input_time'))
221
						],
222
						$hhvm_version ? false : [
223
							"$L->default_socket_timeout:",
224
							format_time(ini_get('default_socket_timeout'))
225
						],
226
						[
227
							"$L->allow_url_fopen:",
228
							[
229
								$L->get(ini_get('allow_url_fopen')),
230
								[
231
									'class' => self::state(ini_get('allow_url_fopen'))
232
								]
233
							]
234
						],
235
						[
236
							"$L->display_errors:",
237
							[
238
								$L->get((bool)ini_get('display_errors')),
239
								[
240
									'class' => self::state(!ini_get('display_errors'))
241
								]
242
							]
243
						]
244
					)
245
				]
246
			)
247
		);
248
	}
249
	static private function state ($state) {
250
		return $state ? 'cs-block-success cs-text-success' : 'cs-block-error cs-text-error';
251
	}
252
	/**
253
	 * Returns server type
254
	 *
255
	 * @return string
256
	 */
257
	static private function server_api () {
258
		$phpinfo = ob_wrapper('phpinfo');
259
		if (stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== false) {
260
			return 'Apache'.(stripos($phpinfo, 'mod_php') !== false ? ' + mod_php' : '');
261
		} elseif (stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false) {
262
			$return = 'Nginx';
263
			if (stripos($phpinfo, 'php-fpm') !== false) {
264
				$return .= ' + PHP-FPM';
265
			} elseif (defined('HHVM_VERSION')) {
266
				$return .= ' + HHVM';
267
			}
268
			return $return;
269
		} elseif (isset($_SERVER['SERVER_SOFTWARE'])) {
270
			return $_SERVER['SERVER_SOFTWARE'];
271
		} else {
272
			return Language::instance()->indefinite;
273
		}
274
	}
275
	static private function apache_version () {
276
		preg_match(
277
			'/Apache[\-\/]([0-9\.\-]+)/',
278
			ob_wrapper('phpinfo'),
279
			$version
280
		);
281
		return $version[1];
282
	}
283
	static function general_appearance () {
284
		$Index       = Index::instance();
285
		$Index->form = false;
286
		$Index->content(
287
			h::cs_system_admin_themes()
288
		);
289
	}
290
	static function general_languages () {
291
		$Index       = Index::instance();
292
		$Index->form = false;
293
		$Index->content(
294
			h::cs_system_admin_languages()
295
		);
296
	}
297
	static function general_optimization () {
298
		$Config              = Config::instance();
299
		$Index               = Index::instance();
300
		$L                   = Language::instance();
301
		$sa                  = $Config->core['simple_admin_mode'];
302
		$Index->apply_button = true;
303
		$Index->content(
304
			static::vertical_table(
305
				static::core_input('cache_compress_js_css', 'radio'),
306
				static::core_input('vulcanization', 'radio'),
307
				static::core_input('put_js_after_body', 'radio'),
308
				(!$sa ? static::core_input('inserts_limit', 'number', null, false, 1) : false),
309
				(!$sa ? static::core_input('update_ratio', 'number', null, false, 0, 100) : false),
310
				[
311
					h::{'div#clean_cache'}(),
312
					h::{'div#clean_pcache'}()
313
				],
314
				[
315
					h::{'input[is=cs-input-text][compact][tight]'}(
316
						[
317
							'placeholder' => $L->partial_cache_cleaning,
318
							'style'       => $Config->core['simple_admin_mode'] ? 'display:none;' : false
319
						]
320
					).
321
					h::{'button[is=cs-button]'}(
322
						$L->clean_settings_cache,
323
						Cache::instance()->cache_state() ? [
324
							'onMouseDown' => "cs.admin_cache('#clean_cache', '{$Config->base_url()}/api/System/admin/cache/clean_cache', this.previousElementSibling.value);"
325
						] : ['disabled']
326
					),
327
					h::{'button[is=cs-button]'}(
328
						$L->clean_scripts_styles_cache,
329
						$Config->core['cache_compress_js_css'] ? [
330
							'onMouseDown' => "cs.admin_cache('#clean_pcache', '{$Config->base_url()}/api/System/admin/cache/clean_pcache');"
331
						] : ['disabled']
332
					)
333
				]
334
			)
335
		);
336
	}
337
	static function general_site_info () {
338
		$Config              = Config::instance();
339
		$Index               = Index::instance();
340
		$timezones           = get_timezones_list();
341
		$sa                  = $Config->core['simple_admin_mode'];
342
		$Index->apply_button = true;
343
		Index::instance()->content(
344
			static::vertical_table(
345
				static::core_input('name', 'text', 'site_name'),
346
				!$sa ? static::core_textarea('url') : false,
347
				!$sa ? static::core_textarea('cookie_domain') : false,
348
				!$sa ? static::core_input('cookie_prefix') : false,
349
				[
350
					h::info('timezone'),
351
					h::{'select[is=cs-select]'}(
352
						[
353
							'in'    => array_keys($timezones),
354
							'value' => array_values($timezones)
355
						],
356
						[
357
							'name'     => 'core[timezone]',
358
							'selected' => $Config->core['timezone'],
359
							'size'     => 7
360
						]
361
					)
362
				],
363
				static::core_input('admin_email', 'email')
364
			)
365
		);
366
	}
367
	static function general_system () {
368
		$Config              = Config::instance();
369
		$Index               = Index::instance();
370
		$sa                  = $Config->core['simple_admin_mode'];
371
		$Index->apply_button = true;
372
		$Index->content(
373
			static::vertical_table(
374
				static::core_input('site_mode', 'radio'),
375
				static::core_input('closed_title'),
376
				static::core_textarea('closed_text', 'SIMPLE_EDITOR'),
377
				static::core_input('title_delimiter'),
378
				static::core_input('title_reverse', 'radio'),
379
				static::core_input('show_tooltips', 'radio', false),
380
				static::core_input('simple_admin_mode', 'radio'),
381
				!$sa ? [
382
					h::info('routing'),
383
					h::{'table.cs-table[center] tr| td'}(
384
						[
385
							h::info('routing_in'),
386
							h::info('routing_out')
387
						],
388
						[
389
							h::{'textarea[is=cs-textarea][autosize]'}(
390
								$Config->routing['in'],
391
								[
392
									'name' => 'routing[in]'
393
								]
394
							),
395
							h::{'textarea[is=cs-textarea][autosize]'}(
396
								$Config->routing['out'],
397
								[
398
									'name' => 'routing[out]'
399
								]
400
							)
401
						]
402
					)
403
				] : false,
404
				!$sa ? [
405
					h::info('replace'),
406
					h::{'table.cs-table[center] tr| td'}(
407
						[
408
							h::info('replace_in'),
409
							h::info('replace_out')
410
						],
411
						[
412
							h::{'textarea[is=cs-textarea][autosize]'}(
413
								$Config->replace['in'],
414
								[
415
									'name' => 'replace[in]'
416
								]
417
							),
418
							h::{'textarea[is=cs-textarea][autosize]'}(
419
								$Config->replace['out'],
420
								[
421
									'name' => 'replace[out]'
422
								]
423
							)
424
						]
425
					)
426
				] : false
427
			)
428
		);
429
	}
430
}
431