view.php
13.8 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<?php
/**
* View class to output any HTML used at User Role Editor
*
* @package User-Role-Editor
* @subpackage Admin
* @author Vladimir Garagulya <support@role-editor.com>
* @copyright Copyright (c) 2010 - 2016, Vladimir Garagulya
**/
class URE_View {
protected $lib = null;
protected $editor = null;
public function __construct() {
$this->lib = URE_Lib::get_instance();
$this->editor = URE_Editor::get_instance();
}
// end of __construct()
public function display() {}
public function toolbar() {}
/**
* display opening part of the HTML box with title and CSS style
*
* @param string $title
* @param string $style
*/
public function display_box_start($title, $style = '') {
?>
<div class="postbox" style="float: left; <?php echo $style; ?>">
<h3 style="cursor:default;"><span><?php echo $title ?></span></h3>
<div class="inside">
<?php
}
// end of display_box_start()
/**
* close HTML box opened by display_box_start() call
*/
public function display_box_end() {
?>
</div>
</div>
<?php
}
// end of display_box_end()
public function show_caps_groups() {
$groups = URE_Capabilities_Groups_Manager::get_instance();
$groups_list = $groups->get_groups_tree();
$output = '<ul id="ure_caps_groups_list">'. PHP_EOL;
foreach($groups_list as $group_id=>$group) {
if ($group_id=='all') {
$spacer = '';
$subgroup = '';
} else {
$spacer = 'style="padding-left: '. 15*$group['level'] .'px"';
$subgroup = '- ';
}
$output .= '<li id="ure_caps_group_'. $group_id .'" '. $spacer .'>' .
$subgroup . $group['caption'] .'</li>'. PHP_EOL;
}
$output .= '</ul>'. PHP_EOL;
echo $output;
}
// end of show_caps_groups()
private function deprecated_show_and_color($cap_id, $builtin_wp_caps, &$label_style, &$hidden_class) {
if (isset($builtin_wp_caps[$cap_id])) {
if (in_array('deprecated', $builtin_wp_caps[$cap_id])) {
$show_deprecated_caps = $this->editor->get('show_deprecated_caps');
if (!$show_deprecated_caps) {
$hidden_class = 'hidden';
}
$label_style = 'style="color:#BBBBBB;"';
}
}
}
// end of deprecated_show_and_color()
private function blocked_for_single_admin_style($cap_id, &$label_style) {
$blocked = false;
$multisite = $this->lib->get('multisite');
if ($multisite && $this->editor->block_cap_for_single_admin($cap_id, true)) {
if ($this->lib->is_super_admin()) {
if (!is_network_admin()) {
$label_style = 'style="color: red;"';
}
} else {
$blocked = true;
}
}
return $blocked;
}
// end of blocked_for_single_admin_style()
// Get full capabilities list and exclude Visual Composer capabilities from it
// Do not take VC capabilities into account as VC stores not boolean values with them
protected function get_full_capabilities() {
$full_caps = $this->editor->get('full_capabilities');
foreach($full_caps as $key=>$capability) {
if (strpos($key, 'vc_access_rules_')!==false) {
unset($full_caps[$key]);
}
}
return $full_caps;
}
// end of get_full_capabilities()
/*
* Output HTML-code for capabilities list
* Used build output for response to AJAX request
* @param boolean $for_role - if true, it is role capabilities list, else - user specific capabilities list
* @param boolean $edit_mode - if false, capabilities checkboxes are shown as disable - readonly mode
*/
public function _show_capabilities( $for_role = true, $edit_mode=true ) {
$onclick_for_admin = '';
$multisite = $this->lib->get( 'multisite' );
$current_role = $this->editor->get( 'current_role' );
$user_to_edit = $this->editor->get( 'user_to_edit' );
$roles = $this->editor->get( 'roles' );
$full_capabilities = $this->get_full_capabilities();
$built_in_wp_caps = $this->lib->get_built_in_wp_caps();
$caps_readable = $this->editor->get( 'caps_readable' );
$caps_groups_manager = URE_Capabilities_Groups_Manager::get_instance();
$key_capability = URE_Own_Capabilities::get_key_capability();
$user_is_ure_admin = current_user_can( $key_capability );
$ure_caps = URE_Own_Capabilities::get_caps();
$output = '';
foreach ($full_capabilities as $capability) {
$cap_id = $capability['inner'];
if (!$user_is_ure_admin) {
if (isset($ure_caps[$cap_id]) ||
($multisite && $cap_id=='manage_network_plugins')) {
// exclude URE caps if user does not have full access to URE
continue;
}
}
$label_style = '';
$hidden_class = '';
$this->deprecated_show_and_color($cap_id, $built_in_wp_caps, $label_style, $hidden_class);
$blocked = $this->blocked_for_single_admin_style($cap_id, $label_style);
$classes = array('ure-cap-div');
if ($blocked) {
$classes[] = 'blocked';
$hidden_class = 'hidden';
}
if ($hidden_class) {
$classes[] = $hidden_class;
}
$cap_groups = $caps_groups_manager->get_cap_groups($cap_id, $built_in_wp_caps);
$classes = ure_array_merge( $classes, $cap_groups );
$checked = '';
$disabled = '';
if ($for_role) {
if (isset($roles[$current_role]['capabilities'][$cap_id]) &&
!empty($roles[$current_role]['capabilities'][$cap_id])) {
$checked = 'checked="checked"';
}
} else {
if (empty($edit_mode)) {
$disabled = 'disabled="disabled"';
} else {
$disabled = '';
}
if ($this->editor->user_can($cap_id)) {
$checked = 'checked="checked"';
if (!isset($user_to_edit->caps[$cap_id])) {
$disabled = 'disabled="disabled"';
}
}
}
$class = 'class="' . implode(' ', $classes) .'"';
$cap_id_esc = URE_Capability::escape($cap_id);
$cap_html = '<div id="ure_cap_div_'. $cap_id_esc .'" '. $class .'><input type="checkbox" name="' . $cap_id_esc . '" id="' .
$cap_id_esc . '" value="' . $cap_id .'" '. $checked . ' ' . $disabled . ' class="ure-cap-cb">';
if ($caps_readable) {
$cap_ind = 'human';
$cap_ind_alt = 'inner';
} else {
$cap_ind = 'inner';
$cap_ind_alt = 'human';
}
$cap_html .= '<label for="' . $cap_id_esc . '" title="' . $capability[$cap_ind_alt] . '" ' . $label_style . ' > ' .
$capability[$cap_ind] . '</label> </div>';
$output .= $cap_html;
}
return $output;
}
// end of _show_capabilities()
/**
* Output HTML-code for capabilities list
* Used to built full page output for usual HTTP request
* @param boolean $for_role - if true, it is role capabilities list, else - user specific capabilities list
* @param boolean $edit_mode - if false, capabilities checkboxes are shown as disable - readonly mode
*/
public function show_capabilities( $for_role = true, $edit_mode=true ) {
$output = '<div id="ure_caps_list_container">'
. '<div id="ure_caps_list">';
$output .= $this->_show_capabilities( $for_role, $edit_mode );
$output .= '</div></div>' ;
echo $output;
}
// end of show_capabilities()
// content of User Role Editor Pro advertisement slot - for direct call
public function advertise_pro() {
?>
<div id="ure_pro_advertisement" style="clear:left;display:block; float: left;">
<a href="https://www.role-editor.com?utm_source=UserRoleEditor&utm_medium=banner&utm_campaign=Plugins " target="_new" >
<?php
$hide_pro_banner = $this->lib->get_option('ure_hide_pro_banner', 0);
if ($hide_pro_banner) {
echo 'User Role Editor Pro: extended functionality, no advertisement - from $29.</a>';
} else {
?>
<img src="<?php echo URE_PLUGIN_URL; ?>images/user-role-editor-pro-728x90.jpg" alt="User Role Editor Pro"
title="More functionality and premium support with Pro version of User Role Editor."/>
</a><br />
<label for="ure_hide_pro_banner">
<input type="checkbox" name="ure_hide_pro_banner" id="ure_hide_pro_banner" onclick="ure_main.hide_pro_banner();"/> Thanks, hide this banner.
</label>
<?php
}
?>
</div>
<?php
}
// end of advertise_pro_version()
public function advertise_commercials() {
require_once(URE_PLUGIN_DIR . 'includes/classes/advertisement.php');
$this->advert = new URE_Advertisement();
$this->advert->display();
}
// end of advertisement()
public static function output_confirmation_dialog() {
?>
<div id="ure_confirmation_dialog" class="ure-modal-dialog">
<div id="ure_cd_html" style="padding:10px;"></div>
</div>
<?php
}
// end of output_confirmation_dialog()
public static function output_task_status_div() {
?>
<div id="ure_task_status" style="display:none;position:absolute;top:10px;right:10px;padding:10px;background-color:#000000;color:#ffffff;">
<img src="<?php echo URE_PLUGIN_URL .'images/ajax-loader.gif';?>" width="16" height="16"/> <?php esc_html_e('Working...','user-role-editor');?>
</div>
<?php
}
// end of output task_status_div()
private function show_select_all() {
$multisite = $this->lib->get('multisite');
$current_role = $this->editor->get('current_role');
$show = true;
if ($multisite) {
if ($current_role=='administrator' && !$this->lib->is_super_admin()) {
$show = false;
}
} elseif ($current_role=='administrator') {
$show = false;
}
return $show;
}
// end of show_select_all()
public function display_caps($for_role = true, $edit_mode=true) {
$caps_columns_quant = $this->editor->get('caps_columns_quant');
?>
<table id="ure_caps_container" cellpadding="0" cellspacing="0">
<tr>
<td id="ure_caps_groups_title"><span style="font-weight: bold;"><?php esc_html_e('Group', 'user-role-editor');?></span> (<?php esc_html_e('Total', 'user-role-editor');?>/<?php esc_html_e('Granted', 'user-role-editor');?>)</td>
<td id="ure_caps_select">
<div class="ure-table">
<?php
if ($this->show_select_all()) {
?>
<div class="ure-table-cell">
<input type="checkbox" id="ure_select_all_caps" name="ure_select_all_caps" value="ure_select_all_caps"/>
</div>
<?php
}
?>
<div class="ure-table-cell ure-caps-option nowrap">
<?php esc_html_e('Quick filter:', 'user-role-editor'); ?>
<input type="text" id="quick_filter" name="quick_filter" value="" size="10" onkeyup="ure_main.filter_capabilities(this.value);" />
<input type="checkbox" id="granted_only" name="granted_only" />
<label for="granted_only"><?php esc_html_e('Granted Only', 'user-role-editor'); ?></label>
</div>
<div class="ure-table-cell ure-caps-option nowrap">
<?php esc_html_e('Columns:', 'user-role-editor');?>
<select id="caps_columns_quant" name="caps_columns_quant" onchange="ure_main.change_caps_columns_quant();">
<option value="1" <?php selected(1, $caps_columns_quant);?> >1</option>
<option value="2" <?php selected(2, $caps_columns_quant);?> >2</option>
<option value="3" <?php selected(3, $caps_columns_quant);?> >3</option>
</select>
</div>
</div>
</td>
<td id="ure_toolbar_title"> </td>
</tr>
<tr>
<td id="ure_caps_groups_td" class="ure-caps-cell">
<?php $this->show_caps_groups(); ?>
</td>
<td id="ure_caps_td" class="ure-caps-cell">
<?php $this->show_capabilities($for_role, $edit_mode); ?>
</td>
<td id="ure_toolbar_td" class="ure-caps-cell">
<?php $this->toolbar(); ?>
</td>
</tr>
</table>
<?php
}
// end of display_caps()
}
// end of class URE_View