Changeset 6286
- Timestamp:
- 08/12/06 17:47:30 (2 years ago)
- Files:
-
- wp-useronline/trunk/readme.html (modified) (4 diffs)
- wp-useronline/trunk/useronline/useronline-options.php (modified) (2 diffs)
- wp-useronline/trunk/useronline/useronline-widget.php (modified) (3 diffs)
- wp-useronline/trunk/useronline/useronline.php (modified) (20 diffs)
- wp-useronline/trunk/useronline/wp-useronline.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
wp-useronline/trunk/readme.html
r6254 r6286 211 211 <p><b>Development:</b><br /><b>»</b> <a href="http://dev.wp-plugins.org/browser/wp-useronline/" title="http://dev.wp-plugins.org/browser/wp-useronline/">http://dev.wp-plugins.org/browser/wp-useronline/</a></p> 212 212 <p><b>Support Forums:</b><br /><b>»</b> <a href="http://forums.lesterchan.net/viewforum.php?f=10" title="http://forums.lesterchan.net/viewforum.php?f=10">http://forums.lesterchan.net/viewforum.php?f=10</a></p> 213 <p><b>Updated:</b><br /><b>»</b> 1st August 2006</p> 213 <p><b>Updated:</b><br /><b>»</b> 1st October 2006</p> 214 <p><b>Note:</b><br /><b>»</b> I have changed some of WP-UserOnline's structure, So if there is any bug, please contact me immediately.</p> 214 215 <div class="SubSubTitle">Changelog</div> 215 216 <ul> 216 217 <li> 217 <b>Version 2.05 (01-08-2006)</b> 218 <ul> 218 <b>Version 2.05 (01-10-2006)</b> 219 <ul> 220 <li>NEW: UserOnline Is Now Embedded Into A Page, And Hence No More Integrating Of UserOnline Page</li> 221 <li>NEW: Changed In WP-UserOnline Structure: Members Mean Registered Users and Guests Mean Comment Authors</li> 219 222 <li>NEW: get_users_browsing_site(false) And get_users_browsing_page(false) Will Now Return An Array Containing Total Users, Total Members, Total Guests and Total Bots Online</li> 223 <li>NEW: Added Widget Title Option To WP-UserOnline Widget</li> 220 224 <li>FIXED: Invalid IP Error</li> 221 225 <li>FIXED: If Site URL Doesn't Match WP Option's Site URL, WP-UserOnline Will Not Work</li> … … 304 308 </li> 305 309 <li> 306 Delete :310 Delete file if exists: 307 311 <blockquote>File: wp-useronline.php</blockquote> 308 312 </li> 309 313 <li> 310 314 Open <b>wp-content/plugins</b> Folder 311 </li>312 <li>313 Delete:314 <blockquote>File: useronline.php</blockquote>315 315 </li> 316 316 <li> 317 317 Put: 318 318 <blockquote>Folder: useronline</blockquote> 319 </li> 320 <li> 321 Delete file if exists: 322 <blockquote>File: useronline.php</blockquote> 323 </li> 324 <li> 325 Open <b>wp-content/plugins/useronline</b> Folder 326 </li> 327 <li> 328 Delete file if exists: 329 <blockquote>File: wp-useronline.php</blockquote> 319 330 </li> 320 331 <li> … … 330 341 <div id="Usage" style="display: none;"> 331 342 <div class="SubTitle">» Usage Instructions</div> 332 <div class="SubSubTitle">General Usage </div>343 <div class="SubSubTitle">General Usage (Without Widget)</div> 333 344 <ol> 334 345 <li> … … 348 359 </blockquote> 349 360 </li> 350 <li> 351 Tutorial On How To Integrate wp-useronline.php With Your Theme: 352 <blockquote><a href="http://www.lesterchan.net/wordpress/tutorials/integrating/" target="_blank">http://www.lesterchan.net/wordpress/tutorials/integrating/</a></blockquote> 361 </ol> 362 <div class="SubSubTitle">General Usage (With Widget)</div> 363 <ol> 364 <li> 365 <b>Activate</b> WP-UserOnline Widget Plugin 366 </li> 367 <li> 368 Go to 'WP-Admin -> Presentation -> Sidebar Widgets' 369 </li> 370 <li> 371 <b>Drag</b> the UserOnline Widget to your sidebar 372 </li> 373 <li> 374 You can <b>configure</b> the UserOnline Widget by clicking on the configure icon 375 </li> 376 <li> 377 Click 'Save changes' 378 </li> 379 <li> 380 Scroll down for instructions on how to create a <b>UserOnline Page</b>. 381 </li> 382 </ol> 383 <div class="SubSubTitle">UserOnline Page</div> 384 <ol> 385 <li> 386 Go to 'WP-Admin -> Write -> Write Page' 387 </li> 388 <li> 389 Type any title you like in the post's title area 390 </li> 391 <li> 392 Type '<b><page_useronline></b>' in the post's content area (without the quotes) 393 </li> 394 <li> 395 Type '<b>useronline</b>' in the post's slug area (without the quotes) 396 </li> 397 <li> 398 Click 'Publish' 353 399 </li> 354 400 </ol> wp-useronline/trunk/useronline/useronline-options.php
r6244 r6286 34 34 $useronline_bots[trim($useronline_bots_keys[$i])] = trim($useronline_bots_vals[$i]); 35 35 } 36 $useronline_url = addslashes(trim($_POST['useronline_url'])); 36 37 $update_useronline_queries = array(); 37 38 $update_useronline_text = array(); 38 39 $update_useronline_queries[] = update_option('useronline_timeout', $useronline_timeout); 39 40 $update_useronline_queries[] = update_option('useronline_bots', $useronline_bots); 41 $update_useronline_queries[] = update_option('useronline_url', $useronline_url); 40 42 $update_useronline_text[] = __('Useronline Timeout'); 41 43 $update_useronline_text[] = __('Useronline Bots'); 44 $update_useronline_text[] = __('Useronline URL'); 42 45 $i=0; 43 46 $text = ''; … … 77 80 </td> 78 81 </tr> 82 <tr valign="top"> 83 <th align="left" width="30%"><?php _e('UserOnline URL'); ?></th> 84 <td align="left"> 85 <input type="text" name="useronline_url" value="<?php echo get_settings('useronline_url'); ?>" size="50" /><br />URL To UserOnline Page. 86 </td> 87 </tr> 79 88 <tr valign="top"> 80 89 <th align="left" width="30%"><?php _e('Bots Name/User Agent'); ?></th> wp-useronline/trunk/useronline/useronline-widget.php
r6244 r6286 38 38 extract($args); 39 39 $options = get_option('widget_useronline'); 40 $title = __('UserOnline');40 $title = htmlspecialchars($options['title']); 41 41 echo $before_widget.$before_title.$title.$after_title; 42 42 if (function_exists('useronline')) { … … 59 59 $options = get_option('widget_useronline'); 60 60 if (!is_array($options)) { 61 $options = array('display_usersbrowsingsite' => '0' );61 $options = array('display_usersbrowsingsite' => '0', 'title' => 'UserOnline'); 62 62 } 63 63 if ($_POST['useronline-submit']) { 64 64 $options['display_usersbrowsingsite'] = intval($_POST['useronline-usersbrowsingsite']); 65 $options['title'] = strip_tags(stripslashes($_POST['useronline-title'])); 65 66 update_option('widget_useronline', $options); 66 67 } 68 echo '<p style="text-align: left;"><label for="useronline-title">Widget Title:</label> <input type="text" id="useronline-title" name="useronline-title" value="'.htmlspecialchars($options['title']).'" />'; 67 69 echo '<p style="text-align: center;"><label for="useronline-usersbrowsingsite">Display Users Browsing Site Under Users Online Count?</label></p>'."\n"; 68 70 echo '<p style="text-align: center;"><input type="radio" id="useronline-usersbrowsingsite" name="useronline-usersbrowsingsite" value="1"'; … … 76 78 // Register Widgets 77 79 register_sidebar_widget('UserOnline', 'widget_useronline'); 78 register_widget_control('UserOnline', 'widget_useronline_options', 350, 1 00);80 register_widget_control('UserOnline', 'widget_useronline_options', 350, 120); 79 81 } 80 82 wp-useronline/trunk/useronline/useronline.php
r6254 r6286 90 90 add_action('wp_head', 'useronline'); 91 91 function useronline() { 92 global $wpdb, $useronline , $user_identity;92 global $wpdb, $useronline; 93 93 // Useronline Settings 94 94 $timeoutseconds = get_settings('useronline_timeout'); … … 98 98 $url = addslashes(urlencode($_SERVER['REQUEST_URI'])); 99 99 $useragent = $_SERVER['HTTP_USER_AGENT']; 100 101 // Check For Members 102 if(!empty($_COOKIE['comment_author_'.COOKIEHASH])) { 103 $memberonline = addslashes(trim($_COOKIE['comment_author_'.COOKIEHASH])); 104 $where = "WHERE username='$memberonline'"; 105 // Check For Admins 106 } elseif(!empty($user_identity)) { 107 $memberonline = addslashes($user_identity); 108 $where = "WHERE username='$memberonline'"; 109 // Check For Guests 110 } else { 111 $memberonline = 'Guest'; 112 $where = "WHERE ip='$ip'"; 113 } 100 $current_user = wp_get_current_user(); 101 114 102 // Check For Bot 115 103 $bots = get_settings('useronline_bots'); 116 104 foreach ($bots as $name => $lookfor) { 117 105 if (stristr($useragent, $lookfor) !== false) { 118 $memberonline = addslashes($name); 119 $where = "WHERE ip='$ip'"; 106 $user_id = 0; 107 $display_name = addslashes($name); 108 $user_name = addslashes($lookfor); 109 $type = 'bot'; 110 $where = "WHERE ip = '$ip'"; 111 $bot_found = true; 120 112 break; 121 113 } 122 114 } 115 116 // If No Bot Is Found, Then We Check Members And Guests 117 if(!$bot_found) { 118 // Check For Member 119 if($current_user->ID > 0) { 120 $user_id = $current_user->ID; 121 $display_name = addslashes($current_user->display_name); 122 $user_name = addslashes($current_user->user_login); 123 $type = 'member'; 124 $where = "WHERE userid = '$user_id'"; 125 // Check For Comment Author (Guest) 126 } elseif(!empty($_COOKIE['comment_author_'.COOKIEHASH])) { 127 $user_id = 0; 128 $display_name = addslashes(trim($_COOKIE['comment_author_'.COOKIEHASH])); 129 $user_name = "guest_$display_name"; 130 $type = 'guest'; 131 $where = "WHERE ip = '$ip'"; 132 // Check For Guest 133 } else { 134 $user_id = 0; 135 $display_name = 'Guest'; 136 $user_name = "guest"; 137 $type = 'guest'; 138 $where = "WHERE ip = '$ip'"; 139 } 140 } 141 142 // Get User Agent 123 143 $useragent = addslashes($useragent); 124 144 … … 138 158 139 159 // Insert Users 140 $insert_user = $wpdb->query("INSERT INTO $wpdb->useronline VALUES ('$timestamp', '$ memberonline', '$useragent', '$ip', '$make_page', '$url')");160 $insert_user = $wpdb->query("INSERT INTO $wpdb->useronline VALUES ('$timestamp', '$user_id', '$user_name', '$display_name', '$useragent', '$ip', '$make_page', '$url', '$type')"); 141 161 142 162 // Count Users Online … … 158 178 function get_useronline($user = 'User', $users = 'Users', $display = true) { 159 179 global $useronline; 180 $useronline_url = get_settings('useronline_url'); 160 181 // Display User Online 161 182 if($display) { 162 183 if($useronline > 1) { 163 echo '<a href="'. get_settings('siteurl').'/wp-content/plugins/useronline/wp-useronline.php"><b>'.number_format($useronline).'</b> '.$users.' '.__('Online').'</a>'."\n";184 echo '<a href="'.$useronline_url.'"><b>'.number_format($useronline).'</b> '.$users.' '.__('Online').'</a>'."\n"; 164 185 } else { 165 echo '<a href="'. get_settings('siteurl').'/wp-content/plugins/useronline/wp-useronline.php"><b>'.$useronline.'</b> '.$user.' '.__('Online').'</a>'."\n";186 echo '<a href="'.$useronline_url.'"><b>'.$useronline.'</b> '.$user.' '.__('Online').'</a>'."\n"; 166 187 } 167 188 } else { … … 186 207 ### Function: Display Max UserOnline Date 187 208 if(!function_exists('get_most_useronline_date')) { 188 function get_most_useronline_date($d ate_format = 'jS F Y, H:i', $display =true) {209 function get_most_useronline_date($display = true, $date_format = 'jS F Y, H:i') { 189 210 $most_useronline_timestamp = get_settings('useronline_most_timestamp'); 190 211 $most_useronline_date = gmdate($date_format, $most_useronline_timestamp); … … 204 225 // Get Users Browsing Site 205 226 $page_url = addslashes(urlencode($_SERVER['REQUEST_URI'])); 206 $users_browse = $wpdb->get_results("SELECT username FROM $wpdb->useronline");227 $users_browse = $wpdb->get_results("SELECT displayname, type FROM $wpdb->useronline ORDER BY type"); 207 228 208 229 // Variables 209 230 $members = array(); 231 $guests = array(); 232 $bots = array(); 210 233 $total_users = 0; 211 234 $total_members = 0; … … 218 241 // If There Is Users Browsing, Then We Execute 219 242 if($users_browse) { 220 // Reassign Bots Name221 $bots = get_settings('useronline_bots');222 $bots_name = array();223 foreach($bots as $botname => $botlookfor) {224 $bots_name[] = $botname;225 }226 243 // Get Users Information 227 244 foreach($users_browse as $user_browse) { 228 if($user_browse->username == 'Guest') { 229 $total_guests++; 230 } elseif(in_array($user_browse->username, $bots_name)) { 231 $total_bots++; 232 } else { 233 $members[] = stripslashes($user_browse->username); 234 $total_members++; 245 switch($user_browse->type) { 246 case 'member': 247 $members[] = stripslashes($user_browse->displayname); 248 $total_members++; 249 break; 250 case 'guest': 251 $guests[] = stripslashes($user_browse->displayname); 252 $total_guests++; 253 break; 254 case 'bot': 255 $bots[] = stripslashes($user_browse->displayname); 256 $total_bots++; 257 break; 235 258 } 236 259 } … … 289 312 // Get Users Browsing Page 290 313 $page_url = addslashes(urlencode($_SERVER['REQUEST_URI'])); 291 $users_browse = $wpdb->get_results("SELECT username FROM $wpdb->useronline WHERE url = '$page_url'");314 $users_browse = $wpdb->get_results("SELECT displayname, type FROM $wpdb->useronline WHERE url = '$page_url' ORDER BY type"); 292 315 293 316 // Variables 294 317 $members = array(); 318 $guests = array(); 319 $bots = array(); 295 320 $total_users = 0; 296 321 $total_members = 0; … … 311 336 // Get Users Information 312 337 foreach($users_browse as $user_browse) { 313 if($user_browse->username == 'Guest') { 314 $total_guests++; 315 } elseif(in_array($user_browse->username, $bots_name)) { 316 $total_bots++; 317 } else { 318 $members[] = stripslashes($user_browse->username); 319 $total_members++; 338 switch($user_browse->type) { 339 case 'member': 340 $members[] = stripslashes($user_browse->displayname); 341 $total_members++; 342 break; 343 case 'guest': 344 $guests[] = stripslashes($user_browse->displayname); 345 $total_guests++; 346 break; 347 case 'bot': 348 $bots[] = stripslashes($user_browse->displayname); 349 $total_bots++; 350 break; 320 351 } 321 352 } … … 386 417 ### Function: Check IP 387 418 function check_ip($ip) { 388 $ip2long = ip2long($ip); 389 if(is_user_logged_in() && ($ip != 'unknown') && $ip == long2ip($ip2long) && $ip2long !== false) { 390 return "(<a href=\"http://ws.arin.net/cgi-bin/whois.pl?queryinput=$ip\" target=\"_blank\" title=\"".gethostbyaddr($ip)."\">$ip</a>)"; 391 } 419 $current_user = wp_get_current_user(); 420 $user_level = intval($current_user->wp_user_level); 421 $ip2long = ip2long($ip); 422 if($user_level == 10 && ($ip != 'unknown') && $ip == long2ip($ip2long) && $ip2long !== false) { 423 return "(<a href=\"http://ws.arin.net/cgi-bin/whois.pl?queryinput=$ip\" target=\"_blank\" title=\"".gethostbyaddr($ip)."\">$ip</a>)"; 424 } 425 } 426 427 428 ### Function Check If User Is Online 429 function is_online($user_login) { 430 global $wpdb; 431 $is_online = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->useronline WHERE username = '$user_login' LIMIT 1"); 432 return intval($is_online); 392 433 } 393 434 … … 398 439 $country_code = wp_ozh_getCountryCode(0, $ip); 399 440 $country_name = wp_ozh_getCountryName(0, $ip); 441 $country_mirror = ''; 442 $mirrors = array("http://frenchfragfactory.net/images", "http://www.lesterchan.net/wordpress/images/flags"); 400 443 if($country_name != 'Private') { 401 $temp = '<img src="http://frenchfragfactory.net/images/flag_'.$country_code.'.gif" alt="'.$country_name.'" />'; 444 foreach($mirrors as $mirror) { 445 if(file($mirror.'/flag_sg.gif')) { 446 $country_mirror = $mirror; 447 break; 448 } 449 } 450 $temp = '<img src="'.$mirror.'/flag_'.$country_code.'.gif" alt="'.$country_name.'" />'; 402 451 if($display_countryname) { 403 452 $temp .= $country_name; … … 415 464 function display_useronline() { 416 465 global $wpdb; 417 // Reassign Bots Name418 $bots = get_settings('useronline_bots');419 $bots_name = array();420 foreach($bots as $botname => $botlookfor) {421 $bots_name[] = $botname;422 }423 424 466 // Get The Users Online 425 $usersonline = $wpdb->get_results("SELECT * FROM $wpdb->useronline ");467 $usersonline = $wpdb->get_results("SELECT * FROM $wpdb->useronline ORDER BY type"); 426 468 427 469 // Variables Variables Variables … … 441 483 if($usersonline) { 442 484 foreach($usersonline as $useronline) { 443 if($useronline->username == 'Guest') { 444 $guests[] = array('username' => stripslashes($useronline->username), 'timestamp' => $useronline->timestamp, 'ip' => $useronline->ip, 'location' => stripslashes($useronline->location), 'url' => stripslashes(urldecode($useronline->url))); 445 $total_guests++; 446 } elseif(in_array($useronline->username, $bots_name)) { 447 $bots[] = array('username' => stripslashes($useronline->username), 'timestamp' => $useronline->timestamp, 'ip' => $useronline->ip, 'location' => stripslashes($useronline->location), 'url' => stripslashes(urldecode($useronline->url))); 448 $total_bots++; 449 } else { 450 $members[] = array('username' => stripslashes($useronline->username), 'timestamp' => $useronline->timestamp, 'ip' => $useronline->ip, 'location' => stripslashes($useronline->location), 'url' => stripslashes(urldecode($useronline->url))); 451 $total_members++; 485 switch($useronline->type) { 486 case 'member': 487 $members[] = array('timestamp' => $useronline->timestamp, 'user_id' => $useronline->userid, 'user_name' => stripslashes($useronline->username), 'display_name' => stripslashes($useronline->displayname), 'user_agent' => stripslashes($useronline->useragent), 'ip' => $useronline->ip, 'location' => stripslashes($useronline->location), 'url' => stripslashes($useronline->url)); 488 $total_members++; 489 break; 490 case 'guest': 491 $guests[] = array('timestamp' => $useronline->timestamp, 'user_id' => $useronline->userid, 'user_name' => stripslashes($useronline->username), 'display_name' => stripslashes($useronline->displayname), 'user_agent' => stripslashes($useronline->useragent), 'ip' => $useronline->ip, 'location' => stripslashes($useronline->location), 'url' => stripslashes($useronline->url)); 492 $total_guests++; 493 break; 494 case 'bot': 495 $bots[] = array('timestamp' => $useronline->timestamp, 'user_id' => $useronline->userid, 'user_name' => stripslashes($useronline->username), 'display_name' => stripslashes($useronline->displayname), 'user_agent' => stripslashes($useronline->useragent), 'ip' => $useronline->ip, 'location' => stripslashes($useronline->location), 'url' => stripslashes($useronline->url)); 496 $total_bots++; 497 break; 452 498 } 453 499 } … … 482 528 } else { 483 529 $nicetext_bots = number_format($total_bots).' '.__('Bots'); 530 } 531 532 // Check Whether WP-Stats Is Activated 533 $wp_stats = false; 534 if(function_exists('get_totalposts')) { 535 $wp_stats = true; 484 536 } 485 537 ?> … … 496 548 $no=1; 497 549 if($members) { 498 $wp_stats = false;499 if(function_exists('get_totalposts')) {500 $wp_stats = true;501 }502 550 foreach($members as $member) { 503 551 if($wp_stats) { 504 echo '<p><b>#'.$no.' - <a href="'.get_settings(' home').'/wp-stats.php?author='.$member['username'].'">'.$member['username'].'</a></b> '.ip2nation_country($member['ip']).check_ip($member['ip']).' on '.gmdate('d.m.Y @ H:i', $member['timestamp']).'<br />'.$member['location'].' [<a href="'.$member['url'].'">url</a>]</p>'."\n";552 echo '<p><b>#'.$no.' - <a href="'.get_settings('siteurl').'/wp-content/plugins/stats/wp-stats.php?author='.$member['display_name'].'">'.$member['display_name'].'</a></b> '.ip2nation_country($member['ip']).check_ip($member['ip']).' on '.gmdate('d.m.Y @ H:i', $member['timestamp']).'<br />'.$member['location'].' [<a href="'.$member['url'].'">url</a>]</p>'."\n"; 505 553 } else { 506 554 echo '<p><b>#'.$no.' - '.$member['username'].'</b> '.check_ip($member['ip']).' on '.gmdate('d.m.Y @ H:i', $member['timestamp']).'<br />'.$member['location'].' [<a href="'.$member['url'].'">url</a>]</p>'."\n"; … … 509 557 } 510 558 } 559 if($total_members > 0) { 560 echo '</div>'; 561 } 562 511 563 // Print Out Guest 512 564 if($total_guests > 0) { … … 516 568 if($guests) { 517 569 foreach($guests as $guest) { 518 echo '<p><b>#'.$no.' - '.$guest['username'].'</b> '.ip2nation_country($guest['ip']).check_ip($guest['ip']).' on '.gmdate('d.m.Y @ H:i', $guest['timestamp']).'<br />'.$guest['location'].' [<a href="'.$guest['url'].'">url</a>]</p>'."\n"; 570 if($wp_stats) { 571 echo '<p><b>#'.$no.' - <a href="'.get_settings('siteurl').'/wp-content/plugins/stats/wp-stats.php?author='.$guest['display_name'].'">'.$guest['display_name'].'</a></b> '.ip2nation_country($guest['ip']).check_ip($guest['ip']).' on '.gmdate('d.m.Y @ H:i', $guest['timestamp']).'<br />'.$guest['location'].' [<a href="'.$guest['url'].'">url</a>]</p>'."\n"; 572 } else { 573 echo '<p><b>#'.$no.' - '.$guest['username'].'</b> '.check_ip($guest['ip']).' on '.gmdate('d.m.Y @ H:i', $guest['timestamp']).'<br />'.$guest['location'].' [<a href="'.$guest['url'].'">url</a>]</p>'."\n"; 574 } 519 575 $no++; 520 576 } 577 } 578 if($total_guests > 0) { 521 579 echo '</div>'; 522 580 } 581 523 582 // Print Out Bots 524 583 if($total_bots > 0) { … … 528 587 if($bots) { 529 588 foreach($bots as $bot) { 530 echo '<p><b>#'.$no.' - '.$bot[' username'].'</b> '.check_ip($bot['ip']).' on '.gmdate('d.m.Y @ H:i', $bot['timestamp']).'<br />'.$bot['location'].' [<a href="'.$bot['url'].'">url</a>]</p>'."\n";589 echo '<p><b>#'.$no.' - '.$bot['display_name'].'</b> '.check_ip($bot['ip']).' on '.gmdate('d.m.Y @ H:i', $bot['timestamp']).'<br />'.$bot['location'].' [<a href="'.$bot['url'].'">url</a>]</p>'."\n"; 531 590 $no++; 532 591 } 592 } 593 if($total_bots > 0) { 533 594 echo '</div>'; 534 595 } 596 597 // Print Out No One Is Online Now 535 598 if($total_users == 0) { 536 599 echo '<div class="wrap"><h2>'.__('No One Is Online Now').'</h2></div>'."\n"; 537 600 } 538 echo '</div>'; 601 } 602 603 604 ### Function: Place Polls Archive In Content 605 add_filter('the_content', 'place_useronlinepage', '12'); 606 function place_useronlinepage($content){ 607 $content = preg_replace( "/\<page_useronline\>/ise", "useronline_page()", $content); 608 return $content; 609 } 610 611 612 ### Function: UserOnline Page 613 function useronline_page() { 614 global $wpdb; 615 // Get The Users Online 616 $usersonline = $wpdb->get_results("SELECT * FROM $wpdb->useronline ORDER BY type"); 617 618 // Variables Variables Variables 619 $useronline_output = ''; 620 $members = array(); 621 $guests = array(); 622 $bots = array(); 623 $total_users = 0; 624 $total_members = 0; 625 $total_guests = 0; 626 $total_bots = 0; 627 $nicetext_users = ''; 628 $nicetext_members = ''; 629 $nicetext_guests = ''; 630 $nicetext_bots = ''; 631 632 // Process Those User Who Is Online 633 if($usersonline) { 634 foreach($usersonline as $useronline) { 635 switch($useronline->type) { 636 case 'member': 637 $members[] = array('timestamp' => $useronline->timestamp, 'user_id' => $useronline->userid, 'user_name' => stripslashes($useronline->username), 'display_name' => stripslashes($useronline->displayname), 'user_agent' => stripslashes($useronline->useragent), 'ip' => $useronline->ip, 'location' => stripslashes($useronline->location), 'url' => stripslashes($useronline->url)); 638 $total_members++; 639 break; 640 case 'guest': 641 $guests[] = array('timestamp' => $useronline->timestamp, 'user_id' => $useronline->userid, 'user_name' => stripslashes($useronline->username), 'display_name' => stripslashes($useronline->displayname), 'user_agent' => stripslashes($useronline->useragent), 'ip' => $useronline->ip, 'location' => stripslashes($useronline->location), 'url' => stripslashes($useronline->url)); 642 $total_guests++; 643 break; 644 case 'bot': 645 $bots[] = array('timestamp' => $useronline->timestamp, 'user_id' => $useronline->userid, 'user_name' => stripslashes($useronline->username), 'display_name' => stripslashes($useronline->displayname), 'user_agent' => stripslashes($useronline->useragent), 'ip' => $useronline->ip, 'location' => stripslashes($useronline->location), 'url' => stripslashes($useronline->url)); 646 $total_bots++; 647 break; 648 } 649 } 650 $total_users = ($total_guests+$total_bots+$total_members); 651 } 652 653 // Nice Text For Users 654 if($total_users == 1) { 655 $nicetext_users = $total_users.' '.__('User'); 656 } else { 657 $nicetext_users = number_format($total_users).' '.__('Users'); 658 } 659 660 // Nice Text For Members 661 if($total_members == 1) { 662 $nicetext_members = $total_members.' '.__('Member'); 663 } else { 664 $nicetext_members = number_format($total_members).' '.__('Members'); 665 } 666 667 668 // Nice Text For Guests 669 if($total_guests == 1) { 670 $nicetext_guests = $total_guests.' '.__('Guest'); 671 } else { 672 $nicetext_guests = number_format($total_guests).' '.__('Guests'); 673 } 674 675 // Nice Text For Bots 676 if($total_bots == 1) { 677 $nicetext_bots = $total_bots.' '.__('Bot'); 678 } else { 679 $nicetext_bots = number_format($total_bots).' '.__('Bots'); 680 } 681 682 // Check Whether WP-Stats Is Activated 683 $wp_stats = false; 684 if(function_exists('get_totalposts')) { 685 $wp_stats = true; 686 } 687 $useronline_output .= '<p>'; 688 if ($total_users == 1) { 689 $useronline_output .= __('There is '); 690 } else { 691 $useronline_output .= __('There are a total of '); 692 } 693 $useronline_output .= "<b>$nicetext_users</b> online now: <b>$nicetext_members</b>, <b>$nicetext_guests</b> and <b>$nicetext_bots</b>.</p>\n"; 694 $useronline_output .= "<p>Most users ever online were <b>".get_most_useronline(false)."</b>, on <b>".get_most_useronline_date(false)."</b></p>\n"; 695 // Print Out Members 696 if($total_members > 0) { 697 $useronline_output .= '<h2 class="pagetitle">'.$nicetext_members.' '.__('Online Now').'</h2>'."\n"; 698 } 699 $no=1; 700 if($members) { 701 foreach($members as $member) { 702 if($wp_stats) { 703 $useronline_output .= '<p><b>#'.$no.' - <a href="'.get_settings('siteurl').'/wp-content/plugins/stats/wp-stats.php?author='.$member['display_name'].'">'.$member['display_name'].'</a></b> '.ip2nation_country($member['ip']).check_ip($member['ip']).' on '.gmdate('d.m.Y @ H:i', $member['timestamp']).'<br />'.$member['location'].' [<a href="'.$member['url'].'">url</a>]</p>'."\n"; 704 } else { 705 $useronline_output .= '<p><b>#'.$no.' - '.$member['username'].'</b> '.check_ip($member['ip']).' on '.gmdate('d.m.Y @ H:i', $member['timestamp']).'<br />'.$member['location'].' [<a href="'.$member['url'].'">url</a>]</p>'."\n"; 706 } 707 $no++; 708 } 709 } 710 711 // Print Out Guest 712 if($total_guests > 0) { 713 $useronline_output .= '<h2 class="pagetitle">'.$nicetext_guests.' '.__('Online Now').'</h2>'."\n"; 714 } 715 $no=1; 716 if($guests) { 717 foreach($guests as $guest) { 718 if($wp_stats) { 719 $useronline_output .= '<p><b>#'.$no.' - <a href="'.get_settings('siteurl').'/wp-content/plugins/stats/wp-stats.php?author='.$guest['display_name'].'">'.$guest['display_name'].'</a></b> '.ip2nation_country($guest['ip']).check_ip($guest['ip']).' on '.gmdate('d.m.Y @ H:i', $guest['timestamp']).'<br />'.$guest['location'].' [<a href="'.$guest['url'].'">url</a>]</p>'."\n"; 720 } else { 721 $useronline_output .= '<p><b>#'.$no.' - '.$guest['username'].'</b> '.check_ip($guest['ip']).' on '.gmdate('d.m.Y @ H:i', $guest['timestamp']).'<br />'.$guest['location'].' [<a href="'.$guest['url'].'">url</a>]</p>'."\n"; 722 } 723 } 724 } 725 726 // Print Out Bots 727 if($total_bots > 0) { 728 $useronline_output .= '<h2 class="pagetitle">'.$nicetext_bots.' '.__('Online Now').'</h2>'."\n"; 729 } 730 $no=1; 731 if($bots) { 732 foreach($bots as $bot) { 733 $useronline_output .= '<p><b>#'.$no.' - '.$bot['username'].'</b> '.check_ip($bot['ip']).' on '.gmdate('d.m.Y @ H:i', $bot['timestamp']).'<br />'.$bot['location'].' [<a href="'.$bot['url'].'">url</a>]</p>'."\n"; 734 $no++; 735 } 736 } 737 738 // Print Out No One Is Online Now 739 if($total_users == 0) { 740 $useronline_output .= '<h2 class="pagetitle">'.__('No One Is Online Now').'</h2>'."\n"; 741 } 742 743 // Output UserOnline Page 744 return $useronline_output; 539 745 } 540 746 … … 551 757 $create_table = "CREATE TABLE $wpdb->useronline (". 552 758 " timestamp int(15) NOT NULL default '0',". 553 " username varchar(50) NOT NULL default '',". 759 " userid int(10) NOT NULL default '0',". 760 " username varchar(255) NOT NULL default '',". 761 " displayname varchar(255) NOT NULL default '',". 554 762 " useragent varchar(255) NOT NULL default '',". 555 763 " ip varchar(40) NOT NULL default '',". 556 764 " location varchar(255) NOT NULL default '',". 557 765 " url varchar(255) NOT NULL default '',". 766 " type enum('member','guest','bot') NOT NULL default 'guest',". 558 767 " UNIQUE KEY useronline_id (timestamp,username,ip,useragent))"; 559 768 maybe_create_table($wpdb->useronline, $create_table); … … 563 772 add_option('useronline_timeout', 300, 'Timeout In Seconds'); 564 773 add_option('useronline_bots', $bots, 'Bots Name/Useragent'); 774 // Database Upgrade For WP-UserOnline 2.05 775 add_option('useronline_url', get_settings('siteurl').'/useronline/', 'UserOnline Page URL'); 565 776 } 566 777 ?> wp-useronline/trunk/useronline/wp-useronline.php
r6244 r6286 27 27 } 28 28 29 ### Reassign Bots Name30 $bots = get_settings('useronline_bots');31 $bots_name = array();32 foreach($bots as $botname => $botlookfor) {33 $bots_name[] = $botname;34 }35 36 29 ### Get The Users Online 37 $usersonline = $wpdb->get_results("SELECT * FROM $wpdb->useronline ");30 $usersonline = $wpdb->get_results("SELECT * FROM $wpdb->useronline ORDER BY type"); 38 31 39 32 ### Variables Variables Variables … … 53 46 if($usersonline) { 54 47 foreach($usersonline as $useronline) { 55 if($useronline->username == 'Guest') { 56 $guests[] = array('username' => stripslashes($useronline->username), 'timestamp' => $useronline->timestamp, 'ip' => $useronline->ip, 'location' => stripslashes($useronline->location), 'url' => stripslashes(urldecode($useronline->url))); 57 $total_guests++; 58 } elseif(in_array($useronline->username, $bots_name)) { 59 $bots[] = array('username' => stripslashes($useronline->username), 'timestamp' => $useronline->timestamp, 'ip' => $useronline->ip, 'location' => stripslashes($useronline->location), 'url' => stripslashes(urldecode($useronline->url))); 60 $total_bots++; 61 } else { 62 $members[] = array('username' => stripslashes($useronline->username), 'timestamp' => $useronline->timestamp, 'ip' => $useronline->ip, 'location' => stripslashes($useronline->location), 'url' => stripslashes(urldecode($useronline->url))); 63 $total_members++; 48 switch($useronline->type) { 49 case 'member': 50 $members[] = array('timestamp' => $useronline->timestamp, 'user_id' => $useronline->userid, 'user_name' => stripslashes($useronline->username), 'display_name' => stripslashes($useronline->displayname), 'user_agent' => stripslashes($useronline->useragent), 'ip' => $useronline->ip, 'location' => stripslashes($useronline->location), 'url' => stripslashes($useronline->url)); 51 $total_members++; 52 break; 53 case 'guest': 54 $guests[] = array('timestamp' => $useronline->timestamp, 'user_id' => $useronline->userid, 'user_name' => stripslashes($useronline->username), 'display_name' => stripslashes($useronline->displayname), 'user_agent' => stripslashes($useronline->useragent), 'ip' => $useronline->ip, 'location' => stripslashes($useronline->location), 'url' => stripslashes($useronline->url)); 55 $total_guests++; 56 break; 57 case 'bot': 58 $bots[] = array('timestamp' => $useronline->timestamp, 'user_id' => $useronline->userid, 'user_name' => stripslashes($useronline->username), 'display_name' => stripslashes($useronline->displayname), 'user_agent' => stripslashes($useronline->useragent), 'ip' => $useronline->ip, 'location' => stripslashes($useronline->location), 'url' => stripslashes($useronline->url)); 59 $total_bots++; 60 break; 64 61 } 65 62 } … … 95 92 $nicetext_bots = number_format($total_bots).' '.__('Bots'); 96 93 } 94 95 ### Check Whether WP-Stats Is Activated 96 $wp_stats = false; 97 if(function_exists('get_totalposts')) { 98 $wp_stats = true; 99 } 97 100 ?> 98 101 <?php get_header(); ?> … … 107 110 $no=1; 108 111 if($members) { 109 $wp_stats = false;110 if(function_exists('get_totalposts')) {111 $wp_stats = true;112 }113 112 foreach($members as $member) { 114 113 if($wp_stats) { 115 echo '<p><b>#'.$no.' - <a href="'.get_settings('home').'/wp-stats.php?author='.$member[' username'].'">'.$member['username'].'</a></b> '.ip2nation_country($member['ip']).check_ip($member['ip']).' on '.gmdate('d.m.Y @ H:i', $member['timestamp']).'<br />'.$member['location'].' [<a href="'.$member['url'].'">url</a>]</p>'."\n";114 echo '<p><b>#'.$no.' - <a href="'.get_settings('home
