WP-UserOnline - Version 2.80

Version Description

  • don't show url and referral links for users in the admin area
  • smarter detection via ajax requests
  • fix SQL errors
Download this release

Release Info

Developer scribu
Plugin Icon WP-UserOnline
Version 2.80
Comparing to
See all releases

Code changes from version 2.73 to 2.80

admin.php CHANGED
@@ -6,15 +6,15 @@ class UserOnline_Admin_Integration extends scbAdminPage {
6
  $this->textdomain = 'wp-useronline';
7
 
8
  $this->args = array(
9
- 'page_title' => __('Users Online Now', $this->textdomain),
10
- 'menu_title' => __('WP-UserOnline', $this->textdomain),
11
  'page_slug' => 'useronline',
12
  'parent' => 'index.php',
13
  'capability' => 'read',
14
  'action_link' => false,
15
  );
16
 
17
- add_action('rightnow_end', array($this, 'rightnow'));
18
  }
19
 
20
  function rightnow() {
@@ -26,19 +26,19 @@ class UserOnline_Admin_Integration extends scbAdminPage {
26
  $total_users, 'wp-useronline'
27
  );
28
 
29
- $out = sprintf($str, add_query_arg('page', $this->args['page_slug'], admin_url('index.php')), number_format_i18n($total_users));
30
  $out .= '<br>';
31
-
32
  if ( $tmp = get_users_browsing_site() )
33
  $out .= $tmp . '<br>';
34
 
35
  $out .= UserOnline_Template::format_most_users();
36
 
37
- echo html('p', $out);
38
  }
39
 
40
  function page_content() {
41
- echo users_online_page();
42
  }
43
  }
44
 
@@ -49,24 +49,24 @@ class UserOnline_Options extends scbAdminPage {
49
  $this->textdomain = 'wp-useronline';
50
 
51
  $this->args = array(
52
- 'page_title' => __('UserOnline Options', $this->textdomain),
53
- 'menu_title' => __('UserOnline', $this->textdomain),
54
  'page_slug' => 'useronline-settings',
55
  );
56
-
57
  $this->option_name = 'useronline';
58
  }
59
 
60
- function validate($options) {
61
- $options['timeout'] = absint($options['timeout']);
62
- $options['url'] = trim($options['url']);
63
  $options['names'] = (bool) $options['names'];
64
 
65
  foreach ( $options['templates'] as $key => $template )
66
- if ( is_array($template) )
67
- $options['templates'][$key]['text'] = trim($template['text']);
68
  else
69
- $options['templates'][$key] = trim($template);
70
 
71
  return $options;
72
  }
@@ -82,13 +82,13 @@ class UserOnline_Options extends scbAdminPage {
82
 
83
  <script type="text/javascript">
84
  function useronline_default_naming() {
85
- jQuery("#current_naming").html(jQuery("#default_naming").html());
86
 
87
  return false;
88
  }
89
 
90
- function useronline_default_template(template) {
91
- jQuery('#current_template_' + template).html(jQuery('#default_template_' + template).html());
92
 
93
  return false;
94
  }
@@ -101,36 +101,36 @@ class UserOnline_Options extends scbAdminPage {
101
  $defaults = $this->options->get_defaults();
102
  ?>
103
  <form method="post" action="options.php">
104
- <?php settings_fields($this->option_name); ?>
105
 
106
  <table class="form-table">
107
  <?php
108
  $rows = array(
109
  array(
110
- 'title' => __('Time Out', 'wp-useronline'),
111
  'type' => 'text',
112
  'name_tree' => 'timeout',
113
- 'desc' => '<br />' . __('How long until it will remove the user from the database (In seconds).', 'wp-useronline'),
114
  'extra' => 'size="4"'
115
  ),
116
 
117
  array(
118
- 'title' => __('UserOnline URL', 'wp-useronline'),
119
  'type' => 'text',
120
  'name_tree' => 'url',
121
- 'desc' => '<br />' . __('URL To UserOnline Page<br />Example: http://www.yoursite.com/useronline/<br />Example: http://www.yoursite.com/?page_id=2', 'wp-useronline'),
122
  ),
123
 
124
  array(
125
- 'title' => __('User Names', 'wp-useronline'),
126
  'type' => 'checkbox',
127
  'name_tree' => 'names',
128
- 'desc' => __('Link user names to their author page', 'wp-useronline'),
129
  ),
130
  );
131
 
132
  foreach ( $rows as $row )
133
- echo $this->table_row($row);
134
  ?>
135
  <tbody id="default_naming" style="display:none">
136
  <?php $this->formdata = $defaults; $this->naming_table(); ?>
@@ -142,7 +142,7 @@ class UserOnline_Options extends scbAdminPage {
142
 
143
  </table>
144
 
145
- <h3><?php _e('Useronline Templates', 'wp-useronline'); ?></h3>
146
  <table class="form-table">
147
  <tbody id="default_template_useronline" style="display:none">
148
  <?php $this->formdata = $defaults; $this->useronline_template_table(); ?>
@@ -154,21 +154,21 @@ class UserOnline_Options extends scbAdminPage {
154
 
155
  <?php
156
  $templates = array(
157
- 'browsingsite' => __('User(s) Browsing Site:', 'wp-useronline'),
158
- 'browsingpage' => __('User(s) Browsing Page:', 'wp-useronline'),
159
  );
160
  foreach ( $templates as $name => $title ) { ?>
161
  <tbody id="default_template_<?php echo $name; ?>" style="display:none">
162
- <?php $this->formdata = $defaults; $this->template_table($title, $name); ?>
163
  </tbody>
164
 
165
  <tbody id="current_template_<?php echo $name; ?>">
166
- <?php $this->formdata = $options; $this->template_table($title, $name); ?>
167
  </tbody>
168
  <?php } ?>
169
  </table>
170
  <p class="submit">
171
- <input type="submit" name="Submit" class="button" value="<?php _e('Save Changes', 'wp-useronline'); ?>" />
172
  </p>
173
  </form>
174
  <?php
@@ -178,30 +178,30 @@ class UserOnline_Options extends scbAdminPage {
178
  ?>
179
  <tr>
180
  <td width="30%">
181
- <strong><?php _e('Naming Conventions:', 'wp-useronline'); ?></strong><br /><br />
182
- <?php _e('Allowed Variables:', 'wp-useronline'); ?><br />
183
  - %COUNT%<br /><br />
184
- <input type="button" value="<?php _e('Restore Defaults', 'wp-useronline'); ?>" onclick="useronline_default_naming();" class="button" />
185
  </td>
186
  <td>
187
  <table class="form-table">
188
  <thead>
189
  <tr>
190
- <th><?php _e('Singular Form', 'wp-useronline'); ?></th>
191
- <th><?php _e('Plural Form', 'wp-useronline'); ?></th>
192
  </tr>
193
  </thead>
194
  <tbody>
195
- <?php
196
- foreach ( array('user', 'member', 'guest', 'bot') as $tmp ) {
197
  echo "\n<tr>\n";
198
- foreach ( array($tmp, $tmp . 's') as $type ) {
199
- echo $this->input(array(
200
  'type' => 'text',
201
- 'name_tree' => array('naming', $type),
202
  'extra' => 'size="30"',
203
- 'desc' => html('td', '%input%')
204
- ));
205
  }
206
  echo "\n</tr>\n";
207
  }
@@ -218,30 +218,30 @@ class UserOnline_Options extends scbAdminPage {
218
  ?>
219
  <tr>
220
  <td width="30%">
221
- <strong><?php _e('User(s) Online:', 'wp-useronline'); ?></strong><br /><br />
222
- <?php _e('Allowed Variables:', 'wp-useronline'); ?><br />
223
  - %USERS%<br />
224
  - %PAGE_URL%<br />
225
  - %MOSTONLINE_COUNT%<br />
226
  - %MOSTONLINE_DATE%<br /><br />
227
- <input type="button" value="<?php _e('Restore Default Template', 'wp-useronline'); ?>" onclick="useronline_default_template('useronline');" class="button" />
228
  </td>
229
  <td>
230
- <?php echo $this->input(array(
231
  'type' => 'textarea',
232
- 'name_tree' => array('templates', 'useronline'),
233
- )); ?>
234
  </td>
235
  </tr>
236
  <?php
237
  }
238
 
239
- private function template_table($title, $option) {
240
  ?>
241
  <tr>
242
  <td width="30%">
243
  <strong><?php echo $title; ?></strong><br /><br />
244
- <?php _e('Allowed Variables:', 'wp-useronline'); ?><br />
245
  - %USERS%<br />
246
  - %MEMBERS%<br />
247
  - %MEMBER_NAMES%<br />
@@ -249,32 +249,32 @@ class UserOnline_Options extends scbAdminPage {
249
  - %GUESTS%<br />
250
  - %BOTS_SEPERATOR%<br />
251
  - %BOTS%<br /><br />
252
- <input type="button" value="<?php _e('Restore Default Template', 'wp-useronline'); ?>" onclick="useronline_default_template('<?php echo $option; ?>');" class="button" />
253
  </td>
254
  <td>
255
  <table class="form-table">
256
  <thead>
257
  <tr>
258
- <th><?php _e('Member Names Separator', 'wp-useronline'); ?></th>
259
- <th><?php _e('Guests Separator', 'wp-useronline'); ?></th>
260
- <th><?php _e('Bots Separator', 'wp-useronline'); ?></th>
261
  </tr>
262
  </thead>
263
  <tr>
264
- <?php foreach ( array_keys($this->options->templates[$option]['separators']) as $type ) {
265
- echo html('td', $this->input(array(
266
  'type' => 'text',
267
- 'name_tree' => array('templates', $option, 'separators', $type),
268
  'extra' => "size='15'",
269
- )));
270
  } ?>
271
  </tr>
272
  </table>
273
  <br />
274
- <?php echo $this->input(array(
275
  'type' => 'textarea',
276
- 'name_tree' => array('templates', $option, 'text')
277
- )); ?>
278
  </td>
279
  </tr>
280
  <?php
6
  $this->textdomain = 'wp-useronline';
7
 
8
  $this->args = array(
9
+ 'page_title' => __( 'Users Online Now', $this->textdomain ),
10
+ 'menu_title' => __( 'WP-UserOnline', $this->textdomain ),
11
  'page_slug' => 'useronline',
12
  'parent' => 'index.php',
13
  'capability' => 'read',
14
  'action_link' => false,
15
  );
16
 
17
+ add_action( 'rightnow_end', array( $this, 'rightnow' ) );
18
  }
19
 
20
  function rightnow() {
26
  $total_users, 'wp-useronline'
27
  );
28
 
29
+ $out = sprintf( $str, add_query_arg( 'page', $this->args['page_slug'], admin_url( 'index.php' ) ), number_format_i18n( $total_users ) );
30
  $out .= '<br>';
31
+
32
  if ( $tmp = get_users_browsing_site() )
33
  $out .= $tmp . '<br>';
34
 
35
  $out .= UserOnline_Template::format_most_users();
36
 
37
+ echo html( 'p', $out );
38
  }
39
 
40
  function page_content() {
41
+ echo users_online_page();
42
  }
43
  }
44
 
49
  $this->textdomain = 'wp-useronline';
50
 
51
  $this->args = array(
52
+ 'page_title' => __( 'UserOnline Options', $this->textdomain ),
53
+ 'menu_title' => __( 'UserOnline', $this->textdomain ),
54
  'page_slug' => 'useronline-settings',
55
  );
56
+
57
  $this->option_name = 'useronline';
58
  }
59
 
60
+ function validate( $options ) {
61
+ $options['timeout'] = absint( $options['timeout'] );
62
+ $options['url'] = trim( $options['url'] );
63
  $options['names'] = (bool) $options['names'];
64
 
65
  foreach ( $options['templates'] as $key => $template )
66
+ if ( is_array( $template ) )
67
+ $options['templates'][$key]['text'] = trim( $template['text'] );
68
  else
69
+ $options['templates'][$key] = trim( $template );
70
 
71
  return $options;
72
  }
82
 
83
  <script type="text/javascript">
84
  function useronline_default_naming() {
85
+ jQuery( "#current_naming" ).html( jQuery( "#default_naming" ).html() );
86
 
87
  return false;
88
  }
89
 
90
+ function useronline_default_template( template ) {
91
+ jQuery( '#current_template_' + template ).html( jQuery( '#default_template_' + template ).html() );
92
 
93
  return false;
94
  }
101
  $defaults = $this->options->get_defaults();
102
  ?>
103
  <form method="post" action="options.php">
104
+ <?php settings_fields( $this->option_name ); ?>
105
 
106
  <table class="form-table">
107
  <?php
108
  $rows = array(
109
  array(
110
+ 'title' => __( 'Time Out', 'wp-useronline' ),
111
  'type' => 'text',
112
  'name_tree' => 'timeout',
113
+ 'desc' => '<br />' . __( 'How long until it will remove the user from the database ( In seconds ).', 'wp-useronline' ),
114
  'extra' => 'size="4"'
115
  ),
116
 
117
  array(
118
+ 'title' => __( 'UserOnline URL', 'wp-useronline' ),
119
  'type' => 'text',
120
  'name_tree' => 'url',
121
+ 'desc' => '<br />' . __( 'URL To UserOnline Page<br />Example: http://www.yoursite.com/useronline/<br />Example: http://www.yoursite.com/?page_id=2', 'wp-useronline' ),
122
  ),
123
 
124
  array(
125
+ 'title' => __( 'User Names', 'wp-useronline' ),
126
  'type' => 'checkbox',
127
  'name_tree' => 'names',
128
+ 'desc' => __( 'Link user names to their author page', 'wp-useronline' ),
129
  ),
130
  );
131
 
132
  foreach ( $rows as $row )
133
+ echo $this->table_row( $row );
134
  ?>
135
  <tbody id="default_naming" style="display:none">
136
  <?php $this->formdata = $defaults; $this->naming_table(); ?>
142
 
143
  </table>
144
 
145
+ <h3><?php _e( 'Useronline Templates', 'wp-useronline' ); ?></h3>
146
  <table class="form-table">
147
  <tbody id="default_template_useronline" style="display:none">
148
  <?php $this->formdata = $defaults; $this->useronline_template_table(); ?>
154
 
155
  <?php
156
  $templates = array(
157
+ 'browsingsite' => __( 'User(s) Browsing Site:', 'wp-useronline' ),
158
+ 'browsingpage' => __( 'User(s) Browsing Page:', 'wp-useronline' ),
159
  );
160
  foreach ( $templates as $name => $title ) { ?>
161
  <tbody id="default_template_<?php echo $name; ?>" style="display:none">
162
+ <?php $this->formdata = $defaults; $this->template_table( $title, $name ); ?>
163
  </tbody>
164
 
165
  <tbody id="current_template_<?php echo $name; ?>">
166
+ <?php $this->formdata = $options; $this->template_table( $title, $name ); ?>
167
  </tbody>
168
  <?php } ?>
169
  </table>
170
  <p class="submit">
171
+ <input type="submit" name="Submit" class="button" value="<?php _e( 'Save Changes', 'wp-useronline' ); ?>" />
172
  </p>
173
  </form>
174
  <?php
178
  ?>
179
  <tr>
180
  <td width="30%">
181
+ <strong><?php _e( 'Naming Conventions:', 'wp-useronline' ); ?></strong><br /><br />
182
+ <?php _e( 'Allowed Variables:', 'wp-useronline' ); ?><br />
183
  - %COUNT%<br /><br />
184
+ <input type="button" value="<?php _e( 'Restore Defaults', 'wp-useronline' ); ?>" onclick="useronline_default_naming();" class="button" />
185
  </td>
186
  <td>
187
  <table class="form-table">
188
  <thead>
189
  <tr>
190
+ <th><?php _e( 'Singular Form', 'wp-useronline' ); ?></th>
191
+ <th><?php _e( 'Plural Form', 'wp-useronline' ); ?></th>
192
  </tr>
193
  </thead>
194
  <tbody>
195
+ <?php
196
+ foreach ( array( 'user', 'member', 'guest', 'bot' ) as $tmp ) {
197
  echo "\n<tr>\n";
198
+ foreach ( array( $tmp, $tmp . 's' ) as $type ) {
199
+ echo $this->input( array(
200
  'type' => 'text',
201
+ 'name_tree' => array( 'naming', $type ),
202
  'extra' => 'size="30"',
203
+ 'desc' => html( 'td', '%input%' )
204
+ ) );
205
  }
206
  echo "\n</tr>\n";
207
  }
218
  ?>
219
  <tr>
220
  <td width="30%">
221
+ <strong><?php _e( 'User(s) Online:', 'wp-useronline' ); ?></strong><br /><br />
222
+ <?php _e( 'Allowed Variables:', 'wp-useronline' ); ?><br />
223
  - %USERS%<br />
224
  - %PAGE_URL%<br />
225
  - %MOSTONLINE_COUNT%<br />
226
  - %MOSTONLINE_DATE%<br /><br />
227
+ <input type="button" value="<?php _e( 'Restore Default Template', 'wp-useronline' ); ?>" onclick="useronline_default_template( 'useronline' );" class="button" />
228
  </td>
229
  <td>
230
+ <?php echo $this->input( array(
231
  'type' => 'textarea',
232
+ 'name_tree' => array( 'templates', 'useronline' ),
233
+ ) ); ?>
234
  </td>
235
  </tr>
236
  <?php
237
  }
238
 
239
+ private function template_table( $title, $option ) {
240
  ?>
241
  <tr>
242
  <td width="30%">
243
  <strong><?php echo $title; ?></strong><br /><br />
244
+ <?php _e( 'Allowed Variables:', 'wp-useronline' ); ?><br />
245
  - %USERS%<br />
246
  - %MEMBERS%<br />
247
  - %MEMBER_NAMES%<br />
249
  - %GUESTS%<br />
250
  - %BOTS_SEPERATOR%<br />
251
  - %BOTS%<br /><br />
252
+ <input type="button" value="<?php _e( 'Restore Default Template', 'wp-useronline' ); ?>" onclick="useronline_default_template( '<?php echo $option; ?>' );" class="button" />
253
  </td>
254
  <td>
255
  <table class="form-table">
256
  <thead>
257
  <tr>
258
+ <th><?php _e( 'Member Names Separator', 'wp-useronline' ); ?></th>
259
+ <th><?php _e( 'Guests Separator', 'wp-useronline' ); ?></th>
260
+ <th><?php _e( 'Bots Separator', 'wp-useronline' ); ?></th>
261
  </tr>
262
  </thead>
263
  <tr>
264
+ <?php foreach ( array_keys( $this->options->templates[$option]['separators'] ) as $type ) {
265
+ echo html( 'td', $this->input( array(
266
  'type' => 'text',
267
+ 'name_tree' => array( 'templates', $option, 'separators', $type ),
268
  'extra' => "size='15'",
269
+ ) ) );
270
  } ?>
271
  </tr>
272
  </table>
273
  <br />
274
+ <?php echo $this->input( array(
275
  'type' => 'textarea',
276
+ 'name_tree' => array( 'templates', $option, 'text' )
277
+ ) ); ?>
278
  </td>
279
  </tr>
280
  <?php
core.php ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class UserOnline_Core {
4
+
5
+ static $add_script = false;
6
+
7
+ static $options;
8
+ static $most;
9
+
10
+ private static $useronline;
11
+
12
+ function get_user_online_count() {
13
+ global $wpdb;
14
+
15
+ if ( is_null( self::$useronline ) )
16
+ self::$useronline = intval( $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->useronline" ) );
17
+
18
+ return self::$useronline;
19
+ }
20
+
21
+ function init( $options, $most ) {
22
+ self::$options = $options;
23
+ self::$most = $most;
24
+
25
+ add_action( 'plugins_loaded', array( __CLASS__, 'wp_stats_integration' ) );
26
+
27
+ add_action( 'admin_head', array( __CLASS__, 'record' ) );
28
+ add_action( 'wp_head', array( __CLASS__, 'record' ) );
29
+
30
+ add_action( 'wp_footer', array( __CLASS__, 'scripts' ) );
31
+
32
+ add_action( 'wp_ajax_useronline', array( __CLASS__, 'ajax' ) );
33
+ add_action( 'wp_ajax_nopriv_useronline', array( __CLASS__, 'ajax' ) );
34
+
35
+ add_shortcode( 'page_useronline', 'users_online_page' );
36
+
37
+ if ( self::$options->names )
38
+ add_filter( 'useronline_display_user', array( __CLASS__, 'linked_names' ), 10, 2 );
39
+ }
40
+
41
+ function linked_names( $name, $user ) {
42
+ if ( !$user->user_id )
43
+ return $name;
44
+
45
+ return html_link( get_author_posts_url( $user->user_id ), $name );
46
+ }
47
+
48
+ function scripts() {
49
+ if ( !self::$add_script )
50
+ return;
51
+
52
+ $js_dev = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.dev' : '';
53
+
54
+ wp_enqueue_script( 'wp-useronline', plugins_url( "useronline$js_dev.js", __FILE__ ), array( 'jquery' ), '2.80', true );
55
+ wp_localize_script( 'wp-useronline', 'useronlineL10n', array(
56
+ 'ajax_url' => admin_url( 'admin-ajax.php' ),
57
+ 'timeout' => self::$options->timeout * 1000
58
+ ) );
59
+
60
+ scbUtil::do_scripts('wp-useronline');
61
+ }
62
+
63
+ function record( $page_url = '', $page_title = '' ) {
64
+ global $wpdb;
65
+
66
+ if ( empty( $page_url ) )
67
+ $page_url = $_SERVER['REQUEST_URI'];
68
+
69
+ if ( empty( $page_title ) )
70
+ $page_title = self::get_title();
71
+
72
+ $referral = strip_tags( @$_SERVER['HTTP_REFERER'] );
73
+
74
+ $user_ip = self::get_ip();
75
+ $user_agent = $_SERVER['HTTP_USER_AGENT'];
76
+ $current_user = wp_get_current_user();
77
+
78
+ // Check For Bot
79
+ $bots = array( 'Google Bot' => 'googlebot', 'Google Bot' => 'google', 'MSN' => 'msnbot', 'Alex' => 'ia_archiver', 'Lycos' => 'lycos', 'Ask Jeeves' => 'jeeves', 'Altavista' => 'scooter', 'AllTheWeb' => 'fast-webcrawler', 'Inktomi' => 'slurp@inktomi', 'Turnitin.com' => 'turnitinbot', 'Technorati' => 'technorati', 'Yahoo' => 'yahoo', 'Findexa' => 'findexa', 'NextLinks' => 'findlinks', 'Gais' => 'gaisbo', 'WiseNut' => 'zyborg', 'WhoisSource' => 'surveybot', 'Bloglines' => 'bloglines', 'BlogSearch' => 'blogsearch', 'PubSub' => 'pubsub', 'Syndic8' => 'syndic8', 'RadioUserland' => 'userland', 'Gigabot' => 'gigabot', 'Become.com' => 'become.com', 'Baidu' => 'baidu', 'Yandex' => 'yandex', 'Amazon' => 'amazonaws.com' );
80
+
81
+ $bot_found = false;
82
+ foreach ( $bots as $name => $lookfor )
83
+ if ( stristr( $user_agent, $lookfor ) !== false ) {
84
+ $user_id = 0;
85
+ $user_name = $name;
86
+ $username = $lookfor;
87
+ $user_type = 'bot';
88
+ $bot_found = true;
89
+
90
+ break;
91
+ }
92
+
93
+ // If No Bot Is Found, Then We Check Members And Guests
94
+ if ( !$bot_found ) {
95
+ if ( $current_user->ID ) {
96
+ // Check For Member
97
+ $user_id = $current_user->ID;
98
+ $user_name = $current_user->display_name;
99
+ $user_type = 'member';
100
+ $where = $wpdb->prepare( "WHERE user_id = %d", $user_id );
101
+ } elseif ( !empty( $_COOKIE['comment_author_'.COOKIEHASH] ) ) {
102
+ // Check For Comment Author ( Guest )
103
+ $user_id = 0;
104
+ $user_name = trim( strip_tags( $_COOKIE['comment_author_'.COOKIEHASH] ) );
105
+ $user_type = 'guest';
106
+ } else {
107
+ // Check For Guest
108
+ $user_id = 0;
109
+ $user_name = __( 'Guest', 'wp-useronline' );
110
+ $user_type = 'guest';
111
+ }
112
+ }
113
+
114
+ // Purge table
115
+ $wpdb->query( $wpdb->prepare( "
116
+ DELETE FROM $wpdb->useronline
117
+ WHERE user_ip = %s
118
+ OR timestamp < DATE_SUB(CURRENT_TIMESTAMP, INTERVAL %d SECOND)
119
+ ", $user_ip, self::$options->timeout ) );
120
+
121
+ // Insert Users
122
+ $data = compact( 'user_type', 'user_id', 'user_name', 'user_ip', 'user_agent', 'page_title', 'page_url', 'referral' );
123
+ $data = stripslashes_deep( $data );
124
+ $insert_user = $wpdb->insert( $wpdb->useronline, $data );
125
+
126
+ // Count Users Online
127
+ self::$useronline = intval( $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->useronline" ) );
128
+
129
+ // Maybe Update Most User Online
130
+ if ( self::$useronline > self::$most->count )
131
+ self::$most->update( array(
132
+ 'count' => self::$useronline,
133
+ 'date' => current_time( 'timestamp' )
134
+ ) );
135
+ }
136
+
137
+ private function clear_table() {
138
+ global $wpdb;
139
+
140
+ $wpdb->query( "DELETE FROM $wpdb->useronline" );
141
+ }
142
+
143
+ function ajax() {
144
+ global $wpdb;
145
+
146
+ $mode = trim( $_POST['mode'] );
147
+
148
+ $page_title = strip_tags( $_POST['page_title'] );
149
+
150
+ $page_url = str_replace( get_bloginfo( 'url' ), '', $_POST['page_url'] );
151
+
152
+ if ( $page_url != $_POST['page_url'] )
153
+ self::record( $page_url, $page_title );
154
+
155
+ switch( $mode ) {
156
+ case 'count':
157
+ users_online();
158
+ break;
159
+ case 'browsing-site':
160
+ users_browsing_site();
161
+ break;
162
+ case 'browsing-page':
163
+ users_browsing_page($page_url);
164
+ break;
165
+ case 'details':
166
+ echo users_online_page();
167
+ break;
168
+ }
169
+
170
+ die;
171
+ }
172
+
173
+ function wp_stats_integration() {
174
+ if ( function_exists( 'stats_page' ) )
175
+ require_once dirname( __FILE__ ) . '/wp-stats.php';
176
+ }
177
+
178
+ private function get_title() {
179
+ if ( is_admin() && function_exists( 'get_admin_page_title' ) ) {
180
+ $page_title = ' &raquo; ' . __( 'Admin', 'wp-useronline' ) . ' &raquo; ' . get_admin_page_title();
181
+ } else {
182
+ $page_title = wp_title( '&raquo;', false );
183
+ if ( empty( $page_title ) )
184
+ $page_title = ' &raquo; ' . strip_tags( $_SERVER['REQUEST_URI'] );
185
+ elseif ( is_singular() )
186
+ $page_title = ' &raquo; ' . __( 'Archive', 'wp-useronline' ) . ' ' . $page_title;
187
+ }
188
+ $page_title = get_bloginfo( 'name' ) . $page_title;
189
+
190
+ return $page_title;
191
+ }
192
+
193
+ private function get_ip() {
194
+ if ( isset( $_SERVER["HTTP_X_FORWARDED_FOR"] ) )
195
+ $ip_address = $_SERVER["HTTP_X_FORWARDED_FOR"];
196
+ else
197
+ $ip_address = $_SERVER["REMOTE_ADDR"];
198
+
199
+ list( $ip_address ) = explode( ',', $ip_address );
200
+
201
+ return $ip_address;
202
+ }
203
+ }
204
+
deprecated.php CHANGED
@@ -1,31 +1,31 @@
1
  <?php
2
 
3
  function useronline_page() {
4
- _deprecated_function(__FUNCTION__, '2.70', 'users_online_page()');
5
 
6
  users_online_page();
7
  }
8
 
9
  function get_useronline() {
10
- _deprecated_function(__FUNCTION__, '2.70', 'users_online()');
11
 
12
  users_online();
13
  }
14
 
15
  function get_most_useronline() {
16
- _deprecated_function(__FUNCTION__, '2.70', 'get_most_users_online()');
17
 
18
  return get_most_users_online();
19
  }
20
 
21
  function get_most_useronline_date() {
22
- _deprecated_function(__FUNCTION__, '2.70', 'get_most_users_online()');
23
 
24
  return get_most_users_online_date();
25
  }
26
 
27
- function get_useronline_count($display = false) {
28
- _deprecated_function(__FUNCTION__, '2.70', 'users_online_count()');
29
 
30
  if ( !$display )
31
  return get_users_online_count();
1
  <?php
2
 
3
  function useronline_page() {
4
+ _deprecated_function( __FUNCTION__, '2.70', 'users_online_page()' );
5
 
6
  users_online_page();
7
  }
8
 
9
  function get_useronline() {
10
+ _deprecated_function( __FUNCTION__, '2.70', 'users_online()' );
11
 
12
  users_online();
13
  }
14
 
15
  function get_most_useronline() {
16
+ _deprecated_function( __FUNCTION__, '2.70', 'get_most_users_online()' );
17
 
18
  return get_most_users_online();
19
  }
20
 
21
  function get_most_useronline_date() {
22
+ _deprecated_function( __FUNCTION__, '2.70', 'get_most_users_online()' );
23
 
24
  return get_most_users_online_date();
25
  }
26
 
27
+ function get_useronline_count( $display = false ) {
28
+ _deprecated_function( __FUNCTION__, '2.70', 'users_online_count()' );
29
 
30
  if ( !$display )
31
  return get_users_online_count();
lang/wp-useronline-ro_RO.mo CHANGED
Binary file
lang/wp-useronline-ro_RO.po CHANGED
@@ -2,7 +2,7 @@ msgid ""
2
  msgstr ""
3
  "Project-Id-Version: WP-UserOnline 2.70\n"
4
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/wp-useronline\n"
5
- "POT-Creation-Date: 2010-05-07 16:14+0300\n"
6
  "PO-Revision-Date: \n"
7
  "Last-Translator: scribu <scribu@gmail.com>\n"
8
  "Language-Team: scribu <scribu@gmail.com>\n"
@@ -17,7 +17,7 @@ msgstr ""
17
  msgid "Users Online Now"
18
  msgstr ""
19
 
20
- #. #-#-#-#-# wp-useronline.pot (WP-UserOnline 2.70-beta) #-#-#-#-#
21
  #. Plugin Name of the plugin/theme
22
  #: admin.php:10
23
  #: wp-stats.php:14
@@ -32,142 +32,155 @@ msgid_plural "There are a total of <strong><a href='%s'>%s users</a></strong> on
32
  msgstr[0] ""
33
  msgstr[1] ""
34
 
35
- #: admin.php:51
36
  msgid "UserOnline Options"
37
  msgstr ""
38
 
39
- #: admin.php:52
40
  #: widget.php:6
41
  #: widget.php:49
42
  msgid "UserOnline"
43
  msgstr ""
44
 
45
- #: admin.php:107
46
  msgid "Time Out"
47
  msgstr ""
48
 
49
- #: admin.php:110
50
- msgid "How long until it will remove the user from the database (In seconds)."
51
  msgstr ""
52
 
53
- #: admin.php:115
54
  msgid "UserOnline URL"
55
  msgstr ""
56
 
57
- #: admin.php:118
58
  msgid "URL To UserOnline Page<br />Example: http://www.yoursite.com/useronline/<br />Example: http://www.yoursite.com/?page_id=2"
59
  msgstr ""
60
 
61
- #: admin.php:122
62
  msgid "User Names"
63
  msgstr ""
64
 
65
- #: admin.php:125
66
  msgid "Link user names to their author page"
67
  msgstr ""
68
 
69
- #: admin.php:142
70
  msgid "Useronline Templates"
71
  msgstr ""
72
 
73
- #: admin.php:154
74
  msgid "User(s) Browsing Site:"
75
  msgstr ""
76
 
77
- #: admin.php:155
78
  msgid "User(s) Browsing Page:"
79
  msgstr ""
80
 
81
- #: admin.php:168
82
  #: scb/AdminPage.php:179
83
- #: scb/AdminPage.php:190
84
  msgid "Save Changes"
85
  msgstr ""
86
 
87
- #: admin.php:178
88
  msgid "Naming Conventions:"
89
  msgstr ""
90
 
91
- #: admin.php:179
92
- #: admin.php:219
93
- #: admin.php:241
94
  msgid "Allowed Variables:"
95
  msgstr ""
96
 
97
- #: admin.php:181
98
  msgid "Restore Defaults"
99
  msgstr ""
100
 
101
- #: admin.php:187
102
  msgid "Singular Form"
103
  msgstr ""
104
 
105
- #: admin.php:188
106
  msgid "Plural Form"
107
  msgstr ""
108
 
109
- #: admin.php:218
110
  msgid "User(s) Online:"
111
  msgstr ""
112
 
113
- #: admin.php:224
114
- #: admin.php:249
115
  msgid "Restore Default Template"
116
  msgstr ""
117
 
118
- #: admin.php:255
119
  msgid "Member Names Separator"
120
  msgstr ""
121
 
122
- #: admin.php:256
123
  msgid "Guests Separator"
124
  msgstr ""
125
 
126
- #: admin.php:257
127
  msgid "Bots Separator"
128
  msgstr ""
129
 
130
- #: scb/AdminPage.php:166
 
 
 
 
 
 
 
 
 
 
 
 
131
  msgid "Settings <strong>saved</strong>."
132
  msgstr ""
133
 
134
- #: scb/AdminPage.php:376
135
  msgid "Settings"
136
  msgstr ""
137
 
138
- #: template-tags.php:79
139
  #, php-format
140
  msgid "There is <strong>%s</strong> online now: <strong>%s</strong>, <strong>%s</strong> and <strong>%s</strong>."
141
  msgid_plural "There are a total of <strong>%s</strong> online now: <strong>%s</strong>, <strong>%s</strong> and <strong>%s</strong>."
142
  msgstr[0] ""
143
  msgstr[1] ""
144
 
145
- #: template-tags.php:181
146
  msgid "No one is online now."
147
  msgstr "Nimeni nu este online acum."
148
 
149
- #: template-tags.php:183
150
  msgid "on"
151
  msgstr ""
152
 
153
- #: template-tags.php:184
154
  msgid "url"
155
  msgstr ""
156
 
157
- #: template-tags.php:185
158
  msgid "referral"
159
  msgstr ""
160
 
161
- #: template-tags.php:196
162
  msgid "Online Now"
163
  msgstr ""
164
 
165
- #: template-tags.php:227
 
166
  #, php-format
167
  msgid "%s @ %s"
168
  msgstr ""
169
 
170
- #: template-tags.php:247
171
  #, php-format
172
  msgid "Most users ever online were <strong>%s</strong>, on <strong>%s</strong>"
173
  msgstr ""
@@ -211,79 +224,67 @@ msgid_plural "<strong>%s</strong> users online now."
211
  msgstr[0] ""
212
  msgstr[1] ""
213
 
214
- #: wp-useronline.php:83
215
  msgid "1 User"
216
  msgstr "1 utilizator"
217
 
218
- #: wp-useronline.php:84
219
  msgid "%COUNT% Users"
220
  msgstr "%COUNT% utilizatori"
221
 
222
- #: wp-useronline.php:85
223
  msgid "1 Member"
224
  msgstr "1 membru"
225
 
226
- #: wp-useronline.php:86
227
  msgid "%COUNT% Members"
228
  msgstr "%COUNT% membri"
229
 
230
- #: wp-useronline.php:87
231
  msgid "1 Guest"
232
  msgstr "1 musafir"
233
 
234
- #: wp-useronline.php:88
235
  msgid "%COUNT% Guests"
236
  msgstr "%COUNT% musafiri"
237
 
238
- #: wp-useronline.php:89
239
  msgid "1 Bot"
240
  msgstr "1 bot"
241
 
242
- #: wp-useronline.php:90
243
  msgid "%COUNT% Bots"
244
  msgstr "%COUNT% boți"
245
 
246
- #: wp-useronline.php:94
247
  msgid "Online"
248
  msgstr "Online"
249
 
250
- #: wp-useronline.php:98
251
- #: wp-useronline.php:99
252
- #: wp-useronline.php:100
253
- #: wp-useronline.php:107
254
- #: wp-useronline.php:108
255
- #: wp-useronline.php:109
256
  msgid ","
257
  msgstr ","
258
 
259
- #: wp-useronline.php:102
260
- #: wp-useronline.php:111
261
  msgctxt "Template Element"
262
  msgid "Users"
263
  msgstr "utilizatori"
264
 
265
- #: wp-useronline.php:111
266
  msgid "Browsing This Page."
267
  msgstr ""
268
 
269
- #: wp-useronline.php:210
270
- msgid "Guest"
271
- msgstr ""
272
-
273
- #: wp-useronline.php:217
274
- msgid "Admin"
275
- msgstr ""
276
-
277
- #: wp-useronline.php:223
278
- msgid "Archive"
279
- msgstr "Arhivă"
280
-
281
  #. Plugin URI of the plugin/theme
282
  msgid "http://wordpress.org/extend/plugins/wp-useronline/"
283
  msgstr ""
284
 
285
  #. Description of the plugin/theme
286
- msgid "Enable you to display how many users are online on your Wordpress blog with detailed statistics of where they are and who there are(Members/Guests/Search Bots)."
287
  msgstr ""
288
 
289
  #. Author of the plugin/theme
2
  msgstr ""
3
  "Project-Id-Version: WP-UserOnline 2.70\n"
4
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/wp-useronline\n"
5
+ "POT-Creation-Date: 2010-09-20 15:01+0300\n"
6
  "PO-Revision-Date: \n"
7
  "Last-Translator: scribu <scribu@gmail.com>\n"
8
  "Language-Team: scribu <scribu@gmail.com>\n"
17
  msgid "Users Online Now"
18
  msgstr ""
19
 
20
+ #. #-#-#-#-# wp-useronline.pot (WP-UserOnline 2.80) #-#-#-#-#
21
  #. Plugin Name of the plugin/theme
22
  #: admin.php:10
23
  #: wp-stats.php:14
32
  msgstr[0] ""
33
  msgstr[1] ""
34
 
35
+ #: admin.php:52
36
  msgid "UserOnline Options"
37
  msgstr ""
38
 
39
+ #: admin.php:53
40
  #: widget.php:6
41
  #: widget.php:49
42
  msgid "UserOnline"
43
  msgstr ""
44
 
45
+ #: admin.php:110
46
  msgid "Time Out"
47
  msgstr ""
48
 
49
+ #: admin.php:113
50
+ msgid "How long until it will remove the user from the database ( In seconds )."
51
  msgstr ""
52
 
53
+ #: admin.php:118
54
  msgid "UserOnline URL"
55
  msgstr ""
56
 
57
+ #: admin.php:121
58
  msgid "URL To UserOnline Page<br />Example: http://www.yoursite.com/useronline/<br />Example: http://www.yoursite.com/?page_id=2"
59
  msgstr ""
60
 
61
+ #: admin.php:125
62
  msgid "User Names"
63
  msgstr ""
64
 
65
+ #: admin.php:128
66
  msgid "Link user names to their author page"
67
  msgstr ""
68
 
69
+ #: admin.php:145
70
  msgid "Useronline Templates"
71
  msgstr ""
72
 
73
+ #: admin.php:157
74
  msgid "User(s) Browsing Site:"
75
  msgstr ""
76
 
77
+ #: admin.php:158
78
  msgid "User(s) Browsing Page:"
79
  msgstr ""
80
 
81
+ #: admin.php:171
82
  #: scb/AdminPage.php:179
83
+ #: scb/AdminPage.php:189
84
  msgid "Save Changes"
85
  msgstr ""
86
 
87
+ #: admin.php:181
88
  msgid "Naming Conventions:"
89
  msgstr ""
90
 
91
+ #: admin.php:182
92
+ #: admin.php:222
93
+ #: admin.php:244
94
  msgid "Allowed Variables:"
95
  msgstr ""
96
 
97
+ #: admin.php:184
98
  msgid "Restore Defaults"
99
  msgstr ""
100
 
101
+ #: admin.php:190
102
  msgid "Singular Form"
103
  msgstr ""
104
 
105
+ #: admin.php:191
106
  msgid "Plural Form"
107
  msgstr ""
108
 
109
+ #: admin.php:221
110
  msgid "User(s) Online:"
111
  msgstr ""
112
 
113
+ #: admin.php:227
114
+ #: admin.php:252
115
  msgid "Restore Default Template"
116
  msgstr ""
117
 
118
+ #: admin.php:258
119
  msgid "Member Names Separator"
120
  msgstr ""
121
 
122
+ #: admin.php:259
123
  msgid "Guests Separator"
124
  msgstr ""
125
 
126
+ #: admin.php:260
127
  msgid "Bots Separator"
128
  msgstr ""
129
 
130
+ #: core.php:109
131
+ msgid "Guest"
132
+ msgstr ""
133
+
134
+ #: core.php:180
135
+ msgid "Admin"
136
+ msgstr ""
137
+
138
+ #: core.php:186
139
+ msgid "Archive"
140
+ msgstr "Arhivă"
141
+
142
+ #: scb/AdminPage.php:167
143
  msgid "Settings <strong>saved</strong>."
144
  msgstr ""
145
 
146
+ #: scb/AdminPage.php:371
147
  msgid "Settings"
148
  msgstr ""
149
 
150
+ #: template-tags.php:81
151
  #, php-format
152
  msgid "There is <strong>%s</strong> online now: <strong>%s</strong>, <strong>%s</strong> and <strong>%s</strong>."
153
  msgid_plural "There are a total of <strong>%s</strong> online now: <strong>%s</strong>, <strong>%s</strong> and <strong>%s</strong>."
154
  msgstr[0] ""
155
  msgstr[1] ""
156
 
157
+ #: template-tags.php:190
158
  msgid "No one is online now."
159
  msgstr "Nimeni nu este online acum."
160
 
161
+ #: template-tags.php:192
162
  msgid "on"
163
  msgstr ""
164
 
165
+ #: template-tags.php:193
166
  msgid "url"
167
  msgstr ""
168
 
169
+ #: template-tags.php:194
170
  msgid "referral"
171
  msgstr ""
172
 
173
+ #: template-tags.php:205
174
  msgid "Online Now"
175
  msgstr ""
176
 
177
+ #: template-tags.php:247
178
+ #: template-tags.php:249
179
  #, php-format
180
  msgid "%s @ %s"
181
  msgstr ""
182
 
183
+ #: template-tags.php:269
184
  #, php-format
185
  msgid "Most users ever online were <strong>%s</strong>, on <strong>%s</strong>"
186
  msgstr ""
224
  msgstr[0] ""
225
  msgstr[1] ""
226
 
227
+ #: wp-useronline.php:61
228
  msgid "1 User"
229
  msgstr "1 utilizator"
230
 
231
+ #: wp-useronline.php:62
232
  msgid "%COUNT% Users"
233
  msgstr "%COUNT% utilizatori"
234
 
235
+ #: wp-useronline.php:63
236
  msgid "1 Member"
237
  msgstr "1 membru"
238
 
239
+ #: wp-useronline.php:64
240
  msgid "%COUNT% Members"
241
  msgstr "%COUNT% membri"
242
 
243
+ #: wp-useronline.php:65
244
  msgid "1 Guest"
245
  msgstr "1 musafir"
246
 
247
+ #: wp-useronline.php:66
248
  msgid "%COUNT% Guests"
249
  msgstr "%COUNT% musafiri"
250
 
251
+ #: wp-useronline.php:67
252
  msgid "1 Bot"
253
  msgstr "1 bot"
254
 
255
+ #: wp-useronline.php:68
256
  msgid "%COUNT% Bots"
257
  msgstr "%COUNT% boți"
258
 
259
+ #: wp-useronline.php:72
260
  msgid "Online"
261
  msgstr "Online"
262
 
263
+ #: wp-useronline.php:76
264
+ #: wp-useronline.php:77
265
+ #: wp-useronline.php:78
266
+ #: wp-useronline.php:85
267
+ #: wp-useronline.php:86
268
+ #: wp-useronline.php:87
269
  msgid ","
270
  msgstr ","
271
 
272
+ #: wp-useronline.php:80
273
+ #: wp-useronline.php:89
274
  msgctxt "Template Element"
275
  msgid "Users"
276
  msgstr "utilizatori"
277
 
278
+ #: wp-useronline.php:89
279
  msgid "Browsing This Page."
280
  msgstr ""
281
 
 
 
 
 
 
 
 
 
 
 
 
 
282
  #. Plugin URI of the plugin/theme
283
  msgid "http://wordpress.org/extend/plugins/wp-useronline/"
284
  msgstr ""
285
 
286
  #. Description of the plugin/theme
287
+ msgid "Enable you to display how many users are online on your Wordpress site"
288
  msgstr ""
289
 
290
  #. Author of the plugin/theme
lang/wp-useronline.pot CHANGED
@@ -1,4 +1,4 @@
1
- # Translation of the WordPress plugin WP-UserOnline 2.73 by Lester 'GaMerZ' Chan & scribu.
2
  # Copyright (C) 2010 Lester 'GaMerZ' Chan & scribu
3
  # This file is distributed under the same license as the WP-UserOnline package.
4
  # FIRST AUTHOR <EMAIL@ADDRESS>, 2010.
@@ -6,9 +6,9 @@
6
  #, fuzzy
7
  msgid ""
8
  msgstr ""
9
- "Project-Id-Version: WP-UserOnline 2.73\n"
10
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/wp-useronline\n"
11
- "POT-Creation-Date: 2010-05-13 16:18+0000\n"
12
  "PO-Revision-Date: 2010-MO-DA HO:MI+ZONE\n"
13
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
  "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -21,7 +21,7 @@ msgstr ""
21
  msgid "Users Online Now"
22
  msgstr ""
23
 
24
- #. #-#-#-#-# plugin.pot (WP-UserOnline 2.73) #-#-#-#-#
25
  #. Plugin Name of the plugin/theme
26
  #: admin.php:10 wp-stats.php:14 wp-stats.php:31
27
  msgid "WP-UserOnline"
@@ -48,7 +48,8 @@ msgid "Time Out"
48
  msgstr ""
49
 
50
  #: admin.php:113
51
- msgid "How long until it will remove the user from the database (In seconds)."
 
52
  msgstr ""
53
 
54
  #: admin.php:118
@@ -81,7 +82,7 @@ msgstr ""
81
  msgid "User(s) Browsing Page:"
82
  msgstr ""
83
 
84
- #: admin.php:171 scb/AdminPage.php:180 scb/AdminPage.php:191
85
  msgid "Save Changes"
86
  msgstr ""
87
 
@@ -125,15 +126,27 @@ msgstr ""
125
  msgid "Bots Separator"
126
  msgstr ""
127
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  #: scb/AdminPage.php:167
129
  msgid "Settings <strong>saved</strong>."
130
  msgstr ""
131
 
132
- #: scb/AdminPage.php:377
133
  msgid "Settings"
134
  msgstr ""
135
 
136
- #: template-tags.php:79
137
  #, php-format
138
  msgid ""
139
  "There is <strong>%s</strong> online now: <strong>%s</strong>, <strong>%s</"
@@ -144,32 +157,32 @@ msgid_plural ""
144
  msgstr[0] ""
145
  msgstr[1] ""
146
 
147
- #: template-tags.php:181
148
  msgid "No one is online now."
149
  msgstr ""
150
 
151
- #: template-tags.php:183
152
  msgid "on"
153
  msgstr ""
154
 
155
- #: template-tags.php:184
156
  msgid "url"
157
  msgstr ""
158
 
159
- #: template-tags.php:185
160
  msgid "referral"
161
  msgstr ""
162
 
163
- #: template-tags.php:196
164
  msgid "Online Now"
165
  msgstr ""
166
 
167
- #: template-tags.php:228 template-tags.php:230
168
  #, php-format
169
  msgid "%s @ %s"
170
  msgstr ""
171
 
172
- #: template-tags.php:250
173
  #, php-format
174
  msgid "Most users ever online were <strong>%s</strong>, on <strong>%s</strong>"
175
  msgstr ""
@@ -213,68 +226,56 @@ msgid_plural "<strong>%s</strong> users online now."
213
  msgstr[0] ""
214
  msgstr[1] ""
215
 
216
- #: wp-useronline.php:83
217
  msgid "1 User"
218
  msgstr ""
219
 
220
- #: wp-useronline.php:84
221
  msgid "%COUNT% Users"
222
  msgstr ""
223
 
224
- #: wp-useronline.php:85
225
  msgid "1 Member"
226
  msgstr ""
227
 
228
- #: wp-useronline.php:86
229
  msgid "%COUNT% Members"
230
  msgstr ""
231
 
232
- #: wp-useronline.php:87
233
  msgid "1 Guest"
234
  msgstr ""
235
 
236
- #: wp-useronline.php:88
237
  msgid "%COUNT% Guests"
238
  msgstr ""
239
 
240
- #: wp-useronline.php:89
241
  msgid "1 Bot"
242
  msgstr ""
243
 
244
- #: wp-useronline.php:90
245
  msgid "%COUNT% Bots"
246
  msgstr ""
247
 
248
- #: wp-useronline.php:94
249
  msgid "Online"
250
  msgstr ""
251
 
252
- #: wp-useronline.php:98 wp-useronline.php:99 wp-useronline.php:100
253
- #: wp-useronline.php:107 wp-useronline.php:108 wp-useronline.php:109
254
  msgid ","
255
  msgstr ""
256
 
257
- #: wp-useronline.php:102 wp-useronline.php:111
258
  msgctxt "Template Element"
259
  msgid "Users"
260
  msgstr ""
261
 
262
- #: wp-useronline.php:111
263
  msgid "Browsing This Page."
264
  msgstr ""
265
 
266
- #: wp-useronline.php:233
267
- msgid "Guest"
268
- msgstr ""
269
-
270
- #: wp-useronline.php:240
271
- msgid "Admin"
272
- msgstr ""
273
-
274
- #: wp-useronline.php:246
275
- msgid "Archive"
276
- msgstr ""
277
-
278
  #. Plugin URI of the plugin/theme
279
  msgid "http://wordpress.org/extend/plugins/wp-useronline/"
280
  msgstr ""
1
+ # Translation of the WordPress plugin WP-UserOnline 2.80 by Lester 'GaMerZ' Chan & scribu.
2
  # Copyright (C) 2010 Lester 'GaMerZ' Chan & scribu
3
  # This file is distributed under the same license as the WP-UserOnline package.
4
  # FIRST AUTHOR <EMAIL@ADDRESS>, 2010.
6
  #, fuzzy
7
  msgid ""
8
  msgstr ""
9
+ "Project-Id-Version: WP-UserOnline 2.80\n"
10
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/wp-useronline\n"
11
+ "POT-Creation-Date: 2010-09-20 15:01+0300\n"
12
  "PO-Revision-Date: 2010-MO-DA HO:MI+ZONE\n"
13
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
  "Language-Team: LANGUAGE <LL@li.org>\n"
21
  msgid "Users Online Now"
22
  msgstr ""
23
 
24
+ #. #-#-#-#-# wp-useronline.pot (WP-UserOnline 2.80) #-#-#-#-#
25
  #. Plugin Name of the plugin/theme
26
  #: admin.php:10 wp-stats.php:14 wp-stats.php:31
27
  msgid "WP-UserOnline"
48
  msgstr ""
49
 
50
  #: admin.php:113
51
+ msgid ""
52
+ "How long until it will remove the user from the database ( In seconds )."
53
  msgstr ""
54
 
55
  #: admin.php:118
82
  msgid "User(s) Browsing Page:"
83
  msgstr ""
84
 
85
+ #: admin.php:171 scb/AdminPage.php:179 scb/AdminPage.php:189
86
  msgid "Save Changes"
87
  msgstr ""
88
 
126
  msgid "Bots Separator"
127
  msgstr ""
128
 
129
+ #: core.php:109
130
+ msgid "Guest"
131
+ msgstr ""
132
+
133
+ #: core.php:180
134
+ msgid "Admin"
135
+ msgstr ""
136
+
137
+ #: core.php:186
138
+ msgid "Archive"
139
+ msgstr ""
140
+
141
  #: scb/AdminPage.php:167
142
  msgid "Settings <strong>saved</strong>."
143
  msgstr ""
144
 
145
+ #: scb/AdminPage.php:371
146
  msgid "Settings"
147
  msgstr ""
148
 
149
+ #: template-tags.php:81
150
  #, php-format
151
  msgid ""
152
  "There is <strong>%s</strong> online now: <strong>%s</strong>, <strong>%s</"
157
  msgstr[0] ""
158
  msgstr[1] ""
159
 
160
+ #: template-tags.php:190
161
  msgid "No one is online now."
162
  msgstr ""
163
 
164
+ #: template-tags.php:192
165
  msgid "on"
166
  msgstr ""
167
 
168
+ #: template-tags.php:193
169
  msgid "url"
170
  msgstr ""
171
 
172
+ #: template-tags.php:194
173
  msgid "referral"
174
  msgstr ""
175
 
176
+ #: template-tags.php:205
177
  msgid "Online Now"
178
  msgstr ""
179
 
180
+ #: template-tags.php:247 template-tags.php:249
181
  #, php-format
182
  msgid "%s @ %s"
183
  msgstr ""
184
 
185
+ #: template-tags.php:269
186
  #, php-format
187
  msgid "Most users ever online were <strong>%s</strong>, on <strong>%s</strong>"
188
  msgstr ""
226
  msgstr[0] ""
227
  msgstr[1] ""
228
 
229
+ #: wp-useronline.php:61
230
  msgid "1 User"
231
  msgstr ""
232
 
233
+ #: wp-useronline.php:62
234
  msgid "%COUNT% Users"
235
  msgstr ""
236
 
237
+ #: wp-useronline.php:63
238
  msgid "1 Member"
239
  msgstr ""
240
 
241
+ #: wp-useronline.php:64
242
  msgid "%COUNT% Members"
243
  msgstr ""
244
 
245
+ #: wp-useronline.php:65
246
  msgid "1 Guest"
247
  msgstr ""
248
 
249
+ #: wp-useronline.php:66
250
  msgid "%COUNT% Guests"
251
  msgstr ""
252
 
253
+ #: wp-useronline.php:67
254
  msgid "1 Bot"
255
  msgstr ""
256
 
257
+ #: wp-useronline.php:68
258
  msgid "%COUNT% Bots"
259
  msgstr ""
260
 
261
+ #: wp-useronline.php:72
262
  msgid "Online"
263
  msgstr ""
264
 
265
+ #: wp-useronline.php:76 wp-useronline.php:77 wp-useronline.php:78
266
+ #: wp-useronline.php:85 wp-useronline.php:86 wp-useronline.php:87
267
  msgid ","
268
  msgstr ""
269
 
270
+ #: wp-useronline.php:80 wp-useronline.php:89
271
  msgctxt "Template Element"
272
  msgid "Users"
273
  msgstr ""
274
 
275
+ #: wp-useronline.php:89
276
  msgid "Browsing This Page."
277
  msgstr ""
278
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  #. Plugin URI of the plugin/theme
280
  msgid "http://wordpress.org/extend/plugins/wp-useronline/"
281
  msgstr ""
readme.txt CHANGED
@@ -1,10 +1,9 @@
1
  === WP-UserOnline ===
2
  Contributors: GamerZ, scribu
3
- Donate link: http://lesterchan.net/wordpress
4
  Tags: useronline, usersonline, wp-useronline, online, users, user, ajax, widget
5
- Requires at least: 2.9
6
  Tested up to: 3.0
7
- Stable tag: 2.73
8
 
9
  Enable you to display how many users are online on your Wordpress blog with detailed statistics.
10
 
@@ -96,15 +95,16 @@ Make sure your host is running PHP 5. The only foolproof way to do this is to ad
96
 
97
  == Changelog ==
98
 
99
- = 2.73 =
100
- * fixed "0 users" problem
101
- * fixed "%MOSTONLINE_DATE% problem
 
102
 
103
  = 2.72 =
104
- * fixed fatal error on upgrade
105
 
106
  = 2.71 =
107
- * fixed %USERONLINE_COUNT% problem
108
 
109
  = 2.70 =
110
  * added option to link user names to their author page
1
  === WP-UserOnline ===
2
  Contributors: GamerZ, scribu
 
3
  Tags: useronline, usersonline, wp-useronline, online, users, user, ajax, widget
4
+ Requires at least: 3.0
5
  Tested up to: 3.0
6
+ Stable tag: 2.80
7
 
8
  Enable you to display how many users are online on your Wordpress blog with detailed statistics.
9
 
95
 
96
  == Changelog ==
97
 
98
+ = 2.80 =
99
+ * don't show url and referral links for users in the admin area
100
+ * smarter detection via ajax requests
101
+ * fix SQL errors
102
 
103
  = 2.72 =
104
+ * fix fatal error on upgrade
105
 
106
  = 2.71 =
107
+ * fix %USERONLINE_COUNT% problem
108
 
109
  = 2.70 =
110
  * added option to link user names to their author page
scb/AdminPage.php CHANGED
@@ -10,13 +10,13 @@ abstract class scbAdminPage {
10
  /** Page args
11
  * $toplevel string If not empty, will create a new top level menu
12
  * $icon string Path to an icon for the top level menu
13
- * $parent string (default: options-general.php)
14
- * $capability string (default: 'manage_options')
15
- * $page_title string (mandatory)
16
- * $menu_title string (default: $page_title)
17
- * $page_slug string (default: sanitized $page_title)
18
- * $nonce string (default: $page_slug)
19
- * $action_link string|bool Text of the action link on the Plugins page (default: 'Settings')
20
  */
21
  protected $args;
22
 
@@ -44,39 +44,39 @@ abstract class scbAdminPage {
44
 
45
  private static $registered = array();
46
 
47
- static function register($class, $file, $options = null) {
48
- if ( isset(self::$registered[$class]) )
49
  return false;
50
 
51
- self::$registered[$class] = array($file, $options);
52
 
53
- add_action('_admin_menu', array(__CLASS__, '_pages_init'));
54
 
55
  return true;
56
  }
57
 
58
- static function replace($old_class, $new_class) {
59
- if ( ! isset(self::$registered[$old_class]) )
60
  return false;
61
 
62
  self::$registered[$new_class] = self::$registered[$old_class];
63
- unset(self::$registered[$old_class]);
64
 
65
  return true;
66
  }
67
 
68
- static function remove($class) {
69
- if ( ! isset(self::$registered[$class]) )
70
  return false;
71
 
72
- unset(self::$registered[$class]);
73
 
74
  return true;
75
  }
76
 
77
  static function _pages_init() {
78
  foreach ( self::$registered as $class => $args )
79
- new $class($args[0], $args[1]);
80
  }
81
 
82
 
@@ -84,29 +84,29 @@ abstract class scbAdminPage {
84
 
85
 
86
  // Constructor
87
- function __construct($file, $options = NULL) {
88
  if ( NULL !== $options ) {
89
  $this->options = $options;
90
  $this->formdata = $this->options->get();
91
  }
92
 
93
  $this->file = $file;
94
- $this->plugin_url = plugin_dir_url($file);
95
 
96
  $this->setup();
97
  $this->check_args();
98
 
99
- if ( isset($this->option_name) ) {
100
- add_action('admin_init', array($this, 'option_init'));
101
- if ( function_exists('settings_errors') )
102
- add_action('admin_notices', 'settings_errors');
103
  }
104
 
105
- add_action('admin_menu', array($this, 'page_init'));
106
- add_filter('contextual_help', array($this, '_contextual_help'), 10, 2);
107
 
108
  if ( $this->args['action_link'] )
109
- add_filter('plugin_action_links_' . plugin_basename($file), array($this, '_action_link'));
110
  }
111
 
112
  // This is where all the page args can be set
@@ -136,35 +136,35 @@ abstract class scbAdminPage {
136
  }
137
 
138
  // This is where the form data should be validated
139
- function validate($new_data, $old_data) {
140
  return $new_data;
141
  }
142
 
143
- // Manually handle option saving (use Settings API instead)
144
  function form_handler() {
145
- if ( empty($_POST['action']) )
146
  return false;
147
 
148
- check_admin_referer($this->nonce);
149
 
150
  $new_data = array();
151
- foreach ( array_keys($this->formdata) as $key )
152
  $new_data[$key] = @$_POST[$key];
153
 
154
- $new_data = stripslashes_deep($new_data);
155
 
156
- $this->formdata = $this->validate($new_data, $this->formdata);
157
 
158
- if ( isset($this->options) )
159
- $this->options->update($this->formdata);
160
 
161
  $this->admin_msg();
162
  }
163
 
164
- // Manually generate a standard admin notice (use Settings API instead)
165
- function admin_msg($msg = '', $class = "updated") {
166
- if ( empty($msg) )
167
- $msg = __('Settings <strong>saved</strong>.', $this->textdomain);
168
 
169
  echo "<div class='$class fade'><p>$msg</p></div>\n";
170
  }
@@ -174,35 +174,31 @@ abstract class scbAdminPage {
174
 
175
 
176
  // Generates a form submit button
177
- function submit_button($value = '', $action = 'action', $class = "button") {
178
- if ( is_array($value) ) {
179
- extract(wp_parse_args($value, array(
180
- 'value' => __('Save Changes', $this->textdomain),
181
  'action' => 'action',
182
  'class' => 'button',
183
- 'ajax' => true
184
- )));
185
 
186
  if ( ! $ajax )
187
  $class .= ' no-ajax';
188
  }
189
  else {
190
- if ( empty($value) )
191
- $value = __('Save Changes', $this->textdomain);
192
  }
193
 
194
- $input_args = array(
195
- 'type' => 'submit',
196
  'names' => $action,
197
  'values' => $value,
198
  'extra' => '',
199
- 'desc' => false
200
- );
201
 
202
- if ( ! empty($class) )
203
  $input_args['extra'] = "class='{$class}'";
204
 
205
- $output = "<p class='submit'>\n" . scbForms::input($input_args) . "</p>\n";
206
 
207
  return $output;
208
  }
@@ -210,94 +206,92 @@ abstract class scbAdminPage {
210
  /*
211
  Mimics scbForms::form_wrap()
212
 
213
- $this->form_wrap($content); // generates a form with a default submit button
214
 
215
- $this->form_wrap($content, false); // generates a form with no submit button
216
 
217
  // the second argument is sent to submit_button()
218
- $this->form_wrap($content, array(
219
- 'text' => 'Save changes',
220
  'name' => 'action',
221
  'ajax' => true,
222
- ));
223
  */
224
- function form_wrap($content, $submit_button = true) {
225
- if ( is_array($submit_button) ) {
226
- $content .= call_user_func(array($this, 'submit_button'), $submit_button);
227
  } elseif ( true === $submit_button ) {
228
  $content .= $this->submit_button();
229
- } elseif ( false !== strpos($submit_button, '<input') ) {
230
  $content .= $submit_button;
231
  } elseif ( false !== $submit_button ) {
232
- $button_args = array_slice(func_get_args(), 1);
233
- $content .= call_user_func_array(array($this, 'submit_button'), $button_args);
234
  }
235
 
236
- return scbForms::form_wrap($content, $this->nonce);
237
  }
238
 
239
  // See scbForms::form()
240
- function form($rows, $formdata = array()) {
241
- return scbForms::form($rows, $formdata, $this->nonce);
242
  }
243
 
244
  // Generates a table wrapped in a form
245
- function form_table($rows, $formdata = array()) {
246
  $output = '';
247
  foreach ( $rows as $row )
248
- $output .= $this->table_row($row, $formdata);
249
 
250
- $output = $this->form_table_wrap($output);
251
 
252
  return $output;
253
  }
254
 
255
  // Wraps the given content in a <form><table>
256
- function form_table_wrap($content) {
257
- $output = $this->table_wrap($content);
258
- $output = $this->form_wrap($output, $this->nonce);
259
 
260
  return $output;
261
  }
262
 
263
  // Generates a form table
264
- function table($rows, $formdata = array()) {
265
  $output = '';
266
  foreach ( $rows as $row )
267
- $output .= $this->table_row($row, $formdata);
268
 
269
- $output = $this->table_wrap($output);
270
 
271
  return $output;
272
  }
273
 
274
  // Generates a table row
275
- function table_row($args, $formdata = array()) {
276
- return $this->row_wrap($args['title'], $this->input($args, $formdata));
277
  }
278
 
279
  // Wraps the given content in a <table>
280
- function table_wrap($content) {
281
  return
282
- html('table class="form-table"', $content);
283
  }
284
 
285
  // Wraps the given content in a <tr><td>
286
- function row_wrap($title, $content) {
287
  return
288
- html('tr',
289
- html('th scope="row"', $title)
290
- .html('td', $content)
291
- );
292
  }
293
 
294
- function input($args, $formdata = array()) {
295
- if ( empty($formdata) )
296
  $formdata = $this->formdata;
297
 
298
- if ( isset($args['name_tree']) ) {
299
- $tree = (array) $args['name_tree'];
300
- unset($args['name_tree']);
301
 
302
  $value = $formdata;
303
  $name = $this->option_name;
@@ -307,28 +301,28 @@ abstract class scbAdminPage {
307
  }
308
 
309
  $args['name'] = $name;
310
- unset($args['names']);
311
 
312
- unset($args['values']);
313
 
314
- $formdata = array($name => $value);
315
  }
316
 
317
- return scbForms::input($args, $formdata);
318
  }
319
 
320
  // Mimic scbForms inheritance
321
- function __call($method, $args) {
322
- return call_user_func_array(array('scbForms', $method), $args);
323
  }
324
 
325
  // Wraps a string in a <script> tag
326
- function js_wrap($string) {
327
  return "\n<script type='text/javascript'>\n" . $string . "\n</script>\n";
328
  }
329
 
330
  // Wraps a string in a <style> tag
331
- function css_wrap($string) {
332
  return "\n<style type='text/css'>\n" . $string . "\n</style>\n";
333
  }
334
 
@@ -338,13 +332,13 @@ abstract class scbAdminPage {
338
 
339
  // Registers a page
340
  function page_init() {
341
- extract($this->args);
342
 
343
  if ( ! $toplevel ) {
344
- $this->pagehook = add_submenu_page($parent, $page_title, $menu_title, $capability, $page_slug, array($this, '_page_content_hook'));
345
  } else {
346
  $func = 'add_' . $toplevel . '_page';
347
- $this->pagehook = $func($page_title, $menu_title, $capability, $page_slug, array($this, '_page_content_hook'), $icon_url);
348
  }
349
 
350
  if ( ! $this->pagehook )
@@ -352,21 +346,21 @@ abstract class scbAdminPage {
352
 
353
  if ( $ajax_submit ) {
354
  $this->ajax_response();
355
- add_action('admin_footer', array($this, 'ajax_submit'), 20);
356
  }
357
 
358
- add_action('admin_print_styles-' . $this->pagehook, array($this, 'page_head'));
359
  }
360
 
361
  function option_init() {
362
- register_setting($this->option_name, $this->option_name, array($this, 'validate'));
363
  }
364
 
365
  private function check_args() {
366
- if ( empty($this->args['page_title']) )
367
- trigger_error('Page title cannot be empty', E_USER_WARNING);
368
 
369
- $this->args = wp_parse_args($this->args, array(
370
  'toplevel' => '',
371
  'icon' => '',
372
  'parent' => 'options-general.php',
@@ -374,29 +368,31 @@ abstract class scbAdminPage {
374
  'menu_title' => $this->args['page_title'],
375
  'page_slug' => '',
376
  'nonce' => '',
377
- 'action_link' => __('Settings', $this->textdomain),
378
- 'ajax_submit' => false,
379
- ));
380
 
381
- if ( empty($this->args['page_slug']) )
382
- $this->args['page_slug'] = sanitize_title_with_dashes($this->args['menu_title']);
383
 
384
- if ( empty($this->args['nonce']) )
385
  $this->nonce = $this->args['page_slug'];
386
  }
387
 
388
- function _contextual_help($help, $screen) {
389
- if ( is_object($screen) )
390
  $screen = $screen->id;
391
 
392
- if ( $screen == $this->pagehook && $actual_help = $this->page_help() )
 
 
393
  return $actual_help;
394
 
395
  return $help;
396
  }
397
 
398
  function ajax_response() {
399
- if ( ! isset($_POST['_ajax_submit']) || $_POST['_ajax_submit'] != $this->pagehook )
400
  return;
401
 
402
  $this->form_handler();
@@ -410,40 +406,40 @@ abstract class scbAdminPage {
410
  return;
411
  ?>
412
  <script type="text/javascript">
413
- jQuery(document).ready(function($){
414
- var $spinner = $(new Image()).attr('src', '<?php echo admin_url("images/wpspin_light.gif"); ?>');
415
 
416
- $(':submit').click(function(ev){
417
- var $submit = $(this);
418
- var $form = $submit.parents('form');
419
 
420
- if ( $submit.hasClass('no-ajax') || $form.attr('method').toLowerCase() != 'post' )
421
  return true;
422
 
423
  var $this_spinner = $spinner.clone();
424
 
425
- $submit.before($this_spinner).hide();
426
 
427
  var data = $form.serializeArray();
428
- data.push({name: $submit.attr('name'), value: $submit.val()});
429
- data.push({name: '_ajax_submit', value: '<?php echo $this->pagehook; ?>'});
430
 
431
- $.post(location.href, data, function(response){
432
- var $prev = $('.wrap > .updated, .wrap > .error');
433
- var $msg = $(response).hide().insertAfter($('.wrap h2'));
434
  if ( $prev.length > 0 )
435
- $prev.fadeOut('slow', function(){ $msg.fadeIn('slow'); });
436
  else
437
- $msg.fadeIn('slow');
438
 
439
  $this_spinner.hide();
440
  $submit.show();
441
- });
442
 
443
  ev.stopPropagation();
444
  ev.preventDefault();
445
- });
446
- });
447
  </script>
448
  <?php
449
  }
@@ -456,10 +452,10 @@ jQuery(document).ready(function($){
456
  $this->page_footer();
457
  }
458
 
459
- function _action_link($links) {
460
- $url = add_query_arg('page', $this->args['page_slug'], admin_url($this->args['parent']));
461
 
462
- $links[] = html_link($url, $this->args['action_link']);
463
 
464
  return $links;
465
  }
10
  /** Page args
11
  * $toplevel string If not empty, will create a new top level menu
12
  * $icon string Path to an icon for the top level menu
13
+ * $parent string ( default: options-general.php )
14
+ * $capability string ( default: 'manage_options' )
15
+ * $page_title string ( mandatory )
16
+ * $menu_title string ( default: $page_title )
17
+ * $page_slug string ( default: sanitized $page_title )
18
+ * $nonce string ( default: $page_slug )
19
+ * $action_link string|bool Text of the action link on the Plugins page ( default: 'Settings' )
20
  */
21
  protected $args;
22
 
44
 
45
  private static $registered = array();
46
 
47
+ static function register( $class, $file, $options = null ) {
48
+ if ( isset( self::$registered[$class] ) )
49
  return false;
50
 
51
+ self::$registered[$class] = array( $file, $options );
52
 
53
+ add_action( '_admin_menu', array( __CLASS__, '_pages_init' ) );
54
 
55
  return true;
56
  }
57
 
58
+ static function replace( $old_class, $new_class ) {
59
+ if ( ! isset( self::$registered[$old_class] ) )
60
  return false;
61
 
62
  self::$registered[$new_class] = self::$registered[$old_class];
63
+ unset( self::$registered[$old_class] );
64
 
65
  return true;
66
  }
67
 
68
+ static function remove( $class ) {
69
+ if ( ! isset( self::$registered[$class] ) )
70
  return false;
71
 
72
+ unset( self::$registered[$class] );
73
 
74
  return true;
75
  }
76
 
77
  static function _pages_init() {
78
  foreach ( self::$registered as $class => $args )
79
+ new $class( $args[0], $args[1] );
80
  }
81
 
82
 
84
 
85
 
86
  // Constructor
87
+ function __construct( $file, $options = NULL ) {
88
  if ( NULL !== $options ) {
89
  $this->options = $options;
90
  $this->formdata = $this->options->get();
91
  }
92
 
93
  $this->file = $file;
94
+ $this->plugin_url = plugin_dir_url( $file );
95
 
96
  $this->setup();
97
  $this->check_args();
98
 
99
+ if ( isset( $this->option_name ) ) {
100
+ add_action( 'admin_init', array( $this, 'option_init' ) );
101
+ if ( function_exists( 'settings_errors' ) )
102
+ add_action( 'admin_notices', 'settings_errors' );
103
  }
104
 
105
+ add_action( 'admin_menu', array( $this, 'page_init' ) );
106
+ add_filter( 'contextual_help', array( $this, '_contextual_help' ), 10, 2 );
107
 
108
  if ( $this->args['action_link'] )
109
+ add_filter( 'plugin_action_links_' . plugin_basename( $file ), array( $this, '_action_link' ) );
110
  }
111
 
112
  // This is where all the page args can be set
136
  }
137
 
138
  // This is where the form data should be validated
139
+ function validate( $new_data, $old_data ) {
140
  return $new_data;
141
  }
142
 
143
+ // Manually handle option saving ( use Settings API instead )
144
  function form_handler() {
145
+ if ( empty( $_POST['action'] ) )
146
  return false;
147
 
148
+ check_admin_referer( $this->nonce );
149
 
150
  $new_data = array();
151
+ foreach ( array_keys( $this->formdata ) as $key )
152
  $new_data[$key] = @$_POST[$key];
153
 
154
+ $new_data = stripslashes_deep( $new_data );
155
 
156
+ $this->formdata = $this->validate( $new_data, $this->formdata );
157
 
158
+ if ( isset( $this->options ) )
159
+ $this->options->set( $this->formdata );
160
 
161
  $this->admin_msg();
162
  }
163
 
164
+ // Manually generate a standard admin notice ( use Settings API instead )
165
+ function admin_msg( $msg = '', $class = "updated" ) {
166
+ if ( empty( $msg ) )
167
+ $msg = __( 'Settings <strong>saved</strong>.', $this->textdomain );
168
 
169
  echo "<div class='$class fade'><p>$msg</p></div>\n";
170
  }
174
 
175
 
176
  // Generates a form submit button
177
+ function submit_button( $value = '', $action = 'action', $class = "button" ) {
178
+ if ( is_array( $value ) ) {
179
+ extract( wp_parse_args( $value, array( 'value' => __( 'Save Changes', $this->textdomain ),
 
180
  'action' => 'action',
181
  'class' => 'button',
182
+ 'ajax' => true ) ) );
 
183
 
184
  if ( ! $ajax )
185
  $class .= ' no-ajax';
186
  }
187
  else {
188
+ if ( empty( $value ) )
189
+ $value = __( 'Save Changes', $this->textdomain );
190
  }
191
 
192
+ $input_args = array( 'type' => 'submit',
 
193
  'names' => $action,
194
  'values' => $value,
195
  'extra' => '',
196
+ 'desc' => false );
 
197
 
198
+ if ( ! empty( $class ) )
199
  $input_args['extra'] = "class='{$class}'";
200
 
201
+ $output = "<p class='submit'>\n" . scbForms::input( $input_args ) . "</p>\n";
202
 
203
  return $output;
204
  }
206
  /*
207
  Mimics scbForms::form_wrap()
208
 
209
+ $this->form_wrap( $content ); // generates a form with a default submit button
210
 
211
+ $this->form_wrap( $content, false ); // generates a form with no submit button
212
 
213
  // the second argument is sent to submit_button()
214
+ $this->form_wrap( $content, array( 'text' => 'Save changes',
 
215
  'name' => 'action',
216
  'ajax' => true,
217
+ ) );
218
  */
219
+ function form_wrap( $content, $submit_button = true ) {
220
+ if ( is_array( $submit_button ) ) {
221
+ $content .= call_user_func( array( $this, 'submit_button' ), $submit_button );
222
  } elseif ( true === $submit_button ) {
223
  $content .= $this->submit_button();
224
+ } elseif ( false !== strpos( $submit_button, '<input' ) ) {
225
  $content .= $submit_button;
226
  } elseif ( false !== $submit_button ) {
227
+ $button_args = array_slice( func_get_args(), 1 );
228
+ $content .= call_user_func_array( array( $this, 'submit_button' ), $button_args );
229
  }
230
 
231
+ return scbForms::form_wrap( $content, $this->nonce );
232
  }
233
 
234
  // See scbForms::form()
235
+ function form( $rows, $formdata = array() ) {
236
+ return scbForms::form( $rows, $formdata, $this->nonce );
237
  }
238
 
239
  // Generates a table wrapped in a form
240
+ function form_table( $rows, $formdata = array() ) {
241
  $output = '';
242
  foreach ( $rows as $row )
243
+ $output .= $this->table_row( $row, $formdata );
244
 
245
+ $output = $this->form_table_wrap( $output );
246
 
247
  return $output;
248
  }
249
 
250
  // Wraps the given content in a <form><table>
251
+ function form_table_wrap( $content ) {
252
+ $output = $this->table_wrap( $content );
253
+ $output = $this->form_wrap( $output, $this->nonce );
254
 
255
  return $output;
256
  }
257
 
258
  // Generates a form table
259
+ function table( $rows, $formdata = array() ) {
260
  $output = '';
261
  foreach ( $rows as $row )
262
+ $output .= $this->table_row( $row, $formdata );
263
 
264
+ $output = $this->table_wrap( $output );
265
 
266
  return $output;
267
  }
268
 
269
  // Generates a table row
270
+ function table_row( $args, $formdata = array() ) {
271
+ return $this->row_wrap( $args['title'], $this->input( $args, $formdata ) );
272
  }
273
 
274
  // Wraps the given content in a <table>
275
+ function table_wrap( $content ) {
276
  return
277
+ html( 'table class="form-table"', $content );
278
  }
279
 
280
  // Wraps the given content in a <tr><td>
281
+ function row_wrap( $title, $content ) {
282
  return
283
+ html( 'tr',
284
+ html( 'th scope="row"', $title )
285
+ .html( 'td', $content ) );
 
286
  }
287
 
288
+ function input( $args, $formdata = array() ) {
289
+ if ( empty( $formdata ) )
290
  $formdata = $this->formdata;
291
 
292
+ if ( isset( $args['name_tree'] ) ) {
293
+ $tree = ( array ) $args['name_tree'];
294
+ unset( $args['name_tree'] );
295
 
296
  $value = $formdata;
297
  $name = $this->option_name;
301
  }
302
 
303
  $args['name'] = $name;
304
+ unset( $args['names'] );
305
 
306
+ unset( $args['values'] );
307
 
308
+ $formdata = array( $name => $value );
309
  }
310
 
311
+ return scbForms::input( $args, $formdata );
312
  }
313
 
314
  // Mimic scbForms inheritance
315
+ function __call( $method, $args ) {
316
+ return call_user_func_array( array( 'scbForms', $method ), $args );
317
  }
318
 
319
  // Wraps a string in a <script> tag
320
+ function js_wrap( $string ) {
321
  return "\n<script type='text/javascript'>\n" . $string . "\n</script>\n";
322
  }
323
 
324
  // Wraps a string in a <style> tag
325
+ function css_wrap( $string ) {
326
  return "\n<style type='text/css'>\n" . $string . "\n</style>\n";
327
  }
328
 
332
 
333
  // Registers a page
334
  function page_init() {
335
+ extract( $this->args );
336
 
337
  if ( ! $toplevel ) {
338
+ $this->pagehook = add_submenu_page( $parent, $page_title, $menu_title, $capability, $page_slug, array( $this, '_page_content_hook' ) );
339
  } else {
340
  $func = 'add_' . $toplevel . '_page';
341
+ $this->pagehook = $func( $page_title, $menu_title, $capability, $page_slug, array( $this, '_page_content_hook' ), $icon_url );
342
  }
343
 
344
  if ( ! $this->pagehook )
346
 
347
  if ( $ajax_submit ) {
348
  $this->ajax_response();
349
+ add_action( 'admin_footer', array( $this, 'ajax_submit' ), 20 );
350
  }
351
 
352
+ add_action( 'admin_print_styles-' . $this->pagehook, array( $this, 'page_head' ) );
353
  }
354
 
355
  function option_init() {
356
+ register_setting( $this->option_name, $this->option_name, array( $this, 'validate' ) );
357
  }
358
 
359
  private function check_args() {
360
+ if ( empty( $this->args['page_title'] ) )
361
+ trigger_error( 'Page title cannot be empty', E_USER_WARNING );
362
 
363
+ $this->args = wp_parse_args( $this->args, array(
364
  'toplevel' => '',
365
  'icon' => '',
366
  'parent' => 'options-general.php',
368
  'menu_title' => $this->args['page_title'],
369
  'page_slug' => '',
370
  'nonce' => '',
371
+ 'action_link' => __( 'Settings', $this->textdomain ),
372
+ 'ajax_submit' => false,
373
+ ) );
374
 
375
+ if ( empty( $this->args['page_slug'] ) )
376
+ $this->args['page_slug'] = sanitize_title_with_dashes( $this->args['menu_title'] );
377
 
378
+ if ( empty( $this->args['nonce'] ) )
379
  $this->nonce = $this->args['page_slug'];
380
  }
381
 
382
+ function _contextual_help( $help, $screen ) {
383
+ if ( is_object( $screen ) )
384
  $screen = $screen->id;
385
 
386
+ $actual_help = $this->page_help();
387
+
388
+ if ( $screen == $this->pagehook && $actual_help )
389
  return $actual_help;
390
 
391
  return $help;
392
  }
393
 
394
  function ajax_response() {
395
+ if ( ! isset( $_POST['_ajax_submit'] ) || $_POST['_ajax_submit'] != $this->pagehook )
396
  return;
397
 
398
  $this->form_handler();
406
  return;
407
  ?>
408
  <script type="text/javascript">
409
+ jQuery( document ).ready( function( $ ){
410
+ var $spinner = $( new Image() ).attr( 'src', '<?php echo admin_url( "images/wpspin_light.gif" ); ?>' );
411
 
412
+ $( ':submit' ).click( function( ev ){
413
+ var $submit = $( this );
414
+ var $form = $submit.parents( 'form' );
415
 
416
+ if ( $submit.hasClass( 'no-ajax' ) || $form.attr( 'method' ).toLowerCase() != 'post' )
417
  return true;
418
 
419
  var $this_spinner = $spinner.clone();
420
 
421
+ $submit.before( $this_spinner ).hide();
422
 
423
  var data = $form.serializeArray();
424
+ data.push( {name: $submit.attr( 'name' ), value: $submit.val()} );
425
+ data.push( {name: '_ajax_submit', value: '<?php echo $this->pagehook; ?>'} );
426
 
427
+ $.post( location.href, data, function( response ){
428
+ var $prev = $( '.wrap > .updated, .wrap > .error' );
429
+ var $msg = $( response ).hide().insertAfter( $( '.wrap h2' ) );
430
  if ( $prev.length > 0 )
431
+ $prev.fadeOut( 'slow', function(){ $msg.fadeIn( 'slow' ); } );
432
  else
433
+ $msg.fadeIn( 'slow' );
434
 
435
  $this_spinner.hide();
436
  $submit.show();
437
+ } );
438
 
439
  ev.stopPropagation();
440
  ev.preventDefault();
441
+ } );
442
+ } );
443
  </script>
444
  <?php
445
  }
452
  $this->page_footer();
453
  }
454
 
455
+ function _action_link( $links ) {
456
+ $url = add_query_arg( 'page', $this->args['page_slug'], admin_url( $this->args['parent'] ) );
457
 
458
+ $links[] = html_link( $url, $this->args['action_link'] );
459
 
460
  return $links;
461
  }
scb/BoxesPage.php ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ Creates an admin page with widgets, similar to the dashboard
5
+
6
+ For example, if you defined the boxes like this:
7
+
8
+ $this->boxes = array( array( 'settings', 'Settings box', 'normal' )
9
+ ... );
10
+
11
+ You must also define two methods in your class for each box:
12
+
13
+ function settings_box() - this is where the box content is echoed
14
+ function settings_handler() - this is where the box settings are saved
15
+ ...
16
+ */
17
+ abstract class scbBoxesPage extends scbAdminPage {
18
+ /*
19
+ A box definition looks like this:
20
+ array( $slug, $title, $column );
21
+
22
+ Available columns: normal, side, column3, column4
23
+ */
24
+ protected $boxes = array();
25
+
26
+ function __construct( $file, $options = null ) {
27
+ parent::__construct( $file, $options );
28
+
29
+ // too late
30
+ scbUtil::add_uninstall_hook( $this->file, array( $this, 'uninstall' ) );
31
+ }
32
+
33
+ function page_init() {
34
+ if ( !isset( $this->args['columns'] ) )
35
+ $this->args['columns'] = 2;
36
+
37
+ parent::page_init();
38
+
39
+ add_action( 'load-' . $this->pagehook, array( $this, 'boxes_init' ) );
40
+ add_filter( 'screen_layout_columns', array( $this, 'columns' ) );
41
+ }
42
+
43
+ function default_css() {
44
+ ?>
45
+ <style type="text/css">
46
+ .postbox-container + .postbox-container {margin-left: 18px}
47
+ .postbox-container {padding-right: 0}
48
+
49
+ .inside {clear: both; overflow: hidden; padding: 10px 10px 0 10px !important}
50
+ .inside table {margin: 0 !important; padding: 0 !important}
51
+ .inside table td {vertical-align: middle !important}
52
+ .inside table .regular-text {width: 100% !important}
53
+ .inside .form-table th {width: 30%; max-width: 200px; padding: 10px 0 !important}
54
+ .inside .widefat .check-column {padding-bottom: 7px !important}
55
+ .inside p, .inside table {margin: 0 0 10px 0 !important}
56
+ .inside p.submit {float:left !important; padding: 0 !important}
57
+ </style>
58
+ <?php
59
+ }
60
+
61
+ function page_content() {
62
+ $this->default_css();
63
+
64
+ global $screen_layout_columns;
65
+
66
+ if ( isset( $screen_layout_columns ) ) {
67
+ $hide2 = $hide3 = $hide4 = '';
68
+ switch ( $screen_layout_columns ) {
69
+ case 4:
70
+ $width = 'width:24.5%;';
71
+ break;
72
+ case 3:
73
+ $width = 'width:32.67%;';
74
+ $hide4 = 'display:none;';
75
+ break;
76
+ case 2:
77
+ $width = 'width:49%;';
78
+ $hide3 = $hide4 = 'display:none;';
79
+ break;
80
+ default:
81
+ $width = 'width:98%;';
82
+ $hide2 = $hide3 = $hide4 = 'display:none;';
83
+ }
84
+ }
85
+ ?>
86
+ <div id='<?php echo $this->pagehook ?>-widgets' class='metabox-holder'>
87
+ <?php
88
+ echo "\t<div class='postbox-container' style='$width'>\n";
89
+ do_meta_boxes( $this->pagehook, 'normal', '' );
90
+
91
+ echo "\t</div><div class='postbox-container' style='{$hide2}$width'>\n";
92
+ do_meta_boxes( $this->pagehook, 'side', '' );
93
+
94
+ echo "\t</div><div class='postbox-container' style='{$hide3}$width'>\n";
95
+ do_meta_boxes( $this->pagehook, 'column3', '' );
96
+
97
+ echo "\t</div><div class='postbox-container' style='{$hide4}$width'>\n";
98
+ do_meta_boxes( $this->pagehook, 'column4', '' );
99
+ ?>
100
+ </div></div>
101
+ <?php
102
+ }
103
+
104
+ function page_footer() {
105
+ parent::page_footer();
106
+ $this->_boxes_js_init();
107
+ }
108
+
109
+ function form_handler() {
110
+ if ( empty( $_POST ) )
111
+ return;
112
+
113
+ check_admin_referer( $this->nonce );
114
+
115
+ // Box handler
116
+ foreach ( $this->boxes as $box ) {
117
+ $args = isset( $box[4] ) ? $box[4] : array();
118
+
119
+ $handler = $box[0] . '_handler';
120
+
121
+ if ( method_exists( $this, $handler ) )
122
+ call_user_func_array( array( $this, $handler ), $args );
123
+ }
124
+
125
+ if ( $this->options )
126
+ $this->formdata = $this->options->get();
127
+ }
128
+
129
+ function columns( $columns ) {
130
+ $columns[$this->pagehook] = $this->args['columns'];
131
+
132
+ return $columns;
133
+ }
134
+
135
+ function uninstall() {
136
+ global $wpdb;
137
+
138
+ $hook = str_replace( '-', '', $this->pagehook );
139
+
140
+ foreach ( array( 'metaboxhidden', 'closedpostboxes', 'wp_metaboxorder', 'screen_layout' ) as $option )
141
+ $keys[] = "'{$option}_{$hook}'";
142
+
143
+ $keys = '( ' . implode( ', ', $keys ) . ' )';
144
+
145
+ $wpdb->query( "
146
+ DELETE FROM {$wpdb->usermeta}
147
+ WHERE meta_key IN {$keys}
148
+ " );
149
+ }
150
+
151
+ function boxes_init() {
152
+ wp_enqueue_script( 'common' );
153
+ wp_enqueue_script( 'wp-lists' );
154
+ wp_enqueue_script( 'postbox' );
155
+
156
+ $registered = array();
157
+ foreach( $this->boxes as $box_args ) {
158
+ @list( $name, $title, $context, $priority, $args ) = $box_args;
159
+
160
+ if ( empty( $title ) )
161
+ $title = ucfirst( $name );
162
+ if ( empty( $context ) )
163
+ $context = 'normal';
164
+ if ( empty( $priority ) )
165
+ $priority = 'default';
166
+ if ( empty( $args ) )
167
+ $args = array();
168
+
169
+ if ( isset( $registered[$name] ) ) {
170
+ if ( empty( $args ) )
171
+ trigger_error( "Duplicate box name: $name", E_USER_NOTICE );
172
+
173
+ $name = $this->_increment( $name );
174
+ } else {
175
+ $registered[$name] = true;
176
+ }
177
+
178
+ add_meta_box( $name, $title, array( $this, '_intermediate_callback' ), $this->pagehook, $context, $priority, $args );
179
+ }
180
+ }
181
+
182
+ // Make it so that $args is actually what's passed to the callback
183
+ function _intermediate_callback( $_, $box ) {
184
+ list( $name ) = explode( '-', $box['id'] );
185
+
186
+ call_user_func_array( array( $this, $name . '_box' ), $box['args'] );
187
+ }
188
+
189
+ private function _increment( $name ) {
190
+ $parts = explode( '-', $name );
191
+ if ( isset( $parts[1] ) )
192
+ $parts[1]++;
193
+ else
194
+ $parts[1] = 2;
195
+
196
+ return implode( '-', $parts );
197
+ }
198
+
199
+ // Adds necesary code for JS to work
200
+ function _boxes_js_init() {
201
+ echo $this->js_wrap( <<<EOT
202
+ jQuery( document ).ready( function( $ ){
203
+ // close postboxes that should be closed
204
+ $( '.if-js-closed' ).removeClass( 'if-js-closed' ).addClass( 'closed' );
205
+ // postboxes setup
206
+ postboxes.add_postbox_toggles( '$this->pagehook' );
207
+ } );
208
+ EOT
209
+ );
210
+ ?>
211
+
212
+ <form style='display: none' method='get' action=''>
213
+ <p>
214
+ <?php
215
+ wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
216
+ wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
217
+ ?>
218
+ </p>
219
+ </form>
220
+ <?php
221
+ }
222
+ }
223
+
scb/Cron.php ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class scbCron {
4
+ protected $schedule;
5
+ protected $interval;
6
+ protected $time;
7
+
8
+ protected $hook;
9
+ protected $callback_args;
10
+
11
+ /**
12
+ * Create a new cron job
13
+ *
14
+ * @param string Reference to main plugin file
15
+ * @param array List of args:
16
+ string $action OR callback $callback
17
+ string $schedule OR number $interval
18
+ array $callback_args ( optional )
19
+ * @param bool Debug mode
20
+ */
21
+ function __construct( $file, $args, $debug = false ) {
22
+ $this->_set_args( $args );
23
+
24
+ scbUtil::add_activation_hook( $file, array( $this, 'reset' ) );
25
+ register_deactivation_hook( $file, array( $this, 'unschedule' ) );
26
+
27
+ add_filter( 'cron_schedules', array( $this, '_add_timing' ) );
28
+
29
+ if ( $debug )
30
+ self::debug();
31
+ }
32
+
33
+ /* Change the interval of the cron job
34
+ *
35
+ * @param array List of args:
36
+ string $schedule OR number $interval
37
+ timestamp $time ( optional )
38
+ */
39
+ function reschedule( $args ) {
40
+ extract( $args );
41
+
42
+ if ( $schedule && $this->schedule != $schedule ) {
43
+ $this->schedule = $schedule;
44
+ } elseif ( $interval && $this->interval != $interval ) {
45
+ $this->schedule = $interval . 'secs';
46
+ $this->interval = $interval;
47
+ }
48
+
49
+ $this->time = $time;
50
+
51
+ $this->reset();
52
+ }
53
+
54
+ /**
55
+ * Reset the schedule
56
+ */
57
+ function reset() {
58
+ $this->unschedule();
59
+ $this->schedule();
60
+ }
61
+
62
+ /**
63
+ * Clear the cron job
64
+ */
65
+ function unschedule() {
66
+ # wp_clear_scheduled_hook( $this->hook, $this->callback_args );
67
+ self::really_clear_scheduled_hook( $this->hook );
68
+ }
69
+
70
+ /**
71
+ * Execute the job now
72
+ */
73
+ function do_now() {
74
+ do_action( $this->hook );
75
+ }
76
+
77
+ /**
78
+ * Execute the job with a given delay
79
+ * @param int Delay in seconds
80
+ */
81
+ function do_once( $delay = 0 ) {
82
+ wp_schedule_single_event( time() + $delay, $this->hook, $this->callback_args );
83
+ }
84
+
85
+ /**
86
+ * Display current cron jobs
87
+ */
88
+ function debug() {
89
+ add_action( 'admin_footer', array( __CLASS__, '_debug' ) );
90
+ }
91
+
92
+
93
+ //_____INTERNAL METHODS_____
94
+
95
+
96
+ function _add_timing( $schedules ) {
97
+ if ( isset( $schedules[$this->schedule] ) )
98
+ return $schedules;
99
+
100
+ $schedules[$this->schedule] = array( 'interval' => $this->interval,
101
+ 'display' => $this->interval . ' seconds' );
102
+
103
+ return $schedules;
104
+ }
105
+
106
+ function _debug() {
107
+ if ( ! current_user_can( 'manage_options' ) )
108
+ return;
109
+
110
+ echo "<pre>";
111
+ print_r( get_option( 'cron' ) );
112
+ echo "</pre>";
113
+ }
114
+
115
+ protected function schedule() {
116
+ if ( ! $this->time )
117
+ $this->time = time();
118
+
119
+ wp_schedule_event( $this->time, $this->schedule, $this->hook, $this->callback_args );
120
+ }
121
+
122
+ protected function _set_args( $args ) {
123
+ extract( $args );
124
+
125
+ // Set hook
126
+ if ( isset( $action ) ) {
127
+ $this->hook = $action;
128
+ } elseif ( isset( $callback ) ) {
129
+ $this->hook = self::_callback_to_string( $callback );
130
+
131
+ add_action( $this->hook, $callback );
132
+ } elseif ( method_exists( $this, 'callback' ) ) {
133
+ $this->hook = self::_callback_to_string( $callback );
134
+
135
+ add_action( $this->hook, $callback );
136
+ } else {
137
+ trigger_error( '$action OR $callback not set', E_USER_WARNING );
138
+ }
139
+
140
+ // Set schedule
141
+ if ( isset( $interval ) ) {
142
+ $this->schedule = $interval . 'secs';
143
+ $this->interval = $interval;
144
+ } elseif ( isset( $schedule ) ) {
145
+ $this->schedule = $schedule;
146
+ } else {
147
+ trigger_error( '$schedule OR $interval not set', E_USER_WARNING );
148
+ }
149
+
150
+ if ( isset( $callback_args ) )
151
+ $this->callback_args = ( array ) $callback_args;
152
+ }
153
+
154
+ protected static function really_clear_scheduled_hook( $name ) {
155
+ $crons = _get_cron_array();
156
+
157
+ foreach ( $crons as $timestamp => $hooks ) {
158
+ foreach ( $hooks as $hook => $args )
159
+ if ( $hook == $name )
160
+ unset( $crons[$timestamp][$hook] );
161
+
162
+ if ( empty( $hooks ) )
163
+ unset( $crons[$timestamp] );
164
+ }
165
+
166
+ _set_cron_array( $crons );
167
+ }
168
+
169
+ protected static function _callback_to_string( $callback ) {
170
+ if ( ! is_array( $callback ) )
171
+ $str = $callback;
172
+ elseif ( ! is_string( $callback[0] ) )
173
+ $str = get_class( $callback[0] ) . '_' . $callback[1];
174
+ else
175
+ $str = $callback[0] . '::' . $callback[1];
176
+
177
+ $str .= '_hook';
178
+
179
+ return $str;
180
+ }
181
+ }
182
+
scb/Forms.php CHANGED
@@ -9,24 +9,24 @@ class scbForms {
9
  protected static $args;
10
  protected static $formdata = array();
11
 
12
- static function input($args, $formdata = array()) {
13
- $args = self::validate_data($args);
14
 
15
  $error = false;
16
- foreach ( array('name', 'value') as $key ) {
17
  $old = $key . 's';
18
 
19
- if ( isset($args[$old]) ) {
20
  $args[$key] = $args[$old];
21
- unset($args[$old]);
22
  }
23
  }
24
 
25
- if ( empty($args['name']) )
26
- return trigger_error('Empty name', E_USER_WARNING);
27
 
28
  self::$args = $args;
29
- self::$formdata = self::validate_data($formdata);
30
 
31
  if ( 'select' == $args['type'] )
32
  return self::_select();
@@ -35,82 +35,136 @@ class scbForms {
35
  }
36
 
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  // Generates a form
39
- static function form($inputs, $formdata = NULL, $nonce) {
40
  $output = '';
41
  foreach ( $inputs as $input )
42
- $output .= self::input($input, $formdata);
 
 
 
 
 
43
 
44
- $output = self::form_wrap($output, $nonce);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  return $output;
47
  }
48
 
49
  // Wraps the given content in a <form> tag
50
- static function form_wrap($content, $nonce = 'update_options') {
51
  $output = "\n<form method='post' action=''>\n";
52
  $output .= $content;
53
- $output .= wp_nonce_field($action = $nonce, $name = "_wpnonce", $referer = true , $echo = false);
54
  $output .= "\n</form>\n";
55
 
56
  return $output;
57
  }
58
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  // ____________PRIVATE METHODS____________
61
 
62
 
63
  // Recursivly transform empty arrays to ''
64
- private static function validate_data($data) {
65
- if ( !is_array($data) )
66
  return $data;
67
 
68
- if ( empty($data) )
69
  return '';
70
 
71
  foreach ( $data as $key => &$value )
72
- $value = self::validate_data($value);
73
 
74
  return $data;
75
  }
76
 
77
  // From multiple inputs to single inputs
78
  private static function _input() {
79
- extract(wp_parse_args(self::$args, array(
80
  'name' => NULL,
81
  'value' => NULL,
82
  'desc' => NULL,
83
  'checked' => NULL,
84
- )));
85
 
86
- $m_name = is_array($name);
87
- $m_value = is_array($value);
88
- $m_desc = is_array($desc);
89
 
90
  // Correct name
91
  if ( !$m_name && $m_value
92
  && 'checkbox' == $type
93
- && false === strpos($name, '[')
94
  )
95
  $args['name'] = $name = $name . '[]';
96
 
97
  // Expand names or values
98
  if ( !$m_name && !$m_value ) {
99
- $a = array($name => $value);
100
  }
101
  elseif ( $m_name && !$m_value ) {
102
- $a = array_fill_keys($name, $value);
103
  }
104
  elseif ( !$m_name && $m_value ) {
105
- $a = array_fill_keys($value, $name);
106
  }
107
  else {
108
- $a = array_combine($name, $value);
109
  }
110
 
111
  // Correct descriptions
112
  $_after = '';
113
- if ( isset($desc) && !$m_desc && false === strpos($desc, self::token) ) {
114
  if ( $m_value ) {
115
  $_after = $desc;
116
  $args['desc'] = $desc = $value;
@@ -130,12 +184,15 @@ class scbForms {
130
  $i2 = 'val';
131
  }
132
 
133
- $func = in_array($type, array('checkbox', 'radio')) ? '_checkbox_single' : '_input_single';
134
 
135
  // Set constant args
136
- $const_args = self::array_extract(self::$args, array('type', 'desc_pos', 'checked'));
137
- if ( isset($extra) )
138
- $const_args['extra'] = explode(' ', $extra);
 
 
 
139
 
140
  $i = 0;
141
  foreach ( $a as $name => $val ) {
@@ -148,120 +205,120 @@ class scbForms {
148
  $cur_args['value'] = $$i2;
149
 
150
  // Set desc
151
- if ( is_array($desc) )
152
  $cur_args['desc'] = $desc[$i];
153
- elseif ( isset($desc) )
154
  $cur_args['desc'] = $desc;
155
 
156
  // Find relevant formdata
157
  $match = NULL;
158
  if ( $checked === NULL ) {
159
- $match = @self::$formdata[str_replace('[]', '', $$i1)];
160
- if ( is_array($match) ) {
161
  $match = $match[$i];
162
  }
163
- } else if ( is_array($checked) ) {
164
- $cur_args['checked'] = isset($checked[$i]) && $checked[$i];
165
  }
166
 
167
- $output[] = self::$func($cur_args, $match);
168
 
169
  $i++;
170
  }
171
 
172
- return implode("\n", $output) . $_after;
173
  }
174
 
175
  // Handle args for checkboxes and radio inputs
176
- private static function _checkbox_single($args, $data) {
177
- $args = wp_parse_args($args, array(
178
  'name' => NULL,
179
  'value' => true,
180
  'desc_pos' => 'after',
181
  'desc' => NULL,
182
  'checked' => NULL,
183
  'extra' => array(),
184
- ));
185
 
186
  foreach ( $args as $key => &$val )
187
  $$key = &$val;
188
- unset($val);
189
 
190
  if ( $checked === NULL && $value == $data )
191
  $checked = true;
192
 
193
  if ( $checked )
194
- $extra[] = 'checked="checked"';
195
 
196
- if ( $desc === NULL && !is_bool($value) )
197
- $desc = str_replace('[]', '', $value);
198
 
199
- return self::_input_gen($args);
200
  }
201
 
202
  // Handle args for text inputs
203
- private static function _input_single($args, $data) {
204
- $args = wp_parse_args($args, array(
205
  'value' => $data,
206
  'desc_pos' => 'after',
207
- 'extra' => array('class="regular-text"'),
208
- ));
209
 
210
  foreach ( $args as $key => &$val )
211
  $$key = &$val;
212
- unset($val);
213
 
214
- if ( FALSE === strpos($name, '[') )
215
- $extra[] = "id='{$name}'";
216
 
217
- return self::_input_gen($args);
218
  }
219
 
220
  // Generate html with the final args
221
- private static function _input_gen($args) {
222
- extract(wp_parse_args($args, array(
223
  'name' => NULL,
224
  'value' => NULL,
225
  'desc' => NULL,
226
  'extra' => array()
227
- )));
228
 
229
- $extra = self::validate_extra($extra, $name);
230
 
231
  if ( 'textarea' == $type ) {
232
- $value = esc_html($value);
233
- $input = "<textarea name='{$name}'{$extra}>\n{$value}\n</textarea>\n";
234
  }
235
  else {
236
- $value = esc_attr($value);
237
  $input = "<input name='{$name}' value='{$value}' type='{$type}'{$extra} /> ";
238
  }
239
 
240
- return self::add_label($input, $desc, $desc_pos);
241
  }
242
 
243
  private static function _select() {
244
- extract(wp_parse_args(self::$args, array(
245
  'name' => '',
246
  'value' => array(),
247
  'text' => '',
248
- 'selected' => array('foo'), // hack to make default blank
249
- 'extra' => '',
250
  'numeric' => false, // use numeric array instead of associative
251
  'desc' => '',
252
  'desc_pos' => '',
253
- )), EXTR_SKIP);
254
 
255
- if ( empty($value) )
256
- $value = array('' => '');
257
 
258
- if ( !is_array($value) )
259
- return trigger_error("'value' argument is expected to be an array", E_USER_WARNING);
260
 
261
- if ( !self::is_associative($value) && !$numeric )
262
- $value = array_combine($value, $value);
263
 
264
- if ( isset(self::$formdata[$name]) )
265
  $cur_val = self::$formdata[$name];
266
  else
267
  $cur_val = $selected;
@@ -269,39 +326,32 @@ class scbForms {
269
  if ( false === $text ) {
270
  $opts = '';
271
  } else {
272
- $opts = "\t<option value=''";
273
- if ( $cur_val === array('foo') )
274
- $opts .= " selected='selected'";
275
- $opts .= ">{$text}</option>\n";
276
  }
277
 
278
  foreach ( $value as $key => $value ) {
279
- if ( empty($key) || empty($value) )
280
  continue;
281
 
282
- $cur_extra = array();
283
- if ( (string) $key == (string) $cur_val )
284
- $cur_extra[] = "selected='selected'";
285
-
286
- $cur_extra = self::validate_extra($cur_extra, $key);
287
-
288
- $opts .= "\t<option value='{$key}'{$cur_extra}>{$value}</option>\n";
289
  }
290
 
291
- $extra = self::validate_extra($extra, $name);
 
 
292
 
293
  $input = "<select name='{$name}'$extra>\n{$opts}</select>";
294
 
295
- return self::add_label($input, $desc, $desc_pos);
296
  }
297
 
298
- private static function add_label($input, $desc, $desc_pos) {
299
- if ( empty($desc_pos) )
300
  $desc_pos = 'after';
301
 
302
  $label = '';
303
- if ( false === strpos($desc, self::token) ) {
304
- switch ($desc_pos) {
305
  case 'before': $label = $desc . ' ' . self::token; break;
306
  case 'after': $label = self::token . ' ' . $desc;
307
  }
@@ -309,9 +359,9 @@ class scbForms {
309
  $label = $desc;
310
  }
311
 
312
- $label = trim(str_replace(self::token, $input, $label));
313
 
314
- if ( empty($desc) )
315
  $output = $input . "\n";
316
  else
317
  $output = "<label>{$label}</label>\n";
@@ -319,31 +369,35 @@ class scbForms {
319
  return $output;
320
  }
321
 
322
- private static function validate_extra($extra, $name, $implode = true) {
323
- if ( !is_array($extra) )
324
- $extra = explode(' ', $extra);
325
 
326
- if ( empty($extra) )
327
- return '';
328
 
329
- return ' ' . ltrim(implode(' ', $extra));
 
 
330
  }
331
 
332
- // Utilities
 
 
 
 
 
 
333
 
334
- private static function is_associative($array) {
335
- if ( !is_array($array) || empty($array) )
336
  return false;
337
 
338
- $keys = array_keys($array);
339
 
340
- return array_keys($keys) !== $keys;
341
  }
342
 
343
- private static function array_extract($array, $keys) {
344
  $r = array();
345
  foreach ( $keys as $key )
346
- if ( isset($array[$key]) )
347
  $r[$key] = $array[$key];
348
 
349
  return $r;
@@ -351,10 +405,10 @@ class scbForms {
351
  }
352
 
353
  // PHP < 5.2
354
- if ( !function_exists('array_fill_keys') ) :
355
- function array_fill_keys($keys, $value) {
356
- if ( !is_array($keys) )
357
- trigger_error('First argument is expected to be an array.' . gettype($keys) . 'given', E_USER_WARNING);
358
 
359
  $r = array();
360
  foreach ( $keys as $key )
9
  protected static $args;
10
  protected static $formdata = array();
11
 
12
+ static function input( $args, $formdata = array() ) {
13
+ $args = self::validate_data( $args );
14
 
15
  $error = false;
16
+ foreach ( array( 'name', 'value' ) as $key ) {
17
  $old = $key . 's';
18
 
19
+ if ( isset( $args[$old] ) ) {
20
  $args[$key] = $args[$old];
21
+ unset( $args[$old] );
22
  }
23
  }
24
 
25
+ if ( empty( $args['name'] ) )
26
+ return trigger_error( 'Empty name', E_USER_WARNING );
27
 
28
  self::$args = $args;
29
+ self::$formdata = self::validate_data( $formdata );
30
 
31
  if ( 'select' == $args['type'] )
32
  return self::_select();
35
  }
36
 
37
 
38
+ // ____________UTILITIES____________
39
+
40
+
41
+ // Generates a table wrapped in a form
42
+ static function form_table( $rows, $formdata = NULL ) {
43
+ $output = '';
44
+ foreach ( $rows as $row )
45
+ $output .= self::table_row( $row, $formdata );
46
+
47
+ $output = self::form_table_wrap( $output );
48
+
49
+ return $output;
50
+ }
51
+
52
  // Generates a form
53
+ static function form( $inputs, $formdata = NULL, $nonce ) {
54
  $output = '';
55
  foreach ( $inputs as $input )
56
+ $output .= self::input( $input, $formdata );
57
+
58
+ $output = self::form_wrap( $output, $nonce );
59
+
60
+ return $output;
61
+ }
62
 
63
+ // Generates a table
64
+ static function table( $rows, $formdata = NULL ) {
65
+ $output = '';
66
+ foreach ( $rows as $row )
67
+ $output .= self::table_row( $row, $formdata );
68
+
69
+ $output = self::table_wrap( $output );
70
+
71
+ return $output;
72
+ }
73
+
74
+ // Generates a table row
75
+ static function table_row( $args, $formdata = NULL ) {
76
+ return self::row_wrap( $args['title'], self::input( $args, $formdata ) );
77
+ }
78
+
79
+
80
+ // ____________WRAPPERS____________
81
+
82
+
83
+ // Wraps the given content in a <form><table>
84
+ static function form_table_wrap( $content, $nonce = 'update_options' ) {
85
+ $output = self::table_wrap( $content );
86
+ $output = self::form_wrap( $output, $nonce );
87
 
88
  return $output;
89
  }
90
 
91
  // Wraps the given content in a <form> tag
92
+ static function form_wrap( $content, $nonce = 'update_options' ) {
93
  $output = "\n<form method='post' action=''>\n";
94
  $output .= $content;
95
+ $output .= wp_nonce_field( $action = $nonce, $name = "_wpnonce", $referer = true , $echo = false );
96
  $output .= "\n</form>\n";
97
 
98
  return $output;
99
  }
100
 
101
+ // Wraps the given content in a <table>
102
+ static function table_wrap( $content ) {
103
+ $output = "\n<table class='form-table'>\n" . $content . "\n</table>\n";
104
+
105
+ return $output;
106
+ }
107
+
108
+ // Wraps the given content in a <tr><td>
109
+ static function row_wrap( $title, $content ) {
110
+ return "\n<tr>\n\t<th scope='row'>" . $title . "</th>\n\t<td>\n\t\t" . $content . "\t</td>\n\n</tr>";
111
+ }
112
+
113
 
114
  // ____________PRIVATE METHODS____________
115
 
116
 
117
  // Recursivly transform empty arrays to ''
118
+ private static function validate_data( $data ) {
119
+ if ( !is_array( $data ) )
120
  return $data;
121
 
122
+ if ( empty( $data ) )
123
  return '';
124
 
125
  foreach ( $data as $key => &$value )
126
+ $value = self::validate_data( $value );
127
 
128
  return $data;
129
  }
130
 
131
  // From multiple inputs to single inputs
132
  private static function _input() {
133
+ extract( wp_parse_args( self::$args, array(
134
  'name' => NULL,
135
  'value' => NULL,
136
  'desc' => NULL,
137
  'checked' => NULL,
138
+ ) ) );
139
 
140
+ $m_name = is_array( $name );
141
+ $m_value = is_array( $value );
142
+ $m_desc = is_array( $desc );
143
 
144
  // Correct name
145
  if ( !$m_name && $m_value
146
  && 'checkbox' == $type
147
+ && false === strpos( $name, '[' )
148
  )
149
  $args['name'] = $name = $name . '[]';
150
 
151
  // Expand names or values
152
  if ( !$m_name && !$m_value ) {
153
+ $a = array( $name => $value );
154
  }
155
  elseif ( $m_name && !$m_value ) {
156
+ $a = array_fill_keys( $name, $value );
157
  }
158
  elseif ( !$m_name && $m_value ) {
159
+ $a = array_fill_keys( $value, $name );
160
  }
161
  else {
162
+ $a = array_combine( $name, $value );
163
  }
164
 
165
  // Correct descriptions
166
  $_after = '';
167
+ if ( isset( $desc ) && !$m_desc && false === strpos( $desc, self::token ) ) {
168
  if ( $m_value ) {
169
  $_after = $desc;
170
  $args['desc'] = $desc = $value;
184
  $i2 = 'val';
185
  }
186
 
187
+ $func = in_array( $type, array( 'checkbox', 'radio' ) ) ? '_checkbox_single' : '_input_single';
188
 
189
  // Set constant args
190
+ $const_args = self::array_extract( self::$args, array( 'type', 'desc_pos', 'checked' ) );
191
+ if ( isset( $extra ) ) {
192
+ if ( !is_array( $extra ) )
193
+ $extra = self::attr_to_array( $extra );
194
+ $const_args['extra'] = $extra;
195
+ }
196
 
197
  $i = 0;
198
  foreach ( $a as $name => $val ) {
205
  $cur_args['value'] = $$i2;
206
 
207
  // Set desc
208
+ if ( is_array( $desc ) )
209
  $cur_args['desc'] = $desc[$i];
210
+ elseif ( isset( $desc ) )
211
  $cur_args['desc'] = $desc;
212
 
213
  // Find relevant formdata
214
  $match = NULL;
215
  if ( $checked === NULL ) {
216
+ $match = @self::$formdata[str_replace( '[]', '', $$i1 )];
217
+ if ( is_array( $match ) ) {
218
  $match = $match[$i];
219
  }
220
+ } else if ( is_array( $checked ) ) {
221
+ $cur_args['checked'] = isset( $checked[$i] ) && $checked[$i];
222
  }
223
 
224
+ $output[] = self::$func( $cur_args, $match );
225
 
226
  $i++;
227
  }
228
 
229
+ return implode( "\n", $output ) . $_after;
230
  }
231
 
232
  // Handle args for checkboxes and radio inputs
233
+ private static function _checkbox_single( $args, $data ) {
234
+ $args = wp_parse_args( $args, array(
235
  'name' => NULL,
236
  'value' => true,
237
  'desc_pos' => 'after',
238
  'desc' => NULL,
239
  'checked' => NULL,
240
  'extra' => array(),
241
+ ) );
242
 
243
  foreach ( $args as $key => &$val )
244
  $$key = &$val;
245
+ unset( $val );
246
 
247
  if ( $checked === NULL && $value == $data )
248
  $checked = true;
249
 
250
  if ( $checked )
251
+ $extra['checked'] = 'checked';
252
 
253
+ if ( is_null( $desc ) && !is_bool( $value ) )
254
+ $desc = str_replace( '[]', '', $value );
255
 
256
+ return self::_input_gen( $args );
257
  }
258
 
259
  // Handle args for text inputs
260
+ private static function _input_single( $args, $data ) {
261
+ $args = wp_parse_args( $args, array(
262
  'value' => $data,
263
  'desc_pos' => 'after',
264
+ 'extra' => array( 'class' => 'regular-text' ),
265
+ ) );
266
 
267
  foreach ( $args as $key => &$val )
268
  $$key = &$val;
269
+ unset( $val );
270
 
271
+ if ( FALSE === strpos( $name, '[' ) )
272
+ $extra['id'] = $name;
273
 
274
+ return self::_input_gen( $args );
275
  }
276
 
277
  // Generate html with the final args
278
+ private static function _input_gen( $args ) {
279
+ extract( wp_parse_args( $args, array(
280
  'name' => NULL,
281
  'value' => NULL,
282
  'desc' => NULL,
283
  'extra' => array()
284
+ ) ) );
285
 
286
+ $extra = self::array_to_attr( $extra );
287
 
288
  if ( 'textarea' == $type ) {
289
+ $value = esc_html( $value );
290
+ $input = "<textarea name='{$name}'{$extra}>{$value}</textarea>\n";
291
  }
292
  else {
293
+ $value = esc_attr( $value );
294
  $input = "<input name='{$name}' value='{$value}' type='{$type}'{$extra} /> ";
295
  }
296
 
297
+ return self::add_label( $input, $desc, $desc_pos );
298
  }
299
 
300
  private static function _select() {
301
+ extract( wp_parse_args( self::$args, array(
302
  'name' => '',
303
  'value' => array(),
304
  'text' => '',
305
+ 'selected' => array( 'foo' ), // hack to make default blank
306
+ 'extra' => array(),
307
  'numeric' => false, // use numeric array instead of associative
308
  'desc' => '',
309
  'desc_pos' => '',
310
+ ) ), EXTR_SKIP );
311
 
312
+ if ( empty( $value ) )
313
+ $value = array( '' => '' );
314
 
315
+ if ( !is_array( $value ) )
316
+ return trigger_error( "'value' argument is expected to be an array", E_USER_WARNING );
317
 
318
+ if ( !self::is_associative( $value ) && !$numeric )
319
+ $value = array_combine( $value, $value );
320
 
321
+ if ( isset( self::$formdata[$name] ) )
322
  $cur_val = self::$formdata[$name];
323
  else
324
  $cur_val = $selected;
326
  if ( false === $text ) {
327
  $opts = '';
328
  } else {
329
+ $opts = "\t<option value=''" . selected( $cur_val, array( 'foo' ), false ) . ">{$text}</option>\n";
 
 
 
330
  }
331
 
332
  foreach ( $value as $key => $value ) {
333
+ if ( empty( $key ) || empty( $value ) )
334
  continue;
335
 
336
+ $opts .= "\t<option value='{$key}'" . selected( (string) $key, (string) $cur_val, false) . '>' . $value . "</option>\n";
 
 
 
 
 
 
337
  }
338
 
339
+ if ( !is_array( $extra ) )
340
+ $extra = self::attr_to_array( $extra );
341
+ $extra = self::array_to_attr( $extra );
342
 
343
  $input = "<select name='{$name}'$extra>\n{$opts}</select>";
344
 
345
+ return self::add_label( $input, $desc, $desc_pos );
346
  }
347
 
348
+ private static function add_label( $input, $desc, $desc_pos ) {
349
+ if ( empty( $desc_pos ) )
350
  $desc_pos = 'after';
351
 
352
  $label = '';
353
+ if ( false === strpos( $desc, self::token ) ) {
354
+ switch ( $desc_pos ) {
355
  case 'before': $label = $desc . ' ' . self::token; break;
356
  case 'after': $label = self::token . ' ' . $desc;
357
  }
359
  $label = $desc;
360
  }
361
 
362
+ $label = trim( str_replace( self::token, $input, $label ) );
363
 
364
+ if ( empty( $desc ) )
365
  $output = $input . "\n";
366
  else
367
  $output = "<label>{$label}</label>\n";
369
  return $output;
370
  }
371
 
 
 
 
372
 
373
+ // Utilities
 
374
 
375
+
376
+ private static function attr_to_array( $html ) {
377
+ return shortcode_parse_atts( $html );
378
  }
379
 
380
+ private static function array_to_attr( $attr ) {
381
+ $out = '';
382
+ foreach ( $attr as $key => $value )
383
+ $out .= ' ' . $key . '=' . '"' . esc_attr( $value ) . '"';
384
+
385
+ return $out;
386
+ }
387
 
388
+ private static function is_associative( $array ) {
389
+ if ( !is_array( $array ) || empty( $array ) )
390
  return false;
391
 
392
+ $keys = array_keys( $array );
393
 
394
+ return array_keys( $keys ) !== $keys;
395
  }
396
 
397
+ private static function array_extract( $array, $keys ) {
398
  $r = array();
399
  foreach ( $keys as $key )
400
+ if ( isset( $array[$key] ) )
401
  $r[$key] = $array[$key];
402
 
403
  return $r;
405
  }
406
 
407
  // PHP < 5.2
408
+ if ( !function_exists( 'array_fill_keys' ) ) :
409
+ function array_fill_keys( $keys, $value ) {
410
+ if ( !is_array( $keys ) )
411
+ trigger_error( 'First argument is expected to be an array.' . gettype( $keys ) . 'given', E_USER_WARNING );
412
 
413
  $r = array();
414
  foreach ( $keys as $key )
scb/Options.php CHANGED
@@ -6,7 +6,7 @@ class scbOptions {
6
 
7
  protected $key; // the option name
8
 
9
- protected $defaults; // the default value(s)
10
 
11
  public $wp_filter_id; // used by WP hooks
12
 
@@ -15,16 +15,15 @@ class scbOptions {
15
  *
16
  * @param string $key Option name
17
  * @param string $file Reference to main plugin file
18
- * @param array $defaults An associative array of default values (optional)
19
  */
20
- public function __construct($key, $file, $defaults = '') {
21
  $this->key = $key;
22
  $this->defaults = $defaults;
23
 
24
- if ( is_array($this->defaults) )
25
- register_activation_hook($file, array($this, '_update_reset'));
26
 
27
- scbUtil::add_uninstall_hook($file, array($this, 'delete'));
28
  }
29
 
30
  /**
@@ -37,42 +36,42 @@ class scbOptions {
37
  /**
38
  * Get option values for one, many or all fields
39
  *
40
- * @param string|array $field The field(s) to get
41
  * @return mixed Whatever is in those fields
42
  */
43
- public function get($field = '') {
44
- $data = get_option($this->key);
45
 
46
- if ( is_array($this->defaults) )
47
- $data = (array) $data;
48
 
49
- return $this->_get($field, $data);
50
  }
51
 
52
  /**
53
  * Get default values for one, many or all fields
54
  *
55
- * @param string|array $field The field(s) to get
56
  * @return mixed Whatever is in those fields
57
  */
58
- public function get_defaults($field = '') {
59
- return $this->_get($field, $this->defaults);
60
  }
61
 
62
  /**
63
  * Set all data fields, certain fields or a single field
64
  *
65
  * @param string|array $field The field to update or an associative array
66
- * @param mixed $value The new value (ignored if $field is array)
67
  * @return null
68
  */
69
- public function set($field, $value = '') {
70
- if ( is_array($field) )
71
  $newdata = $field;
72
  else
73
- $newdata = array($field => $value);
74
 
75
- $this->update(array_merge($this->get(), $newdata));
76
  }
77
 
78
  /**
@@ -81,7 +80,7 @@ class scbOptions {
81
  * @return null
82
  */
83
  public function reset() {
84
- $this->update($this->defaults, false);
85
  }
86
 
87
  /**
@@ -90,7 +89,7 @@ class scbOptions {
90
  * @return bool
91
  */
92
  public function cleanup() {
93
- $this->update($this->_clean($this->get()));
94
  }
95
 
96
  /**
@@ -100,11 +99,11 @@ class scbOptions {
100
  * @param bool $clean wether to remove unrecognized keys or not
101
  * @return null
102
  */
103
- public function update($newdata, $clean = true) {
104
  if ( $clean )
105
- $newdata = $this->_clean($newdata);
106
 
107
- update_option($this->key, $newdata);
108
  }
109
 
110
  /**
@@ -113,7 +112,7 @@ class scbOptions {
113
  * @return null
114
  */
115
  public function delete() {
116
- delete_option($this->key);
117
  }
118
 
119
 
@@ -122,49 +121,52 @@ class scbOptions {
122
 
123
  // Add new fields with their default values
124
  function _update_reset() {
125
- $this->update(array_merge($this->defaults, $this->get()));
 
 
 
126
  }
127
 
128
- private function _clean($data) {
129
- if ( !is_array($data) || !is_array($this->defaults) )
130
  return $data;
131
 
132
  $r = array();
133
- foreach ( array_keys($this->defaults) as $key )
134
  $r[$key] = @$data[$key];
135
 
136
  return $r;
137
  }
138
 
139
  // Get one, more or all fields from an array
140
- private function _get($field, $data) {
141
- if ( empty($field) )
142
  return $data;
143
 
144
- if ( is_string($field) )
145
  return $data[$field];
146
 
147
  foreach ( $field as $key )
148
- if ( isset($data[$key]) )
149
  $result[] = $data[$key];
150
 
151
  return $result;
152
  }
153
 
154
  // Magic method: $options->field
155
- function __get($field) {
156
- return $this->get($field);
157
  }
158
 
159
  // Magic method: $options->field = $value
160
- function __set($field, $value) {
161
- $this->set($field, $value);
162
  }
163
 
164
- // Magic method: isset($options->field)
165
- function __isset($field) {
166
  $data = $this->get();
167
- return isset($data[$field]);
168
  }
169
  }
170
 
6
 
7
  protected $key; // the option name
8
 
9
+ protected $defaults; // the default value( s )
10
 
11
  public $wp_filter_id; // used by WP hooks
12
 
15
  *
16
  * @param string $key Option name
17
  * @param string $file Reference to main plugin file
18
+ * @param array $defaults An associative array of default values ( optional )
19
  */
20
+ public function __construct( $key, $file, $defaults = '' ) {
21
  $this->key = $key;
22
  $this->defaults = $defaults;
23
 
24
+ scbUtil::add_activation_hook( $file, array( $this, '_update_reset' ) );
 
25
 
26
+ scbUtil::add_uninstall_hook( $file, array( $this, 'delete' ) );
27
  }
28
 
29
  /**
36
  /**
37
  * Get option values for one, many or all fields
38
  *
39
+ * @param string|array $field The field( s ) to get
40
  * @return mixed Whatever is in those fields
41
  */
42
+ public function get( $field = '' ) {
43
+ $data = get_option( $this->key );
44
 
45
+ if ( is_array( $this->defaults ) )
46
+ $data = ( array ) $data;
47
 
48
+ return $this->_get( $field, $data );
49
  }
50
 
51
  /**
52
  * Get default values for one, many or all fields
53
  *
54
+ * @param string|array $field The field( s ) to get
55
  * @return mixed Whatever is in those fields
56
  */
57
+ public function get_defaults( $field = '' ) {
58
+ return $this->_get( $field, $this->defaults );
59
  }
60
 
61
  /**
62
  * Set all data fields, certain fields or a single field
63
  *
64
  * @param string|array $field The field to update or an associative array
65
+ * @param mixed $value The new value ( ignored if $field is array )
66
  * @return null
67
  */
68
+ public function set( $field, $value = '' ) {
69
+ if ( is_array( $field ) )
70
  $newdata = $field;
71
  else
72
+ $newdata = array( $field => $value );
73
 
74
+ $this->update( array_merge( $this->get(), $newdata ) );
75
  }
76
 
77
  /**
80
  * @return null
81
  */
82
  public function reset() {
83
+ $this->update( $this->defaults, false );
84
  }
85
 
86
  /**
89
  * @return bool
90
  */
91
  public function cleanup() {
92
+ $this->update( $this->_clean( $this->get() ) );
93
  }
94
 
95
  /**
99
  * @param bool $clean wether to remove unrecognized keys or not
100
  * @return null
101
  */
102
+ public function update( $newdata, $clean = true ) {
103
  if ( $clean )
104
+ $newdata = $this->_clean( $newdata );
105
 
106
+ update_option( $this->key, $newdata );
107
  }
108
 
109
  /**
112
  * @return null
113
  */
114
  public function delete() {
115
+ delete_option( $this->key );
116
  }
117
 
118
 
121
 
122
  // Add new fields with their default values
123
  function _update_reset() {
124
+ if ( is_array( $this->defaults ) )
125
+ $this->update( array_merge( $this->defaults, $this->get() ) );
126
+ else
127
+ add_option( $this->key, $this->defaults );
128
  }
129
 
130
+ private function _clean( $data ) {
131
+ if ( !is_array( $data ) || !is_array( $this->defaults ) )
132
  return $data;
133
 
134
  $r = array();
135
+ foreach ( array_keys( $this->defaults ) as $key )
136
  $r[$key] = @$data[$key];
137
 
138
  return $r;
139
  }
140
 
141
  // Get one, more or all fields from an array
142
+ private function &_get( $field, $data ) {
143
+ if ( empty( $field ) )
144
  return $data;
145
 
146
+ if ( is_string( $field ) )
147
  return $data[$field];
148
 
149
  foreach ( $field as $key )
150
+ if ( isset( $data[$key] ) )
151
  $result[] = $data[$key];
152
 
153
  return $result;
154
  }
155
 
156
  // Magic method: $options->field
157
+ function __get( $field ) {
158
+ return $this->get( $field );
159
  }
160
 
161
  // Magic method: $options->field = $value
162
+ function __set( $field, $value ) {
163
+ $this->set( $field, $value );
164
  }
165
 
166
+ // Magic method: isset( $options->field )
167
+ function __isset( $field ) {
168
  $data = $this->get();
169
+ return isset( $data[$field] );
170
  }
171
  }
172
 
scb/QueryManipulation.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class scbQueryManipulation {
4
+
5
+ private $bits = array();
6
+ private $wp_query;
7
+
8
+ private static $filters = array(
9
+ 'posts_where',
10
+ 'posts_join',
11
+ 'posts_groupby',
12
+ 'posts_orderby',
13
+ 'posts_distinct',
14
+ 'post_limits',
15
+ 'posts_fields'
16
+ );
17
+
18
+ public function __construct( $callback, $once = true ) {
19
+ $this->callback = $callback;
20
+
21
+ $this->enable();
22
+
23
+ if ( !$once )
24
+ return;
25
+
26
+ add_filter( 'posts_request', array( $this, '_disable' ) );
27
+ }
28
+
29
+ function _disable( $request ) {
30
+ remove_filter( 'posts_request', array( $this, '_disable' ) );
31
+
32
+ $this->disable();
33
+
34
+ return $request;
35
+ }
36
+
37
+ public function enable() {
38
+ foreach ( self::$filters as $filter ) {
39
+ add_filter( $filter, array( $this, 'collect' ), 999, 2 );
40
+ add_filter( $filter . '_request' , array( $this, 'update' ), 9 );
41
+ }
42
+
43
+ add_action( 'posts_selection' , array( $this, 'alter' ) );
44
+ }
45
+
46
+ public function disable() {
47
+ foreach ( self::$filters as $filter ) {
48
+ remove_filter( $filter, array( $this, 'collect' ), 999, 2 );
49
+ remove_filter( $filter . '_request' , array( $this, 'update' ), 9 );
50
+ }
51
+
52
+ remove_action( 'posts_selection' , array( $this, 'alter' ) );
53
+ }
54
+
55
+ function collect( $value, $wp_query ) {
56
+ // remove 'posts_'
57
+ $key = explode( '_', current_filter() );
58
+ $key = array_slice( $key, 1 );
59
+ $key = implode( '_', $key );
60
+
61
+ $this->bits[ $key ] = $value;
62
+
63
+ $this->wp_query = $wp_query;
64
+
65
+ return $value;
66
+ }
67
+
68
+ function alter( $query ) {
69
+ $this->bits = call_user_func( $this->callback, $this->bits, $this->wp_query );
70
+ }
71
+
72
+ function update( $value ) {
73
+ // remove 'posts_' and '_request'
74
+ $key = explode( '_', current_filter() );
75
+ $key = array_slice( $key, 1, -1 );
76
+ $key = implode( '_', $key );
77
+
78
+ return $this->bits[ $key ];
79
+ }
80
+ }
81
+
scb/Table.php CHANGED
@@ -4,15 +4,17 @@
4
  class scbTable {
5
  protected $name;
6
  protected $columns;
 
7
 
8
- function __construct($name, $file, $columns) {
9
  global $wpdb;
10
 
11
  $this->name = $wpdb->$name = $wpdb->prefix . $name;
12
  $this->columns = $columns;
 
13
 
14
- register_activation_hook($file, array($this, 'install'));
15
- scbUtil::add_uninstall_hook($file, array($this, 'uninstall'));
16
  }
17
 
18
  function install() {
@@ -20,21 +22,28 @@ class scbTable {
20
 
21
  $charset_collate = '';
22
  if ( $wpdb->has_cap( 'collation' ) ) {
23
- if ( ! empty($wpdb->charset) )
24
  $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
25
- if ( ! empty($wpdb->collate) )
26
  $charset_collate .= " COLLATE $wpdb->collate";
27
  }
28
 
29
- require_once ABSPATH . 'wp-admin/includes/upgrade.php';
 
 
 
 
 
 
 
30
 
31
- dbDelta("CREATE TABLE $this->name ($this->columns) $charset_collate;");
32
  }
33
 
34
  function uninstall() {
35
  global $wpdb;
36
 
37
- $wpdb->query("DROP TABLE IF EXISTS $this->name");
38
  }
39
  }
40
 
4
  class scbTable {
5
  protected $name;
6
  protected $columns;
7
+ protected $upgrade_method;
8
 
9
+ function __construct( $name, $file, $columns, $upgrade_method = 'dbDelta' ) {
10
  global $wpdb;
11
 
12
  $this->name = $wpdb->$name = $wpdb->prefix . $name;
13
  $this->columns = $columns;
14
+ $this->upgrade_method = $upgrade_method;
15
 
16
+ scbUtil::add_activation_hook( $file, array( $this, 'install' ) );
17
+ scbUtil::add_uninstall_hook( $file, array( $this, 'uninstall' ) );
18
  }
19
 
20
  function install() {
22
 
23
  $charset_collate = '';
24
  if ( $wpdb->has_cap( 'collation' ) ) {
25
+ if ( ! empty( $wpdb->charset ) )
26
  $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
27
+ if ( ! empty( $wpdb->collate ) )
28
  $charset_collate .= " COLLATE $wpdb->collate";
29
  }
30
 
31
+ if ( 'dbDelta' == $this->upgrade_method ) {
32
+ require_once ABSPATH . 'wp-admin/includes/upgrade.php';
33
+ dbDelta( "CREATE TABLE $this->name ( $this->columns ) $charset_collate" );
34
+ return;
35
+ }
36
+
37
+ if ( 'delete_first' == $this->upgrade_method )
38
+ $wpdb->query( "DROP TABLE IF EXISTS $this->name;" );
39
 
40
+ $wpdb->query( "CREATE TABLE IF NOT EXISTS $this->name ( $this->columns ) $charset_collate;" );
41
  }
42
 
43
  function uninstall() {
44
  global $wpdb;
45
 
46
+ $wpdb->query( "DROP TABLE IF EXISTS $this->name" );
47
  }
48
  }
49
 
scb/Util.php CHANGED
@@ -3,73 +3,77 @@
3
  class scbUtil {
4
 
5
  // Force script enqueue
6
- static function do_scripts($handles) {
7
  global $wp_scripts;
8
 
9
- if ( ! is_a($wp_scripts, 'WP_Scripts') )
10
  $wp_scripts = new WP_Scripts();
11
 
12
- $wp_scripts->do_items((array) $handles);
13
  }
14
 
15
  // Force style enqueue
16
- static function do_styles($handles) {
17
- self::do_scripts('jquery');
18
 
19
  global $wp_styles;
20
 
21
- if ( ! is_a($wp_styles, 'WP_Styles') )
22
  $wp_styles = new WP_Styles();
23
 
24
  ob_start();
25
- $wp_styles->do_items((array) $handles);
26
- $content = str_replace(array('"', "\n"), array("'", ''), ob_get_clean());
27
 
28
  echo "<script type='text/javascript'>\n";
29
- echo "jQuery(document).ready(function($) {\n";
30
- echo "$('head').prepend(\"$content\");\n";
31
- echo "});\n";
32
  echo "</script>";
33
  }
34
 
 
 
 
 
35
 
36
  // Have more than one uninstall hooks; also prevents an UPDATE query on each page load
37
- static function add_uninstall_hook($plugin, $callback) {
38
- register_uninstall_hook($plugin, '__return_false'); // dummy
39
 
40
- add_action('uninstall_' . plugin_basename($plugin), $callback);
41
  }
42
 
43
- // Apply a function to each element of a (nested) array recursively
44
- static function array_map_recursive($callback, $array) {
45
- array_walk_recursive($array, array(__CLASS__, 'array_map_recursive_helper'), $callback);
46
 
47
  return $array;
48
  }
49
 
50
- static function array_map_recursive_helper(&$val, $key, $callback) {
51
- $val = call_user_func($callback, $val);
52
  }
53
 
54
  // Extract certain $keys from $array
55
- static function array_extract($array, $keys) {
56
  $r = array();
57
 
58
  foreach ( $keys as $key )
59
- if ( array_key_exists($key, $array) )
60
  $r[$key] = $array[$key];
61
 
62
  return $r;
63
  }
64
 
65
  // Extract a certain value from a list of arrays
66
- static function array_pluck($array, $key) {
67
  $r = array();
68
 
69
  foreach ( $array as $value ) {
70
- if ( is_object($value) )
71
- $value = get_object_vars($value);
72
- if ( array_key_exists($key, $value) )
73
  $r[] = $value[$key];
74
  }
75
 
@@ -77,7 +81,7 @@ class scbUtil {
77
  }
78
 
79
  // Transform a list of objects into an associative array
80
- static function objects_to_assoc($objects, $key, $value) {
81
  $r = array();
82
 
83
  foreach ( $objects as $obj )
@@ -87,24 +91,24 @@ class scbUtil {
87
  }
88
 
89
  // Prepare an array for an IN statement
90
- static function array_to_sql($values) {
91
  foreach ( $values as &$val )
92
- $val = "'" . esc_sql(trim($val)) . "'";
93
 
94
- return implode(',', $values);
95
  }
96
 
97
- // Example: split_at('</', '<a></a>') => array('<a>', '</a>')
98
- static function split_at($delim, $str) {
99
- $i = strpos($str, $delim);
100
 
101
  if ( false === $i )
102
  return false;
103
 
104
- $start = substr($str, 0, $i);
105
- $finish = substr($str, $i);
106
 
107
- return array($start, $finish);
108
  }
109
  }
110
 
@@ -112,51 +116,44 @@ class scbUtil {
112
  //_____Minimalist HTML framework_____
113
 
114
 
115
- if ( ! function_exists('html') ):
116
- function html($tag, $content = '') {
117
- list($closing) = explode(' ', $tag, 2);
 
 
 
 
 
 
 
 
118
 
119
  return "<{$tag}>{$content}</{$closing}>";
120
  }
121
  endif;
122
 
123
  // Generate an <a> tag
124
- if ( ! function_exists('html_link') ):
125
- function html_link($url, $title = '') {
126
- if ( empty($title) )
127
  $title = $url;
128
 
129
- return sprintf("<a href='%s'>%s</a>", esc_url($url), $title);
130
  }
131
  endif;
132
 
133
 
134
  //_____Compatibility layer_____
135
 
136
-
137
- // WP < 3.0
138
- if ( ! function_exists('__return_false') ) :
139
- function __return_false() {
140
- return false;
141
- }
142
- endif;
143
-
144
- // WP < ?
145
- if ( ! function_exists('__return_true') ) :
146
- function __return_true() {
147
- return true;
148
- }
149
- endif;
150
-
151
  // WP < ?
152
- if ( ! function_exists('set_post_field') ) :
153
- function set_post_field($field, $value, $post_id) {
154
  global $wpdb;
155
 
156
- $post_id = absint($post_id);
157
- $value = sanitize_post_field($field, $value, $post_id, 'db');
158
 
159
- return $wpdb->update($wpdb->posts, array($field => $value), array('ID' => $post_id));
160
  }
161
  endif;
162
 
3
  class scbUtil {
4
 
5
  // Force script enqueue
6
+ static function do_scripts( $handles ) {
7
  global $wp_scripts;
8
 
9
+ if ( ! is_a( $wp_scripts, 'WP_Scripts' ) )
10
  $wp_scripts = new WP_Scripts();
11
 
12
+ $wp_scripts->do_items( ( array ) $handles );
13
  }
14
 
15
  // Force style enqueue
16
+ static function do_styles( $handles ) {
17
+ self::do_scripts( 'jquery' );
18
 
19
  global $wp_styles;
20
 
21
+ if ( ! is_a( $wp_styles, 'WP_Styles' ) )
22
  $wp_styles = new WP_Styles();
23
 
24
  ob_start();
25
+ $wp_styles->do_items( ( array ) $handles );
26
+ $content = str_replace( array( '"', "\n" ), array( "'", '' ), ob_get_clean() );
27
 
28
  echo "<script type='text/javascript'>\n";
29
+ echo "jQuery( document ).ready( function( $ ) {\n";
30
+ echo "$( 'head' ).prepend( \"$content\" );\n";
31
+ echo "} );\n";
32
  echo "</script>";
33
  }
34
 
35
+ // Enable delayed activation ( to be used with scb_init() )
36
+ static function add_activation_hook( $plugin, $callback ) {
37
+ add_action( 'scb_activation_' . plugin_basename( $plugin ), $callback );
38
+ }
39
 
40
  // Have more than one uninstall hooks; also prevents an UPDATE query on each page load
41
+ static function add_uninstall_hook( $plugin, $callback ) {
42
+ register_uninstall_hook( $plugin, '__return_false' ); // dummy
43
 
44
+ add_action( 'uninstall_' . plugin_basename( $plugin ), $callback );
45
  }
46
 
47
+ // Apply a function to each element of a ( nested ) array recursively
48
+ static function array_map_recursive( $callback, $array ) {
49
+ array_walk_recursive( $array, array( __CLASS__, 'array_map_recursive_helper' ), $callback );
50
 
51
  return $array;
52
  }
53
 
54
+ static function array_map_recursive_helper( &$val, $key, $callback ) {
55
+ $val = call_user_func( $callback, $val );
56
  }
57
 
58
  // Extract certain $keys from $array
59
+ static function array_extract( $array, $keys ) {
60
  $r = array();
61
 
62
  foreach ( $keys as $key )
63
+ if ( array_key_exists( $key, $array ) )
64
  $r[$key] = $array[$key];
65
 
66
  return $r;
67
  }
68
 
69
  // Extract a certain value from a list of arrays
70
+ static function array_pluck( $array, $key ) {
71
  $r = array();
72
 
73
  foreach ( $array as $value ) {
74
+ if ( is_object( $value ) )
75
+ $value = get_object_vars( $value );
76
+ if ( array_key_exists( $key, $value ) )
77
  $r[] = $value[$key];
78
  }
79
 
81
  }
82
 
83
  // Transform a list of objects into an associative array
84
+ static function objects_to_assoc( $objects, $key, $value ) {
85
  $r = array();
86
 
87
  foreach ( $objects as $obj )
91
  }
92
 
93
  // Prepare an array for an IN statement
94
+ static function array_to_sql( $values ) {
95
  foreach ( $values as &$val )
96
+ $val = "'" . esc_sql( trim( $val ) ) . "'";
97
 
98
+ return implode( ',', $values );
99
  }
100
 
101
+ // Example: split_at( '</', '<a></a>' ) => array( '<a>', '</a>' )
102
+ static function split_at( $delim, $str ) {
103
+ $i = strpos( $str, $delim );
104
 
105
  if ( false === $i )
106
  return false;
107
 
108
+ $start = substr( $str, 0, $i );
109
+ $finish = substr( $str, $i );
110
 
111
+ return array( $start, $finish );
112
  }
113
  }
114
 
116
  //_____Minimalist HTML framework_____
117
 
118
 
119
+ if ( ! function_exists( 'html' ) ):
120
+ function html( $tag, $attributes = array(), $content = '' ) {
121
+ if ( is_array( $attributes ) ) {
122
+ $closing = $tag;
123
+ foreach ( $attributes as $key => $value ) {
124
+ $tag .= ' ' . $key . '="' . esc_attr( $value ) . '"';
125
+ }
126
+ } else {
127
+ $content = $attributes;
128
+ list( $closing ) = explode(' ', $tag, 2);
129
+ }
130
 
131
  return "<{$tag}>{$content}</{$closing}>";
132
  }
133
  endif;
134
 
135
  // Generate an <a> tag
136
+ if ( ! function_exists( 'html_link' ) ):
137
+ function html_link( $url, $title = '' ) {
138
+ if ( empty( $title ) )
139
  $title = $url;
140
 
141
+ return sprintf( "<a href='%s'>%s</a>", esc_url( $url ), $title );
142
  }
143
  endif;
144
 
145
 
146
  //_____Compatibility layer_____
147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  // WP < ?
149
+ if ( ! function_exists( 'set_post_field' ) ) :
150
+ function set_post_field( $field, $value, $post_id ) {
151
  global $wpdb;
152
 
153
+ $post_id = absint( $post_id );
154
+ $value = sanitize_post_field( $field, $value, $post_id, 'db' );
155
 
156
+ return $wpdb->update( $wpdb->posts, array( $field => $value ), array( 'ID' => $post_id ) );
157
  }
158
  endif;
159
 
scb/Widget.php CHANGED
@@ -7,41 +7,41 @@ abstract class scbWidget extends WP_Widget {
7
 
8
  private static $scb_widgets = array();
9
 
10
- static function init($class, $file = '', $base = '') {
11
  self::$scb_widgets[] = $class;
12
 
13
- add_action('widgets_init', array(__CLASS__, '_scb_register'));
14
 
15
  // for auto-uninstall
16
- if ( $file && $base && class_exists('scbOptions') )
17
- new scbOptions("widget_$base", $file);
18
  }
19
 
20
  static function _scb_register() {
21
  foreach ( self::$scb_widgets as $widget )
22
- register_widget($widget);
23
  }
24
 
25
  // A pre-filled method, for convenience
26
- function widget($args, $instance) {
27
- $instance = wp_parse_args($instance, $this->defaults);
28
 
29
- extract($args);
30
 
31
  echo $before_widget;
32
 
33
- $title = apply_filters('widget_title', isset($instance['title']) ? $instance['title'] : '', $instance, $this->id_base);
34
 
35
- if ( ! empty($title) )
36
  echo $before_title . $title . $after_title;
37
 
38
- $this->content($instance);
39
 
40
  echo $after_widget;
41
  }
42
 
43
  // This is where the actual widget content goes
44
- function content($instance) {}
45
 
46
 
47
  //_____HELPER METHODS_____
@@ -49,52 +49,41 @@ abstract class scbWidget extends WP_Widget {
49
 
50
  // See scbForms::input()
51
  // Allows extra parameter $args['title']
52
- protected function input($args, $formdata = array()) {
53
  // Add default class
54
- if ( !isset($args['extra']) )
55
  $args['extra'] = 'class="regular-text"';
56
 
57
  // Add default label position
58
- if ( !in_array($args['type'], array('checkbox', 'radio')) && empty($args['desc_pos']) )
59
  $args['desc_pos'] = 'before';
60
 
61
  // Then add prefix to names and formdata
62
  $new_formdata = array();
63
- foreach ( (array) $args['name'] as $name )
64
- $new_formdata[$this->scb_get_field_name($name)] = @$formdata[$name];
65
- $new_names = array_keys($new_formdata);
66
 
67
  // Finally, replace the old names
68
- if ( 1 == count($new_names) )
69
  $args['name'] = $new_names[0];
70
  else
71
  $args['name'] = $new_names;
72
 
73
- // Remember $desc and replace with $title
74
- $desc = '';
75
- if ( isset($args['title']) ) {
76
- if ( isset($args['desc']) )
77
- $desc = "<small>{$args['desc']}</small>";
78
- $args['desc'] = $args['title'];
79
- unset($args['title']);
80
- }
81
-
82
- $input = scbForms::input($args, $new_formdata);
83
-
84
- return "<p>{$input}\n<br />\n$desc\n</p>\n";
85
  }
86
 
87
 
88
  //_____INTERNAL METHODS_____
89
 
90
 
91
- private function scb_get_field_name($name) {
92
- if ( $split = scbUtil::split_at('[', $name) )
93
- list($basename, $extra) = $split;
94
  else
95
- return $this->get_field_name($name);
96
 
97
- return str_replace('[]', '', $this->get_field_name($basename)) . $extra;
98
  }
99
  }
100
 
7
 
8
  private static $scb_widgets = array();
9
 
10
+ static function init( $class, $file = '', $base = '' ) {
11
  self::$scb_widgets[] = $class;
12
 
13
+ add_action( 'widgets_init', array( __CLASS__, '_scb_register' ) );
14
 
15
  // for auto-uninstall
16
+ if ( $file && $base && class_exists( 'scbOptions' ) )
17
+ new scbOptions( "widget_$base", $file );
18
  }
19
 
20
  static function _scb_register() {
21
  foreach ( self::$scb_widgets as $widget )
22
+ register_widget( $widget );
23
  }
24
 
25
  // A pre-filled method, for convenience
26
+ function widget( $args, $instance ) {
27
+ $instance = wp_parse_args( $instance, $this->defaults );
28
 
29
+ extract( $args );
30
 
31
  echo $before_widget;
32
 
33
+ $title = apply_filters( 'widget_title', isset( $instance['title'] ) ? $instance['title'] : '', $instance, $this->id_base );
34
 
35
+ if ( ! empty( $title ) )
36
  echo $before_title . $title . $after_title;
37
 
38
+ $this->content( $instance );
39
 
40
  echo $after_widget;
41
  }
42
 
43
  // This is where the actual widget content goes
44
+ function content( $instance ) {}
45
 
46
 
47
  //_____HELPER METHODS_____
49
 
50
  // See scbForms::input()
51
  // Allows extra parameter $args['title']
52
+ protected function input( $args, $formdata = array() ) {
53
  // Add default class
54
+ if ( !isset( $args['extra'] ) )
55
  $args['extra'] = 'class="regular-text"';
56
 
57
  // Add default label position
58
+ if ( !in_array( $args['type'], array( 'checkbox', 'radio' ) ) && empty( $args['desc_pos'] ) )
59
  $args['desc_pos'] = 'before';
60
 
61
  // Then add prefix to names and formdata
62
  $new_formdata = array();
63
+ foreach ( ( array ) $args['name'] as $name )
64
+ $new_formdata[$this->scb_get_field_name( $name )] = @$formdata[$name];
65
+ $new_names = array_keys( $new_formdata );
66
 
67
  // Finally, replace the old names
68
+ if ( 1 == count( $new_names ) )
69
  $args['name'] = $new_names[0];
70
  else
71
  $args['name'] = $new_names;
72
 
73
+ return scbForms::input( $args, $new_formdata );
 
 
 
 
 
 
 
 
 
 
 
74
  }
75
 
76
 
77
  //_____INTERNAL METHODS_____
78
 
79
 
80
+ private function scb_get_field_name( $name ) {
81
+ if ( $split = scbUtil::split_at( '[', $name ) )
82
+ list( $basename, $extra ) = $split;
83
  else
84
+ return $this->get_field_name( $name );
85
 
86
+ return str_replace( '[]', '', $this->get_field_name( $basename ) ) . $extra;
87
  }
88
  }
89
 
scb/load.php CHANGED
@@ -1,69 +1,85 @@
1
  <?php
2
- if ( !class_exists('scbLoad3') ) :
3
- class scbLoad3 {
 
 
 
 
 
 
 
4
 
5
  private static $candidates;
 
 
 
6
  private static $loaded;
7
- private static $initial_load;
8
-
9
- static function init($rev, $file, $classes) {
10
- if ( $path = get_option('scb-framework') && !self::$initial_load ) {
11
- if ( $path != __FILE__ )
12
- include $path;
13
 
14
- self::$initial_load = true;
15
- }
16
 
17
  self::$candidates[$file] = $rev;
 
 
 
 
18
 
19
- self::load(dirname($file) . '/', $classes);
 
20
 
21
- add_action('deactivate_plugin', array(__CLASS__, 'deactivate'));
22
- add_action('update_option_active_plugins', array(__CLASS__, 'reorder'));
23
  }
24
 
25
- static function deactivate($plugin) {
26
- $plugin = dirname($plugin);
27
 
28
- if ( '.' == $plugin )
29
  return;
30
 
31
- foreach ( self::$candidates as $path => $rev )
32
- if ( plugin_basename(dirname(dirname($path))) == $plugin )
33
- unset(self::$candidates[$path]);
 
 
 
 
34
  }
35
 
36
- static function reorder() {
37
- arsort(self::$candidates);
38
 
39
- update_option('scb-framework', key(self::$candidates));
40
- }
41
-
42
- private static function load($path, $classes) {
43
- foreach ( $classes as $class_name ) {
44
- if ( class_exists($class_name) )
45
- continue;
46
 
47
- $fpath = $path . substr($class_name, 3) . '.php';
48
 
49
- if ( file_exists($fpath) ) {
50
- self::$loaded[$class_name] = $fpath;
 
 
 
 
51
  include $fpath;
 
52
  }
53
  }
 
 
 
 
54
  }
55
 
56
  static function get_info() {
57
- arsort(self::$candidates);
58
 
59
- return array(get_option('scb-framework'), self::$loaded, self::$candidates);
60
  }
61
  }
62
  endif;
63
 
64
- scbLoad3::init(14, __FILE__, array(
65
- 'scbUtil', 'scbOptions', 'scbForms', 'scbTable', 'scbDebug',
66
- 'scbWidget', 'scbAdminPage', 'scbBoxesPage',
67
- 'scbQuery', 'scbRewrite', 'scbCron',
68
- ));
69
 
1
  <?php
2
+
3
+ $GLOBALS['_scb_data'] = array( 24, __FILE__, array(
4
+ 'scbUtil', 'scbOptions', 'scbForms', 'scbTable',
5
+ 'scbWidget', 'scbAdminPage', 'scbBoxesPage',
6
+ 'scbQueryManipulation', 'scbCron',
7
+ ) );
8
+
9
+ if ( !class_exists( 'scbLoad4' ) ) :
10
+ class scbLoad4 {
11
 
12
  private static $candidates;
13
+ private static $classes;
14
+ private static $callbacks = array();
15
+
16
  private static $loaded;
 
 
 
 
 
 
17
 
18
+ static function init( $callback = '' ) {
19
+ list( $rev, $file, $classes ) = $GLOBALS['_scb_data'];
20
 
21
  self::$candidates[$file] = $rev;
22
+ self::$classes[$file] = $classes;
23
+
24
+ if ( !empty( $callback ) ) {
25
+ self::$callbacks[$file] = $callback;
26
 
27
+ add_action( 'activate_plugin', array( __CLASS__, 'delayed_activation' ) );
28
+ }
29
 
30
+ // TODO: don't load when activating a plugin ?
31
+ add_action( 'plugins_loaded', array( __CLASS__, 'load' ), 10, 0 );
32
  }
33
 
34
+ static function delayed_activation( $plugin ) {
35
+ $plugin_dir = dirname( $plugin );
36
 
37
+ if ( '.' == $plugin_dir )
38
  return;
39
 
40
+ foreach ( self::$callbacks as $file => $callback )
41
+ if ( plugin_basename( dirname( dirname( $file ) ) ) == $plugin_dir ) {
42
+ self::load( false );
43
+ call_user_func( $callback );
44
+ do_action( 'scb_activation_' . $plugin );
45
+ break;
46
+ }
47
  }
48
 
49
+ static function load( $do_callbacks = true ) {
50
+ arsort( self::$candidates );
51
 
52
+ $file = key( self::$candidates );
 
 
 
 
 
 
53
 
54
+ $path = dirname( $file ) . '/';
55
 
56
+ foreach ( self::$classes[$file] as $class_name ) {
57
+ if ( class_exists( $class_name ) )
58
+ continue;
59
+
60
+ $fpath = $path . substr( $class_name, 3 ) . '.php';
61
+ if ( file_exists( $fpath ) ) {
62
  include $fpath;
63
+ self::$loaded[] = $fpath;
64
  }
65
  }
66
+
67
+ if ( $do_callbacks )
68
+ foreach ( self::$callbacks as $callback )
69
+ call_user_func( $callback );
70
  }
71
 
72
  static function get_info() {
73
+ arsort( self::$candidates );
74
 
75
+ return array( self::$loaded, self::$candidates );
76
  }
77
  }
78
  endif;
79
 
80
+ if ( !function_exists( 'scb_init' ) ) :
81
+ function scb_init( $callback = '' ) {
82
+ scbLoad4::init( $callback );
83
+ }
84
+ endif;
85
 
template-tags.php CHANGED
@@ -7,16 +7,16 @@ function users_online() {
7
 
8
  function get_users_online() {
9
  $template = UserOnline_Core::$options->templates['useronline'];
10
- $template = str_ireplace('%PAGE_URL%', UserOnline_Core::$options->url, $template);
11
- $template = str_ireplace('%MOSTONLINE_COUNT%', get_most_users_online(), $template);
12
- $template = str_ireplace('%MOSTONLINE_DATE%', get_most_users_online_date(), $template);
13
 
14
- return UserOnline_Template::format_count(get_users_online_count(), 'user', $template);
15
  }
16
 
17
  ### Function: Display UserOnline Count
18
  function users_online_count() {
19
- echo number_format_i18n(get_useronline_count());
20
  }
21
 
22
  function get_users_online_count() {
@@ -25,11 +25,11 @@ function get_users_online_count() {
25
 
26
  ### Function: Display Max UserOnline
27
  function most_users_online() {
28
- echo number_format_i18n(get_most_users_online());
29
  }
30
 
31
  function get_most_users_online() {
32
- return intval(UserOnline_Core::$most->count);
33
  }
34
 
35
  ### Function: Display Max UserOnline Date
@@ -38,7 +38,7 @@ function most_users_online_date() {
38
  }
39
 
40
  function get_most_users_online_date() {
41
- return UserOnline_Template::format_date(UserOnline_Core::$most->date);
42
  }
43
 
44
  ### Function: Display Users Browsing The Site
@@ -47,33 +47,35 @@ function users_browsing_site() {
47
  }
48
 
49
  function get_users_browsing_site() {
50
- return UserOnline_Template::compact_list('site');
51
  }
52
 
53
- ### Function: Display Users Browsing The (Current) Page
54
- function users_browsing_page($page_url = '') {
55
- echo get_users_browsing_page($page_url);
56
  }
57
 
58
- function get_users_browsing_page($page_url = '') {
59
- return UserOnline_Template::compact_list('page');
60
  }
61
 
62
  ### Function: UserOnline Page
63
  function users_online_page() {
64
  global $wpdb;
65
 
66
- $usersonline = $wpdb->get_results("SELECT * FROM $wpdb->useronline");
67
 
68
  $user_buckets = array();
69
  foreach ( $usersonline as $useronline )
70
  $user_buckets[$useronline->user_type][] = $useronline;
71
 
72
- $counts = UserOnline_Template::get_counts($user_buckets);
 
 
73
 
74
  $nicetexts = array();
75
- foreach ( array('user', 'member', 'guest', 'bot') as $user_type )
76
- $nicetexts[$user_type] = UserOnline_Template::format_count($counts[$user_type], $user_type);
77
 
78
  $text = _n(
79
  'There is <strong>%s</strong> online now: <strong>%s</strong>, <strong>%s</strong> and <strong>%s</strong>.',
@@ -81,44 +83,49 @@ function users_online_page() {
81
  $counts['user'], 'wp-useronline'
82
  );
83
 
84
- $output =
85
- html('p', vsprintf($text, $nicetexts))
86
- .html('p', UserOnline_Template::format_most_users())
87
- .UserOnline_Template::detailed_list($counts, $user_buckets, $nicetexts);
 
 
88
 
89
- return apply_filters('useronline_page', $output);
90
  }
91
 
92
  ### Function Check If User Is Online
93
- function is_user_online($user_id) {
94
  global $wpdb;
95
 
96
- return (bool) $wpdb->get_var($wpdb-prepare("SELECT COUNT(*) FROM $wpdb->useronline WHERE user_id = %d LIMIT 1", $user_id));
97
  }
98
 
99
- function get_useronline_($output, $type = 'site') {
100
- return UserOnline_Template::compact_list($type, $output);
101
  }
102
 
103
  class UserOnline_Template {
104
 
105
  private static $cache = array();
106
 
107
- function compact_list($type, $output = 'html') {
 
108
 
109
- if ( !isset(self::$cache[$type]) ) {
110
  global $wpdb;
111
 
112
- if ( 'site' == $type )
113
  $where = '';
114
- elseif ( 'page' == $type )
115
- $where = $wpdb->prepare('WHERE page_url = %s', $_SERVER['REQUEST_URI']);
116
- else
117
- $where = $wpdb->prepare('WHERE page_url = %s', $type);
 
118
 
119
- self::$cache[$type] = $wpdb->get_results("SELECT * FROM $wpdb->useronline $where");
120
  }
121
- $users = self::$cache[$type];
 
122
 
123
  if ( 'list' == $output )
124
  return $users;
@@ -130,7 +137,7 @@ class UserOnline_Template {
130
  if ( 'buckets' == $output )
131
  return $buckets;
132
 
133
- $counts = self::get_counts($buckets);
134
 
135
  if ( 'counts' == $output )
136
  return $counts;
@@ -142,50 +149,52 @@ class UserOnline_Template {
142
  $template = UserOnline_Core::$options->templates["browsing$type"];
143
 
144
  // Nice Text For Users
145
- $output = self::format_count($counts['user'], 'user', $template['text']);
146
 
147
  // Print Member Name
148
  $temp_member = '';
149
- $members = $buckets['member'];
150
  if ( $members ) {
151
  $temp_member = array();
152
  foreach ( $members as $member )
153
- $temp_member[] = self::format_name($member);
154
- $temp_member = implode($template['separators']['members'], $temp_member);
155
  }
156
- $output = str_ireplace('%MEMBER_NAMES%', $temp_member, $output);
157
 
158
  // Counts
159
- foreach ( array('member', 'guest', 'bot') as $user_type ) {
160
  if ( $counts[$user_type] > 1 )
161
- $number = str_ireplace('%COUNT%', number_format_i18n($counts[$user_type]), $naming[$user_type . 's']);
162
  elseif ( $counts[$user_type] == 1 )
163
  $number = $naming[$user_type];
164
  else
165
  $number = '';
166
- $output = str_ireplace("%{$user_type}S%", $number, $output);
167
  }
168
 
169
  // Seperators
170
  $separator = ( $counts['member'] && $counts['guest'] ) ? $template['separators']['guests'] : '';
171
- $output = str_ireplace('%GUESTS_SEPERATOR%', $separator, $output);
172
 
173
  $separator = ( ( $counts['guest'] || $counts['member'] ) && $counts['bot'] ) ? $template['separators']['bots'] : '';
174
- $output = str_ireplace('%BOTS_SEPERATOR%', $separator, $output);
175
 
176
  return $output;
177
  }
178
 
179
- function detailed_list($counts, $user_buckets, $nicetexts) {
 
 
180
  if ( $counts['user'] == 0 )
181
- return html('h2', __('No one is online now.', 'wp-useronline'));
182
 
183
- $_on = __('on', 'wp-useronline');
184
- $_url = __('url', 'wp-useronline');
185
- $_referral = __('referral', 'wp-useronline');
186
 
187
  $output = '';
188
- foreach ( array('member', 'guest', 'bot') as $user_type ) {
189
  if ( !$counts[$user_type] )
190
  continue;
191
 
@@ -193,20 +202,20 @@ class UserOnline_Template {
193
  $users = $user_buckets[$user_type];
194
  $nicetext = $nicetexts[$user_type];
195
 
196
- $output .= html('h2', $nicetext . ' ' . __('Online Now', 'wp-useronline'));
197
 
198
  $i=1;
199
  foreach ( $users as $user ) {
200
- $nr = number_format_i18n($i++);
201
- $name = self::format_name($user);
202
- $user_ip = self::format_ip($user->user_ip);
203
- $date = self::format_date($user->timestamp, true);
204
- $page_title = esc_html($user->page_title);
205
- $current_link = '[' . html_link(esc_url($user->page_url), $_url) . ']';
206
 
207
- $referral_link = '';
208
- if ( !empty($user->referral) )
209
- $referral_link = '[' . html_link(esc_attr(esc_url($user->referral)), $_referral) . ']';
 
 
210
 
211
  $output .= "<p><strong>#$nr - $name</strong> $user_ip $_on $date<br/>$page_title $current_link $referral_link</p>\n";
212
  }
@@ -215,49 +224,59 @@ class UserOnline_Template {
215
  return $output;
216
  }
217
 
 
 
 
218
 
219
- function format_ip($ip) {
220
- if ( ! current_user_can('administrator') || empty($ip) || $ip == 'unknown' )
221
- return;
222
 
223
- return '<span dir="ltr">(<a href="http://whois.domaintools.com/' . $ip . '" title="' . gethostbyaddr($ip) . '">' . $ip . '</a>)</span>';
 
 
 
 
 
 
 
 
224
  }
225
 
226
- function format_date($date, $mysql = false) {
227
  if ( $mysql )
228
- return mysql2date(sprintf(__('%s @ %s', 'wp-useronline'), get_option('date_format'), get_option('time_format')), $date, true);
229
 
230
- return date_i18n(sprintf(__('%s @ %s', 'wp-useronline'), get_option('date_format'), get_option('time_format')), $date);
231
  }
232
 
233
- function format_name($user) {
234
- return apply_filters('useronline_display_user', esc_html($user->user_name), $user);
235
  }
236
 
237
- function format_count($count, $user_type, $template = false) {
238
- $i = ($count == 1) ? '' : 's';
239
  $string = UserOnline_Core::$options->naming[$user_type . $i];
240
 
241
- $output = str_ireplace('%COUNT%', number_format_i18n($count), $string);
242
 
243
  if ( false === $template )
244
  return $output;
245
 
246
- return str_ireplace('%USERS%', $output, $template);
247
  }
248
 
249
  function format_most_users() {
250
- return sprintf(__('Most users ever online were <strong>%s</strong>, on <strong>%s</strong>', 'wp-useronline'),
251
- number_format_i18n(get_most_users_online()),
252
  get_most_users_online_date()
253
  );
254
  }
255
 
256
- function get_counts($buckets) {
257
  $counts = array();
258
  $total = 0;
259
- foreach ( array('member', 'guest', 'bot') as $user_type )
260
- $total += $counts[$user_type] = count(@$buckets[$user_type]);
261
 
262
  $counts['user'] = $total;
263
 
7
 
8
  function get_users_online() {
9
  $template = UserOnline_Core::$options->templates['useronline'];
10
+ $template = str_ireplace( '%PAGE_URL%', UserOnline_Core::$options->url, $template );
11
+ $template = str_ireplace( '%MOSTONLINE_COUNT%', get_most_users_online(), $template );
12
+ $template = str_ireplace( '%MOSTONLINE_DATE%', get_most_users_online_date(), $template );
13
 
14
+ return UserOnline_Template::format_count( get_users_online_count(), 'user', $template );
15
  }
16
 
17
  ### Function: Display UserOnline Count
18
  function users_online_count() {
19
+ echo number_format_i18n( get_useronline_count() );
20
  }
21
 
22
  function get_users_online_count() {
25
 
26
  ### Function: Display Max UserOnline
27
  function most_users_online() {
28
+ echo number_format_i18n( get_most_users_online() );
29
  }
30
 
31
  function get_most_users_online() {
32
+ return intval( UserOnline_Core::$most->count );
33
  }
34
 
35
  ### Function: Display Max UserOnline Date
38
  }
39
 
40
  function get_most_users_online_date() {
41
+ return UserOnline_Template::format_date( UserOnline_Core::$most->date );
42
  }
43
 
44
  ### Function: Display Users Browsing The Site
47
  }
48
 
49
  function get_users_browsing_site() {
50
+ return UserOnline_Template::compact_list( 'site' );
51
  }
52
 
53
+ ### Function: Display Users Browsing The ( Current ) Page
54
+ function users_browsing_page( $page_url = '' ) {
55
+ echo get_users_browsing_page( $page_url );
56
  }
57
 
58
+ function get_users_browsing_page( $page_url = '' ) {
59
+ return UserOnline_Template::compact_list( 'page', 'html', $page_url );
60
  }
61
 
62
  ### Function: UserOnline Page
63
  function users_online_page() {
64
  global $wpdb;
65
 
66
+ $usersonline = $wpdb->get_results( "SELECT * FROM $wpdb->useronline" );
67
 
68
  $user_buckets = array();
69
  foreach ( $usersonline as $useronline )
70
  $user_buckets[$useronline->user_type][] = $useronline;
71
 
72
+ $user_buckets = apply_filters( 'useronline_buckets', $user_buckets );
73
+
74
+ $counts = UserOnline_Template::get_counts( $user_buckets );
75
 
76
  $nicetexts = array();
77
+ foreach ( array( 'user', 'member', 'guest', 'bot' ) as $user_type )
78
+ $nicetexts[$user_type] = UserOnline_Template::format_count( $counts[$user_type], $user_type );
79
 
80
  $text = _n(
81
  'There is <strong>%s</strong> online now: <strong>%s</strong>, <strong>%s</strong> and <strong>%s</strong>.',
83
  $counts['user'], 'wp-useronline'
84
  );
85
 
86
+ $output =
87
+ html( 'div id="useronline-details"',
88
+ html( 'p', vsprintf( $text, $nicetexts ) )
89
+ .html( 'p', UserOnline_Template::format_most_users() )
90
+ .UserOnline_Template::detailed_list( $counts, $user_buckets, $nicetexts )
91
+ );
92
 
93
+ return apply_filters( 'useronline_page', $output );
94
  }
95
 
96
  ### Function Check If User Is Online
97
+ function is_user_online( $user_id ) {
98
  global $wpdb;
99
 
100
+ return (bool) $wpdb->get_var( $wpdb-prepare( "SELECT COUNT( * ) FROM $wpdb->useronline WHERE user_id = %d LIMIT 1", $user_id ) );
101
  }
102
 
103
+ function get_useronline_( $output, $type = 'site' ) {
104
+ return UserOnline_Template::compact_list( $type, $output );
105
  }
106
 
107
  class UserOnline_Template {
108
 
109
  private static $cache = array();
110
 
111
+ function compact_list( $type, $output = 'html', $page_url = '') {
112
+ UserOnline_Core::$add_script = true;
113
 
114
+ if ( !isset( self::$cache[$type] ) ) {
115
  global $wpdb;
116
 
117
+ if ( 'site' == $type ) {
118
  $where = '';
119
+ } elseif ( 'page' == $type ) {
120
+ if ( empty($page_url) )
121
+ $page_url = $_SERVER['REQUEST_URI'];
122
+ $where = $wpdb->prepare( 'WHERE page_url = %s', $page_url );
123
+ }
124
 
125
+ self::$cache[$type . $page_url] = $wpdb->get_results( "SELECT * FROM $wpdb->useronline $where" );
126
  }
127
+
128
+ $users = self::$cache[$type . $page_url];
129
 
130
  if ( 'list' == $output )
131
  return $users;
137
  if ( 'buckets' == $output )
138
  return $buckets;
139
 
140
+ $counts = self::get_counts( $buckets );
141
 
142
  if ( 'counts' == $output )
143
  return $counts;
149
  $template = UserOnline_Core::$options->templates["browsing$type"];
150
 
151
  // Nice Text For Users
152
+ $output = self::format_count( $counts['user'], 'user', $template['text'] );
153
 
154
  // Print Member Name
155
  $temp_member = '';
156
+ $members = @$buckets['member'];
157
  if ( $members ) {
158
  $temp_member = array();
159
  foreach ( $members as $member )
160
+ $temp_member[] = self::format_name( $member );
161
+ $temp_member = implode( $template['separators']['members'], $temp_member );
162
  }
163
+ $output = str_ireplace( '%MEMBER_NAMES%', $temp_member, $output );
164
 
165
  // Counts
166
+ foreach ( array( 'member', 'guest', 'bot' ) as $user_type ) {
167
  if ( $counts[$user_type] > 1 )
168
+ $number = str_ireplace( '%COUNT%', number_format_i18n( $counts[$user_type] ), $naming[$user_type . 's'] );
169
  elseif ( $counts[$user_type] == 1 )
170
  $number = $naming[$user_type];
171
  else
172
  $number = '';
173
+ $output = str_ireplace( "%{$user_type}S%", $number, $output );
174
  }
175
 
176
  // Seperators
177
  $separator = ( $counts['member'] && $counts['guest'] ) ? $template['separators']['guests'] : '';
178
+ $output = str_ireplace( '%GUESTS_SEPERATOR%', $separator, $output );
179
 
180
  $separator = ( ( $counts['guest'] || $counts['member'] ) && $counts['bot'] ) ? $template['separators']['bots'] : '';
181
+ $output = str_ireplace( '%BOTS_SEPERATOR%', $separator, $output );
182
 
183
  return $output;
184
  }
185
 
186
+ function detailed_list( $counts, $user_buckets, $nicetexts ) {
187
+ UserOnline_Core::$add_script = true;
188
+
189
  if ( $counts['user'] == 0 )
190
+ return html( 'h2', __( 'No one is online now.', 'wp-useronline' ) );
191
 
192
+ $_on = __( 'on', 'wp-useronline' );
193
+ $_url = __( 'url', 'wp-useronline' );
194
+ $_referral = __( 'referral', 'wp-useronline' );
195
 
196
  $output = '';
197
+ foreach ( array( 'member', 'guest', 'bot' ) as $user_type ) {
198
  if ( !$counts[$user_type] )
199
  continue;
200
 
202
  $users = $user_buckets[$user_type];
203
  $nicetext = $nicetexts[$user_type];
204
 
205
+ $output .= html( 'h2', $nicetext . ' ' . __( 'Online Now', 'wp-useronline' ) );
206
 
207
  $i=1;
208
  foreach ( $users as $user ) {
209
+ $nr = number_format_i18n( $i++ );
210
+ $name = self::format_name( $user );
211
+ $user_ip = self::format_ip( $user->user_ip );
212
+ $date = self::format_date( $user->timestamp, true );
 
 
213
 
214
+ if ( current_user_can( 'edit_users' ) || false === strpos( $user->page_url, 'wp-admin' ) ) {
215
+ $page_title = esc_html( $user->page_title );
216
+ $current_link = self::format_link( $user->page_url, $_url );
217
+ $referral_link = self::format_link( $user->referral, $_referral );
218
+ }
219
 
220
  $output .= "<p><strong>#$nr - $name</strong> $user_ip $_on $date<br/>$page_title $current_link $referral_link</p>\n";
221
  }
224
  return $output;
225
  }
226
 
227
+ private function format_link($url, $title) {
228
+ if ( !empty($url) )
229
+ return '[' . html_link( esc_url($url), $title ) . ']';
230
 
231
+ return '';
232
+ }
 
233
 
234
+ function format_ip( $ip ) {
235
+ if ( current_user_can( 'edit_users' ) && !empty( $ip ) && $ip != 'unknown' )
236
+ return
237
+ html( 'span', array('dir' => 'ltr'),
238
+ html( 'a', array(
239
+ 'href' => 'http://whois.domaintools.com/' . $ip,
240
+ 'title' => gethostbyaddr( $ip ),
241
+ ), $ip )
242
+ );
243
  }
244
 
245
+ function format_date( $date, $mysql = false ) {
246
  if ( $mysql )
247
+ return mysql2date( sprintf( __( '%s @ %s', 'wp-useronline' ), get_option( 'date_format' ), get_option( 'time_format' ) ), $date, true );
248
 
249
+ return date_i18n( sprintf( __( '%s @ %s', 'wp-useronline' ), get_option( 'date_format' ), get_option( 'time_format' ) ), $date );
250
  }
251
 
252
+ function format_name( $user ) {
253
+ return apply_filters( 'useronline_display_user', esc_html( $user->user_name ), $user );
254
  }
255
 
256
+ function format_count( $count, $user_type, $template = false ) {
257
+ $i = ( $count == 1 ) ? '' : 's';
258
  $string = UserOnline_Core::$options->naming[$user_type . $i];
259
 
260
+ $output = str_ireplace( '%COUNT%', number_format_i18n( $count ), $string );
261
 
262
  if ( false === $template )
263
  return $output;
264
 
265
+ return str_ireplace( '%USERS%', $output, $template );
266
  }
267
 
268
  function format_most_users() {
269
+ return sprintf( __( 'Most users ever online were <strong>%s</strong>, on <strong>%s</strong>', 'wp-useronline' ),
270
+ number_format_i18n( get_most_users_online() ),
271
  get_most_users_online_date()
272
  );
273
  }
274
 
275
+ function get_counts( $buckets ) {
276
  $counts = array();
277
  $total = 0;
278
+ foreach ( array( 'member', 'guest', 'bot' ) as $user_type )
279
+ $total += $counts[$user_type] = count( @$buckets[$user_type] );
280
 
281
  $counts['user'] = $total;
282
 
useronline.dev.js CHANGED
@@ -1,23 +1,21 @@
1
- jQuery(document).ready(function($){
2
  var timeout = parseInt(useronlineL10n.timeout);
3
 
4
  var get_data = function(mode) {
5
  var data = {
6
  'action': 'useronline',
7
- 'mode': mode
 
 
8
  };
9
 
10
- $.post(useronlineL10n.ajax_url, data, function(response){
11
  $('#useronline-' + mode).html(response);
12
  });
13
  }
14
 
15
- if ( $('#useronline-count').length )
16
- setInterval("get_data('count')", timeout);
17
-
18
- if ( $('#useronline-browsing-site').length )
19
- setInterval("get_data('browsing-site')", timeout);
20
-
21
- if ( $('#useronline-browsing-page').length )
22
- setInterval("get_data('browsing-page')", timeout);
23
  });
1
+ jQuery(document).ready(function($) {
2
  var timeout = parseInt(useronlineL10n.timeout);
3
 
4
  var get_data = function(mode) {
5
  var data = {
6
  'action': 'useronline',
7
+ 'mode': mode,
8
+ 'page_url': location.protocol + '//' + location.host + location.pathname + location.search,
9
+ 'page_title': $('title').text()
10
  };
11
 
12
+ $.post(useronlineL10n.ajax_url, data, function(response) {
13
  $('#useronline-' + mode).html(response);
14
  });
15
  }
16
 
17
+ $.each(['count', 'browsing-site', 'browsing-page', 'details'], function(i, mode) {
18
+ if ( $('#useronline-' + mode).length )
19
+ setInterval(function() { get_data(mode); }, timeout);
20
+ });
 
 
 
 
21
  });
useronline.js CHANGED
@@ -1 +1 @@
1
- jQuery(document).ready(function($){var timeout=parseInt(useronlineL10n.timeout);var get_data=function(mode){var data={action:"useronline",mode:mode};$.post(useronlineL10n.ajax_url,data,function(response){$("#useronline-"+mode).html(response)})};if($("#useronline-count").length){setInterval("get_data('count')",timeout)}if($("#useronline-browsing-site").length){setInterval("get_data('browsing-site')",timeout)}if($("#useronline-browsing-page").length){setInterval("get_data('browsing-page')",timeout)}});
1
+ jQuery(document).ready(function(c){var b=parseInt(useronlineL10n.timeout);var a=function(e){var d={action:"useronline",mode:e,page_url:location.protocol+"//"+location.host+location.pathname+location.search,page_title:c("title").text()};c.post(useronlineL10n.ajax_url,d,function(f){c("#useronline-"+e).html(f)})};c.each(["count","browsing-site","browsing-page","details"],function(d,e){if(c("#useronline-"+e).length){setInterval(function(){a(e)},b)}})});
widget.php CHANGED
@@ -2,72 +2,72 @@
2
 
3
  class UserOnline_Widget extends scbWidget {
4
  function UserOnline_Widget() {
5
- $widget_ops = array('description' => __('WP-UserOnline users online statistics', 'wp-useronline'));
6
- $this->WP_Widget('useronline', __('UserOnline', 'wp-useronline'), $widget_ops);
7
  }
8
 
9
- function content($instance) {
10
  $out = '';
11
 
12
  switch( $instance['type'] ) {
13
  case 'users_online':
14
- $out .= html('div id="useronline-count"', get_users_online());
15
  break;
16
  case 'users_browsing_page':
17
- $out .= html('div id="useronline-browsing-page"', get_users_browsing_page());
18
  break;
19
  case 'users_browsing_site':
20
- $out .= html('div id="useronline-browsing-site"', get_users_browsing_site());
21
  break;
22
  case 'users_online_browsing_page':
23
- $out .= html('div id="useronline-count"', get_users_online());
24
- $out .= html('div id="useronline-browsing-page"', get_users_browsing_page());
25
  break;
26
  case 'users_online_browsing_site':
27
- $out .= html('div id="useronline-count"', get_users_online());
28
- $out .= html('div id="useronline-browsing-site"', get_users_browsing_site());
29
  break;
30
  }
31
 
32
  echo $out;
33
  }
34
 
35
- function update($new_instance, $old_instance) {
36
- if ( !isset($new_instance['submit']) )
37
  return false;
38
 
39
  $instance = $old_instance;
40
- $instance['title'] = strip_tags($new_instance['title']);
41
- $instance['type'] = strip_tags($new_instance['type']);
42
 
43
  return $instance;
44
  }
45
 
46
- function form($instance) {
47
  global $wpdb;
48
- $instance = wp_parse_args((array) $instance, array(
49
- 'title' => __('UserOnline', 'wp-useronline'),
50
  'type' => 'users_online'
51
- ));
52
- $title = esc_attr($instance['title']);
53
- $type = esc_attr($instance['type']);
54
  ?>
55
  <p>
56
- <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'wp-useronline'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label>
57
  </p>
58
  <p>
59
- <label for="<?php echo $this->get_field_id('type'); ?>"><?php _e('Statistics Type:', 'wp-useronline'); ?>
60
- <select name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>" class="widefat">
61
- <option value="users_online"<?php selected('users_online', $type); ?>><?php _e('Users Online Count', 'wp-useronline'); ?></option>
62
- <option value="users_browsing_page"<?php selected('users_browsing_page', $type); ?>><?php _e('Users Browsing Current Page', 'wp-useronline'); ?></option>
63
- <option value="users_browsing_site"<?php selected('users_browsing_site', $type); ?>><?php _e('Users Browsing Site', 'wp-useronline'); ?></option>
64
  <optgroup>&nbsp;</optgroup>
65
- <option value="users_online_browsing_page"<?php selected('users_online_browsing_page', $type); ?>><?php _e('Users Online Count & Users Browsing Current Page', 'wp-useronline'); ?></option>
66
- <option value="users_online_browsing_site"<?php selected('users_online_browsing_site', $type); ?>><?php _e('Users Online Count & Users Browsing Site', 'wp-useronline'); ?></option>
67
  </select>
68
  </label>
69
  </p>
70
- <input type="hidden" id="<?php echo $this->get_field_id('submit'); ?>" name="<?php echo $this->get_field_name('submit'); ?>" value="1" />
71
  <?php
72
  }
73
  }
2
 
3
  class UserOnline_Widget extends scbWidget {
4
  function UserOnline_Widget() {
5
+ $widget_ops = array( 'description' => __( 'WP-UserOnline users online statistics', 'wp-useronline' ) );
6
+ $this->WP_Widget( 'useronline', __( 'UserOnline', 'wp-useronline' ), $widget_ops );
7
  }
8
 
9
+ function content( $instance ) {
10
  $out = '';
11
 
12
  switch( $instance['type'] ) {
13
  case 'users_online':
14
+ $out .= html( 'div id="useronline-count"', get_users_online() );
15
  break;
16
  case 'users_browsing_page':
17
+ $out .= html( 'div id="useronline-browsing-page"', get_users_browsing_page() );
18
  break;
19
  case 'users_browsing_site':
20
+ $out .= html( 'div id="useronline-browsing-site"', get_users_browsing_site() );
21
  break;
22
  case 'users_online_browsing_page':
23
+ $out .= html( 'div id="useronline-count"', get_users_online() );
24
+ $out .= html( 'div id="useronline-browsing-page"', get_users_browsing_page() );
25
  break;
26
  case 'users_online_browsing_site':
27
+ $out .= html( 'div id="useronline-count"', get_users_online() );
28
+ $out .= html( 'div id="useronline-browsing-site"', get_users_browsing_site() );
29
  break;
30
  }
31
 
32
  echo $out;
33
  }
34
 
35
+ function update( $new_instance, $old_instance ) {
36
+ if ( !isset( $new_instance['submit'] ) )
37
  return false;
38
 
39
  $instance = $old_instance;
40
+ $instance['title'] = strip_tags( $new_instance['title'] );
41
+ $instance['type'] = strip_tags( $new_instance['type'] );
42
 
43
  return $instance;
44
  }
45
 
46
+ function form( $instance ) {
47
  global $wpdb;
48
+ $instance = wp_parse_args( (array) $instance, array(
49
+ 'title' => __( 'UserOnline', 'wp-useronline' ),
50
  'type' => 'users_online'
51
+ ) );
52
+ $title = esc_attr( $instance['title'] );
53
+ $type = esc_attr( $instance['type'] );
54
  ?>
55
  <p>
56
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'wp-useronline' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></label>
57
  </p>
58
  <p>
59
+ <label for="<?php echo $this->get_field_id( 'type' ); ?>"><?php _e( 'Statistics Type:', 'wp-useronline' ); ?>
60
+ <select name="<?php echo $this->get_field_name( 'type' ); ?>" id="<?php echo $this->get_field_id( 'type' ); ?>" class="widefat">
61
+ <option value="users_online"<?php selected( 'users_online', $type ); ?>><?php _e( 'Users Online Count', 'wp-useronline' ); ?></option>
62
+ <option value="users_browsing_page"<?php selected( 'users_browsing_page', $type ); ?>><?php _e( 'Users Browsing Current Page', 'wp-useronline' ); ?></option>
63
+ <option value="users_browsing_site"<?php selected( 'users_browsing_site', $type ); ?>><?php _e( 'Users Browsing Site', 'wp-useronline' ); ?></option>
64
  <optgroup>&nbsp;</optgroup>
65
+ <option value="users_online_browsing_page"<?php selected( 'users_online_browsing_page', $type ); ?>><?php _e( 'Users Online Count & Users Browsing Current Page', 'wp-useronline' ); ?></option>
66
+ <option value="users_online_browsing_site"<?php selected( 'users_online_browsing_site', $type ); ?>><?php _e( 'Users Online Count & Users Browsing Site', 'wp-useronline' ); ?></option>
67
  </select>
68
  </label>
69
  </p>
70
+ <input type="hidden" id="<?php echo $this->get_field_id( 'submit' ); ?>" name="<?php echo $this->get_field_name( 'submit' ); ?>" value="1" />
71
  <?php
72
  }
73
  }
wp-stats.php CHANGED
@@ -3,35 +3,35 @@
3
  class UserOnline_WpStats {
4
 
5
  function init() {
6
- add_filter('wp_stats_page_admin_plugins', array(__CLASS__, 'page_admin_general_stats'));
7
- add_filter('wp_stats_page_plugins', array(__CLASS__, 'page_general_stats'));
8
  }
9
 
10
  // Add WP-UserOnline General Stats To WP-Stats Page Options
11
- function page_admin_general_stats($content) {
12
- $stats_display = get_option('stats_display');
13
-
14
- $content .= '<input type="checkbox" name="stats_display[]" id="wpstats_useronline" value="useronline"' . checked($stats_display['useronline'], 1, false) . '/>&nbsp;&nbsp;<label for="wpstats_useronline">'.__('WP-UserOnline', 'wp-useronline').'</label><br />'."\n";
15
 
16
  return $content;
17
  }
18
 
19
  // Add WP-UserOnline General Stats To WP-Stats Page
20
- function page_general_stats($content) {
21
- $stats_display = get_option('stats_display');
22
 
23
  $str = _n(
24
  '<strong>%s</strong> user online now.',
25
- '<strong>%s</strong> users online now.',
26
  get_users_online_count(), 'wp-useronline'
27
  );
28
 
29
  if ( $stats_display['useronline'] == 1 )
30
- $content .=
31
- html('p', html('strong', __('WP-UserOnline', 'wp-useronline')))
32
- .html('ul',
33
- html('li', sprintf($str, number_format_i18n(get_users_online_count())))
34
- .html('li', UserOnline_Template::format_most_users())
35
  );
36
 
37
  return $content;
3
  class UserOnline_WpStats {
4
 
5
  function init() {
6
+ add_filter( 'wp_stats_page_admin_plugins', array( __CLASS__, 'page_admin_general_stats' ) );
7
+ add_filter( 'wp_stats_page_plugins', array( __CLASS__, 'page_general_stats' ) );
8
  }
9
 
10
  // Add WP-UserOnline General Stats To WP-Stats Page Options
11
+ function page_admin_general_stats( $content ) {
12
+ $stats_display = get_option( 'stats_display' );
13
+
14
+ $content .= '<input type="checkbox" name="stats_display[]" id="wpstats_useronline" value="useronline"' . checked( $stats_display['useronline'], 1, false ) . '/>&nbsp;&nbsp;<label for="wpstats_useronline">'.__( 'WP-UserOnline', 'wp-useronline' ).'</label><br />'."\n";
15
 
16
  return $content;
17
  }
18
 
19
  // Add WP-UserOnline General Stats To WP-Stats Page
20
+ function page_general_stats( $content ) {
21
+ $stats_display = get_option( 'stats_display' );
22
 
23
  $str = _n(
24
  '<strong>%s</strong> user online now.',
25
+ '<strong>%s</strong> users online now.',
26
  get_users_online_count(), 'wp-useronline'
27
  );
28
 
29
  if ( $stats_display['useronline'] == 1 )
30
+ $content .=
31
+ html( 'p', html( 'strong', __( 'WP-UserOnline', 'wp-useronline' ) ) )
32
+ .html( 'ul',
33
+ html( 'li', sprintf( $str, number_format_i18n( get_users_online_count() ) ) )
34
+ .html( 'li', UserOnline_Template::format_most_users() )
35
  );
36
 
37
  return $content;
wp-useronline.php CHANGED
@@ -3,16 +3,16 @@
3
  Plugin Name: WP-UserOnline
4
  Plugin URI: http://wordpress.org/extend/plugins/wp-useronline/
5
  Description: Enable you to display how many users are online on your Wordpress site
6
- Version: 2.73
7
  Author: Lester 'GaMerZ' Chan & scribu
8
 
9
 
10
- Copyright 2009 Lester Chan (email : lesterchan@gmail.com)
11
 
12
  This program is free software; you can redistribute it and/or modify
13
  it under the terms of the GNU General Public License as published by
14
  the Free Software Foundation; either version 2 of the License, or
15
- (at your option) any later version.
16
 
17
  This program is distributed in the hope that it will be useful,
18
  but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -24,324 +24,85 @@ along with this program; if not, write to the Free Software
24
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
  */
26
 
27
- class UserOnline_Core {
28
- static $options;
29
 
30
- static $most;
31
-
32
- private static $useronline;
33
-
34
- function get_user_online_count() {
35
- global $wpdb;
36
-
37
- if ( is_null(self::$useronline) )
38
- self::$useronline = intval($wpdb->get_var("SELECT COUNT(*) FROM $wpdb->useronline"));
39
-
40
- return self::$useronline;
41
- }
42
-
43
- function init() {
44
- add_action('plugins_loaded', array(__CLASS__, 'wp_stats_integration'));
45
-
46
- add_action('template_redirect', array(__CLASS__, 'scripts'));
47
-
48
- add_action('admin_head', array(__CLASS__, 'record'));
49
- add_action('wp_head', array(__CLASS__, 'record'));
50
-
51
- add_action('wp_ajax_useronline', array(__CLASS__, 'ajax'));
52
- add_action('wp_ajax_nopriv_useronline', array(__CLASS__, 'ajax'));
53
-
54
- add_shortcode('page_useronline', 'users_online_page');
55
-
56
- register_activation_hook(__FILE__, array(__CLASS__, 'upgrade'));
57
-
58
- // Table
59
- new scbTable('useronline', __FILE__, "
60
- timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
61
- user_type varchar(20) NOT NULL default 'guest',
62
- user_id bigint(20) NOT NULL default 0,
63
- user_name varchar(250) NOT NULL default '',
64
- user_ip varchar(20) NOT NULL default '',
65
- user_agent text NOT NULL default '',
66
- page_title text NOT NULL default '',
67
- page_url varchar(255) NOT NULL default '',
68
- referral varchar(255) NOT NULL default '',
69
- UNIQUE KEY useronline_id (timestamp, user_type, user_ip)
70
- ");
71
-
72
- self::$most = new scbOptions('useronline_most', __FILE__, array(
73
- 'count' => 1,
74
- 'date' => current_time('timestamp')
75
- ));
76
-
77
- self::$options = new scbOptions('useronline', __FILE__, array(
78
- 'timeout' => 300,
79
- 'url' => trailingslashit(get_bloginfo('url')) . 'useronline',
80
- 'names' => false,
81
-
82
- 'naming' => array(
83
- 'user' => __('1 User', 'wp-useronline'),
84
- 'users' => __('%COUNT% Users', 'wp-useronline'),
85
- 'member' => __('1 Member', 'wp-useronline'),
86
- 'members' => __('%COUNT% Members', 'wp-useronline'),
87
- 'guest' => __('1 Guest', 'wp-useronline'),
88
- 'guests' => __('%COUNT% Guests', 'wp-useronline'),
89
- 'bot' => __('1 Bot', 'wp-useronline'),
90
- 'bots' => __('%COUNT% Bots', 'wp-useronline')
91
  ),
92
 
93
- 'templates' => array(
94
- 'useronline' => '<a href="%PAGE_URL%"><strong>%USERS%</strong> '.__('Online', 'wp-useronline').'</a>',
95
-
96
- 'browsingsite' => array(
97
- 'separators' => array(
98
- 'members' => __(',', 'wp-useronline').' ',
99
- 'guests' => __(',', 'wp-useronline').' ',
100
- 'bots' => __(',', 'wp-useronline').' ',
101
- ),
102
- 'text' => _x('Users', 'Template Element', 'wp-useronline').': <strong>%MEMBER_NAMES%%GUESTS_SEPERATOR%%GUESTS%%BOTS_SEPERATOR%%BOTS%</strong>'
103
  ),
104
-
105
- 'browsingpage' => array(
106
- 'separators' => array(
107
- 'members' => __(',', 'wp-useronline').' ',
108
- 'guests' => __(',', 'wp-useronline').' ',
109
- 'bots' => __(',', 'wp-useronline').' ',
110
- ),
111
- 'text' => '<strong>%USERS%</strong> '.__('Browsing This Page.', 'wp-useronline').'<br />'._x('Users', 'Template Element', 'wp-useronline').': <strong>%MEMBER_NAMES%%GUESTS_SEPERATOR%%GUESTS%%BOTS_SEPERATOR%%BOTS%</strong>'
112
- )
113
  )
114
- ));
115
- }
116
-
117
- function upgrade() {
118
- global $wpdb;
119
-
120
- // WP >= 2.70
121
- if ( $options = get_option('useronline') ) {
122
- array_walk(&$options['naming'], array(__CLASS__, '_update_template'));
123
 
124
- update_option('useronline', $options);
125
 
126
- $most = get_option('useronline_most');
127
-
128
- if ( !is_int($most['date']) )
129
- $most['date'] = strtotime($most['date']);
130
-
131
- update_option('useronline_most', $most);
132
-
133
- return;
134
- }
135
-
136
- // WP < 2.70
137
- $count = self::get_and_delete_option('useronline_most_users');
138
- $date = self::get_and_delete_option('useronline_most_timestamp');
139
-
140
- if ( !$count )
141
- return;
142
-
143
- add_option('useronline_most', compact('count', 'date'));
144
-
145
- $naming = self::get_and_delete_option('useronline_naming');
146
- array_walk($naming, array(__CLASS__, '_update_template'));
147
-
148
- $templates['useronline'] = str_replace('%USERONLINE_', '%', self::get_and_delete_option('useronline_template_useronline'));
149
-
150
- foreach ( array('browsingsite', 'browsingpage') as $template ) {
151
- list($members, $guests, $bots, $text) = self::get_and_delete_option("useronline_template_$template");
152
- $templates[$template] = array(
153
- 'text' => str_replace('%USERONLINE_', '%', $text),
154
- 'separators' => compact('members', 'guests', 'bots'),
155
- );
156
- }
157
-
158
- $options = compact('naming', 'templates');
159
- foreach ( array('timeout', 'url') as $option )
160
- $options[$option] = self::get_and_delete_option("useronline_$option");
161
-
162
- add_option('useronline', $options);
163
-
164
- delete_option('useronline_bots');
165
-
166
- $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}useronline");
167
- }
168
-
169
- function _update_template(&$text) {
170
- $text = str_replace('%USERONLINE_', '%', $text);
171
- }
172
-
173
- private function get_and_delete_option($key) {
174
- $val = get_option($key);
175
- delete_option($key);
176
- return $val;
177
- }
178
-
179
- function scripts() {
180
- $js_dev = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : '';
181
-
182
- wp_enqueue_script('wp-useronline', plugins_url("useronline$js_dev.js", __FILE__), array('jquery'), '2.70', true);
183
- wp_localize_script('wp-useronline', 'useronlineL10n', array(
184
- 'ajax_url' => admin_url('admin-ajax.php'),
185
- 'timeout' => self::$options->timeout * 1000
186
- ));
187
- }
188
-
189
- function record() {
190
- global $wpdb;
191
-
192
- $user_ip = self::get_ip();
193
- $user_agent = $_SERVER['HTTP_USER_AGENT'];
194
- $page_url = $_SERVER['REQUEST_URI'];
195
-
196
- $referral = strip_tags(@$_SERVER['HTTP_REFERER']);
197
-
198
- $current_user = wp_get_current_user();
199
-
200
- // Check For Bot
201
- $bots = array('Google Bot' => 'googlebot', 'Google Bot' => 'google', 'MSN' => 'msnbot', 'Alex' => 'ia_archiver', 'Lycos' => 'lycos', 'Ask Jeeves' => 'jeeves', 'Altavista' => 'scooter', 'AllTheWeb' => 'fast-webcrawler', 'Inktomi' => 'slurp@inktomi', 'Turnitin.com' => 'turnitinbot', 'Technorati' => 'technorati', 'Yahoo' => 'yahoo', 'Findexa' => 'findexa', 'NextLinks' => 'findlinks', 'Gais' => 'gaisbo', 'WiseNut' => 'zyborg', 'WhoisSource' => 'surveybot', 'Bloglines' => 'bloglines', 'BlogSearch' => 'blogsearch', 'PubSub' => 'pubsub', 'Syndic8' => 'syndic8', 'RadioUserland' => 'userland', 'Gigabot' => 'gigabot', 'Become.com' => 'become.com', 'Baidu' => 'baidu', 'Yandex' => 'yandex');
202
-
203
- $bot_found = false;
204
- foreach ( $bots as $name => $lookfor )
205
- if ( stristr($user_agent, $lookfor) !== false ) {
206
- $user_id = 0;
207
- $user_name = $name;
208
- $username = $lookfor;
209
- $user_type = 'bot';
210
- $bot_found = true;
211
-
212
- break;
213
- }
214
-
215
- $where = $wpdb->prepare("WHERE user_ip = %s", $user_ip);
216
-
217
- // If No Bot Is Found, Then We Check Members And Guests
218
- if ( !$bot_found ) {
219
- if ( $current_user->ID ) {
220
- // Check For Member
221
- $user_id = $current_user->ID;
222
- $user_name = $current_user->display_name;
223
- $user_type = 'member';
224
- $where = $wpdb->prepare("WHERE user_id = %d", $user_id);
225
- } elseif ( !empty($_COOKIE['comment_author_'.COOKIEHASH]) ) {
226
- // Check For Comment Author (Guest)
227
- $user_id = 0;
228
- $user_name = trim(strip_tags($_COOKIE['comment_author_'.COOKIEHASH]));
229
- $user_type = 'guest';
230
- } else {
231
- // Check For Guest
232
- $user_id = 0;
233
- $user_name = __('Guest', 'wp-useronline');
234
- $user_type = 'guest';
235
- }
236
- }
237
-
238
- // Check For Page Title
239
- if ( is_admin() && function_exists('get_admin_page_title') ) {
240
- $page_title = ' &raquo; ' . __('Admin', 'wp-useronline') . ' &raquo; ' . get_admin_page_title();
241
- } else {
242
- $page_title = wp_title('&raquo;', false);
243
- if ( empty($page_title) )
244
- $page_title = ' &raquo; ' . strip_tags($_SERVER['REQUEST_URI']);
245
- elseif ( is_singular() )
246
- $page_title = ' &raquo; ' . __('Archive', 'wp-useronline') . ' ' . $page_title;
247
- }
248
- $page_title = get_bloginfo('name') . $page_title;
249
-
250
- // Delete Users
251
- $delete_users = $wpdb->query($wpdb->prepare("
252
- DELETE FROM $wpdb->useronline
253
- $where OR timestamp < CURRENT_TIMESTAMP - %d
254
- ", self::$options->timeout));
255
-
256
- // Insert Users
257
- $data = compact('user_type', 'user_id', 'user_name', 'user_ip', 'user_agent', 'page_title', 'page_url', 'referral');
258
- $data = stripslashes_deep($data);
259
- $insert_user = $wpdb->insert($wpdb->useronline, $data);
260
-
261
- // Count Users Online
262
- self::$useronline = intval($wpdb->get_var("SELECT COUNT(*) FROM $wpdb->useronline"));
263
-
264
- // Maybe Update Most User Online
265
- if ( self::$useronline > self::$most->count )
266
- self::$most->update(array(
267
- 'count' => self::$useronline,
268
- 'date' => current_time('timestamp')
269
- ));
270
- }
271
-
272
- function ajax() {
273
- $mode = trim($_POST['mode']);
274
-
275
- switch($mode) {
276
- case 'count':
277
- users_online();
278
- break;
279
- case 'browsingsite':
280
- users_browsing_site();
281
- break;
282
- case 'browsingpage':
283
- users_browsing_page();
284
- break;
285
- }
286
-
287
- die;
288
- }
289
-
290
- function wp_stats_integration() {
291
- if ( function_exists('stats_page') )
292
- require_once dirname(__FILE__) . '/wp-stats.php';
293
- }
294
-
295
- private function get_ip() {
296
- if ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) )
297
- $ip_address = $_SERVER["HTTP_X_FORWARDED_FOR"];
298
- else
299
- $ip_address = $_SERVER["REMOTE_ADDR"];
300
-
301
- list($ip_address) = explode(',', $ip_address);
302
-
303
- return $ip_address;
304
- }
305
-
306
- private function clear_table() {
307
- global $wpdb;
308
-
309
- $wpdb->query("DELETE FROM $wpdb->useronline");
310
- }
311
- }
312
-
313
- function _useronline_init() {
314
- require_once dirname(__FILE__) . '/scb/load.php';
315
-
316
- require_once dirname(__FILE__) . '/template-tags.php';
317
- require_once dirname(__FILE__) . '/deprecated.php';
318
-
319
- load_plugin_textdomain('wp-useronline', '', dirname(plugin_basename(__FILE__)) . '/lang');
320
-
321
- UserOnline_Core::init();
322
-
323
- if ( UserOnline_Core::$options->names )
324
- add_filter('useronline_display_user', 'wpu_linked_names', 10, 2);
325
-
326
- require_once dirname(__FILE__) . '/widget.php';
327
- scbWidget::init('UserOnline_Widget', __FILE__, 'useronline');
328
-
329
- if ( function_exists('stats_page') )
330
- require_once dirname(__FILE__) . '/wp-stats.php';
331
 
332
  if ( is_admin() ) {
333
- require_once dirname(__FILE__) . '/admin.php';
334
- scbAdminPage::register('UserOnline_Admin_Integration', __FILE__);
335
- scbAdminPage::register('UserOnline_Options', __FILE__, UserOnline_Core::$options);
336
- }
337
- }
338
- _useronline_init();
339
-
340
 
341
- function wpu_linked_names($name, $user) {
342
- if ( !$user->user_id )
343
- return $name;
344
-
345
- return html_link(get_author_posts_url($user->user_id), $name);
346
  }
 
347
 
3
  Plugin Name: WP-UserOnline
4
  Plugin URI: http://wordpress.org/extend/plugins/wp-useronline/
5
  Description: Enable you to display how many users are online on your Wordpress site
6
+ Version: 2.80
7
  Author: Lester 'GaMerZ' Chan & scribu
8
 
9
 
10
+ Copyright 2009 Lester Chan ( email : lesterchan@gmail.com )
11
 
12
  This program is free software; you can redistribute it and/or modify
13
  it under the terms of the GNU General Public License as published by
14
  the Free Software Foundation; either version 2 of the License, or
15
+ ( at your option ) any later version.
16
 
17
  This program is distributed in the hope that it will be useful,
18
  but WITHOUT ANY WARRANTY; without even the implied warranty of
24
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
  */
26
 
27
+ require_once dirname( __FILE__ ) . '/scb/load.php';
 
28
 
29
+ function _useronline_init() {
30
+ load_plugin_textdomain( 'wp-useronline', '', dirname( plugin_basename( __FILE__ ) ) . '/lang' );
31
+
32
+ require_once dirname( __FILE__ ) . '/core.php';
33
+ require_once dirname( __FILE__ ) . '/template-tags.php';
34
+ require_once dirname( __FILE__ ) . '/deprecated.php';
35
+ require_once dirname( __FILE__ ) . '/widget.php';
36
+
37
+ new scbTable( 'useronline', __FILE__, "
38
+ timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
39
+ user_type varchar( 20 ) NOT NULL default 'guest',
40
+ user_id bigint( 20 ) NOT NULL default 0,
41
+ user_name varchar( 250 ) NOT NULL default '',
42
+ user_ip varchar( 20 ) NOT NULL default '',
43
+ user_agent text NOT NULL,
44
+ page_title text NOT NULL,
45
+ page_url varchar( 255 ) NOT NULL default '',
46
+ referral varchar( 255 ) NOT NULL default '',
47
+ UNIQUE KEY useronline_id ( timestamp, user_type, user_ip )
48
+ ", 'delete_first' );
49
+
50
+ $most = new scbOptions( 'useronline_most', __FILE__, array(
51
+ 'count' => 1,
52
+ 'date' => current_time( 'timestamp' )
53
+ ) );
54
+
55
+ $options = new scbOptions( 'useronline', __FILE__, array(
56
+ 'timeout' => 300,
57
+ 'url' => trailingslashit( get_bloginfo( 'url' ) ) . 'useronline',
58
+ 'names' => false,
59
+
60
+ 'naming' => array(
61
+ 'user' => __( '1 User', 'wp-useronline' ),
62
+ 'users' => __( '%COUNT% Users', 'wp-useronline' ),
63
+ 'member' => __( '1 Member', 'wp-useronline' ),
64
+ 'members' => __( '%COUNT% Members', 'wp-useronline' ),
65
+ 'guest' => __( '1 Guest', 'wp-useronline' ),
66
+ 'guests' => __( '%COUNT% Guests', 'wp-useronline' ),
67
+ 'bot' => __( '1 Bot', 'wp-useronline' ),
68
+ 'bots' => __( '%COUNT% Bots', 'wp-useronline' )
69
+ ),
70
+
71
+ 'templates' => array(
72
+ 'useronline' => '<a href="%PAGE_URL%"><strong>%USERS%</strong> '.__( 'Online', 'wp-useronline' ).'</a>',
73
+
74
+ 'browsingsite' => array(
75
+ 'separators' => array(
76
+ 'members' => __( ',', 'wp-useronline' ).' ',
77
+ 'guests' => __( ',', 'wp-useronline' ).' ',
78
+ 'bots' => __( ',', 'wp-useronline' ).' ',
79
+ ),
80
+ 'text' => _x( 'Users', 'Template Element', 'wp-useronline' ).': <strong>%MEMBER_NAMES%%GUESTS_SEPERATOR%%GUESTS%%BOTS_SEPERATOR%%BOTS%</strong>'
 
 
 
 
 
 
 
 
 
81
  ),
82
 
83
+ 'browsingpage' => array(
84
+ 'separators' => array(
85
+ 'members' => __( ',', 'wp-useronline' ).' ',
86
+ 'guests' => __( ',', 'wp-useronline' ).' ',
87
+ 'bots' => __( ',', 'wp-useronline' ).' ',
 
 
 
 
 
88
  ),
89
+ 'text' => '<strong>%USERS%</strong> '.__( 'Browsing This Page.', 'wp-useronline' ).'<br />'._x( 'Users', 'Template Element', 'wp-useronline' ).': <strong>%MEMBER_NAMES%%GUESTS_SEPERATOR%%GUESTS%%BOTS_SEPERATOR%%BOTS%</strong>'
 
 
 
 
 
 
 
 
90
  )
91
+ )
92
+ ) );
 
 
 
 
 
 
 
93
 
94
+ UserOnline_Core::init( $options, $most );
95
 
96
+ scbWidget::init( 'UserOnline_Widget', __FILE__, 'useronline' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
  if ( is_admin() ) {
99
+ require_once dirname( __FILE__ ) . '/admin.php';
100
+ scbAdminPage::register( 'UserOnline_Admin_Integration', __FILE__ );
101
+ scbAdminPage::register( 'UserOnline_Options', __FILE__, UserOnline_Core::$options );
 
 
 
 
102
 
103
+ if ( function_exists( 'stats_page' ) )
104
+ require_once dirname( __FILE__ ) . '/wp-stats.php';
105
+ }
 
 
106
  }
107
+ scb_init( '_useronline_init' );
108