Changeset 73 for trunk

Show
Ignore:
Timestamp:
02/12/08 14:08:39 (11 months ago)
Author:
root
Message:

cleaned code

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/action.php

    r64 r73  
    4242                $Tot->from_date = $from_date; 
    4343                $Tot->to_date = $to_date; 
    44                 $items_pie[] = $Tot->calc_tot("items_by_type", $search, "spam"); 
    45                 $items_pie[] = $Tot->calc_tot("items_by_type", $search, "searchengine"); 
    46                 $items_pie[] = $Tot->calc_tot("items_by_type", $search, "referrer"); 
    47                 $items_pie[] = $Tot->calc_tot("items_by_type", $search, "direct"); 
     44                $items_pie[] = $Tot->calc_tot("count", $search, "AND spam>0", "DISTINCT"); 
     45                $items_pie[] = $Tot->calc_tot("count", $search, "AND searchengine!='' AND spam=0", "DISTINCT"); 
     46                $items_pie[] = $Tot->calc_tot("count", $search, "AND searchengine='' AND referrer NOT LIKE '%".$this->WpUrl."%' AND referrer!='' AND spam=0", "DISTINCT"); 
     47                $items_pie[] = $Tot->calc_tot("count", $search, "AND searchengine='' AND (referrer LIKE '%".$this->WpUrl."%' OR referrer='') AND spam=0", "DISTINCT"); 
    4848                echo "<div align='center'><img src=http://chart.apis.google.com/chart?cht=p3&chco=0000ff&chs=600x300&chl=Spam|Search%20Engine|Referrer|Direct&chd=".chart_data($items_pie, null, null, null, 'pie')."></div>"; 
    4949        // ACTION: DISPLAY RAW RECORDS 
  • trunk/lib/main.php

    r72 r73  
    717717        var $Limit; 
    718718        var $Last; 
    719         var $Marked_ip; 
    720719        var $WpUrl; 
    721720 
    722721        // Function to show main query and count items 
    723         function calc_tot($Type, $Search="", $pertype="") { 
     722        function calc_tot($Type, $Search="", $specific_where_clause=null, $distinct_type=null) { 
    724723                global $wpdb; 
    725724                $this->ItemsType = $Type; 
     
    737736                        break; 
    738737                        // These are the queries to count the items hits/pages/spam 
    739                         case "items": 
    740                                 $itemstot = $wpdb->get_var("SELECT COUNT(DISTINCT wassup_id) AS itemstot FROM ".$this->tableName." WHERE wassup_id IS NOT NULL AND timestamp BETWEEN ".$this->from_date." AND ".$this->to_date." $ss ".$this->whereis); 
     738                        case "count": 
     739                                $itemstot = $wpdb->get_var("SELECT COUNT(".$distinct_type." wassup_id) AS itemstot FROM ".$this->tableName." WHERE wassup_id IS NOT NULL ".$specific_where_clause." AND timestamp BETWEEN ".$this->from_date." AND ".$this->to_date." $ss ".$this->whereis); 
    741740                                return $itemstot; 
    742                         break; 
    743                         case "pages": 
    744                                 $pagestot = $wpdb->get_var("SELECT COUNT(wassup_id) AS pagestot FROM ".$this->tableName." WHERE wassup_id IS NOT NULL AND timestamp BETWEEN ".$this->from_date." AND ".$this->to_date." $ss ".$this->whereis); 
    745                                 return $pagestot; 
    746                         break; 
    747                         case "spam": 
    748                                 $spamtot = $wpdb->get_var("SELECT COUNT(wassup_id) AS spamtot FROM ".$this->tableName." WHERE wassup_id IS NOT NULL AND spam>0 AND timestamp BETWEEN ".$this->from_date." AND ".$this->to_date." $ss ".$this->whereis); 
    749                                 return $spamtot; 
    750                         break; 
    751                         // Switch by specific count 
    752                         case "items_by_type": 
    753                                 switch ($pertype) { 
    754                                         case "spam": 
    755                                         $items_type = "spam>0"; 
    756                                         break; 
    757                                         case "marked": 
    758                                         $items_type = "ip LIKE '%".$this->Marked_ip."%'"; 
    759                                         break; 
    760                                         case "searchengine": 
    761                                         $items_type = "searchengine!='' AND spam=0"; 
    762                                         break; 
    763                                         case "referrer": 
    764                                         $items_type = "searchengine='' AND referrer NOT LIKE '%".$this->WpUrl."%' AND referrer!='' AND spam=0"; 
    765                                         break; 
    766                                         case "direct": 
    767                                         $items_type = "searchengine='' AND (referrer LIKE '%".$this->WpUrl."%' OR referrer='') AND spam=0"; 
    768                                         break; 
    769                                 } 
    770                                 $itemstot_by_type = $wpdb->get_var("SELECT COUNT(DISTINCT wassup_id) AS itemstot FROM ".$this->tableName." WHERE wassup_id IS NOT NULL AND $items_type AND timestamp BETWEEN ".$this->from_date." AND ".$this->to_date." $ss ".$this->whereis); 
    771                                 return $itemstot_by_type; 
    772741                        break; 
    773742                } 
  • trunk/wassup.php

    r71 r73  
    608608                $Tot->WpUrl = $wpurl; 
    609609 
    610                 $itemstot = $Tot->calc_tot("items", $search); 
    611                 $pagestot = $Tot->calc_tot("pages", $search); 
    612                 $spamtot = $Tot->calc_tot("spam", $search); 
     610                $itemstot = $Tot->calc_tot("count", $search, null, "DISTINCT"); 
     611                $pagestot = $Tot->calc_tot("count", $search, null, null); 
     612                $spamtot = $Tot->calc_tot("count", $search, "AND spam>0"); 
    613613                // Check if some records was marked 
    614614                if ($wassup_settings['wmark'] == 1) { 
    615                         $Tot->Marked_ip = $wassup_settings['wip'];  
    616                         $markedtot = $Tot->calc_tot("items_by_type", $search, "marked"); 
     615                        $markedtot = $Tot->calc_tot("count", $search, "AND ip LIKE '%".$wassup_settings['wip']."%'", "DISTINCT"); 
    617616                } 
    618617 
     
    11001099           } 
    11011100           session_start();     //required to use/update $_SESSION 
     1101            
     1102           // Prevent Session Fixation attack (http://shiflett.org/articles/session-fixation) 
     1103           if (!isset($_SESSION['initiated'])) {  
     1104              session_regenerate_id();  
     1105              $_SESSION['initiated'] = true;  
     1106           }  
     1107 
    11021108           //#confirm that session is started... 
    11031109           if (isset($_SESSION)) { 
     
    12801286                $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)  
    12811287                   VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s )", 
    1282                    $wassup_id, 
    1283                    $timestamp, 
     1288                   attribute_escape($wassup_id), 
     1289                   attribute_escape($timestamp), 
    12841290                   attribute_escape($ipAddress), 
    12851291                   attribute_escape($hostname), 
     
    12871293                   attribute_escape($userAgent), 
    12881294                   attribute_escape($referrer), 
    1289                    $search_phrase, 
    1290                    $searchpage,  
    1291                    $os,  
    1292                    $browser,  
    1293                    $language[0],  
    1294                    $screen_res,  
    1295                    $searchengine,  
    1296                    $spider,  
    1297                    $feed,  
     1295                   attribute_escape($search_phrase), 
     1296                   attribute_escape($searchpage),  
     1297                   attribute_escape($os),  
     1298                   attribute_escape($browser),  
     1299                   attribute_escape($language[0]),  
     1300                   attribute_escape($screen_res),  
     1301                   attribute_escape($searchengine),  
     1302                   attribute_escape($spider),  
     1303                   attribute_escape($feed),  
    12981304                   attribute_escape($logged_user),  
    12991305                   attribute_escape($comment_user),  
    1300                    $spam 
     1306                   attribute_escape($spam) 
    13011307                   )); 
    13021308 
     
    18521858        $wassup_settings = get_option('wassup_settings'); 
    18531859         
    1854         if (isset($_POST['submit'])) 
     1860        if (isset($_POST['wassup-submit'])) 
    18551861        { 
    18561862                $wassup_settings['wassup_widget_title'] = $_POST['wassup_widget_title']; 
     
    18751881        <div class="wrap" style="text-align:left"> 
    18761882        <h3>Wassup Widget</h3> 
    1877         <form action="" method="post"> 
    18781883        <p style="text-align:left"><input type="text" name="wassup_widget_title" size="20" value="<?php echo $wassup_settings['wassup_widget_title'] ?>" /> What title for the widget (default "Visitors Online")</p> 
    18791884        <p style="text-align:left"><input type="text" name="wassup_widget_ulclass" size="3" value="<?php echo $wassup_settings['wassup_widget_ulclass'] ?>" /> What style sheet class for &lt;ul&gt; attribute (default "links")</p> 
     
    18891894        <p style="text-align:left"><input type="checkbox" name="wassup_widget_topos" value="1" <?php if ($wassup_settings['wassup_widget_topos'] == 1) echo "CHECKED"; ?> /> Check if you want to show top operating systems (default Yes)</p> 
    18901895        <p style="text-align:left"><input type="text" name="wassup_widget_toposlimit" size="3" value="<?php echo $wassup_settings['wassup_widget_toposlimit'] ?>" /> How many top operating systems want to show (default 5)</p> 
    1891         <p style="text-align:left"><input type="submit" name="submit" value="Save Settings" /></p> 
    1892         </form> 
     1896        <p style="text-align:left"><input type="hidden" name="wassup-submit" id="wassup-submit" value="1" /> </p> 
    18931897        </div> 
    18941898        <?php 
     
    19001904                        $wassup_settings['wassup_userlevel'] = 8; 
    19011905                        update_option('wassup_settings', $wassup_settings); 
    1902                 } 
    1903                 if ($wassup_settings['wassup_refresh'] == "") { 
     1906        } 
     1907        if ($wassup_settings['wassup_refresh'] == "") { 
    19041908                        $wassup_settings['wassup_refresh'] = 3; 
    19051909                        update_option('wassup_settings', $wassup_settings);