Changeset 141 for trunk/wassup.php

Show
Ignore:
Timestamp:
06/12/08 09:04:03 (7 months ago)
Author:
root
Message:

testing major release 1.6

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/wassup.php

    r140 r141  
    44Plugin URI: http://www.wpwp.org 
    55Description: Wordpress plugin to analyze your visitors traffic with real time stats, chart and a lot of chronological informations. It has sidebar Widget support to show current online visitors and other statistics. 
    6 Version: 1.5.2 
     6Version: 1.6 
    77Author: Michele Marcucci 
    88Author URI: http://www.michelem.org/ 
     
    1717        die('Permission Denied! You are not allowed to call this page directly.'); 
    1818} 
    19 $version = "1.5.2"; 
     19$version = "1.6"; 
    2020define('WASSUPFOLDER', dirname(plugin_basename(__FILE__)), TRUE); 
    2121require_once(dirname(__FILE__).'/lib/wassup.class.php'); 
     
    165165//#   -Load jquery AJAX library and dependent javascripts for admin menus 
    166166//#   -Load language/localization files for admin menus and widget 
    167 //#   -Set 'wassup' ## General hooks 
     167//#   -Set 'wassup' cookie for new visitor hits 
    168168function wassup_init() { 
    169169        global $wpurl; 
     
    550550                $to_date = wassup_get_time(); 
    551551                $from_date = strtotime('-3 minutes', $to_date); 
    552                 $currenttot = $wpdb->get_var("SELECT COUNT(DISTINCT wassup_id) as currenttot FROM $table_tmp_name WHERE timestamp BETWEEN $from_date AND $to_date"); 
     552                $currenttot = $wpdb->get_var("SELECT COUNT(DISTINCT wassup_id) as currenttot FROM $table_tmp_name WHERE `timestamp` BETWEEN $from_date AND $to_date"); 
    553553                $currenttot = $currenttot+0;    //set to integer 
    554554                print "<p class='legend'>".__("Visitors online", "wassup").": <strong>".$currenttot."</strong></p><br />"; 
    555555                if ($currenttot > 0) { 
    556                         $qryC = $wpdb->get_results("SELECT id, wassup_id, max(timestamp) as max_timestamp, ip, hostname, searchengine, urlrequested, agent, referrer, spider, username, comment_author FROM $table_tmp_name WHERE timestamp BETWEEN $from_date AND $to_date GROUP BY ip ORDER BY max_timestamp DESC"); 
     556                        $qryC = $wpdb->get_results("SELECT id, wassup_id, max(timestamp) as max_timestamp, ip, hostname, searchengine, urlrequested, agent, referrer, spider, username, comment_author FROM $table_tmp_name WHERE `timestamp` BETWEEN $from_date AND $to_date GROUP BY ip ORDER BY max_timestamp DESC"); 
    557557                foreach ($qryC as $cv) { 
    558558                //$timestamp = $cv->max_timestamp;      //redundant 
    559559                $timed = gmdate("H:i:s", $cv->max_timestamp); 
    560                 $ip = @explode(",", $cv->ip); 
     560                $ip_proxy = strpos($cv->ip,","); 
     561                //if proxy, get 2nd ip... 
     562                if ($ip_proxy !== false) { 
     563                        $ip = substr($cv->ip,(int)$ip_proxy+1); 
     564                } else {  
     565                        $ip = $cv->ip; 
     566                } 
    561567                if ($cv->referrer != '') { 
    562568                        if (!eregi($wpurl, $cv->referrer) OR $cv->searchengine != "") {  
     
    575581        ?> 
    576582                        <div class="sum"> 
    577                         <span class="sum-box"><?php if ($numurl >= 2) { ?><a  href="#" class="showhide" id="<?php echo $cv->id ?>"><?php print $ip[0]; ?></a><?php } else { ?><?php print $ip[0]; ?><?php } ?></span> 
     583                        <span class="sum-box"><?php if ($numurl >= 2) { ?><a  href="#" class="showhide" id="<?php echo $cv->id ?>"><?php print $ip; ?></a><?php } else { ?><?php print $ip; ?><?php } ?></span> 
    578584                        <div class="sum-det"><span class="det1"> 
    579585                        <?php 
     
    604610                        <ul class="url"> 
    605611        <?php  
    606                         $qryCD = $wpdb->get_results("SELECT timestamp, urlrequested FROM $table_tmp_name WHERE wassup_id='".$cv->wassup_id."' ORDER BY timestamp ASC"); 
     612                        $qryCD = $wpdb->get_results("SELECT `timestamp`, urlrequested FROM $table_tmp_name WHERE wassup_id='".$cv->wassup_id."' ORDER BY `timestamp` ASC"); 
    607613                        $i=0; 
    608614                        foreach ($qryCD as $cd) {        
     
    758764                //#   -Helene D. 3/4/08. 
    759765                if (!empty($_GET['deleteMARKED']) && $wassup_options->wmark == "1" ) { 
    760                         $rec_deleted = $wpdb->get_var("SELECT COUNT(ip) as deleted FROM $table_name WHERE ip='".urlencode(attribute_escape($_GET['dip']))."' AND timestamp BETWEEN $from_date AND $to_date"); 
     766                        $rec_deleted = $wpdb->get_var("SELECT COUNT(ip) as deleted FROM $table_name WHERE ip='".urlencode(attribute_escape($_GET['dip']))."' AND `timestamp` BETWEEN $from_date AND $to_date"); 
    761767                        if (method_exists($wpdb,'prepare')) { 
    762                                 $wpdb->query($wpdb->prepare("DELETE FROM $table_name WHERE ip='%s' AND timestamp BETWEEN %s AND %s", urlencode(attribute_escape($_GET['dip'])), $from_date, $to_date)); 
     768                                $wpdb->query($wpdb->prepare("DELETE FROM $table_name WHERE ip='%s' AND `timestamp` BETWEEN %s AND %s", urlencode(attribute_escape($_GET['dip'])), $from_date, $to_date)); 
    763769                        } else { 
    764                                 $wpdb->query("DELETE FROM $table_name WHERE ip='".urlencode(attribute_escape($_GET['dip']))."' AND timestamp BETWEEN $from_date AND $to_date"); 
     770                                $wpdb->query("DELETE FROM $table_name WHERE ip='".urlencode(attribute_escape($_GET['dip']))."' AND `timestamp` BETWEEN $from_date AND $to_date"); 
    765771                        } 
    766772                        echo '<p><strong>'.$rec_deleted.' '.__('records deleted','wassup').'</strong></p>'; 
     
    936942                $timeF = gmdate("H:i:s", $timestampF); 
    937943                $datetimeF = gmdate('Y-m-d H:i:s', $timestampF); 
    938                 $ip = @explode(",", $rk->ip); 
    939  
    940                 // Visitor Record - raw data (hidden) ?> 
    941                 <div id="raw-<?php echo $rk->wassup_id; ?>" style="display:none; padding-top:7px;" > 
     944                //$ip = @explode(",", $rk->ip); 
     945                $ip_proxy = strpos($rk->ip,","); 
     946                //if proxy, get 2nd ip... 
     947                if ($ip_proxy !== false) { 
     948                        $ip = substr($rk->ip,(int)$ip_proxy+1); 
     949                } else {  
     950                        $ip = $rk->ip; 
     951                } 
     952 
     953                // Visitor Record - raw data (hidden) 
     954                $raw_div="raw-".substr($rk->wassup_id,0,25).rand(0,99); 
     955                echo "\n"; ?> 
     956                <div id="<?php echo $raw_div; ?>" style="display:none; padding-top:7px;" > 
    942957                <h2><?php _e("Raw data","wassup"); ?>:</h2> 
    943958                <style type="text/css">.raw { color: #542; padding-left:5px; }</style> 
    944959                <ul style="list-style-type:none;padding:20px 0 0 30px;"> 
     960                <li><?php echo __("Visit type","wassup").': <span class="raw">'; 
     961                if ($rk->username != "") {  
     962                        echo __("Logged-in user","wassup").' - '.$rk->username; 
     963                } elseif ($rk->spam == "1" || $rk->spam == "2" ) {  
     964                        _e("Spammer","wassup"); 
     965                } elseif ($rk->comment_author != "") {  
     966                        echo __("Comment author","wassup").' - '.$rk->comment_author; 
     967                } elseif ($rk->feed != "") {  
     968                        echo __("Feed","wassup").' - '.$rk->feed; 
     969                } elseif ($rk->spider != "") {  
     970                        echo __("Spider","wassup").' - '.$rk->spider; 
     971                } else { 
     972                         _e("Regular visitor","wassup"); 
     973                } 
     974                echo '</span>'; ?></li> 
    945975                <li><?php echo __("IP","wassup").': <span class="raw">'.$rk->ip.'</span>'; ?></li> 
    946976                <li><?php echo __("Hostname","wassup").': <span class="raw">'.$rk->hostname.'</span>'; ?></li> 
     977                <li><?php echo __("Url Requested","wassup").': <span class="raw">'.htmlspecialchars(html_entity_decode(clean_url($rk->urlrequested))).'</span>'; ?></li> 
    947978                <li><?php echo __("User Agent","wassup").': <span class="raw">'.$rk->agent.'</span>'; ?></li> 
    948979                <li><?php echo __("Referrer","wassup").': <span class="raw">'.urldecode($rk->referrer).'</span>'; ?></li> 
    949980                <?php if ($rk->search != "") { ?> 
    950                 <li><?php echo __("Search","wassup").': <span class="raw">'.$rk->search.'</span>'; ?></li> 
     981                <li><?php echo __("Search Engine","wassup").': <span class="raw">'.$rk->searchengine.'</span> &nbsp; &nbsp; '; 
     982                echo __("Search","wassup").': <span class="raw">'.$rk->search.'</span>'; ?></li> 
    951983                <?php } 
    952984                if ($rk->os != "") { ?> 
     
    957989                <?php } 
    958990                if ($rk->language != "") { ?> 
    959                 <li><?php echo __("Language","wassup").': <span class="raw">'.$rk->language.'</span>'; ?></li> 
     991                <li><?php echo __("Locale/Language","wassup").': <span class="raw">'.$rk->language.'</span>'; ?></li> 
    960992                <?php } ?> 
    961                 <li><?php echo __("Url Requested","wassup").': <span class="raw">'.htmlspecialchars(html_entity_decode(clean_url($rk->urlrequested))).'</span>'; ?></li> 
    962                 <li><?php echo __("End Timestamp","wassup").': <span class="raw">'.$datetimeF.' ( '.$rk->max_timestamp.' )</span>'; ?></li> 
     993                <li><?php echo 'Wassup ID'.': <span class="raw">'.$rk->wassup_id.'</span>'; ?></li> 
     994                <li><?php echo __("End timestamp","wassup").': <span class="raw">'.$datetimeF.' ( '.$rk->max_timestamp.' )</span>'; ?></li> 
    963995                </ul> 
    964996                </div> <!-- raw-wassup_id --> 
     
    9831015 
    9841016                <div class="delID<?php echo $rk->wassup_id ?>"> 
    985                 <div class="<?php if ($wassup_options->wmark == 1 AND $wassup_options->wip == $ip[0]) echo "sum-nav-mark"; else echo "sum-nav"; ?>"> 
     1017                <div class="<?php if ($wassup_options->wmark == 1 AND $wassup_options->wip == $ip) echo "sum-nav-mark"; else echo "sum-nav"; ?>"> 
    9861018 
    9871019                <p class="delbut"> 
    9881020                <?php // Mark/Unmark IP 
    989                 if ($wassup_options->wmark == 1 AND $wassup_options->wip ==  $ip[0]) { ?> 
    990                         <a  href="?<?php echo $_SERVER['QUERY_STRING']; ?>&deleteMARKED=1&dip=<?php print $ip[0]; ?>" style="text-decoration:none;"> 
     1021                if ($wassup_options->wmark == 1 AND $wassup_options->wip ==  $ip) { ?> 
     1022                        <a  href="?<?php echo $_SERVER['QUERY_STRING']; ?>&deleteMARKED=1&dip=<?php print $ip; ?>" style="text-decoration:none;"> 
    9911023                        <img src="<?php echo $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/img/cross.png" alt="'.__('delete','wassup').'" title="'.__('Delete ALL marked records with this IP','wassup'); ?>" /></a> 
    9921024                        <a href="?page=<?php echo WASSUPFOLDER; ?>&wmark=0" style="text-decoration:none;"> 
     
    9951027                        <a  href="#" class="deleteID" id="<?php echo $rk->wassup_id ?>" style="text-decoration:none;"> 
    9961028                        <img src="<?php echo $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/img/cross.png" alt="'.__('delete','wassup').'" title="'.__('Delete this record','wassup'); ?>" /></a> 
    997                         <a href="?<?php echo $_SERVER['QUERY_STRING']; ?>&wmark=1&wip=<?php print $ip[0]; ?>" style="text-decoration:none;"> 
     1029                        <a href="?<?php echo $_SERVER['QUERY_STRING']; ?>&wmark=1&wip=<?php print $ip; ?>" style="text-decoration:none;"> 
    9981030                        <img src="<?php echo $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/img/error_add.png" alt="'.__('mark','wassup').'" title="'.__('Mark IP','wassup'); ?>" /></a> 
    9991031                <?php } ?> 
    1000                 <a href="#TB_inline?height=400&width=<?php echo $res.'&inlineId=raw-'.$rk->wassup_id; ?>" class="thickbox"> 
     1032                <a href="#TB_inline?height=400&width=<?php echo $res.'&inlineId='.$raw_div; ?>" class="thickbox"> 
    10011033                <img src="<?php echo $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/img/database_table.png" alt="'.__('show raw table','wassup').'" title="'.__('Show the items as raw table','wassup'); ?>" /></a> 
    10021034                </p> 
    10031035 
    1004                         <span class="sum-box"><?php if ($numurl >= 2) { ?><a  href="#" class="showhide" id="<?php echo $rk->id ?>"><?php print $ip[0]; ?></a><?php } else { ?><?php print $ip[0]; ?><?php } ?></span> 
     1036                        <span class="sum-box"><?php if ($numurl >= 2) { ?><a  href="#" class="showhide" id="<?php echo $rk->id ?>"><?php print $ip; ?></a><?php } else { ?><?php print $ip; ?><?php } ?></span> 
    10051037                        <span class="sum-date"><?php print $datetimeF; ?></span> 
    10061038                        <div class="sum-det"><span class="det1"> 
     
    10591091                        <ul style="background:#fdeec8;" class="spider"> 
    10601092                                <li class="feed"><span class="indent-li-agent"><?php _e('FEEDREADER','wassup'); ?>: <strong><?php print $rk->spider; ?></strong></span></li> 
    1061                                 <li class="feed"><span class="indent-li-agent"><?php _e('SUBSCRIBER(S)','wassup'); ?>: <strong><?php print $rk->feed; ?></strong></span></li> 
     1093                                <?php if (is_numeric($rk->feed)) { ?> 
     1094                                <li class="feed"><span class="indent-li-agent"><?php _e('SUBSCRIBER(S)','wassup'); ?>: <strong><?php print (int)$rk->feed; ?></strong></span></li> 
     1095                                <?php  } ?> 
    10621096                        </ul> 
    10631097                        <?php  } else { ?> 
     
    10961130                        <ul class="url"> 
    10971131        <?php  
    1098                         $qryCD = $wpdb->get_results("SELECT timestamp, urlrequested FROM $table_name WHERE wassup_id='".$rk->wassup_id."' ORDER BY timestamp ASC"); 
     1132                        $qryCD = $wpdb->get_results("SELECT `timestamp`, urlrequested FROM $table_name WHERE wassup_id='".$rk->wassup_id."' ORDER BY `timestamp` ASC"); 
    10991133                        $i=0; 
    11001134                        foreach ($qryCD as $cd) {        
     
    12421276                $ipAddress = ""; 
    12431277                $hostname = ""; 
    1244                 //#### Get the host/IP details from http header... 
     1278                //#### Get the visitor's details from http header... 
    12451279                if (isset($_SERVER["REMOTE_ADDR"])) { 
    12461280                if ($_SERVER["HTTP_X_FORWARDED_FOR"] != ""){ 
    1247                         $IP = $_SERVER["HTTP_X_FORWARDED_FOR"]; 
     1281                        //in case of multiple forwarding 
     1282                        list($IP) = explode(",",$_SERVER["HTTP_X_FORWARDED_FOR"]); 
    12481283                        $proxy = $_SERVER["REMOTE_ADDR"]; 
    1249                         $hostname = @gethostbyaddr($_SERVER["HTTP_X_FORWARDED_FOR"]); 
     1284                        $hostname = @gethostbyaddr($IP); 
     1285                        if (empty($hostname) || $hostname == "unknown") { 
     1286                                $hostname = @gethostbyaddr($proxy); 
     1287                        } 
    12501288                        $ipAddress = $proxy.",".$IP; 
    12511289                }else{ 
    1252                         $IP = $_SERVER["REMOTE_ADDR"]; 
    1253                         $hostname = @gethostbyaddr($_SERVER["REMOTE_ADDR"]); 
    1254                         $ipAddress = $IP; 
     1290                        list($IP) = explode(",",$_SERVER["REMOTE_ADDR"]); 
     1291                        $hostname = @gethostbyaddr($IP); 
     1292                        $ipAddress = $_SERVER["REMOTE_ADDR"]; 
    12551293                }  
    12561294                } 
     1295                if (empty($IP)) { $IP = $ipAddress; } 
     1296                if (empty($hostname)) { $hostname = "unknown"; } 
    12571297                $userAgent = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''); 
    12581298                //# Create a new wassup id for this visit from a  
     
    12611301                //#  same ip/userAgent within a 30 minute-period, can be  
    12621302                //#  tracked, even when session/cookies is disabled.  
    1263                 $temp_id = sprintf("%-064.64s", date('YmdH').str_replace(array('','/','.','\'','"',"\\",'$','-','&','+','_',';',',','>','<',':','#','*','%','http',')','(',), '', intval(date('i')/30).$ipAddress.strrev($userAgent).strrev($hostname).intval(date('i')/30)).date('HdmY').rand()); 
     1303                $temp_id = sprintf("%-060.60s", date('YmdH').str_replace(array(' ','http://','www.','/','.','\'','"',"\\",'$','-','&','+','_',';',',','>','<',':','#','*','%','!','@',')','(',), '', intval(date('i')/30).$IP.strrev($userAgent).strrev($hostname).intval(date('i')/30)).date('HdmY').$hostname.rand()); 
    12641304 
    12651305                //Work-around for cookie rejection: 
     
    12931333        if (isset($_SERVER["REMOTE_ADDR"])) { 
    12941334                if ($_SERVER["HTTP_X_FORWARDED_FOR"] != ""){ 
    1295                         $IP = $_SERVER["HTTP_X_FORWARDED_FOR"]; 
     1335                        //in case of multiple forwarding 
     1336                        list($IP) = explode(",",$_SERVER["HTTP_X_FORWARDED_FOR"]); 
    12961337                        $proxy = $_SERVER["REMOTE_ADDR"]; 
    1297                         $hostname = @gethostbyaddr($_SERVER["HTTP_X_FORWARDED_FOR"]); 
     1338                        $hostname = @gethostbyaddr($IP); 
     1339                        if (empty($hostname) || $hostname == "unknown") { 
     1340                                $hostname = @gethostbyaddr($proxy); 
     1341                        } 
    12981342                        $ipAddress = $proxy.",".$IP; 
    12991343                }else{ 
    1300                         $IP = $_SERVER["REMOTE_ADDR"]; 
    1301                         $hostname = @gethostbyaddr($_SERVER["REMOTE_ADDR"]); 
    1302                         $ipAddress = $IP; 
     1344                        list($IP) = explode(",",$_SERVER["REMOTE_ADDR"]); 
     1345                        $hostname = @gethostbyaddr($IP); 
     1346                        $ipAddress = $_SERVER["REMOTE_ADDR"]; 
    13031347                }  
    13041348        } 
     1349        if (empty($IP)) { $IP = $ipAddress; } 
     1350        if (empty($hostname)) { $hostname = "unknown"; } 
     1351 
    13051352        // Get the visitor's resolution, TODO 
    13061353        /* 
     
    13681415        if ($wassup_options->wassup_loggedin == 1 || !is_user_logged_in() ) { 
    13691416        if ($wassup_options->wassup_attack == 1 || stristr($userAgent,"libwww-perl") === FALSE ) { 
     1417        if (!is_404()) {        //don't record 404 pages... 
    13701418 
    13711419                //##### Extract useful visit information from http header.. 
    1372                 $dip = &new Detector("", $userAgent); 
    1373                 $browser =  $dip->browser." ".$dip->browser_version; 
    1374                 $os = $dip->os." ".$dip->os_version; 
     1420                $browser = ""; 
     1421                $os = ""; 
     1422                list($browser,$os) = wGetBrowser($userAgent); 
    13751423 
    13761424        //#=================================================== 
     
    13831431        //#  such, even when session/cookies is disabled.  
    13841432        //# An md5 encoded version of temp_id is saved as "wassup_id". 
    1385         $temp_id = sprintf("%-064.64s", date('YmdH').str_replace(array('','/','.','\'','"',"\\",'$','-','&','+','_',';',',','>','<',':','#','*','%','http',')','(',), '', intval(date('i')/30).$ipAddress.strrev($userAgent).strrev($hostname).intval(date('i')/30)).date('HdmY').rand()); 
     1433        $temp_id = sprintf("%-060.60s", date('YmdH').str_replace(array(' ','http://','www.','/','.','\'','"',"\\",'$','-','&','+','_',';',',','>','<',':','#','*','%','!','@',')','(',), '', intval(date('i')/30).$IP.strrev($userAgent).strrev($hostname).intval(date('i')/30)).date('HdmY').$hostname.rand()); 
    13861434        $wassup_id = ""; 
    13871435        //Read the cookie for wassup_id 
     
    14941542        if ($dup_urlrequest == 0) { 
    14951543                //##### Extract useful visit information from http header.. 
    1496                 if ($os != "" OR $browser != "") {  
    1497                         $bot=wGetSpider($userAgent); 
    1498                         if (is_array($bot)) { 
    1499                                 $spider = $bot[0]; 
    1500                                 $feed = $bot[1]; 
    1501                         } else { 
    1502                                 $spider = trim($bot); 
    1503                         } 
    1504                 } 
     1544                if (empty($browser) || stristr($browser,"N/A")) { 
     1545                        list($spider,$feed) = wGetSpider($userAgent,$hostname); 
     1546                } 
     1547                 
    15051548                //#I prefer to see os/browser info. for spiders/bots. 
    1506                 //if ($spider != '') { $os=''; $browser=''; } 
    15071549 
    15081550        //spider exclusion control 
     
    15591601        } 
    15601602        if ( $wassup_options->wassup_spam == 1 && $spam == 0 ) { 
    1561                 //# some useragents to exclude from spam checking... 
    1562                 $goodbots = array('Google','Yahoo!','MSN','SummizeFeedReader'); 
     1603                //# some valid spiders to exclude from spam checking 
     1604                $goodbot = false; 
     1605                if ($hostname!="" && !empty($spider)) { 
     1606                        if (preg_match('/^(googlebot|msnbot|yahoo\!\ slurp|technorati)/i',$spider)>0 && preg_match('/(googlebot|live|msn|yahoo|technorati)\.(com|net)$/i',$hostname)>0){ 
     1607                                $goodbot = true; 
     1608                        } 
     1609                } 
    15631610 
    15641611                //# No duplicate spam testing in same session unless there  
     
    15691616                //# No spam check on known bots (google, yahoo,...) unless 
    15701617                //#  there is a comment or forum page request... 
    1571                 } elseif (empty($spider) || array_search($spider,$goodbots) === FALSE || stristr($urlRequested,"comment") !== FALSE || stristr($urlRequested,"forum") !== FALSE  || !empty($comment_user) ) {  
     1618                } elseif (empty($spider) || !$goodbot || stristr($urlRequested,"comment") !== FALSE || stristr($urlRequested,"forum") !== FALSE  || !empty($comment_user) ) {  
    15721619 
    15731620                   // Try to search for previous spammer detected by akismet with same IP 
     
    16541701                $recorded = true; 
    16551702                // Delete records older then 3 minutes 
    1656                 $wpdb->query("DELETE FROM $table_tmp_name WHERE timestamp<'".strtotime("-3 minutes", $timestamp)."'"); 
     1703                $wpdb->query("DELETE FROM $table_tmp_name WHERE `timestamp`<'".strtotime("-3 minutes", $timestamp)."'"); 
    16571704 
    16581705        } //end if $spam == 0 
     
    16611708        } //end if dup_urlrequest == 0 
    16621709 
     1710        } //end if !is_404 
    16631711        } //end if wassup_attack 
    16641712        } //end if wassup_loggedin 
     
    16781726                $from_date = strtotime($wassup_options->delete_auto, $timestamp); 
    16791727                //#check before doing delete as it could lock the table... 
    1680                 if ((int)$wpdb->get_var("SELECT COUNT(id) FROM $table_name WHERE timestamp<'$from_date'") > 0) { 
    1681                         $wpdb->query("DELETE FROM $table_name WHERE timestamp<'$from_date'"); 
     1728                if ((int)$wpdb->get_var("SELECT COUNT(id) FROM $table_name WHERE `timestamp`<'$from_date'") > 0) { 
     1729                        $wpdb->query("DELETE FROM $table_name WHERE `timestamp`<'$from_date'"); 
    16821730                } 
    16831731                // Optimize table once a day 
     
    17261774 
    17271775                if (method_exists($wpdb,'prepare')) { 
    1728                         $insert = $wpdb->query( $wpdb->prepare("INSERT INTO $table_name (wassup_id, timestamp, ip, hostname, urlrequested, agent, referrer, search, searchpage, os, browser, language, screen_res, searchengine, spider, feed, username, comment_author, spam)  
     1776                        $insert = $wpdb->query( $wpdb->prepare("INSERT INTO $table_name (wassup_id, `timestamp`, ip, hostname, urlrequested, agent, referrer, search, searchpage, os, browser, language, screen_res, searchengine, spider, feed, username, comment_author, spam)  
    17291777                           VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s )", 
    17301778                           attribute_escape($wassup_id), 
     
    17501798                } else { 
    17511799                        $insert = $wpdb->query("INSERT INTO " . $table_name . 
    1752                            " (wassup_id, timestamp, ip, hostname, urlrequested, agent, referrer, search, searchpage, os, browser, language, screen_res, searchengine, spider, feed, username, comment_author, spam) " . 
     1800                           " (wassup_id, `timestamp`, ip, hostname, urlrequested, agent, referrer, search, searchpage, os, browser, language, screen_res, searchengine, spider, feed, username, comment_author, spam) " . 
    17531801                           "VALUES ( 
    17541802                           '".attribute_escape($wassup_id)."', 
     
    19051953} 
    19061954 
    1907 function wGetSpider($agent = null){ 
     1955//extract browser and platform info from a user agent string and 
     1956// return the values in an array: 0->browser 1->os. -Helene D. 6/7/08. 
     1957function wGetBrowser($agent="") { 
     1958        if (empty($agent)) { $agent = $_SERVER['HTTP_USER_AGENT']; } 
     1959        $browsercap = array(); 
     1960        $browser = ""; 
     1961        $os = ""; 
     1962        //check PHP browscap data for browser and platform, when available 
     1963        if (ini_get("browscap") != "" ) { 
     1964                $browsercap = get_browser($agent,true); 
     1965                if (!empty($browsercap['platform'])) { 
     1966                if (stristr($browsercap['platform'],"unknown") === false) { 
     1967                        $os = $browsercap['platform']; 
     1968                        if (!empty($browsercap['browser'])) { 
     1969                                $browser = $browsercap['browser']; 
     1970                        } else { 
     1971                                $browser = $browsercap['parent']; 
     1972                        } 
     1973                        if (!empty($browsercap['version'])) { 
     1974                                $browser = $browser." ".$browsercap['version']; 
     1975                        } 
     1976                } } 
     1977                //reject generic browscap browsers (ex: mozilla, default) 
     1978                if (preg_match('/^(mozilla|default|unknown)/i',$browser) > 0) { 
     1979                        $browser = ""; 
     1980                } 
     1981        } 
     1982        $os = trim($os);  
     1983        $browser = trim($browser); 
     1984 
     1985        //use Detector class when browscap is missing or browser is unknown 
     1986        if ( $os == "" || $browser == "") { 
     1987                $dip = &new Detector("", $agent); 
     1988                $browser =  $dip->browser." ".$dip->browser_version; 
     1989                $os = $dip->os." ".$dip->os_version; 
     1990        } 
     1991        return array(trim($browser),trim($os)); 
     1992} //end function wGetBrowser 
     1993 
     1994//extract spider and feed info from a user agent string and 
     1995// return the values in an array: 0->spider 1->feed 
     1996function wGetSpider($agent="",$hostname=""){ 
     1997        if (empty($agent)) { $agent = $_SERVER['HTTP_USER_AGENT']; } 
     1998        $crawler = ""; 
     1999        $feed = ""; 
     2000        $os = ""; 
     2001        //check browscap data for crawler info., when available 
     2002        if (ini_get("browscap") != "" ) { 
     2003                $browsercap = get_browser($agent,true); 
     2004                //if no platform(os), assume crawler... 
     2005                if (!empty($browsercap['platform'])) { 
     2006                        if ( $browsercap['platform'] != "unknown") { 
     2007                                $os = $browsercap['platform']; 
     2008                        } 
     2009                } 
     2010                if (!empty($browsercap['crawler']) || !empty($browsercap['stripper']) || $os == "") { 
     2011                        if (!empty($browsercap['browser'])) { 
     2012                                $crawler = $browsercap['browser']; 
     2013                        } else { 
     2014                                $crawler = $browsercap['parent']; 
     2015                        } 
     2016                        if (!empty($browsercap['version'])) { 
     2017                                $crawler = $crawler." ".$browsercap['version']; 
     2018                        } 
     2019                } 
     2020                //reject unknown browscap crawlers (ex: default) 
     2021                if (preg_match('/^(default|unknown)/i',$crawler) > 0) { 
     2022                        $crawler = ""; 
     2023                } 
     2024        } 
     2025 
     2026        //get crawler info. from a known list 
     2027        $crawler = trim($crawler); 
    19082028        $agent=str_replace(" ","",$agent); 
    1909         $key = null; 
     2029        if (empty($crawler)) { 
     2030                $key = null; 
    19102031        $lines = array("Wordpress Pingback/Trackback|Wordpress|", "Alexa|ia_archiver|","Ask.com/Teoma|AskJeeves/Teoma)|","Biz360|Biz360|","Naver|NaverBot|","Naver|Cowbot|","cURL|curl/|","Google|Googlebot/|", 
    19112032                        "Google|googlebot/|","Google Images|Googlebot-Image|","LookSmart|grub-client|","Yahoo!|slurp@inktomi|","Yahoo!|Yahoo!Slurp|", 
     
    19682089                        "GurujiBot|GurujiBot|", "Missigua Locator|Missigua Locator|", "ISC Systems iRc Search|ISC Systems iRc Search|", "whiteiexpres/Nutch|whiteiexpres/Nutch|", 
    19692090                        "kalooga/kalooga|kalooga/kalooga|", "Bookdog|Bookdog|", "webLyzard|webLyzard|", "EnaBot|EnaBot|", "AboutUsBot|AboutUsBot|"); 
    1970         foreach($lines as $line_num => $spider) { 
    1971                 list($nome,$key)=explode("|",$spider); 
    1972                 if(@strpos(strtolower($agent),strtolower($key))===FALSE) continue; 
    1973                 if (@strpos(strtolower($agent), "subscriber")!== FALSE) { 
    1974                         preg_match("/([0-9]{1,10})(subscriber)/i", $agent, $subscriber); 
    1975                         $feed[] = $nome; 
    1976                         $feed[] = $subscriber[1]; 
    1977                         // It's a feedreader with some subscribers 
    1978                         return $feed; 
     2091                foreach($lines as $line_num => $spider) { 
     2092                        list($nome,$key)=explode("|",$spider); 
     2093                        if(stristr($agent,$key)===FALSE) { continue; } 
     2094                        else { $crawler = trim($nome); } 
     2095                } 
     2096        } // end if crawler 
     2097 
     2098        //determine if this is a feed reader... 
     2099        if (preg_match("/([0-9]{1,10})(subscriber)/i",$agent,$subscriber) > 0) { 
     2100                // It's a feedreader with some subscribers 
     2101                $feed = $subscriber[1]; 
     2102                if (empty($crawler)) {  
     2103                        $crawler = "Feed Reader"; 
     2104                } 
     2105        } elseif (@strpos(strtolower($agent),"feed")!== FALSE) { 
     2106                if (empty($crawler)) {  
     2107                        $crawler = "Feed Reader"; 
     2108                        $feed = "feed reader"; 
    19792109                } else { 
    1980                         // find it! 
    1981                         return $nome; 
    1982                 } 
    1983         } 
    1984         return null; 
     2110                        $feed = $crawler; 
     2111                } 
     2112        } //end if preg_match subscriber 
     2113 
     2114        //check for spoofers of Google/Msn/Yahoo crawlers... 
     2115        if ($hostname!="") { 
     2116                if (preg_match('/^(googlebot|msnbot|yahoo\!\ slurp)/i',$crawler)>0 && preg_match('/(googlebot|live|msn|yahoo)\./i',$hostname)==0){ 
     2117                        $crawler = "Spoofer bot"; 
     2118                } 
     2119        } //end if hostname 
     2120 
     2121        return array($crawler,trim($feed)); 
    19852122} 
    19862123 
     
    19932130        $badhostfile= dirname(__FILE__).'/badhosts.txt'; 
    19942131        $key = null; 
    1995        
    19962132        if (empty($referrer)) { return null; }  //nothing to check... 
    19972133 
     
    20042140                } 
    20052141        } 
    2006          
    20072142        $lines = array("1clickholdem.com", "1ps.biz", "24h.to", "4all-credit.com", "4all-prescription.com", "4u-money.com", "6q.org", "88.to", "always-casino.com", 
    20082143        "always-credit.com", "andipink.com", "antiquemarketplace.net", "artmedia.com.ru", "asstraffic.com", "at.cx", "available-casino.com", "available-credit.com",