| 41 | | $mini_track_options['bots']="Googlebot|mediapartners|MSNBOT|YahooSeeker|Overture|VerticalCrawler|FastSearch|modspider|froogle|" |
|---|
| 42 | | ."Bloglines|ZyBorg|InfoSeek|looksmart|Scooter|AskJeeves|Teoma|teoma_agent|teomaagent|MARTINI|Gigabot|Netcraft|SurveyBot|ia_archiver|" |
|---|
| 43 | | ."lycos|scooter|fast\-webcrawler|inktomi|slurp\@inktomi|Slurp|turnitinbot|technorati|Findexa|NextLinks|findlinks|Gais|gaisbo|zyborg|surveybot|" |
|---|
| 44 | | ."Feedfetcher|bloglines|BlogSearch|PubSub|pubsub|Syndic8|userland|gigabot|become\.com|Yeti|naver|Sogou|worm|spider|crawler|bot"; |
|---|
| | 50 | $mini_track_options['bots']="Googlebot\-Image|Googlebot|mediapartners|MSNBOT|YahooSeeker|froogle|" |
|---|
| | 51 | ."Yahoo\! Slurp|Slurp|YahooSeeker|Yahoo Test|Yahoo (stealth)|Ask Jeeves|AskJeeves|teoma_agent|Teoma|teomaagent|slurp\@inktomi|inktomi|" |
|---|
| | 52 | ."Gigabot|Netcraft|ia_archiver|lycos|fast\-webcrawler|turnitinbot|technorati|Findexa|NextLinks|findlinks|" |
|---|
| | 53 | ."ZyBorg|InfoSeek|looksmart|Scooter|MARTINI|SurveyBot|Overture|VerticalCrawler|FastSearch|modspider|" |
|---|
| | 54 | ."Gais|gaisbo|zyborg|surveybot|Bloglines|BlogSearch|blogpulse|thumbshots|Snapbot|" |
|---|
| | 55 | ."Feedfetcher|BlogSearch|PubSub|pubsub|Syndic8|userland|become\.com|Yeti|naver|Sogou|Netcache|Netapp|BlogTick|Baiduspider|" |
|---|
| | 56 | ."Virtual Reach|Wordpress\/2\.|Yandex|linkcheck|idbot|id\-search|Nutch|larbin|heritrix|WebAlta|Indy Library|" |
|---|
| | 57 | ."Java\/|Wget\/|libcurl|libwww|lwp-trivial|urllib|GT::WWW|Snoopy|HTTP::Lite|PHPCrawl|URI::Fetch|Zend_Http_Client|http client|PECL::HTTP|" // scrapers |
|---|
| | 58 | ."crawler|indexer|archiver|worm|spider|bot"; // generic |
|---|
| 73 | | // store first seen date when they arrive |
|---|
| 74 | | if (!is_array($mini_track) || !array_key_exists($index,$mini_track)) {$mini_track[$index]->seen=time(); if ($bb_current_user->ID) {@bb_update_usermeta($bb_current_user->ID,'mini_track',date('r'));}} |
|---|
| 75 | | |
|---|
| 76 | | $mini_track[$index]->time=time(); |
|---|
| 77 | | $mini_track[$index]->ip=$_SERVER['REMOTE_ADDR']; |
|---|
| 78 | | $mini_track[$index]->url=$_SERVER['REQUEST_URI']; // this also has some issues with dynamic url cruft but is acceptable |
|---|
| 79 | | $mini_track[$index]->id=$bb_current_user->ID; |
|---|
| | 93 | // store first seen date (and referer when they arrive) |
|---|
| | 94 | if (!is_array($mini_track) || !array_key_exists($index,$mini_track)) { |
|---|
| | 95 | $mini_track[$index]->seen=time(); if ($bb_current_user->ID) {@bb_update_usermeta($bb_current_user->ID,'mini_track',date('r'));} |
|---|
| | 96 | $referer=mini_track_safe_url($_SERVER['HTTP_REFERER']); $uri=bb_get_option('uri'); $found=strpos($referer,str_replace(array("https://","http://","www."),"",trim($uri,"/ "))); |
|---|
| | 97 | if (!empty($referer) && (strpos($referer,"http://")===0 || strpos($referer,"https://")===0) && strpos($uri,$referer)===false && ($found===false || $found>20)) {$mini_track[$index]->referer=$referer;} |
|---|
| | 98 | |
|---|
| | 99 | $mini_track[$index]->id=intval($bb_current_user->ID); // save current user id |
|---|
| | 100 | |
|---|
| | 101 | // determine bots from agent - moved to first time seen to save cpu cycles and re-check unnecessary |
|---|
| 81 | | else { |
|---|
| 82 | | // if (eregi($mini_track_options['bots'],$_SERVER['HTTP_USER_AGENT'])) {$mini_track[$index]->bot=1;} |
|---|
| 83 | | $agent=strtolower($_SERVER['HTTP_USER_AGENT']); |
|---|
| 84 | | foreach ($mini_track_options['bots'] as $key=>$name) {if (!(strpos($agent,$name)===false)) {$mini_track[$index]->bot=$key+1; break;}} |
|---|
| 85 | | } // detect/save bots |
|---|
| | 103 | else {if ($bot=mini_track_bot_lookup()) {$mini_track[$index]->bot=$bot;}} // detect/save bots |
|---|
| | 104 | |
|---|
| | 105 | } // end of first seen checks |
|---|
| | 106 | |
|---|
| | 107 | if ($mini_track_options['debug']) {$mini_track[$index]->debug=$debug;} // save debug info if in debug mode |
|---|
| | 108 | |
|---|
| | 109 | $mini_track[$index]->time=time(); |
|---|
| | 110 | $mini_track[$index]->ip=mini_track_remote_addr(); |
|---|
| 106 | | $bbdb->update( $bbdb->topicmeta, array( 'meta_value' => bb_maybe_serialize( $mini_track )), array( 'topic_id' => 0, 'meta_key' => 'mini_track' ) ); |
|---|
| | 135 | // $bbdb->update( $bbdb->topicmeta, array( 'meta_value' => bb_maybe_serialize( $mini_track )), array( 'topic_id' => 0, 'meta_key' => 'mini_track' ) ); |
|---|
| | 136 | |
|---|
| | 137 | if (bb_get_option('bb_db_version')>1600) {$table="$bbdb->meta"; $where="WHERE object_type='bb_option'";} // 1.0 compatibility |
|---|
| | 138 | else {$table="$bbdb->topicmeta"; $where="WHERE topic_id = 0";} // 0.9 compatibility |
|---|
| | 139 | $value=addslashes(bb_maybe_serialize( $mini_track)); |
|---|
| | 140 | @$bbdb->query("UPDATE $table SET meta_value='$value' $where AND meta_key='mini_track' LIMIT 1"); |
|---|
| 127 | | echo "<div class='mini_track'>There are <strong>".$mini_track_current['users']."</strong> total $start"."users online".$end."."; |
|---|
| 128 | | if ($mini_track_current['onpage']>1 && !$mini_track_options['show_only_on_front_page']) {echo " <strong>".$mini_track_current['onpage']."</strong> of them are on this page.";} |
|---|
| 129 | | if ($mini_track_current['members']>0) {echo " <strong>".$mini_track_current['members']."</strong> of them are members";} |
|---|
| | 161 | echo "<div class='mini_track'>There are <span class='mini_track_num'>".$mini_track_current['users']."</span> total $start"."users online".$end."."; |
|---|
| | 162 | if ($mini_track_current['onpage']>1 && !$mini_track_options['show_only_on_front_page']) {echo " <span class='mini_track_num'>".$mini_track_current['onpage']."</span> of them are on this page.";} |
|---|
| | 163 | if ($mini_track_current['members']>0) {echo " <span class='mini_track_num'>".$mini_track_current['members']."</span> of them are members";} |
|---|
| 143 | | <style>table {border:1px solid #111;} table td {text-align:center;} table .link {text-align:left;} table th.link {padding-left:5em;} |
|---|
| 144 | | table th {background: #aaa;} .alt {background: #eee;} .tiny {font-size:85%;} .bot {color:red; font-size:90%;} .guest {color:green;} |
|---|
| 145 | | .link div {padding-left: 5px; width:500px; white-space:nowrap; overflow; hidden;} </style></head><body>'; |
|---|
| | 177 | <style>table {border:1px solid #111; font-size:14px; font-family: arial, san-serif; line-height:150%;} table td {text-align:center; white-space:nowrap;} table .link {text-align:left;} table th.link {padding-left:5em;} |
|---|
| | 178 | table th {background: #aaa;} .alt {background: #eee;} .tiny {font-size:12px;} .bot {color:red; font-size:90%;} .guest {color:green;} |
|---|
| | 179 | .link div {padding-left: 5px; width:500px; white-space:nowrap; overflow; hidden;} </style> |
|---|
| | 180 | <script>window.onload=titlelink; function titlelink() {blank="_blank"; for (i=0;x=document.links[i];++i){x.target=blank; x.title=x.href;}};</script> |
|---|
| | 181 | </head><body>'; |
|---|
| 154 | | echo "<tr".(($counter % 2) ? " class=alt" : "")."><td align=right>".(++$counter)."</td><td>"; |
|---|
| 155 | | if ($value->id) echo "<a target='_blank' href='$profile$value->id'>$value->name</a>"; |
|---|
| 156 | | elseif (isset($value->bot)) {echo "<span class=bot>".$mini_track_options['bots'][$value->bot-1]."</span>";} else {echo "<span class=guest>guest</span>";} |
|---|
| 157 | | echo "</td><td class=tiny><a target='_blank' ".(($mini_track_options['debug']) ?" title='$value->debug' " : "")."href='?mini_track_ip=$value->ip'>$value->ip</a></td><td>".intval($value->pages)."</td><td class=tiny>".ceil((($value->time)-$value->seen+1)/60)." minutes</td><td class=tiny>".ceil(((time())-$value->time+1)/60)." minutes ago</td><td class=link><div style='overflow:hidden;'><a href='$url'>$url</a></div></td></tr>"; |
|---|
| | 190 | echo "<tr".(($counter % 2) ? " class=alt" : "")."><td align=right class=tiny ".(($mini_track_options['debug']) ?" title='$value->debug' " : "")."> ".(++$counter)." </td><td>"; // line number |
|---|
| | 191 | if ($value->id) echo "<a href='$profile$value->id'>$value->name</a>"; // member profile link |
|---|
| | 192 | elseif (isset($value->bot)) {echo "<span class=bot>".preg_replace("/[^A-Za-z_ ]+?/is","",$mini_track_options['bots'][$value->bot-1])."</span>";} else {echo "<span class=guest>guest</span>";} |
|---|
| | 193 | echo "</td><td class=tiny><a href='?mini_track_ip=$value->ip'>$value->ip</a></td>"; |
|---|
| | 194 | if (isset($value->referer)) {$parse_url=parse_url($value->referer); // referer |
|---|
| | 195 | $host=substr(ereg_replace("^(www[0-9]?|search|talk|community|support|foro|mitmachen|board[s]?|forum[s]?)(\.?)","",$parse_url['host']),0,30); |
|---|
| | 196 | echo "<td><a href='$value->referer'>".$host."</a></td>";} else {echo "<td> </td>"; |
|---|
| | 197 | } |
|---|
| | 198 | echo "<td>".intval($value->pages)."</td>"; // page count |
|---|
| | 199 | echo "<td class=tiny>".ceil((($value->time)-$value->seen+1)/60)." minutes</td>"; // total activity time |
|---|
| | 200 | echo "<td class=tiny>".ceil(((time())-$value->time+1)/60)." minutes ago</td>"; // last activity time |
|---|
| | 201 | echo "<td class=link><div style='overflow:hidden;'><a href='$url'>$url</a></div></td></tr>"; // last url |
|---|
| 170 | | $indexlist=array('REMOTE_ADDR','HTTP_USER_AGENT','HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR','HTTP_FORWARDED','HTTP_VIA', 'HTTP_X_COMING_FROM', 'HTTP_COMING_FROM'); |
|---|
| | 215 | $indexlist=array('REMOTE_ADDR','HTTP_USER_AGENT','HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR','HTTP_FORWARDED','HTTP_VIA', 'HTTP_X_COMING_FROM', 'HTTP_COMING_FROM','HTTP_CLIENT_IP'); |
|---|
| | 220 | } |
|---|
| | 221 | |
|---|
| | 222 | function mini_track_remote_addr() { // detects true IP of known proxies and NATs |
|---|
| | 223 | // 67\.195\.|74\.6\. == inktomi/yahoo slurp, sometimes masqurades as regular browser too! |
|---|
| | 224 | if (ereg("^(67\.195\.|74\.6\.)",$_SERVER['REMOTE_ADDR']) && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|---|
| | 225 | return $_SERVER['HTTP_X_FORWARDED_FOR']; |
|---|
| | 226 | } else {return $_SERVER['REMOTE_ADDR'];} |
|---|
| | 227 | } |
|---|
| | 228 | |
|---|
| | 229 | function mini_track_bot_lookup() { |
|---|
| | 230 | global $mini_track_options; $bot=0; |
|---|
| | 231 | $agent=strtolower($_SERVER['HTTP_USER_AGENT']); |
|---|
| | 232 | foreach ($mini_track_options['bots'] as $key=>$name) {if (!(strpos($agent,$name)===false)) {$bot=$key+1; break;}} |
|---|
| | 233 | if ($bot==0) {if (ereg("^(67\.195\.|74\.6\.)",$_SERVER['REMOTE_ADDR'])) {$bot=1+array_search("yahoo stealth",$mini_track_options['bots']);}} // yahoo fakes it |
|---|
| | 234 | return $bot; |
|---|
| 208 | | function mini_track_activation() {global $mini_track,$mini_track_done; unset($mini_track_done); $mini_track=array(); @bb_update_option('mini_track',$mini_track);} |
|---|
| | 268 | function mini_track_safe_url($url) {return substr(strip_tags(stripslashes(trim(urldecode($url),"?& "))),0,128);} |
|---|
| | 269 | |
|---|
| | 270 | function mini_track_activation() { |
|---|
| | 271 | global $mini_track, $mini_track_statistics, $mini_track_done; unset($mini_track_done); |
|---|
| | 272 | $mini_track=array(); @bb_update_option('mini_track',$mini_track); |
|---|
| | 273 | $mini_track_statistics=bb_get_option('mini_track_statistics'); |
|---|
| | 274 | if (empty($mini_track_statistics)) {$mini_track_statistics=array(); @bb_update_option('mini_track_statistics',$mini_track_statistics);} |
|---|
| | 275 | } |
|---|
| | 320 | |
|---|
| | 321 | function mini_track_statistics() { |
|---|
| | 322 | global $mini_track, $mini_track_options, $mini_track_statistics_done; |
|---|
| | 323 | if (isset($mini_track_statistics_done)) {return;} $mini_track_statistics_done=true; // only run once if manually called |
|---|
| | 324 | if ($mini_track_options['statistics_only_on_front_page'] && !is_front()) {return;} |
|---|
| | 325 | $results=bb_get_option('mini_track_statistics'); if (!$results) {$results=mini_track_statistics_update();} |
|---|
| | 326 | $months=ceil((time()-strtotime($results->days)) / (3600 * 24 * 30)); |
|---|
| | 327 | $output="<div class='mini_track_statistics'>"; |
|---|
| | 328 | $output.="<span class='mini_track_wrap'>"; |
|---|
| | 329 | $output.=" <span class='mini_track_num'>".$results->posts."</span> ".__('posts in'); |
|---|
| | 330 | $output.=" <span class='mini_track_num'>".$results->topics."</span> ".__('topics over'); |
|---|
| | 331 | $output.=" <span class='mini_track_num'>$months</span> ".__('months by'); |
|---|
| | 332 | $output.=" <span class='mini_track_num'>".$results->active."</span> ".__('of')." <span class='mini_track_num'>".$results->members."</span> ".__('members.'); |
|---|
| | 333 | $output.=" </span> <span class='mini_track_wrap'> "; |
|---|
| | 334 | if (!empty($results->latest)) {$output.=__('Latest:'); $uri=bb_get_option('uri')."profile.php?id="; foreach ($results->latest as $key=>$value) {$output.=" <a href='$uri$key'>$value</a>, ";}} |
|---|
| | 335 | $output=trim($output,", ")."</span></div> "; |
|---|
| | 336 | echo $output; |
|---|
| | 337 | } |
|---|
| | 338 | |
|---|
| | 339 | function mini_track_statistics_update($x="") { |
|---|
| | 340 | global $bbdb, $mini_track; // this is kind of insane overkill to do each new post / new user - might want to calculate incrementally somehow |
|---|
| | 341 | $query="SELECT count(*) as posts, count(distinct topic_id) as topics, count(distinct poster_id) as active, min(post_time) as days FROM bb_posts WHERE post_status=0"; |
|---|
| | 342 | $results=$bbdb->get_results($query); |
|---|
| | 343 | $usertable=$bbdb->users; $usermeta=$bbdb->usermeta; |
|---|
| | 344 | $base="FROM $usertable as t1 LEFT JOIN $usermeta as t2 on t1.ID=t2.user_id WHERE user_status=0 AND (meta_key='bb_capabilities' AND NOT (meta_value LIKE '%inactive%' OR meta_value LIKE '%blocked%'))"; |
|---|
| | 345 | $query="SELECT user_login,ID $base ORDER BY user_registered DESC LIMIT 3"; |
|---|
| | 346 | $results2=$bbdb->get_results($query); |
|---|
| | 347 | $results2=array_reverse($results2); |
|---|
| | 348 | foreach ($results2 as $key=>$value) {$results[0]->latest[$value->ID]=$value->user_login;} |
|---|
| | 349 | $query="SELECT count(*) as members $base"; |
|---|
| | 350 | $results2=$bbdb->get_results($query); |
|---|
| | 351 | $results[0]->members=$results2[0]->members; |
|---|
| | 352 | bb_update_option('mini_track_statistics',$results[0]); |
|---|
| | 353 | return $results[0]; |
|---|
| | 354 | } |
|---|