-
Notifications
You must be signed in to change notification settings - Fork 13
/
pagesection.php
66 lines (65 loc) · 1.89 KB
/
pagesection.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
<?php
class PageSection {
private $template;
private $data;
public function __construct($template) {
global $relative_request_url;
global $active_user;
global $database;
global $config;
$this->template = $template;
$this->data = new StdClass;
$this->data->menu_items = array();
$this->data->menu_items['/'] = 'Home';
$this->data->menu_items['/servers'] = 'Servers';
$this->data->menu_items['/users'] = 'Users';
$this->data->menu_items['/groups'] = 'Groups';
$this->data->menu_items['/pubkeys'] = 'Public keys';
if($active_user && ($active_user->admin || count($active_user->list_admined_servers()) > 0)) {
$this->data->menu_items['/activity'] = 'Activity';
}
if($active_user && $active_user->admin) {
$this->data->menu_items['/tools'] = 'Tools';
}
$this->data->menu_items['/help'] = 'Help';
$this->data->relative_request_url = $relative_request_url;
$this->data->active_user = $active_user;
$this->data->web_config = $config['web'];
$this->data->email_config = $config['email'];
if($active_user && $active_user->developer) {
$this->data->database = $database;
}
}
public function set_by_array($array, $prefix = '') {
foreach($array as $item => $data) {
$this->setData($prefix.$item, $data);
}
}
public function set($item, $data) {
$this->data->$item = $data;
}
public function get($item) {
if(isset($this->data->$item)) {
if(is_object($this->data->$item) && get_class($this->data->$item) == 'PageSection') {
return $this->data->$item->generate();
} else {
return $this->data->$item;
}
} else {
return null;
}
}
public function config() {
global $config;
return $config;
}
public function generate() {
ob_start();
$data = $this->data;
include_once(path_join('templates', 'functions.php'));
include(path_join('templates', $this->template.'.php'));
$output = ob_get_contents();
ob_end_clean();
return $output;
}
}