Completed
Push — master ( 46b1a6...b603d8 )
by Nazar
04:31 queued 27s
created

general::general_languages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 7
rs 9.4286
cc 1
eloc 5
nc 1
nop 0
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\Core,
13
	cs\DB,
14
	cs\Index,
15
	cs\Language,
16
	h;
17
18
trait general {
19
	static function general_about_server (
20
		/** @noinspection PhpUnusedParameterInspection */
21
		$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...
22
		$route_path
23
	) {
24
		$Core  = Core::instance();
25
		$Index = Index::instance();
26
		$L     = Language::instance();
27
		if (isset($route_path[2])) {
28
			interface_off();
29
			$Index->form = false;
30
			switch ($route_path[2]) {
31
				case 'phpinfo':
32
					$Index->Content = ob_wrapper(
33
						function () {
34
							phpinfo();
35
						}
36
					);
37
					break;
38
				case 'readme.html':
39
					$Index->Content = file_get_contents(DIR.'/readme.html');
40
			}
41
			return;
42
		}
43
		$hhvm_version = defined('HHVM_VERSION') ? HHVM_VERSION : false;
44
		$Index->form  = false;
45
		$Index->content(
46
			h::{'div.cs-text-right'}(
47
				h::{'a[is=cs-link-button][target=_blank]'}(
48
					'phpinfo()',
49
					[
50
						'href' => "$Index->action/phpinfo"
51
					]
52
				).
53
				h::{'a[is=cs-link-button][icon=info][target=_blank]'}(
54
					$L->information_about_system,
55
					[
56
						'href' => "$Index->action/readme.html"
57
					]
58
				).
59
				h::{'button[is=cs-button][icon=legal]'}(
60
					$L->license
61
				).
62
				h::{'section[is=cs-section-modal] pre'}(
63
					file_get_contents(DIR.'/license.txt')
64
				)
65
			).
66
			static::vertical_table(
67
				[
68
					"$L->operation_system:",
69
					php_uname('s').' '.php_uname('r').' '.php_uname('v')
70
				],
71
				[
72
					"$L->server_type:",
73
					self::server_api()
74
				],
75
				stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== false ? [
76
					$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...
77
					self::apache_version()
78
				] : false,
79
				stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false ? [
80
					$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...
81
					explode('/', $_SERVER['SERVER_SOFTWARE'])[1]
82
				] : false,
83
				$hhvm_version ? [
84
					$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...
85
					$hhvm_version
86
				] : false,
87
				$hhvm_version ? false : [
88
					"$L->available_ram:",
89
					str_replace(
90
						['K', 'M', 'G'],
91
						[" $L->KB", " $L->MB", " $L->GB"],
92
						ini_get('memory_limit')
93
					)
94
				],
95
				[
96
					$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...
97
					PHP_VERSION
98
				],
99
				[
100
					"$L->php_components:",
101
					h::{'table.cs-table tr| td'}(
102
						[
103
							"$L->openssl:",
104
							[
105
								extension_loaded('openssl') ? $L->on : $L->off.' '.h::icon('info-circle', ['tooltip' => $L->openssl_warning]),
106
								[
107
									'class' => self::state(extension_loaded('openssl'))
108
								]
109
							]
110
						],
111
						[
112
							"$L->curl_lib:",
113
							[
114
								$L->get(extension_loaded('curl')),
115
								[
116
									'class' => self::state(extension_loaded('curl'))
117
								]
118
							]
119
						],
120
						[
121
							"$L->apcu_module:",
122
							[
123
								$L->get(extension_loaded('apcu')),
124
								[
125
									'class' => self::state(extension_loaded('apcu'))
126
								]
127
							]
128
						],
129
						[
130
							"$L->memcached_module:",
131
							[
132
								$L->get(extension_loaded('memcached'))
133
							]
134
						]
135
					)
136
				],
137
				[
138
					"$L->main_db:",
139
					$Core->db_type
140
				],
141
				[
142
					"$L->properties $Core->db_type:",
143
					h::{'table.cs-table tr| td'}(
144
						[
145
							"$L->host:",
146
							$Core->db_host
147
						],
148
						[
149
							$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...
150
							[
151
								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...
152
							]
153
						],
154
						[
155
							"$L->name_of_db:",
156
							$Core->db_name
157
						],
158
						[
159
							"$L->prefix_for_db_tables:",
160
							$Core->db_prefix
161
						]
162
					)
163
				],
164
				[
165
					"$L->main_storage:",
166
					$Core->storage_type
167
				],
168
				[
169
					"$L->cache_engine:",
170
					$Core->cache_engine
171
				],
172
				[
173
					"$L->free_disk_space:",
174
					format_filesize(disk_free_space('./'), 2)
175
				],
176
				[
177
					"$L->php_ini_settings:",
178
					h::{'table.cs-table tr| td'}(
179
						[
180
							"$L->allow_file_upload:",
181
							[
182
								$L->get(ini_get('file_uploads')),
183
								[
184
									'class' => self::state(ini_get('file_uploads'))
185
								]
186
							]
187
						],
188
						$hhvm_version ? false : [
189
							"$L->max_file_uploads:",
190
							ini_get('max_file_uploads')
191
						],
192
						[
193
							"$L->upload_limit:",
194
							format_filesize(
195
								str_replace(
196
									['K', 'M', 'G'],
197
									[" $L->KB", " $L->MB", " $L->GB"],
198
									ini_get('upload_max_filesize')
199
								)
200
							)
201
						],
202
						[
203
							"$L->post_max_size:",
204
							format_filesize(
205
								str_replace(
206
									['K', 'M', 'G'],
207
									[" $L->KB", " $L->MB", " $L->GB"],
208
									ini_get('post_max_size')
209
								)
210
							)
211
						],
212
						$hhvm_version ? false : [
213
							"$L->max_execution_time:",
214
							format_time(ini_get('max_execution_time'))
215
						],
216
						$hhvm_version ? false : [
217
							"$L->max_input_time:",
218
							format_time(ini_get('max_input_time'))
219
						],
220
						$hhvm_version ? false : [
221
							"$L->default_socket_timeout:",
222
							format_time(ini_get('default_socket_timeout'))
223
						],
224
						[
225
							"$L->allow_url_fopen:",
226
							[
227
								$L->get(ini_get('allow_url_fopen')),
228
								[
229
									'class' => self::state(ini_get('allow_url_fopen'))
230
								]
231
							]
232
						],
233
						[
234
							"$L->display_errors:",
235
							[
236
								$L->get((bool)ini_get('display_errors')),
237
								[
238
									'class' => self::state(!ini_get('display_errors'))
239
								]
240
							]
241
						]
242
					)
243
				]
244
			)
245
		);
246
	}
247
	static private function state ($state) {
248
		return $state ? 'cs-block-success cs-text-success' : 'cs-block-error cs-text-error';
249
	}
250
	/**
251
	 * Returns server type
252
	 *
253
	 * @return string
254
	 */
255
	static private function server_api () {
256
		$phpinfo = ob_wrapper('phpinfo');
257
		if (stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== false) {
258
			return 'Apache'.(stripos($phpinfo, 'mod_php') !== false ? ' + mod_php' : '');
259
		} elseif (stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false) {
260
			$return = 'Nginx';
261
			if (stripos($phpinfo, 'php-fpm') !== false) {
262
				$return .= ' + PHP-FPM';
263
			} elseif (defined('HHVM_VERSION')) {
264
				$return .= ' + HHVM';
265
			}
266
			return $return;
267
		} elseif (isset($_SERVER['SERVER_SOFTWARE'])) {
268
			return $_SERVER['SERVER_SOFTWARE'];
269
		} else {
270
			return Language::instance()->indefinite;
271
		}
272
	}
273
	static private function apache_version () {
274
		preg_match(
275
			'/Apache[\-\/]([0-9\.\-]+)/',
276
			ob_wrapper('phpinfo'),
277
			$version
278
		);
279
		return $version[1];
280
	}
281
	static function general_appearance () {
282
		$Index       = Index::instance();
283
		$Index->form = false;
284
		$Index->content(
285
			h::cs_system_admin_themes()
286
		);
287
	}
288
	static function general_languages () {
289
		$Index       = Index::instance();
290
		$Index->form = false;
291
		$Index->content(
292
			h::cs_system_admin_languages()
293
		);
294
	}
295
	static function general_optimization () {
296
		$Index       = Index::instance();
297
		$Index->form = false;
298
		$Index->content(
299
			h::cs_system_admin_optimization()
300
		);
301
	}
302
	static function general_site_info () {
303
		$Index       = Index::instance();
304
		$Index->form = false;
305
		$Index->content(
306
			h::cs_system_admin_site_info()
307
		);
308
	}
309
	static function general_system () {
310
		$Index       = Index::instance();
311
		$Index->form = false;
312
		$Index->content(
313
			h::cs_system_admin_system()
314
		);
315
	}
316
}
317