Plugin Directory

Changeset 620603


Ignore:
Timestamp:
11/03/2012 06:09:12 AM (13 years ago)
Author:
sandyr
Message:

Made changes to cover link unit clicks

Location:
cbprotect/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cbprotect/trunk/cbprotectclass.php

    r618891 r620603  
    33class bombclick {
    44
    5     var $wpdb = null;
     5    var $wpdb = null;
    66    var $clientip = null;
    77    var $clickcount = null;
    88    var $clientfound = null;
    9     var $isblockedip = null;
    10     var $table_name = null;
     9    var $isblockedip = null;
     10    var $table_name = null;
    1111
    1212    function __construct($dbcls=null)
     
    1414        if ($dbcls) $this->wpdb = $dbcls;
    1515        else $this->getdbo();
    16         $this->table_name = $this->wpdb->prefix."AD_CLICK";
     16        $this->table_name = $this->wpdb->prefix."AD_CLICK";
    1717        $this->clientip = $this->getclientip();
    1818        $this->clickcount = (isset($_POST['count']))?isset($_POST['count']):isset($_GET['count']);
    1919        $this->clientfound = $this->checkclient();
    2020    }
    21    
    2221
    2322
    24 function fs_get_wp_root_path()
    25 {
    26     $base = dirname(__FILE__);
    27     $path = false;
    2823
    29     if (@file_exists(dirname(dirname($base))."/wp-config.php"))
    30     {
    31         $path = dirname(dirname($base))."/";
    32     }
    33     else
    34     if (@file_exists(dirname(dirname(dirname($base)))."/wp-config.php"))
    35     {
    36         $path = dirname(dirname(dirname($base)))."/";
    37     }
    38     else
    39     $path = false;
     24    function fs_get_wp_root_path()
     25    {
     26        $base = dirname(__FILE__);
     27        $path = false;
    4028
    41     if ($path != false)
    42     {
    43         $path = str_replace("\\", "/", $path);
    44     }
    45     return $path;
    46 }
     29        if (@file_exists(dirname(dirname($base))."/wp-config.php"))
     30        {
     31            $path = dirname(dirname($base))."/";
     32        }
     33        else
     34            if (@file_exists(dirname(dirname(dirname($base)))."/wp-config.php"))
     35            {
     36                $path = dirname(dirname(dirname($base)))."/";
     37            }
     38            else
     39                $path = false;
     40
     41        if ($path != false)
     42        {
     43            $path = str_replace("\\", "/", $path);
     44        }
     45        return $path;
     46    }
    4747
    4848    function getdbo() {
    4949        if (!isset($wpdb)) {           
    5050            $wp_root_path = $this->fs_get_wp_root_path();
    51            
    52             //include_once($wp_root_path . 'wp-config.php');
    5351            include_once($wp_root_path . 'wp-load.php');
    5452            include_once($wp_root_path .'wp-includes/wp-db.php');
     
    5755        $this->wpdb = $wpdb;
    5856    }
    59    
     57
    6058
    6159    function getclientip() {
    62         $clientip =   $_SERVER['REMOTE_ADDR']; //"222.4.4.1";
    63         return $clientip;
    64     }
    65    
    66     function getFirstClickTimeStamp()
    67     {
    68         $getresult = null;
    69         $result = $this->wpdb->get_var( "SELECT CLICK_TIMESTAMP FROM ".esc_attr($this->table_name)." where IP_ADDRESS='".esc_attr($this->clientip)."' order by CLICK_TIMESTAMP asc limit 0,1");
    70         $fulldate = explode(" ",$result);
    71         $date =  $fulldate[0];
    72         $time = $fulldate[1];
    73         $firstclickdata[] = explode("-",$date);
    74         $firstclickdata[] = explode(":",$time);
    75    
    76         return $firstclickdata;
    77        
    78     }
    79    
    80     function dateDiff($start, $end)
    81     {
    82    
    83         $start_ts = strtotime($start);
    84    
    85         $end_ts = strtotime($end);
    86    
    87         $diff = $end_ts - $start_ts;
    88    
    89         return round($diff / 86400);
    90    
    91     }
    92    
    93  
     60        $clientip =   $_SERVER['REMOTE_ADDR'];
     61        return $clientip;
     62    }
     63
     64    function getFirstClickTimeStamp()
     65    {
     66        $getresult = null;
     67        $result = $this->wpdb->get_var( "SELECT CLICK_TIMESTAMP FROM ".esc_attr($this->table_name)." where IP_ADDRESS='".esc_attr($this->clientip)."' order by CLICK_TIMESTAMP asc limit 0,1");
     68        $fulldate = explode(" ",$result);
     69        $date =  $fulldate[0];
     70        $time = $fulldate[1];
     71        $firstclickdata[] = explode("-",$date);
     72        $firstclickdata[] = explode(":",$time);
     73
     74        return $firstclickdata;
     75
     76    }
     77
     78    function dateDiff($start, $end)
     79    {
     80        $start_ts = strtotime($start);
     81        $end_ts = strtotime($end);
     82        $diff = $end_ts - $start_ts;
     83        return round($diff / 86400);
     84    }
     85
     86
    9487    function checkclient()
    9588    {
    96        
    9789        $bannedperiod = get_option('cbprotect_ban_period');
    9890        $daySpan = get_option('cbprotect_day_span');
     
    10193        $clickdateimplode = implode("-",$clickfirstdate);
    10294        $clickdate = str_replace("-","",$clickdateimplode);
    103        
    104          $currentdatedata =  date('Y-m-d'); //date("2012-09-15");
     95
     96        $currentdatedata =  date('Y-m-d'); //date("2012-09-15");
    10597        $currentdate = str_replace("-","",$currentdatedata);
    10698        $enddatedata = strtotime ( '+'.$bannedperiod.' day' , strtotime ( $clickdateimplode ) ) ;
    10799        $enddate =  str_replace("-","",date ( 'Y-m-d' , $enddatedata ));
    108          $endformat = date($enddate);
    109        
    110          $daysDiff = $this->dateDiff($clickdateimplode,$currentdatedata);
    111        
    112          $sql = "select IP_ADDRESS,BLOCKED from ".$this->table_name." where IP_ADDRESS='".$this->clientip."'";
     100        $endformat = date($enddate);
     101
     102        $daysDiff = $this->dateDiff($clickdateimplode,$currentdatedata);
     103
     104        $sql = "select IP_ADDRESS,BLOCKED from ".$this->table_name." where IP_ADDRESS='".$this->clientip."'";
    113105        $results = $this->wpdb->get_results($sql);
    114        
     106
    115107        if(empty($results))
    116108        {
     
    124116            {
    125117                $clickip = $row->IP_ADDRESS;
    126                                
    127                     if($daysDiff <= $daySpan)
    128                     {
    129                          $sqlquery = "select * from ".$this->table_name." where IP_ADDRESS ='".$clickip."' and CLICK_TIMESTAMP like '$clickdateimplode%'";
    130                          $resultsql = $this->wpdb->get_results($sqlquery);
    131                     }
    132                     else if($daysDiff > $daySpan)
    133                     {
    134                        
    135                         $sqlquery = "select * from ".$this->table_name." where IP_ADDRESS ='".$clickip."' and CLICK_TIMESTAMP like '$currentdatedata%'";
    136                          $resultsql = $this->wpdb->get_results($sqlquery);
    137                     }
    138                
     118
     119                if($daysDiff <= $daySpan)
     120                {
     121                    $sqlquery = "select * from ".$this->table_name." where IP_ADDRESS ='".$clickip."' and CLICK_TIMESTAMP like '$clickdateimplode%'";
     122                    $resultsql = $this->wpdb->get_results($sqlquery);
     123                }
     124                else if($daysDiff > $daySpan)
     125                {
     126
     127                    $sqlquery = "select * from ".$this->table_name." where IP_ADDRESS ='".$clickip."' and CLICK_TIMESTAMP like '$currentdatedata%'";
     128                    $resultsql = $this->wpdb->get_results($sqlquery);
     129                }
     130
    139131                $countresult = count($resultsql);
    140132                return $countresult;
    141            
     133
    142134            }
    143135        }
    144            
     136
    145137    }
    146138
     
    148140    function updateclick()
    149141    {
    150         $clickcount = get_option('cbprotect_click_threshold');
     142        $clickcount = get_option('cbprotect_click_threshold');
    151143        $bannedperiod = get_option('cbprotect_ban_period');
    152144        $daySpan = get_option('cbprotect_day_span');
    153        
     145
    154146        $clickdata = $this->getFirstClickTimeStamp();
    155147        $clickfirstdate = $clickdata[0];
    156          $clickdateimplode = implode("-",$clickfirstdate);
     148        $clickdateimplode = implode("-",$clickfirstdate);
    157149        $clickdate = str_replace("-","",$clickdateimplode);
    158        
     150
    159151        $currentdatedata = date('Y-m-d'); //date("2012-09-15");
    160          $currentdate = str_replace("-","",$currentdate1);
     152        $currentdate = str_replace("-","",$currentdate1);
    161153        $enddate = strtotime ( '+'.$bannedperiod.' day' , strtotime ( $clickdateimplode ) ) ;
    162154        $enddate =  str_replace("-","",date ( 'Y-m-d' , $enddate ));
    163155        $endformat = date($enddate);
    164156        $daysDiff = $this->dateDiff($clickdateimplode,$currentdatedata);
    165        
     157
    166158        if ($this->clientfound < $clickcount)
    167159        {
     
    174166            if (($this->clientfound >= $clickcount || $this->clickcount >= $clickcount)) {
    175167                $setfield = 'BLOCKED=1 ';
    176            
    177              $sql = "UPDATE ".$this->table_name." SET ".$setfield." where IP_ADDRESS='".$this->clientip."'";
    178              $resultinsert = $this->wpdb->query($sql);
     168
     169                $sql =  "UPDATE ".$this->table_name." SET ".$setfield." where IP_ADDRESS='".$this->clientip."'";
     170                $resultinsert = $this->wpdb->query($sql);
    179171            }   
    180172        }
    181        
    182        
     173
     174
    183175        return $resultinsert;
    184                
     176
    185177    }
    186    
     178
    187179    function clientdetail($preurl) {
    188180        $clientdetail = array(
    189                            "client_ip"=>$this->getclientip(),
    190                            "clickcount"=>get_option('cbprotect_click_threshold'),
    191                            "bannedperiod"=>get_option('cbprotect_ban_period'),
    192                            "preurl" => $preurl,
    193                            "firstclickdate" => $this->getFirstClickTimeStamp(),
    194                            "updatedVisitCount" => $this->checkclient(),
    195                              );
     181            "client_ip"=>$this->getclientip(),
     182            "clickcount"=>get_option('cbprotect_click_threshold'),
     183            "bannedperiod"=>get_option('cbprotect_ban_period'),
     184            "preurl" => $preurl,
     185            "firstclickdate" => $this->getFirstClickTimeStamp(),
     186            "updatedVisitCount" => $this->checkclient(),
     187        );
    196188        return $clientdetail;
    197189    }
    198190
    199191}
    200 
    201 
    202192?>
  • cbprotect/trunk/js/click_bomb_check.js

    r618891 r620603  
    11var clientIP= client.client_ip;
    2 //alert("clientIP"+clientIP);
    32var maxclickcount = client.clickcount;
    43var bannedperiod = client.bannedperiod;
    54var preurl = client.preurl;
    65var firstclickdata = client.firstclickdate;
    7 //alert("firstclickdata"+firstclickdata);
    86var firstclickdate = firstclickdata[0][1]-1;
    9 //alert(firstclickdate);
    107var updatedVisitCount = parseInt(client.updatedVisitCount);
    118var jq = null;
     
    1310var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
    1411var clickdate = new Date(firstclickdata[0][0],firstclickdate,firstclickdata[0][2],firstclickdata[1][0],firstclickdata[1][1],firstclickdata[1][2]);
    15 //alert("clickdate"+clickdate);
    16 
    1712var currDate = new Date();
    18 
    1913var secondDate = clickdate.setTime(clickdate.getTime() + (bannedperiod * 24 * 60 * 60 * 1000));
    2014var endDate = new Date(secondDate);
    21 //alert("endDate"+endDate);
    2215
    2316
     
    2518{
    2619    var clientdata = {"clientIP":clientIP,"visitcount":updatedVisitCount};
    27     console.log(clientdata);
    2820    if (clientdata.clientIP) {
    29         console.log("The client IP has matched");
    3021        updatedVisitCount = ++clientdata.visitcount;
    31         //alert("in if updatedVisitCount"+updatedVisitCount);
    3222       
    3323    } else {
     
    3525   
    3626    }
    37    
    3827    ajax_post();
    39    
    4028    if (updatedVisitCount > maxclickcount)
    4129    {
    42         //alert("in maxclick");
    43            
    44         console.log("Default click has been prevented");
    4530        event.preventDefault();
    4631       
    4732       
    4833    }
    49    
    5034}
    5135
     
    7559    jq = jQuery.noConflict();
    7660   
    77     $("#cbprotect img").click(function(event) {
     61    $("#cbprotect").click(function(event) {
    7862        cbProtectProcess(event);
    7963       
Note: See TracChangeset for help on using the changeset viewer.