-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass.SecurePage.php
101 lines (92 loc) · 2.57 KB
/
class.SecurePage.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
91
92
93
94
95
96
97
98
99
100
101
<?php
require_once('Autoload.php');
require_once('class.SecurePlugin.php');
trait SecureWebPage
{
protected function getSecureRoot()
{
$root = $_SERVER['DOCUMENT_ROOT'];
$script_dir = dirname(__FILE__);
$ret = substr($script_dir, strlen($root));
if($ret === false || strlen($ret) === 0)
{
return '/';
}
else if($ret[strlen($ret)-1] !== '/')
{
$ret .= '/';
}
return $ret;
}
protected function loadAndGetPlugins()
{
$script_dir = dirname(__FILE__);
$plugin_files = glob($script_dir.'/*/plugin.php');
$count = count($plugin_files);
for($i = 0; $i < $count; $i++)
{
include($plugin_files[$i]);
}
$ret = array();
foreach(get_declared_classes() as $class)
{
if(is_subclass_of($class, 'SecurePlugin'))
{
$ret[] = new $class();
}
}
return $ret;
}
public function addPluginLinks($count, $plugins)
{
$secure_menu = array();
for($i = 0; $i < $count; $i++)
{
$ret = $plugins[$i]->get_secure_menu_entries($this, $this->user);
if($ret !== false)
{
$secure_menu = array_merge($secure_menu, $ret);
}
}
$this->addLink('Secure', $this->secure_root, $secure_menu);
}
}
class SecurePage extends \Flipside\Http\WebPage
{
use SecureWebPage;
public $secure_root;
protected $plugins;
protected $plugin_count;
function __construct($title)
{
parent::__construct($title, true);
$this->secure_root = $this->getSecureRoot();
$this->plugins = $this->loadAndGetPlugins();
$this->plugin_count = count($this->plugins);
$this->add_links();
$this->content['root'] = $this->secure_root;
$this->addTemplateDir(dirname(__FILE__).'/templates', 'Secure');
$this->setTemplateName('@Secure/main.html');
}
function add_links()
{
if($this->user !== false)
{
$this->addPluginLinks($this->plugin_count, $this->plugins);
}
}
function get_secure_child_entry_points()
{
$entry_points = '';
for($i = 0; $i < $this->plugin_count; $i++)
{
$ret = $this->plugins[$i]->get_plugin_entry_point();
if($ret !== false)
{
$entry_points .= '<li><a href="'.$ret['link'].'">'.$ret['name'].'</a></li>';
}
}
return $entry_points;
}
}
?>