Completed
Push — master ( 4b7f62...6a99e5 )
by Nazar
04:14
created

functions.php ➔ get_footer()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 36
Code Lines 23

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 4
eloc 23
nc 2
nop 0
dl 0
loc 36
rs 8.5806
1
<?php
2
/**
3
 * @package    CleverStyle CMS
4
 * @subpackage CleverStyle theme
5
 * @author     Nazar Mokrynskyi <[email protected]>
6
 * @copyright  Copyright (c) 2014-2016, Nazar Mokrynskyi
7
 * @license    MIT License, see license.txt
8
 */
9
namespace cs\themes\CleverStyle;
10
use
11
	cs\Config,
12
	cs\DB,
13
	cs\Event,
14
	cs\Language,
15
	cs\Page,
16
	cs\Request,
17
	cs\User,
18
	h;
19
20
/**
21
 * Returns array with `a` items
22
 *
23
 * @return string[]
24
 */
25
function get_main_menu () {
26
	$Config          = Config::instance();
27
	$L               = Language::instance();
28
	$User            = User::instance();
29
	$main_menu_items = [];
30
	/**
31
	 * Administration item
32
	 */
33
	if ($User->admin()) {
34
		$main_menu_items[] = h::a(
35
			$L->system_admin_administration,
36
			[
37
				'href' => 'admin'
38
			]
39
		);
40
	}
41
	/**
42
	 * Home item
43
	 */
44
	$main_menu_items[] = h::a(
45
		$L->system_home,
46
		[
47
			'href' => '/'
48
		]
49
	);
50
	/**
51
	 * All other active modules if permissions allow to visit
52
	 */
53
	foreach (array_keys($Config->components['modules']) as $module) {
54
		if (
55
			$module != Config::SYSTEM_MODULE &&
56
			$module != $Config->core['default_module'] &&
57
			$User->get_permission($module, 'index') &&
58
			file_exists_with_extension(MODULES."/$module/index", ['php', 'html', 'json']) &&
59
			!@file_get_json(MODULES."/$module/meta.json")['hide_in_menu'] &&
60
			$Config->module($module)->enabled()
61
		) {
62
			$main_menu_items[] = h::a(
63
				$L->$module,
64
				[
65
					'href' => path($L->$module)
66
				]
67
			);
68
		}
69
	}
70
	return $main_menu_items;
71
}
72
73
/**
74
 * Getting footer information
75
 *
76
 * @return string
77
 */
78
function get_footer () {
79
	$db = class_exists('cs\\DB', false) ? DB::instance() : null;
80
	/**
81
	 * Some useful details about page execution process, will be called directly before output
82
	 */
83
	Event::instance()->on(
84
		'System/Page/render/after',
85
		function () {
86
			$Page       = Page::instance();
87
			$Page->Html = str_replace(
88
				[
89
					'<!--generate time-->',
90
					'<!--memory usage-->',
91
					'<!--peak memory usage-->'
92
				],
93
				[
94
					round(microtime(true) - Request::instance()->started, 5),
95
					round(memory_get_usage() / 1024 / 1024, 5),
96
					round(memory_get_peak_usage() / 1024 / 1024, 5)
97
				],
98
				$Page->Html
99
			);
100
		}
101
	);
102
	return h::div(
103
		sprintf(
104
			'Page generated in %s s; %d queries to DB in %f s; memory consumption %s MiB (peak %s MiB)',
105
			'<!--generate time-->',
106
			$db ? $db->queries() : 0,
107
			$db ? round($db->time(), 5) : 0,
108
			'<!--memory usage-->',
109
			'<!--peak memory usage-->'
110
		),
111
		'© Powered by <a target="_blank" href="http://cleverstyle.org/cms" title="CleverStyle CMS">CleverStyle CMS</a>'
112
	);
113
}
114
115
function level ($in, $level) {
116
	return trim(h::level($in, $level))."\n";
117
}
118