-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathadmin.php
299 lines (258 loc) · 8.67 KB
/
admin.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
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
<?php
class UserOnline_Admin_Integration extends scbAdminPage {
function setup() {
$this->textdomain = 'wp-useronline';
$this->args = array(
'page_title' => __( 'Users Online Now', $this->textdomain ),
'menu_title' => __( 'WP-UserOnline', $this->textdomain ),
'page_slug' => 'useronline',
'parent' => 'index.php',
'action_link' => false,
'capability' => 'list_users',
);
add_action( 'rightnow_end', array( $this, 'rightnow' ) );
}
function rightnow() {
if ( !current_user_can( 'manage_options' ) )
return;
$total_users = get_users_online_count();
$str = _n(
"There is <strong><a href='%s'>%s user</a></strong> online now.",
"There are a total of <strong><a href='%s'>%s users</a></strong> online now.",
$total_users, 'wp-useronline'
);
$out = sprintf( $str, add_query_arg( 'page', $this->args['page_slug'], admin_url( 'index.php' ) ), number_format_i18n( $total_users ) );
$out .= '<br>';
if ( $tmp = get_users_browsing_site() )
$out .= $tmp . '<br>';
$out .= UserOnline_Template::format_most_users();
echo html( 'p', $out );
}
function page_content() {
echo users_online_page();
}
}
class UserOnline_Options extends scbAdminPage {
public function setup() {
$this->textdomain = 'wp-useronline';
$this->args = array(
'page_title' => __( 'UserOnline Options', $this->textdomain ),
'menu_title' => __( 'UserOnline', $this->textdomain ),
'page_slug' => 'useronline-settings',
);
$this->option_name = 'useronline';
}
public function validate( $options, $old_data = array() ) {
$options['timeout'] = isset( $options['timeout'] ) ? absint( $options['timeout'] ) : 0;
$options['url'] = ! empty( $options['url'] ) ? esc_url_raw( trim( $options['url'] ) ) : '';
$options['names'] = ! empty( $options['names'] ) ? (int) $options['names'] : 0;
foreach ( $options['naming'] as $key => $template ) {
$options['naming'][$key] = wp_kses_post( trim( $template ) );
}
foreach ( $options['templates'] as $key => $template ) {
if ( is_array( $template ) ) {
$options['templates'][$key]['text'] = wp_kses_post( trim( $template['text'] ) );
if ( ! empty( $template['separators'] ) && is_array( $template['separators'] ) ) {
foreach( $template['separators'] as $seperator_key => $seperator_value ) {
$options['templates'][$key]['separators'][$seperator_key] = wp_kses_post( trim( $seperator_value ) );
}
}
} else {
$options['templates'][$key] = wp_kses_post( trim( $template ) );
}
}
return $options;
}
public function page_head() {
?>
<style type="text/css">
.form-table td {vertical-align: top}
.form-table .form-table {margin-top: 0}
.form-table .form-table th, .form-table .form-table td {padding: 0}
.form-table textarea {width: 100%; height: 150px}
</style>
<script type="text/javascript">
function useronline_default_naming() {
jQuery( "#current_naming" ).html( jQuery( "#default_naming" ).html() );
return false;
}
function useronline_default_template( template ) {
jQuery( '#current_template_' + template ).html( jQuery( '#default_template_' + template ).html() );
return false;
}
</script>
<?php
}
public function page_content() {
$options = $this->options->get();
$defaults = $this->options->get_defaults();
?>
<form method="post" action="">
<?php wp_nonce_field( $this->nonce ); ?>
<table class="form-table">
<?php
$rows = array(
array(
'title' => __( 'Time Out', 'wp-useronline' ),
'type' => 'text',
'name' => 'timeout',
'desc' => '<br />' . __( 'How long until it will remove the user from the database (in seconds).', 'wp-useronline' ),
'extra' => 'size="4"'
),
array(
'title' => __( 'UserOnline URL', 'wp-useronline' ),
'type' => 'text',
'name' => 'url',
'desc' => '<br />' . __( 'URL To UserOnline Page<br />Example: http://www.yoursite.com/useronline/<br />Example: http://www.yoursite.com/?page_id=2', 'wp-useronline' ),
),
array(
'title' => __( 'Link user names?', 'wp-useronline' ),
'type' => 'radio',
'name' => 'names',
'choices' => array( 1 => __( 'Yes', 'wp-useronline' ), 0 => __( 'No', 'wp-useronline' ) ),
'desc' => '<br />' . __( 'Link user names to their author page', 'wp-useronline' )
),
);
foreach ( $rows as $row ) {
echo $this->table_row( $row );
}
?>
<tbody id="default_naming" style="display:none">
<?php $this->naming_table( $defaults ); ?>
</tbody>
<tbody id="current_naming">
<?php $this->naming_table( $options ); ?>
</tbody>
</table>
<h3><?php _e( 'Useronline Templates', 'wp-useronline' ); ?></h3>
<table class="form-table">
<tbody id="default_template_useronline" style="display:none">
<?php $this->useronline_template_table( $defaults ); ?>
</tbody>
<tbody id="current_template_useronline">
<?php $this->useronline_template_table( $options ); ?>
</tbody>
<?php
$templates = array(
'browsingsite' => __( 'User(s) Browsing Site:', 'wp-useronline' ),
'browsingpage' => __( 'User(s) Browsing Page:', 'wp-useronline' ),
);
foreach ( $templates as $name => $title ) { ?>
<tbody id="default_template_<?php echo $name; ?>" style="display:none">
<?php $this->template_table( $title, $name, $defaults ); ?>
</tbody>
<tbody id="current_template_<?php echo $name; ?>">
<?php $this->template_table( $title, $name, $options ); ?>
</tbody>
<?php } ?>
</table>
<p class="submit">
<input type="submit" name="action" class="button" value="<?php _e( 'Save Changes', 'wp-useronline' ); ?>" />
</p>
</form>
<?php
}
private function naming_table( $data ) {
?>
<tr>
<td width="30%">
<strong><?php _e( 'Naming Conventions:', 'wp-useronline' ); ?></strong><br /><br />
<?php _e( 'Allowed Variables:', 'wp-useronline' ); ?><br />
- %COUNT%<br /><br />
<input type="button" value="<?php _e( 'Restore Defaults', 'wp-useronline' ); ?>" onclick="useronline_default_naming();" class="button" />
</td>
<td>
<table class="form-table">
<thead>
<tr>
<th><?php _e( 'Singular Form', 'wp-useronline' ); ?></th>
<th><?php _e( 'Plural Form', 'wp-useronline' ); ?></th>
</tr>
</thead>
<tbody>
<?php
foreach ( array( 'user', 'member', 'guest', 'bot' ) as $tmp ) {
echo "\n<tr>\n";
foreach ( array( $tmp, $tmp . 's' ) as $type ) {
echo $this->input( array(
'type' => 'text',
'name' => array( 'naming', $type ),
'extra' => 'size="30"',
'desc' => html( 'td', $type )
), $data );
}
echo "\n</tr>\n";
}
?>
</tbody>
</table>
<br />
</td>
</tr>
<?php
}
private function useronline_template_table( $data ) {
?>
<tr>
<td width="30%">
<strong><?php _e( 'User(s) Online:', 'wp-useronline' ); ?></strong><br /><br />
<?php _e( 'Allowed Variables:', 'wp-useronline' ); ?><br />
- %USERS%<br />
- %PAGE_URL%<br />
- %MOSTONLINE_COUNT%<br />
- %MOSTONLINE_DATE%<br /><br />
<input type="button" value="<?php _e( 'Restore Default Template', 'wp-useronline' ); ?>" onclick="useronline_default_template( 'useronline' );" class="button" />
</td>
<td>
<?php echo $this->input( array(
'type' => 'textarea',
'name' => array( 'templates', 'useronline' ),
), $data ); ?>
</td>
</tr>
<?php
}
private function template_table( $title, $option, $data ) {
?>
<tr>
<td width="30%">
<strong><?php echo $title; ?></strong><br /><br />
<?php _e( 'Allowed Variables:', 'wp-useronline' ); ?><br />
- %USERS%<br />
- %MEMBERS%<br />
- %MEMBER_NAMES%<br />
- %GUESTS_SEPARATOR%<br />
- %GUESTS%<br />
- %BOTS_SEPARATOR%<br />
- %BOTS%<br /><br />
<input type="button" value="<?php _e( 'Restore Default Template', 'wp-useronline' ); ?>" onclick="useronline_default_template( '<?php echo $option; ?>' );" class="button" />
</td>
<td>
<table class="form-table">
<thead>
<tr>
<th><?php _e( 'Member Names Separator', 'wp-useronline' ); ?></th>
<th><?php _e( 'Guests Separator', 'wp-useronline' ); ?></th>
<th><?php _e( 'Bots Separator', 'wp-useronline' ); ?></th>
</tr>
</thead>
<tr>
<?php foreach ( array_keys( $this->options->templates[$option]['separators'] ) as $type ) {
echo html( 'td', $this->input( array(
'type' => 'text',
'name' => array( 'templates', $option, 'separators', $type ),
'extra' => "size='15'",
), $data ) );
} ?>
</tr>
</table>
<br />
<?php echo $this->input( array(
'type' => 'textarea',
'name' => array( 'templates', $option, 'text' )
), $data ); ?>
</td>
</tr>
<?php
}
}