-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathindex.php
90 lines (72 loc) · 1.69 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* Konstanta Aplikasi
*/
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', __DIR__.DS);
define('EXT', '.php');
/**
* Memuat Sistem
*/
$app = require 'system/loader.php';
$app->add('routes', function ($c, $name) {
$routes = [
'login' => 'home/login',
'register' => 'home/register',
'logout' => 'home/logout',
'cart' => 'shop/cart',
'account' => 'admin/account',
];
$c->add('pages', function() {
return Page::show()->fetch(false);
});
foreach ($c->get('pages') as $row) {
$routes[$row->alias] = 'home/index/'.$row->alias;
}
$c->merge($name, $routes);
return $routes;
});
/**
* Inisialisasi Menu.
*/
$app->add('main-menu', function ($c) {
$menu = [
'/' => 'Home',
'/shop' => 'Toko',
];
foreach ($c->get('pages') as $row) {
$menu['/'.$row->alias] = $row->judul;
}
return new Menu($menu);
});
$app->add('user-menu', function () {
$items = [];
if ($_tmp = session('cart-items')) {
$items = unserialize($_tmp);
}
$menu = [
'/cart' => 'Trolli '.count($items),
'/admin' => 'Akun Saya',
];
if (User::loggedin()) {
$admin_label = $menu['/admin'];
$menu['/admin'] = [
'label' => User::current('username') ?: $admin_label,
'subs' => ['/logout' => 'Logout']
];
}
return new Menu($menu);
});
$app->add('admin-menu', function () {
$menu = [];
if (User::is('admin')) {
$menu['admin/pages'] = 'Halaman';
$menu['admin/users'] = 'Pengguna';
$menu[] = '-';
}
return new Menu($menu);
});
/**
* Memulai Sistem
*/
$app->start();