-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmindetour.plugin.php
128 lines (106 loc) · 3.63 KB
/
admindetour.plugin.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
class admindetour extends Plugin {
public $mainmenus = array();
public function filter_rewrite_rules( $db_rules )
{
$db_rules[] = new RewriteRule ( array(
'name' => 'admin_dashboard',
'parse_regex' => '%^admin/dashboard/?$%i',
'build_str' => 'admin/dashboard',
'handler' => 'AdminHandler',
'action' => 'admin',
'priority' => 7,
'is_active' => 1,
'rule_class' => RewriteRule::RULE_CUSTOM,
'description' => 'Add "admin/dashboard" so Admin Detour can hijack "admin".'
) );
return $db_rules;
}
public function filter_login_redirect_dest( $login_dest, $user, $login_session )
{
if(isset($user->info->admindetour_real) && !empty($user->info->admindetour_real)) {
$redir = $user->info->admindetour_real;
return URL::get($redir['rule'], $redir['args']);
}
else return $login_dest;
}
public function filter_adminhandler_post_loadplugins_main_menu( $mainmenus )
{
$mainmenus['dashboard'] = array( 'url' => URL::get( 'admin', 'page=dashboard' ), 'title' => _t( 'View your user dashboard' ), 'text' => _t( 'Dashboard' ), 'hotkey' => 'D', 'selected' => false );
$this->mainmenus = $mainmenus;
return $mainmenus;
}
public function filter_plugin_config( $actions, $plugin_id )
{
if ( $plugin_id == $this->plugin_id() ) {
$actions[] = _t('Configure');
}
return $actions;
}
public function action_plugin_ui( $plugin_id, $action )
{
if ( $plugin_id == $this->plugin_id() ) {
switch ( $action ) {
case _t('Configure'):
$mainmenus = array();
foreach ($this->mainmenus as $mainmenu) {
$mainmenus[$mainmenu['url']] = $mainmenu['text'];
}
$ui = new FormUI( strtolower( get_class( $this ) ) );
$ui->append( 'select', 'mainmenus', 'user:admindetour_fake', _t('Select the wanted admin frontpage:') );
if(User::identify()->can('super_user')) {
$ui->append( 'checkbox', 'affect_all', 'null:null', _t('Force detour for all users'));
}
$ui->mainmenus->options = $mainmenus;
$ui->append( 'submit', 'save', _t('Save') );
$ui->on_success( array( $this, 'save_mainmenu' ) );
$ui->out();
break;
}
}
}
public function save_mainmenu($form)
{
$base_url = Site::get_url('habari', true);
$start_url = $form->mainmenus->value;
/* Strip out the base URL from the requested URL */
/* but only if the base URL isn't / */
if ( '/' != $base_url) {
$start_url = str_replace($base_url, '', $start_url);
}
/* Trim off any leading or trailing slashes */
$start_url = trim($start_url, '/');
/* Remove the querystring from the URL */
if ( strpos($start_url, '?') !== FALSE ) {
list($start_url, $query_string)= explode('?', $start_url);
}
/* Allow plugins to rewrite the stub before it's passed through the rules */
$start_url = Plugins::filter('rewrite_request', $start_url);
$stub = $start_url;
/* Grab the URL filtering rules from DB */
$matched_rule = URL::parse($stub);
if ($matched_rule === FALSE) {
print 'error, cant find rule';
// error!!!!
}
/* Return $_GET values to their proper place */
$args = array();
if( !empty($query_string) ) {
parse_str($query_string, $args);
}
$rule = $matched_rule->name;
$args = array_merge($matched_rule->named_arg_values, $args);
if(User::identify()->can('super_user') && $form->affect_all->value == true) {
foreach(Users::get_all() as $user) {
$user->info->admindetour_real = array( 'rule' => $rule, 'args' => $args );
$user->update();
}
}
else {
User::identify()->info->admindetour_real = array( 'rule' => $rule, 'args' => $args );
}
$_POST[$form->mainmenus->field] = URL::get( $rule, $args );
$form->save();
}
}
?>