Changeset 149 for trunk

Show
Ignore:
Timestamp:
07/13/08 22:14:55 (4 months ago)
Author:
root
Message:

Initial 1.6.2b with Google Maps GEO IP support

Location:
trunk
Files:
5 added
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/main.php

    r147 r149  
    611611                   }  
    612612                   // User is logged in or is a comment's author 
    613                    if ($cv->username != "" AND $cv->comment_author != "") { 
     613                   if ($cv->username != "") { 
    614614                        $unclass = "-log"; 
    615                    } elseif ($cv->comment_author != "") { 
     615                        $map_icon = "marker_loggedin.png"; 
     616                   } elseif ($cv->comment_author != "" AND $cv->username == "") { 
    616617                        $unclass = "-aut"; 
     618                        $map_icon = "marker_author.png"; 
    617619                   } elseif ($cv->spider != "") { 
    618620                        $unclass = "-spider"; 
    619                    }  
     621                        $map_icon = "marker_bot.png"; 
     622                   } else { 
     623                        $map_icon = "marker_user.png"; 
     624                   } 
    620625                   // Start getting GEOIP info 
    621                    /* 
    622                    // TODO 
    623                    $ch = curl_init("http://api.hostip.info/get_html.php?ip=".$ip[0]."&position=true"); 
    624                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    625                    curl_setopt($ch, CURLOPT_HEADER, 0); 
    626                    $data = curl_exec($ch); 
    627                    curl_close($ch); 
    628                    */ 
     626                   $geo_url = "http://api.hostip.info/get_html.php?ip=".$ip[0]."&position=true"; 
     627                   $data = file($geo_url); 
     628                   $location = $data[0]." ".$data[1]; 
     629                   $location = eregi_replace("country: ", "", $location); 
     630                   $location = eregi_replace("city: ", "", $location); 
     631        if ($wassup_settings['wassup_geoip_map'] == 1) { 
     632                $gkey = $wassup_settings['wassup_googlemaps_key']; 
     633                   if (trim($location) != "") { 
     634                           $geocode = explode(",", geocode($location, $gkey)); 
     635                                if(array_search("Error", $geocode) == "") { 
     636                                        $lat = explode(":", $data[2]); 
     637                                        $lat = $lat[1]; 
     638                                        $lon = explode(":", $data[3]); 
     639                                        $lon = $lon[1]; 
     640                                } else { 
     641                                        $lat = $geocode[0]; 
     642                                        $lon = $geocode[1]; 
     643                                } 
     644                   } else { 
     645                           $lat = 0; 
     646                           $lon = 0; 
     647                   } 
     648        } 
    629649                   ?> 
    630650                   <div class="sum-spy"> 
    631  
    632651                   <span class="sum-box<?php print $unclass; ?>"> 
    633652                        <?php print $ip[0]; ?></span> 
    634                    <div class="sum-det"><span class="det1"> 
     653                   <div class="sum-det-spy"><span class="det1"> 
    635654                   <?php 
    636655                        print '<a href="'.wAddSiteurl(htmlspecialchars(html_entity_decode($cv->urlrequested))).'" target="_BLANK">'; 
     
    638657                   </a></span><br /> 
    639658                   <span class="det2"><strong><?php print gmdate("H:i:s", $timestamp); ?> - </strong> 
    640                    <?php print $referrer; ?></span> 
     659                   <?php print $referrer; ?> 
     660                   <?php print "<br />".$location;  
     661                        ?> 
     662                   </span> 
    641663                   </div></div> 
    642 <?php           } //end if row_count 
     664<?php 
     665        if ($wassup_settings['wassup_geoip_map'] == 1) { 
     666                if ($lat!=0 && $lon!=0) { 
     667                $item_id = $cv->id; 
     668                $img_dir = $wpurl.'/wp-content/plugins/'.WASSUPFOLDER.'/img'; 
     669                echo " 
     670                <script type=\"text/javascript\"> 
     671                var icon$item_id = new GIcon(); 
     672                icon$item_id.image = '".$img_dir."/".$map_icon."'; 
     673                icon$item_id.shadow = '$img_dir/shadow.png'; 
     674                icon$item_id.iconSize = new GSize(20.0, 34.0); 
     675                icon$item_id.shadowSize = new GSize(38.0, 34.0); 
     676                icon$item_id.iconAnchor = new GPoint(10.0, 17.0); 
     677                icon$item_id.infoWindowAnchor = new GPoint(10.0, 17.0); 
     678                var point = new GLatLng($lat,$lon); 
     679                var marker$item_id = new GMarker(point, icon$item_id); 
     680                map.addOverlay(marker$item_id); 
     681                GEvent.addListener(marker$item_id, 'click', function() { 
     682                marker$item_id.openInfoWindowHtml('<div style=\"white-space:nowrap\"><div class=\"bubble\">Ip: ". 
     683                        $ip[0] 
     684                        ."<br />Hour: ". 
     685                        gmdate('H:i:s', $timestamp) 
     686                        ."<br />Request: <a href=". 
     687                        wAddSiteurl(htmlspecialchars(html_entity_decode($cv->urlrequested))) 
     688                        ." target=\"_BLANK\">". 
     689                        stringShortener(html_entity_decode($cv->urlrequested), round($max_char_len*.9,0)) 
     690                        ."</a></div></div>'); 
     691                }); 
     692                map.panTo(new GLatLng($lat,$lon),3); 
     693                </script>"; 
     694                } 
     695        } 
     696 
     697                } //end if row_count 
    643698                $row_count=$row_count+1; 
    644699                } //end foreach 
     
    650705        } //end if !empty($qryC) 
    651706} //end function spyview 
     707 
     708// Geocoding location with Google Maps 
     709function geocode($location, $key) { 
     710//Three parts to the querystring: q is address, output is the format ( 
     711$address = urlencode($location); 
     712$url = "http://maps.google.com/maps/geo?q=".$address."&output=csv&key=".$key; 
     713 
     714$ch = curl_init(); 
     715 
     716curl_setopt($ch, CURLOPT_URL, $url); 
     717curl_setopt($ch, CURLOPT_HEADER,0); 
     718curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER[HTTP_USER_AGEN]); 
     719curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
     720curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     721 
     722$data = curl_exec($ch); 
     723curl_close($ch); 
     724 
     725$data = explode(",",$data); 
     726if ($data[0] == 200) 
     727{ 
     728$lat = $data[2]; 
     729$lon = $data[3]; 
     730$coords = $lat.":".$lon; 
     731return $coords; 
     732 
     733} else { 
     734$coords = $data[0]; 
     735return $coords; 
     736} 
     737} 
    652738 
    653739// How many digits have an integer 
  • trunk/lib/settings.php

    r147 r149  
    8989                <p><input type="checkbox" name="wassup_dashboard_chart" value="1" <?php if($wassup_options->wassup_dashboard_chart == 1) print "CHECKED"; ?> /> <strong><?php _e('Display small chart in the dashboard','wassup'); ?></strong> 
    9090                </p><br /> 
     91 
     92                <?php // Test Google Maps Key If the test fails deactivate *map options  
     93                if ($wassup_options->wassup_geoip_map == 1 && $wassup_options->wassup_googlemaps_key != "") { 
     94                        $code = geocode("Ancona", $wassup_options->wassup_googlemaps_key); 
     95                                if ($code != "200") {  
     96                                        $style_key = "style='background:red'"; 
     97                                        $code_error = "<p>--->> <strong>WARNING</strong> Activation problem >> Error code: <a href='http://code.google.com/apis/maps/documentation/reference.html#GGeoStatusCode' target='_BLANK'>".$code."</a> <<---</p>"; 
     98                                        $wassup_options->wassup_geoip_map = 0; 
     99                                        $wassup_options->wassup_googlemaps_key = ""; 
     100                                        $wassup_options->saveSettings(); 
     101                                } 
     102                      } 
     103                ?> 
     104                <br /><h3><?php _e('GEO IP Map (Spy view)','wassup'); ?></h3> 
     105                <?php echo $code_error; ?> 
     106                <p><input type="checkbox" name="wassup_geoip_map" value="1" <?php if($wassup_options->wassup_geoip_map == 1) print "CHECKED"; ?> /> <strong><?php _e('Display a GEO IP Map in the spy visitors view','wassup'); ?></strong> 
     107                </p> 
     108                <p><strong>Google Maps API key:</strong> <input <?php echo $style_key; ?> type="text" name="wassup_googlemaps_key" size="40" value="<?php print $wassup_options->wassup_googlemaps_key; ?>" /> - <a href="http://www.google.com/maps/api_signup?url=<?php echo $wpurl; ?>">signup for your key</a></p></br /> 
    91109 
    92110                <br /><h3><?php _e('Time format','wassup'); ?></h3> 
  • trunk/lib/wassup.class.php

    r147 r149  
    1616        var $wassup_top10 ; 
    1717        var $wassup_dashboard_chart; 
     18        var $wassup_geoip_map; 
     19        var $wassup_googlemaps_key; 
    1820        var $wassup_time_format;        //new 
    1921 
     
    98100                $this->wassup_default_limit = "10"; 
    99101                $this->wassup_dashboard_chart = "0"; 
     102                $this->wassup_geoip_map = "0"; 
     103                $this->wassup_googlemaps_key = ""; 
    100104                $this->wassup_time_format = "24"; 
    101105                $this->wassup_widget_title = "Visitors Online"; 
  • trunk/wassup.css

    r122 r149  
    5353} 
    5454.sum-spy { 
     55        min-height: 54px; 
    5556        position: relative; 
    5657        clear: left; 
     
    9697        width: 100%; 
    9798} 
     99.sum-det-spy { 
     100        float:left; 
     101        margin: 0px 0 0px 0; 
     102        padding: 0; 
     103        line-height: 20px; 
     104        font-size: 14px; 
     105} 
    98106.sum-det { 
    99107        margin: 0px 0 0px 0; 
  • trunk/wassup.php

    r148 r149  
    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.6.1 
     6Version: 1.6.2b 
    77Author: Michele Marcucci, Helene D. 
    88Author URI: http://www.michelem.org/ 
     
    460460                $wassup_options->wassup_userlevel = $_POST['wassup_userlevel']; 
    461461                $wassup_options->wassup_dashboard_chart = $_POST['wassup_dashboard_chart']; 
     462                $wassup_options->wassup_geoip_map = $_POST['wassup_geoip_map']; 
     463                $wassup_options->wassup_googlemaps_key = $_POST['wassup_googlemaps_key']; 
    462464                $wassup_options->wassup_time_format = $_POST['wassup_time_format']; 
    463465                $wassup_options->wassup_default_type = $_POST['wassup_default_type']; 
     
    647649                <a href="#?" onclick="return playSpy();"><span id="spy-play"><?php _e("Play", "wassup"); ?></span></a> 
    648650                <br />&nbsp;<br /></div> 
     651 
     652        <?php // GEO IP Map 
     653        if ($wassup_options->wassup_geoip_map == 1 AND $wassup_options->wassup_googlemaps_key != "") { ?> 
     654                <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<?php echo $wassup_options->wassup_googlemaps_key; ?>" type="text/javascript"></script> 
     655                <div id="map" style="width: <?php echo ($screen_res_size*95/100); ?>px; height: 220px;border:2px solid #999;"></div> 
     656                    <script type="text/javascript"> 
     657                    //<![CDATA[ 
     658                    if (GBrowserIsCompatible()) {  
     659                      // Display the map, with some controls and set the initial location  
     660                      var map = new GMap2(document.getElementById("map")); 
     661                      map.addControl(new GSmallMapControl()); 
     662                      map.addControl(new GMapTypeControl()); 
     663                      //map.enableScrollWheelZoom(); 
     664                      map.setCenter(new GLatLng(0,0),3); 
     665                    } 
     666                    // display a warning if the browser was not compatible 
     667                    else { 
     668                      alert("Sorry, the Google Maps API is not compatible with this browser"); 
     669                    } 
     670                    //]]> 
     671                    </script> 
     672                <p>&nbsp;</p> 
     673        <? } //end if geoip_map ?> 
    649674                <div id="spyContainer"> 
    650675                <?php